diff --git a/kernel/Makefile b/kernel/Makefile index 0689fc6..6072b6f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -9,7 +9,9 @@ SRCS = kernel.asm \ dev/vga_console.inc \ mm/mm.inc \ mm/pmm.inc \ - lock.inc + lock.inc \ + gdt.inc \ + isr.inc .PHONY: all all: $(KERNEL) diff --git a/kernel/isr.inc b/kernel/isr.inc index e444ae5..3fb21e6 100644 --- a/kernel/isr.inc +++ b/kernel/isr.inc @@ -1,5 +1,4 @@ macro ISR [name,error] { -isr_table: forward dd isr_#name forward @@ -13,6 +12,34 @@ forward } +idt_setup: + xor ecx, ecx +@@: + mov eax, [aISRTable + (ecx * 4)] + mov [aInterruptGate + (ecx * 8)], ax + mov [aInterruptGate + (ecx * 8) + 2], word 0x08 + + mov [aInterruptGate + (ecx * 8) + 5], word 0x8E + shr eax, 16 + mov [aInterruptGate + (ecx * 8) + 6], ax + inc ecx + cmp ecx, 32 + jb @b + + lidt [pIDT] + sti + ret + +pIDT: + dw aInterruptGate.end-aInterruptGate-1 + dd aInterruptGate + +; variable: idt_entries +aInterruptGate: + dd 256*2 dup(0) +.end: + + isr_common: pusha @@ -25,6 +52,9 @@ isr_common: mov fs, ax mov gs, ax + mov esi, szMsgInterrupt + call klog + pop eax mov ds, ax mov es, ax @@ -36,6 +66,7 @@ isr_common: sti iret +aISRTable: ISR \ division_by_zero, 0, \ debug, 0, \ @@ -69,3 +100,5 @@ ISR \ reserved29, 0, \ security_exception, 0, \ reserved31, 0 + +szMsgInterrupt db "Interrupt", 0 diff --git a/kernel/kernel.asm b/kernel/kernel.asm index 2d6cc42..256762a 100644 --- a/kernel/kernel.asm +++ b/kernel/kernel.asm @@ -56,6 +56,7 @@ kmain: lgdt [pGDT] ; I don't think i need to reload segment cuz their value are already correct + call idt_setup .halt: @@ -73,6 +74,7 @@ kmain: include 'mm/mm.inc' include 'lock.inc' include 'gdt.inc' + include 'isr.inc' szMsgKernelAlive db "Kernel is alive", 0 szErrorBootProtocol db "Error: wrong magic number", 0 diff --git a/kernel/pic.inc b/kernel/pic.inc index 231041d..9fca0b0 100644 --- a/kernel/pic.inc +++ b/kernel/pic.inc @@ -1,3 +1,6 @@ + ;; File: pic.inc + ;; + PIC1_COMMAND = 0x20 PIC1_DATA = 0x21 PIC2_COMMAND = 0xA0 diff --git a/kernel/sys/cpu.inc b/kernel/sys/cpu.inc index 5e25e8c..cd390b2 100644 --- a/kernel/sys/cpu.inc +++ b/kernel/sys/cpu.inc @@ -102,6 +102,7 @@ struc idt_gate .attributes: resb 1 .offset_high: resw 1 endstruc +defn idt_gate ;; About: Gates ;; - Task Gate