]> Git Repo - qemu.git/blame - hw/arm_boot.c
Get rid of _t suffix
[qemu.git] / hw / arm_boot.c
CommitLineData
5fafdf24 1/*
16406950
PB
2 * ARM kernel loader.
3 *
9ee6e8bb 4 * Copyright (c) 2006-2007 CodeSourcery.
16406950
PB
5 * Written by Paul Brook
6 *
7 * This code is licenced under the GPL.
8 */
9
87ecb68b
PB
10#include "hw.h"
11#include "arm-misc.h"
12#include "sysemu.h"
ca20cf32
BS
13#include "loader.h"
14#include "elf.h"
16406950
PB
15
16#define KERNEL_ARGS_ADDR 0x100
17#define KERNEL_LOAD_ADDR 0x00010000
18#define INITRD_LOAD_ADDR 0x00800000
19
20/* The worlds second smallest bootloader. Set r0-r2, then jump to kernel. */
21static uint32_t bootloader[] = {
22 0xe3a00000, /* mov r0, #0 */
23 0xe3a01000, /* mov r1, #0x?? */
24 0xe3811c00, /* orr r1, r1, #0x??00 */
25 0xe59f2000, /* ldr r2, [pc, #0] */
26 0xe59ff000, /* ldr pc, [pc, #0] */
27 0, /* Address of kernel args. Set by integratorcp_init. */
28 0 /* Kernel entry point. Set by integratorcp_init. */
29};
30
9ee6e8bb
PB
31/* Entry point for secondary CPUs. Enable interrupt controller and
32 Issue WFI until start address is written to system controller. */
33static uint32_t smpboot[] = {
34 0xe3a00201, /* mov r0, #0x10000000 */
35 0xe3800601, /* orr r0, r0, #0x001000000 */
36 0xe3a01001, /* mov r1, #1 */
37 0xe5801100, /* str r1, [r0, #0x100] */
38 0xe3a00201, /* mov r0, #0x10000000 */
39 0xe3800030, /* orr r0, #0x30 */
40 0xe320f003, /* wfi */
41 0xe5901000, /* ldr r1, [r0] */
42 0xe3110003, /* tst r1, #3 */
43 0x1afffffb, /* bne <wfi> */
44 0xe12fff11 /* bx r1 */
45};
46
f3d6b95e
PB
47static void main_cpu_reset(void *opaque)
48{
49 CPUState *env = opaque;
50
51 cpu_reset(env);
f93eb9ff
AZ
52 if (env->boot_info)
53 arm_load_kernel(env, env->boot_info);
9ee6e8bb
PB
54
55 /* TODO: Reset secondary CPUs. */
f3d6b95e
PB
56}
57
52b43737
PB
58#define WRITE_WORD(p, value) do { \
59 stl_phys_notdirty(p, value); \
60 p += 4; \
61} while (0)
62
f93eb9ff 63static void set_kernel_args(struct arm_boot_info *info,
99a0949b 64 int initrd_size, a_target_phys_addr base)
16406950 65{
99a0949b 66 a_target_phys_addr p;
16406950 67
52b43737 68 p = base + KERNEL_ARGS_ADDR;
16406950 69 /* ATAG_CORE */
52b43737
PB
70 WRITE_WORD(p, 5);
71 WRITE_WORD(p, 0x54410001);
72 WRITE_WORD(p, 1);
73 WRITE_WORD(p, 0x1000);
74 WRITE_WORD(p, 0);
16406950 75 /* ATAG_MEM */
f93eb9ff 76 /* TODO: handle multiple chips on one ATAG list */
52b43737
PB
77 WRITE_WORD(p, 4);
78 WRITE_WORD(p, 0x54410002);
79 WRITE_WORD(p, info->ram_size);
80 WRITE_WORD(p, info->loader_start);
16406950
PB
81 if (initrd_size) {
82 /* ATAG_INITRD2 */
52b43737
PB
83 WRITE_WORD(p, 4);
84 WRITE_WORD(p, 0x54420005);
85 WRITE_WORD(p, info->loader_start + INITRD_LOAD_ADDR);
86 WRITE_WORD(p, initrd_size);
16406950 87 }
f93eb9ff 88 if (info->kernel_cmdline && *info->kernel_cmdline) {
16406950
PB
89 /* ATAG_CMDLINE */
90 int cmdline_size;
91
f93eb9ff 92 cmdline_size = strlen(info->kernel_cmdline);
52b43737
PB
93 cpu_physical_memory_write(p + 8, (void *)info->kernel_cmdline,
94 cmdline_size + 1);
16406950 95 cmdline_size = (cmdline_size >> 2) + 1;
52b43737
PB
96 WRITE_WORD(p, cmdline_size + 2);
97 WRITE_WORD(p, 0x54410009);
98 p += cmdline_size * 4;
16406950 99 }
f93eb9ff
AZ
100 if (info->atag_board) {
101 /* ATAG_BOARD */
102 int atag_board_len;
52b43737 103 uint8_t atag_board_buf[0x1000];
f93eb9ff 104
52b43737
PB
105 atag_board_len = (info->atag_board(info, atag_board_buf) + 3) & ~3;
106 WRITE_WORD(p, (atag_board_len + 8) >> 2);
107 WRITE_WORD(p, 0x414f4d50);
108 cpu_physical_memory_write(p, atag_board_buf, atag_board_len);
f93eb9ff
AZ
109 p += atag_board_len;
110 }
16406950 111 /* ATAG_END */
52b43737
PB
112 WRITE_WORD(p, 0);
113 WRITE_WORD(p, 0);
16406950
PB
114}
115
f93eb9ff 116static void set_kernel_args_old(struct arm_boot_info *info,
99a0949b 117 int initrd_size, a_target_phys_addr base)
2b8f2d41 118{
99a0949b 119 a_target_phys_addr p;
52b43737
PB
120 const char *s;
121
2b8f2d41
AZ
122
123 /* see linux/include/asm-arm/setup.h */
52b43737 124 p = base + KERNEL_ARGS_ADDR;
2b8f2d41 125 /* page_size */
52b43737 126 WRITE_WORD(p, 4096);
2b8f2d41 127 /* nr_pages */
52b43737 128 WRITE_WORD(p, info->ram_size / 4096);
2b8f2d41 129 /* ramdisk_size */
52b43737 130 WRITE_WORD(p, 0);
2b8f2d41
AZ
131#define FLAG_READONLY 1
132#define FLAG_RDLOAD 4
133#define FLAG_RDPROMPT 8
134 /* flags */
52b43737 135 WRITE_WORD(p, FLAG_READONLY | FLAG_RDLOAD | FLAG_RDPROMPT);
2b8f2d41 136 /* rootdev */
52b43737 137 WRITE_WORD(p, (31 << 8) | 0); /* /dev/mtdblock0 */
2b8f2d41 138 /* video_num_cols */
52b43737 139 WRITE_WORD(p, 0);
2b8f2d41 140 /* video_num_rows */
52b43737 141 WRITE_WORD(p, 0);
2b8f2d41 142 /* video_x */
52b43737 143 WRITE_WORD(p, 0);
2b8f2d41 144 /* video_y */
52b43737 145 WRITE_WORD(p, 0);
2b8f2d41 146 /* memc_control_reg */
52b43737 147 WRITE_WORD(p, 0);
2b8f2d41
AZ
148 /* unsigned char sounddefault */
149 /* unsigned char adfsdrives */
150 /* unsigned char bytes_per_char_h */
151 /* unsigned char bytes_per_char_v */
52b43737 152 WRITE_WORD(p, 0);
2b8f2d41 153 /* pages_in_bank[4] */
52b43737
PB
154 WRITE_WORD(p, 0);
155 WRITE_WORD(p, 0);
156 WRITE_WORD(p, 0);
157 WRITE_WORD(p, 0);
2b8f2d41 158 /* pages_in_vram */
52b43737 159 WRITE_WORD(p, 0);
2b8f2d41
AZ
160 /* initrd_start */
161 if (initrd_size)
52b43737 162 WRITE_WORD(p, info->loader_start + INITRD_LOAD_ADDR);
2b8f2d41 163 else
52b43737 164 WRITE_WORD(p, 0);
2b8f2d41 165 /* initrd_size */
52b43737 166 WRITE_WORD(p, initrd_size);
2b8f2d41 167 /* rd_start */
52b43737 168 WRITE_WORD(p, 0);
2b8f2d41 169 /* system_rev */
52b43737 170 WRITE_WORD(p, 0);
2b8f2d41 171 /* system_serial_low */
52b43737 172 WRITE_WORD(p, 0);
2b8f2d41 173 /* system_serial_high */
52b43737 174 WRITE_WORD(p, 0);
2b8f2d41 175 /* mem_fclk_21285 */
52b43737 176 WRITE_WORD(p, 0);
2b8f2d41 177 /* zero unused fields */
52b43737
PB
178 while (p < base + KERNEL_ARGS_ADDR + 256 + 1024) {
179 WRITE_WORD(p, 0);
180 }
181 s = info->kernel_cmdline;
182 if (s) {
183 cpu_physical_memory_write(p, (void *)s, strlen(s) + 1);
184 } else {
185 WRITE_WORD(p, 0);
186 }
2b8f2d41
AZ
187}
188
f93eb9ff 189void arm_load_kernel(CPUState *env, struct arm_boot_info *info)
16406950
PB
190{
191 int kernel_size;
192 int initrd_size;
193 int n;
1c7b3754
PB
194 int is_linux = 0;
195 uint64_t elf_entry;
99a0949b 196 a_target_phys_addr entry;
ca20cf32 197 int big_endian;
16406950
PB
198
199 /* Load the kernel. */
f93eb9ff 200 if (!info->kernel_filename) {
16406950
PB
201 fprintf(stderr, "Kernel image must be specified\n");
202 exit(1);
203 }
daf90626 204
f93eb9ff
AZ
205 if (!env->boot_info) {
206 if (info->nb_cpus == 0)
207 info->nb_cpus = 1;
208 env->boot_info = info;
a08d4367 209 qemu_register_reset(main_cpu_reset, env);
f3d6b95e 210 }
f93eb9ff 211
ca20cf32
BS
212#ifdef TARGET_WORDS_BIGENDIAN
213 big_endian = 1;
214#else
215 big_endian = 0;
216#endif
217
1c7b3754 218 /* Assume that raw images are linux kernels, and ELF images are not. */
ca20cf32
BS
219 kernel_size = load_elf(info->kernel_filename, 0, &elf_entry, NULL, NULL,
220 big_endian, ELF_MACHINE, 1);
1c7b3754
PB
221 entry = elf_entry;
222 if (kernel_size < 0) {
5a9154e0
AL
223 kernel_size = load_uimage(info->kernel_filename, &entry, NULL,
224 &is_linux);
1c7b3754
PB
225 }
226 if (kernel_size < 0) {
f93eb9ff 227 entry = info->loader_start + KERNEL_LOAD_ADDR;
3b760e04
PB
228 kernel_size = load_image_targphys(info->kernel_filename, entry,
229 ram_size - KERNEL_LOAD_ADDR);
1c7b3754
PB
230 is_linux = 1;
231 }
232 if (kernel_size < 0) {
f93eb9ff
AZ
233 fprintf(stderr, "qemu: could not load kernel '%s'\n",
234 info->kernel_filename);
1c7b3754
PB
235 exit(1);
236 }
237 if (!is_linux) {
238 /* Jump to the entry point. */
daf90626
PB
239 env->regs[15] = entry & 0xfffffffe;
240 env->thumb = entry & 1;
241 } else {
f93eb9ff 242 if (info->initrd_filename) {
3b760e04
PB
243 initrd_size = load_image_targphys(info->initrd_filename,
244 info->loader_start
245 + INITRD_LOAD_ADDR,
246 ram_size - INITRD_LOAD_ADDR);
daf90626
PB
247 if (initrd_size < 0) {
248 fprintf(stderr, "qemu: could not load initrd '%s'\n",
f93eb9ff 249 info->initrd_filename);
daf90626
PB
250 exit(1);
251 }
252 } else {
253 initrd_size = 0;
254 }
f93eb9ff
AZ
255 bootloader[1] |= info->board_id & 0xff;
256 bootloader[2] |= (info->board_id >> 8) & 0xff;
257 bootloader[5] = info->loader_start + KERNEL_ARGS_ADDR;
1c7b3754 258 bootloader[6] = entry;
52b43737
PB
259 for (n = 0; n < sizeof(bootloader) / 4; n++) {
260 stl_phys_notdirty(info->loader_start + (n * 4), bootloader[n]);
261 }
262 if (info->nb_cpus > 1) {
263 for (n = 0; n < sizeof(smpboot) / 4; n++) {
264 stl_phys_notdirty(info->smp_loader_start + (n * 4), smpboot[n]);
265 }
266 }
2b8f2d41 267 if (old_param)
52b43737 268 set_kernel_args_old(info, initrd_size, info->loader_start);
2b8f2d41 269 else
52b43737 270 set_kernel_args(info, initrd_size, info->loader_start);
16406950 271 }
16406950 272}
This page took 0.296548 seconds and 4 git commands to generate.