Code: Select all
//In gdtc.h
#include <stdint.h>
typedef struct {
uint16_t lLimit;
uint16_t lBase;
uint8_t mBase;
uint8_t access;
uint8_t granularity;
uint8_t hBase;
} gdtEntry_t;
struct {
uint16_t limit;
uint32_t base;
} gdtPointer;
extern void loadGdt();
void setupGdt();
//In gdtc.c
#include "gdtc.h"
gdtEntry_t gdt[3];
void gdtSetGate(int num, uint64_t base, uint64_t limit, uint8_t access,
uint8_t gran){
gdt[num].lBase = (base & 0xFFFF);
gdt[num].mBase = (base >> 16) & 0xFF;
gdt[num].hBase = (base >> 24) & 0xFF;
gdt[num].lLimit = (limit & 0xFFFF);
gdt[num].granularity = ((limit >> 16) & 0x0F);
gdt[num].granularity |= (gran & 0xF0);
gdt[num].access = access;
}
void setupGdt(){
gdtPointer.limit = (sizeof(gdtEntry_t) * 3) - 1;
gdtPointer.base = &gdt;
gdtSetGate(0, 0, 0, 0, 0);
gdtSetGate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdtSetGate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
loadGdt();
}
//And in gdtaglobal loadGdt
extern gdtPointer
loadGdt:
lgdt[gdtPointer]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:fload
fload:
ret.asm
Code: Select all
gdtc.c:21:19: warning: assignment makes integer from pointer without a cast
gdtPointer.base = &gdt;
Then I changed that line to:
Code: Select all
gdtPointer.base = (uint32_t*) *gdt;
Code: Select all
gdtc.c:21:2: error: cannot convert to a pointer type
gdtPointer.base = (uint32_t*) *gdt;