2 * arch/ia64/boot/bootloader.c
6 * Copyright (C) 1998, 1999, 2001 Hewlett-Packard Co
7 * Copyright (C) 1998, 1999, 2001 David Mosberger-Tang <davidm@hpl.hp.com>
8 * Copyright (C) 1998, 1999 Stephane Eranian <eranian@hpl.hp.com>
10 * 01/07/99 S.Eranian modified to pass command line arguments to kernel
12 #include <linux/config.h>
13 #include <linux/elf.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
19 #include <asm/pgtable.h>
21 #include <asm/system.h>
23 /* Simulator system calls: */
25 #define SSC_CONSOLE_INIT 20
26 #define SSC_GETCHAR 21
27 #define SSC_PUTCHAR 31
32 #define SSC_GET_COMPLETION 54
33 #define SSC_WAIT_COMPLETION 55
34 #define SSC_CONNECT_INTERRUPT 58
35 #define SSC_GENERATE_INTERRUPT 59
36 #define SSC_SET_PERIODIC_INTERRUPT 60
37 #define SSC_GET_RTC 65
39 #define SSC_LOAD_SYMBOLS 69
40 #define SSC_GET_TOD 74
42 #define SSC_GET_ARGS 75
54 #include "../kernel/fw-emu.c"
57 * Set a break point on this function so that symbols are available to set breakpoints in
58 * the kernel being debugged.
66 cons_write (const char *buf)
70 while ((ch = *buf++) != '\0') {
71 ssc(ch, 0, 0, 0, SSC_PUTCHAR);
73 ssc('\r', 0, 0, 0, SSC_PUTCHAR);
82 static char stack[16384] __attribute__ ((aligned (16)));
83 static char mem[4096];
84 static char buffer[1024];
88 struct disk_stat stat;
90 struct elf_phdr *elf_phdr; /* program header */
91 unsigned long e_entry, e_phoff, e_phnum;
92 register struct ia64_boot_param *bp;
96 asm volatile ("movl gp=__gp;;" ::: "memory");
97 asm volatile ("mov sp=%0" :: "r"(stack) : "memory");
98 asm volatile ("bsw.1;;");
100 ssc(0, 0, 0, 0, SSC_CONSOLE_INIT);
103 * S.Eranian: extract the commandline argument from the simulator
105 * The expected format is as follows:
109 * Both are optional but you can't have the second one without the first.
111 arglen = ssc((long) buffer, 0, 0, 0, SSC_GET_ARGS);
117 while (*args != ' ' && *args != '\0')
120 *args++ = '\0', --arglen;
128 fd = ssc((long) kpath, 1, 0, 0, SSC_OPEN);
132 cons_write(": file not found, reboot now\n");
138 req.len = sizeof(mem);
139 req.addr = (long) mem;
140 ssc(fd, 1, (long) &req, off, SSC_READ);
141 ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
143 elf = (struct elfhdr *) mem;
144 if (elf->e_ident[0] == 0x7f && strncmp(elf->e_ident + 1, "ELF", 3) != 0) {
145 cons_write("not an ELF file\n");
148 if (elf->e_type != ET_EXEC) {
149 cons_write("not an ELF executable\n");
152 if (!elf_check_arch(elf)) {
153 cons_write("kernel not for this processor\n");
157 e_entry = elf->e_entry;
158 e_phnum = elf->e_phnum;
159 e_phoff = elf->e_phoff;
161 cons_write("loading ");
165 for (i = 0; i < e_phnum; ++i) {
166 req.len = sizeof(*elf_phdr);
167 req.addr = (long) mem;
168 ssc(fd, 1, (long) &req, e_phoff, SSC_READ);
169 ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
170 if (stat.count != sizeof(*elf_phdr)) {
171 cons_write("failed to read phdr\n");
174 e_phoff += sizeof(*elf_phdr);
176 elf_phdr = (struct elf_phdr *) mem;
178 if (elf_phdr->p_type != PT_LOAD)
181 req.len = elf_phdr->p_filesz;
182 req.addr = __pa(elf_phdr->p_vaddr);
183 ssc(fd, 1, (long) &req, elf_phdr->p_offset, SSC_READ);
184 ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
185 memset((char *)__pa(elf_phdr->p_vaddr) + elf_phdr->p_filesz, 0,
186 elf_phdr->p_memsz - elf_phdr->p_filesz);
188 ssc(fd, 0, 0, 0, SSC_CLOSE);
190 cons_write("starting kernel...\n");
192 /* fake an I/O base address: */
193 asm volatile ("mov ar.k0=%0" :: "r"(0xffffc000000UL));
195 bp = sys_fw_init(args, arglen);
197 ssc(0, (long) kpath, 0, 0, SSC_LOAD_SYMBOLS);
200 asm volatile ("mov sp=%2; mov r28=%1; br.sptk.few %0"
201 :: "b"(e_entry), "r"(bp), "r"(__pa(&stack)));
203 cons_write("kernel returned!\n");
204 ssc(-1, 0, 0, 0, SSC_EXIT);