From c444c992313a8cf29a8f4d97d668d71c2df9e0a9 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 13 Dec 2023 15:27:14 +0100 Subject: [PATCH] revert SMP boot for BIOS systems to previous way, WIP for UEFI systems (currently only one core supported) --- src/arch/x86_64/kernel/apic.rs | 43 ++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/arch/x86_64/kernel/apic.rs b/src/arch/x86_64/kernel/apic.rs index 367b51d21b..590642916a 100644 --- a/src/arch/x86_64/kernel/apic.rs +++ b/src/arch/x86_64/kernel/apic.rs @@ -693,20 +693,37 @@ 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 + + if crate::kernel::is_uefi() { + // Currently, this does NOT work as intended, this only supports one core + let length = BasePageSize::SIZE as usize; + let phys_addr: PhysAddr = crate::arch::mm::physicalmem::allocate(length).unwrap(); + + let mut flags = PageTableEntryFlags::empty(); + flags.normal().writable(); + 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); + } else { + // 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, + ); + } - // 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, - ); unsafe { ptr::copy_nonoverlapping( smp_boot_code.as_ptr(),