Home | History | Annotate | Line # | Download | only in boot
autoconf.c revision 1.18
      1 /*	$NetBSD: autoconf.c,v 1.18 2002/05/31 15:58:26 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 *, 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 extern int jbuf[10];
    137 
    138 static void
    139 mcheck(void *arg)
    140 {
    141 	int off, *mfp = (int *)&arg;
    142 
    143 	off = (mfp[7]/4 + 8);
    144 	printf("Machine check, pc=%x, psl=%x\n", mfp[off], mfp[off+1]);
    145 	longjmp(jbuf, 1);
    146 }
    147 
    148 /*
    149  * Init the SCB and set up a handler for all vectors in the lower space,
    150  * to detect unwanted interrupts.
    151  */
    152 void
    153 scbinit()
    154 {
    155 	int i;
    156 
    157 	/*
    158 	 * Allocate space. We need one page for the SCB, and 128*20 == 2.5k
    159 	 * for the vectors. The SCB must be on a page boundary.
    160 	 */
    161 	i = (int)alloc(VAX_NBPG + 128*sizeof(scb_vec[0])) + VAX_PGOFSET;
    162 	i &= ~VAX_PGOFSET;
    163 
    164 	mtpr(i, PR_SCBB);
    165 	scb = (void *)i;
    166 	scb_vec = (struct ivec_dsp *)(i + VAX_NBPG);
    167 
    168 	for (i = 0; i < 128; i++) {
    169 		scb[i] = &scb_vec[i];
    170 		(int)scb[i] |= SCB_ISTACK;	/* Only interrupt stack */
    171 		scb_vec[i] = idsptch;
    172 		scb_vec[i].hoppaddr = scb_stray;
    173 		scb_vec[i].pushlarg = (void *) (i * 4);
    174 		scb_vec[i].ev = NULL;
    175 	}
    176 	scb_vec[0xc0/4].hoppaddr = rtimer;
    177 	scb_vec[4/4].hoppaddr = mcheck;
    178 
    179 	if (vax_boardtype != VAX_BTYP_VXT)
    180 		mtpr(-10000, PR_NICR);		/* Load in count register */
    181 	mtpr(0x800000d1, PR_ICCS);	/* Start clock and enable interrupt */
    182 
    183 	mtpr(20, PR_IPL);
    184 }
    185 
    186 extern int sluttid, senast, skip;
    187 
    188 void
    189 rtimer(void *arg)
    190 {
    191 	mtpr(IPL_HIGH, PR_IPL);
    192 	tickcnt++;
    193 	mtpr(0xc1, PR_ICCS);
    194 	if (skip)
    195 		return;
    196 	if ((vax_boardtype == VAX_BTYP_46) ||
    197 	    (vax_boardtype == VAX_BTYP_48) ||
    198 	    (vax_boardtype == VAX_BTYP_49)) {
    199 		int nu = sluttid - getsecs();
    200 		if (senast != nu) {
    201 			mtpr(20, PR_IPL);
    202 			longjmp(jbuf, 1);
    203 		}
    204 	}
    205 }
    206 
    207 #ifdef __ELF__
    208 #define	IDSPTCH "idsptch"
    209 #define	EIDSPTCH "eidsptch"
    210 #define	CMN_IDSPTCH "cmn_idsptch"
    211 #else
    212 #define	IDSPTCH "_idsptch"
    213 #define	EIDSPTCH "_eidsptch"
    214 #define	CMN_IDSPTCH "_cmn_idsptch"
    215 #endif
    216 
    217 asm("
    218 	.text
    219 	.align	2
    220 	.globl  " IDSPTCH ", " EIDSPTCH "
    221 " IDSPTCH ":
    222 	pushr   $0x3f
    223 	.word	0x9f16
    224 	.long   " CMN_IDSPTCH "
    225 	.long	0
    226 	.long	0
    227 	.long	0
    228 " EIDSPTCH ":
    229 
    230 " CMN_IDSPTCH ":
    231 	movl	(%sp)+,%r0
    232 	pushl	4(%r0)
    233 	calls	$1,*(%r0)
    234 	popr	$0x3f
    235 	rei
    236 ");
    237 
    238 /*
    239  * Stray interrupt handler.
    240  * This function must _not_ save any registers (in the reg save mask).
    241  */
    242 void
    243 scb_stray(void *arg)
    244 {
    245 	static int vector, ipl;
    246 
    247 	ipl = mfpr(PR_IPL);
    248 	vector = (int) arg;
    249 	printf("stray interrupt: vector 0x%x, ipl %d\n", vector, ipl);
    250 }
    251