Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export BUILD_BOOT_MULTIBOOT2 = 1
# Optional core modules

export BUILD_KERNEL_GRAPHICSBASE = 1
export BUILD_KERNEL_MEM_TEST = 1


# Optional driver modules

export BUILD_DRIVERS_SERIAL = 1

export BUILD_DRIVERS_HPET = 1

# End of options
Expand Down
15 changes: 12 additions & 3 deletions drivers/acpi/tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,17 @@ static void map_header(const volatile void* table) {
const volatile struct acpi_gen_header_t* gen = (struct acpi_gen_header_t*)table;
uint64_t alloc_base = (uint64_t)gen & PAGE_BASE_MASK;

paging_map(alloc_base, alloc_base, PAGE_PRESENT | PAT_MMIO_4K, PAGE_4K);
if (!paging_map(alloc_base, alloc_base, PAGE_PRESENT | PAT_MMIO_4K, PAGE_4K)) {
logging_log_error("Failed to map ACPI header");
panic(PANIC_PAGING);
}

if ((uint64_t)gen != alloc_base) {
alloc_base += PAGE_SIZE_4K;
paging_map(alloc_base, alloc_base, PAGE_PRESENT | PAT_MMIO_4K, PAGE_4K);
if (!paging_map(alloc_base, alloc_base, PAGE_PRESENT | PAT_MMIO_4K, PAGE_4K)) {
logging_log_error("Failed to map ACPI header");
panic(PANIC_PAGING);
}
}
}

Expand All @@ -243,7 +249,10 @@ static void map_table(const volatile void* table) {

while (alloc_base < (uint64_t)gen + gen->Length) {
alloc_base += PAGE_SIZE_4K;
paging_map(alloc_base, alloc_base, PAGE_PRESENT | PAT_MMIO_4K, PAGE_4K);
if (!paging_map(alloc_base, alloc_base, PAGE_PRESENT | PAT_MMIO_4K, PAGE_4K)) {
logging_log_error("Failed to map ACPI table");
panic(PANIC_PAGING);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion drivers/acpica_osl/osl.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ void* AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS paddr, ACPI_SIZE len) {
}

for (uint64_t i = 0; i < len; i += PAGE_SIZE_4K) {
paging_map(vaddr + i, page_base + i, PAGE_PRESENT | PAGE_RW | PAT_MMIO_4K, PAGE_4K);
if (!paging_map(vaddr + i, page_base + i, PAGE_PRESENT | PAGE_RW | PAT_MMIO_4K, PAGE_4K)) {
logging_log_error("Failed to map memory for ACPICA");
return 0;
}
}

return (void*)(vaddr + adj);
Expand Down
8 changes: 6 additions & 2 deletions drivers/apic/apic_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <kernel/core/proc_data.h>
#include <kernel/core/mm.h>
#include <kernel/core/gdt.h>
#include <kernel/core/alloc.h>

#include <kernel/lib/kmemcpy.h>

Expand Down Expand Up @@ -102,8 +103,11 @@ uint8_t* ap_init_locks;

void apic_init(void) {
apic_base = msr_read(MSR_APIC_BASE) & APIC_BASE_MASK;
paging_map(apic_base, apic_base,
PAGE_PRESENT | PAGE_RW | PAT_MMIO_4K, PAGE_4K);
if (!paging_map(apic_base, apic_base,
PAGE_PRESENT | PAGE_RW | PAT_MMIO_4K, PAGE_4K)) {
logging_log_error("Failed to map memory for LAPIC");
panic(PANIC_PAGING);
}

timer_vector = idt_get_vector();
error_vector = idt_get_vector();
Expand Down
11 changes: 9 additions & 2 deletions drivers/hpet/hpet_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,18 @@ void hpet_init(void) {
if (hpet_reg_bases[i]) {
logging_log_debug("Found HPET register base @ 0x%lx", hpet_reg_bases[i]);
const uint64_t temp = mm_alloc_v(PAGE_SIZE_4K);
paging_map(
if (!temp) {
logging_log_error("Failed to allocate memory for hpet");
panic(PANIC_NO_MEM);
}
if(!paging_map(
temp,
(uint64_t)hpet_reg_bases[i],
PAGE_PRESENT | PAGE_RW | PAT_MMIO_4K,
PAGE_4K);
PAGE_4K)) {
logging_log_error("Failed to map memory for HPET");
panic(PANIC_PAGING);
}
hpet_reg_bases[i] = (void*)temp;

// disable all interrupts
Expand Down
11 changes: 9 additions & 2 deletions drivers/ioapic/ioapic_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <kernel/core/alloc.h>
#include <kernel/core/cpu_instr.h>
#include <kernel/lib/kmemset.h>
#include <kernel/core/panic.h>

#define IOAPIC_OFF_IOREGSEL 0x00
#define IOAPIC_OFF_IOWIN 0x10
Expand Down Expand Up @@ -58,7 +59,10 @@ void ioapic_init(void) {

logging_log_info("Initializing IO APIC 0x%lX", (uint64_t)ioapic->IOAPICID);
const uint64_t ioapic_base = ioapic->IOAPICAddress;
paging_map(ioapic_base, ioapic_base, PAGE_PRESENT | PAGE_RW | PAT_MMIO_4K, PAGE_4K);
if (!paging_map(ioapic_base, ioapic_base, PAGE_PRESENT | PAGE_RW | PAT_MMIO_4K, PAGE_4K)) {
logging_log_error("Failed to map memory for IOAPIC");
panic(PANIC_PAGING);
}

*(volatile uint32_t*)(ioapic_base + IOAPIC_OFF_IOREGSEL) = IOAPIC_IOAPICVER;
const uint64_t num_redir = 1 + (MAX_REDIR_ENTRY_MSK &
Expand All @@ -74,7 +78,10 @@ void ioapic_init(void) {
for (uint64_t mapping_base = ioapic_base + PAGE_SIZE_4K;
mapping_base < ioapic_base + IOAPIC_REDIR_ST + num_redir * 2;
mapping_base += PAGE_SIZE_4K) {
paging_map(mapping_base, mapping_base, PAGE_PRESENT | PAGE_RW | PAT_MMIO_4K, PAGE_4K);
if (!paging_map(mapping_base, mapping_base, PAGE_PRESENT | PAGE_RW | PAT_MMIO_4K, PAGE_4K)) {
logging_log_error("Failed to map memory for IOAPIC");
panic(PANIC_PAGING);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ ifdef BUILD_KERNEL_GRAPHICSBASE
$(call add_directory,graphicsbase,GRAPHICSBASE)
endif

ifdef BUILD_KERNEL_MEM_TEST
$(call add_directory,mem_test,MEM_TEST)
endif

ifdef BUILD_DRIVERS_SERIAL
DEFINES := $(DEFINES) -DSERIAL
endif
Expand Down
Loading