xref: /openbmc/qemu/hw/m68k/an5206.c (revision 6f9ff551)
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/m68k/mcf.h"
13 #include "hw/boards.h"
14 #include "hw/loader.h"
15 #include "elf.h"
16 #include "exec/address-spaces.h"
17 #include "qemu/error-report.h"
18 #include "sysemu/qtest.h"
19 
20 #define KERNEL_LOAD_ADDR 0x10000
21 #define AN5206_MBAR_ADDR 0x10000000
22 #define AN5206_RAMBAR_ADDR 0x20000000
23 
24 static void mcf5206_init(MemoryRegion *sysmem, uint32_t base)
25 {
26     DeviceState *dev;
27     SysBusDevice *s;
28 
29     dev = qdev_new(TYPE_MCF5206_MBAR);
30     s = SYS_BUS_DEVICE(dev);
31     sysbus_realize_and_unref(s, &error_fatal);
32 
33     memory_region_add_subregion(sysmem, base, sysbus_mmio_get_region(s, 0));
34 }
35 
36 static void an5206_init(MachineState *machine)
37 {
38     ram_addr_t ram_size = machine->ram_size;
39     const char *kernel_filename = machine->kernel_filename;
40     M68kCPU *cpu;
41     CPUM68KState *env;
42     int kernel_size;
43     uint64_t elf_entry;
44     hwaddr entry;
45     MemoryRegion *address_space_mem = get_system_memory();
46     MemoryRegion *sram = g_new(MemoryRegion, 1);
47 
48     cpu = M68K_CPU(cpu_create(machine->cpu_type));
49     env = &cpu->env;
50 
51     /* Initialize CPU registers.  */
52     env->vbr = 0;
53     /* TODO: allow changing MBAR and RAMBAR.  */
54     env->mbar = AN5206_MBAR_ADDR | 1;
55     env->rambar0 = AN5206_RAMBAR_ADDR | 1;
56 
57     /* DRAM at address zero */
58     memory_region_add_subregion(address_space_mem, 0, machine->ram);
59 
60     /* Internal SRAM.  */
61     memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal);
62     memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
63 
64     mcf5206_init(address_space_mem, AN5206_MBAR_ADDR);
65 
66     /* Load kernel.  */
67     if (!kernel_filename) {
68         if (qtest_enabled()) {
69             return;
70         }
71         error_report("Kernel image must be specified");
72         exit(1);
73     }
74 
75     kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry,
76                            NULL, 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);
81     }
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;
86     }
87     if (kernel_size < 0) {
88         error_report("Could not load kernel '%s'", kernel_filename);
89         exit(1);
90     }
91 
92     env->pc = entry;
93 }
94 
95 static void an5206_machine_init(MachineClass *mc)
96 {
97     mc->desc = "Arnewsh 5206";
98     mc->init = an5206_init;
99     mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5206");
100     mc->default_ram_id = "an5206.ram";
101 }
102 
103 DEFINE_MACHINE("an5206", an5206_machine_init)
104