xref: /openbmc/qemu/hw/m68k/an5206.c (revision 979a8902)
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 /* Board init.  */
25 
26 static void an5206_init(MachineState *machine)
27 {
28     ram_addr_t ram_size = machine->ram_size;
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);
38 
39     cpu = M68K_CPU(cpu_create(machine->cpu_type));
40     env = &cpu->env;
41 
42     /* Initialize CPU registers.  */
43     env->vbr = 0;
44     /* TODO: allow changing MBAR and RAMBAR.  */
45     env->mbar = AN5206_MBAR_ADDR | 1;
46     env->rambar0 = AN5206_RAMBAR_ADDR | 1;
47 
48     /* DRAM at address zero */
49     memory_region_allocate_system_memory(ram, NULL, "an5206.ram", ram_size);
50     memory_region_add_subregion(address_space_mem, 0, ram);
51 
52     /* Internal SRAM.  */
53     memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal);
54     memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
55 
56     mcf5206_init(address_space_mem, AN5206_MBAR_ADDR, cpu);
57 
58     /* Load kernel.  */
59     if (!kernel_filename) {
60         if (qtest_enabled()) {
61             return;
62         }
63         error_report("Kernel image must be specified");
64         exit(1);
65     }
66 
67     kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry,
68                            NULL, NULL, NULL, 1, EM_68K, 0, 0);
69     entry = elf_entry;
70     if (kernel_size < 0) {
71         kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL,
72                                   NULL, NULL);
73     }
74     if (kernel_size < 0) {
75         kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
76                                           ram_size - KERNEL_LOAD_ADDR);
77         entry = KERNEL_LOAD_ADDR;
78     }
79     if (kernel_size < 0) {
80         error_report("Could not load kernel '%s'", kernel_filename);
81         exit(1);
82     }
83 
84     env->pc = entry;
85 }
86 
87 static void an5206_machine_init(MachineClass *mc)
88 {
89     mc->desc = "Arnewsh 5206";
90     mc->init = an5206_init;
91     mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5206");
92 }
93 
94 DEFINE_MACHINE("an5206", an5206_machine_init)
95