sun4u_iommu: update to reflect IOMMU is no longer part of the APB device
[qemu/ar7.git] / hw / moxie / moxiesim.c
blob6c200becaba6dc47917f3a7fc302a137cf701fcd
1 /*
2 * QEMU/moxiesim emulation
4 * Emulates a very simple machine model similar to the one used by the
5 * GDB moxie simulator.
7 * Copyright (c) 2008, 2009, 2010, 2013 Anthony Green
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
27 #include "qemu/osdep.h"
28 #include "qemu/error-report.h"
29 #include "qapi/error.h"
30 #include "qemu-common.h"
31 #include "cpu.h"
32 #include "hw/sysbus.h"
33 #include "hw/hw.h"
34 #include "hw/isa/isa.h"
35 #include "net/net.h"
36 #include "sysemu/sysemu.h"
37 #include "hw/boards.h"
38 #include "hw/loader.h"
39 #include "hw/char/serial.h"
40 #include "exec/address-spaces.h"
41 #include "elf.h"
43 #define PHYS_MEM_BASE 0x80000000
44 #define FIRMWARE_BASE 0x1000
45 #define FIRMWARE_SIZE (128 * 0x1000)
47 typedef struct {
48 uint64_t ram_size;
49 const char *kernel_filename;
50 const char *kernel_cmdline;
51 const char *initrd_filename;
52 } LoaderParams;
54 static void load_kernel(MoxieCPU *cpu, LoaderParams *loader_params)
56 uint64_t entry, kernel_low, kernel_high;
57 long kernel_size;
58 long initrd_size;
59 ram_addr_t initrd_offset;
61 kernel_size = load_elf(loader_params->kernel_filename, NULL, NULL,
62 &entry, &kernel_low, &kernel_high, 1, EM_MOXIE,
63 0, 0);
65 if (kernel_size <= 0) {
66 fprintf(stderr, "qemu: could not load kernel '%s'\n",
67 loader_params->kernel_filename);
68 exit(1);
71 /* load initrd */
72 initrd_size = 0;
73 initrd_offset = 0;
74 if (loader_params->initrd_filename) {
75 initrd_size = get_image_size(loader_params->initrd_filename);
76 if (initrd_size > 0) {
77 initrd_offset = (kernel_high + ~TARGET_PAGE_MASK)
78 & TARGET_PAGE_MASK;
79 if (initrd_offset + initrd_size > loader_params->ram_size) {
80 fprintf(stderr,
81 "qemu: memory too small for initial ram disk '%s'\n",
82 loader_params->initrd_filename);
83 exit(1);
85 initrd_size = load_image_targphys(loader_params->initrd_filename,
86 initrd_offset,
87 ram_size);
89 if (initrd_size == (target_ulong)-1) {
90 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
91 loader_params->initrd_filename);
92 exit(1);
97 static void main_cpu_reset(void *opaque)
99 MoxieCPU *cpu = opaque;
101 cpu_reset(CPU(cpu));
104 static void moxiesim_init(MachineState *machine)
106 MoxieCPU *cpu = NULL;
107 ram_addr_t ram_size = machine->ram_size;
108 const char *kernel_filename = machine->kernel_filename;
109 const char *kernel_cmdline = machine->kernel_cmdline;
110 const char *initrd_filename = machine->initrd_filename;
111 CPUMoxieState *env;
112 MemoryRegion *address_space_mem = get_system_memory();
113 MemoryRegion *ram = g_new(MemoryRegion, 1);
114 MemoryRegion *rom = g_new(MemoryRegion, 1);
115 hwaddr ram_base = 0x200000;
116 LoaderParams loader_params;
118 /* Init CPUs. */
119 cpu = MOXIE_CPU(cpu_create(machine->cpu_type));
120 env = &cpu->env;
122 qemu_register_reset(main_cpu_reset, cpu);
124 /* Allocate RAM. */
125 memory_region_init_ram(ram, NULL, "moxiesim.ram", ram_size, &error_fatal);
126 memory_region_add_subregion(address_space_mem, ram_base, ram);
128 memory_region_init_ram(rom, NULL, "moxie.rom", FIRMWARE_SIZE, &error_fatal);
129 memory_region_add_subregion(get_system_memory(), FIRMWARE_BASE, rom);
131 if (kernel_filename) {
132 loader_params.ram_size = ram_size;
133 loader_params.kernel_filename = kernel_filename;
134 loader_params.kernel_cmdline = kernel_cmdline;
135 loader_params.initrd_filename = initrd_filename;
136 load_kernel(cpu, &loader_params);
138 if (bios_name) {
139 if (load_image_targphys(bios_name, FIRMWARE_BASE, FIRMWARE_SIZE) < 0) {
140 error_report("Failed to load firmware '%s'", bios_name);
144 /* A single 16450 sits at offset 0x3f8. */
145 if (serial_hds[0]) {
146 serial_mm_init(address_space_mem, 0x3f8, 0, env->irq[4],
147 8000000/16, serial_hds[0], DEVICE_LITTLE_ENDIAN);
151 static void moxiesim_machine_init(MachineClass *mc)
153 mc->desc = "Moxie simulator platform";
154 mc->init = moxiesim_init;
155 mc->is_default = 1;
156 mc->default_cpu_type = MOXIE_CPU_TYPE_NAME("MoxieLite");
159 DEFINE_MACHINE("moxiesim", moxiesim_machine_init)