VirtualBox

Changeset 51797 in vbox for trunk/src


Ignore:
Timestamp:
Jul 2, 2014 6:09:31 AM (11 years ago)
Author:
vboxsync
Message:

VMM/GIM/Minimal: OS X bits.

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r51764 r51797  
    10021002        }
    10031003
     1004#if 0
    10041005        /* Expose extended MWAIT features to Mac OS X guests. */
    10051006        if (fOsXGuest)
     
    10391040                InsertConfigInteger(pCPUM, "MaxIntelFamilyModelStep", uMaxIntelFamilyModelStep);
    10401041        }
    1041 
     1042#endif
    10421043
    10431044        /* Synthetic CPU */
  • trunk/src/VBox/VMM/VMMR3/CPUMR3CpuId.cpp

    r51735 r51797  
    939939
    940940/**
     941 * Gets a CPU ID leaf.
     942 *
     943 * @returns VBox status code.
     944 * @param   pVM         Pointer to the VM.
     945 * @param   pLeaf       Where to store the found leaf.
     946 * @param   uLeaf       The leaf to locate.
     947 * @param   uSubLeaf    The subleaf to locate.  Pass 0 if no subleaves.
     948 */
     949VMMR3DECL(int) CPUMR3CpuIdGetLeaf(PVM pVM, PCPUMCPUIDLEAF pLeaf, uint32_t uLeaf, uint32_t uSubLeaf)
     950{
     951    PCPUMCPUIDLEAF pcLeaf = cpumR3CpuIdGetLeaf(pVM->cpum.s.GuestInfo.paCpuIdLeavesR3, pVM->cpum.s.GuestInfo.cCpuIdLeaves,
     952                                               uLeaf, uSubLeaf);
     953    if (pcLeaf)
     954    {
     955        memcpy(pLeaf, pcLeaf, sizeof(*pLeaf));
     956        return VINF_SUCCESS;
     957    }
     958
     959    return VERR_NOT_FOUND;
     960}
     961
     962
     963/**
    941964 * Inserts a CPU ID leaf, replacing any existing ones.
    942965 *
  • trunk/src/VBox/VMM/VMMR3/GIM.cpp

    r51643 r51797  
    115115    AssertLogRelRCReturn(rc, rc);
    116116
     117    /** @cfgm{GIM/GuestOsId, uint32_t}
     118     * The guest OS identifier. The default is 0, implying an unknown Guest OS. */
     119    GIMOSID GuestOsId = GIMOSID_END;
     120    uint32_t uGuestOsId;
     121    rc = CFGMR3QueryU32Def(pCfgNode, "GuestOsId", &uGuestOsId, GIMOSID_UNKNOWN);
     122    AssertLogRelRCReturn(rc, rc);
     123    if (uGuestOsId < GIMOSID_END)
     124        GuestOsId = (GIMOSID)uGuestOsId;
     125    else
     126    {
     127        LogRel(("GIM: GuestOsId %u invalid.", uGuestOsId));
     128        return VERR_GIM_INVALID_GUESTOS_ID;
     129    }
     130
    117131    /*
    118132     * Setup the GIM provider for this VM.
     
    131145        {
    132146            pVM->gim.s.enmProviderId = GIMPROVIDERID_MINIMAL;
    133             rc = GIMR3MinimalInit(pVM);
     147            rc = GIMR3MinimalInit(pVM, GuestOsId);
    134148        }
    135149        else if (!RTStrCmp(szProvider, "HyperV"))
     
    587601#endif
    588602
     603
     604/**
     605 * Checks if the given Guest OS identifier implies an OS X family of guests.
     606 *
     607 * @returns true if it's an OS X guest, false otherwise.
     608 * @param   enmGuestOs      The Guest OS Id.
     609 */
     610VMMR3_INT_DECL(bool) GIMR3IsOSXGuest(GIMOSID enmGuestOs)
     611{
     612    switch (enmGuestOs)
     613    {
     614        case GIMOSID_OSX:
     615        case GIMOSID_OSX_64:
     616        case GIMOSID_OSX_106:
     617        case GIMOSID_OSX_106_64:
     618        case GIMOSID_OSX_107:
     619        case GIMOSID_OSX_107_64:
     620        case GIMOSID_OSX_108:
     621        case GIMOSID_OSX_108_64:
     622        case GIMOSID_OSX_109:
     623        case GIMOSID_OSX_109_64:
     624        {
     625            return true;
     626        }
     627
     628        default:    /* shut up gcc */
     629            break;
     630    }
     631    return false;
     632}
     633
  • trunk/src/VBox/VMM/VMMR3/GIMMinimal.cpp

    r51731 r51797  
    2020*******************************************************************************/
    2121#define LOG_GROUP LOG_GROUP_GIM
    22 #include "GIMMinimalInternal.h"
    2322#include "GIMInternal.h"
    2423
    2524#include <iprt/assert.h>
    2625#include <iprt/err.h>
     26#include <iprt/asm-amd64-x86.h>
    2727
    2828#include <VBox/vmm/cpum.h>
     
    3333*******************************************************************************/
    3434
    35 VMMR3_INT_DECL(int) GIMR3MinimalInit(PVM pVM)
     35VMMR3_INT_DECL(int) GIMR3MinimalInit(PVM pVM, GIMOSID enmGuest)
    3636{
    3737    AssertReturn(pVM, VERR_INVALID_PARAMETER);
     
    3939
    4040    /*
    41      * Enable the Hypervisor Present and MWait Extensions bits.
     41     * Enable the Hypervisor Present.
    4242     */
    4343    CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_HVP);
    44     CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_MWAIT_EXTS);
     44
     45    if (GIMR3IsOSXGuest(enmGuest))
     46    {
     47        /*
     48         * Enable MWAIT Extensions for OS X Guests.
     49         */
     50        CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_MWAIT_EXTS);
     51
     52        /*
     53         * Fake the CPU family/model so the guest works. This is partly because older
     54         * Mac releases really doesn't work on newer CPUs, and partly because OS X
     55         * expects more from systems with newer CPUs (MSRs, power features etc.)
     56         */
     57        if (CPUMGetGuestCpuVendor(pVM) == CPUMCPUVENDOR_INTEL)
     58        {
     59            uint32_t uMaxIntelFamilyModelStep = UINT32_MAX;
     60            switch (enmGuest)
     61            {
     62                case GIMOSID_OSX:
     63                case GIMOSID_OSX_64:
     64                    uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 7); /* Penryn / X5482. */
     65                    break;
     66                case GIMOSID_OSX_106:
     67                case GIMOSID_OSX_106_64:
     68                    uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 7); /* Penryn / X5482 */
     69                    break;
     70                case GIMOSID_OSX_107:
     71                case GIMOSID_OSX_107_64:
     72                    /** @todo Figure out what is required here. */
     73                    uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 7); /* Penryn / X5482 */
     74                    break;
     75                case GIMOSID_OSX_108:
     76                case GIMOSID_OSX_108_64:
     77                    /** @todo Figure out what is required here. */
     78                    uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 7); /* Penryn / X5482 */
     79                    break;
     80                case GIMOSID_OSX_109:
     81                case GIMOSID_OSX_109_64:
     82                    /** @todo Figure out what is required here. */
     83                    uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 7); /* Penryn / X5482 */
     84                    break;
     85
     86                default:    /* shut up gcc */
     87                    break;
     88            }
     89
     90            if (uMaxIntelFamilyModelStep != UINT32_MAX)
     91            {
     92                CPUMCPUIDLEAF Leaf;
     93                int rc = CPUMR3CpuIdGetLeaf(pVM, &Leaf, 1, 0);
     94                if (RT_SUCCESS(rc))
     95                {
     96                    uint32_t uCurIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(ASMGetCpuStepping(Leaf.uEax),
     97                                                                            ASMGetCpuModelIntel(Leaf.uEax),
     98                                                                            ASMGetCpuFamily(Leaf.uEax),
     99                                                                            0);
     100                    if (uMaxIntelFamilyModelStep < uCurIntelFamilyModelStep)
     101                    {
     102                        uint32_t uNew = Leaf.uEax & UINT32_C(0xf0003000);
     103                        uNew |=  RT_BYTE1(uMaxIntelFamilyModelStep) & 0xf;       /* stepping */
     104                        uNew |= (RT_BYTE2(uMaxIntelFamilyModelStep) & 0xf) << 4; /* 4 low model bits */
     105                        uNew |= (RT_BYTE2(uMaxIntelFamilyModelStep) >> 4) << 16; /* 4 high model bits */
     106                        uNew |= (RT_BYTE3(uMaxIntelFamilyModelStep) & 0xf) << 8; /* 4 low family bits */
     107                        /* 8 high family bits, Intel's suggested calculation. */
     108                        if (RT_BYTE3(uMaxIntelFamilyModelStep) > 0xf)
     109                        {
     110                            uNew |= (  (RT_BYTE3(uMaxIntelFamilyModelStep)
     111                                     - (RT_BYTE3(uMaxIntelFamilyModelStep) & 0xf)) & 0xff ) << 20;
     112                        }
     113
     114                        LogRel(("GIM: Minimal: CPUID(0).EAX %#x -> %#x (uMaxIntelFamilyModelStep=%#x, uCurIntelFamilyModelStep=%#x\n",
     115                                Leaf.uEax, uNew, uMaxIntelFamilyModelStep, uCurIntelFamilyModelStep));
     116                        Leaf.uEax = uNew;
     117                    }
     118
     119                    rc = CPUMR3CpuIdInsert(pVM, &Leaf);
     120                    if (RT_FAILURE(rc))
     121                    {
     122                        LogRel(("GIM: Minimal: Failed to insert CPUID leaf for OS X guest. rc=%Rrc\n", rc));
     123                        return rc;
     124                    }
     125                }
     126                else
     127                {
     128                    LogRel(("GIM: Minimal: Failed to retreive std. CPUID leaf. rc=%Rrc\n", rc));
     129                    return rc;
     130                }
     131            }
     132        }
     133    }
    45134
    46135    /** @todo Register CPUID leaves, MSR ranges with CPUM. */
     136    /** -XXX_ CPUMGetGuestCpuId CPUMGetGuestCpuVendor CPUMR3CpuIdInsert  */
    47137    return VINF_SUCCESS;
    48138}
  • trunk/src/VBox/VMM/include/GIMInternal.h

    r51643 r51797  
    2121#include <VBox/vmm/gim.h>
    2222#include "GIMHvInternal.h"
     23#include "GIMMinimalInternal.h"
    2324
    2425RT_C_DECLS_BEGIN
     
    9697VMMR3_INT_DECL(int)           GIMR3Mmio2HandlerPhysicalRegister(PVM pVM, PGIMMMIO2REGION pRegion);
    9798VMMR3_INT_DECL(int)           GIMR3Mmio2HandlerPhysicalDeregister(PVM pVM, PGIMMMIO2REGION pRegion);
     99VMMR3_INT_DECL(bool)          GIMR3IsOSXGuest(GIMOSID enmGuestOs);
    98100#endif /* IN_RING3 */
    99101
  • trunk/src/VBox/VMM/include/GIMMinimalInternal.h

    r50994 r51797  
    2525
    2626#ifdef IN_RING3
    27 VMMR3_INT_DECL(int)         GIMR3MinimalInit(PVM pVM);
     27VMMR3_INT_DECL(int)         GIMR3MinimalInit(PVM pVM, GIMOSID enmGuest);
    2828VMMR3_INT_DECL(void)        GIMR3MinimalRelocate(PVM pVM, RTGCINTPTR offDelta);
    2929#endif /* IN_RING3 */
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