reimplements the gdt
This commit is contained in:
23
kernel/arch/gdt/gdt.s
Normal file
23
kernel/arch/gdt/gdt.s
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
gdtr DW 0 ; limit store
|
||||||
|
DD 0 ; base storage
|
||||||
|
|
||||||
|
global setGdt
|
||||||
|
setGdt:
|
||||||
|
mov ax, [esp + 4]
|
||||||
|
mov [gdtr], ax
|
||||||
|
mov eax, [esp + 8]
|
||||||
|
mov [gdtr + 2], eax
|
||||||
|
lgdt [gdtr]
|
||||||
|
ret
|
||||||
|
|
||||||
|
global reloadSegments
|
||||||
|
reloadSegments:
|
||||||
|
jmp 0x08:.reload_CS ; 0x08 is a stand in for the code segment
|
||||||
|
.reload_CS:
|
||||||
|
mov ax, 0x10 ; stand in for the data segment
|
||||||
|
mov ds, ax
|
||||||
|
mov es, ax
|
||||||
|
mov fs, ax
|
||||||
|
mov gs, ax
|
||||||
|
mov ss, ax
|
||||||
|
ret
|
@ -1,10 +1,24 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <kernel/tty.h>
|
#include <kernel/tty.h>
|
||||||
#include <kernel/serial.h>
|
#include <kernel/serial.h>
|
||||||
|
#include <kernel/x86/gdt.h>
|
||||||
|
|
||||||
|
uint64_t gdt[5];
|
||||||
|
|
||||||
void kmain(void)
|
void kmain(void)
|
||||||
{
|
{
|
||||||
|
gdt[0] = create_descriptor(0, 0, 0); // null
|
||||||
|
gdt[1] = create_descriptor(0, 0x000FFFFF, (GDT_CODE_PL0));
|
||||||
|
gdt[2] = create_descriptor(0, 0x000FFFFF, (GDT_DATA_PL0));
|
||||||
|
gdt[3] = create_descriptor(0, 0x000FFFFF, (GDT_CODE_PL3));
|
||||||
|
gdt[4] = create_descriptor(0, 0x000FFFFF, (GDT_DATA_PL3));
|
||||||
|
|
||||||
|
setGdt((sizeof(uint64_t) * 5) - 1, &(gdt[0]));
|
||||||
|
reloadSegments();
|
||||||
|
|
||||||
|
|
||||||
terminal_initialize();
|
terminal_initialize();
|
||||||
serial_initialize();
|
serial_initialize();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user