OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: preemptive Multitasking - how does the task-switch work
PostPosted: Wed May 04, 2022 10:42 am 
Offline

Joined: Thu Sep 23, 2021 3:08 am
Posts: 6
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?


Top
 Profile  
 
 Post subject: Re: preemptive Multitasking - how does the task-switch work
PostPosted: Wed May 04, 2022 11:24 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Your task switch function should return to its caller. That way, when you call it inside your PIT handler, it returns to your PIT handler, and when you call it somewhere else, it returns to that somewhere else.

Typical kernels handle this by switching between kernel stacks, so each task has its own kernel stack.


Top
 Profile  
 
 Post subject: Re: preemptive Multitasking - how does the task-switch work
PostPosted: Wed May 04, 2022 11:29 am 
Offline

Joined: Thu Sep 23, 2021 3:08 am
Posts: 6
Octocontrabass wrote:
Your task switch function should return to its caller. That way, when you call it inside your PIT handler, it returns to your PIT handler, and when you call it somewhere else, it returns to that somewhere else.

Typical kernels handle this by switching between kernel stacks, so each task has its own kernel stack.

but how do i get the iretq at the end to switch to the new task then?


Top
 Profile  
 
 Post subject: Re: preemptive Multitasking - how does the task-switch work
PostPosted: Wed May 04, 2022 11:37 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
You don't. The IRETQ at the end of your PIT handler is used to return to the original task.

If you're setting up a new task and you want that new task to be in ring 3, you set up the new task's ring 0 stack to point to code that will jump into ring 3 (using IRETQ or SYSRET or whatever you want).


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 49 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