Page 1 of 1

Multiple rings with software multitasking

Posted: Sun Mar 23, 2008 3:09 pm
by yakujabi
Switching rings requires a TSS, which implies hardware-based multitasking, yet software multitasking seems to be extremely popular.

Is there some way to do ring-switching in software that I'm not aware of, or is it just that most people stick to ring 0?

Posted: Sun Mar 23, 2008 4:15 pm
by Combuster
Hardware multitasking is about switching TSS's. With software multitasking you use one and the same TSS, essentially staying within the same hardware task.

Posted: Mon Mar 24, 2008 1:03 am
by yakujabi
but if the processor operates on the same TSS, reading from it and writing into it, isn't that the same as a switch between TSS's?

Posted: Mon Mar 24, 2008 2:15 am
by cyr1x
yakujabi wrote:but if the processor operates on the same TSS, reading from it and writing into it, isn't that the same as a switch between TSS's?
No in SM you only load the ESP0, SS0 field that's all, the registers are saved on the stack. In HM every task has a TSS and the registers are saved in the TSS.

Posted: Mon Mar 24, 2008 6:20 am
by yakujabi
so how exactly is saving the registers on the stack faster than letting the processor do the saving?

Posted: Mon Mar 24, 2008 6:57 am
by exkor
yakujabi wrote:so how exactly is saving the registers on the stack faster than letting the processor do the saving?
its probably not but there are other things that make software multitasking faster. More detailed can be found in this thread and many threads like it.

Posted: Mon Mar 24, 2008 6:58 am
by JamesM
yakujabi wrote:so how exactly is saving the registers on the stack faster than letting the processor do the saving?
Hi,

First of all, it is not faster. However, it is of comparable and similar speed, because saving registers requires quite a few memory bus cycles. Also, with software multitasking the programmer has the option to save only a subset of the available registers, or a superset of those saved by HW task switching (notably the floating point registers, which are not saved by a TSS switch).

The big advantages that people see to software task switching are (a) less bit fiddling in the TSS, (b) infinite tasks - you can only fit a certain number of TSSes into your GDT, and (c) it's FAR more portable. HW task switching will only work on the x86. Software will work in principle without much code modification on other platforms.

Hope this helps,

James

Posted: Mon Mar 24, 2008 8:22 am
by yakujabi
It sure did help, thanks a lot :)