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