Changeset 6322
- Timestamp:
- 01/10/08 12:03:56 (11 months ago)
- Files:
-
- trunk/src/VBox/Devices/PC/DevPcBios.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/VBox/Devices/PC/DevPcBios.cpp
r6309 r6322 84 84 /** The name of the logo file. */ 85 85 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; 86 92 /** The LAN boot ROM data. */ 87 93 uint8_t *pu8LanBoot; … … 1022 1028 */ 1023 1029 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); 1024 1047 1025 1048 /* the low ROM mapping. */ 1026 unsigned cb = RT_MIN( g_cbPcBiosBinary, 128 * _1K);1049 unsigned cb = RT_MIN(cbPcBiosBinary, 128 * _1K); 1027 1050 RTGCPHYS GCPhys = 0x00100000 - cb; 1028 const uint8_t *pbVirgin = & g_abPcBiosBinary[g_cbPcBiosBinary - cb];1051 const uint8_t *pbVirgin = &pu8PcBiosBinary[cbPcBiosBinary - cb]; 1029 1052 while (GCPhys < 0x00100000) 1030 1053 { … … 1045 1068 1046 1069 /* 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]) 1050 1073 { 1051 1074 PDMDevHlpPhysRead(pDevIns, GCPhys, abBuf, PAGE_SIZE); … … 1086 1109 * Free MM heap pointers. 1087 1110 */ 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 1088 1123 if (pData->pu8LanBoot) 1089 1124 { … … 1190 1225 "ShowBootMenu\0" 1191 1226 "DelayBoot\0" 1227 "BiosRom\0" 1192 1228 "LanBootRom\0" 1193 1229 "PXEDebug\0" … … 1276 1312 1277 1313 /* 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 /* 1278 1411 * Map the BIOS into memory. 1279 1412 * There are two mappings: … … 1282 1415 * 2. 0xfffxxxxx to 0xffffffff contains the entire bios. 1283 1416 */ 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], 1289 1422 false /* fShadow */, "PC BIOS - 0xfffff"); 1290 1423 if (VBOX_FAILURE(rc)) 1291 1424 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, 1293 1426 false /* fShadow */, "PC BIOS - 0xffffffff"); 1294 1427 if (VBOX_FAILURE(rc)) … … 1446 1579 } 1447 1580 1448 const uint8_t *pu8LanBoot = NULL;1449 1581 uint64_t cbFileLanBoot; 1450 #ifdef VBOX_DO_NOT_LINK_LANBOOT 1582 const uint8_t *pu8LanBootBinary = NULL; 1583 uint64_t cbLanBootBinary; 1584 1451 1585 /* 1452 1586 * Determine the LAN boot ROM size, open specified ROM file in the process. … … 1463 1597 { 1464 1598 if ( RT_ALIGN(cbFileLanBoot, _4K) != cbFileLanBoot 1465 || cbFileLanBoot > _ 32K)1599 || cbFileLanBoot > _64K) 1466 1600 rc = VERR_TOO_MUCH_DATA; 1467 1601 } … … 1470 1604 { 1471 1605 /* 1472 * Ignore failure and fall back to noLAN boot ROM.1606 * Ignore failure and fall back to the built-in LAN boot ROM. 1473 1607 */ 1474 1608 Log(("pcbiosConstruct: Failed to open LAN boot ROM file '%s', rc=%Vrc!\n", pData->pszLanBootFile, rc)); … … 1488 1622 * Allocate buffer for the LAN boot ROM data. 1489 1623 */ 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) 1493 1626 { 1494 1627 rc = RTFileRead(FileLanBoot, pData->pu8LanBoot, cbFileLanBoot, NULL); … … 1496 1629 { 1497 1630 AssertMsgFailed(("RTFileRead(,,%d,NULL) -> %Vrc\n", cbFileLanBoot, rc)); 1498 MMR3HeapFree(pu8LanBoot); 1499 pu8LanBoot = NULL; 1631 MMR3HeapFree(pData->pu8LanBoot); 1500 1632 pData->pu8LanBoot = NULL; 1501 1633 } … … 1512 1644 RTFileClose(FileLanBoot); 1513 1645 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 } 1519 1659 1520 1660 /* … … 1523 1663 * the (up to) 32 kb ROM image. 1524 1664 */ 1525 if (pu8LanBoot )1526 rc = PDMDevHlpROMRegister(pDevIns, VBOX_LANBOOT_SEG << 4, cb FileLanBoot, pu8LanBoot,1665 if (pu8LanBootBinary) 1666 rc = PDMDevHlpROMRegister(pDevIns, VBOX_LANBOOT_SEG << 4, cbLanBootBinary, pu8LanBootBinary, 1527 1667 true /* fShadow */, "Net Boot ROM"); 1528 1668

