2 * From $NetBSD: bootxx.c,v 1.4 1997/09/06 14:08:29 drochner Exp $
4 * $DragonFly: src/sys/boot/alpha/boot1/Attic/boot1.c,v 1.4 2003/11/10 06:08:25 dillon Exp $
8 * Copyright (c) 1995 Carnegie-Mellon University.
11 * Author: Chris G. Demetriou
13 * Permission to use, copy, modify and distribute this software and
14 * its documentation is hereby granted, provided that both the copyright
15 * notice and this permission notice appear in all copies of the
16 * software, derivative works or modified versions, and any portions
17 * thereof, and that both notices appear in supporting documentation.
19 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
20 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
21 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
23 * Carnegie Mellon requests users of this software to return to
25 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
26 * School of Computer Science
27 * Carnegie Mellon University
28 * Pittsburgh PA 15213-3890
30 * any improvements or extensions that they make and grant Carnegie the
31 * rights to redistribute these changes.
35 #include <sys/param.h>
36 #include <sys/dirent.h>
38 #include <machine/prom.h>
39 #include <machine/rpb.h>
43 void puts(const char *s);
44 void puthex(u_long v);
45 static int dskread(void *, u_int64_t, size_t);
50 #define memcpy(dst, src, len) \
58 char *heap = (char*) end;
61 bcopy(const void *src, void *dst, size_t len)
66 for (d = dst, s = src; len; len--)
81 return prom_getchar();
98 panic(const char *message, ...)
116 ret.bits = prom_getenv(PROM_E_BOOTED_DEV, devname, sizeof devname);
118 ret.bits = prom_open(devname, ret.u.retval + 1);
120 panic("devopen: open failed\n");
122 prom_fd = ret.u.retval;
124 /* XXX read disklabel and setup partition offset */
135 char hex[] = "0123456789abcdef";
143 for (digit = 0; v >= (0x10L << digit); digit += 4)
146 for (; digit >= 0; digit -= 4)
147 putchar(hex[(v >> digit) & 0xf]);
153 dskread(void *buf, u_int64_t block, size_t size)
165 prom_read(prom_fd, size * DEV_BSIZE, buf, block);
179 getfilename(char *filename, const char *defname)
186 while ((c = getchar()) != '\r') {
187 if (c == '\b' || c == 0177) {
200 strcpy(filename, defname);
204 static struct dmadat __dmadat;
207 loadfile(char *name, char *addr)
219 if (devopen() || (ino = lookup(name)) == 0) {
220 puts("Can't open file ");
228 n = fsread(ino, p, VBLKSIZE);
230 puts("Can't read file ");
237 } while (n == VBLKSIZE);
242 static inline u_long rpcc()
245 __asm__ __volatile__ ("rpcc %0" : "=r"(v));
246 return v & 0xffffffff;
252 char *loadaddr = (char*) SECONDARY_LOAD_ADDRESS;
253 char *name = "/boot/loader";
263 freq = ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq;
264 while (((rpcc() - start) & 0xffffffff) < freq) {
267 getfilename(filename, name);
273 loadfile(name, loadaddr);
275 entry = (void (*)())loadaddr;