LDT uses

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

LDT uses

Post by Hangin10 »

What would some uses of the LDT be?
And don't just say "none" because new stuff should use Long Mode. :P

At first I thought maybe being able to run everything in ring 0, making the segments not
include kernel space. But then I realized that can just as easily be done with the GDT (assuming
paging gives all the segments the same address space and all that's needed is different base/limits
for kernel vs. apps/drivers).

Were they useful for making lists of call gates different for each process?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: LDT uses

Post by Troy Martin »

Wikipedia wrote:The LDT is the sibling of the Global Descriptor Table and similarly defines up to 8191 memory segments accessible to programs.

On x86 processors not having paging features, like the Intel 80286, the LDT is essential to implementing separate address spaces for multiple processes. There will be generally one LDT per user process, describing privately held memory, while shared memory and kernel memory will be described by the GDT. The operating system will switch the current LDT when scheduling a new process, using the LLDT machine instruction. On the contrary, the GDT is generally not switched (although this may happen if virtual machine monitors like VMware are running on the computer).
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

Re: LDT uses

Post by Hangin10 »

:oops: doh.

So it's just a holder from when segmentation was important?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: LDT uses

Post by Troy Martin »

Looks like it! I guess you could use it as an alternative to TSSes or something.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
kasper
Posts: 19
Joined: Sun Apr 27, 2008 7:59 am
Location: The Netherlands, Amersfoort
Contact:

Re: LDT uses

Post by kasper »

Hi all,
Hangin10 wrote:What would some uses of the LDT be?
  • Perhaps you can use them to share some memory between processes. The shared memory can contain pointers, which point to other parts in the shared segment. The shared memory doesn't have to have the same virtual address, since each process can use its own segment selector in the segment register.

    But I'm not sure if this is useful or that allocating a virtual address range free in all sharing processes is never a problem. What do others advise?
  • The [tt]limit[/tt] part of LDT entries allows more fine grained control over what memory you share than 4k pages do.
  • Hangin10 wrote:Were they useful for making lists of call gates different for each process?
    Good idea, you can use them for that. Would it be wise to do so?
Kasper
Last edited by kasper on Sun Dec 28, 2008 6:02 am, edited 1 time in total.
User avatar
kasper
Posts: 19
Joined: Sun Apr 27, 2008 7:59 am
Location: The Netherlands, Amersfoort
Contact:

Re: LDT uses

Post by kasper »

Hi again,

I noticed an other use for LDT in the topic L4's hidden secret, started by kiwipresse.
Brendan wrote:[...]
kiwipresse wrote:I'm just wondering why L4 is considered to be so efficient instead of other microkernels? I read the wikipedia article which suggests that they use some fancy IPC and optimize here and there. Does somebody know something more concretly before I dig into sources :?
There's at least 2 techniques that L4 uses that I'm aware of...

The first one is called "small address spaces". The idea here is to use segmentation to split a large address space into a medium address space and several small address spaces; so you can switch from one process to another by changing segment registers if both processes are in the same large address space, which reduces TLB misses because there's no need to flush any TLB entries in this case. For example, the large 4 GiB address space might be split into one 2 GiB medium address space and eight 128 MiB small address spaces (with the remaining 1 GiB used by the kernel). Also, if a process is running in a small address space and grows too big it'll be shifted into it's own medium address space, so that processes aren't limited to the size of a small address space.
[...]
Kasper
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: LDT uses

Post by Love4Boobies »

LDTs are dropped on 64-bit modes (in fact, segmentation is dropped altogether). Also, as I've said on the topic you're quoting, L4 can't be ported to 64 bits since it is tied to segmentation in order to reduce the number of TLB flushes.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: LDT uses

Post by Brendan »

Hi,
Love4Boobies wrote:LDTs are dropped on 64-bit modes (in fact, segmentation is dropped altogether).
That's actually a fairly common misconception.

In long mode, you can have 64-bit code, 32-bit code and 16-bit code (just like in protected mode you can have 32-bit code and 16-bit code). All segmentation is still used for 32-bit code and 16-bit code - the only real difference is the GDT and LDT entry format used for these segments (the base address is extended to 64-bit). Also, FS and GS are still used for 64-bit code (the base addresses of these segments are honoured, but the segments limits are ignored). The LDT can still be used in long mode too.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: LDT uses

Post by Love4Boobies »

I don't have time to go through the manuals now (since I'm not at home) but is that only true for the compatibility mode?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: LDT uses

Post by Brendan »

Hi,
Love4Boobies wrote:I don't have time to go through the manuals now (since I'm not at home) but is that only true for the compatibility mode?
In long mode, the code segment is either 64-bit, 32-bit or 16-bit. If the code segment is 64-bit then you're in "64-bit mode" (most segmentation disabled), and if the code segment is 32-bit or 16-bit then you're in "compatibility mode" (all segmentation enabled). All of these modes are described as "sub-modes" in AMD's manual - you'd still be in "long mode" regardless of the what sort of code segment you use (same paging structures, same GDT/LDT entries, same IDT entries, same TSS, same lack of virtual80x86, etc).

This is one thing I'm planning to take serious advantage of. If device drivers run as separate CPL=3 processes, then all 32-bit device drivers can be run under both 32-bit kernels and 64-bit kernels; which means that for a large number of device drivers there's no need for me to provide 64-bit device drivers.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply