Code: Select all
typedef struct s_entree_GDT
{
unsigned short limit15_00;
unsigned short base15_00;
unsigned char base23_16;
unsigned char type;
unsigned char type_util;
unsigned char base31_24;
} t_entree_gdt;
// La GDT peut avoir au plus 8192 segments...
//struct s_entree_GDT GDT[128];
t_entree_gdt GDT[128];
// Fonction permettant de charger la GDT (page 3-8)
void _lgdt(void * base, unsigned long limit)
{
unsigned long i[2];
i[0] = limit << 16;
i[1] = (unsigned long) base;
print("\n");
__asm__ __volatile__ ("lgdt (%0)": :"p" (((char *) i)+2));
print("GDT charg?e\n");
asm volatile("jmp reinit_cs\n \
reinit_cs:\n \
movl $0x10,%eax\n \
movw %ax,%ds\n \
movw %ax,%es\n \
movw %ax,%fs\n \
movw %ax,%gs\n \
movw %ax,%ss\n");
}
/**
* D?finit un descripteur de la GDT
**/
void set_gdt_desc(int num, long base, long limite, char G, char DB, char AVL,
char present, char DPL, char S, char t)
{
// CF page 3-10 du tome 3 du IA-32 Intel Architecture Software Developer's Manual.
GDT[num].limit15_00 = limite & 0xFFFF;
GDT[num].base15_00 = base & 0xFFFF;
GDT[num].base23_16 = (base >> 16) & 0xFF;
GDT[num].type = t & 0xF | ((present * 0x8 + DPL * 2 + S)<<8)&0xF0;
GDT[num].type_util = (limite >> 16) & 0xF + ((AVL + DB*4 + G*8)<<8)&0xF0;
GDT[num].base31_24 = (base >> 24) & 0xFF;
}
void init_gdt(void)
{
set_gdt_desc(0,0,0,0,0,0,0,0,0,0);
/* Le bouquin Intel est clair : le 1er descripteur
* doit ?tre enti?rement ? 0. D'o? cette ligne.
*/
set_gdt_desc(1,0,0xFFFFF,1,1,0,1,1,1,0xB); // CS
set_gdt_desc(2,0,0xFFFFF,1,1,0,1,1,1,0x7); // DS
_lgdt(GDT,0x3FF);
}
Thanks.
Damien Szczyt