Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / sparc / stand / bootxx / bootxx.c
blob75b8ac6e5b69ffaaf29351aa41f22a00fe4b0395
1 /* $NetBSD: bootxx.c,v 1.24 2009/08/23 08:51:56 he Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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>
33 #include <sys/exec.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>
43 int debug;
44 int netif_debug;
47 * Boot device is derived from ROM provided information.
49 const char progname[] = "bootxx";
50 struct open_file io;
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,
62 { 0 }
65 int main(void);
66 void loadboot(struct open_file *, char *);
68 int
69 main(void)
71 char *dummy1;
72 const char *dummy;
73 void (*entry)(void *) = (void (*)(void *))PROM_LOADADDR;
74 void *arg;
76 #ifdef HEAP_VARIABLE
78 extern char end[];
79 setheap((void *)ALIGN(end), (void *)0xffffffff);
81 #endif
82 prom_init();
83 dummy = prom_getbootpath();
84 if (dummy && *dummy != '\0')
85 strcpy(prom_bootdevice, dummy);
86 io.f_flags = F_RAW;
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;
96 (*entry)(arg);
97 _rtt();
100 void
101 loadboot(struct open_file *f, char *addr)
103 int i;
104 char *buf;
105 size_t n;
106 daddr_t blk;
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);
114 if (buf == NULL)
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);
121 #ifdef DEBUG
122 printf("%s: block # %d = %d\n", progname, i, blk);
123 #endif
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);
127 _rtt();
129 memcpy(addr, buf, bbinfo.bbi_block_size);
130 if (n != bbinfo.bbi_block_size)
131 panic("%s: short read", progname);
132 if (i == 0) {
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);
140 addr += n;