Page 1 of 1

Ned some help with the GDT

Posted: Thu Jun 07, 2007 12:18 am
by Pyrofan1
I understand what the GDT is for, but I'm not exactly sure how to create one.
I've come up with this code
gdt.h

Code: Select all

extern unsigned char gdt[4]

void fill_gdt(void)
{
	unsigned char gdt[4];
	gdt[0]=0x00;
	gdt[1]=0x9A;
	gdt[2]=0x92;
	gdt[3]=0x00;
}

extern void _list_gdt(void);
gdt.s

Code: Select all

.global _list_gdt
.global gdt

.type _list_gdt,@function
_list_gdt:
	lgdt $(gdt)
	ret
But i'm almost %100 sure that this code won't work. How can I fix it?

Posted: Thu Jun 07, 2007 5:23 am
by Combuster
the gdt is an array of descriptors. each gdt descriptor is 8 bytes, and you need at least three: null, code and data.

For the exact format, refer to the intel manuals

Posted: Thu Jun 07, 2007 8:30 am
by JAAman
yes, this is exactly where the intel manuals are invaluable -- become very familier with them (the information you need is in 3A:3.4.5, the associated diagram shows the GDT entries very clearly, as 2 32bit fields)

Posted: Thu Jun 07, 2007 10:40 am
by xyjamepa
Hi...
try this it might helphttp://osdever.net/bkerndev/Docs/intro.htm