Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / sun68k / stand / bootxx / bootxx.c
blobf73831e897d5136bb74adab764f62be2a55dca0b
1 /* $NetBSD: bootxx.c,v 1.11 2008/04/28 20:23:38 martin 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.
33 * This is a generic "first-stage" boot program.
35 * Note that this program has absolutely no filesystem knowledge!
37 * Instead, this uses a table of disk block numbers that are
38 * filled in by the installboot program such that this program
39 * can load the "second-stage" boot program.
42 #include <sys/param.h>
43 #include <sys/bootblock.h>
44 #include <machine/mon.h>
46 #include <stand.h>
47 #include "libsa.h"
49 int copyboot(struct open_file *, char *);
52 * This is the address where we load the second-stage boot loader.
54 #define LOADADDR 0x4000
57 * The contents of the sun68k_bbinfo below are set by installboot(8)
58 * to hold the filesystem data of the second-stage boot program
59 * (typically `/ufsboot'): filesystem block size, # of filesystem
60 * blocks and the block numbers themselves.
62 struct shared_bbinfo bbinfo = {
63 { SUN68K_BBINFO_MAGIC },
65 SHARED_BBINFO_MAXBLOCKS,
66 { 0 }
69 int
70 main(void)
72 struct open_file f;
73 void *entry;
74 char *addr;
75 int error;
77 #ifdef DEBUG
78 printf("bootxx: open...\n");
79 #endif
80 f.f_flags = F_RAW;
81 if (devopen(&f, 0, &addr)) {
82 putstr("bootxx: devopen failed\n");
83 return 1;
86 addr = (char*)LOADADDR;
87 error = copyboot(&f, addr);
88 f.f_dev->dv_close(&f);
89 if (!error) {
90 #ifdef DEBUG
91 printf("bootxx: start 0x%x\n", (long)addr);
92 #endif
93 entry = addr;
94 chain_to(entry);
96 /* copyboot had a problem... */
97 return 0;
100 int
101 copyboot(struct open_file *fp, char *addr)
103 size_t n;
104 int i, blknum;
105 char *buf;
107 /* Need to use a buffer that can be mapped into DVMA space. */
108 buf = alloc(bbinfo.bbi_block_size);
109 if (!buf)
110 panic("bootxx: alloc failed");
112 for (i = 0; i < bbinfo.bbi_block_count; i++) {
114 if ((blknum = bbinfo.bbi_block_table[i]) == 0)
115 break;
117 #ifdef DEBUG
118 printf("bootxx: block # %d = %d\n", i, blknum);
119 #endif
120 if ((fp->f_dev->dv_strategy)(fp->f_devdata, F_READ, blknum,
121 bbinfo.bbi_block_size, buf, &n))
123 putstr("bootxx: read failed\n");
124 return -1;
126 if (n != bbinfo.bbi_block_size) {
127 putstr("bootxx: short read\n");
128 return -1;
130 memcpy(addr, buf, bbinfo.bbi_block_size);
131 addr += bbinfo.bbi_block_size;
134 return 0;