Commit 7587cf44019d593bb12703e7046bd7738996c55c

Authored by bellard
1 parent 70867490

accept bigger PC BIOSes


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@946 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 3 changed files with 45 additions and 8 deletions
@@ -322,6 +322,8 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device, @@ -322,6 +322,8 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
322 { 322 {
323 char buf[1024]; 323 char buf[1024];
324 int ret, linux_boot, initrd_size, i, nb_nics1, fd; 324 int ret, linux_boot, initrd_size, i, nb_nics1, fd;
  325 + unsigned long bios_offset, vga_bios_offset;
  326 + int bios_size, isa_bios_size;
325 327
326 linux_boot = (kernel_filename != NULL); 328 linux_boot = (kernel_filename != NULL);
327 329
@@ -329,25 +331,47 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device, @@ -329,25 +331,47 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device,
329 cpu_register_physical_memory(0, ram_size, 0); 331 cpu_register_physical_memory(0, ram_size, 0);
330 332
331 /* BIOS load */ 333 /* BIOS load */
  334 + bios_offset = ram_size + vga_ram_size;
  335 + vga_bios_offset = bios_offset + 256 * 1024;
  336 +
332 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); 337 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME);
333 - ret = load_image(buf, phys_ram_base + 0x000f0000);  
334 - if (ret != 0x10000) { 338 + bios_size = get_image_size(buf);
  339 + if (bios_size <= 0 ||
  340 + (bios_size % 65536) != 0 ||
  341 + bios_size > (256 * 1024)) {
  342 + goto bios_error;
  343 + }
  344 + ret = load_image(buf, phys_ram_base + bios_offset);
  345 + if (ret != bios_size) {
  346 + bios_error:
335 fprintf(stderr, "qemu: could not load PC bios '%s'\n", buf); 347 fprintf(stderr, "qemu: could not load PC bios '%s'\n", buf);
336 exit(1); 348 exit(1);
337 } 349 }
338 - 350 +
339 /* VGA BIOS load */ 351 /* VGA BIOS load */
340 if (cirrus_vga_enabled) { 352 if (cirrus_vga_enabled) {
341 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_CIRRUS_FILENAME); 353 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_CIRRUS_FILENAME);
342 } else { 354 } else {
343 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); 355 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
344 } 356 }
345 - ret = load_image(buf, phys_ram_base + 0x000c0000); 357 + ret = load_image(buf, phys_ram_base + vga_bios_offset);
346 358
347 /* setup basic memory access */ 359 /* setup basic memory access */
348 - cpu_register_physical_memory(0xc0000, 0x10000, 0xc0000 | IO_MEM_ROM);  
349 - cpu_register_physical_memory(0xd0000, 0x20000, IO_MEM_UNASSIGNED);  
350 - cpu_register_physical_memory(0xf0000, 0x10000, 0xf0000 | IO_MEM_ROM); 360 + cpu_register_physical_memory(0xc0000, 0x10000,
  361 + vga_bios_offset | IO_MEM_ROM);
  362 +
  363 + /* map the last 128KB of the BIOS in ISA space */
  364 + isa_bios_size = bios_size;
  365 + if (isa_bios_size > (128 * 1024))
  366 + isa_bios_size = 128 * 1024;
  367 + cpu_register_physical_memory(0xd0000, (192 * 1024) - isa_bios_size,
  368 + IO_MEM_UNASSIGNED);
  369 + cpu_register_physical_memory(0x100000 - isa_bios_size,
  370 + isa_bios_size,
  371 + (bios_offset + bios_size - isa_bios_size) | IO_MEM_ROM);
  372 + /* map all the bios at the top of memory */
  373 + cpu_register_physical_memory((uint32_t)(-bios_size),
  374 + bios_size, bios_offset | IO_MEM_ROM);
351 375
352 bochs_bios_init(); 376 bochs_bios_init();
353 377
@@ -291,6 +291,18 @@ char *pstrcat(char *buf, int buf_size, const char *s) @@ -291,6 +291,18 @@ char *pstrcat(char *buf, int buf_size, const char *s)
291 } 291 }
292 292
293 /* return the size or -1 if error */ 293 /* return the size or -1 if error */
  294 +int get_image_size(const char *filename)
  295 +{
  296 + int fd, size;
  297 + fd = open(filename, O_RDONLY | O_BINARY);
  298 + if (fd < 0)
  299 + return -1;
  300 + size = lseek(fd, 0, SEEK_END);
  301 + close(fd);
  302 + return size;
  303 +}
  304 +
  305 +/* return the size or -1 if error */
294 int load_image(const char *filename, uint8_t *addr) 306 int load_image(const char *filename, uint8_t *addr)
295 { 307 {
296 int fd, size; 308 int fd, size;
@@ -209,6 +209,7 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c); @@ -209,6 +209,7 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
209 209
210 void hw_error(const char *fmt, ...); 210 void hw_error(const char *fmt, ...);
211 211
  212 +int get_image_size(const char *filename);
212 int load_image(const char *filename, uint8_t *addr); 213 int load_image(const char *filename, uint8_t *addr);
213 extern const char *bios_dir; 214 extern const char *bios_dir;
214 215
@@ -243,7 +244,7 @@ extern int cirrus_vga_enabled; @@ -243,7 +244,7 @@ extern int cirrus_vga_enabled;
243 #if defined (TARGET_PPC) 244 #if defined (TARGET_PPC)
244 #define BIOS_SIZE (512 * 1024) 245 #define BIOS_SIZE (512 * 1024)
245 #else 246 #else
246 -#define BIOS_SIZE 0 247 +#define BIOS_SIZE ((256 + 64) * 1024)
247 #endif 248 #endif
248 249
249 /* keyboard/mouse support */ 250 /* keyboard/mouse support */