qapi-commands: Inline single-use helpers of gen_marshal()
[qemu/cris-port.git] / hw / m68k / an5206.c
blob85f72770d7c99a2d9c297dfef8e63b7d499e0abc
1 /*
2 * Arnewsh 5206 ColdFire system emulation.
4 * Copyright (c) 2007 CodeSourcery.
6 * This code is licensed under the GPL
7 */
9 #include "qemu/osdep.h"
10 #include "hw/hw.h"
11 #include "hw/m68k/mcf.h"
12 #include "hw/boards.h"
13 #include "hw/loader.h"
14 #include "elf.h"
15 #include "exec/address-spaces.h"
16 #include "qemu/error-report.h"
17 #include "sysemu/qtest.h"
19 #define KERNEL_LOAD_ADDR 0x10000
20 #define AN5206_MBAR_ADDR 0x10000000
21 #define AN5206_RAMBAR_ADDR 0x20000000
23 /* Board init. */
25 static void an5206_init(MachineState *machine)
27 ram_addr_t ram_size = machine->ram_size;
28 const char *cpu_model = machine->cpu_model;
29 const char *kernel_filename = machine->kernel_filename;
30 M68kCPU *cpu;
31 CPUM68KState *env;
32 int kernel_size;
33 uint64_t elf_entry;
34 hwaddr entry;
35 MemoryRegion *address_space_mem = get_system_memory();
36 MemoryRegion *ram = g_new(MemoryRegion, 1);
37 MemoryRegion *sram = g_new(MemoryRegion, 1);
39 if (!cpu_model) {
40 cpu_model = "m5206";
42 cpu = cpu_m68k_init(cpu_model);
43 if (!cpu) {
44 error_report("Unable to find m68k CPU definition");
45 exit(1);
47 env = &cpu->env;
49 /* Initialize CPU registers. */
50 env->vbr = 0;
51 /* TODO: allow changing MBAR and RAMBAR. */
52 env->mbar = AN5206_MBAR_ADDR | 1;
53 env->rambar0 = AN5206_RAMBAR_ADDR | 1;
55 /* DRAM at address zero */
56 memory_region_allocate_system_memory(ram, NULL, "an5206.ram", ram_size);
57 memory_region_add_subregion(address_space_mem, 0, ram);
59 /* Internal SRAM. */
60 memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal);
61 vmstate_register_ram_global(sram);
62 memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
64 mcf5206_init(address_space_mem, AN5206_MBAR_ADDR, cpu);
66 /* Load kernel. */
67 if (!kernel_filename) {
68 if (qtest_enabled()) {
69 return;
71 fprintf(stderr, "Kernel image must be specified\n");
72 exit(1);
75 kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
76 NULL, NULL, 1, EM_68K, 0, 0);
77 entry = elf_entry;
78 if (kernel_size < 0) {
79 kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL,
80 NULL, NULL);
82 if (kernel_size < 0) {
83 kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
84 ram_size - KERNEL_LOAD_ADDR);
85 entry = KERNEL_LOAD_ADDR;
87 if (kernel_size < 0) {
88 fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
89 exit(1);
92 env->pc = entry;
95 static void an5206_machine_init(MachineClass *mc)
97 mc->desc = "Arnewsh 5206";
98 mc->init = an5206_init;
101 DEFINE_MACHINE("an5206", an5206_machine_init)