Ned some help with the GDT

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Ned some help with the GDT

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post 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)
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Hi...
try this it might helphttp://osdever.net/bkerndev/Docs/intro.htm
Post Reply