OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 9:53 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Use TSS only for stack switching
PostPosted: Sun Oct 15, 2017 9:30 am 
Offline
Member
Member
User avatar

Joined: Sat May 20, 2017 1:25 am
Posts: 51
Location: PCI bus: 3, slot: 9, function: 5
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!


Top
 Profile  
 
 Post subject: Re: Use TSS only for stack switching
PostPosted: Sun Oct 15, 2017 10:52 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
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.

_________________
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].


Top
 Profile  
 
 Post subject: Re: Use TSS only for stack switching
PostPosted: Sun Oct 15, 2017 11:58 am 
Offline
Member
Member
User avatar

Joined: Sat May 20, 2017 1:25 am
Posts: 51
Location: PCI bus: 3, slot: 9, function: 5
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.


I will not use the syscall instruction, I will have not any problem, will I have (maybe something that I didn't understand)?

_________________
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 68 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group