separating: there will be libk and libc
This commit is contained in:
44
kernel/gdt.c
Normal file
44
kernel/gdt.c
Normal file
@@ -0,0 +1,44 @@
|
||||
// Global descriptor table setup
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https://github.com/xamidev/blankos
|
||||
|
||||
#include "gdt.h"
|
||||
#include "../libk/stdio.h"
|
||||
|
||||
struct gdt_entry gdt[3];
|
||||
struct gdt_ptr gp;
|
||||
|
||||
extern void gdt_flush();
|
||||
|
||||
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran)
|
||||
{
|
||||
gdt[num].base_low = (base & 0xFFFF);
|
||||
gdt[num].base_middle = (base >> 16) & 0xFF;
|
||||
gdt[num].base_high = (base >> 24) & 0xFF;
|
||||
|
||||
gdt[num].limit_low = (limit & 0xFFFF);
|
||||
gdt[num].granularity = ((limit >> 16) & 0x0F);
|
||||
|
||||
gdt[num].granularity |= (gran & 0xF0);
|
||||
gdt[num].access = access;
|
||||
}
|
||||
|
||||
void gdt_install()
|
||||
{
|
||||
gp.limit = (sizeof(struct gdt_entry)*3) - 1;
|
||||
gp.base = (unsigned int)&gdt;
|
||||
|
||||
gdt_set_gate(0, 0, 0, 0, 0);
|
||||
|
||||
// Ring 0 code + data
|
||||
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
|
||||
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
|
||||
|
||||
// Ring 3
|
||||
//gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);
|
||||
//gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);
|
||||
|
||||
gdt_flush();
|
||||
printf("[kernel] GDT gates set (ring 0), gdt=0x%x\n", (unsigned int)&gdt);
|
||||
}
|
||||
Reference in New Issue
Block a user