2 * arch/ia64/hp/sim/boot/bootloader.c
6 * Copyright (C) 1998-2003 Hewlett-Packard Co
7 * David Mosberger-Tang <davidm@hpl.hp.com>
8 * Stephane Eranian <eranian@hpl.hp.com>
10 * 01/07/99 S.Eranian modified to pass command line arguments to kernel
12 struct task_struct; /* forward declaration for elf.h */
14 #include <linux/elf.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
19 #include <asm/intrinsics.h>
21 #include <asm/pgtable.h>
36 extern void jmp_to_kernel (unsigned long bp, unsigned long e_entry);
37 extern struct ia64_boot_param *sys_fw_init (const char *args, int arglen);
38 extern void debug_break (void);
41 cons_write (const char *buf)
45 while ((ch = *buf++) != '\0') {
46 ssc(ch, 0, 0, 0, SSC_PUTCHAR);
48 ssc('\r', 0, 0, 0, SSC_PUTCHAR);
55 start_bootloader (void)
57 static char mem[4096];
58 static char buffer[1024];
62 struct disk_stat stat;
64 struct elf_phdr *elf_phdr; /* program header */
65 unsigned long e_entry, e_phoff, e_phnum;
66 register struct ia64_boot_param *bp;
70 ssc(0, 0, 0, 0, SSC_CONSOLE_INIT);
73 * S.Eranian: extract the commandline argument from the simulator
75 * The expected format is as follows:
79 * Both are optional but you can't have the second one without the first.
81 arglen = ssc((long) buffer, 0, 0, 0, SSC_GET_ARGS);
87 while (*args != ' ' && *args != '\0')
90 *args++ = '\0', --arglen;
98 fd = ssc((long) kpath, 1, 0, 0, SSC_OPEN);
102 cons_write(": file not found, reboot now\n");
108 req.len = sizeof(mem);
109 req.addr = (long) mem;
110 ssc(fd, 1, (long) &req, off, SSC_READ);
111 ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
113 elf = (struct elfhdr *) mem;
114 if (elf->e_ident[0] == 0x7f && strncmp(elf->e_ident + 1, "ELF", 3) != 0) {
115 cons_write("not an ELF file\n");
118 if (elf->e_type != ET_EXEC) {
119 cons_write("not an ELF executable\n");
122 if (!elf_check_arch(elf)) {
123 cons_write("kernel not for this processor\n");
127 e_entry = elf->e_entry;
128 e_phnum = elf->e_phnum;
129 e_phoff = elf->e_phoff;
131 cons_write("loading ");
135 for (i = 0; i < e_phnum; ++i) {
136 req.len = sizeof(*elf_phdr);
137 req.addr = (long) mem;
138 ssc(fd, 1, (long) &req, e_phoff, SSC_READ);
139 ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
140 if (stat.count != sizeof(*elf_phdr)) {
141 cons_write("failed to read phdr\n");
144 e_phoff += sizeof(*elf_phdr);
146 elf_phdr = (struct elf_phdr *) mem;
148 if (elf_phdr->p_type != PT_LOAD)
151 req.len = elf_phdr->p_filesz;
152 req.addr = __pa(elf_phdr->p_paddr);
153 ssc(fd, 1, (long) &req, elf_phdr->p_offset, SSC_READ);
154 ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
155 memset((char *)__pa(elf_phdr->p_paddr) + elf_phdr->p_filesz, 0,
156 elf_phdr->p_memsz - elf_phdr->p_filesz);
158 ssc(fd, 0, 0, 0, SSC_CLOSE);
160 cons_write("starting kernel...\n");
162 /* fake an I/O base address: */
163 ia64_setreg(_IA64_REG_AR_KR0, 0xffffc000000UL);
165 bp = sys_fw_init(args, arglen);
167 ssc(0, (long) kpath, 0, 0, SSC_LOAD_SYMBOLS);
170 jmp_to_kernel((unsigned long) bp, e_entry);
172 cons_write("kernel returned!\n");
173 ssc(-1, 0, 0, 0, SSC_EXIT);