Code: Select all
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran){
gdt[num].base_low = (base & 0xFFFF);
gdt[num].base_middle = (base >> 16) & 0xFF;
gdt[num].base_high = (base >> 24) & 0xFF;
gdt[num].limit_low = (limit & 0xFFFF);
gdt[num].granularity = ((limit >> 16) & 0x0F);
gdt[num].granularity |= (gran & 0xF0);
gdt[num].access = access;
}
//....
gdt_set_gate(0, 0, 0, 0, 0);
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
gdt_set_gate(3, 0, 0xFFFFF, 0x9a, 0x00);
gdt_set_gate(4, 0, 0xFFFFF, 0x92, 0x00);
gdt_set_gate(5, 0x50000, 0x40000, 0x92, 0x40); //Stack...
The segment has to map the memory from 0x50000 up to 0x90000. Why this code doesn't work?
EDIT: This code updates my segments
Code: Select all
global _gdt_flush
extern _gp
_gdt_flush:
lgdt [_gp]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ax, 0x30
mov ss, ax
sub esp, 0x50000
jmp 0x08:flush2
flush2:
ret