I am trying to write multithreading code for my OS.
'push eax' pushes the esp of the interrupted process onto the stack.
Code: Select all
;push process stack
push eax
mov eax, irq_handler
call eax
pop eax
Code: Select all
void irq_handler(struct x86_registers *regs)
{
void (*handler)(struct x86_registers *regs);
handler = irq_handlers[regs->int_no - 32];
if (handler)
handler(regs);
irq_send_EOI_8259(regs->int_no);
}
(BTW When an interrupt happens on my OS all registers are pushed onto the stack, then esp is put in eax. The stack is changed to a predefined 'interrupt stack' then eax is pushed, and the handler is called. eax is popped back off, stack is changed back, and regs are popped off. IRET)
Code: Select all
_irq_stub:
;push all data onto current stack
pusha
push ds
push es
push fs
push gs
;set up for handler
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
; ====switch stacks:
; load interrupt stack
mov esp, [int_stack]
mov ebp, [int_stack+4]
;push process stack
push eax
mov eax, irq_handler
call eax
pop eax
; save interrupt stack
mov [int_stack], esp
mov [int_stack+4], ebp
;reload process stack
mov esp, eax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8 ; jump past interrupt number and code
iret
Thanks so much!