Page 1 of 1
Software task switchin
Posted: Mon Sep 15, 2003 10:41 am
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 ?
Re:Software task switchin
Posted: Tue Sep 16, 2003 12:35 am
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
Re:Software task switchin
Posted: Tue Sep 16, 2003 2:40 am
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 ...
Re:Software task switchin
Posted: Tue Sep 16, 2003 3:34 am
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...
Re:Software task switchin
Posted: Tue Sep 16, 2003 5:04 am
by pini
Beyond Infinity: thanks for the URLs, I will help a lot to achieve my task switching code. ;D