armv7m: R14 should reset to 0xffffffff
[qemu/kevin.git] / hw / m68k / an5206.c
blob142bab98c9ff850f6773bea6648702078d78565d
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 "qapi/error.h"
11 #include "qemu-common.h"
12 #include "cpu.h"
13 #include "hw/hw.h"
14 #include "hw/m68k/mcf.h"
15 #include "hw/boards.h"
16 #include "hw/loader.h"
17 #include "elf.h"
18 #include "exec/address-spaces.h"
19 #include "qemu/error-report.h"
20 #include "sysemu/qtest.h"
22 #define KERNEL_LOAD_ADDR 0x10000
23 #define AN5206_MBAR_ADDR 0x10000000
24 #define AN5206_RAMBAR_ADDR 0x20000000
26 /* Board init. */
28 static void an5206_init(MachineState *machine)
30 ram_addr_t ram_size = machine->ram_size;
31 const char *cpu_model = machine->cpu_model;
32 const char *kernel_filename = machine->kernel_filename;
33 M68kCPU *cpu;
34 CPUM68KState *env;
35 int kernel_size;
36 uint64_t elf_entry;
37 hwaddr entry;
38 MemoryRegion *address_space_mem = get_system_memory();
39 MemoryRegion *ram = g_new(MemoryRegion, 1);
40 MemoryRegion *sram = g_new(MemoryRegion, 1);
42 if (!cpu_model) {
43 cpu_model = "m5206";
45 cpu = cpu_m68k_init(cpu_model);
46 if (!cpu) {
47 error_report("Unable to find m68k CPU definition");
48 exit(1);
50 env = &cpu->env;
52 /* Initialize CPU registers. */
53 env->vbr = 0;
54 /* TODO: allow changing MBAR and RAMBAR. */
55 env->mbar = AN5206_MBAR_ADDR | 1;
56 env->rambar0 = AN5206_RAMBAR_ADDR | 1;
58 /* DRAM at address zero */
59 memory_region_allocate_system_memory(ram, NULL, "an5206.ram", ram_size);
60 memory_region_add_subregion(address_space_mem, 0, ram);
62 /* Internal SRAM. */
63 memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal);
64 vmstate_register_ram_global(sram);
65 memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
67 mcf5206_init(address_space_mem, AN5206_MBAR_ADDR, cpu);
69 /* Load kernel. */
70 if (!kernel_filename) {
71 if (qtest_enabled()) {
72 return;
74 fprintf(stderr, "Kernel image must be specified\n");
75 exit(1);
78 kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
79 NULL, NULL, 1, EM_68K, 0, 0);
80 entry = elf_entry;
81 if (kernel_size < 0) {
82 kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL,
83 NULL, NULL);
85 if (kernel_size < 0) {
86 kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
87 ram_size - KERNEL_LOAD_ADDR);
88 entry = KERNEL_LOAD_ADDR;
90 if (kernel_size < 0) {
91 fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
92 exit(1);
95 env->pc = entry;
98 static void an5206_machine_init(MachineClass *mc)
100 mc->desc = "Arnewsh 5206";
101 mc->init = an5206_init;
104 DEFINE_MACHINE("an5206", an5206_machine_init)