What's new

Ldt

blueshogun96

A lowdown dirty shame
It's been a while since I've posted, great to be back :)

Anyway, I'm just wondering if anyone familiar with LDT might know an alternative to using LDT (for 64-bit windows)? For those who don't know what LDT is/does here's a wiki on it: Local Descriptor Table - Wikipedia, the free encyclopedia

TBH, LDT is still rather new to me (I never actually heard of it until sometime in August of last year). Any ideas are appreciated. :*
 

Exophase

Emulator Developer
What is it that you want to do exactly? Do you want to define segments to make regions of memory only visible via certain segment overrides like VMWare does it? x86-64 still has lldt, but I remember reading something about how VMWare in 64bit Windows couldn't use the same approach. I don't remember the details though (it could have to do with OS changes)

Maybe you could explain a little more what you'd like to do with this.
 

Cyberman

Moderator
Moderator
I believe this is something from before this generation of processors IE before the 386 286 series it appears. This is the series you had to RESET (IE club the processor over the head) to switch between protected and real mode.

I think if you can find anything about Extended memory you might find more about it.

Cyb
 
OP
blueshogun96

blueshogun96

A lowdown dirty shame
I'm trying to add a little update for Cxbx. In 64-bit windows, the function NtSetLdtEntries always fails. Here's the function that calls this:

Code:
// ******************************************************************
// * func: EmuAllocateLDT
// ******************************************************************
uint16 EmuAllocateLDT(uint32 dwBaseAddr, uint32 dwLimit)
{
    NtDll::LDT_ENTRY LDTEntry;

    int x=0;

    EnterCriticalSection(&EmuLDTLock);

    // ******************************************************************
    // * Locate a free LDT entry
    // ******************************************************************
    {
        for(x=0;x<MAXIMUM_XBOX_THREADS;x++)
            if(FreeLDTEntries[x])
                break;

        if(x == MAXIMUM_XBOX_THREADS)
        {
            LeaveCriticalSection(&EmuLDTLock);

			CxbxKrnlCleanup("Could not locate free LDT entry (too many threads?)");

            return 0;
        }
    }

    // ******************************************************************
    // * Set up selector information
    // ******************************************************************
    {
        LDTEntry.BaseLow                    = (WORD)(dwBaseAddr & 0xFFFF);
        LDTEntry.HighWord.Bits.BaseMid      = (dwBaseAddr >> 16) & 0xFF;
        LDTEntry.HighWord.Bits.BaseHi       = (dwBaseAddr >> 24) & 0xFF;
	    LDTEntry.HighWord.Bits.Type         = 0x13; // RW data segment
	    LDTEntry.HighWord.Bits.Dpl          = 3;    // user segment
	    LDTEntry.HighWord.Bits.Pres         = 1;    // present
	    LDTEntry.HighWord.Bits.Sys          = 0;
	    LDTEntry.HighWord.Bits.Reserved_0   = 0;
	    LDTEntry.HighWord.Bits.Default_Big  = 1;    // 386 segment
	    LDTEntry.HighWord.Bits.Granularity  = (dwLimit >= 0x00100000) ? 1 : 0;

        if(LDTEntry.HighWord.Bits.Granularity)
            dwLimit >>= 12;

        LDTEntry.LimitLow                   = (WORD)(dwLimit & 0xFFFF);
	    LDTEntry.HighWord.Bits.LimitHi      = (dwLimit >> 16) & 0xF;
    }

    // ******************************************************************
    // * Allocate selector
    // ******************************************************************
    {
        using namespace NtDll;

        // Problem resides right here!
        if(!NT_SUCCESS(NtDll::NtSetLdtEntries((x*8)+7+8, LDTEntry, 0, LDTEntry)))
        {
            LeaveCriticalSection(&EmuLDTLock);

	    CxbxKrnlCleanup("Could not set LDT entries");

            return 0;
        }
    }

    LeaveCriticalSection(&EmuLDTLock);

    FreeLDTEntries[x] = 0;

    return (x*8)+7+8;
}

Basically I just wanted to make a work around for this problem so that Cxbx will run in a 64-bit OS. That's basically it. I'm still learning exactly what LDT is and how it works. I've been too busy to actually read the whole documentation on it lately... :(
 

Exophase

Emulator Developer
Sorry, if Windows doesn't offer it then there's really no way to emulate this kind of functionality. The only possible alternative is if you can go around the OS and use lldt directly; however, even if you do this, there's little saying that 64bit Windows will even use LDTs to begin with (and if it doesn't let you modify them anymore I doubt it does). Normally LDTs would be switched along with a context switch, but if the OS uses software context switching as opposed to TSS's there's no reason why it has to do this, and even if it does use TSS's there's no reason why it has to give unique LDTs per process.
 

Cyberman

Moderator
Moderator
LOL I'm getting old (Seriously) or I need more sleep sorry not completely on target with my remark. OH well.
 

Top