From: John Tsiombikas Date: Sun, 13 Oct 2019 14:46:38 +0000 (+0300) Subject: fixed the interrupt gate descriptor setup X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=ld45_start_nothing;a=commitdiff_plain;h=74628dd7656a232ac4a701079fd81a742600985e fixed the interrupt gate descriptor setup --- diff --git a/src/boot/boot2.asm b/src/boot/boot2.asm index 40807ef..df2653c 100644 --- a/src/boot/boot2.asm +++ b/src/boot/boot2.asm @@ -63,7 +63,7 @@ gdt_lim: dw 23 gdt_base: dd gdt align 4 -idt_lim: dw 111 +idt_lim: dw 2047 idt_base: dd idt align 8 @@ -85,6 +85,7 @@ idt: times 104 db 0 dw 8 dw 8f00h ; type: trap, present, default dw 0 + times 1944 db 0 ; enough space for 256 gates gpf_msg: db "GP fault " diff --git a/src/intr.asm b/src/intr.asm index 58ef37f..fdd06ef 100644 --- a/src/intr.asm +++ b/src/intr.asm @@ -12,8 +12,81 @@ GATE_PRESENT equ 8000h global init_intr init_intr: call init_pic + ; install trap handlers + set_trap 0, trap_entry_div + set_trap 1, trap_entry_debug + set_trap 2, trap_entry_nmi + set_trap 3, trap_entry_bp + set_trap 4, trap_entry_overflow + set_trap 5, trap_entry_bound + set_trap 6, trap_entry_ill + set_trap 7, trap_entry_nodev + set_trap 8, trap_entry_dfault + set_trap 9, trap_entry_copseg + set_trap 10, trap_entry_tss + set_trap 11, trap_entry_segpres + set_trap 12, trap_entry_stack + set_trap 13, trap_entry_prot + set_trap 14, trap_entry_page + set_trap 15, trap_entry_reserved + set_trap 16, trap_entry_fpu + set_trap 17, trap_entry_align + set_trap 18, trap_entry_mce + set_trap 19, trap_entry_sse + + ; install dummy interrupt handlers for all IRQ vectors +%assign i 0 +%rep 8 + set_irq_vector i, dummy_intr_pic1 + set_irq_vector i+8, dummy_intr_pic2 +%assign i i+1 +%endrep ret +%macro trap_err 2 + global trap_entry_%2 +trap_entry_%2: + push dword %1 + jmp trap_entry_common +%endmacro + +%macro trap_noerr 2 + global trap_entry_%2 +trap_entry_%2: + push dword 0 + push dword %1 + jmp trap_entry_common +%endmacro + +trap_entry_common: + pusha + ; do exception handling + popa + add esp, 8 ; remove error code and exception number from stack + iret + + trap_noerr 0, div + trap_noerr 1, debug + trap_noerr 2, nmi + trap_noerr 3, bp + trap_noerr 4, overflow + trap_noerr 5, bound + trap_noerr 6, ill + trap_noerr 7, nodev + trap_err 8, dfault + trap_noerr 9, copseg + trap_err 10, tss + trap_err 11, segpres + trap_err 12, stack + trap_err 13, prot + trap_err 14, page + trap_noerr 15, reserved + trap_noerr 16, fpu + trap_err 17, align + trap_noerr 18, mce + trap_noerr 19, sse + + global set_intr set_intr: push ebp @@ -21,47 +94,38 @@ set_intr: push ebx mov ebx, [ebp + 8] - mov eax, GATE_TRAP + mov ax, GATE_TRAP cmp ebx, 32 ; determine if it's an IRQ or an exception (trap) jb .notirq - mov eax, GATE_INTR + mov ax, GATE_INTR .notirq: - shl ebx, 1 lea ebx, [ebx * 8 + idt] ; ebx <- pointer to gate descriptor - ; type|dpl goes to the 3rd dword of the descriptor (dpl is 0) - or eax, (GATE_DEFAULT | GATE_PRESENT) - mov [ebx + 8], eax - ; address low 16bits go to the first dword of the descriptor + ; type|dpl goes to the 3rd word of the descriptor (dpl is 0) + or ax, (GATE_DEFAULT | GATE_PRESENT) + mov [ebx + 4], ax + ; address low 16bits go to the first word of the descriptor mov eax, [ebp + 12] mov [ebx], ax - ; address high 16bits go to the last dword of the descriptor + ; address high 16bits go to the last word of the descriptor shr eax, 16 - mov [ebx + 12], eax - ; selector (kcode:1) goes to the second dword of the descriptor - mov dword [ebx + 4], 08h - - ; install dummy interrupt handlers for all IRQ vectors -%assign i 0 -%rep 8 - set_irq_vector i, dummy_intr_pic1 - set_irq_vector i+8, dummy_intr_pic2 -%assign i i+1 -%endrep + mov [ebx + 6], ax + ; selector (kcode:1) goes to the second word of the descriptor + mov word [ebx + 2], 08h pop ebx pop ebp ret dummy_intr_pic1: - push eax + pusha end_of_irq 0 - pop eax + popa iret dummy_intr_pic2: - push eax + pusha end_of_irq 8 - pop eax + popa iret ; PIC initialization command word 1 bits diff --git a/src/intr.inc b/src/intr.inc index a96b164..4bcc085 100644 --- a/src/intr.inc +++ b/src/intr.inc @@ -10,6 +10,12 @@ IRQ_OFFSET equ 32 %define IRQ_TO_INTR(x) ((x) + IRQ_OFFSET) %define INTR_TO_IRQ(x) ((x) - IRQ_OFFSET) +%macro set_trap 2 + push dword %2 + push dword %1 + call set_intr + add esp, 8 +%endmacro %macro set_irq_vector 2 push dword %2