Code: Select all
; Common ISR code
isr_common_stub:
; Save CPU state into a structure,
; assembled onto the stack
pusha ; Pushes rdi, rsi, rbp and r[a-d]x
mov ax, ds ; Set the lower 16 bits of rax to ds
push rax ; save the value of rax, which is now ds
mov ax, 0x10 ; kernel data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; Since we assembled the struct
; on the stack, we can simply
; pass the stack pointer as a
; pointer to our structure
mov rdi, rsp
; 2. Call C handler
cld
call ISRHandler
; 3. Restore state
pop rbx
mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
popa
add rsp, 8 ; Cleans up the pushed error code and pushed ISR number
iretq ; pops 5 things at once: CS, EIP, EFLAGS, SS, and RSP
; Common IRQ code. Identical to ISR code except for the 'call'
; and the 'pop ebx'
irq_common_stub:
; Save CPU state into a structure,
; assembled onto the stack
pusha ; Pushes rdi, rsi, rbp and r[a-d]x
mov ax, ds ; Set the lower 16 bits of rax to ds
push rax ; save the value of rax, which is now ds
mov ax, 0x10 ; kernel data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; Since we assembled the struct
; on the stack, we can simply
; pass the stack pointer as a
; pointer to our structure
mov rdi, rsp
; 2. Call C handler
cld
call IRQHandler
; 3. Restore state
pop rax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
popa
add rsp, 8 ; Cleans up the pushed error code and pushed ISR number
iretq ; pops 5 things at once: CS, EIP, EFLAGS, SS, and RSP
Haven't pushed this code yet because I don't feel comfortable committing it yet. I added CLD and it still don't work. I also changed the C IRQHandler to use the Registers structure reference parameter...