1 /* $NetBSD: autoconf.c,v 1.17 2002/05/24 21:40:59 ragge 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 if (vax_boardtype != VAX_BTYP_VXT) 168 mtpr(-10000, PR_NICR); /* Load in count register */ 169 mtpr(0x800000d1, PR_ICCS); /* Start clock and enable interrupt */ 170 171 mtpr(20, PR_IPL); 172 } 173 174 extern int jbuf[10]; 175 extern int sluttid, senast, skip; 176 177 void 178 rtimer(void *arg) 179 { 180 mtpr(IPL_HIGH, PR_IPL); 181 tickcnt++; 182 mtpr(0xc1, PR_ICCS); 183 if (skip) 184 return; 185 if ((vax_boardtype == VAX_BTYP_46) || 186 (vax_boardtype == VAX_BTYP_48) || 187 (vax_boardtype == VAX_BTYP_49)) { 188 int nu = sluttid - getsecs(); 189 if (senast != nu) { 190 mtpr(20, PR_IPL); 191 longjmp(jbuf); 192 } 193 } 194 } 195 196 #ifdef __ELF__ 197 #define IDSPTCH "idsptch" 198 #define EIDSPTCH "eidsptch" 199 #define CMN_IDSPTCH "cmn_idsptch" 200 #else 201 #define IDSPTCH "_idsptch" 202 #define EIDSPTCH "_eidsptch" 203 #define CMN_IDSPTCH "_cmn_idsptch" 204 #endif 205 206 asm(" 207 .text 208 .align 2 209 .globl " IDSPTCH ", " EIDSPTCH " 210 " IDSPTCH ": 211 pushr $0x3f 212 .word 0x9f16 213 .long " CMN_IDSPTCH " 214 .long 0 215 .long 0 216 .long 0 217 " EIDSPTCH ": 218 219 " CMN_IDSPTCH ": 220 movl (%sp)+,%r0 221 pushl 4(%r0) 222 calls $1,*(%r0) 223 popr $0x3f 224 rei 225 "); 226 227 /* 228 * Stray interrupt handler. 229 * This function must _not_ save any registers (in the reg save mask). 230 */ 231 void 232 scb_stray(void *arg) 233 { 234 static int vector, ipl; 235 236 ipl = mfpr(PR_IPL); 237 vector = (int) arg; 238 printf("stray interrupt: vector 0x%x, ipl %d\n", vector, ipl); 239 } 240