Multiple rings with software multitasking

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
yakujabi
Posts: 12
Joined: Mon Feb 25, 2008 11:16 pm

Multiple rings with software multitasking

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
yakujabi
Posts: 12
Joined: Mon Feb 25, 2008 11:16 pm

Post 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?
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post 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.
yakujabi
Posts: 12
Joined: Mon Feb 25, 2008 11:16 pm

Post by yakujabi »

so how exactly is saving the registers on the stack faster than letting the processor do the saving?
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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
yakujabi
Posts: 12
Joined: Mon Feb 25, 2008 11:16 pm

Post by yakujabi »

It sure did help, thanks a lot :)
Post Reply