hppa: specify target_phys_bits in configure script
[qemu/hppa.git] / hw / dummy_hppa.c
blobb7969093fb08f5b23185f8cd5a263141b9d25abf
1 /*
2 * Dummy HPPA machine.
4 * Copyright (c) 2009 Stuart Brady, Laurent Desnogues
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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
21 /* This platform is based on IntegratorCP. */
22 #include "hw.h"
23 #include "hw/pc.h"
24 #include "boards.h"
26 /* Boot */
27 #include "sysemu.h"
29 #define KERNEL_ARGS_ADDR 0x100
30 #define KERNEL_LOAD_ADDR 0x00010000
31 #define INITRD_LOAD_ADDR 0x00800000
33 static uint32_t bootloader[] = {
34 0, /* Address of kernel args. Set by hppa_load_kernel. */
35 0 /* Kernel entry point. Set by hppa_load_kernel. */
38 struct hppa_boot_info {
39 int ram_size;
40 const char *kernel_filename;
41 const char *kernel_cmdline;
42 const char *initrd_filename;
43 target_phys_addr_t loader_start;
44 int nb_cpus;
46 static void hppa_load_kernel(CPUState *env, struct hppa_boot_info *info);
48 static void main_cpu_reset(void *opaque)
50 CPUState *env = opaque;
52 cpu_reset(env);
53 if (env->boot_info)
54 hppa_load_kernel(env, env->boot_info);
57 /* XXX: tempo */
58 static void set_kernel_args(struct hppa_boot_info *info,
59 int initrd_size, target_phys_addr_t base)
63 /* XXX: tempo */
64 static
65 void hppa_load_kernel(CPUState *env, struct hppa_boot_info *info)
67 int kernel_size;
68 int initrd_size;
69 int n;
70 int is_linux = 0;
71 target_ulong entry;
72 uint64_t elf_entry;
74 /* Load the kernel. */
75 if (!info->kernel_filename) {
76 fprintf(stderr, "Kernel image must be specified\n");
77 exit(1);
80 if (!env->boot_info) {
81 if (info->nb_cpus == 0)
82 info->nb_cpus = 1;
83 env->boot_info = info;
84 qemu_register_reset(main_cpu_reset, 0, env);
87 /* Assume that raw images are linux kernels, and ELF images are not. */
88 kernel_size = load_elf(info->kernel_filename, 0, &elf_entry, NULL, NULL);
89 entry = elf_entry;
90 if (kernel_size < 0) {
91 kernel_size = load_uimage(info->kernel_filename, &entry, NULL,
92 &is_linux);
94 if (kernel_size < 0) {
95 entry = info->loader_start + KERNEL_LOAD_ADDR;
96 kernel_size = load_image_targphys(info->kernel_filename, entry,
97 ram_size - KERNEL_LOAD_ADDR);
98 is_linux = 1;
100 if (kernel_size < 0) {
101 fprintf(stderr, "qemu: could not load kernel '%s'\n",
102 info->kernel_filename);
103 exit(1);
105 if (!is_linux) {
106 /* Jump to the entry point. */
107 env->iaoq[0] = entry;
108 env->iaoq[1] = entry + 4;
109 } else {
110 if (info->initrd_filename) {
111 initrd_size = load_image_targphys(info->initrd_filename,
112 info->loader_start
113 + INITRD_LOAD_ADDR,
114 ram_size - INITRD_LOAD_ADDR);
115 if (initrd_size < 0) {
116 fprintf(stderr, "qemu: could not load initrd '%s'\n",
117 info->initrd_filename);
118 exit(1);
120 } else {
121 initrd_size = 0;
123 /* XXX: change these indices. */
124 /* bootloader[1] = info->loader_start + KERNEL_ARGS_ADDR; */
125 /* bootloader[2] = entry; */
126 for (n = 0; n < sizeof(bootloader) / 4; n++) {
127 stl_phys_notdirty(info->loader_start + (n * 4), bootloader[n]);
129 set_kernel_args(info, initrd_size, info->loader_start);
133 /* XXX: tempo */
134 typedef struct {
135 } dummy_hppa_state;
137 /* XXX: tempo */
138 void irq_info(Monitor *mon)
142 /* XXX: tempo */
143 void pic_info(Monitor *mon)
147 #if 0
148 /* XXX: tempo */
149 static uint32_t dummy_hppa_read(void *opaque, target_phys_addr_t offset)
151 //dummy_hppa_state *s = (dummy_hppa_state *)opaque;
153 cpu_abort(cpu_single_env,
154 "dummy_hppa_read: Unimplemented offset 0x%x\n", (int)offset);
155 return 0;
158 /* XXX: tempo */
159 static void dummy_hppa_write(void *opaque, target_phys_addr_t offset,
160 uint32_t value)
162 //dummy_hppa_state *s = (dummy_hppa_state *)opaque;
164 cpu_abort(cpu_single_env,
165 "dummy_hppa_write: Unimplemented offset 0x%x\n", (int)offset);
168 /* Dummy HPPA board control registers. */
170 static CPUReadMemoryFunc *dummy_hppa_readfn[] = {
171 dummy_hppa_read,
172 dummy_hppa_read,
173 dummy_hppa_read
176 static CPUWriteMemoryFunc *dummy_hppa_writefn[] = {
177 dummy_hppa_write,
178 dummy_hppa_write,
179 dummy_hppa_write
182 /* int iomemtype; */
183 /* dummy_hppa_state *s; */
185 /* s = (dummy_hppa_state *)qemu_mallocz(sizeof(dummy_hppa_state)); */
187 /* iomemtype = cpu_register_io_memory(0, dummy_hppa_readfn, */
188 /* dummy_hppa_writefn, s); */
189 /* cpu_register_physical_memory(0x10000000, 0x00800000, iomemtype); */
190 /* cpu_register_physical_memory(0, 0x100000, IO_MEM_RAM); */
191 #endif
193 /* Board init. */
195 static struct hppa_boot_info hppa_binfo = {
196 .loader_start = 0x0,
199 /* XXX: tempo */
200 static
201 void dummy_hppa_init(ram_addr_t ram_size,
202 const char *boot_device,
203 const char *kernel_filename, const char *kernel_cmdline,
204 const char *initrd_filename, const char *cpu_model)
206 CPUState *env;
207 ram_addr_t ram_offset;
209 env = cpu_init(cpu_model);
210 if (!env) {
211 fprintf(stderr, "Unable to find CPU definition\n");
212 exit(1);
215 ram_offset = qemu_ram_alloc(ram_size);
216 cpu_register_physical_memory(0, ram_size, ram_offset | IO_MEM_RAM);
218 hppa_binfo.ram_size = ram_size;
219 hppa_binfo.kernel_filename = kernel_filename;
220 hppa_binfo.kernel_cmdline = kernel_cmdline;
221 hppa_binfo.initrd_filename = initrd_filename;
222 hppa_load_kernel(env, &hppa_binfo);
225 static QEMUMachine dummy_hppa_machine = {
226 .name = "dummy",
227 .desc = "Dummy HPPA board",
228 .init = dummy_hppa_init,
231 static void dummy_hppa_machine_init(void)
233 qemu_register_machine(&dummy_hppa_machine);
236 machine_init(dummy_hppa_machine_init);