Code: Select all
asm("lgdtl (gdt_ptr)");
asm(" movw $0x10, %ax \n \
movw %ax, %ds \n \
movw %ax, %es \n \
movw %ax, %fs \n \
movw %ax, %gs \n \
ljmp $0x08, $next \n \
next: \n");
It is likely that the compiler is shuffling things around.
Merge these two
asm statements as one, like this:
Code: Select all
__asm__ __volatile__("lgdtl (gdt_ptr)\n \
movw $0x10, %ax \n \
movw %ax, %ds \n \
movw %ax, %es \n \
movw %ax, %ss \n \ \\ You ommited this line. Looks fine in your initial post
movw %ax, %fs \n \
movw %ax, %gs \n \
ljmp $0x08, $next \n \
next: \n");
You seem to ignore both
os64dev's and
Combuster's advice.
Here's another source of error:
Code: Select all
void gdt_set_gate(int num, u32_int base, u32_int limite, u8_int access, u8_int gran)
{
gdt_entries[num].base_low = (base & 0xFFFF);
gdt_entries[num].base_middle = (base >> 16) & 0xFF;
gdt_entries[num].base_hight = (base >> 24) & 0xFF;
gdt_entries[num].limite_low = (limite & 0xFFFF);
gdt_entries[num].granularity = (limite >> 16) & 0x0F;
gdt_entries[num].granularity |= gran & 0xF0;
gdt_entries[num].access = access;
}
It seems as if you're treating
gdt_entries as an array without first declaring it as an array.
Here's the change required:
Code: Select all
struct struct_entry_gdt
{
u16_int limite_low;
u16_int base_low;
u8_int base_middle;
u8_int base_hight;
u8_int access;
u8_int granularity;
} __attribute__((packed));
typedef struct struct_entry_gdt gdt_entry_t[5]; // Can hold 5 entries now.
struct gdt_ptr_struct
{
u16_int limite;
u32_int base;
} __attribute__((packed));
typedef struct gdt_ptr_struct gdt_ptr_t;
And oh!, you don't need to copy your descriptor tables to somewhere else. If you worry about overwriting your GDT, copy it to some safe location(and not 0x0, because real mode IVT resides there). And remember to update your
gdt_base.ptr to point to your new GDT location(As I said before).
Best Regards,
Chandra