1 /* $NetBSD: bootxx.c,v 1.24 2009/08/23 08:51:56 he Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/param.h>
34 #include <sys/exec_aout.h>
35 #include <sys/bootblock.h>
37 #include <lib/libkern/libkern.h>
38 #include <lib/libsa/stand.h>
40 #include <machine/promlib.h>
41 #include <sparc/stand/common/promdev.h>
47 * Boot device is derived from ROM provided information.
49 const char progname
[] = "bootxx";
53 * The contents of the bbinfo below are set by installboot(8)
54 * to hold the filesystem data of the second-stage boot program
55 * (typically `/boot'): filesystem block size, # of filesystem
56 * blocks and the block numbers themselves.
58 struct shared_bbinfo bbinfo
= {
59 { SPARC_BBINFO_MAGIC
},
61 SHARED_BBINFO_MAXBLOCKS
,
66 void loadboot(struct open_file
*, char *);
73 void (*entry
)(void *) = (void (*)(void *))PROM_LOADADDR
;
79 setheap((void *)ALIGN(end
), (void *)0xffffffff);
83 dummy
= prom_getbootpath();
84 if (dummy
&& *dummy
!= '\0')
85 strcpy(prom_bootdevice
, dummy
);
87 if (devopen(&io
, 0, &dummy1
)) {
88 panic("%s: can't open device `%s'", progname
,
89 prom_bootdevice
!= NULL
? prom_bootdevice
: "unknown");
92 (void)loadboot(&io
, (void *)PROM_LOADADDR
);
93 (io
.f_dev
->dv_close
)(&io
);
95 arg
= (prom_version() == PROM_OLDMON
) ? (void *)PROM_LOADADDR
: romp
;
101 loadboot(struct open_file
*f
, char *addr
)
109 * Allocate a buffer that we can map into DVMA space; only
110 * needed for sun4 architecture, but use it for all machines
111 * to keep code size down as much as possible.
113 buf
= alloc(bbinfo
.bbi_block_size
);
115 panic("%s: alloc failed", progname
);
117 for (i
= 0; i
< bbinfo
.bbi_block_count
; i
++) {
118 if ((blk
= bbinfo
.bbi_block_table
[i
]) == 0)
119 panic("%s: block table corrupt", progname
);
122 printf("%s: block # %d = %d\n", progname
, i
, blk
);
124 if ((f
->f_dev
->dv_strategy
)(f
->f_devdata
, F_READ
, blk
,
125 bbinfo
.bbi_block_size
, buf
, &n
)) {
126 printf("%s: read failure", progname
);
129 memcpy(addr
, buf
, bbinfo
.bbi_block_size
);
130 if (n
!= bbinfo
.bbi_block_size
)
131 panic("%s: short read", progname
);
133 int m
= N_GETMAGIC(*(struct exec
*)addr
);
134 if (m
== ZMAGIC
|| m
== NMAGIC
|| m
== OMAGIC
) {
135 /* Move exec header out of the way */
136 memcpy(addr
- sizeof(struct exec
), addr
, n
);
137 addr
-= sizeof(struct exec
);