autoconf.c revision 1.29 1 1.29 ragge /* $NetBSD: autoconf.c,v 1.29 2017/05/22 16:59:32 ragge Exp $ */
2 1.1 ragge /*
3 1.1 ragge * Copyright (c) 1994, 1998 Ludd, University of Lule}, Sweden.
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 *
15 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 ragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 ragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1 ragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 ragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 ragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 ragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 ragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 ragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 ragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 ragge */
26 1.1 ragge
27 1.1 ragge /* All bugs are subject to removal without further notice */
28 1.1 ragge
29 1.1 ragge
30 1.1 ragge
31 1.11 ragge #include <sys/param.h>
32 1.11 ragge
33 1.11 ragge #include <lib/libsa/stand.h>
34 1.27 tsutsui #include <lib/libsa/net.h>
35 1.11 ragge
36 1.1 ragge #include "../include/mtpr.h"
37 1.1 ragge #include "../include/sid.h"
38 1.12 matt #include "../include/intr.h"
39 1.11 ragge #include "../include/rpb.h"
40 1.12 matt #include "../include/scb.h"
41 1.11 ragge
42 1.1 ragge #include "vaxstand.h"
43 1.1 ragge
44 1.11 ragge void autoconf(void);
45 1.11 ragge void findcpu(void);
46 1.11 ragge void consinit(void);
47 1.11 ragge void scbinit(void);
48 1.11 ragge void scb_stray(void *);
49 1.18 ragge void longjmp(int *, int);
50 1.11 ragge void rtimer(void *);
51 1.1 ragge
52 1.13 ragge long *bootregs;
53 1.13 ragge
54 1.1 ragge /*
55 1.13 ragge * Do some initial setup. Also create a fake RPB for net-booted machines
56 1.13 ragge * that don't have an in-prom VMB.
57 1.1 ragge */
58 1.1 ragge
59 1.11 ragge void
60 1.28 cegger autoconf(void)
61 1.1 ragge {
62 1.13 ragge int copyrpb = 1;
63 1.13 ragge int fromnet = (bootregs[12] != -1);
64 1.1 ragge
65 1.3 ragge findcpu(); /* Configures CPU variables */
66 1.3 ragge consinit(); /* Allow us to print out things */
67 1.3 ragge scbinit(); /* Fix interval clock etc */
68 1.3 ragge
69 1.14 ragge #ifdef DEV_DEBUG
70 1.14 ragge printf("Register contents:\n");
71 1.14 ragge for (copyrpb = 0; copyrpb < 13; copyrpb++)
72 1.14 ragge printf("r%d: %lx\n", copyrpb, bootregs[copyrpb]);
73 1.14 ragge #endif
74 1.3 ragge switch (vax_boardtype) {
75 1.1 ragge
76 1.19 ragge case VAX_BTYP_780:
77 1.19 ragge case VAX_BTYP_790:
78 1.13 ragge case VAX_BTYP_8000:
79 1.13 ragge case VAX_BTYP_9CC:
80 1.13 ragge case VAX_BTYP_9RR:
81 1.13 ragge case VAX_BTYP_1202:
82 1.13 ragge if (fromnet == 0)
83 1.13 ragge break;
84 1.13 ragge copyrpb = 0;
85 1.13 ragge bootrpb.devtyp = bootregs[0];
86 1.13 ragge bootrpb.adpphy = bootregs[1];
87 1.13 ragge bootrpb.csrphy = bootregs[2];
88 1.13 ragge bootrpb.unit = bootregs[3];
89 1.13 ragge bootrpb.rpb_bootr5 = bootregs[5];
90 1.13 ragge bootrpb.pfncnt = 0;
91 1.13 ragge break;
92 1.13 ragge
93 1.3 ragge case VAX_BTYP_46:
94 1.3 ragge case VAX_BTYP_48:
95 1.3 ragge {int *map, i;
96 1.3 ragge
97 1.3 ragge /* Map all 16MB of I/O space to low 16MB of memory */
98 1.3 ragge map = (int *)0x700000; /* XXX */
99 1.3 ragge *(int *)0x20080008 = (int)map; /* XXX */
100 1.3 ragge for (i = 0; i < 0x8000; i++)
101 1.3 ragge map[i] = 0x80000000 | i;
102 1.3 ragge }break;
103 1.3 ragge
104 1.5 ragge break;
105 1.13 ragge }
106 1.13 ragge
107 1.13 ragge if (copyrpb) {
108 1.13 ragge struct rpb *prpb = (struct rpb *)bootregs[11];
109 1.26 he memcpy(&bootrpb, (void *)prpb, sizeof(struct rpb));
110 1.13 ragge if (prpb->iovec) {
111 1.13 ragge bootrpb.iovec = (int)alloc(prpb->iovecsz);
112 1.26 he memcpy((void *)bootrpb.iovec, (void *)prpb->iovec,
113 1.13 ragge prpb->iovecsz);
114 1.13 ragge }
115 1.1 ragge }
116 1.1 ragge }
117 1.1 ragge
118 1.1 ragge /*
119 1.1 ragge * Clock handling routines, needed to do timing in standalone programs.
120 1.1 ragge */
121 1.3 ragge
122 1.3 ragge volatile int tickcnt;
123 1.1 ragge
124 1.27 tsutsui satime_t
125 1.28 cegger getsecs(void)
126 1.1 ragge {
127 1.3 ragge return tickcnt/100;
128 1.3 ragge }
129 1.3 ragge
130 1.5 ragge struct ivec_dsp **scb;
131 1.5 ragge struct ivec_dsp *scb_vec;
132 1.6 matt extern struct ivec_dsp idsptch;
133 1.18 ragge extern int jbuf[10];
134 1.18 ragge
135 1.18 ragge static void
136 1.18 ragge mcheck(void *arg)
137 1.18 ragge {
138 1.21 matt int off, *mfp = (int *)(void *)&arg;
139 1.18 ragge
140 1.18 ragge off = (mfp[7]/4 + 8);
141 1.18 ragge printf("Machine check, pc=%x, psl=%x\n", mfp[off], mfp[off+1]);
142 1.18 ragge longjmp(jbuf, 1);
143 1.18 ragge }
144 1.3 ragge
145 1.5 ragge /*
146 1.5 ragge * Init the SCB and set up a handler for all vectors in the lower space,
147 1.5 ragge * to detect unwanted interrupts.
148 1.5 ragge */
149 1.11 ragge void
150 1.28 cegger scbinit(void)
151 1.3 ragge {
152 1.24 he int i, addr;
153 1.3 ragge
154 1.5 ragge /*
155 1.12 matt * Allocate space. We need one page for the SCB, and 128*20 == 2.5k
156 1.5 ragge * for the vectors. The SCB must be on a page boundary.
157 1.5 ragge */
158 1.12 matt i = (int)alloc(VAX_NBPG + 128*sizeof(scb_vec[0])) + VAX_PGOFSET;
159 1.3 ragge i &= ~VAX_PGOFSET;
160 1.3 ragge
161 1.3 ragge mtpr(i, PR_SCBB);
162 1.5 ragge scb = (void *)i;
163 1.5 ragge scb_vec = (struct ivec_dsp *)(i + VAX_NBPG);
164 1.3 ragge
165 1.5 ragge for (i = 0; i < 128; i++) {
166 1.5 ragge scb[i] = &scb_vec[i];
167 1.24 he addr = (int)scb[i];
168 1.24 he addr |= SCB_ISTACK; /* Only interrupt stack */
169 1.24 he scb[i] = (struct ivec_dsp*)addr;
170 1.6 matt scb_vec[i] = idsptch;
171 1.5 ragge scb_vec[i].hoppaddr = scb_stray;
172 1.12 matt scb_vec[i].pushlarg = (void *) (i * 4);
173 1.12 matt scb_vec[i].ev = NULL;
174 1.5 ragge }
175 1.5 ragge scb_vec[0xc0/4].hoppaddr = rtimer;
176 1.18 ragge scb_vec[4/4].hoppaddr = mcheck;
177 1.3 ragge
178 1.17 ragge if (vax_boardtype != VAX_BTYP_VXT)
179 1.17 ragge mtpr(-10000, PR_NICR); /* Load in count register */
180 1.3 ragge mtpr(0x800000d1, PR_ICCS); /* Start clock and enable interrupt */
181 1.3 ragge
182 1.5 ragge mtpr(20, PR_IPL);
183 1.5 ragge }
184 1.5 ragge
185 1.7 ragge extern int sluttid, senast, skip;
186 1.7 ragge
187 1.5 ragge void
188 1.11 ragge rtimer(void *arg)
189 1.5 ragge {
190 1.12 matt mtpr(IPL_HIGH, PR_IPL);
191 1.5 ragge tickcnt++;
192 1.5 ragge mtpr(0xc1, PR_ICCS);
193 1.7 ragge if (skip)
194 1.7 ragge return;
195 1.9 ragge if ((vax_boardtype == VAX_BTYP_46) ||
196 1.9 ragge (vax_boardtype == VAX_BTYP_48) ||
197 1.9 ragge (vax_boardtype == VAX_BTYP_49)) {
198 1.7 ragge int nu = sluttid - getsecs();
199 1.7 ragge if (senast != nu) {
200 1.7 ragge mtpr(20, PR_IPL);
201 1.18 ragge longjmp(jbuf, 1);
202 1.7 ragge }
203 1.7 ragge }
204 1.3 ragge }
205 1.1 ragge
206 1.15 matt #ifdef __ELF__
207 1.15 matt #define IDSPTCH "idsptch"
208 1.15 matt #define EIDSPTCH "eidsptch"
209 1.15 matt #define CMN_IDSPTCH "cmn_idsptch"
210 1.15 matt #else
211 1.15 matt #define IDSPTCH "_idsptch"
212 1.15 matt #define EIDSPTCH "_eidsptch"
213 1.15 matt #define CMN_IDSPTCH "_cmn_idsptch"
214 1.15 matt #endif
215 1.15 matt
216 1.23 perry __asm(
217 1.20 matt " .text;"
218 1.20 matt " .align 2;"
219 1.20 matt " .globl " IDSPTCH ", " EIDSPTCH ";"
220 1.20 matt IDSPTCH ":;"
221 1.20 matt " pushr $0x3f;"
222 1.20 matt " .word 0x9f16;"
223 1.20 matt " .long " CMN_IDSPTCH ";"
224 1.20 matt " .long 0;"
225 1.20 matt " .long 0;"
226 1.20 matt " .long 0;"
227 1.20 matt EIDSPTCH ":;"
228 1.20 matt
229 1.20 matt CMN_IDSPTCH ":;"
230 1.20 matt " movl (%sp)+,%r0;"
231 1.20 matt " pushl 4(%r0);"
232 1.20 matt " calls $1,*(%r0);"
233 1.20 matt " popr $0x3f;"
234 1.20 matt " rei;"
235 1.20 matt );
236 1.5 ragge
237 1.5 ragge /*
238 1.5 ragge * Stray interrupt handler.
239 1.5 ragge * This function must _not_ save any registers (in the reg save mask).
240 1.5 ragge */
241 1.5 ragge void
242 1.11 ragge scb_stray(void *arg)
243 1.5 ragge {
244 1.12 matt static int vector, ipl;
245 1.5 ragge
246 1.5 ragge ipl = mfpr(PR_IPL);
247 1.12 matt vector = (int) arg;
248 1.12 matt printf("stray interrupt: vector 0x%x, ipl %d\n", vector, ipl);
249 1.5 ragge }
250