#include
static gdt_t ALIGN(PAGE_SIZE) gdt;
static gdt_ptr_t ALIGN(PAGE_SIZE) gdt_ptr;
void gdt_set_entry(uint32_t index, addr_t base, uint32_t limit, uint32_t type)
{
gdt_entry_t *g = &(gdt.entries[index]);
g->limit_low = (limit / 4096) & 0xffff;
g->limit_high = ((limit / 4096) >> 16) & 0xf;
g->base_low = base & 0xffff;
g->base_high1 = (base >> 16) & 0xff;
g->base_high2 = (base >> 24) & 0xff;
g->type = type;
if (type != 0)
g->flags = GDT_GRAN_4K | GDT_MODE_32;
}
void dump_gdt(gdt_ptr_t *ptr)
{
gdt_t *val = (gdt_t*)ptr->base;
int i;
for(i=0; ilimit / sizeof(gdt_entry_t); i++)
{
uint8_t *v =(uint8_t *)&val->entries[i];
int j;
for(j=0; j
KPRINTF("%02X", *v);
KPRINTF(" ");
KPRINTF("%01X%04X|", val->entries[i].limit_high, val->entries[i].limit_low);
KPRINTF("%02X%02X%04X|", val->entries[i].base_high2, val->entries[i].base_high1, val->entries[i].base_low);
KPRINTF("%02X|", val->entries[i].type);
KPRINTF("%01X\n", val->entries[i].flags);
}
}
static void gdt_init()
{
KPRINTF("gdt_init\n");
gdt_ptr_t *ptr = &gdt_ptr;
/* Setup GDT entries. */
gdt_set_entry(GDT_NULL , 0, 0, 0);
gdt_set_entry(GDT_KERNEL_CS , 0, 0xffffffff, GDT_TYPE_CODE0);
gdt_set_entry(GDT_KERNEL_DS , 0, 0xffffffff, GDT_TYPE_DATA0);
gdt_set_entry(GDT_USER_CS , 0, 0xffffffff, GDT_TYPE_CODE3);
gdt_set_entry(GDT_USER_DS , 0, 0xffffffff, GDT_TYPE_DATA3);
gdt_set_entry(GDT_TSS , (addr_t)tss_get(), sizeof(tss_t), GDT_TYPE_TSS0);
/* Set GDT pointer. */
ptr->base = (addr_t) &gdt;
ptr->limit = sizeof(gdt_t);
/* Load the GDT. */
load_gdt(&gdt_ptr);
}
INITFUNC(gdt_init, INIT_GDT);
阅读(1154) | 评论(0) | 转发(0) |