Files
Espresso/arch/x86/isr.asm

157 lines
2.6 KiB
NASM
Raw Normal View History

2025-06-13 18:03:39 -05:00
[BITS 32]
2026-03-20 16:57:08 -05:00
2025-06-13 18:03:39 -05:00
[GLOBAL isr_stub_table]
[GLOBAL irq_stub_table]
2026-03-20 16:57:08 -05:00
[GLOBAL interrupt_entry]
extern interrupt_dispatcher
2025-06-13 18:03:39 -05:00
section .text
2026-03-20 16:57:08 -05:00
; ============================================================
; COMMON INTERRUPT ENTRY
; ============================================================
2025-06-13 18:03:39 -05:00
2026-03-20 16:57:08 -05:00
interrupt_entry:
; Stack already contains:
; err_code
; int_no
; eip
; cs
; eflags
pusha ; eax, ecx, edx, ebx, esp, ebp, esi, edi
2025-06-13 18:03:39 -05:00
push gs
2026-03-20 16:57:08 -05:00
push fs
push es
push ds
2025-06-13 18:03:39 -05:00
2026-03-20 16:57:08 -05:00
mov ax, 0x10 ; load kernel data selector
2025-06-13 18:03:39 -05:00
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
2026-03-20 16:57:08 -05:00
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
2025-06-13 18:03:39 -05:00
2026-03-20 16:57:08 -05:00
; don't do this yet, it corrupts stuff. wait until the scheduler is finished
;mov esp, eax ; move the new stack pointer into esp
2025-06-13 18:03:39 -05:00
pop gs
pop fs
pop es
pop ds
2026-03-20 16:57:08 -05:00
2025-06-13 18:03:39 -05:00
popa
2026-03-20 16:57:08 -05:00
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
2025-06-13 18:03:39 -05:00
2026-03-20 16:57:08 -05:00
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
2025-06-13 18:03:39 -05:00
irq_stub_table:
%assign i 0
2026-03-20 16:57:08 -05:00
%rep 20
2025-06-13 18:03:39 -05:00
dd irq_stub_%+i
%assign i i+1
%endrep
2026-03-20 16:57:08 -05:00
; ============================================================
; EXCEPTION STUBS
; ============================================================
2025-06-13 18:03:39 -05:00
2026-03-20 16:57:08 -05:00
%macro ISR_NOERR 1
2025-06-13 18:03:39 -05:00
isr_stub_%+%1:
2026-03-20 16:57:08 -05:00
push dword 0 ; fake error code
push dword %1 ; interrupt number
jmp interrupt_entry
2025-06-13 18:03:39 -05:00
%endmacro
2026-03-20 16:57:08 -05:00
%macro ISR_ERR 1
2025-06-13 18:03:39 -05:00
isr_stub_%+%1:
2026-03-20 16:57:08 -05:00
push dword %1 ; interrupt number
jmp interrupt_entry
2025-06-13 18:03:39 -05:00
%endmacro
2026-03-20 16:57:08 -05:00
; Exceptions 031
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
2025-06-13 18:03:39 -05:00
isr_stub_table:
%assign i 0
%rep 32
dd isr_stub_%+i
%assign i i+1
%endrep