target-arm: Implement AArch64 views of AArch32 ID registers
[qemu.git] / hw / lm32 / milkymist.c
blobbaf234ce04d555a0b7445274ea1368d6917266bc
1 /*
2 * QEMU model for the Milkymist board.
4 * Copyright (c) 2010 Michael Walle <michael@walle.cc>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "hw/sysbus.h"
21 #include "hw/hw.h"
22 #include "hw/block/flash.h"
23 #include "sysemu/sysemu.h"
24 #include "sysemu/qtest.h"
25 #include "hw/devices.h"
26 #include "hw/boards.h"
27 #include "hw/loader.h"
28 #include "elf.h"
29 #include "sysemu/blockdev.h"
30 #include "milkymist-hw.h"
31 #include "lm32.h"
32 #include "exec/address-spaces.h"
34 #define BIOS_FILENAME "mmone-bios.bin"
35 #define BIOS_OFFSET 0x00860000
36 #define BIOS_SIZE (512*1024)
37 #define KERNEL_LOAD_ADDR 0x40000000
39 typedef struct {
40 LM32CPU *cpu;
41 hwaddr bootstrap_pc;
42 hwaddr flash_base;
43 hwaddr initrd_base;
44 size_t initrd_size;
45 hwaddr cmdline_base;
46 } ResetInfo;
48 static void cpu_irq_handler(void *opaque, int irq, int level)
50 LM32CPU *cpu = opaque;
51 CPUState *cs = CPU(cpu);
53 if (level) {
54 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
55 } else {
56 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
60 static void main_cpu_reset(void *opaque)
62 ResetInfo *reset_info = opaque;
63 CPULM32State *env = &reset_info->cpu->env;
65 cpu_reset(CPU(reset_info->cpu));
67 /* init defaults */
68 env->pc = reset_info->bootstrap_pc;
69 env->regs[R_R1] = reset_info->cmdline_base;
70 env->regs[R_R2] = reset_info->initrd_base;
71 env->regs[R_R3] = reset_info->initrd_base + reset_info->initrd_size;
72 env->eba = reset_info->flash_base;
73 env->deba = reset_info->flash_base;
76 static void
77 milkymist_init(QEMUMachineInitArgs *args)
79 const char *cpu_model = args->cpu_model;
80 const char *kernel_filename = args->kernel_filename;
81 const char *kernel_cmdline = args->kernel_cmdline;
82 const char *initrd_filename = args->initrd_filename;
83 LM32CPU *cpu;
84 CPULM32State *env;
85 int kernel_size;
86 DriveInfo *dinfo;
87 MemoryRegion *address_space_mem = get_system_memory();
88 MemoryRegion *phys_sdram = g_new(MemoryRegion, 1);
89 qemu_irq irq[32], *cpu_irq;
90 int i;
91 char *bios_filename;
92 ResetInfo *reset_info;
94 /* memory map */
95 hwaddr flash_base = 0x00000000;
96 size_t flash_sector_size = 128 * 1024;
97 size_t flash_size = 32 * 1024 * 1024;
98 hwaddr sdram_base = 0x40000000;
99 size_t sdram_size = 128 * 1024 * 1024;
101 hwaddr initrd_base = sdram_base + 0x1002000;
102 hwaddr cmdline_base = sdram_base + 0x1000000;
103 size_t initrd_max = sdram_size - 0x1002000;
105 reset_info = g_malloc0(sizeof(ResetInfo));
107 if (cpu_model == NULL) {
108 cpu_model = "lm32-full";
110 cpu = cpu_lm32_init(cpu_model);
111 if (cpu == NULL) {
112 fprintf(stderr, "qemu: unable to find CPU '%s'\n", cpu_model);
113 exit(1);
116 env = &cpu->env;
117 reset_info->cpu = cpu;
119 cpu_lm32_set_phys_msb_ignore(env, 1);
121 memory_region_init_ram(phys_sdram, NULL, "milkymist.sdram", sdram_size);
122 vmstate_register_ram_global(phys_sdram);
123 memory_region_add_subregion(address_space_mem, sdram_base, phys_sdram);
125 dinfo = drive_get(IF_PFLASH, 0, 0);
126 /* Numonyx JS28F256J3F105 */
127 pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size,
128 dinfo ? dinfo->bdrv : NULL, flash_sector_size,
129 flash_size / flash_sector_size, 2,
130 0x00, 0x89, 0x00, 0x1d, 1);
132 /* create irq lines */
133 cpu_irq = qemu_allocate_irqs(cpu_irq_handler, cpu, 1);
134 env->pic_state = lm32_pic_init(*cpu_irq);
135 for (i = 0; i < 32; i++) {
136 irq[i] = qdev_get_gpio_in(env->pic_state, i);
139 /* load bios rom */
140 if (bios_name == NULL) {
141 bios_name = BIOS_FILENAME;
143 bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
145 if (bios_filename) {
146 load_image_targphys(bios_filename, BIOS_OFFSET, BIOS_SIZE);
149 reset_info->bootstrap_pc = BIOS_OFFSET;
151 /* if no kernel is given no valid bios rom is a fatal error */
152 if (!kernel_filename && !dinfo && !bios_filename && !qtest_enabled()) {
153 fprintf(stderr, "qemu: could not load Milkymist One bios '%s'\n",
154 bios_name);
155 exit(1);
158 milkymist_uart_create(0x60000000, irq[0]);
159 milkymist_sysctl_create(0x60001000, irq[1], irq[2], irq[3],
160 80000000, 0x10014d31, 0x0000041f, 0x00000001);
161 milkymist_hpdmc_create(0x60002000);
162 milkymist_vgafb_create(0x60003000, 0x40000000, 0x0fffffff);
163 milkymist_memcard_create(0x60004000);
164 milkymist_ac97_create(0x60005000, irq[4], irq[5], irq[6], irq[7]);
165 milkymist_pfpu_create(0x60006000, irq[8]);
166 milkymist_tmu2_create(0x60007000, irq[9]);
167 milkymist_minimac2_create(0x60008000, 0x30000000, irq[10], irq[11]);
168 milkymist_softusb_create(0x6000f000, irq[15],
169 0x20000000, 0x1000, 0x20020000, 0x2000);
171 /* make sure juart isn't the first chardev */
172 env->juart_state = lm32_juart_init();
174 if (kernel_filename) {
175 uint64_t entry;
177 /* Boots a kernel elf binary. */
178 kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL,
179 1, ELF_MACHINE, 0);
180 reset_info->bootstrap_pc = entry;
182 if (kernel_size < 0) {
183 kernel_size = load_image_targphys(kernel_filename, sdram_base,
184 sdram_size);
185 reset_info->bootstrap_pc = sdram_base;
188 if (kernel_size < 0) {
189 fprintf(stderr, "qemu: could not load kernel '%s'\n",
190 kernel_filename);
191 exit(1);
195 if (kernel_cmdline && strlen(kernel_cmdline)) {
196 pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
197 kernel_cmdline);
198 reset_info->cmdline_base = (uint32_t)cmdline_base;
201 if (initrd_filename) {
202 size_t initrd_size;
203 initrd_size = load_image_targphys(initrd_filename, initrd_base,
204 initrd_max);
205 reset_info->initrd_base = (uint32_t)initrd_base;
206 reset_info->initrd_size = (uint32_t)initrd_size;
209 qemu_register_reset(main_cpu_reset, reset_info);
212 static QEMUMachine milkymist_machine = {
213 .name = "milkymist",
214 .desc = "Milkymist One",
215 .init = milkymist_init,
216 .is_default = 0,
219 static void milkymist_machine_init(void)
221 qemu_register_machine(&milkymist_machine);
224 machine_init(milkymist_machine_init);