Page 1 of 1

Task Switching

Posted: Mon Jun 04, 2001 5:16 am
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!

Re: Task Switching

Posted: Fri Jun 08, 2001 7:11 pm
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.

Re: Task Switching

Posted: Tue Jul 03, 2001 5:31 am
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