Kernel: Cleanup code and move kmalloc initialization to later

This commit is contained in:
Bananymous
2022-12-28 04:16:21 +02:00
parent 2a65c5fd0f
commit 3e8590687f
7 changed files with 53 additions and 43 deletions

View File

@@ -373,8 +373,8 @@ namespace APIC
// Enable Local APIC
SetMSR(IA32_APIC_BASE, (s_local_apic & 0xFFFFF000) | IA32_APIC_BASE_ENABLE, 0);
uint32_t sipi = ReadLocalAPIC(0xF0);
WriteIOAPIC(0xF0, sipi | 0x1FF);
uint32_t sivr = ReadLocalAPIC(0xF0);
WriteLocalAPIC(0xF0, sivr | 0x1FF);
return true;
}

View File

@@ -8,7 +8,7 @@ struct GDTR
} __attribute__((packed));
static GDTR s_gdtr;
static SegmentDesriptor* s_gdt;
static SegmentDesriptor s_gdt[5];
extern "C" void load_gdt(void* gdt_ptr);
asm(
@@ -43,12 +43,8 @@ void write_gdt_entry(uint8_t segment, SegmentDesriptor descriptor)
void gdt_initialize()
{
constexpr uint8_t GDT_SIZE = 5;
s_gdt = new SegmentDesriptor[GDT_SIZE];
s_gdtr.address = s_gdt;
s_gdtr.size = GDT_SIZE * 8 - 1;
s_gdtr.size = sizeof(s_gdt) - 1;
write_gdt_entry(0x00, { 0, 0x00000, 0x00, 0x0 }); // null
write_gdt_entry(0x08, { 0, 0xFFFFF, 0x9A, 0xC }); // kernel code

View File

@@ -1,6 +1,5 @@
#include <kernel/APIC.h>
#include <kernel/IDT.h>
#include <kernel/kmalloc.h>
#include <kernel/panic.h>
#include <kernel/kprint.h>
#include <kernel/Serial.h>

View File

@@ -42,9 +42,10 @@ void TTY::Clear()
void TTY::SetCursorPosition(uint32_t x, uint32_t y)
{
static uint32_t last_x = 0;
static uint32_t last_y = 0;
RenderFromBuffer(last_x, last_y); // Hacky way to clear previous cursor in graphics mode :D
static uint32_t last_x = -1;
static uint32_t last_y = -1;
if (last_x != uint32_t(-1) && last_y != uint32_t(-1))
RenderFromBuffer(last_x, last_y); // Hacky way to clear previous cursor in graphics mode :D
VESA::SetCursorPosition(x, y, VESA::Color::BRIGHT_WHITE);
last_x = m_column = x;
last_y = m_row = y;
@@ -349,10 +350,11 @@ void TTY::PutCharCurrent(char ch)
break;
default:
VESA::PutCharAt(ch, x, y, VESA::Color::BRIGHT_WHITE, VESA::Color::BLACK);
x++;
break;
}
if (++x == VESA::GetTerminalWidth())
if (x == VESA::GetTerminalWidth())
{
x = 0;
y++;

View File

@@ -20,12 +20,12 @@ extern const struct bitmap_font font;
namespace VESA
{
static void* s_addr = nullptr;
static uint8_t s_bpp = 0;
static uint32_t s_pitch = 0;
static uint32_t s_width = 0;
static uint32_t s_height = 0;
static uint8_t s_mode = 0;
static uintptr_t s_addr = 0;
static uint8_t s_bpp = 0;
static uint32_t s_pitch = 0;
static uint32_t s_width = 0;
static uint32_t s_height = 0;
static uint8_t s_mode = 0;
static uint32_t s_terminal_width = 0;
static uint32_t s_terminal_height = 0;
@@ -73,9 +73,9 @@ namespace VESA
{
if (!(s_multiboot_info->flags & MULTIBOOT_FLAGS_FRAMEBUFFER))
return false;
auto& framebuffer = s_multiboot_info->framebuffer;
s_addr = (void*)framebuffer.addr;
s_addr = framebuffer.addr;
s_bpp = framebuffer.bpp;
s_pitch = framebuffer.pitch;
s_width = framebuffer.width;
@@ -90,6 +90,7 @@ namespace VESA
return false;
}
dprintln("Graphics Mode {}x{} ({} bpp)", s_width, s_height, s_bpp);
PutCharAtImpl = GraphicsPutCharAt;
ClearImpl = GraphicsClear;
SetCursorPositionImpl = GraphicsSetCursorPosition;
@@ -98,6 +99,7 @@ namespace VESA
}
else if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_TEXT)
{
dprintln("Text Mode {}x{}", s_width, s_height);
PutCharAtImpl = TextPutCharAt;
ClearImpl = TextClear;
SetCursorPositionImpl = TextSetCursorPosition;
@@ -137,7 +139,7 @@ namespace VESA
static void GraphicsSetPixel(uint32_t offset, uint32_t color)
{
uint32_t* address = (uint32_t*)((uint32_t)s_addr + offset);
uint32_t* address = (uint32_t*)(s_addr + offset);
switch (s_bpp)
{
case 24:
@@ -264,7 +266,7 @@ namespace VESA
static void TextPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg)
{
uint32_t index = y * s_width + x;
uint32_t index = y * s_pitch + x;
((uint16_t*)s_addr)[index] = TextEntry(ch, TextColor(fg, bg));
}