hw: Don't use hw_error() for machine initialization errors
[qemu/ar7.git] / hw / m68k / an5206.c
blob8d9ccaa88ef3df619d9dca46ab712ecc0fbb6273
1 /*
2 * Arnewsh 5206 ColdFire system emulation.
4 * Copyright (c) 2007 CodeSourcery.
6 * This code is licensed under the GPL
7 */
9 #include "hw/hw.h"
10 #include "hw/m68k/mcf.h"
11 #include "hw/boards.h"
12 #include "hw/loader.h"
13 #include "elf.h"
14 #include "exec/address-spaces.h"
15 #include "qemu/error-report.h"
16 #include "sysemu/qtest.h"
18 #define KERNEL_LOAD_ADDR 0x10000
19 #define AN5206_MBAR_ADDR 0x10000000
20 #define AN5206_RAMBAR_ADDR 0x20000000
22 /* Board init. */
24 static void an5206_init(MachineState *machine)
26 ram_addr_t ram_size = machine->ram_size;
27 const char *cpu_model = machine->cpu_model;
28 const char *kernel_filename = machine->kernel_filename;
29 M68kCPU *cpu;
30 CPUM68KState *env;
31 int kernel_size;
32 uint64_t elf_entry;
33 hwaddr entry;
34 MemoryRegion *address_space_mem = get_system_memory();
35 MemoryRegion *ram = g_new(MemoryRegion, 1);
36 MemoryRegion *sram = g_new(MemoryRegion, 1);
38 if (!cpu_model) {
39 cpu_model = "m5206";
41 cpu = cpu_m68k_init(cpu_model);
42 if (!cpu) {
43 error_report("Unable to find m68k CPU definition");
44 exit(1);
46 env = &cpu->env;
48 /* Initialize CPU registers. */
49 env->vbr = 0;
50 /* TODO: allow changing MBAR and RAMBAR. */
51 env->mbar = AN5206_MBAR_ADDR | 1;
52 env->rambar0 = AN5206_RAMBAR_ADDR | 1;
54 /* DRAM at address zero */
55 memory_region_allocate_system_memory(ram, NULL, "an5206.ram", ram_size);
56 memory_region_add_subregion(address_space_mem, 0, ram);
58 /* Internal SRAM. */
59 memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal);
60 vmstate_register_ram_global(sram);
61 memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
63 mcf5206_init(address_space_mem, AN5206_MBAR_ADDR, cpu);
65 /* Load kernel. */
66 if (!kernel_filename) {
67 if (qtest_enabled()) {
68 return;
70 fprintf(stderr, "Kernel image must be specified\n");
71 exit(1);
74 kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
75 NULL, NULL, 1, EM_68K, 0);
76 entry = elf_entry;
77 if (kernel_size < 0) {
78 kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL,
79 NULL, NULL);
81 if (kernel_size < 0) {
82 kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
83 ram_size - KERNEL_LOAD_ADDR);
84 entry = KERNEL_LOAD_ADDR;
86 if (kernel_size < 0) {
87 fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
88 exit(1);
91 env->pc = entry;
94 static void an5206_machine_init(MachineClass *mc)
96 mc->desc = "Arnewsh 5206";
97 mc->init = an5206_init;
100 DEFINE_MACHINE("an5206", an5206_machine_init)