@@ -460,15 +460,15 @@ fn detect_from_mp() -> Result<PhysAddr, ()> {
460460 ( virtual_address | ( u64:: from ( mp_float. mp_config ) & ( BasePageSize :: SIZE - 1 ) ) ) as usize ;
461461 let mp_config: & ApicConfigTable = unsafe { & * ( ptr:: with_exposed_provenance ( addr) ) } ;
462462 if mp_config. signature != MP_CONFIG_SIGNATURE {
463- warn ! ( "Invalid MP config table" ) ;
463+ warn ! ( "MP config table invalid! " ) ;
464464 unsafe {
465465 deallocate_virtual ( virtual_address, BasePageSize :: SIZE as usize ) ;
466466 }
467467 return Err ( ( ) ) ;
468468 }
469469
470470 if mp_config. entry_count == 0 {
471- warn ! ( "No MP table entries! Guess IO-APIC! " ) ;
471+ warn ! ( "No MP table entries, guessing IOAPIC... " ) ;
472472 let default_address = PhysAddr :: new ( 0xfec0_0000 ) ;
473473
474474 init_ioapic_address ( default_address) ;
@@ -490,7 +490,7 @@ fn detect_from_mp() -> Result<PhysAddr, ()> {
490490 2 => {
491491 let io_entry: & ApicIoEntry = unsafe { & * ( ptr:: with_exposed_provenance ( addr) ) } ;
492492 let ioapic = PhysAddr :: new ( io_entry. addr . into ( ) ) ;
493- info ! ( "Found IOAPIC at 0x {ioapic:p}" ) ;
493+ info ! ( "IOAPIC found at {ioapic:p}" ) ;
494494
495495 init_ioapic_address ( ioapic) ;
496496
@@ -507,10 +507,10 @@ fn detect_from_mp() -> Result<PhysAddr, ()> {
507507}
508508
509509fn default_apic ( ) -> PhysAddr {
510- warn ! ( "Try to use default APIC address" ) ;
511-
512510 let default_address = PhysAddr :: new ( 0xfee0_0000 ) ;
513511
512+ warn ! ( "Using default APIC address: {default_address:p}" ) ;
513+
514514 // currently, uhyve doesn't support an IO-APIC
515515 if !env:: is_uhyve ( ) {
516516 init_ioapic_address ( default_address) ;
@@ -525,32 +525,30 @@ pub fn eoi() {
525525
526526pub fn init ( ) {
527527 // Detect CPUs and APICs.
528- let local_apic_physical_address = detect_from_acpi ( )
529- . or_else ( |( ) | detect_from_mp ( ) )
530- . unwrap_or_else ( |( ) | default_apic ( ) ) ;
528+ let local_apic_physical_address = if env:: is_uhyve ( ) {
529+ default_apic ( )
530+ } else {
531+ detect_from_acpi ( )
532+ . or_else ( |( ) | detect_from_mp ( ) )
533+ . unwrap_or_else ( |( ) | default_apic ( ) )
534+ } ;
531535
532536 // Initialize x2APIC or xAPIC, depending on what's available.
533- init_x2apic ( ) ;
534- if !processor:: supports_x2apic ( ) {
537+ if processor:: supports_x2apic ( ) {
538+ init_x2apic ( ) ;
539+ } else if env:: is_uefi ( ) {
540+ // already id mapped in UEFI systems, just use the physical address as virtual one
541+ LOCAL_APIC_ADDRESS
542+ . set ( VirtAddr :: new ( local_apic_physical_address. as_u64 ( ) ) )
543+ . unwrap ( ) ;
544+ } else {
535545 // We use the traditional xAPIC mode available on all x86-64 CPUs.
536546 // It uses a mapped page for communication.
537- if env:: is_uefi ( ) {
538- //already id mapped in UEFI systems, just use the physical address as virtual one
539- LOCAL_APIC_ADDRESS
540- . set ( VirtAddr :: new ( local_apic_physical_address. as_u64 ( ) ) )
541- . unwrap ( ) ;
542- } else {
543- let local_apic_address =
547+ let local_apic_address =
544548 allocate_virtual ( BasePageSize :: SIZE as usize , BasePageSize :: SIZE as usize ) . unwrap ( ) ;
545- LOCAL_APIC_ADDRESS . set ( local_apic_address) . unwrap ( ) ;
546- debug ! (
547- "Mapping Local APIC at {local_apic_physical_address:p} to virtual address {local_apic_address:p}"
548- ) ;
549-
550- let mut flags = PageTableEntryFlags :: empty ( ) ;
551- flags. device ( ) . writable ( ) . execute_disable ( ) ;
552- paging:: map :: < BasePageSize > ( local_apic_address, local_apic_physical_address, 1 , flags) ;
553- }
549+ let mut flags = PageTableEntryFlags :: empty ( ) ;
550+ flags. device ( ) . writable ( ) . execute_disable ( ) ;
551+ paging:: map :: < BasePageSize > ( local_apic_address, local_apic_physical_address, 1 , flags) ;
554552 }
555553
556554 // Set gates to ISRs for the APIC interrupts we are going to enable.
@@ -722,16 +720,14 @@ pub fn set_oneshot_timer(wakeup_time: Option<u64>) {
722720}
723721
724722pub fn init_x2apic ( ) {
725- if processor:: supports_x2apic ( ) {
726- debug ! ( "Enable x2APIC support" ) ;
727- // The CPU supports the modern x2APIC mode, which uses MSRs for communication.
728- // Enable it.
729- let mut msr = IA32_APIC_BASE ;
730- let mut apic_base = unsafe { msr. read ( ) } ;
731- apic_base |= X2APIC_ENABLE ;
732- unsafe {
733- msr. write ( apic_base) ;
734- }
723+ debug ! ( "Enable x2APIC support" ) ;
724+ // The CPU supports the modern x2APIC mode, which uses MSRs for communication.
725+ // Enable it.
726+ let mut msr = IA32_APIC_BASE ;
727+ let mut apic_base = unsafe { msr. read ( ) } ;
728+ apic_base |= X2APIC_ENABLE ;
729+ unsafe {
730+ msr. write ( apic_base) ;
735731 }
736732}
737733
0 commit comments