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>
23 #include <asm/system.h>
37 extern void jmp_to_kernel (unsigned long bp
, unsigned long e_entry
);
38 extern struct ia64_boot_param
*sys_fw_init (const char *args
, int arglen
);
39 extern void debug_break (void);
42 cons_write (const char *buf
)
46 while ((ch
= *buf
++) != '\0') {
47 ssc(ch
, 0, 0, 0, SSC_PUTCHAR
);
49 ssc('\r', 0, 0, 0, SSC_PUTCHAR
);
56 start_bootloader (void)
58 static char mem
[4096];
59 static char buffer
[1024];
63 struct disk_stat stat
;
65 struct elf_phdr
*elf_phdr
; /* program header */
66 unsigned long e_entry
, e_phoff
, e_phnum
;
67 register struct ia64_boot_param
*bp
;
71 ssc(0, 0, 0, 0, SSC_CONSOLE_INIT
);
74 * S.Eranian: extract the commandline argument from the simulator
76 * The expected format is as follows:
80 * Both are optional but you can't have the second one without the first.
82 arglen
= ssc((long) buffer
, 0, 0, 0, SSC_GET_ARGS
);
88 while (*args
!= ' ' && *args
!= '\0')
91 *args
++ = '\0', --arglen
;
99 fd
= ssc((long) kpath
, 1, 0, 0, SSC_OPEN
);
103 cons_write(": file not found, reboot now\n");
109 req
.len
= sizeof(mem
);
110 req
.addr
= (long) mem
;
111 ssc(fd
, 1, (long) &req
, off
, SSC_READ
);
112 ssc((long) &stat
, 0, 0, 0, SSC_WAIT_COMPLETION
);
114 elf
= (struct elfhdr
*) mem
;
115 if (elf
->e_ident
[0] == 0x7f && strncmp(elf
->e_ident
+ 1, "ELF", 3) != 0) {
116 cons_write("not an ELF file\n");
119 if (elf
->e_type
!= ET_EXEC
) {
120 cons_write("not an ELF executable\n");
123 if (!elf_check_arch(elf
)) {
124 cons_write("kernel not for this processor\n");
128 e_entry
= elf
->e_entry
;
129 e_phnum
= elf
->e_phnum
;
130 e_phoff
= elf
->e_phoff
;
132 cons_write("loading ");
136 for (i
= 0; i
< e_phnum
; ++i
) {
137 req
.len
= sizeof(*elf_phdr
);
138 req
.addr
= (long) mem
;
139 ssc(fd
, 1, (long) &req
, e_phoff
, SSC_READ
);
140 ssc((long) &stat
, 0, 0, 0, SSC_WAIT_COMPLETION
);
141 if (stat
.count
!= sizeof(*elf_phdr
)) {
142 cons_write("failed to read phdr\n");
145 e_phoff
+= sizeof(*elf_phdr
);
147 elf_phdr
= (struct elf_phdr
*) mem
;
149 if (elf_phdr
->p_type
!= PT_LOAD
)
152 req
.len
= elf_phdr
->p_filesz
;
153 req
.addr
= __pa(elf_phdr
->p_paddr
);
154 ssc(fd
, 1, (long) &req
, elf_phdr
->p_offset
, SSC_READ
);
155 ssc((long) &stat
, 0, 0, 0, SSC_WAIT_COMPLETION
);
156 memset((char *)__pa(elf_phdr
->p_paddr
) + elf_phdr
->p_filesz
, 0,
157 elf_phdr
->p_memsz
- elf_phdr
->p_filesz
);
159 ssc(fd
, 0, 0, 0, SSC_CLOSE
);
161 cons_write("starting kernel...\n");
163 /* fake an I/O base address: */
164 ia64_setreg(_IA64_REG_AR_KR0
, 0xffffc000000UL
);
166 bp
= sys_fw_init(args
, arglen
);
168 ssc(0, (long) kpath
, 0, 0, SSC_LOAD_SYMBOLS
);
171 jmp_to_kernel((unsigned long) bp
, e_entry
);
173 cons_write("kernel returned!\n");
174 ssc(-1, 0, 0, 0, SSC_EXIT
);