Move BootGDT definition to C

This commit is contained in:
Thomas Lovén 2018-02-16 12:38:25 +01:00
parent 3508b182b7
commit 04f2123499
4 changed files with 30 additions and 22 deletions

View File

@ -43,7 +43,7 @@ _start:
mov cr0, eax
//; Load a new GDT
lgdt [V2P(BootGDTp)]
lgdt [V2P(GDTp)]
//; and update the code selector by a long jump
jmp 0x8:V2P(long_mode_start)
@ -76,7 +76,7 @@ upper_memory:
mov cr3, rax
//; Reload GDT
movabs rax, offset BootGDTp
movabs rax, offset GDTp
lgdt [rax]
mov rax, 0x0
mov ss, rax

View File

@ -1,14 +0,0 @@
#include <gdt.h>
#include <memory.h>
.intel_syntax noprefix
.section .rodata
.align PAGE_SIZE
.global BootGDT
.global BootGDTp
BootGDT:
.long 0, 0
.long 0, (GDT_PRESENT | GDT_DPL(0) | GDT_CODE | GDT_LONG)
BootGDTp:
.short 2*8-1
.quad offset BootGDT

28
src/kernel/cpu/gdt.c Normal file
View File

@ -0,0 +1,28 @@
#include <stdint.h>
#include <cpu.h>
#define GDT_CODE (3<<11)
#define GDT_DPL(lvl) ((lvl)<<13)
#define GDT_PRESENT (1<<15)
#define GDT_LONG (1<<21)
struct gdt
{
uint32_t _;
uint32_t flags;
}__attribute__((packed));
struct gdtp
{
uint16_t len;
struct gdt *gdt;
}__attribute__((packed));
struct gdt BootGDT[] = {
{0, 0},
{0, GDT_PRESENT | GDT_DPL(0) | GDT_CODE | GDT_LONG}
};
struct gdtp GDTp = {2*8-1, BootGDT};

View File

@ -1,6 +0,0 @@
#pragma once
#define GDT_CODE (3<<11)
#define GDT_DPL(lvl) ((lvl)<<13)
#define GDT_PRESENT (1<<15)
#define GDT_LONG (1<<21)