VirtualBox

Changeset 67112 in vbox for trunk/src


Ignore:
Timestamp:
May 26, 2017 11:34:08 AM (8 years ago)
Author:
vboxsync
Message:

BIOS: Check APIC availability before hitting the APIC base MSR.

Location:
trunk/src/VBox/Devices/PC/BIOS
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/BIOS/inlines.h

    r62509 r67112  
    44
    55/*
    6  * Copyright (C) 2010-2016 Oracle Corporation
     6 * Copyright (C) 2010-2017 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    146146#if VBOX_BIOS_CPU >= 80386
    147147
    148 /* Warning: msr_read/msr_write destroy high bits of 32-bit registers. */
     148/* Warning: msr_read/msr_write destroy high bits of 32-bit registers (EAX, ECX, EDX). */
    149149
    150150uint64_t msr_read(uint32_t msr);
     
    177177    parm [ax bx cx dx] [di si] modify [] nomemory;
    178178
     179/* Warning: eflags_read/eflags_write destroy high bits of 32-bit registers (EDX). */
     180uint32_t eflags_read( void );
     181#pragma aux eflags_read =   \
     182    ".386"                  \
     183    "pushfd"                \
     184    "pop  edx"              \
     185    "mov  ax, dx"           \
     186    "shr  edx, 16"          \
     187    value [dx ax] modify [dx ax];
     188
     189uint32_t eflags_write( uint32_t e_flags );
     190#pragma aux eflags_write =  \
     191    ".386"                  \
     192    "shl  edx, 16"          \
     193    "mov  dx, ax"           \
     194    "push edx"              \
     195    "popfd"                 \
     196    parm [dx ax] modify [dx ax];
     197
     198/* Warning cpuid destroys high bits of 32-bit registers (EAX, EBX, ECX, EDX). */
     199void cpuid( uint32_t __far cpu_id[4], uint32_t leaf );
     200#pragma aux cpuid =         \
     201    ".586"                  \
     202    "shl  edx, 16"          \
     203    "mov  dx, ax"           \
     204    "mov  eax, edx"         \
     205    "cpuid"                 \
     206    "mov  es:[di+0], eax"   \
     207    "mov  es:[di+4], ebx"   \
     208    "mov  es:[di+8], ecx"   \
     209    "mov  es:[di+12], edx"  \
     210    parm [es di] [dx ax] modify [bx cx dx]
     211
    179212#endif
  • trunk/src/VBox/Devices/PC/BIOS/post.c

    r62509 r67112  
    44
    55/*
    6  * Copyright (C) 2004-2016 Oracle Corporation
     6 * Copyright (C) 2004-2017 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    104104#if VBOX_BIOS_CPU >= 80386
    105105
     106/* NB: The CPUID detection is generic but currently not used elsewhere. */
     107
     108/* Check CPUID availability. */
     109int is_cpuid_supported( void )
     110{
     111    uint32_t    old_flags, new_flags;
     112
     113    old_flags = eflags_read();
     114    new_flags = old_flags ^ (1L << 21); /* Toggle CPUID bit. */
     115    eflags_write( new_flags );
     116    new_flags = eflags_read();
     117    return( old_flags != new_flags );   /* Supported if bit changed. */
     118}
     119
    106120#define APICMODE_DISABLED   0
    107121#define APICMODE_APIC       1
     
    121135 * existing virtual wire setup.
    122136 *
    123  * NB: This code assumes that there *is* a local APIC.
     137 * NB: This code does not assume that there is a local APIC. It is necessary
     138 * to check CPUID whether APIC is present; the CPUID instruction might not be
     139 * available either.
    124140 *
    125141 * NB: Destroys high bits of 32-bit registers.
     
    130146    uint16_t    mask;
    131147    uint8_t     apic_mode;
     148    uint32_t    cpu_id[4];
     149
     150    /* If there's no CPUID, there's certainly no APIC. */
     151    if (!is_cpuid_supported()) {
     152        return;
     153    }
     154
     155    /* Check EDX bit 9 */
     156    cpuid(&cpu_id, 1);
     157    BX_DEBUG("CPUID EDX: 0x%lx\n", cpu_id[3]);
     158    if ((cpu_id[3] & (1 << 9)) == 0) {
     159        return; /* No local APIC, nothing to do. */
     160    }
    132161
    133162    /* APIC mode at offset 78h in CMOS NVRAM. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette