Task Switching

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
VLAVI

Task Switching

Post by VLAVI »

Hi!
I've some doubts (two, by now :-) )

1) The IDEA:
?...
?save_current_context(return_point);
?load_others_task_context();
?return_point:
?...
?
When you save the current context you have to save a value for EIP that must be AFTER the load context procedure, so you use return_point.

2) I'm tring to do this without using the INTEL processor facilities (TSS,etc.), would it be very difficult?

Thanks!
Alexei A. Frounze

Re: Task Switching

Post by Alexei A. Frounze »

Hi!
I've some doubts (two, by now :-) )

1) The IDEA:
?...
?save_current_context(return_point);
?load_others_task_context();
?return_point:
?...
?
When you save the current context you have to save a value for EIP that must be AFTER the load context procedure, so you use return_point.

2) I'm tring to do this without using the INTEL processor facilities (TSS,etc.), would it be very difficult?

Thanks!
:) Actually, it's not difficult at all. The most common way of doing that is by switching stacks. You write an interrupt routine for the scheduler. This routine pushes all registers of the current task to the stack, then it saves current values of SS and (E)SP in some array, loads SS and (E)SP of the other task, pops all registers and issues IRET. So to switch tasks you just make an INT xx call and that's it. The only thing you should do besides this scheduler thing, is some routine that would prepare stack contents for a new task (e.g. would "push" (E)FLAGS+CS+(E)IP and other registers to the new stack and save resulting SS:(E)SP so that the scheduler gets the required information from that array easily and does not make any data processing.
Im_VLAVI

Re: Task Switching

Post by Im_VLAVI »

Ok... but I think the interrupt i not necessary.
In my OS the call is made by an interrupt and after some code it makes the task switching...in a C function (following your 'stack advice').
I think that making another interrupt call will overload the system, and It tries to be a real-time one :-D
Post Reply