forked from CHatingPython/towos
feat: load GDT
This commit is contained in:
+50
-8
@@ -1,15 +1,57 @@
|
||||
using u8 = unsigned char;
|
||||
using u16 = unsigned short;
|
||||
using u32 = unsigned int;
|
||||
using u64 = unsigned long long;
|
||||
#include "gdt.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
static volatile u16* const s_vga = reinterpret_cast<volatile u16*>(0xB8000);
|
||||
|
||||
extern "C" void kmain() {
|
||||
const char* msg = "Zdravstvuyte, tovorisch!";
|
||||
static constexpr u8 VGA_ROWS = 25;
|
||||
static constexpr u8 VGA_COLS = 80;
|
||||
|
||||
for (int i = 0; msg[i] != '\0'; i++)
|
||||
s_vga[i] = 0x0700 | msg[i];
|
||||
static inline void clrsc(void) {
|
||||
for (u32 i = 0; i < VGA_ROWS * VGA_COLS; ++i)
|
||||
s_vga[i] = 0;
|
||||
}
|
||||
|
||||
static inline void puts(const char* str, u8 row, u8 col) {
|
||||
for (u32 off = 0; str[off] != '\0'; ++off)
|
||||
s_vga[col + off + (VGA_COLS * row)] = 0x0700 | str[off];
|
||||
}
|
||||
|
||||
static constexpr gdt_entry s_gdt[5] = {
|
||||
// Null Descriptor
|
||||
gdt_entry{ 0, 0, 0, 0 },
|
||||
// Kernel Mode Code Segment
|
||||
gdt_entry{ 0,
|
||||
0xFFFFF,
|
||||
gdt_entry::ACCESS_P | gdt_entry::ACCESS_DPL0 | gdt_entry::ACCESS_S | gdt_entry::ACCESS_E | gdt_entry::ACCESS_RW,
|
||||
gdt_entry::FLAG_G | gdt_entry::FLAG_L },
|
||||
// Kernel Mode Data Segment
|
||||
gdt_entry{ 0,
|
||||
0xFFFFF,
|
||||
gdt_entry::ACCESS_P | gdt_entry::ACCESS_DPL0 | gdt_entry::ACCESS_S | gdt_entry::ACCESS_RW,
|
||||
gdt_entry::FLAG_G | gdt_entry::FLAG_DB },
|
||||
// User Mode Data Segment
|
||||
gdt_entry{ 0,
|
||||
0xFFFFF,
|
||||
gdt_entry::ACCESS_P | gdt_entry::ACCESS_DPL3 | gdt_entry::ACCESS_S | gdt_entry::ACCESS_RW,
|
||||
gdt_entry::FLAG_G | gdt_entry::FLAG_DB },
|
||||
// User Mode Code Segment
|
||||
gdt_entry{ 0,
|
||||
0xFFFFF,
|
||||
gdt_entry::ACCESS_P | gdt_entry::ACCESS_DPL3 | gdt_entry::ACCESS_S | gdt_entry::ACCESS_E | gdt_entry::ACCESS_RW,
|
||||
gdt_entry::FLAG_G | gdt_entry::FLAG_L },
|
||||
// Task State Segment
|
||||
// gdt_entry{ 0, 0, gdt_entry::ACCESS_P | gdt_entry::ACCESS_E | gdt_entry::ACCESS_A, 0 },
|
||||
// gdt_entry{ 0 }
|
||||
};
|
||||
|
||||
extern "C" void kmain(void) {
|
||||
clrsc();
|
||||
|
||||
load_gdt(s_gdt, sizeof(s_gdt));
|
||||
reload_segments(0x8, 0x10);
|
||||
|
||||
puts("Loaded GDT!", 0, 0);
|
||||
puts("Zdravstvuyte, tovarisch!", 1, 0);
|
||||
|
||||
for (;;)
|
||||
__asm__ volatile("hlt");
|
||||
|
||||
Reference in New Issue
Block a user