Implemented GDT initialisation

This commit is contained in:
2022-12-24 10:28:41 +00:00
parent 0c0830cca7
commit 26853c32c8
10 changed files with 129 additions and 3 deletions

27
arch/x86_64/gdt.c Normal file
View File

@@ -0,0 +1,27 @@
#include <socks/libc/string.h>
#include <socks/machine/_gdt.h>
static void init_entry(struct gdt_entry *entry, int access, int flags)
{
entry->ge_limit_low = 0xFFFF;
entry->ge_base_low = 0x00;
entry->ge_base_mid = 0x00;
entry->ge_access = access;
entry->ge_gran = flags;
entry->ge_base_hi = 0x00;
}
int gdt_init(struct gdt *gdt, struct gdt_ptr *gdtp)
{
memset(&gdt->g_entries[0], 0x0, sizeof gdt->g_entries[0]);
init_entry(&gdt->g_entries[1], GDT_A_PRESENT | GDT_A_CODEREAD | GDT_A_CODE, GDT_F_64BIT);
init_entry(&gdt->g_entries[2], GDT_A_PRESENT | GDT_A_DATAWRITE | GDT_A_DATA, GDT_F_64BIT);
init_entry(&gdt->g_entries[3], GDT_A_PRESENT | GDT_A_USER | GDT_A_CODEREAD | GDT_A_CODE, GDT_F_64BIT);
init_entry(&gdt->g_entries[4], GDT_A_PRESENT | GDT_A_USER | GDT_A_DATAWRITE | GDT_A_DATA, GDT_F_64BIT);
gdtp->g_ptr = (uint64_t)gdt;
gdtp->g_limit = sizeof(*gdt) - 1;
return 0;
}