Changeset 37917 in vbox for trunk/src/VBox/Devices/PC
- Timestamp:
- Jul 13, 2011 1:25:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/PC/DevPcBios.cpp
r35400 r37917 157 157 uint8_t *pu8PcBios; 158 158 /** The size of the system BIOS ROM. */ 159 uint 64_t cbPcBios;159 uint32_t cbPcBios; 160 160 /** The name of the BIOS ROM file. */ 161 161 char *pszPcBiosFile; … … 1165 1165 } 1166 1166 1167 const uint8_t *pu8PcBiosBinary = NULL; 1168 uint64_t cbPcBiosBinary; 1169 /* 1170 * Determine the system BIOS ROM size, open specified ROM file in the process. 1171 */ 1172 RTFILE FilePcBios = NIL_RTFILE; 1167 const uint8_t *pu8PcBiosBinary; 1168 uint32_t cbPcBiosBinary; 1173 1169 if (pThis->pszPcBiosFile) 1174 1170 { 1175 rc = RTFileOpen(&FilePcBios, pThis->pszPcBiosFile, 1171 /* 1172 * Load the BIOS ROM. 1173 */ 1174 RTFILE hFilePcBios; 1175 rc = RTFileOpen(&hFilePcBios, pThis->pszPcBiosFile, 1176 1176 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE); 1177 1177 if (RT_SUCCESS(rc)) 1178 1178 { 1179 rc = RTFileGetSize(FilePcBios, &pThis->cbPcBios); 1179 /* Figure the size and check restrictions. */ 1180 uint64_t cbPcBios; 1181 rc = RTFileGetSize(hFilePcBios, &cbPcBios); 1180 1182 if (RT_SUCCESS(rc)) 1181 1183 { 1182 /* The following checks should be in sync the AssertReleaseMsg's below. */ 1183 if ( RT_ALIGN(pThis->cbPcBios, _64K) != pThis->cbPcBios 1184 || pThis->cbPcBios > 32 * _64K 1185 || pThis->cbPcBios < _64K) 1186 rc = VERR_TOO_MUCH_DATA; 1187 } 1188 } 1184 pThis->cbPcBios = (uint32_t)cbPcBios; 1185 if ( RT_ALIGN(pThis->cbPcBios, _64K) == pThis->cbPcBios 1186 && pThis->cbPcBios == cbPcBios 1187 && pThis->cbPcBios <= 32 * _64K 1188 && pThis->cbPcBios >= _64K) 1189 { 1190 pThis->pu8PcBios = (uint8_t *)PDMDevHlpMMHeapAlloc(pDevIns, pThis->cbPcBios); 1191 if (pThis->pu8PcBios) 1192 { 1193 rc = RTFileRead(hFilePcBios, pThis->pu8PcBios, pThis->cbPcBios, NULL); 1194 if (RT_FAILURE(rc)) 1195 rc = PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, 1196 N_("Error reading the BIOS image ('%s)"), pThis->pszPcBiosFile); 1197 } 1198 else 1199 rc = PDMDevHlpVMSetError(pDevIns, VERR_NO_MEMORY, RT_SRC_POS, 1200 N_("Failed to allocate %#x bytes for loading the BIOS image"), 1201 pThis->cbPcBios); 1202 } 1203 else 1204 rc = PDMDevHlpVMSetError(pDevIns, VERR_OUT_OF_RANGE, RT_SRC_POS, 1205 N_("Invalid system BIOS file size ('%s'): %#llx (%llu)"), 1206 pThis->pszPcBiosFile, cbPcBios, cbPcBios); 1207 } 1208 else 1209 rc = PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, N_("Failed to query the system BIOS file size ('%s')"), 1210 pThis->pszPcBiosFile); 1211 RTFileClose(hFilePcBios); 1212 } 1213 else 1214 rc = PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, N_("Failed to open system BIOS file '%s'"), pThis->pszPcBiosFile); 1189 1215 if (RT_FAILURE(rc)) 1190 { 1191 /* 1192 * In case of failure simply fall back to the built-in BIOS ROM. 1193 */ 1194 Log(("pcbiosConstruct: Failed to open system BIOS ROM file '%s', rc=%Rrc!\n", pThis->pszPcBiosFile, rc)); 1195 RTFileClose(FilePcBios); 1196 FilePcBios = NIL_RTFILE; 1197 MMR3HeapFree(pThis->pszPcBiosFile); 1198 pThis->pszPcBiosFile = NULL; 1199 } 1200 } 1201 1202 /* 1203 * Attempt to get the system BIOS ROM data from file. 1204 */ 1205 if (pThis->pszPcBiosFile) 1216 return rc; 1217 1218 pu8PcBiosBinary = pThis->pu8PcBios; 1219 cbPcBiosBinary = pThis->cbPcBios; 1220 LogRel(("Using BIOS ROM '%s' with a size of %#x bytes\n", pThis->pszPcBiosFile, pThis->cbPcBios)); 1221 } 1222 else 1206 1223 { 1207 1224 /* 1208 * Allocate buffer for the system BIOS ROM data.1225 * Use the embedded BIOS ROM image. 1209 1226 */ 1210 pThis->pu8PcBios = (uint8_t *)PDMDevHlpMMHeapAlloc(pDevIns, pThis->cbPcBios);1211 if (pThis->pu8PcBios)1212 {1213 rc = RTFileRead(FilePcBios, pThis->pu8PcBios, pThis->cbPcBios, NULL);1214 if (RT_FAILURE(rc))1215 {1216 AssertMsgFailed(("RTFileRead(,,%d,NULL) -> %Rrc\n", pThis->cbPcBios, rc));1217 MMR3HeapFree(pThis->pu8PcBios);1218 pThis->pu8PcBios = NULL;1219 }1220 rc = VINF_SUCCESS;1221 }1222 else1223 rc = VERR_NO_MEMORY;1224 }1225 else1226 pThis->pu8PcBios = NULL;1227 1228 /* cleanup */1229 if (FilePcBios != NIL_RTFILE)1230 RTFileClose(FilePcBios);1231 1232 /* If we were unable to get the data from file for whatever reason, fall1233 back to the built-in ROM image. */1234 uint32_t fFlags = 0;1235 if (pThis->pu8PcBios == NULL)1236 {1237 1227 pu8PcBiosBinary = g_abPcBiosBinary; 1238 1228 cbPcBiosBinary = g_cbPcBiosBinary; 1239 fFlags = PGMPHYS_ROM_FLAGS_PERMANENT_BINARY;1240 }1241 else1242 {1243 pu8PcBiosBinary = pThis->pu8PcBios;1244 cbPcBiosBinary = pThis->cbPcBios;1245 1229 } 1246 1230 … … 1257 1241 cb = RT_MIN(cbPcBiosBinary, 128 * _1K); /* Effectively either 64 or 128K. */ 1258 1242 rc = PDMDevHlpROMRegister(pDevIns, 0x00100000 - cb, cb, &pu8PcBiosBinary[cbPcBiosBinary - cb], cb, 1259 fFlags, "PC BIOS - 0xfffff");1243 PGMPHYS_ROM_FLAGS_PERMANENT_BINARY, "PC BIOS - 0xfffff"); 1260 1244 if (RT_FAILURE(rc)) 1261 1245 return rc; 1262 1246 rc = PDMDevHlpROMRegister(pDevIns, (uint32_t)-(int32_t)cbPcBiosBinary, cbPcBiosBinary, pu8PcBiosBinary, cbPcBiosBinary, 1263 fFlags, "PC BIOS - 0xffffffff");1247 PGMPHYS_ROM_FLAGS_PERMANENT_BINARY, "PC BIOS - 0xffffffff"); 1264 1248 if (RT_FAILURE(rc)) 1265 1249 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.