e500: fix memory leak
[qemu.git] / hw / m68k / dummy_m68k.c
blobfacd561efa128fa8672bdf8366318462a14c56d6
1 /*
2 * Dummy board with just RAM and CPU for use as an ISS.
4 * Copyright (c) 2007 CodeSourcery.
6 * This code is licensed under the GPL
7 */
9 #include "hw/hw.h"
10 #include "hw/boards.h"
11 #include "hw/loader.h"
12 #include "elf.h"
13 #include "exec/address-spaces.h"
15 #define KERNEL_LOAD_ADDR 0x10000
17 /* Board init. */
19 static void dummy_m68k_init(MachineState *machine)
21 ram_addr_t ram_size = machine->ram_size;
22 const char *cpu_model = machine->cpu_model;
23 const char *kernel_filename = machine->kernel_filename;
24 CPUM68KState *env;
25 MemoryRegion *address_space_mem = get_system_memory();
26 MemoryRegion *ram = g_new(MemoryRegion, 1);
27 int kernel_size;
28 uint64_t elf_entry;
29 hwaddr entry;
31 if (!cpu_model)
32 cpu_model = "cfv4e";
33 env = cpu_init(cpu_model);
34 if (!env) {
35 fprintf(stderr, "Unable to find m68k CPU definition\n");
36 exit(1);
39 /* Initialize CPU registers. */
40 env->vbr = 0;
42 /* RAM at address zero */
43 memory_region_init_ram(ram, NULL, "dummy_m68k.ram", ram_size, &error_abort);
44 vmstate_register_ram_global(ram);
45 memory_region_add_subregion(address_space_mem, 0, ram);
47 /* Load kernel. */
48 if (kernel_filename) {
49 kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
50 NULL, NULL, 1, ELF_MACHINE, 0);
51 entry = elf_entry;
52 if (kernel_size < 0) {
53 kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL,
54 NULL, NULL);
56 if (kernel_size < 0) {
57 kernel_size = load_image_targphys(kernel_filename,
58 KERNEL_LOAD_ADDR,
59 ram_size - KERNEL_LOAD_ADDR);
60 entry = KERNEL_LOAD_ADDR;
62 if (kernel_size < 0) {
63 fprintf(stderr, "qemu: could not load kernel '%s'\n",
64 kernel_filename);
65 exit(1);
67 } else {
68 entry = 0;
70 env->pc = entry;
73 static QEMUMachine dummy_m68k_machine = {
74 .name = "dummy",
75 .desc = "Dummy board",
76 .init = dummy_m68k_init,
79 static void dummy_m68k_machine_init(void)
81 qemu_register_machine(&dummy_m68k_machine);
84 machine_init(dummy_m68k_machine_init);