VirtualBox

Changeset 100184 in vbox


Ignore:
Timestamp:
Jun 16, 2023 6:51:39 AM (18 months ago)
Author:
vboxsync
Message:

VMM: Add a CPUMGetGuestArch() method and PDM device helper to make it easier to determine the guest architecture and not having to deal with the massive CPUMMICROARCH enum, bugref:10385

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/cpum.h

    r99051 r100184  
    6969    CPUMCPUVENDOR_32BIT_HACK = 0x7fffffff
    7070} CPUMCPUVENDOR;
     71
     72
     73/**
     74 * CPU architecture.
     75 */
     76typedef enum CPUMARCH
     77{
     78    /** Invalid zero value. */
     79    kCpumArch_Invalid = 0,
     80    /** x86 based architecture (includes 64-bit). */
     81    kCpumArch_X86,
     82    /** ARM based architecture (includs both AArch32 and AArch64). */
     83    kCpumArch_Arm,
     84
     85    /** @todo RiscV, Mips, ... ;). */
     86
     87    /*
     88     * Unknown.
     89     */
     90    kCpumArch_Unknown,
     91
     92    kCpumArch_32BitHack = 0x7fffffff
     93} CPUMARCH;
    7194
    7295
     
    352375VMMDECL(uint64_t)       CPUMGetGuestFlatSP(PVMCPU pVCpu);
    353376VMMDECL(CPUMCPUVENDOR)  CPUMGetGuestCpuVendor(PVM pVM);
     377VMMDECL(CPUMARCH)       CPUMGetGuestArch(PCVM pVM);
    354378VMMDECL(CPUMMICROARCH)  CPUMGetGuestMicroarch(PCVM pVM);
    355379VMMDECL(void)           CPUMGetGuestAddrWidths(PCVM pVM, uint8_t *pcPhysAddrWidth, uint8_t *pcLinearAddrWidth);
     
    362386
    363387VMMDECL(CPUMCPUVENDOR)  CPUMGetHostCpuVendor(PVM pVM);
     388VMMDECL(CPUMARCH)       CPUMGetHostArch(PCVM pVM);
    364389VMMDECL(CPUMMICROARCH)  CPUMGetHostMicroarch(PCVM pVM);
    365390
  • trunk/include/VBox/vmm/pdmdev.h

    r99745 r100184  
    46114611
    46124612    /**
     4613     * Returns the architecture used for the guest.
     4614     *
     4615     * @returns CPU architecture enum.
     4616     * @param   pDevIns             The device instance.
     4617     */
     4618    DECLR3CALLBACKMEMBER(CPUMARCH, pfnCpuGetGuestArch,(PPDMDEVINS pDevIns));
     4619
     4620    /**
    46134621     * Returns the micro architecture used for the guest.
    46144622     *
     
    73597367{
    73607368    return pDevIns->CTX_SUFF(pHlp)->pfnPhysChangeMemBalloon(pDevIns, fInflate, cPages, paPhysPage);
     7369}
     7370
     7371/**
     7372 * @copydoc PDMDEVHLPR3::pfnCpuGetGuestArch
     7373 */
     7374DECLINLINE(CPUMARCH) PDMDevHlpCpuGetGuestArch(PPDMDEVINS pDevIns)
     7375{
     7376    return pDevIns->CTX_SUFF(pHlp)->pfnCpuGetGuestArch(pDevIns);
     7377}
     7378
     7379/**
     7380 * Returns a flag whether the current guest CPU architecture is x86.
     7381 *
     7382 * @returns Flag whether the current guest architecture is x86.
     7383 * @param   pDevIns     The device instance.
     7384 */
     7385DECLINLINE(bool) PDMDevHlpCpuIsGuestArchX86(PPDMDEVINS pDevIns)
     7386{
     7387    return pDevIns->CTX_SUFF(pHlp)->pfnCpuGetGuestArch(pDevIns) == kCpumArch_X86;
     7388}
     7389
     7390/**
     7391 * Returns a flag whether the current guest CPU architecture is ARM.
     7392 *
     7393 * @returns Flag whether the current guest architecture is ARM.
     7394 * @param   pDevIns     The device instance.
     7395 */
     7396DECLINLINE(bool) PDMDevHlpCpuIsGuestArchArm(PPDMDEVINS pDevIns)
     7397{
     7398    return pDevIns->CTX_SUFF(pHlp)->pfnCpuGetGuestArch(pDevIns) == kCpumArch_Arm;
    73617399}
    73627400
  • trunk/include/VBox/vmm/vmmr3vtable-def.h

    r99547 r100184  
    370370VTABLE_ENTRY(CPUMGetHostCpuVendor)
    371371VTABLE_ENTRY(CPUMGetHostMicroarch)
     372VTABLE_ENTRY(CPUMGetGuestCpuVendor)
     373VTABLE_ENTRY(CPUMGetGuestArch)
     374VTABLE_ENTRY(CPUMGetGuestMicroarch)
    372375
    373376VTABLE_RESERVED(pfnCPUMR3Reserved1)
  • trunk/include/VBox/vmm/vmmr3vtable.h

    r99547 r100184  
    7272
    7373/** Magic and version for the VMM vtable.  (Magic: Emmet Cohen)   */
    74 #define VMMR3VTABLE_MAGIC_VERSION         RT_MAKE_U64(0x19900525, 0x00040000)
     74#define VMMR3VTABLE_MAGIC_VERSION         RT_MAKE_U64(0x19900525, 0x00050000)
    7575/** Compatibility mask: These bits must match - magic and major version. */
    7676#define VMMR3VTABLE_MAGIC_VERSION_MASK    RT_MAKE_U64(0xffffffff, 0xffff0000)
  • trunk/src/VBox/VMM/VMMAll/CPUMAllRegs-armv8.cpp

    r100167 r100184  
    173173
    174174/**
     175 * Gets the guest CPU architecture.
     176 *
     177 * @returns CPU architecture.
     178 * @param   pVM     The cross context VM structure.
     179 */
     180VMMDECL(CPUMARCH) CPUMGetGuestArch(PCVM pVM)
     181{
     182    RT_NOREF(pVM);
     183    return kCpumArch_Arm; /* Static as we are in the ARM VMM module here. */
     184}
     185
     186
     187/**
    175188 * Gets the guest CPU microarchitecture.
    176189 *
  • trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp

    r99739 r100184  
    10971097{
    10981098    return (CPUMCPUVENDOR)pVM->cpum.s.GuestFeatures.enmCpuVendor;
     1099}
     1100
     1101
     1102/**
     1103 * Gets the guest CPU architecture.
     1104 *
     1105 * @returns CPU architecture.
     1106 * @param   pVM     The cross context VM structure.
     1107 */
     1108VMMDECL(CPUMARCH) CPUMGetGuestArch(PCVM pVM)
     1109{
     1110    RT_NOREF(pVM);
     1111    return kCpumArch_X86; /* Static as we are in the x86 VMM module here. */
    10991112}
    11001113
  • trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp

    r100108 r100184  
    11931193    Log(("pdmR3DevHlp_PhysChangeMemBalloon: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
    11941194    return rc;
     1195}
     1196
     1197
     1198/** @interface_method_impl{PDMDEVHLPR3,pfnCpuGetGuestArch} */
     1199static DECLCALLBACK(CPUMARCH) pdmR3DevHlp_CpuGetGuestArch(PPDMDEVINS pDevIns)
     1200{
     1201    PDMDEV_ASSERT_DEVINS(pDevIns);
     1202    PVM pVM = pDevIns->Internal.s.pVMR3;
     1203    LogFlow(("pdmR3DevHlp_CpuGetGuestArch: caller='%s'/%d\n",
     1204             pDevIns->pReg->szName, pDevIns->iInstance));
     1205
     1206    CPUMARCH enmArch = CPUMGetGuestArch(pVM);
     1207
     1208    Log(("pdmR3DevHlp_CpuGetGuestArch: caller='%s'/%d: returns %u\n", pDevIns->pReg->szName, pDevIns->iInstance, enmArch));
     1209    return enmArch;
    11951210}
    11961211
     
    51975212    pdmR3DevHlp_PhysBulkGCPhys2CCPtrReadOnly,
    51985213    pdmR3DevHlp_PhysBulkReleasePageMappingLocks,
     5214    pdmR3DevHlp_CpuGetGuestArch,
    51995215    pdmR3DevHlp_CpuGetGuestMicroarch,
    52005216    pdmR3DevHlp_CpuGetGuestAddrWidths,
     
    55955611    pdmR3DevHlp_PhysBulkGCPhys2CCPtrReadOnly,
    55965612    pdmR3DevHlp_PhysBulkReleasePageMappingLocks,
     5613    pdmR3DevHlp_CpuGetGuestArch,
    55975614    pdmR3DevHlp_CpuGetGuestMicroarch,
    55985615    pdmR3DevHlp_CpuGetGuestAddrWidths,
     
    63136330    pdmR3DevHlp_PhysBulkGCPhys2CCPtrReadOnly,
    63146331    pdmR3DevHlp_PhysBulkReleasePageMappingLocks,
     6332    pdmR3DevHlp_CpuGetGuestArch,
    63156333    pdmR3DevHlp_CpuGetGuestMicroarch,
    63166334    pdmR3DevHlp_CpuGetGuestAddrWidths,
  • trunk/src/VBox/VMM/VMMR3/VMMR3.def

    r98103 r100184  
    107107
    108108    CPUMGetHostMicroarch
     109    CPUMGetGuestArch
    109110    CPUMGetGuestMicroarch
    110111
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