Software Task switching && ESP0

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
xnix

Software Task switching && ESP0

Post 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 ?
Assembler

Re:Software Task switching && ESP0

Post by Assembler »

Search the forum, there were many threads about that

Assembler,
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Software Task switching && ESP0

Post 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 ...
Post Reply