Espresso 0.0.2c
This commit is contained in:
231
arch/x86/isr.asm
231
arch/x86/isr.asm
@ -1,163 +1,152 @@
|
||||
[BITS 32]
|
||||
|
||||
[GLOBAL isr_stub_table]
|
||||
[GLOBAL irq_stub_table]
|
||||
extern irq_handler ; C function
|
||||
[GLOBAL interrupt_entry]
|
||||
|
||||
extern interrupt_dispatcher
|
||||
|
||||
section .text
|
||||
|
||||
; --------------------------------------------
|
||||
; ------------------- IRQs -------------------
|
||||
; --------------------------------------------
|
||||
; ============================================================
|
||||
; COMMON INTERRUPT ENTRY
|
||||
; ============================================================
|
||||
|
||||
%macro irq_stub 1
|
||||
irq_stub_%+%1:
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
interrupt_entry:
|
||||
|
||||
; Stack already contains:
|
||||
; err_code
|
||||
; int_no
|
||||
; eip
|
||||
; cs
|
||||
; eflags
|
||||
|
||||
pusha ; eax, ecx, edx, ebx, esp, ebp, esi, edi
|
||||
|
||||
push gs
|
||||
push fs
|
||||
push es
|
||||
push ds
|
||||
|
||||
mov ax, 0x10
|
||||
mov ax, 0x10 ; load kernel data selector
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
push dword %1 ; Push IRQ number
|
||||
call irq_handler
|
||||
add esp, 4 ; Clean up stack
|
||||
push esp ; pass pointer to registers_t
|
||||
call interrupt_dispatcher
|
||||
add esp, 4 ; I don't remember what this does... but don't remove it
|
||||
; NVM, I remember: it cleans up the registers_t* argument we passed to interrupt_dispatcher
|
||||
|
||||
; Send EOI
|
||||
mov al, 0x20
|
||||
mov bl, %1
|
||||
cmp bl, 8
|
||||
jb .skip_slave_eoi
|
||||
out 0xA0, al
|
||||
.skip_slave_eoi:
|
||||
out 0x20, al
|
||||
; don't do this yet, it corrupts stuff. wait until the scheduler is finished
|
||||
;mov esp, eax ; move the new stack pointer into esp
|
||||
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
|
||||
popa
|
||||
iret
|
||||
|
||||
add esp, 8 ; remove int_no + err_code
|
||||
|
||||
iret ; return from interrupt
|
||||
|
||||
|
||||
; ============================================================
|
||||
; IRQ STUBS
|
||||
; ============================================================
|
||||
|
||||
%macro IRQ 1
|
||||
irq_stub_%+%1:
|
||||
push dword 0 ; fake error code
|
||||
push dword (32 + %1) ; vector number
|
||||
jmp interrupt_entry
|
||||
%endmacro
|
||||
|
||||
|
||||
; Define 16 IRQ stubs
|
||||
irq_stub 0
|
||||
irq_stub 1
|
||||
irq_stub 2
|
||||
irq_stub 3
|
||||
irq_stub 4
|
||||
irq_stub 5
|
||||
irq_stub 6
|
||||
irq_stub 7
|
||||
irq_stub 8
|
||||
irq_stub 9
|
||||
irq_stub 10
|
||||
irq_stub 11
|
||||
irq_stub 12
|
||||
irq_stub 13
|
||||
irq_stub 14
|
||||
irq_stub 15
|
||||
IRQ 0
|
||||
IRQ 1
|
||||
IRQ 2
|
||||
IRQ 3
|
||||
IRQ 4
|
||||
IRQ 5
|
||||
IRQ 6
|
||||
IRQ 7
|
||||
IRQ 8
|
||||
IRQ 9
|
||||
IRQ 10
|
||||
IRQ 11
|
||||
IRQ 12
|
||||
IRQ 13
|
||||
IRQ 14
|
||||
IRQ 15
|
||||
IRQ 16
|
||||
IRQ 17
|
||||
IRQ 18
|
||||
IRQ 19
|
||||
|
||||
irq_stub_table:
|
||||
%assign i 0
|
||||
%rep 16
|
||||
%rep 20
|
||||
dd irq_stub_%+i
|
||||
%assign i i+1
|
||||
%endrep
|
||||
|
||||
; --------------------------------------------
|
||||
; ------------------- ISRs -------------------
|
||||
; --------------------------------------------
|
||||
|
||||
; Common exception handler entry point
|
||||
isr_common_handler:
|
||||
pusha ; Push general-purpose registers
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
push gs
|
||||
; ============================================================
|
||||
; EXCEPTION STUBS
|
||||
; ============================================================
|
||||
|
||||
; Load known-good segment selectors
|
||||
mov ax, 0x10
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
|
||||
; Print exception number and error code
|
||||
; You can insert direct port writes or call kernel logging function here
|
||||
; For now, just hang
|
||||
.halt:
|
||||
cli
|
||||
hlt
|
||||
jmp .halt
|
||||
|
||||
; If you want to later restore:
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
add esp, 8 ; clean up int_no + err_code
|
||||
iret
|
||||
|
||||
; Macro: for exceptions with error code
|
||||
%macro isr_err_stub 1
|
||||
%macro ISR_NOERR 1
|
||||
isr_stub_%+%1:
|
||||
cli
|
||||
push dword %1 ; interrupt number
|
||||
jmp isr_common_handler
|
||||
push dword 0 ; fake error code
|
||||
push dword %1 ; interrupt number
|
||||
jmp interrupt_entry
|
||||
%endmacro
|
||||
|
||||
; Macro: for exceptions without error code
|
||||
%macro isr_no_err_stub 1
|
||||
%macro ISR_ERR 1
|
||||
isr_stub_%+%1:
|
||||
cli
|
||||
push dword 0 ; fake error code
|
||||
push dword %1 ; interrupt number
|
||||
jmp isr_common_handler
|
||||
push dword %1 ; interrupt number
|
||||
jmp interrupt_entry
|
||||
%endmacro
|
||||
|
||||
; Define all 32 exception stubs
|
||||
isr_no_err_stub 0
|
||||
isr_no_err_stub 1
|
||||
isr_no_err_stub 2
|
||||
isr_no_err_stub 3
|
||||
isr_no_err_stub 4
|
||||
isr_no_err_stub 5
|
||||
isr_no_err_stub 6
|
||||
isr_no_err_stub 7
|
||||
isr_err_stub 8
|
||||
isr_no_err_stub 9
|
||||
isr_err_stub 10
|
||||
isr_err_stub 11
|
||||
isr_err_stub 12
|
||||
isr_err_stub 13
|
||||
isr_err_stub 14
|
||||
isr_no_err_stub 15
|
||||
isr_no_err_stub 16
|
||||
isr_err_stub 17
|
||||
isr_no_err_stub 18
|
||||
isr_no_err_stub 19
|
||||
isr_no_err_stub 20
|
||||
isr_no_err_stub 21
|
||||
isr_no_err_stub 22
|
||||
isr_no_err_stub 23
|
||||
isr_no_err_stub 24
|
||||
isr_no_err_stub 25
|
||||
isr_no_err_stub 26
|
||||
isr_no_err_stub 27
|
||||
isr_no_err_stub 28
|
||||
isr_no_err_stub 29
|
||||
isr_err_stub 30
|
||||
isr_no_err_stub 31
|
||||
|
||||
; Create jump table
|
||||
; Exceptions 0–31
|
||||
|
||||
ISR_NOERR 0
|
||||
ISR_NOERR 1
|
||||
ISR_NOERR 2
|
||||
ISR_NOERR 3
|
||||
ISR_NOERR 4
|
||||
ISR_NOERR 5
|
||||
ISR_NOERR 6
|
||||
ISR_NOERR 7
|
||||
ISR_ERR 8
|
||||
ISR_NOERR 9
|
||||
ISR_ERR 10
|
||||
ISR_ERR 11
|
||||
ISR_ERR 12
|
||||
ISR_ERR 13
|
||||
ISR_ERR 14
|
||||
ISR_NOERR 15
|
||||
ISR_NOERR 16
|
||||
ISR_ERR 17
|
||||
ISR_NOERR 18
|
||||
ISR_NOERR 19
|
||||
ISR_NOERR 20
|
||||
ISR_NOERR 21
|
||||
ISR_NOERR 22
|
||||
ISR_NOERR 23
|
||||
ISR_NOERR 24
|
||||
ISR_NOERR 25
|
||||
ISR_NOERR 26
|
||||
ISR_NOERR 27
|
||||
ISR_NOERR 28
|
||||
ISR_NOERR 29
|
||||
ISR_ERR 30
|
||||
ISR_NOERR 31
|
||||
|
||||
isr_stub_table:
|
||||
%assign i 0
|
||||
%rep 32
|
||||
|
||||
Reference in New Issue
Block a user