TSS and software switching
Posted: Thu Jun 25, 2020 2:44 am
Hi,
I'm just starting to work on my multitasking code and I have a few questions:
- Do I understand correctly that if I do software switching I only need 1 TSS per core, that stores the kernel stack pointer of the current thread and the kernel data selector?
- Are those^ the only values fetched from the TSS when going from ring3 -> ring0?
- Is updating the kernel stack pointer in TSS the correct way to go when switching between threads?
- Do I need to reload the TSS by doing ltr each time I change the kernel stack pointer or is it updated automatically?
- Also, do I understand the multitasking pipeline correctly:
1. Create a "fake" initial task with the correct values on its stack, so we can switch from and to it later.
2. Whenever an IRQ fires we switch the task by changing the kernel stack pointer in the TSS and the current kernel esp, to the new task's kernel esp. (also storing the current stack top in the task state)
3. Since this new esp already contains the stuff necessary to do an IRET to this task we don't change anything else.
4. repeat 2-3 (this is oversimplified of course not taking priority / time slices, etc into account)
Thanks
I'm just starting to work on my multitasking code and I have a few questions:
- Do I understand correctly that if I do software switching I only need 1 TSS per core, that stores the kernel stack pointer of the current thread and the kernel data selector?
- Are those^ the only values fetched from the TSS when going from ring3 -> ring0?
- Is updating the kernel stack pointer in TSS the correct way to go when switching between threads?
- Do I need to reload the TSS by doing ltr each time I change the kernel stack pointer or is it updated automatically?
- Also, do I understand the multitasking pipeline correctly:
1. Create a "fake" initial task with the correct values on its stack, so we can switch from and to it later.
2. Whenever an IRQ fires we switch the task by changing the kernel stack pointer in the TSS and the current kernel esp, to the new task's kernel esp. (also storing the current stack top in the task state)
3. Since this new esp already contains the stuff necessary to do an IRET to this task we don't change anything else.
4. repeat 2-3 (this is oversimplified of course not taking priority / time slices, etc into account)
Thanks