40 lines
909 B
C
40 lines
909 B
C
/* 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");
|
|
}
|