Modify values on stack in c
Posted: Tue Jan 31, 2017 7:19 am
Hello,
I am trying to write multithreading code for my OS.
'push eax' pushes the esp of the interrupted process onto the stack.
In C:
*regs is that eax value. However, if I modify it to point to a different thread's stack, will the new value be what the handler removes from the stack? (pop eax) Or does the value just get cloned? With the *regs struct, I can modify all cpu registers of the interrupted process, except for the pointer to the processes curent stack!
(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)
https://github.com/michaellangford99/Pa ... ---Clement
Thanks so much!
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!