xref: /netbsd-src/sys/arch/news68k/stand/bootxx/bootxx.c (revision 9fbd88883c38d0c0fbfcbe66d76fe6b0fab3f9de)
1 /*	$NetBSD: bootxx.c,v 1.1 1999/12/09 14:53:23 tsutsui 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 #define MAXBLOCKNUM 64
35 
36 void (*entry_point)() = (void *)0x3e0000;
37 int block_size = 8192;
38 int block_count = MAXBLOCKNUM;
39 int block_table[MAXBLOCKNUM] = { 0 };
40 
41 #ifdef BOOTXX_DEBUG
42 # define DPRINTF printf
43 #else
44 # define DPRINTF while (0) printf
45 #endif
46 
47 char *devs[] = { "hd", "fh", "fd", NULL, NULL, "rd", "st" };
48 
49 void
50 bootxx(d4, d5, d6, d7)
51 	int d4, d5, d6, d7;
52 {
53 	int fd, blk, bs;
54 	int ctlr, unit, part, type;
55 	int i;
56 	int bootdev = d6;
57 	char *addr;
58 	char devname[32];
59 
60 	printf("NetBSD/news68k Primary Boot\n");
61 
62 	DPRINTF("\n");
63 	DPRINTF("d4 %x\n", d4);
64 	DPRINTF("d5 %x (%s)\n", d5, (char *)d5);
65 	DPRINTF("d6 %x\n", d6);
66 	DPRINTF("d7 %x\n", d7);
67 
68 	DPRINTF("block_size  = %d\n", block_size);
69 	DPRINTF("block_count = %d\n", block_count);
70 	DPRINTF("entry_point = %x\n", (int)entry_point);
71 
72 	/* sd(ctlr, lun, part, bus?, host) */
73 
74 	ctlr = BOOTDEV_CTLR(bootdev);
75 	unit = BOOTDEV_UNIT(bootdev);
76 	part = BOOTDEV_PART(bootdev);
77 	type = BOOTDEV_TYPE(bootdev);
78 
79 	if (devs[type] == NULL) {
80 		printf("unknown bootdev (0x%x)\n", bootdev);
81 		return;
82 	}
83 
84 	sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
85 
86 	fd = rom_open(devname, 0);
87 	if (fd == -1) {
88 		printf("cannot open %s\n", devname);
89 		return;
90 	}
91 
92 	addr = (char *)entry_point;
93 	bs = block_size;
94 	DPRINTF("reading block:");
95 	for (i = 0; i < block_count; i++) {
96 		blk = block_table[i];
97 
98 		DPRINTF(" %d", blk);
99 
100 		rom_lseek(fd, blk * 512, 0);
101 		rom_read(fd, addr, bs);
102 		addr += bs;
103 	}
104 	DPRINTF(" done\n");
105 	rom_close(fd);
106 
107 	(*entry_point)(d4, d5, d6, d7);
108 	DPRINTF("bootxx returned?\n");
109 }
110