xref: /openbmc/qemu/hw/m68k/an5206.c (revision 14a650ec)
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 "hw/hw.h"
10 #include "hw/m68k/mcf.h"
11 #include "hw/boards.h"
12 #include "hw/loader.h"
13 #include "elf.h"
14 #include "exec/address-spaces.h"
15 #include "sysemu/qtest.h"
16 
17 #define KERNEL_LOAD_ADDR 0x10000
18 #define AN5206_MBAR_ADDR 0x10000000
19 #define AN5206_RAMBAR_ADDR 0x20000000
20 
21 /* Board init.  */
22 
23 static void an5206_init(QEMUMachineInitArgs *args)
24 {
25     ram_addr_t ram_size = args->ram_size;
26     const char *cpu_model = args->cpu_model;
27     const char *kernel_filename = args->kernel_filename;
28     M68kCPU *cpu;
29     CPUM68KState *env;
30     int kernel_size;
31     uint64_t elf_entry;
32     hwaddr entry;
33     MemoryRegion *address_space_mem = get_system_memory();
34     MemoryRegion *ram = g_new(MemoryRegion, 1);
35     MemoryRegion *sram = g_new(MemoryRegion, 1);
36 
37     if (!cpu_model) {
38         cpu_model = "m5206";
39     }
40     cpu = cpu_m68k_init(cpu_model);
41     if (!cpu) {
42         hw_error("Unable to find m68k CPU definition\n");
43     }
44     env = &cpu->env;
45 
46     /* Initialize CPU registers.  */
47     env->vbr = 0;
48     /* TODO: allow changing MBAR and RAMBAR.  */
49     env->mbar = AN5206_MBAR_ADDR | 1;
50     env->rambar0 = AN5206_RAMBAR_ADDR | 1;
51 
52     /* DRAM at address zero */
53     memory_region_init_ram(ram, NULL, "an5206.ram", ram_size);
54     vmstate_register_ram_global(ram);
55     memory_region_add_subregion(address_space_mem, 0, ram);
56 
57     /* Internal SRAM.  */
58     memory_region_init_ram(sram, NULL, "an5206.sram", 512);
59     vmstate_register_ram_global(sram);
60     memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
61 
62     mcf5206_init(address_space_mem, AN5206_MBAR_ADDR, cpu);
63 
64     /* Load kernel.  */
65     if (!kernel_filename) {
66         if (qtest_enabled()) {
67             return;
68         }
69         fprintf(stderr, "Kernel image must be specified\n");
70         exit(1);
71     }
72 
73     kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
74                            NULL, NULL, 1, ELF_MACHINE, 0);
75     entry = elf_entry;
76     if (kernel_size < 0) {
77         kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL);
78     }
79     if (kernel_size < 0) {
80         kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
81                                           ram_size - KERNEL_LOAD_ADDR);
82         entry = KERNEL_LOAD_ADDR;
83     }
84     if (kernel_size < 0) {
85         fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
86         exit(1);
87     }
88 
89     env->pc = entry;
90 }
91 
92 static QEMUMachine an5206_machine = {
93     .name = "an5206",
94     .desc = "Arnewsh 5206",
95     .init = an5206_init,
96 };
97 
98 static void an5206_machine_init(void)
99 {
100     qemu_register_machine(&an5206_machine);
101 }
102 
103 machine_init(an5206_machine_init);
104