Page 1 of 1

Software Task switching && ESP0

Posted: Sat Feb 11, 2006 4:59 pm
by xnix
I read some tutorials, and it is working.
But I want Ring3 and paging , so I have some quesions.

1) How to write ESP0 ?
2) How to use iobitmap ?
3) How to write cr3 ?

Re:Software Task switching && ESP0

Posted: Sun Feb 12, 2006 1:17 am
by Assembler
Search the forum, there were many threads about that

Assembler,

Re:Software Task switching && ESP0

Posted: Mon Feb 13, 2006 4:36 am
by Pype.Clicker
more specifically you've been pointed to tutorials recently, but haven't replied to those threads ... so maybe you've read them, maybe you haven't.

anyway.

When it comes to ring3 support with software multitasking, you need to keep in mind that the current TSS's ESP0 and SS0 will be used by the CPU when an interrupt or exception arise during handling of userlevel stuff (including INT xx system calls and timer IRQ used for the scheduler).

Since you always keep the same TSS, your thread switching procedure will have to maintain proper state in those fields, that is, grab the values from the thread control block and write them in the TSS as part of the task switching code. Note that there's no reason to store the actual value of TSS.ESP0 in your TCB though (that's something that should be done when initializing the TCB).

taking care of CR3 is basically the same: when switching the tasks, you compare the current value of CR3 and the one stored in the about-to-run TCB. If they're different, you reload CR3 with the new value. Reloading only when different values are detected will give you a strong benefit in terms of performances against hardware task switching ...