xref: /openbmc/qemu/hw/m68k/an5206.c (revision 500eb6db)
1 /*
2  * Arnewsh 5206 ColdFire system emulation.
3  *
4  * Copyright (c) 2007 CodeSourcery.
5  *
6  * This code is licensed under the GPL
7  */
8 
9 #include "qemu/osdep.h"
10 #include "qapi/error.h"
11 #include "cpu.h"
12 #include "hw/hw.h"
13 #include "hw/m68k/mcf.h"
14 #include "hw/boards.h"
15 #include "hw/loader.h"
16 #include "elf.h"
17 #include "exec/address-spaces.h"
18 #include "qemu/error-report.h"
19 #include "sysemu/qtest.h"
20 
21 #define KERNEL_LOAD_ADDR 0x10000
22 #define AN5206_MBAR_ADDR 0x10000000
23 #define AN5206_RAMBAR_ADDR 0x20000000
24 
25 /* Board init.  */
26 
27 static void an5206_init(MachineState *machine)
28 {
29     ram_addr_t ram_size = machine->ram_size;
30     const char *kernel_filename = machine->kernel_filename;
31     M68kCPU *cpu;
32     CPUM68KState *env;
33     int kernel_size;
34     uint64_t elf_entry;
35     hwaddr entry;
36     MemoryRegion *address_space_mem = get_system_memory();
37     MemoryRegion *ram = g_new(MemoryRegion, 1);
38     MemoryRegion *sram = g_new(MemoryRegion, 1);
39 
40     cpu = M68K_CPU(cpu_create(machine->cpu_type));
41     env = &cpu->env;
42 
43     /* Initialize CPU registers.  */
44     env->vbr = 0;
45     /* TODO: allow changing MBAR and RAMBAR.  */
46     env->mbar = AN5206_MBAR_ADDR | 1;
47     env->rambar0 = AN5206_RAMBAR_ADDR | 1;
48 
49     /* DRAM at address zero */
50     memory_region_allocate_system_memory(ram, NULL, "an5206.ram", ram_size);
51     memory_region_add_subregion(address_space_mem, 0, ram);
52 
53     /* Internal SRAM.  */
54     memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal);
55     memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
56 
57     mcf5206_init(address_space_mem, AN5206_MBAR_ADDR, cpu);
58 
59     /* Load kernel.  */
60     if (!kernel_filename) {
61         if (qtest_enabled()) {
62             return;
63         }
64         error_report("Kernel image must be specified");
65         exit(1);
66     }
67 
68     kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry,
69                            NULL, NULL, 1, EM_68K, 0, 0);
70     entry = elf_entry;
71     if (kernel_size < 0) {
72         kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL,
73                                   NULL, NULL);
74     }
75     if (kernel_size < 0) {
76         kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
77                                           ram_size - KERNEL_LOAD_ADDR);
78         entry = KERNEL_LOAD_ADDR;
79     }
80     if (kernel_size < 0) {
81         error_report("Could not load kernel '%s'", kernel_filename);
82         exit(1);
83     }
84 
85     env->pc = entry;
86 }
87 
88 static void an5206_machine_init(MachineClass *mc)
89 {
90     mc->desc = "Arnewsh 5206";
91     mc->init = an5206_init;
92     mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5206");
93 }
94 
95 DEFINE_MACHINE("an5206", an5206_machine_init)
96