xref: /netbsd/sys/arch/news68k/stand/bootxx/bootxx.c (revision bf9ec67e)
1 /*	$NetBSD: bootxx.c,v 1.4 2002/05/20 14:05:22 lukem Exp $	*/
2 
3 /*-
4  * Copyright (C) 1999 Izumi Tsutsui.  All rights reserved.
5  * Copyright (C) 1999 Tsubai Masanari.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <lib/libkern/libkern.h>
31 #include <lib/libsa/stand.h>
32 #include <machine/romcall.h>
33 
34 #include <sys/bootblock.h>
35 
36 struct shared_bbinfo bbinfo = {
37 	{ NEWS68K_BBINFO_MAGIC },	/* bbi_magic[] */
38 	0,				/* bbi_block_size */
39 	SHARED_BBINFO_MAXBLOCKS,	/* bbi_block_count */
40 	{ 0 },				/* bbi_block_table[] */
41 };
42 
43 #ifndef DEFAULT_ENTRY_POINT
44 #define DEFAULT_ENTRY_POINT	0x003e0000
45 #endif
46 void (*entry_point)(u_int32_t, u_int32_t, u_int32_t, u_int32_t) =
47     (void *)DEFAULT_ENTRY_POINT;
48 
49 #ifdef BOOTXX_DEBUG
50 # define DPRINTF(x) printf x
51 #else
52 # define DPRINTF(x)
53 #endif
54 
55 char *devs[] = { "hd", "fh", "fd", NULL, NULL, "rd", "st" };
56 
57 void
58 bootxx(d4, d5, d6, d7)
59 	int d4, d5, d6, d7;
60 {
61 	int fd, blk, bs;
62 	int ctlr, unit, part, type;
63 	int i;
64 	int bootdev = d6;
65 	char *addr;
66 	char devname[32];
67 
68 	printf("NetBSD/news68k Primary Boot\n");
69 
70 	DPRINTF(("\n"));
71 	DPRINTF(("d4 %x\n", d4));
72 	DPRINTF(("d5 %x (%s)\n", d5, (char *)d5));
73 	DPRINTF(("d6 %x\n", d6));
74 	DPRINTF(("d7 %x\n", d7));
75 
76 	DPRINTF(("block_size  = %d\n", bbinfo.bbi_block_size));
77 	DPRINTF(("block_count = %d\n", bbinfo.bbi_block_count));
78 	DPRINTF(("entry_point = %p\n", entry_point));
79 
80 	/* sd(ctlr, lun, part, bus?, host) */
81 
82 	ctlr = BOOTDEV_CTLR(bootdev);
83 	unit = BOOTDEV_UNIT(bootdev);
84 	part = BOOTDEV_PART(bootdev);
85 	type = BOOTDEV_TYPE(bootdev);
86 
87 	if (devs[type] == NULL) {
88 		printf("unknown bootdev (0x%x)\n", bootdev);
89 		return;
90 	}
91 
92 	sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
93 
94 	fd = rom_open(devname, 0);
95 	if (fd == -1) {
96 		printf("cannot open %s\n", devname);
97 		return;
98 	}
99 
100 	addr = (char *)entry_point;
101 	bs = bbinfo.bbi_block_size;
102 	DPRINTF(("reading block:"));
103 	for (i = 0; i < bbinfo.bbi_block_count; i++) {
104 		blk = bbinfo.bbi_block_table[i];
105 
106 		DPRINTF((" %d", blk));
107 
108 		rom_lseek(fd, blk * 512, 0);
109 		rom_read(fd, addr, bs);
110 		addr += bs;
111 	}
112 	DPRINTF((" done\n"));
113 	rom_close(fd);
114 
115 	(*entry_point)(d4, d5, d6, d7);
116 	DPRINTF(("bootxx returned?\n"));
117 }
118