bootxx.c revision 1.6 1 1.6 ragge /* $NetBSD: bootxx.c,v 1.6 2000/05/20 13:21:29 ragge Exp $ */
2 1.1 ragge /*-
3 1.1 ragge * Copyright (c) 1982, 1986 The Regents of the University of California.
4 1.1 ragge * All rights reserved.
5 1.1 ragge *
6 1.1 ragge * Redistribution and use in source and binary forms, with or without
7 1.1 ragge * modification, are permitted provided that the following conditions
8 1.1 ragge * are met:
9 1.1 ragge * 1. Redistributions of source code must retain the above copyright
10 1.1 ragge * notice, this list of conditions and the following disclaimer.
11 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 ragge * notice, this list of conditions and the following disclaimer in the
13 1.1 ragge * documentation and/or other materials provided with the distribution.
14 1.1 ragge * 3. All advertising materials mentioning features or use of this software
15 1.1 ragge * must display the following acknowledgement:
16 1.1 ragge * This product includes software developed by the University of
17 1.1 ragge * California, Berkeley and its contributors.
18 1.1 ragge * 4. Neither the name of the University nor the names of its contributors
19 1.1 ragge * may be used to endorse or promote products derived from this software
20 1.1 ragge * without specific prior written permission.
21 1.1 ragge *
22 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 ragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 ragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 ragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 ragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 ragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 ragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 ragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 ragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 ragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 ragge * SUCH DAMAGE.
33 1.1 ragge *
34 1.1 ragge * @(#)boot.c 7.15 (Berkeley) 5/4/91
35 1.1 ragge */
36 1.1 ragge
37 1.1 ragge #include "sys/param.h"
38 1.1 ragge #include "sys/reboot.h"
39 1.1 ragge #include "sys/disklabel.h"
40 1.1 ragge
41 1.1 ragge #include "lib/libsa/stand.h"
42 1.1 ragge #include "lib/libsa/ufs.h"
43 1.6 ragge #include "lib/libsa/cd9660.h"
44 1.6 ragge
45 1.6 ragge #include "lib/libkern/libkern.h"
46 1.1 ragge
47 1.1 ragge #include "../include/pte.h"
48 1.1 ragge #include "../include/sid.h"
49 1.1 ragge #include "../include/mtpr.h"
50 1.1 ragge #include "../include/reg.h"
51 1.1 ragge #include "../include/rpb.h"
52 1.1 ragge
53 1.1 ragge #include "../mba/mbareg.h"
54 1.1 ragge #include "../mba/hpreg.h"
55 1.1 ragge
56 1.1 ragge #define NRSP 1 /* Kludge */
57 1.1 ragge #define NCMD 1 /* Kludge */
58 1.1 ragge
59 1.2 ragge #include "dev/mscp/mscp.h"
60 1.2 ragge #include "dev/mscp/mscpreg.h"
61 1.1 ragge
62 1.6 ragge #include "../boot/data.h"
63 1.1 ragge
64 1.6 ragge void Xmain(void);
65 1.6 ragge void hoppabort(int);
66 1.6 ragge void romread_uvax(int lbn, int size, void *buf, struct rpb *rpb);
67 1.6 ragge int hpread(int block, int size, char *buf);
68 1.6 ragge int read750(int block, int *regs);
69 1.6 ragge int unit_init(int, struct rpb *, int);
70 1.1 ragge
71 1.2 ragge struct open_file file;
72 1.2 ragge
73 1.1 ragge unsigned *bootregs;
74 1.1 ragge struct rpb *rpb;
75 1.6 ragge struct bqo *bqo;
76 1.1 ragge int vax_cputype;
77 1.6 ragge struct udadevice {u_short udaip;u_short udasa;};
78 1.6 ragge volatile struct udadevice *csr;
79 1.6 ragge
80 1.6 ragge extern int from;
81 1.6 ragge #define FROM750 1
82 1.6 ragge #define FROMMV 2
83 1.6 ragge #define FROMVMB 4
84 1.1 ragge
85 1.1 ragge /*
86 1.1 ragge * The boot block are used by 11/750, 8200, MicroVAX II/III, VS2000,
87 1.1 ragge * VS3100/??, VS4000 and VAX6000/???, and only when booting from disk.
88 1.1 ragge */
89 1.6 ragge void
90 1.1 ragge Xmain()
91 1.1 ragge {
92 1.1 ragge int io;
93 1.1 ragge char *hej = "/boot";
94 1.1 ragge
95 1.1 ragge vax_cputype = (mfpr(PR_SID) >> 24) & 0xFF;
96 1.1 ragge
97 1.2 ragge /*
98 1.2 ragge */
99 1.6 ragge rpb = (void *)0xf0000; /* Safe address right now */
100 1.6 ragge bqo = (void *)0xf1000;
101 1.6 ragge if (from == FROMMV) {
102 1.1 ragge /*
103 1.1 ragge * now relocate rpb/bqo (which are used by ROM-routines)
104 1.1 ragge */
105 1.6 ragge bcopy ((void *)bootregs[11], rpb, sizeof(struct rpb));
106 1.1 ragge bcopy ((void*)rpb->iovec, bqo, rpb->iovecsz);
107 1.4 ragge if (rpb->devtyp == BDEV_SDN)
108 1.4 ragge rpb->devtyp = BDEV_SD; /* XXX until driver fixed */
109 1.6 ragge } else {
110 1.6 ragge bzero(rpb, sizeof(struct rpb));
111 1.6 ragge rpb->devtyp = bootregs[0];
112 1.6 ragge rpb->unit = bootregs[3];
113 1.6 ragge rpb->rpb_bootr5 = bootregs[5];
114 1.6 ragge rpb->csrphy = bootregs[2];
115 1.6 ragge rpb->adpphy = bootregs[1]; /* BI node on 8200 */
116 1.1 ragge }
117 1.6 ragge rpb->rpb_base = rpb;
118 1.6 ragge rpb->iovec = (int)bqo;
119 1.1 ragge
120 1.1 ragge io = open(hej, 0);
121 1.1 ragge
122 1.2 ragge read(io, (void *)0x10000, 0x10000);
123 1.2 ragge bcopy((void *) 0x10000, 0, 0xffff);
124 1.6 ragge hoppabort(32);
125 1.2 ragge asm("halt");
126 1.1 ragge }
127 1.1 ragge
128 1.2 ragge /*
129 1.2 ragge * Write an extremely limited version of a (us)tar filesystem, suitable
130 1.2 ragge * for loading secondary-stage boot loader.
131 1.2 ragge * - Can only load file "boot".
132 1.2 ragge * - Must be the first file on tape.
133 1.2 ragge */
134 1.6 ragge struct fs_ops file_system[] = {
135 1.6 ragge { ufs_open, 0, ufs_read, 0, 0, ufs_stat },
136 1.6 ragge { cd9660_open, 0, cd9660_read, 0, 0, cd9660_stat },
137 1.6 ragge #if 0
138 1.6 ragge { ustarfs_open, 0, ustarfs_read, 0, 0, ustarfs_stat },
139 1.6 ragge #endif
140 1.6 ragge };
141 1.6 ragge
142 1.6 ragge int nfsys = (sizeof(file_system) / sizeof(struct fs_ops));
143 1.6 ragge
144 1.6 ragge #if 0
145 1.2 ragge int tar_open(char *path, struct open_file *f);
146 1.2 ragge ssize_t tar_read(struct open_file *f, void *buf, size_t size, size_t *resid);
147 1.1 ragge
148 1.2 ragge int
149 1.2 ragge tar_open(path, f)
150 1.2 ragge char *path;
151 1.2 ragge struct open_file *f;
152 1.2 ragge {
153 1.2 ragge char *buf = alloc(512);
154 1.2 ragge
155 1.2 ragge bzero(buf, 512);
156 1.2 ragge romstrategy(0, 0, 8192, 512, buf, 0);
157 1.2 ragge if (bcmp(buf, "boot", 5) || bcmp(&buf[257], "ustar", 5))
158 1.2 ragge return EINVAL; /* Not a ustarfs with "boot" first */
159 1.2 ragge return 0;
160 1.2 ragge }
161 1.2 ragge
162 1.2 ragge ssize_t
163 1.2 ragge tar_read(f, buf, size, resid)
164 1.2 ragge struct open_file *f;
165 1.2 ragge void *buf;
166 1.2 ragge size_t size;
167 1.2 ragge size_t *resid;
168 1.2 ragge {
169 1.2 ragge romstrategy(0, 0, (8192+512), size, buf, 0);
170 1.2 ragge *resid = size;
171 1.6 ragge return 0; /* XXX */
172 1.2 ragge }
173 1.6 ragge #endif
174 1.1 ragge
175 1.1 ragge volatile struct uda {
176 1.1 ragge struct mscp_1ca uda_ca; /* communications area */
177 1.1 ragge struct mscp uda_rsp; /* response packets */
178 1.1 ragge struct mscp uda_cmd; /* command packets */
179 1.1 ragge } uda;
180 1.1 ragge
181 1.6 ragge int
182 1.1 ragge devopen(f, fname, file)
183 1.1 ragge struct open_file *f;
184 1.1 ragge const char *fname;
185 1.1 ragge char **file;
186 1.1 ragge {
187 1.1 ragge *file = (char *)fname;
188 1.1 ragge
189 1.6 ragge if (from == FROM750)
190 1.6 ragge return 0;
191 1.1 ragge /*
192 1.6 ragge * Reinit the VMB boot device.
193 1.1 ragge */
194 1.6 ragge if (bqo->unit_init) {
195 1.6 ragge int initfn;
196 1.6 ragge
197 1.6 ragge initfn = rpb->iovec + bqo->unit_init;
198 1.6 ragge if (rpb->devtyp == BDEV_UDA || rpb->devtyp == BDEV_TK) {
199 1.1 ragge csr = (struct udadevice *)rpb->csrphy;
200 1.6 ragge csr->udaip = 0;
201 1.6 ragge while ((csr->udasa & MP_STEP1) == 0)
202 1.6 ragge ;
203 1.1 ragge }
204 1.6 ragge unit_init(initfn, rpb, bootregs[12]);
205 1.1 ragge }
206 1.1 ragge return 0;
207 1.1 ragge }
208 1.1 ragge
209 1.1 ragge int curblock = 0;
210 1.1 ragge
211 1.6 ragge int
212 1.1 ragge romstrategy(sc, func, dblk, size, buf, rsize)
213 1.1 ragge void *sc;
214 1.1 ragge int func;
215 1.1 ragge daddr_t dblk;
216 1.1 ragge size_t size;
217 1.1 ragge void *buf;
218 1.1 ragge size_t *rsize;
219 1.1 ragge {
220 1.1 ragge int block = dblk;
221 1.1 ragge int nsize = size;
222 1.1 ragge
223 1.6 ragge if (from == FROMMV) {
224 1.6 ragge romread_uvax(block, size, buf, rpb);
225 1.6 ragge } else /* if (from == FROM750) */ {
226 1.6 ragge if (rpb->devtyp == BDEV_HP) {
227 1.6 ragge hpread(block, size, buf);
228 1.6 ragge } else
229 1.1 ragge while (size > 0) {
230 1.1 ragge while ((read750(block, bootregs) & 0x01) == 0){
231 1.1 ragge }
232 1.1 ragge bcopy(0, buf, 512);
233 1.1 ragge size -= 512;
234 1.6 ragge (char *)buf += 512;
235 1.1 ragge block++;
236 1.1 ragge }
237 1.1 ragge }
238 1.1 ragge
239 1.2 ragge if (rsize)
240 1.2 ragge *rsize = nsize;
241 1.1 ragge return 0;
242 1.1 ragge }
243 1.1 ragge
244 1.6 ragge int
245 1.6 ragge hpread(int block, int size, char *buf)
246 1.1 ragge {
247 1.1 ragge volatile struct mba_regs *mr = (void *) bootregs[1];
248 1.1 ragge volatile struct hp_drv *hd = (void*)&mr->mba_md[bootregs[3]];
249 1.6 ragge u_int pfnum, nsize, mapnr, bn, cn, sn, tn;
250 1.6 ragge struct disklabel *dp;
251 1.6 ragge extern char start;
252 1.1 ragge
253 1.6 ragge dp = (struct disklabel *)(LABELOFFSET + &start);
254 1.1 ragge pfnum = (u_int) buf >> PGSHIFT;
255 1.1 ragge
256 1.1 ragge for (mapnr = 0, nsize = size; (nsize + NBPG) > 0; nsize -= NBPG)
257 1.1 ragge *(int *)&mr->mba_map[mapnr++] = PG_V | pfnum++;
258 1.1 ragge mr->mba_var = ((u_int) buf & PGOFSET);
259 1.1 ragge mr->mba_bc = (~size) + 1;
260 1.1 ragge bn = block;
261 1.1 ragge cn = bn / dp->d_secpercyl;
262 1.1 ragge sn = bn % dp->d_secpercyl;
263 1.1 ragge tn = sn / dp->d_nsectors;
264 1.1 ragge sn = sn % dp->d_nsectors;
265 1.1 ragge hd->hp_dc = cn;
266 1.1 ragge hd->hp_da = (tn << 8) | sn;
267 1.1 ragge hd->hp_cs1 = HPCS_READ;
268 1.1 ragge while (mr->mba_sr & MBASR_DTBUSY);
269 1.1 ragge if (mr->mba_sr & MBACR_ABORT){
270 1.1 ragge return 1;
271 1.1 ragge }
272 1.1 ragge return 0;
273 1.1 ragge }
274 1.1 ragge
275 1.2 ragge extern char end[];
276 1.2 ragge static char *top = (char*)end;
277 1.1 ragge
278 1.2 ragge void *
279 1.2 ragge alloc(size)
280 1.2 ragge unsigned size;
281 1.2 ragge {
282 1.2 ragge void *ut = top;
283 1.2 ragge top += size;
284 1.2 ragge return ut;
285 1.1 ragge }
286 1.1 ragge
287 1.1 ragge void
288 1.2 ragge free(ptr, size)
289 1.2 ragge void *ptr;
290 1.2 ragge unsigned size;
291 1.1 ragge {
292 1.1 ragge }
293 1.1 ragge
294 1.2 ragge int
295 1.2 ragge romclose(f)
296 1.2 ragge struct open_file *f;
297 1.1 ragge {
298 1.2 ragge return 0;
299 1.1 ragge }
300