14 #include <linux/elf.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);
41 cons_write (
const char *
buf)
45 while ((ch = *buf++) !=
'\0') {
57 static char mem[4096];
65 unsigned long e_entry, e_phoff, e_phnum;
87 while (*args !=
' ' && *args !=
'\0')
90 *args++ =
'\0', --arglen;
102 cons_write(
": file not found, reboot now\n");
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");
119 cons_write(
"not an ELF executable\n");
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;
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);
155 memset((
char *)
__pa(elf_phdr->p_paddr) + elf_phdr->p_filesz, 0,
156 elf_phdr->p_memsz - elf_phdr->p_filesz);
160 cons_write(
"starting kernel...\n");
172 cons_write(
"kernel returned!\n");