Code: Select all
mov esp, stack+0x4000
push ebx
call _kmain
section .bss
stack: resb 0x4000
Then, tasks - I'd like to implement a basic software task switcher. I've been reading about how to do this, and I think I understand the general idea but I want to be sure this is correct:
Each task has a structure, containing its esp, eip, ebp, task's id, etc. The PIC generates interrupts, and after a few go by a task switch is called. The next task structure pointed to by the current task structure is selected. Then somehow, I need to replace the old task's esp and eip values with the new task's values on the stack - these are then pop'd off by the iret command after returning to the interrupt service routine. This way, instead of returning to the original task that was running when the interrupt occurred, the ISR returns to the new task, at the instruction pointed to by the new eip. Does that all sound correct, or am I missing something?
One thing I'm not clear on is the stack - if I only have one kernel stack, do I need to change the value of esp that iret pops off when I change tasks? If I don't, how does a new task not trample the data the old task had stored on the stack?
Any clarification would be much appreciated.