gtd setup bochs error
Posted: Thu Nov 30, 2006 9:58 am
Hi,
I am so new in os development area. I am trying to figure out a project (it's due date has passed =). I have a problem about GDT. I am trying to add to new segment descriptors to my gdt table but bochs gives panic (i'am using bochs as emulator). I have taken the code from a web site and try to modify it.
#include <gdt.h>
// Setup a descriptor in the Global Descriptor Table
void gdt_set_descriptor(int index, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran)
{
// Setup the descriptor base address
gdt[index].base_low = (base & 0xFFFF);
gdt[index].base_middle = (base >> 16) & 0xFF;
gdt[index].base_high = (base >> 24) & 0xFF;
// Setup the descriptor limits
gdt[index].limit_low = (limit & 0xFFFF);
gdt[index].granularity = ((limit >> 16) & 0x0F);
//Finally, set up the granularity and access flags
gdt[index].granularity |= (gran & 0xF0);
gdt[index].access = access;
}
// This function will be called by kernel.cpp
void gdt_install(unsigned long csbase,unsigned long limit)
{
/* Setup the GDT pointer and limit */
gp.limit = (sizeof(struct gdt_entry) * 5) - 1;
gp.base = &gdt;
/* Our NULL descriptor */
gdt_set_descriptor(0, 0, 0, 0, 0);
gdt_set_descriptor(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdt_set_descriptor(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
gdt_set_descriptor(3, csbase, limit,0xFA, 0xCF);// GIVES PANIC
gdt_set_descriptor(4, csbase, limit, 0xFA, 0xCF);
/* Flush out the old GDT and install the new changes! */
UpdateGdt(gp.base,gp.limit);
}
UpdateGdt
mov eax, [esp+4]
mov [GDTR+2], eax
mov ax, [esp+8]
mov [GDTR], ax
lgdt [GDTR]
ret
I thought that problem can be about access value or granularity.
Thank you.
I am so new in os development area. I am trying to figure out a project (it's due date has passed =). I have a problem about GDT. I am trying to add to new segment descriptors to my gdt table but bochs gives panic (i'am using bochs as emulator). I have taken the code from a web site and try to modify it.
#include <gdt.h>
// Setup a descriptor in the Global Descriptor Table
void gdt_set_descriptor(int index, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran)
{
// Setup the descriptor base address
gdt[index].base_low = (base & 0xFFFF);
gdt[index].base_middle = (base >> 16) & 0xFF;
gdt[index].base_high = (base >> 24) & 0xFF;
// Setup the descriptor limits
gdt[index].limit_low = (limit & 0xFFFF);
gdt[index].granularity = ((limit >> 16) & 0x0F);
//Finally, set up the granularity and access flags
gdt[index].granularity |= (gran & 0xF0);
gdt[index].access = access;
}
// This function will be called by kernel.cpp
void gdt_install(unsigned long csbase,unsigned long limit)
{
/* Setup the GDT pointer and limit */
gp.limit = (sizeof(struct gdt_entry) * 5) - 1;
gp.base = &gdt;
/* Our NULL descriptor */
gdt_set_descriptor(0, 0, 0, 0, 0);
gdt_set_descriptor(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdt_set_descriptor(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
gdt_set_descriptor(3, csbase, limit,0xFA, 0xCF);// GIVES PANIC
gdt_set_descriptor(4, csbase, limit, 0xFA, 0xCF);
/* Flush out the old GDT and install the new changes! */
UpdateGdt(gp.base,gp.limit);
}
UpdateGdt
mov eax, [esp+4]
mov [GDTR+2], eax
mov ax, [esp+8]
mov [GDTR], ax
lgdt [GDTR]
ret
I thought that problem can be about access value or granularity.
Thank you.