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