1 /* $NetBSD: boot.c,v 1.10 2009/05/08 09:33:58 skrll Exp $ */
4 * Copyright (c) 1982, 1986, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)boot.c 8.1 (Berkeley) 6/10/93
35 * Copyright (c) 1998-2004 Michael Shalayeff
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
51 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
52 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
53 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
55 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
56 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
57 * THE POSSIBILITY OF SUCH DAMAGE.
61 #include <sys/param.h>
62 #include <sys/reboot.h>
63 #include <sys/boot_flag.h>
65 #include <arch/hp700/stand/common/libsa.h>
66 #include <lib/libsa/loadfile.h>
68 #include <machine/pdc.h>
69 #include <machine/vmparam.h>
71 #include <arch/hp700/stand/common/dev_hppa.h>
76 * Boot program... bits in `howto' determine whether boot stops to
77 * ask for system name. Boot device is derived from ROM provided
84 char devname_buffer
[16];
91 * XXX UFS accepts a /, NFS doesn't.
95 "netbsd", "netbsd.gz",
96 "netbsd.bak", "netbsd.bak.gz",
97 "netbsd.old", "netbsd.old.gz",
98 "onetbsd", "onetbsd.gz",
101 #define NUMNAMES (sizeof(names) / sizeof(char *))
103 void boot(dev_t boot_dev
);
105 void getbootdev(int *);
106 void exec_hp700(char *, u_long
, int);
111 typedef void (*startfuncp
)(int, int, int, int, int, void *)
112 __attribute__ ((noreturn
));
123 devboot(boot_dev
, devname_buffer
);
131 char *filename
, filename_buffer
[MAXLEN
];
134 printf(">> %s, Revision %s\n", bootprog_name
, bootprog_rev
);
135 printf(">> (%s, %s)\n", bootprog_maker
, bootprog_date
);
136 printf(">> Enter \"reset\" to reset system.\n");
141 /* reset bootinfo structure */
144 name
= names
[currname
++];
145 if (currname
== NUMNAMES
)
152 printf(": %s\n", name
);
153 if (strchr(name
, ':') != 0) {
156 strcpy(filename_buffer
, devname_buffer
);
157 strcat(filename_buffer
, ":");
158 strcat(filename_buffer
, name
);
159 filename
= filename_buffer
;
162 size
= sizeof(struct btinfo_common
) + strlen(name
) + 1;
163 /* Impose limit (somewhat arbitrary) */
164 if (size
< BOOTINFO_MAXSIZE
/ 2) {
166 struct btinfo_kernelfile bi_file
;
169 strcpy(U
.bi_file
.name
, name
);
170 BI_ADD(&U
.bi_file
, BTINFO_KERNELFILE
, size
);
173 exec_hp700(filename
, 0, howto
);
174 printf("boot: %s\n", strerror(errno
));
179 getbootdev(int *boot_howto
)
182 int bdev
, badapt
, bctlr
, bunit
, bpart
;
184 bdev
= B_TYPE(bootdev
);
185 badapt
= B_ADAPTOR(bootdev
);
186 bctlr
= B_CONTROLLER(bootdev
);
187 bunit
= B_UNIT(bootdev
);
188 bpart
= B_PARTITION(bootdev
);
190 printf("Boot: [[[%s%d%c:]%s][-a][-c][-d][-s][-v][-q]] :- ",
191 devsw
[bdev
].dv_name
, badapt
<< 8 | bctlr
<< 4 | bunit
,
195 if (strcmp(line
, "reset") == 0) {
197 printf("panic: can't reboot\n");
200 while ((c
= *ptr
) != '\0') {
206 while ((c
= *++ptr
) && c
!= ' ')
207 BOOT_FLAG(c
, *boot_howto
);
210 while ((c
= *++ptr
) && c
!= ' ');
219 #define round_to_size(x) \
220 (((x) + sizeof(u_long) - 1) & ~(sizeof(u_long) - 1))
223 exec_hp700(char *file
, u_long loadaddr
, int boot_howto
)
229 struct btinfo_symtab bi_syms
;
230 u_long marks
[MARK_MAX
];
233 marks
[MARK_START
] = loadaddr
;
235 printf("file=%s loadaddr=%x howto=%x\n",
236 file
, loadaddr
, boot_howto
);
238 if ((fd
= loadfile(file
, marks
, LOAD_KERNEL
)) == -1)
241 marks
[MARK_END
] = round_to_size(marks
[MARK_END
] - loadaddr
);
242 printf("Start @ 0x%lx [%ld=0x%lx-0x%lx]...\n",
243 marks
[MARK_ENTRY
], marks
[MARK_NSYM
],
244 marks
[MARK_SYM
], marks
[MARK_END
]);
248 printf("ep=0x%x [", marks
[MARK_ENTRY
]);
249 for (i
= 0; i
< 10240; i
++) {
251 printf("\b\n%p:", &((u_int
*)marks
[MARK_ENTRY
])[i
]);
252 if (getchar() != ' ')
255 printf("%x,", ((int *)marks
[MARK_ENTRY
])[i
]);
261 bi_syms
.nsym
= marks
[MARK_NSYM
];
262 bi_syms
.ssym
= marks
[MARK_SYM
];
263 bi_syms
.esym
= marks
[MARK_END
];
264 BI_ADD(&bi_syms
, BTINFO_SYMTAB
, sizeof(bi_syms
));
268 __asm("mtctl %r0, %cr17");
269 __asm("mtctl %r0, %cr17");
271 /* stack and the gung is ok at this point, so, no need for asm setup */
272 (*(startfuncp
)(marks
[MARK_ENTRY
])) ((int)pdc
, boot_howto
, bootdev
,
273 marks
[MARK_END
], BOOTARG_APIVER
, &bootinfo
);