preemptive Multitasking - how does the task-switch work
Posted: Wed May 04, 2022 10:42 am
So i have a working normal task switch for cooperative multitasking.
Now i want to switch tasks with help of the pit irq.
Normally the irq is called, i push all the registers to the stack, call the handler, the handler returns, i pop all the registers from the stack and return back to the state before the interrupt with iretq.
If i simply call the task-switch in the handler, the task switch stores the wrong registers, and returns to the spot where rip points -> to the task, there it pops all the registers stored last time from the stack for the task and proceeds to execute the task, but because it does return to the task the part after the handler call: popping all the registers from the stack and returning back via iretq never happens.
In theory, how would i switch the task if i wanted to use the pit for it?
Now i want to switch tasks with help of the pit irq.
Normally the irq is called, i push all the registers to the stack, call the handler, the handler returns, i pop all the registers from the stack and return back to the state before the interrupt with iretq.
If i simply call the task-switch in the handler, the task switch stores the wrong registers, and returns to the spot where rip points -> to the task, there it pops all the registers stored last time from the stack for the task and proceeds to execute the task, but because it does return to the task the part after the handler call: popping all the registers from the stack and returning back via iretq never happens.
In theory, how would i switch the task if i wanted to use the pit for it?