Context Switching stack in long mode
Posted: Mon Jun 15, 2015 7:57 am
Hi all,
I'm working on a long mode kernel, and I'm at the point where I want to start context switching and getting to ring 3. To do so I wish to use software context switching. I believe I understand the theory, but as resources for 64-bits are quite rare, I'm not sure how to do this best.
To summarise what I believe I need to do:
- Set up a new stack for a process
- Set up an EFLAGS register there with the privilege level set to 3
- Switch to this stack
- Execute IRETQ
Am I right so far?
Now let's say the application switches to a bad stack (for example, some memory of the kernel) and the user either calls an interrupt, this stack will be used, is this correct?
So, I'll need to set up a TSS or IST to switch to a correct stack in either case. I'm a bit confused about whether a TSS can still be used for this purpose for 64-bit mode ("In 64-bit mode, task switching is not supported, but TSS descriptors still exist" - quote from the Intel manual makes me think so).
Which method is best, then? A TSS or setting the IST?
Thanks in advance,
Evoex
I'm working on a long mode kernel, and I'm at the point where I want to start context switching and getting to ring 3. To do so I wish to use software context switching. I believe I understand the theory, but as resources for 64-bits are quite rare, I'm not sure how to do this best.
To summarise what I believe I need to do:
- Set up a new stack for a process
- Set up an EFLAGS register there with the privilege level set to 3
- Switch to this stack
- Execute IRETQ
Am I right so far?
Now let's say the application switches to a bad stack (for example, some memory of the kernel) and the user either calls an interrupt, this stack will be used, is this correct?
So, I'll need to set up a TSS or IST to switch to a correct stack in either case. I'm a bit confused about whether a TSS can still be used for this purpose for 64-bit mode ("In 64-bit mode, task switching is not supported, but TSS descriptors still exist" - quote from the Intel manual makes me think so).
Which method is best, then? A TSS or setting the IST?
Thanks in advance,
Evoex