diff --git a/kernel/src/arch/paging.c b/kernel/src/arch/paging.c index 1441396..20c8e62 100644 --- a/kernel/src/arch/paging.c +++ b/kernel/src/arch/paging.c @@ -232,6 +232,9 @@ void paging_init(void) } memset(kernel_pagemap, 0, PAGE_SIZE); + if (_supports_large_pages()) + log_early("Support for 2MB pages is present"); + /* Map kernel stack */ uint64_t stack_top = ALIGN_UP(kstack_top, PAGE_SIZE); for (uint64_t addr = stack_top - (16 * 1024); addr < stack_top; addr += PAGE_SIZE) diff --git a/kernel/src/sys/apic/lapic.c b/kernel/src/sys/apic/lapic.c index a71ccca..2392772 100644 --- a/kernel/src/sys/apic/lapic.c +++ b/kernel/src/sys/apic/lapic.c @@ -6,6 +6,9 @@ #include #include +#define LAPIC_REG_ALIGN 16 +#define LAPIC_REG_SIZE 4 + atomic_uintptr_t lapic_msr = 0; atomic_uintptr_t lapic_base_atomic = 0; @@ -19,7 +22,13 @@ void lapic_write(uint32_t offset, uint32_t value) log_early("error: LAPIC not initialized!"); kpanic(NULL, "LAPIC write attempted before initialization"); } - base[offset / 4] = value; + if (offset % LAPIC_REG_ALIGN != 0) + { + log_early("error: Misaligned LAPIC offset 0x%x", offset); + kpanic(NULL, "Invalid LAPIC register offset"); + } + volatile uint32_t *reg = base + (offset / LAPIC_REG_SIZE); + *reg = value; } uint32_t lapic_read(uint32_t offset) @@ -30,7 +39,13 @@ uint32_t lapic_read(uint32_t offset) log_early("error: LAPIC not initialized!"); return 0; } - return base[offset / 4]; + if (offset % LAPIC_REG_ALIGN != 0) + { + log_early("error: Misaligned LAPIC offset 0x%x", offset); + kpanic(NULL, "Invalid LAPIC register offset"); + } + volatile uint32_t *reg = base + (offset / LAPIC_REG_SIZE); + return *reg; } void lapic_init(void) @@ -72,4 +87,4 @@ void lapic_enable(void) lapic_write(LAPIC_TPR, 0); uint32_t id = lapic_read(LAPIC_ID) >> 24; log_early("LAPIC enabled and initialized for CPU %u", id); -} +} \ No newline at end of file