Software task switchin

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pini

Software task switchin

Post by pini »

I'm currently dealing with task switching, and I'm trying to use software switching (I know that the Intel arch' provides some technique to make it in a hardware way, but this is not what I currently want).
I was just wondering how it could be possible to achieve this with a C function. I mean, as I have to save/store the values of all the registers/selectors in a task structure, defined like this :

Code: Select all

typedef struct task_s
{
u32 eax;
u32 edx;
...
}task_t;
But if the scheduler is called, say by a system call (ie by a user level accessible int), a piece of assembly code is calling my C handler, and the code of these functions will change the values of mainly all registers.

Do I need to write the saving part in assembly only, or does another technique work ?
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Software task switchin

Post by distantvoices »

You can do the saving (isr-prologue) and the restoring (isr-epilogue) in your isr stubs. This is the easiest and most straight forward way.

the other possibility is to do it like linux: you have a dedicated switch_and_restore function at the end of the scheduler.

I for my part don't like the idea to do it like this. For a micro kernel design like mine, I've found putting the save-state/restore-state in the isr-stubs more convenient. It is a mechanism that is so general and always running, you don't need to put it in an extra function. just put it in the stubs and it does what you expect it to do. - with any privilege level switches and even with vm86 - provided you init the tasks the right way.

Just a suggestion: drop an eye at www.distantvoices.org . You 'll find a text about multitasking there, I've written some time ago. It may cover some of your questions. An older version of it is located at www.osdever.net

stay safe
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Software task switchin

Post by Pype.Clicker »

beyond infinity wrote: You can do the saving (isr-prologue) and the restoring (isr-epilogue) in your isr stubs. This is the easiest and most straight forward way.
One thing that doesn't look obvious in this approach is how you'll deal with a call like "sleep" that need to be called from the user-level world as well as internally from the kernel ...
BI lazy

Re:Software task switchin

Post by BI lazy »

Not being obvious is it indeed, but think it this way:

Since a Micro Kernel has merely nothing more to do but passing messages tither and hither (maybe providing basic service like semaphores too), think at it: a Kernel Service issues a sleep call and sets a user process or itself to sleep. the kernel just passes a message and chooses another process to run. The same it is with user processes... one wants to sleep for certain time: just issue sleep (my fingers are stiff today... ****). The kernel service responsible for this kind of call takes the process into its sleeping queue - and the show goes on...

May be I am in Err and yet to learn from the wise ones...

in the meantime stay safe and I now go off to have something to eat... awful stiff joints...
pini

Re:Software task switchin

Post by pini »

Beyond Infinity: thanks for the URLs, I will help a lot to achieve my task switching code. ;D
Post Reply