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