private static void Set_GDT_Gate(GDT_Entries *gdt_entry, uint address, uint limit, byte access, byte granularity) { gdt_entry->BaseLow = (ushort)address; gdt_entry->BaseMiddle = (byte)(address >> 16); gdt_entry->BaseHigh = (byte)(address >> 24); gdt_entry->LimitLow = (ushort)limit; gdt_entry->Granularity = (byte)(limit >> 16); gdt_entry->Granularity |= (byte)(granularity & 0xF0); gdt_entry->Access = access; }
internal static void Setup() { gdt = Heap.kmalloc(46); gdt_entries = (GDT_Entries *)(gdt + 6); Memory.Write16(gdt, (0x8 * 6) - 1); Memory.Write32(gdt + 2, (uint)gdt_entries); Debug.Write("GDT Setup!!\n"); Debug.Write(" Base Address::%d\n", gdt); Set_GDT_Gate(0, 0, 0, 0, 0); // Null segment Set_GDT_Gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment Set_GDT_Gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment Set_GDT_Gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment Set_GDT_Gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment SetupGDT(gdt); }