Page 1 of 1

TSS GDT Gate

Posted: Fri Feb 24, 2006 7:37 pm
by 0xBADC0DE
Is my code for my TSS GDT Gate good?

Code: Select all


struct KeGDTEntry gdte[6];
struct KeGDTPtr gdt;




void KeGDTSetGate(int num, unsigned long base, unsigned long limit, unsigned char access,unsigned char gran)
{
   gdte[num].base_low = (base & 0xFFFF);
   gdte[num].base_middle = (base >> 16) & 0xFF;
   gdte[num].base_high = (base >> 24) & 0xFF;
   gdte[num].limit_low = (limit & 0xFFFF);
   gdte[num].granularity = ((limit >> 16) & 0x0F);
   gdte[num].granularity |= (gran & 0xF0);
   gdte[num].access = access;
}

void KeGDTSetTSS(int num)
{
   gdte[num].base_low = 0;
   gdte[num].base_middle=0;
   gdte[num].base_high=0;
   gdte[num].limit_low = 103;
   gdte[num].access = 0x89;
   gdte[num].granularity = 0;

}

void KeGDTInstall()
{
   gdt.limit = (sizeof(struct KeGDTEntry)*6) - 1;
   gdt.base = (unsigned int)&gdte;

   /* [0x00] */   KeGDTSetGate(0,0,0,0,0);
   /* [0x08] */   KeGDTSetGate(1,0,0xFFFFFFFF,0x9A,0xCF); // Ring0 CS
   /* [0x10] */   KeGDTSetGate(2,0,0xFFFFFFFF,0x92,0xCF); // Ring0 DS
   /* [0x18] */   KeGDTSetTSS(3);
   /* [0x20] */   KeGDTSetGate(4,0,0xFFFFFFFF,0xFA,0xCF); // Ring3 CS
   /* [0x28] */   KeGDTSetGate(5,0,0xFFFFFFFF,0xF2,0xCF); // Ring3 DS

   KeSetGDT();
}

Re:TSS GDT Gate

Posted: Sat Feb 25, 2006 6:00 am
by Pype.Clicker
i don't see why you call them "gates": CS and DS are loaded with _segments_, not gates.

I think you should read about TSSes again too: a TSS typically _do_ have a base address so i don't see why you load it with 0 by default.

Re:TSS GDT Gate

Posted: Sat Feb 25, 2006 3:54 pm
by 0Scoder
yes, like pype said you need to change the naming for your functions. Also, seen as the 'gate' code you use seems to be for segments, you will also need a function for adding gate descriptors.