x86: add GDT and IDT
Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
parent
f10e3f31d7
commit
e5b55a6ba5
25 changed files with 1211 additions and 13 deletions
40
amd64/init/gdt.c
Normal file
40
amd64/init/gdt.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/common.h>
|
||||
|
||||
#include "descriptor.h"
|
||||
#include "../arch/reg.h"
|
||||
|
||||
static size_t gdt_index = 0;
|
||||
|
||||
void gdt_insert(uint8_t offset, uint8_t access, uint8_t flags)
|
||||
{
|
||||
struct gdt_desc *desc = (__gdt + offset);
|
||||
desc->limit = 0;
|
||||
desc->base = 0;
|
||||
desc->base_2 = 0;
|
||||
desc->base_3 = 0;
|
||||
|
||||
desc->access = access;
|
||||
desc->flags = flags;
|
||||
gdt_index++;
|
||||
}
|
||||
|
||||
void gdt_init()
|
||||
{
|
||||
gdt_insert(0, 0, 0);
|
||||
gdt_insert(1, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(2, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(3, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(4, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(5, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(6, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(7, GDT_ACCESS_DATA_RING3, 0xC0);
|
||||
gdt_insert(8, GDT_ACCESS_CODE_RING3, 0xA0);
|
||||
|
||||
__gdtr.size = (sizeof(__gdt) - 1);
|
||||
__gdtr.offset = (uint64_t)__gdt;
|
||||
|
||||
lgdt();
|
||||
|
||||
krdy("GDT initialized\n");
|
||||
}
|
||||
Loading…
Reference in a new issue