VirtualBox

Changeset 44547 in vbox


Ignore:
Timestamp:
Feb 5, 2013 3:27:45 PM (12 years ago)
Author:
vboxsync
Message:

DevEFI.cpp: Updates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/DevEFI.cpp

    r44528 r44547  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    7878    /** Thunk page pointer. */
    7979    uint8_t        *pu8EfiThunk;
    80     /** First entry point of the EFI firmware */
     80    /** First entry point of the EFI firmware. */
    8181    RTGCPHYS        GCEntryPoint0;
    82     /* Second Entry Point (PeiCore)*/
     82    /** Second Entry Point (PeiCore)*/
    8383    RTGCPHYS        GCEntryPoint1;
    84     /** EFI firmware physical load address */
     84    /** EFI firmware physical load address. */
    8585    RTGCPHYS        GCLoadAddress;
    86     /** Current info selector */
     86    /** Current info selector. */
    8787    uint32_t        iInfoSelector;
    88     /** Current info position */
    89     int32_t         iInfoPosition;
     88    /** Current info position. */
     89    int32_t         offInfo;
    9090
    9191    /** Number of virtual CPUs. (Config) */
     
    9595    /** RAM above 4GB (in bytes). (Config) */
    9696    uint64_t        cbAbove4GB;
    97 
     97    /** The total amount of memory. */
    9898    uint64_t        cbRam;
    99 
     99    /** The size of the RAM hole below 4GB. */
    100100    uint64_t        cbRamHole;
    101101
    102     /** The size of the DMI tables */
     102    /** The size of the DMI tables. */
    103103    uint16_t        cbDmiTables;
    104104    /** The DMI tables. */
     
    108108    uint8_t         u8IOAPIC;
    109109
    110     /* Boot parameters passed to the firmware */
     110    /** Boot parameters passed to the firmware. */
    111111    char            szBootArgs[256];
    112112
    113     /* Host UUID (for DMI) */
     113    /** Host UUID (for DMI). */
    114114    RTUUID          aUuid;
    115115
    116     /* Device properties buffer */
    117     uint8_t*        pu8DeviceProps;
    118     /* Device properties buffer size */
    119     uint32_t        u32DevicePropsLen;
    120 
    121     /* Virtual machine front side bus frequency */
     116    /** Device properties buffer. */
     117    R3PTRTYPE(uint8_t *)    pbDeviceProps;
     118    /** Device properties buffer size. */
     119    uint32_t                cbDeviceProps;
     120
     121    /** Virtual machine front side bus frequency. */
    122122    uint64_t        u64FsbFrequency;
    123     /* Virtual machine time stamp counter frequency */
     123    /** Virtual machine time stamp counter frequency. */
    124124    uint64_t        u64TscFrequency;
    125     /* Virtual machine CPU frequency */
     125    /** Virtual machine CPU frequency. */
    126126    uint64_t        u64CpuFrequency;
    127     /* GOP mode */
     127    /** GOP mode. */
    128128    uint32_t        u32GopMode;
    129     /* Uga mode resolutions */
    130     uint32_t        u32UgaHorisontal;
    131     uint32_t        u32UgaVertical;
     129    /** Uga mode horisontal resolution. */
     130    uint32_t        cxUgaResolution;
     131    /** Uga mode vertical resolution. */
     132    uint32_t        cyUgaResolution;
    132133} DEVEFI;
    133134typedef DEVEFI *PDEVEFI;
     
    147148
    148149
     150
     151/**
     152 * Gets the info item size.
     153 *
     154 * @returns Size in bytes, UINT32_MAX on error.
     155 * @param   pThis               .
     156 */
    149157static uint32_t efiInfoSize(PDEVEFI pThis)
    150158{
     
    162170            return 4;
    163171        case EFI_INFO_INDEX_BOOT_ARGS:
    164             return (uint32_t)RTStrNLen(pThis->szBootArgs,
    165                                        sizeof pThis->szBootArgs) + 1;
     172            return (uint32_t)RTStrNLen(pThis->szBootArgs, sizeof(pThis->szBootArgs)) + 1;
    166173        case EFI_INFO_INDEX_DEVICE_PROPS:
    167             return pThis->u32DevicePropsLen;
     174            return pThis->cbDeviceProps;
    168175        case EFI_INFO_INDEX_FSB_FREQUENCY:
    169176        case EFI_INFO_INDEX_CPU_FREQUENCY:
     
    171178            return 8;
    172179    }
    173     Assert(false);
    174     return 0;
    175 }
    176 
     180    return UINT32_MAX;
     181}
     182
     183
     184/**
     185 * efiInfoNextByte for a uint64_t value.
     186 *
     187 * @returns Next (current) byte.
     188 * @param   pThis               The EFI instance data.
     189 * @param   u64                 The value.
     190 */
     191static uint8_t efiInfoNextByteU64(PDEVEFI pThis, uint64_t u64)
     192{
     193    uint64_t off = pThis->offInfo;
     194    if (off >= 4)
     195        return 0;
     196    return (uint8_t)(off >> (off * 8));
     197}
     198
     199/**
     200 * efiInfoNextByte for a uint32_t value.
     201 *
     202 * @returns Next (current) byte.
     203 * @param   pThis               The EFI instance data.
     204 * @param   u32                 The value.
     205 */
     206static uint8_t efiInfoNextByteU32(PDEVEFI pThis, uint32_t u32)
     207{
     208    uint32_t off = pThis->offInfo;
     209    if (off >= 4)
     210        return 0;
     211    return (uint8_t)(off >> (off * 8));
     212}
     213
     214/**
     215 * efiInfoNextByte for a buffer.
     216 *
     217 * @returns Next (current) byte.
     218 * @param   pThis               The EFI instance data.
     219 * @param   pvBuf               The buffer.
     220 * @param   cbBuf               The buffer size.
     221 */
     222static uint8_t efiInfoNextByteBuf(PDEVEFI pThis, void const *pvBuf, size_t cbBuf)
     223{
     224    uint32_t off = pThis->offInfo;
     225    if (off >= cbBuf)
     226        return 0;
     227    return ((uint8_t const *)pvBuf)[off];
     228}
     229
     230/**
     231 * Gets the next info byte.
     232 *
     233 * @returns Next (current) byte.
     234 * @param   pThis               The EFI instance data.
     235 */
    177236static uint8_t efiInfoNextByte(PDEVEFI pThis)
    178237{
    179     union
    180     {
    181         uint32_t u32;
    182         uint64_t u64;
    183     } value;
    184 
    185238    switch (pThis->iInfoSelector)
    186239    {
    187         case EFI_INFO_INDEX_VOLUME_BASE:
    188             value.u32 = pThis->GCLoadAddress;
    189             break;
    190         case EFI_INFO_INDEX_VOLUME_SIZE:
    191             value.u32 = pThis->cbEfiRom;
    192             break;
    193         case EFI_INFO_INDEX_TEMPMEM_BASE:
    194             value.u32 = VBOX_EFI_TOP_OF_STACK; /* just after stack */
    195             break;
    196         case EFI_INFO_INDEX_TEMPMEM_SIZE:
    197             value.u32 = 512 * 1024; /* 512 K */
    198             break;
    199         case EFI_INFO_INDEX_STACK_BASE:
    200             /* Keep in sync with value in EfiThunk.asm */
    201             value.u32 = VBOX_EFI_TOP_OF_STACK - 128*1024; /* 2M - 128 K */
    202             break;
    203         case EFI_INFO_INDEX_STACK_SIZE:
    204             value.u32 = 128*1024; /* 128 K */
    205             break;
    206         case EFI_INFO_INDEX_FSB_FREQUENCY:
    207             value.u64 = pThis->u64FsbFrequency;
    208             break;
    209         case EFI_INFO_INDEX_TSC_FREQUENCY:
    210             value.u64 = pThis->u64TscFrequency;
    211             break;
    212         case EFI_INFO_INDEX_CPU_FREQUENCY:
    213             value.u64 = pThis->u64CpuFrequency;
    214             break;
    215         case EFI_INFO_INDEX_BOOT_ARGS:
    216             return pThis->szBootArgs[pThis->iInfoPosition];
    217         case EFI_INFO_INDEX_DEVICE_PROPS:
    218             return pThis->pu8DeviceProps[pThis->iInfoPosition];
    219         case EFI_INFO_INDEX_GOP_MODE:
    220             value.u32 = pThis->u32GopMode;
    221             break;
    222         case EFI_INFO_INDEX_UGA_HORISONTAL_RESOLUTION:
    223             value.u32 = pThis->u32UgaHorisontal;
    224             break;
    225         case EFI_INFO_INDEX_UGA_VERTICAL_RESOLUTION:
    226             value.u32 = pThis->u32UgaVertical;
    227             break;
     240
     241        case EFI_INFO_INDEX_VOLUME_BASE:        return efiInfoNextByteU64(pThis, pThis->GCLoadAddress);
     242        case EFI_INFO_INDEX_VOLUME_SIZE:        return efiInfoNextByteU64(pThis, pThis->cbEfiRom);
     243        case EFI_INFO_INDEX_TEMPMEM_BASE:       return efiInfoNextByteU32(pThis, VBOX_EFI_TOP_OF_STACK); /* just after stack */
     244        case EFI_INFO_INDEX_TEMPMEM_SIZE:       return efiInfoNextByteU32(pThis, _512K);
     245        case EFI_INFO_INDEX_FSB_FREQUENCY:      return efiInfoNextByteU64(pThis, pThis->u64FsbFrequency);
     246        case EFI_INFO_INDEX_TSC_FREQUENCY:      return efiInfoNextByteU64(pThis, pThis->u64TscFrequency);
     247        case EFI_INFO_INDEX_CPU_FREQUENCY:      return efiInfoNextByteU64(pThis, pThis->u64CpuFrequency);
     248        case EFI_INFO_INDEX_BOOT_ARGS:          return efiInfoNextByteBuf(pThis, pThis->szBootArgs, sizeof(pThis->szBootArgs));
     249        case EFI_INFO_INDEX_DEVICE_PROPS:       return efiInfoNextByteBuf(pThis, pThis->pbDeviceProps, pThis->cbDeviceProps);
     250        case EFI_INFO_INDEX_GOP_MODE:           return efiInfoNextByteU32(pThis, pThis->u32GopMode);
     251        case EFI_INFO_INDEX_UGA_HORISONTAL_RESOLUTION:  return efiInfoNextByteU32(pThis, pThis->cxUgaResolution);
     252        case EFI_INFO_INDEX_UGA_VERTICAL_RESOLUTION:    return efiInfoNextByteU32(pThis, pThis->cyUgaResolution);
     253
     254        /* Keep in sync with value in EfiThunk.asm */
     255        case EFI_INFO_INDEX_STACK_BASE:         return efiInfoNextByteU32(pThis,  VBOX_EFI_TOP_OF_STACK - _128K); /* 2M - 128 K */
     256        case EFI_INFO_INDEX_STACK_SIZE:         return efiInfoNextByteU32(pThis, _128K);
     257
    228258        default:
    229             Assert(false);
    230             value.u64 = 0;
    231             break;
    232     }
    233 
    234     return *((uint8_t*)&value+pThis->iInfoPosition);
     259            PDMDevHlpDBGFStop(pThis->pDevIns, RT_SRC_POS, "%#x", pThis->iInfoSelector);
     260            return 0;
     261    }
    235262}
    236263
     
    254281    {
    255282        case EFI_INFO_PORT:
    256             if (pThis->iInfoPosition == -1 && cb == 4)
     283            if (pThis->offInfo == -1 && cb == 4)
    257284            {
    258                 *pu32 = efiInfoSize(pThis);
    259                 pThis->iInfoPosition = 0;
     285                pThis->offInfo = 0;
     286                uint32_t cbInfo = *pu32 = efiInfoSize(pThis);
     287                if (cbInfo == UINT32_MAX)
     288                    return PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "iInfoSelector=%#x (%d)\n",
     289                                             pThis->iInfoSelector, pThis->iInfoSelector);
    260290            }
    261291            else
    262292            {
    263                 /* So far */
    264293                if (cb != 1)
    265294                    return VERR_IOM_IOPORT_UNUSED;
    266295                *pu32 = efiInfoNextByte(pThis);
    267                 pThis->iInfoPosition++;
     296                pThis->offInfo++;
    268297            }
    269298            return VINF_SUCCESS;
     
    271300       case EFI_PANIC_PORT:
    272301#ifdef IN_RING3
    273            LogRel(("Panic port read!\n"));
     302           LogRel(("EFI panic port read!\n"));
    274303           /* Insert special code here on panic reads */
    275304           return PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "EFI Panic: panic port read!\n");
     
    304333        case EFI_INFO_PORT:
    305334            pThis->iInfoSelector = u32;
    306             pThis->iInfoPosition = -1;
     335            pThis->offInfo      = -1;
    307336            break;
    308337        case EFI_DEBUG_PORT:
     
    466495
    467496    pThis->iInfoSelector = 0;
    468     pThis->iInfoPosition = -1;
     497    pThis->offInfo      = -1;
    469498
    470499    pThis->iMsg = 0;
     
    544573    }
    545574
    546     if (pThis->pu8DeviceProps)
    547     {
    548         MMR3HeapFree(pThis->pu8DeviceProps);
    549         pThis->pu8DeviceProps = NULL;
    550         pThis->u32DevicePropsLen = 0;
     575    if (pThis->pbDeviceProps)
     576    {
     577        MMR3HeapFree(pThis->pbDeviceProps);
     578        pThis->pbDeviceProps = NULL;
     579        pThis->cbDeviceProps = 0;
    551580    }
    552581
     
    963992
    964993
    965 static int efiParseDeviceString(PDEVEFI  pThis, char* pszDeviceProps)
     994static int efiParseDeviceString(PDEVEFI  pThis, char *pszDeviceProps)
    966995{
    967996    int         rc = 0;
     
    9721001    u32OutLen = (uint32_t)RTStrNLen(pszDeviceProps, RTSTR_MAX) / 2 + 1;
    9731002
    974     pThis->pu8DeviceProps =
    975             (uint8_t*)PDMDevHlpMMHeapAlloc(pThis->pDevIns, u32OutLen);
    976     if (!pThis->pu8DeviceProps)
     1003    pThis->pbDeviceProps = (uint8_t *)PDMDevHlpMMHeapAlloc(pThis->pDevIns, u32OutLen);
     1004    if (!pThis->pbDeviceProps)
    9771005        return VERR_NO_MEMORY;
    9781006
     
    9861014            u8Value = u8Hb << 4;
    9871015        else
    988             pThis->pu8DeviceProps[iHex++] = u8Hb | u8Value;
     1016            pThis->pbDeviceProps[iHex++] = u8Hb | u8Value;
    9891017
    9901018        Assert(iHex < u32OutLen);
     
    9931021
    9941022    Assert(iHex == 0 || fUpper);
    995     pThis->u32DevicePropsLen = iHex;
     1023    pThis->cbDeviceProps = iHex;
    9961024
    9971025    return rc;
     
    11641192    else
    11651193    {
    1166         pThis->pu8DeviceProps    = NULL;
    1167         pThis->u32DevicePropsLen = 0;
     1194        pThis->pbDeviceProps = NULL;
     1195        pThis->cbDeviceProps = 0;
    11681196    }
    11691197
     
    11921220     * Uga graphics
    11931221     */
    1194     rc = CFGMR3QueryU32(pCfg, "UgaHorizontalResolution", &pThis->u32UgaHorisontal);
    1195     AssertRC(rc);
    1196     if (pThis->u32UgaHorisontal == 0)
    1197     {
    1198         pThis->u32UgaHorisontal = 1024; /* 1024x768 */
    1199     }
    1200     rc = CFGMR3QueryU32(pCfg, "UgaVerticalResolution", &pThis->u32UgaVertical);
    1201     AssertRC(rc);
    1202     if (pThis->u32UgaVertical == 0)
    1203     {
    1204         pThis->u32UgaVertical = 768; /* 1024x768 */
    1205     }
     1222    rc = CFGMR3QueryU32Def(pCfg, "UgaHorizontalResolution", &pThis->cxUgaResolution, 0); AssertRC(rc);
     1223    if (pThis->cxUgaResolution == 0)
     1224        pThis->cxUgaResolution = 1024;  /* 1024x768 */
     1225    rc = CFGMR3QueryU32Def(pCfg, "UgaVerticalResolution", &pThis->cyUgaResolution, 0); AssertRC(rc);
     1226    if (pThis->cyUgaResolution == 0)
     1227        pThis->cyUgaResolution = 768;    /* 1024x768 */
    12061228
    12071229#ifdef DEVEFI_WITH_VBOXDBG_SCRIPT
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