boot.c revision 1.1 1 /* $NetBSD: boot.c,v 1.1 1999/07/08 11:48:05 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 <lib/libsa/loadfile.h>
32
33 #include <machine/romcall.h>
34
35 void flushicache __P((void *, int));
36 extern char _edata[], _end[];
37
38 char *devs[] = { "sd", "fh", "fd", NULL, NULL, "rd", "st" };
39 char *kernels[] = { "/netbsd", "/netbsd.gz", NULL };
40
41 #ifdef BOOT_DEBUG
42 # define DPRINTF printf
43 #else
44 # define DPRINTF while (0) printf
45 #endif
46
47 void
48 boot(a0, a1, a2, a3, a4, a5)
49 int a0, a1, a2, a3, a4, a5;
50 {
51 int fd, i;
52 int ctlr, unit, part, type;
53 int bootdev = a1;
54 char *netbsd = (char *)a2;
55 u_long marks[MARK_MAX];
56 char devname[32], file[32];
57 void (*entry)();
58
59 /* Clear BSS. */
60 bzero(_edata, _end - _edata);
61
62 printf("\n");
63 printf("NetBSD/newsmips Secondary Boot\n");
64
65 /* bootname is "/boot" by default. */
66 if (netbsd == NULL || strcmp(netbsd, "/boot") == 0)
67 netbsd = "";
68
69 DPRINTF("howto = 0x%x\n", a0);
70 DPRINTF("bootdev = 0x%x\n", bootdev);
71 DPRINTF("bootname = %s\n", netbsd);
72 DPRINTF("maxmem = 0x%x\n", a3);
73
74 ctlr = BOOTDEV_CTLR(bootdev);
75 unit = BOOTDEV_UNIT(bootdev);
76 part = BOOTDEV_PART(bootdev);
77 type = BOOTDEV_TYPE(bootdev);
78
79 marks[MARK_START] = 0;
80
81 if (devs[type] == NULL) {
82 printf("unknown bootdev (0x%x)\n", bootdev);
83 return;
84 }
85
86 sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
87 printf("Booting %s%s\n", devname, netbsd);
88
89 /* use user specified kernel name if exists */
90 if (*netbsd) {
91 kernels[0] = netbsd;
92 kernels[1] = NULL;
93 }
94
95 for (i = 0; kernels[i]; i++) {
96 sprintf(file, "%s%s", devname, kernels[i]);
97 DPRINTF("trying %s...\n", file);
98 fd = loadfile(file, marks, LOAD_ALL);
99 if (fd != -1)
100 break;
101 }
102 if (fd == -1)
103 return;
104
105 DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]);
106 DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]);
107 DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]);
108
109 entry = (void *)marks[MARK_ENTRY];
110 flushicache(entry, marks[MARK_SYM] - marks[MARK_ENTRY]);
111
112 printf("\n");
113 (*entry)(a0, a1, a2, a3, a4, a5);
114 }
115
116 void
117 putchar(x)
118 int x;
119 {
120 char c = x;
121
122 rom_write(1, &c, 1);
123 }
124