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