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. */
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
{
40 const char *kernel_filename
;
41 const char *kernel_cmdline
;
42 const char *initrd_filename
;
43 target_phys_addr_t loader_start
;
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
;
54 hppa_load_kernel(env
, env
->boot_info
);
58 static void set_kernel_args(struct hppa_boot_info
*info
,
59 int initrd_size
, target_phys_addr_t base
)
65 void hppa_load_kernel(CPUState
*env
, struct hppa_boot_info
*info
)
74 /* Load the kernel. */
75 if (!info
->kernel_filename
) {
76 fprintf(stderr
, "Kernel image must be specified\n");
80 if (!env
->boot_info
) {
81 if (info
->nb_cpus
== 0)
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
);
90 if (kernel_size
< 0) {
91 kernel_size
= load_uimage(info
->kernel_filename
, &entry
, NULL
,
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
);
100 if (kernel_size
< 0) {
101 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
102 info
->kernel_filename
);
106 /* Jump to the entry point. */
107 env
->iaoq
[0] = entry
;
108 env
->iaoq
[1] = entry
+ 4;
110 if (info
->initrd_filename
) {
111 initrd_size
= load_image_targphys(info
->initrd_filename
,
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
);
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
);
138 void irq_info(Monitor
*mon
)
143 void pic_info(Monitor
*mon
)
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
);
159 static void dummy_hppa_write(void *opaque
, target_phys_addr_t offset
,
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
[] = {
176 static CPUWriteMemoryFunc
*dummy_hppa_writefn
[] = {
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); */
195 static struct hppa_boot_info hppa_binfo
= {
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
)
207 ram_addr_t ram_offset
;
209 env
= cpu_init(cpu_model
);
211 fprintf(stderr
, "Unable to find CPU definition\n");
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
= {
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
);