Page 1 of 1

LDT and TSS

Posted: Sat Mar 31, 2007 5:40 pm
by anon19287473
I cannot find any information on the LDT and TSS (in ASM), could someone point me to an article or explain how an LDT is formatted and how to load an LDT? I want to be able to spawn a single task, and when it crashes, the kernel should still be running. I assume an LDT and multitasking is the way to do this :P

Posted: Sun Apr 01, 2007 2:45 pm
by Combuster
Using the LDT is kindof deprecated. The best source of reference for that would be the intel manuals. You do not need a LDT for being resistant from bogus applications.

Posted: Sun Apr 01, 2007 4:46 pm
by anon19287473
What exactly does an LDT do than? Doesn't an LDT stop applications from mucking about in each others memory? How do you do hardware task switching/multitasking?

Posted: Sun Apr 01, 2007 5:40 pm
by urxae
anon19287473 wrote:What exactly does an LDT do than? Doesn't an LDT stop applications from mucking about in each others memory?
An LDT can be used to set up segments that can only be used by certain applications while still being able to use globally defined segments from the GDT. This can be used to put multiple processes in the same address space (by making several non-overlapping small segments with different base addresses and putting them in separate LDTs, reloading LDTR on task switches), but this is not the way process separation is usually implemented.
The more typical way to do it is to just give each process an address space for itself, having the segments used by user space defined as base=0 limit=4GB(-1) (aka "flat" segmentation), reloading CR3 when switching processes.
This is simpler to implement, and more portable; memory segmentation as implemented on x86s is pretty unique, AFAIK no other architecture supports it - though x86-64 (in long mode) supports a subset (only fs and gs are allowed to have non-zero bases, and bases and limits aren't used on segments in other registers. I'm not sure if limits are checked on fs & gs)

The LDT method could be a faster though, when running multiple "small" processes and using a scheduler that tries to minimize address space switching (a relatively expensive operation) by scheduling processes in the same address space right after each other.
How do you do hardware task switching/multitasking?
Typically, you don't :P. Hardware task switching is usually only used for exception handling (esp. double faults) where it's sometimes the only way to do it. Mostly, software task switching is used because it's faster.
Some details and can be found on the wiki: Context_Switching.