Commit 970ac5a3082428dca91171f270dcd95d6f4b2636
1 parent
e9a1ab19
use ram allocation functions
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2405 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
3 changed files
with
57 additions
and
46 deletions
hw/pc.c
@@ -451,8 +451,8 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | @@ -451,8 +451,8 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | ||
451 | { | 451 | { |
452 | char buf[1024]; | 452 | char buf[1024]; |
453 | int ret, linux_boot, initrd_size, i; | 453 | int ret, linux_boot, initrd_size, i; |
454 | - unsigned long bios_offset, vga_bios_offset, option_rom_offset; | ||
455 | - int bios_size, isa_bios_size; | 454 | + ram_addr_t ram_addr, vga_ram_addr, bios_offset, vga_bios_offset; |
455 | + int bios_size, isa_bios_size, vga_bios_size; | ||
456 | PCIBus *pci_bus; | 456 | PCIBus *pci_bus; |
457 | int piix3_devfn = -1; | 457 | int piix3_devfn = -1; |
458 | CPUState *env; | 458 | CPUState *env; |
@@ -477,23 +477,24 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | @@ -477,23 +477,24 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | ||
477 | } | 477 | } |
478 | 478 | ||
479 | /* allocate RAM */ | 479 | /* allocate RAM */ |
480 | - cpu_register_physical_memory(0, ram_size, 0); | 480 | + ram_addr = qemu_ram_alloc(ram_size); |
481 | + cpu_register_physical_memory(0, ram_size, ram_addr); | ||
481 | 482 | ||
482 | - /* BIOS load */ | ||
483 | - bios_offset = ram_size + vga_ram_size; | ||
484 | - vga_bios_offset = bios_offset + 256 * 1024; | 483 | + /* allocate VGA RAM */ |
484 | + vga_ram_addr = qemu_ram_alloc(vga_ram_size); | ||
485 | 485 | ||
486 | + /* BIOS load */ | ||
486 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); | 487 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); |
487 | bios_size = get_image_size(buf); | 488 | bios_size = get_image_size(buf); |
488 | if (bios_size <= 0 || | 489 | if (bios_size <= 0 || |
489 | - (bios_size % 65536) != 0 || | ||
490 | - bios_size > (256 * 1024)) { | 490 | + (bios_size % 65536) != 0) { |
491 | goto bios_error; | 491 | goto bios_error; |
492 | } | 492 | } |
493 | + bios_offset = qemu_ram_alloc(bios_size); | ||
493 | ret = load_image(buf, phys_ram_base + bios_offset); | 494 | ret = load_image(buf, phys_ram_base + bios_offset); |
494 | if (ret != bios_size) { | 495 | if (ret != bios_size) { |
495 | bios_error: | 496 | bios_error: |
496 | - fprintf(stderr, "qemu: could not load PC bios '%s'\n", buf); | 497 | + fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", buf); |
497 | exit(1); | 498 | exit(1); |
498 | } | 499 | } |
499 | 500 | ||
@@ -503,8 +504,18 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | @@ -503,8 +504,18 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | ||
503 | } else { | 504 | } else { |
504 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); | 505 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); |
505 | } | 506 | } |
507 | + vga_bios_size = get_image_size(buf); | ||
508 | + if (vga_bios_size <= 0 || vga_bios_size > 65536) | ||
509 | + goto vga_bios_error; | ||
510 | + vga_bios_offset = qemu_ram_alloc(65536); | ||
511 | + | ||
506 | ret = load_image(buf, phys_ram_base + vga_bios_offset); | 512 | ret = load_image(buf, phys_ram_base + vga_bios_offset); |
507 | - | 513 | + if (ret != vga_bios_size) { |
514 | + vga_bios_error: | ||
515 | + fprintf(stderr, "qemu: could not load VGA BIOS '%s'\n", buf); | ||
516 | + exit(1); | ||
517 | + } | ||
518 | + | ||
508 | /* setup basic memory access */ | 519 | /* setup basic memory access */ |
509 | cpu_register_physical_memory(0xc0000, 0x10000, | 520 | cpu_register_physical_memory(0xc0000, 0x10000, |
510 | vga_bios_offset | IO_MEM_ROM); | 521 | vga_bios_offset | IO_MEM_ROM); |
@@ -519,20 +530,32 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | @@ -519,20 +530,32 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | ||
519 | isa_bios_size, | 530 | isa_bios_size, |
520 | (bios_offset + bios_size - isa_bios_size) | IO_MEM_ROM); | 531 | (bios_offset + bios_size - isa_bios_size) | IO_MEM_ROM); |
521 | 532 | ||
522 | - option_rom_offset = 0; | ||
523 | - for (i = 0; i < nb_option_roms; i++) { | ||
524 | - int offset = bios_offset + bios_size + option_rom_offset; | ||
525 | - int size; | ||
526 | - | ||
527 | - size = load_image(option_rom[i], phys_ram_base + offset); | ||
528 | - if ((size + option_rom_offset) > 0x10000) { | ||
529 | - fprintf(stderr, "Too many option ROMS\n"); | ||
530 | - exit(1); | ||
531 | - } | ||
532 | - cpu_register_physical_memory(0xd0000 + option_rom_offset, | ||
533 | - size, offset | IO_MEM_ROM); | ||
534 | - option_rom_offset += size + 2047; | ||
535 | - option_rom_offset -= (option_rom_offset % 2048); | 533 | + { |
534 | + ram_addr_t option_rom_offset; | ||
535 | + int size, offset; | ||
536 | + | ||
537 | + offset = 0; | ||
538 | + for (i = 0; i < nb_option_roms; i++) { | ||
539 | + size = get_image_size(option_rom[i]); | ||
540 | + if (size < 0) { | ||
541 | + fprintf(stderr, "Could not load option rom '%s'\n", | ||
542 | + option_rom[i]); | ||
543 | + exit(1); | ||
544 | + } | ||
545 | + if (size > (0x10000 - offset)) | ||
546 | + goto option_rom_error; | ||
547 | + option_rom_offset = qemu_ram_alloc(size); | ||
548 | + ret = load_image(option_rom[i], phys_ram_base + option_rom_offset); | ||
549 | + if (ret != size) { | ||
550 | + option_rom_error: | ||
551 | + fprintf(stderr, "Too many option ROMS\n"); | ||
552 | + exit(1); | ||
553 | + } | ||
554 | + size = (size + 4095) & ~4095; | ||
555 | + cpu_register_physical_memory(0xd0000 + offset, | ||
556 | + size, option_rom_offset | IO_MEM_ROM); | ||
557 | + offset += size; | ||
558 | + } | ||
536 | } | 559 | } |
537 | 560 | ||
538 | /* map all the bios at the top of memory */ | 561 | /* map all the bios at the top of memory */ |
@@ -612,19 +635,19 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | @@ -612,19 +635,19 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | ||
612 | if (cirrus_vga_enabled) { | 635 | if (cirrus_vga_enabled) { |
613 | if (pci_enabled) { | 636 | if (pci_enabled) { |
614 | pci_cirrus_vga_init(pci_bus, | 637 | pci_cirrus_vga_init(pci_bus, |
615 | - ds, phys_ram_base + ram_size, ram_size, | ||
616 | - vga_ram_size); | 638 | + ds, phys_ram_base + vga_ram_addr, |
639 | + vga_ram_addr, vga_ram_size); | ||
617 | } else { | 640 | } else { |
618 | - isa_cirrus_vga_init(ds, phys_ram_base + ram_size, ram_size, | ||
619 | - vga_ram_size); | 641 | + isa_cirrus_vga_init(ds, phys_ram_base + vga_ram_addr, |
642 | + vga_ram_addr, vga_ram_size); | ||
620 | } | 643 | } |
621 | } else { | 644 | } else { |
622 | if (pci_enabled) { | 645 | if (pci_enabled) { |
623 | - pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, ram_size, | ||
624 | - vga_ram_size, 0, 0); | 646 | + pci_vga_init(pci_bus, ds, phys_ram_base + vga_ram_addr, |
647 | + vga_ram_addr, vga_ram_size, 0, 0); | ||
625 | } else { | 648 | } else { |
626 | - isa_vga_init(ds, phys_ram_base + ram_size, ram_size, | ||
627 | - vga_ram_size); | 649 | + isa_vga_init(ds, phys_ram_base + vga_ram_addr, |
650 | + vga_ram_addr, vga_ram_size); | ||
628 | } | 651 | } |
629 | } | 652 | } |
630 | 653 |
vl.c
@@ -125,7 +125,6 @@ BlockDriverState *bs_table[MAX_DISKS + 1], *fd_table[MAX_FD]; | @@ -125,7 +125,6 @@ BlockDriverState *bs_table[MAX_DISKS + 1], *fd_table[MAX_FD]; | ||
125 | /* point to the block driver where the snapshots are managed */ | 125 | /* point to the block driver where the snapshots are managed */ |
126 | BlockDriverState *bs_snapshots; | 126 | BlockDriverState *bs_snapshots; |
127 | int vga_ram_size; | 127 | int vga_ram_size; |
128 | -int bios_size; | ||
129 | static DisplayState display_state; | 128 | static DisplayState display_state; |
130 | int nographic; | 129 | int nographic; |
131 | const char* keyboard_layout = NULL; | 130 | const char* keyboard_layout = NULL; |
@@ -6564,7 +6563,6 @@ int main(int argc, char **argv) | @@ -6564,7 +6563,6 @@ int main(int argc, char **argv) | ||
6564 | hd_filename[i] = NULL; | 6563 | hd_filename[i] = NULL; |
6565 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; | 6564 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; |
6566 | vga_ram_size = VGA_RAM_SIZE; | 6565 | vga_ram_size = VGA_RAM_SIZE; |
6567 | - bios_size = BIOS_SIZE; | ||
6568 | #ifdef CONFIG_GDBSTUB | 6566 | #ifdef CONFIG_GDBSTUB |
6569 | use_gdbstub = 0; | 6567 | use_gdbstub = 0; |
6570 | gdbstub_port = DEFAULT_GDBSTUB_PORT; | 6568 | gdbstub_port = DEFAULT_GDBSTUB_PORT; |
@@ -7078,16 +7076,7 @@ int main(int argc, char **argv) | @@ -7078,16 +7076,7 @@ int main(int argc, char **argv) | ||
7078 | #endif | 7076 | #endif |
7079 | 7077 | ||
7080 | /* init the memory */ | 7078 | /* init the memory */ |
7081 | - phys_ram_size = ram_size + vga_ram_size + bios_size; | ||
7082 | - | ||
7083 | - for (i = 0; i < nb_option_roms; i++) { | ||
7084 | - int ret = get_image_size(option_rom[i]); | ||
7085 | - if (ret == -1) { | ||
7086 | - fprintf(stderr, "Could not load option rom '%s'\n", option_rom[i]); | ||
7087 | - exit(1); | ||
7088 | - } | ||
7089 | - phys_ram_size += ret; | ||
7090 | - } | 7079 | + phys_ram_size = ram_size + vga_ram_size + MAX_BIOS_SIZE; |
7091 | 7080 | ||
7092 | phys_ram_base = qemu_vmalloc(phys_ram_size); | 7081 | phys_ram_base = qemu_vmalloc(phys_ram_size); |
7093 | if (!phys_ram_base) { | 7082 | if (!phys_ram_base) { |
vl.h
@@ -165,12 +165,11 @@ extern const char *option_rom[MAX_OPTION_ROMS]; | @@ -165,12 +165,11 @@ extern const char *option_rom[MAX_OPTION_ROMS]; | ||
165 | extern int nb_option_roms; | 165 | extern int nb_option_roms; |
166 | 166 | ||
167 | /* XXX: make it dynamic */ | 167 | /* XXX: make it dynamic */ |
168 | +#define MAX_BIOS_SIZE (4 * 1024 * 1024) | ||
168 | #if defined (TARGET_PPC) || defined (TARGET_SPARC64) | 169 | #if defined (TARGET_PPC) || defined (TARGET_SPARC64) |
169 | #define BIOS_SIZE ((512 + 32) * 1024) | 170 | #define BIOS_SIZE ((512 + 32) * 1024) |
170 | #elif defined(TARGET_MIPS) | 171 | #elif defined(TARGET_MIPS) |
171 | #define BIOS_SIZE (4 * 1024 * 1024) | 172 | #define BIOS_SIZE (4 * 1024 * 1024) |
172 | -#else | ||
173 | -#define BIOS_SIZE ((256 + 64) * 1024) | ||
174 | #endif | 173 | #endif |
175 | 174 | ||
176 | /* keyboard/mouse support */ | 175 | /* keyboard/mouse support */ |