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