Commit 9cca56a9 by malcolm

Fixed up GDT files

parent eecc296c
Showing with 18 additions and 18 deletions
#include "gdt.h" #include "gdt.h"
#include "string.h"
struct gdtr{ typedef struct{
uint16_t limit; uint16_t limit;
uint32_t base; uint32_t base;
} }gdtr;
static struct gdt_desc _gdt [MAX_GDT_DESC]; static gdt_desc _gdt [MAX_GDT_DESC];
static struct gdtr _gdtr; static gdtr _gdtr;
static void gdt_install () { static void gdt_install () {
//TODO: VOODOO MAGIC //TODO: VOODOO MAGIC
...@@ -16,33 +16,33 @@ void gdt_set_desc(uint32_t i, uint64_t base, uint64_t limit, uint8_t access, uin ...@@ -16,33 +16,33 @@ void gdt_set_desc(uint32_t i, uint64_t base, uint64_t limit, uint8_t access, uin
{ {
if (i > MAX_GDT_DESC) if (i > MAX_GDT_DESC)
return; return;
memset ((void*)&_gdt[i], 0, sizeof (gdt_descriptor)); memset ((void*)&_gdt[i], 0, sizeof (gdt_desc));
_gdt[i].low_base = uint16_t(base & 0xffff); _gdt[i].low_base = (uint16_t)(base & 0xffff);
_gdt[i].mid_base = uint8_t((base >> 16) & 0xff); _gdt[i].mid_base = (uint8_t)((base >> 16) & 0xff);
_gdt[i].high_base= uint8_t((base >> 24) & 0xff); _gdt[i].high_base = (uint8_t)((base >> 24) & 0xff);
_gdt[i].lim = uint16_t(limit & 0xffff); _gdt[i].lim = (uint16_t)(limit & 0xffff);
//! set flags and grandularity bytes //! set flags and grandularity bytes
_gdt[i].flags = access; _gdt[i].flags = access;
_gdt[i].gran = uint8_t((limit >> 16) & 0x0f); _gdt[i].gran = (uint8_t)((limit >> 16) & 0x0f);
_gdt[i].gran |= gran & 0xf0; _gdt[i].gran |= gran & 0xf0;
} }
gdt_descriptor* i86_gdt_get_descriptor (int i) { gdt_desc* gdt_get_desc (int i) {
if (i > MAX_GDT_DESC) if (i > MAX_GDT_DESC)
return 0; return 0;
return &_gdt[i]; return &_gdt[i];
} }
int i86_gdt_initialize () { int i86_gdt_initialize () {
_gdtr.limit = (sizeof (struct gdt_desc) * MAX_GDT_DESC)-1; _gdtr.limit = (sizeof (gdt_desc) * MAX_GDT_DESC)-1;
_gdtr.base = (uint32_t)&_gdt[0]; _gdtr.base = (uint32_t)&_gdt[0];
//null //null
gdt_set_descriptor(0, 0, 0, 0, 0); gdt_set_desc(0, 0, 0, 0, 0);
//code //code
gdt_set_descriptor (1,0,0xffffffff, GDT_RW|GDT_EXE|GDT_CDT|GDT_MEM, GDT_GR_PG|GDT_GR_32|GDT_GR_HI); gdt_set_desc(1,0,0xffffffff, GDT_RW|GDT_EXE|GDT_CDT|GDT_MEM, GDT_GR_PG|GDT_GR_32|GDT_GR_HI);
//data //data
gdt_set_descriptor (2,0,0xffffffff, GDT_RW|GDT_CDT|GDT_MEM, GDT_GR_PG|GDT_GR_32|GDT_GR_HI); gdt_set_desc(2,0,0xffffffff, GDT_RW|GDT_CDT|GDT_MEM, GDT_GR_PG|GDT_GR_32|GDT_GR_HI);
gdt_install(); gdt_install();
return 0; return 0;
} }
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
#define GDT_GR_32 0x40 #define GDT_GR_32 0x40
#define GDT_GR_PG 0x80 #define GDT_GR_PG 0x80
struct gdt_desc { typedef struct{
uint16_t lim; uint16_t lim;
uint16_t low_base; uint16_t low_base;
uint8_t mid_base; uint8_t mid_base;
uint8_t flags; uint8_t flags;
uint8_t gran; uint8_t gran;
uint8_t high_base; uint8_t high_base;
}; } gdt_desc;
extern void gdt_set_desc(uint32_t i, uint64_t base, uint64_t limit, uint8_t access, uint8_t gran); extern void gdt_set_desc(uint32_t i, uint64_t base, uint64_t limit, uint8_t access, uint8_t gran);
extern gdt_desc* gdt_get_desc(int i); extern gdt_desc* gdt_get_desc(int i);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment