VirtualBox

Changeset 6322

Show
Ignore:
Timestamp:
01/10/08 12:03:56 (11 months ago)
Author:
vboxsync
Message:

Added code to optionally load system and/or network ROM from external file (selected via setextradata).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/VBox/Devices/PC/DevPcBios.cpp

    r6309 r6322  
    8484    /** The name of the logo file. */ 
    8585    char           *pszLogoFile; 
     86    /** The system BIOS ROM data. */ 
     87    uint8_t        *pu8PcBios; 
     88    /** The size of the system BIOS ROM. */ 
     89    uint64_t        cbPcBios; 
     90    /** The name of the BIOS ROM file. */ 
     91    char           *pszPcBiosFile; 
    8692    /** The LAN boot ROM data. */ 
    8793    uint8_t        *pu8LanBoot; 
     
    10221028     */ 
    10231029    uint8_t abBuf[PAGE_SIZE]; 
     1030    const uint8_t *pu8PcBiosBinary; 
     1031    uint64_t cbPcBiosBinary; 
     1032 
     1033    /* Work with either built-in ROM image or one loaded from file. 
     1034     */ 
     1035    if (pData->pu8PcBios == NULL) 
     1036    { 
     1037        pu8PcBiosBinary = g_abPcBiosBinary; 
     1038        cbPcBiosBinary  = g_cbPcBiosBinary; 
     1039    }  
     1040    else  
     1041    { 
     1042        pu8PcBiosBinary = pData->pu8PcBios; 
     1043        cbPcBiosBinary  = pData->cbPcBios; 
     1044    } 
     1045    Assert(pu8PcBiosBinary); 
     1046    Assert(cbPcBiosBinary); 
    10241047 
    10251048    /* the low ROM mapping. */ 
    1026     unsigned cb = RT_MIN(g_cbPcBiosBinary, 128 * _1K); 
     1049    unsigned cb = RT_MIN(cbPcBiosBinary, 128 * _1K); 
    10271050    RTGCPHYS GCPhys = 0x00100000 - cb; 
    1028     const uint8_t *pbVirgin = &g_abPcBiosBinary[g_cbPcBiosBinary - cb]; 
     1051    const uint8_t *pbVirgin = &pu8PcBiosBinary[cbPcBiosBinary - cb]; 
    10291052    while (GCPhys < 0x00100000) 
    10301053    { 
     
    10451068 
    10461069    /* the high ROM mapping. */ 
    1047     GCPhys = UINT32_C(0xffffffff) - (g_cbPcBiosBinary - 1); 
    1048     pbVirgin = &g_abPcBiosBinary[0]; 
    1049     while (pbVirgin < &g_abPcBiosBinary[g_cbPcBiosBinary]) 
     1070    GCPhys = UINT32_C(0xffffffff) - (cbPcBiosBinary - 1); 
     1071    pbVirgin = &pu8PcBiosBinary[0]; 
     1072    while (pbVirgin < &pu8PcBiosBinary[cbPcBiosBinary]) 
    10501073    { 
    10511074        PDMDevHlpPhysRead(pDevIns, GCPhys, abBuf, PAGE_SIZE); 
     
    10861109     * Free MM heap pointers. 
    10871110     */ 
     1111    if (pData->pu8PcBios) 
     1112    { 
     1113        MMR3HeapFree(pData->pu8PcBios); 
     1114        pData->pu8PcBios = NULL; 
     1115    } 
     1116 
     1117    if (pData->pszPcBiosFile) 
     1118    { 
     1119        MMR3HeapFree(pData->pszPcBiosFile); 
     1120        pData->pszPcBiosFile = NULL; 
     1121    } 
     1122 
    10881123    if (pData->pu8LanBoot) 
    10891124    { 
     
    11901225                              "ShowBootMenu\0" 
    11911226                              "DelayBoot\0" 
     1227                              "BiosRom\0" 
    11921228                              "LanBootRom\0" 
    11931229                              "PXEDebug\0" 
     
    12761312 
    12771313    /* 
     1314     * Get the system BIOS ROM file name. 
     1315     */ 
     1316    rc = CFGMR3QueryStringAlloc(pCfgHandle, "BiosRom", &pData->pszPcBiosFile); 
     1317    if (rc == VERR_CFGM_VALUE_NOT_FOUND) 
     1318    { 
     1319        pData->pszPcBiosFile = NULL; 
     1320        rc = VINF_SUCCESS; 
     1321    } 
     1322    else if (VBOX_FAILURE(rc)) 
     1323        return PDMDEV_SET_ERROR(pDevIns, rc, 
     1324                                N_("Configuration error: Querying \"BiosRom\" as a string failed")); 
     1325    else if (!*pData->pszPcBiosFile) 
     1326    { 
     1327        MMR3HeapFree(pData->pszPcBiosFile); 
     1328        pData->pszPcBiosFile = NULL; 
     1329    } 
     1330 
     1331    const uint8_t *pu8PcBiosBinary = NULL; 
     1332    uint64_t cbPcBiosBinary; 
     1333    /* 
     1334     * Determine the system BIOS ROM size, open specified ROM file in the process. 
     1335     */ 
     1336    RTFILE FilePcBios = NIL_RTFILE; 
     1337    if (pData->pszPcBiosFile) 
     1338    { 
     1339        rc = RTFileOpen(&FilePcBios, pData->pszPcBiosFile, 
     1340                        RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE); 
     1341        if (VBOX_SUCCESS(rc)) 
     1342        { 
     1343            rc = RTFileGetSize(FilePcBios, &pData->cbPcBios); 
     1344            if (VBOX_SUCCESS(rc)) 
     1345            { 
     1346                /* The following checks should be in sync the AssertReleaseMsg's below. */ 
     1347                if (    RT_ALIGN(pData->cbPcBios, _64K) != pData->cbPcBios 
     1348                    ||  pData->cbPcBios > 32 * _64K 
     1349                    ||  pData->cbPcBios < _64K) 
     1350                    rc = VERR_TOO_MUCH_DATA; 
     1351            } 
     1352        } 
     1353        if (VBOX_FAILURE(rc)) 
     1354        { 
     1355            /* 
     1356             * In case of failure simply fall back to the built-in BIOS ROM. 
     1357             */ 
     1358            Log(("pcbiosConstruct: Failed to open system BIOS ROM file '%s', rc=%Vrc!\n", pData->pszPcBiosFile, rc)); 
     1359            RTFileClose(FilePcBios); 
     1360            FilePcBios = NIL_RTFILE; 
     1361            MMR3HeapFree(pData->pszPcBiosFile); 
     1362            pData->pszPcBiosFile = NULL; 
     1363        } 
     1364    } 
     1365 
     1366    /* 
     1367     * Attempt to get the system BIOS ROM data from file. 
     1368     */ 
     1369    if (pData->pszPcBiosFile) 
     1370    { 
     1371        /* 
     1372         * Allocate buffer for the system BIOS ROM data. 
     1373         */ 
     1374        pData->pu8PcBios = (uint8_t *)PDMDevHlpMMHeapAlloc(pDevIns, pData->cbPcBios); 
     1375        if (pData->pu8PcBios) 
     1376        { 
     1377            rc = RTFileRead(FilePcBios, pData->pu8PcBios, pData->cbPcBios, NULL); 
     1378            if (VBOX_FAILURE(rc)) 
     1379            { 
     1380                AssertMsgFailed(("RTFileRead(,,%d,NULL) -> %Vrc\n", pData->cbPcBios, rc)); 
     1381                MMR3HeapFree(pData->pu8PcBios); 
     1382                pData->pu8PcBios = NULL; 
     1383            } 
     1384            rc = VINF_SUCCESS; 
     1385        } 
     1386        else 
     1387            rc = VERR_NO_MEMORY; 
     1388    } 
     1389    else 
     1390        pData->pu8PcBios = NULL; 
     1391 
     1392    /* cleanup */ 
     1393    if (FilePcBios != NIL_RTFILE) 
     1394        RTFileClose(FilePcBios); 
     1395 
     1396    /* If we were unable to get the data from file for whatever reason, fall 
     1397     * back to the built-in ROM image. 
     1398     */ 
     1399    if (pData->pu8PcBios == NULL) 
     1400    { 
     1401        pu8PcBiosBinary = g_abPcBiosBinary; 
     1402        cbPcBiosBinary  = g_cbPcBiosBinary; 
     1403    }  
     1404    else  
     1405    { 
     1406        pu8PcBiosBinary = pData->pu8PcBios; 
     1407        cbPcBiosBinary  = pData->cbPcBios; 
     1408    } 
     1409 
     1410    /* 
    12781411     * Map the BIOS into memory. 
    12791412     * There are two mappings: 
     
    12821415     *      2. 0xfffxxxxx to 0xffffffff contains the entire bios. 
    12831416     */ 
    1284     AssertReleaseMsg(g_cbPcBiosBinary >= _64K, ("g_cbPcBiosBinary=%#x\n", g_cbPcBiosBinary)); 
    1285     AssertReleaseMsg(RT_ALIGN_Z(g_cbPcBiosBinary, _64K) == g_cbPcBiosBinary, 
    1286                      ("g_cbPcBiosBinary=%#x\n", g_cbPcBiosBinary)); 
    1287     cb = RT_MIN(g_cbPcBiosBinary, 128 * _1K); 
    1288     rc = PDMDevHlpROMRegister(pDevIns, 0x00100000 - cb, cb, &g_abPcBiosBinary[g_cbPcBiosBinary - cb], 
     1417    AssertReleaseMsg(cbPcBiosBinary >= _64K, ("cbPcBiosBinary=%#x\n", cbPcBiosBinary)); 
     1418    AssertReleaseMsg(RT_ALIGN_Z(cbPcBiosBinary, _64K) == cbPcBiosBinary, 
     1419                     ("cbPcBiosBinary=%#x\n", cbPcBiosBinary)); 
     1420    cb = RT_MIN(cbPcBiosBinary, 128 * _1K); /* Effectively either 64 or 128K. */ 
     1421    rc = PDMDevHlpROMRegister(pDevIns, 0x00100000 - cb, cb, &pu8PcBiosBinary[cbPcBiosBinary - cb],  
    12891422                              false /* fShadow */, "PC BIOS - 0xfffff"); 
    12901423    if (VBOX_FAILURE(rc)) 
    12911424        return rc; 
    1292     rc = PDMDevHlpROMRegister(pDevIns, (uint32_t)-g_cbPcBiosBinary, g_cbPcBiosBinary, &g_abPcBiosBinary[0], 
     1425    rc = PDMDevHlpROMRegister(pDevIns, (uint32_t)-(int32_t)cbPcBiosBinary, cbPcBiosBinary, pu8PcBiosBinary,  
    12931426                              false /* fShadow */, "PC BIOS - 0xffffffff"); 
    12941427    if (VBOX_FAILURE(rc)) 
     
    14461579    } 
    14471580 
    1448     const uint8_t *pu8LanBoot = NULL; 
    14491581    uint64_t cbFileLanBoot; 
    1450 #ifdef VBOX_DO_NOT_LINK_LANBOOT 
     1582    const uint8_t *pu8LanBootBinary = NULL; 
     1583    uint64_t cbLanBootBinary; 
     1584 
    14511585    /* 
    14521586     * Determine the LAN boot ROM size, open specified ROM file in the process. 
     
    14631597            { 
    14641598                if (    RT_ALIGN(cbFileLanBoot, _4K) != cbFileLanBoot 
    1465                     ||  cbFileLanBoot > _32K) 
     1599                    ||  cbFileLanBoot > _64K) 
    14661600                    rc = VERR_TOO_MUCH_DATA; 
    14671601            } 
     
    14701604        { 
    14711605            /* 
    1472              * Ignore failure and fall back to no LAN boot ROM. 
     1606             * Ignore failure and fall back to the built-in LAN boot ROM. 
    14731607             */ 
    14741608            Log(("pcbiosConstruct: Failed to open LAN boot ROM file '%s', rc=%Vrc!\n", pData->pszLanBootFile, rc)); 
     
    14881622         * Allocate buffer for the LAN boot ROM data. 
    14891623         */ 
    1490         pu8LanBoot = (uint8_t *)PDMDevHlpMMHeapAlloc(pDevIns, cbFileLanBoot); 
    1491         pData->pu8LanBoot = pu8LanBoot; 
    1492         if (pu8LanBoot) 
     1624        pData->pu8LanBoot = (uint8_t *)PDMDevHlpMMHeapAlloc(pDevIns, cbFileLanBoot); 
     1625        if (pData->pu8LanBoot) 
    14931626        { 
    14941627            rc = RTFileRead(FileLanBoot, pData->pu8LanBoot, cbFileLanBoot, NULL); 
     
    14961629            { 
    14971630                AssertMsgFailed(("RTFileRead(,,%d,NULL) -> %Vrc\n", cbFileLanBoot, rc)); 
    1498                 MMR3HeapFree(pu8LanBoot); 
    1499                 pu8LanBoot = NULL; 
     1631                MMR3HeapFree(pData->pu8LanBoot); 
    15001632                pData->pu8LanBoot = NULL; 
    15011633            } 
     
    15121644        RTFileClose(FileLanBoot); 
    15131645 
    1514 #else /* !VBOX_DO_NOT_LINK_LANBOOT */ 
    1515     pData->pu8LanBoot = NULL; 
    1516     pu8LanBoot = g_abNetBiosBinary; 
    1517     cbFileLanBoot = g_cbNetBiosBinary; 
    1518 #endif /* !VBOX_DO_NOT_LINK_LANBOOT */ 
     1646    /* If we were unable to get the data from file for whatever reason, fall 
     1647     * back to the built-in LAN boot ROM image. 
     1648     */ 
     1649    if (pData->pu8LanBoot == NULL) 
     1650    { 
     1651        pu8LanBootBinary = g_abNetBiosBinary; 
     1652        cbLanBootBinary  = g_cbNetBiosBinary; 
     1653    }  
     1654    else  
     1655    { 
     1656        pu8LanBootBinary = pData->pu8LanBoot; 
     1657        cbLanBootBinary  = cbFileLanBoot; 
     1658    } 
    15191659 
    15201660    /* 
     
    15231663     * the (up to) 32 kb ROM image. 
    15241664     */ 
    1525     if (pu8LanBoot
    1526         rc = PDMDevHlpROMRegister(pDevIns, VBOX_LANBOOT_SEG << 4, cbFileLanBoot, pu8LanBoot, 
     1665    if (pu8LanBootBinary
     1666        rc = PDMDevHlpROMRegister(pDevIns, VBOX_LANBOOT_SEG << 4, cbLanBootBinary, pu8LanBootBinary,  
    15271667                                  true /* fShadow */, "Net Boot ROM"); 
    15281668 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy