Use TSS only for stack switching
- Coconut9
- Member
- Posts: 51
- Joined: Sat May 20, 2017 1:25 am
- Location: PCI bus: 3, slot: 9, function: 5
Use TSS only for stack switching
I now that TSS is using for task switching but can I use it only for stack switching? If yes Do I need to set anything else except from "ss0" and "esp0" values to it? Which of the other values will change the processor behavior? Alos which of them are sitting by the processor and when (on task switching)? I am asking because I thought because my kernel functions will not push more than 8 bytes at the same time can that use the "eax","ebx",... positions as the stack, can I?
How people react when a new update of your OS is coming:
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!
Re: Use TSS only for stack switching
Yes, just set the ESP and SS values.
There is a single cases where you need to use hardware context switching, even when your OS performs software context switching during normal operation, and that is the NMI and MCE handlers (when using the syscall instruction). The reason for that is that hardware switching can atomically change the stack even when there is no ring transition. syscall requires you to manually switch to the user mode stack while you're still in supervisor mode. After you did that, NMIs and MCEs will run on this user mode stack if they are not handled by a task gate.
There is a single cases where you need to use hardware context switching, even when your OS performs software context switching during normal operation, and that is the NMI and MCE handlers (when using the syscall instruction). The reason for that is that hardware switching can atomically change the stack even when there is no ring transition. syscall requires you to manually switch to the user mode stack while you're still in supervisor mode. After you did that, NMIs and MCEs will run on this user mode stack if they are not handled by a task gate.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
- Coconut9
- Member
- Posts: 51
- Joined: Sat May 20, 2017 1:25 am
- Location: PCI bus: 3, slot: 9, function: 5
Re: Use TSS only for stack switching
I will not use the syscall instruction, I will have not any problem, will I have (maybe something that I didn't understand)?Korona wrote:Yes, just set the ESP and SS values.
There is a single cases where you need to use hardware context switching, even when your OS performs software context switching during normal operation, and that is the NMI and MCE handlers (when using the syscall instruction). The reason for that is that hardware switching can atomically change the stack even when there is no ring transition. syscall requires you to manually switch to the user mode stack while you're still in supervisor mode. After you did that, NMIs and MCEs will run on this user mode stack if they are not handled by a task gate.
How people react when a new update of your OS is coming:
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!