From 5cf666f61b05138602e9c911aa7261cc66c9590e Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 1 Dec 2023 12:30:05 +0100 Subject: [PATCH] fix(x86_64/apic): map SMP bootcode to allocated physical address instead of fixed one --- src/arch/x86_64/kernel/apic.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/arch/x86_64/kernel/apic.rs b/src/arch/x86_64/kernel/apic.rs index 367b51d21b..2ef6716853 100644 --- a/src/arch/x86_64/kernel/apic.rs +++ b/src/arch/x86_64/kernel/apic.rs @@ -693,20 +693,18 @@ pub fn boot_application_processors() { "SMP Boot Code is larger than a page" ); debug!("SMP boot code is {} bytes long", smp_boot_code.len()); + // We can only allocate full pages of physmem + let length = BasePageSize::SIZE as usize; + let phys_addr: PhysAddr = crate::arch::mm::physicalmem::allocate(length).unwrap(); - // Identity-map the boot code page and copy over the code. - debug!( - "Mapping SMP boot code to physical and virtual address {:p}", - SMP_BOOT_CODE_ADDRESS - ); let mut flags = PageTableEntryFlags::empty(); flags.normal().writable(); - paging::map::( - SMP_BOOT_CODE_ADDRESS, - PhysAddr(SMP_BOOT_CODE_ADDRESS.as_u64()), - 1, - flags, + debug!( + "Mapping SMP boot code from physical address {phys_addr:x} to virtual address {:p}", + SMP_BOOT_CODE_ADDRESS ); + //map physical memory to SMP_BOOT_CODE_ADDRESS in virtual memory + paging::map::(SMP_BOOT_CODE_ADDRESS, phys_addr, 1, flags); unsafe { ptr::copy_nonoverlapping( smp_boot_code.as_ptr(),