Skip to content

Commit

Permalink
refactor: migrate all non-virtio page allocations to PhysAlloc
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
  • Loading branch information
mkroening committed Apr 30, 2024
1 parent db9018b commit a3f6085
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/arch/x86_64/kernel/apic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::vec::Vec;
use core::alloc::{Allocator, Layout};
#[cfg(feature = "smp")]
use core::arch::x86_64::_mm_mfence;
#[cfg(feature = "acpi")]
Expand Down Expand Up @@ -26,8 +27,9 @@ use crate::arch::x86_64::mm::paging::{
use crate::arch::x86_64::mm::{paging, virtualmem, PhysAddr, VirtAddr};
use crate::arch::x86_64::swapgs;
use crate::config::*;
use crate::mm::phys_alloc::PhysAlloc;
use crate::scheduler::CoreId;
use crate::{arch, env, mm, scheduler};
use crate::{arch, env, scheduler};

const MP_FLT_SIGNATURE: u32 = 0x5f504d5f;
const MP_CONFIG_SIGNATURE: u32 = 0x504d4350;
Expand Down Expand Up @@ -684,8 +686,10 @@ pub fn init_x2apic() {
/// Initialize the required _start variables for the next CPU to be booted.
pub fn init_next_processor_variables() {
// Allocate stack for the CPU and pass the addresses.
let stack = mm::allocate(KERNEL_STACK_SIZE, true);
CURRENT_STACK_ADDRESS.store(stack.as_u64(), Ordering::Relaxed);
let layout = Layout::from_size_align(KERNEL_STACK_SIZE, BasePageSize::SIZE as usize).unwrap();
let stack = PhysAlloc.allocate(layout).unwrap();
let stack_address = stack.as_ptr().expose_provenance().try_into().unwrap();
CURRENT_STACK_ADDRESS.store(stack_address, Ordering::Relaxed);
}

/// Boot all Application Processors
Expand Down
8 changes: 6 additions & 2 deletions src/arch/x86_64/kernel/gdt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::boxed::Box;
use core::alloc::{Allocator, Layout};
use core::sync::atomic::Ordering;

use x86_64::instructions::tables;
Expand All @@ -15,6 +16,7 @@ use super::CURRENT_STACK_ADDRESS;
use crate::arch::x86_64::kernel::core_local::{core_scheduler, CoreLocal};
use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize};
use crate::config::KERNEL_STACK_SIZE;
use crate::mm::phys_alloc::PhysAlloc;

pub fn add_current_core() {
let gdt: &mut GlobalDescriptorTable = Box::leak(Box::new(GlobalDescriptorTable::new()));
Expand Down Expand Up @@ -47,8 +49,10 @@ pub fn add_current_core() {
BasePageSize::SIZE as usize
};

let ist = crate::mm::allocate(sz, true);
let ist_start = ist.as_u64() + sz as u64 - TaskStacks::MARKER_SIZE as u64;
let layout = Layout::from_size_align(sz, BasePageSize::SIZE as usize).unwrap();
let ist = PhysAlloc.allocate(layout).unwrap();
let ist: u64 = ist.as_ptr().expose_provenance().try_into().unwrap();
let ist_start = ist + sz as u64 - TaskStacks::MARKER_SIZE as u64;
tss.interrupt_stack_table[i] = VirtAddr::new(ist_start);
}

Expand Down
3 changes: 2 additions & 1 deletion src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ pub(crate) fn init() {
let kernel_heap_size = 10 * LargePageSize::SIZE as usize;

unsafe {
let start = allocate(kernel_heap_size, true);
let layout = Layout::from_size_align(kernel_heap_size, BasePageSize::SIZE as usize).unwrap();
let start = PhysAlloc.allocate(layout).unwrap();
ALLOCATOR.init(start.as_mut_ptr(), kernel_heap_size);

info!("Kernel heap starts at {:#x}", start);
Expand Down

0 comments on commit a3f6085

Please sign in to comment.