Code: Select all
[GLOBAL gdt_flush] ; Allows the C code to call gdt_flush().
gdt_flush:
mov eax, [esp+4] ; Get the pointer to the GDT, passed as a parameter.
lgdt [eax] ; Load the new GDT pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax ; Load all data segment selectors
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:.flush ; 0x08 is the offset to our code segment: Far jump!
.flush:
ret
and C
Code: Select all
struct GDT_Entry_type {
u16 lower;
u16 low;
u8 middle;
u8 ring;
u8 granularity;
u8 high;
} __attribute__((packed));
typedef struct GDT_Entry_type GDT_Entry_t;
struct GDT_Pointer_type {
u32 adress;
u16 limit;
} __attribute__((packed));
typedef struct GDT_Pointer_type GDT_Pointer_t;
GDT_Entry_t GDT_Entry[5];
GDT_Pointer_t GDT_Pointer;
// GDT Flush desde asm
extern void gdt_flush(u32);
// GDT crear entrada
void GDT_CreateEntry ( s32 slot, u32 base, u32 limit, u8 ring, u8 granuality ) {
GDT_Entry [slot].low = (base & 0xFFFF);
GDT_Entry [slot].middle = (base >> 16) & 0xFF;
GDT_Entry [slot].high = (base >> 24) & 0xFF;
GDT_Entry [slot].lower = (limit & 0xFFFF);
GDT_Entry [slot].granularity = (limit >> 16) & 0x0F;
GDT_Entry [slot].granularity |= granuality & 0xF0;
GDT_Entry [slot].ring = ring;
}
// Iniciar GDT
void Init_GDT ( void ) { // Iniciar el GDT
VTM_Write ("Iniciando GDT\n");
GDT_Pointer.limit = ( sizeof ( GDT_Entry_t ) * 5 ) - 1;
GDT_Pointer.adress = ( u32 ) &GDT_Entry;
GDT_CreateEntry ( 0, 0, 0, 0, 0 );
GDT_CreateEntry ( 1, 0, 0xFFFFFFFF, 0x9A, 0xCF );
GDT_CreateEntry ( 2, 0, 0xFFFFFFFF, 0x92, 0xCF );
GDT_CreateEntry ( 3, 0, 0xFFFFFFFF, 0xFA, 0xCF );
GDT_CreateEntry ( 4, 0, 0xFFFFFFFF, 0xF2, 0xCF );
gdt_flush((u32)&GDT_Pointer);
VTM_Write ("GDT Iniciado\n");
}
It doesn't write VTM_Write ("GDT Iniciado\n");
any help?