[MEMORY] GDT
This commit is contained in:
25
kernel/arch/gdt.c
Normal file
25
kernel/arch/gdt.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <gdt.h>
|
||||
#include <stdint.h>
|
||||
#include <debug.h>
|
||||
|
||||
uint64_t gdt[5];
|
||||
struct gdtp_st gdt_p;
|
||||
#define GDT gdt
|
||||
#define GDTP gdt_p
|
||||
|
||||
|
||||
void gdt_init()
|
||||
{
|
||||
|
||||
GDT[0] = 0;
|
||||
GDT[SEG_KCODE/8] = (uint64_t)(GDT_PRESENT | GDT_CODEDATA | GDT_WRITE | GDT_EXECUTE | GDT_64BIT);
|
||||
GDT[SEG_KDATA/8] = (GDT_PRESENT | GDT_CODEDATA | GDT_WRITE);
|
||||
GDT[SEG_UCODE/8] = (GDT_PRESENT | GDT_CODEDATA | GDT_WRITE | GDT_EXECUTE | GDT_64BIT | GDT_RING3);
|
||||
GDT[SEG_UDATA/8] = (GDT_PRESENT | GDT_CODEDATA | GDT_WRITE | GDT_RING3);
|
||||
|
||||
GDTP.len = 5*8-1;
|
||||
GDTP.addr = (uint64_t)&GDT[0];
|
||||
|
||||
load_gdt(&GDTP);
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
.intel_syntax noprefix
|
||||
#include <gdt.h>
|
||||
|
||||
.global load_idt
|
||||
load_idt:
|
||||
@@ -25,3 +26,18 @@ write_cr3:
|
||||
read_cr4:
|
||||
mov rax, cr4
|
||||
ret
|
||||
|
||||
.global load_gdt
|
||||
load_gdt:
|
||||
lgdt [rdi]
|
||||
mov ax, SEG_KDATA
|
||||
mov ss, ax
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
movabs rax, offset .load_gdt
|
||||
pushq SEG_KCODE
|
||||
push rax
|
||||
retfq # perform long jump to SEG_KCODE:.load_gdt
|
||||
.load_gdt:
|
||||
ret
|
||||
|
||||
|
||||
Reference in New Issue
Block a user