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