Skip to content

Commit

Permalink
kern/misc: Ensure bootloader responses are not nil globally
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Jul 12, 2024
1 parent 8c6f049 commit e3c1a48
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
3 changes: 3 additions & 0 deletions kernel/modules/acpi/acpi.v
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ __global (
)

pub fn initialise() {
if rsdp_req.response == unsafe { nil } {
panic('acpi: ACPI not supported on this machine.')
}
rsdp_ptr := rsdp_req.response.address

if rsdp_ptr == 0 {
Expand Down
4 changes: 4 additions & 0 deletions kernel/modules/initramfs/initramfs.v
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ __global (

@[manualfree]
pub fn initialise() {
if module_req.response == unsafe { nil } {
panic('Modules bootloader response missing')
}

if module_req.response.module_count < 1 {
panic('No initramfs')
}
Expand Down
10 changes: 6 additions & 4 deletions kernel/modules/memory/physical.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ __global (
volatile hhdm_req = limine.LimineHHDMRequest{
response: unsafe { nil }
}
volatile paging_mode_req = limine.LiminePagingModeRequest{
response: unsafe { nil }
mode: limine.limine_paging_mode_x86_64_5lvl
}
)

pub fn print_free() {
Expand All @@ -39,10 +35,16 @@ pub fn print_free() {
}

pub fn pmm_init() {
if hhdm_req.response == unsafe { nil } {
lib.kpanic(unsafe { nil }, c'HHDM bootloader response missing')
}
higher_half = hhdm_req.response.offset

C.printf(c'pmm: Higher half direct map at: %p\n', higher_half)

if memmap_req.response == unsafe { nil } {
lib.kpanic(unsafe { nil }, c'Memory map bootloader response missing')
}
memmap := memmap_req.response

unsafe {
Expand Down
20 changes: 14 additions & 6 deletions kernel/modules/memory/virtual.v
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ __global (
volatile memmap_req = limine.LimineMemmapRequest{
response: unsafe { nil }
}
volatile paging_mode_req = limine.LiminePagingModeRequest{
response: unsafe { nil }
mode: limine.limine_paging_mode_x86_64_5lvl
}
)

fn map_kernel_span(virt u64, phys u64, len u64, flags u64) {
Expand All @@ -265,14 +269,13 @@ fn map_kernel_span(virt u64, phys u64, len u64, flags u64) {
}

pub fn vmm_init() {
if paging_mode_req.response.mode == limine.limine_paging_mode_x86_64_5lvl {
print('vmm: Using 5 level paging\n')
la57 = true
if paging_mode_req.response != unsafe { nil } {
if paging_mode_req.response.mode == limine.limine_paging_mode_x86_64_5lvl {
print('vmm: Using 5 level paging\n')
la57 = true
}
}

print('vmm: Kernel physical base: 0x${kaddr_req.response.physical_base:x}\n')
print('vmm: Kernel virtual base: 0x${kaddr_req.response.virtual_base:x}\n')

kernel_pagemap.top_level = pmm_alloc(1)
if kernel_pagemap.top_level == 0 {
panic('vmm_init() allocation failure')
Expand All @@ -287,6 +290,11 @@ pub fn vmm_init() {
}

// Map kernel
if kaddr_req.response == unsafe { nil } {
panic('Kernel address bootloader response missing')
}
print('vmm: Kernel physical base: 0x${kaddr_req.response.physical_base:x}\n')
print('vmm: Kernel virtual base: 0x${kaddr_req.response.virtual_base:x}\n')
virtual_base := kaddr_req.response.virtual_base
physical_base := kaddr_req.response.physical_base

Expand Down
3 changes: 3 additions & 0 deletions kernel/modules/term/term.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ __global (
)

pub fn initialise() {
if fb_req.response == unsafe { nil } {
panic('Framebuffer bootloader response missing')
}
framebuffer_tag = unsafe { fb_req.response.framebuffers[0] }
framebuffer_width = framebuffer_tag.width
framebuffer_height = framebuffer_tag.height
Expand Down
6 changes: 5 additions & 1 deletion kernel/modules/time/time.v
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ __global (
)

pub fn initialise() {
epoch := boottime_req.response.boot_time
epoch := if boottime_req.response != unsafe { nil } {
boottime_req.response.boot_time
} else {
0
}

monotonic_clock = TimeSpec{i64(epoch), 0}
realtime_clock = TimeSpec{i64(epoch), 0}
Expand Down
3 changes: 3 additions & 0 deletions kernel/modules/x86/smp/smp.v
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ __global (
)

pub fn initialise() {
if smp_req.response == unsafe { nil } {
panic('SMP bootloader response missing')
}
smp_tag := smp_req.response

println('smp: BSP LAPIC ID: ${smp_tag.bsp_lapic_id:x}')
Expand Down

0 comments on commit e3c1a48

Please sign in to comment.