mirror of
https://github.com/johndoe6345789/MetalOS.git
synced 2026-04-24 21:55:14 +00:00
121 lines
2.8 KiB
NASM
121 lines
2.8 KiB
NASM
; Interrupt Service Routines (ISRs) for x86_64
|
|
; Assembly stubs that save state and call C handler
|
|
|
|
global isr0, isr1, isr2, isr3, isr4, isr5, isr6, isr7
|
|
global isr8, isr9, isr10, isr11, isr12, isr13, isr14, isr15
|
|
global isr16, isr17, isr18, isr19, isr20, isr21, isr22, isr23
|
|
global isr24, isr25, isr26, isr27, isr28, isr29, isr30, isr31
|
|
global irq0, irq1
|
|
|
|
extern interrupt_handler
|
|
|
|
section .text
|
|
bits 64
|
|
|
|
; Macro for ISRs without error code
|
|
%macro ISR_NOERRCODE 1
|
|
isr%1:
|
|
push qword 0 ; Dummy error code
|
|
push qword %1 ; Interrupt number
|
|
jmp isr_common_stub
|
|
%endmacro
|
|
|
|
; Macro for ISRs with error code
|
|
%macro ISR_ERRCODE 1
|
|
isr%1:
|
|
push qword %1 ; Interrupt number
|
|
jmp isr_common_stub
|
|
%endmacro
|
|
|
|
; Macro for IRQs
|
|
%macro IRQ 2
|
|
irq%1:
|
|
push qword 0 ; Dummy error code
|
|
push qword %2 ; Interrupt number
|
|
jmp isr_common_stub
|
|
%endmacro
|
|
|
|
; CPU Exceptions (0-31)
|
|
ISR_NOERRCODE 0 ; Divide by zero
|
|
ISR_NOERRCODE 1 ; Debug
|
|
ISR_NOERRCODE 2 ; Non-maskable interrupt
|
|
ISR_NOERRCODE 3 ; Breakpoint
|
|
ISR_NOERRCODE 4 ; Overflow
|
|
ISR_NOERRCODE 5 ; Bound range exceeded
|
|
ISR_NOERRCODE 6 ; Invalid opcode
|
|
ISR_NOERRCODE 7 ; Device not available
|
|
ISR_ERRCODE 8 ; Double fault
|
|
ISR_NOERRCODE 9 ; Coprocessor segment overrun
|
|
ISR_ERRCODE 10 ; Invalid TSS
|
|
ISR_ERRCODE 11 ; Segment not present
|
|
ISR_ERRCODE 12 ; Stack-segment fault
|
|
ISR_ERRCODE 13 ; General protection fault
|
|
ISR_ERRCODE 14 ; Page fault
|
|
ISR_NOERRCODE 15 ; Reserved
|
|
ISR_NOERRCODE 16 ; x87 floating-point exception
|
|
ISR_ERRCODE 17 ; Alignment check
|
|
ISR_NOERRCODE 18 ; Machine check
|
|
ISR_NOERRCODE 19 ; SIMD floating-point exception
|
|
ISR_NOERRCODE 20 ; Virtualization exception
|
|
ISR_NOERRCODE 21 ; Reserved
|
|
ISR_NOERRCODE 22 ; Reserved
|
|
ISR_NOERRCODE 23 ; Reserved
|
|
ISR_NOERRCODE 24 ; Reserved
|
|
ISR_NOERRCODE 25 ; Reserved
|
|
ISR_NOERRCODE 26 ; Reserved
|
|
ISR_NOERRCODE 27 ; Reserved
|
|
ISR_NOERRCODE 28 ; Reserved
|
|
ISR_NOERRCODE 29 ; Reserved
|
|
ISR_ERRCODE 30 ; Security exception
|
|
ISR_NOERRCODE 31 ; Reserved
|
|
|
|
; IRQs (32-47)
|
|
IRQ 0, 32 ; Timer
|
|
IRQ 1, 33 ; Keyboard
|
|
|
|
; Common ISR stub - saves state and calls C handler
|
|
isr_common_stub:
|
|
; Save all general purpose registers
|
|
push rax
|
|
push rbx
|
|
push rcx
|
|
push rdx
|
|
push rsi
|
|
push rdi
|
|
push rbp
|
|
push r8
|
|
push r9
|
|
push r10
|
|
push r11
|
|
push r12
|
|
push r13
|
|
push r14
|
|
push r15
|
|
|
|
; Call C handler with pointer to register state
|
|
mov rdi, rsp
|
|
call interrupt_handler
|
|
|
|
; Restore all registers
|
|
pop r15
|
|
pop r14
|
|
pop r13
|
|
pop r12
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rbp
|
|
pop rdi
|
|
pop rsi
|
|
pop rdx
|
|
pop rcx
|
|
pop rbx
|
|
pop rax
|
|
|
|
; Clean up error code and interrupt number
|
|
add rsp, 16
|
|
|
|
; Return from interrupt
|
|
iretq
|