From 9253e1624089a3d3c2c474faeb472127b32e310e Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Mon, 25 Mar 2024 13:29:54 +0100 Subject: [PATCH] Fix kernel stack sizes, other arches. --- src/acpi/madt.rs | 6 +++--- src/arch/aarch64/misc.rs | 2 +- src/arch/x86/gdt.rs | 3 ++- src/arch/x86_shared/idt.rs | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/acpi/madt.rs b/src/acpi/madt.rs index ea892a4dcd..2e950ba227 100644 --- a/src/acpi/madt.rs +++ b/src/acpi/madt.rs @@ -2,7 +2,7 @@ use core::mem; use crate::{ memory::{allocate_p2frame, Frame}, - paging::{KernelMapper, Page, PageFlags, PhysicalAddress, RmmA, RmmArch, VirtualAddress}, + paging::{KernelMapper, Page, PageFlags, PhysicalAddress, RmmA, RmmArch, VirtualAddress, PAGE_SIZE}, }; use super::{find_sdt, sdt::Sdt}; @@ -92,12 +92,12 @@ impl Madt { CPU_COUNT.fetch_add(1, Ordering::SeqCst); // Allocate a stack - let stack_start = allocate_p2frame(6) + let stack_start = allocate_p2frame(4) .expect("no more frames in acpi stack_start") .start_address() .data() + crate::PHYS_OFFSET; - let stack_end = stack_start + 64 * 4096; + let stack_end = stack_start + (PAGE_SIZE << 4); let ap_ready = (TRAMPOLINE + 8) as *mut u64; let ap_cpu_id = unsafe { ap_ready.add(1) }; diff --git a/src/arch/aarch64/misc.rs b/src/arch/aarch64/misc.rs index 7f288261c6..e61864255e 100644 --- a/src/arch/aarch64/misc.rs +++ b/src/arch/aarch64/misc.rs @@ -15,7 +15,7 @@ impl PercpuBlock { #[cold] pub unsafe fn init(cpu_id: LogicalCpuId) { - let frame = crate::memory::allocate_frames(1).expect("failed to allocate percpu memory"); + let frame = crate::memory::allocate_frame().expect("failed to allocate percpu memory"); let virt = RmmA::phys_to_virt(frame.start_address()).data() as *mut PercpuBlock; virt.write(PercpuBlock::init(cpu_id)); diff --git a/src/arch/x86/gdt.rs b/src/arch/x86/gdt.rs index 3c4d0afed3..4f1d4ecdca 100644 --- a/src/arch/x86/gdt.rs +++ b/src/arch/x86/gdt.rs @@ -181,7 +181,8 @@ pub unsafe fn init() { /// Initialize GDT and configure percpu. pub unsafe fn init_paging(stack_offset: usize, cpu_id: LogicalCpuId) { - let pcr_frame = crate::memory::allocate_frames(mem::size_of::().div_ceil(PAGE_SIZE)).expect("failed to allocate PCR frame"); + let alloc_order = mem::size_of::().div_ceil(PAGE_SIZE).next_power_of_two().trailing_zeros(); + let pcr_frame = crate::memory::allocate_p2frame(alloc_order).expect("failed to allocate PCR frame"); let pcr = &mut *(RmmA::phys_to_virt(pcr_frame.start_address()).data() as *mut ProcessorControlRegion); diff --git a/src/arch/x86_shared/idt.rs b/src/arch/x86_shared/idt.rs index 27b359e20c..f2e1eeb37b 100644 --- a/src/arch/x86_shared/idt.rs +++ b/src/arch/x86_shared/idt.rs @@ -14,7 +14,7 @@ use x86::{ #[cfg(target_arch = "x86_64")] use crate::interrupt::irq::{__generic_interrupts_end, __generic_interrupts_start}; -use crate::{interrupt::*, ipi::IpiKind, cpu_set::LogicalCpuId}; +use crate::{cpu_set::LogicalCpuId, interrupt::*, ipi::IpiKind, paging::PAGE_SIZE}; use spin::RwLock; @@ -228,8 +228,8 @@ pub unsafe fn init_generic(cpu_id: LogicalCpuId, idt: &mut Idt) { let index = 1_u8; // Allocate 64 KiB of stack space for the backup stack. - const BACKUP_STACK_SIZE: usize = 4096 << 6; - let frames = crate::memory::allocate_p2frame(6) + const BACKUP_STACK_SIZE: usize = PAGE_SIZE << 4; + let frames = crate::memory::allocate_p2frame(4) .expect("failed to allocate pages for backup interrupt stack"); use crate::paging::{RmmA, RmmArch};