My current GDT code:
Code: Select all
#include "include/gdt.h"
void set_gdt_entry(int num, unsigned long base,unsigned long limit, unsigned char access, unsigned char gran)
{
gdt[num].base=(base & 0xFFFF); /* lowest 2 bytes of base */
gdt[num].base_middle=(base >> 16) & 0xFF; /* third third byte */
gdt[num].base_high=(base >> 24 ) & 0xFF; /* highest byte */
gdt[num].limit=(limit & 0xFFFF); /* lowest 2 bytes of limit */
gdt[num].granularity=((limit >> 16) & 0x0F); /* 1 byte */
gdt[num].granularity|=(gran & 0xF0); /* 1 byte */
gdt[num].access=access;
}
gp.base=(unsigned int)&gdt; /* set base address to our descriptor table */
gp.limit=(sizeof(struct gdt_entry) * 3)-1; /* (size of our gdt table)-1 */
/* NULL descriptor table - CPU needs it */
set_gdt_entry(0,0,0,0,0);
set_gdt_entry(1,0x0,0xFFFFF,0x9A,0xC0);
set_gdt_entry(2,0x0,0xFFFFF,0x92,0xC0);
gdt_flush();
thanks