VirtualBox

Changeset 42443 in vbox for trunk/src


Ignore:
Timestamp:
Jul 30, 2012 5:05:12 AM (12 years ago)
Author:
vboxsync
Message:

EFI/OVMF: some clean up.

File:
1 edited

Legend:

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

    r42397 r42443  
    55
    66/*
    7  * Copyright (C) 2006-2009 Oracle Corporation
     7 * Copyright (C) 2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    358358            {
    359359                case EFI_PANIC_CMD_BAD_ORG:
    360 #if 0
    361                     LogRel(("EFI Panic: You have to fix ORG offset in EfiThunk.asm! Must be 0x%x\n",
    362                             g_cbEfiThunkBinary));
    363                     RTAssertMsg2Weak("Fix ORG offset in EfiThunk.asm: must be 0x%x\n",
    364                                      g_cbEfiThunkBinary);
    365                     break;
    366 #endif
    367 
    368360                case EFI_PANIC_CMD_THUNK_TRAP:
    369361                    LogRel(("EFI Panic: Unexpected trap!!\n"));
     
    577569        pFfsFile = (EFI_FFS_FILE_HEADER *)((uintptr_t)pFfsFile + RT_ALIGN(FFS_SIZE(pFfsFile), 8));
    578570    }
     571#undef FFS_SIZE
    579572    return NULL;
    580573}
     
    614607    pThis->GCLoadAddress = UINT32_C(0xfffff000) - pThis->cbEfiRom + PAGE_SIZE;
    615608
    616 #if 0
    617     /*
    618      * Ffs files are stored one by one, so to find SECURITY_CORE we've to
    619      * search thru every one on the way.
    620      */
    621     uint32_t                    cbFfsFile = 0;  /* shut up gcc */
    622     EFI_FFS_FILE_HEADER const  *pFfsFile  = (EFI_FFS_FILE_HEADER const *)(pThis->pu8EfiRom + pFwVolHdr->HeaderLength);
    623     pFfsFile = efiFwVolFindFileByType(pFfsFile, pbFwVolEnd, EFI_FV_FILETYPE_SECURITY_CORE, &cbFfsFile);
    624     AssertLogRelMsgReturn(pFfsFile, ("No SECURITY_CORE found in the firmware volume\n"), VERR_FILE_NOT_FOUND);
    625 
    626     RTGCPHYS ImageBase = NIL_RTGCPHYS;
    627     uint8_t *pbImage = NULL;
    628     pThis->GCEntryPoint0 = efiFindRelativeAddressOfEPAndBaseAddressOfModule(pFfsFile, cbFfsFile, &ImageBase, &pbImage);
    629     pThis->GCEntryPoint0 += pbImage - pThis->pu8EfiRom;
    630     Assert(pThis->pu8EfiRom <= pbImage);
    631     Assert(pbImage < pThis->pu8EfiRom + pThis->cbEfiRom);
    632     /*
    633      * Calc the firmware load address from the image base and validate it.
    634      */
    635     pThis->GCLoadAddress = ImageBase - (pbImage - pThis->pu8EfiRom);
    636     pThis->GCEntryPoint0 += pThis->GCLoadAddress;
    637     AssertLogRelMsgReturn(~(pThis->GCLoadAddress & PAGE_OFFSET_MASK),
    638                           ("%RGp\n", pThis->GCLoadAddress),
    639                           VERR_INVALID_PARAMETER);
    640     AssertLogRelMsgReturn(pThis->GCLoadAddress > UINT32_C(0xf0000000),
    641                           ("%RGp\n", pThis->GCLoadAddress),
    642                           VERR_OUT_OF_RANGE);
    643     AssertLogRelMsgReturn(   pThis->GCLoadAddress + (pThis->cbEfiRom - 1) > UINT32_C(0xf0000000)
    644                           && pThis->GCLoadAddress + (pThis->cbEfiRom - 1) < UINT32_C(0xffffe000),
    645                           ("%RGp + %RX64\n", pThis->GCLoadAddress, pThis->cbEfiRom),
    646                           VERR_OUT_OF_RANGE);
    647 
    648     LogRel(("EFI: Firmware volume loading at %RGp, SEC CORE at %RGp with EP at %RGp\n",
    649             pThis->GCLoadAddress, ImageBase, pThis->GCEntryPoint0));
    650 
    651     pFfsFile = efiFwVolFindFileByType(pFfsFile, pbFwVolEnd, EFI_FV_FILETYPE_PEI_CORE, &cbFfsFile);
    652     pThis->GCEntryPoint1 = efiFindRelativeAddressOfEPAndBaseAddressOfModule(pFfsFile, cbFfsFile, NULL, &pbImage);
    653     pThis->GCEntryPoint1 += pThis->GCLoadAddress;
    654     pThis->GCEntryPoint1 += pbImage - pThis->pu8EfiRom;
    655     LogRel(("EFI: Firmware volume loading at %RGp, PEI CORE at with EP at %RGp\n",
    656             pThis->GCLoadAddress, pThis->GCEntryPoint1));
    657 #endif
    658609    return VINF_SUCCESS;
    659610}
     
    739690    return VINF_SUCCESS;
    740691}
    741 
    742 #if 0
    743 /**
    744  * Patches and loads the EfiThunk ROM image.
    745  *
    746  * The thunk image is where the CPU starts and will switch it into
    747  * 32-bit protected or long mode and invoke the SEC CORE image in the
    748  * firmware volume. It also contains some static VM configuration data
    749  * at the very beginning of the page, see DEVEFIINFO.
    750  *
    751  * @returns VBox status code.
    752  * @param   pThis       The device instance data.
    753  * @param   pCfg        Configuration node handle for the device.
    754  */
    755 static int efiLoadThunk(PDEVEFI pThis, PCFGMNODE pCfg)
    756 {
    757     uint8_t f64BitEntry = 0;
    758     int rc;
    759 
    760     rc = CFGMR3QueryU8Def(pCfg, "64BitEntry", &f64BitEntry, 0);
    761     if (RT_FAILURE (rc))
    762         return PDMDEV_SET_ERROR(pThis->pDevIns, rc,
    763                                 N_("Configuration error: Failed to read \"64BitEntry\""));
    764 
    765     /*
    766      * Make a copy of the page and set the values of the DEVEFIINFO structure
    767      * found at the beginning of it.
    768      */
    769 
    770     if (f64BitEntry)
    771         LogRel(("Using 64-bit EFI firmware\n"));
    772 
    773     /* Duplicate the page so we can change it. */
    774     AssertRelease(g_cbEfiThunkBinary == PAGE_SIZE);
    775     pThis->pu8EfiThunk = (uint8_t *)PDMDevHlpMMHeapAlloc(pThis->pDevIns, PAGE_SIZE);
    776     if (pThis->pu8EfiThunk == NULL)
    777         return VERR_NO_MEMORY;
    778     memcpy(pThis->pu8EfiThunk, &g_abEfiThunkBinary[0], PAGE_SIZE);
    779 
    780     /* Fill in the info. */
    781     PDEVEFIINFO pEfiInfo = (PDEVEFIINFO)pThis->pu8EfiThunk;
    782     pEfiInfo->pfnFirmwareEP = (uint32_t)pThis->GCEntryPoint0;
    783     //AssertRelease(pEfiInfo->pfnFirmwareEP == pThis->GCEntryPoint0);
    784     pEfiInfo->HighEPAddress = 0;
    785     pEfiInfo->PhysFwVol     = pThis->GCLoadAddress;
    786     pEfiInfo->cbFwVol       = (uint32_t)pThis->cbEfiRom;
    787     AssertRelease(pEfiInfo->cbFwVol == (uint32_t)pThis->cbEfiRom);
    788     pEfiInfo->cbBelow4GB    = pThis->cbBelow4GB;
    789     pEfiInfo->cbAbove4GB    = pThis->cbAbove4GB;
    790     /* zeroth bit controls use of 64-bit entry point in fw */
    791     pEfiInfo->fFlags        = f64BitEntry ? 1 : 0;
    792     pEfiInfo->cCpus         = pThis->cCpus;
    793     pEfiInfo->pfnPeiEP      = (uint32_t)pThis->GCEntryPoint1;
    794     pEfiInfo->u32Reserved2  = 0;
    795 
    796     /* Register the page as a ROM (data will be copied). */
    797     rc = PDMDevHlpROMRegister(pThis->pDevIns, UINT32_C(0xfffff000), PAGE_SIZE,
    798                               pThis->pu8EfiThunk, PAGE_SIZE,
    799                               PGMPHYS_ROM_FLAGS_PERMANENT_BINARY, "EFI Thunk");
    800     if (RT_FAILURE(rc))
    801         return rc;
    802 
    803 #if 1    /** @todo this is probably not necessary. */
    804     /*
    805      * Map thunk page also at low address, so that real->protected mode jump code can
    806      * store GDT/IDT in code segment in low memory and load them during switch to the
    807      * protected mode, while being in 16-bits mode.
    808      *
    809      * @todo: maybe need to unregister later or place somewhere else (although could
    810      *        be needed during reset)
    811      */
    812     rc = PDMDevHlpROMRegister(pThis->pDevIns, 0xff000, PAGE_SIZE,
    813                               pThis->pu8EfiThunk, PAGE_SIZE,
    814                               PGMPHYS_ROM_FLAGS_PERMANENT_BINARY, "EFI Thunk (2)");
    815     if (RT_FAILURE(rc))
    816         return rc;
    817 #endif
    818 
    819     return rc;
    820 }
    821 #endif
    822 
    823692
    824693static uint8_t efiGetHalfByte(char ch)
     
    1042911     */
    1043912    // @todo: we need to have VMM API to access TSC increase speed, for now provide reasonable default
    1044     pThis->u64TscFrequency = RTMpGetMaxFrequency(0) * 1024 * 1024;// TMCpuTicksPerSecond(PDMDevHlpGetVM(pDevIns));
     913    pThis->u64TscFrequency = RTMpGetMaxFrequency(0) * 1000 * 1000;// TMCpuTicksPerSecond(PDMDevHlpGetVM(pDevIns));
    1045914    if (pThis->u64TscFrequency == 0)
    1046915        pThis->u64TscFrequency = UINT64_C(2500000000);
     
    1088957    if (RT_FAILURE(rc))
    1089958        return rc;
    1090 
    1091 #if 0
    1092     rc = efiLoadThunk(pThis, pCfg);
    1093     if (RT_FAILURE(rc))
    1094         return rc;
    1095 #endif
    1096959
    1097960    /*
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