interrupts half-done
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 6 Oct 2019 22:58:23 +0000 (01:58 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 6 Oct 2019 22:58:23 +0000 (01:58 +0300)
src/boot/boot2.asm
src/gfx.asm
src/intr.asm [new file with mode: 0644]
src/intr.inc [new file with mode: 0644]
src/keyb.asm [new file with mode: 0644]

index 0fac8fe..40807ef 100644 (file)
@@ -77,6 +77,7 @@ gdt:  ; 0: null segment
        dd 0000ffffh
        dd 00cf9200h
 
        dd 0000ffffh
        dd 00cf9200h
 
+       global idt
        align 8
 idt:   times 104 db 0
        ; trap gate 13: general protection fault
        align 8
 idt:   times 104 db 0
        ; trap gate 13: general protection fault
index 06ff5e4..ced0863 100644 (file)
@@ -1,19 +1,4 @@
 ; vi:filetype=nasm ts=8 sts=8 sw=8:
 ; vi:filetype=nasm ts=8 sts=8 sw=8:
-;
-; list of functions
-; -----------------
-; init_gfx
-;    initializes the video hardware and graphics routines
-; clear
-;    clears the framebuffer (not vmem)
-;    clobbers: eax, ecx, edi
-; swap_buffers
-;    copies the framebuffer to video memory
-;    clobbers: eax, ecx, edi, esi
-; wait_vsync
-;    clobbers: al, dx
-; set_palette_entry(idx[al], r[ah], g[bl], b[bh])
-;    colors are 0-255
        bits 32
        section .text
 
        bits 32
        section .text
 
diff --git a/src/intr.asm b/src/intr.asm
new file mode 100644 (file)
index 0000000..1bbf319
--- /dev/null
@@ -0,0 +1,60 @@
+; vi:filetype=nasm ts=8 sts=8 sw=8:
+       section .text
+
+%include "intr.inc"
+
+       global init_intr
+init_intr:
+       call init_pic
+       ret
+
+       global set_intr
+set_intr:
+       ret
+
+PIC1_CMD equ 20h
+PIC1_DATA equ 21h
+PIC2_CMD equ 0a0h
+PIC2_DATA equ 0a1h
+
+; PIC initialization command word 1 bits
+ICW1_ICW4_NEEDED       equ 01h
+ICW1_SINGLE            equ 02h
+ICW1_INTERVAL4         equ 04h
+ICW1_LEVEL             equ 08h
+ICW1_INIT              equ 10h
+; PIC initialization command word 4 bits
+ICW4_8086              equ 01h
+ICW4_AUTO_EOI          equ 02h
+ICW4_BUF_SLAVE         equ 08h
+ICW4_BUF_MASTER                equ 0ch
+ICW4_SPECIAL           equ 10h
+; PIC operation command word 2 bits
+OCW2_EOI               equ 20h
+
+init_pic:
+       ; send ICW1 saying we'll follow with ICW4 later on
+       mov al, ICW1_INIT | ICW1_ICW4_NEEDED
+       out PIC1_CMD, al
+       out PIC2_CMD, al
+       ; send ICW2 with IRQ remapping
+       mov al, IRQ_OFFSET
+       out PIC1_DATA, al
+       add al, 8
+       out PIC2_DATA, al
+       ; send ICW3 to setup the master/slave relationship
+       ; ... set bit3 = 3rd interrupt input has a slave
+       mov al, 4
+       out PIC1_DATA, al
+       ; ... set slave ID to 2
+       mov al, 2
+       out PIC2_DATA, al
+       ; send ICW4 to set 8086 mode (no calls generated)
+       mov al, ICW4_8086
+       out PIC1_DATA, al
+       out PIC2_DATA, al
+       ; done, reset the data port to 0
+       xor al, al
+       out PIC1_DATA, al
+       out PIC2_DATA, al
+       ret
diff --git a/src/intr.inc b/src/intr.inc
new file mode 100644 (file)
index 0000000..95b18d6
--- /dev/null
@@ -0,0 +1,45 @@
+; vi:filetype=nasm ts=8 sts=8 sw=8:
+
+%define IRQ_OFFSET     32
+%define IRQ_TO_INTR(x) ((x) + IRQ_OFFSET)
+%define INTR_TO_IRQ(x) ((x) - IRQ_OFFSET)
+
+%macro set_irq_vector 2
+       push dword IRQ_TO_INTR(%1)
+       push dword %2
+       call set_intr
+%endmacro
+
+%macro mask_irq 1
+%if %1 < 8
+%assign port PIC1_DATA
+%assign mask (1 << %1)
+%else
+%assign port PIC2_DATA
+%assign mask (1 << (%1 - 8))
+%endif
+       in al, port
+       or al, mask
+       out port, al
+%endmacro
+
+%macro unmask_irq 1
+%if %1 < 8
+%assign port PIC1_DATA
+%assign mask ~(1 << %1)
+%else
+%assign port PIC2_DATA
+%assign mask ~(1 << (%1 - 8))
+%endif
+       in al, port
+       and al, mask
+       out port, al
+%endmacro
+
+%macro end_of_irq 1
+       mov al, OCW2_EOI
+%if %1 >= 8
+       out PIC2_CMD, al
+%endif
+       out PIC1_CMD, al
+%endmacro
diff --git a/src/keyb.asm b/src/keyb.asm
new file mode 100644 (file)
index 0000000..5200f2a
--- /dev/null
@@ -0,0 +1,5 @@
+; vi:filetype=nasm ts=8 sts=8 sw=8:
+
+       global kb_init
+kb_init:
+