LDT and TSS

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
anon19287473
Member
Member
Posts: 97
Joined: Thu Mar 15, 2007 2:27 pm

LDT and TSS

Post 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
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 »

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.
"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 ]
anon19287473
Member
Member
Posts: 97
Joined: Thu Mar 15, 2007 2:27 pm

Post 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?
urxae
Member
Member
Posts: 149
Joined: Sun Jul 30, 2006 8:16 am
Location: The Netherlands

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