Home | History | Annotate | Line # | Download | only in boot
autoconf.c revision 1.11
      1 /*	$NetBSD: autoconf.c,v 1.11 2000/05/20 13:35:07 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/trap.h"
     43 #include "../include/frame.h"
     44 #include "../include/rpb.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 /*
     58  * Autoconf routine is really stupid; but it actually don't
     59  * need any intelligence. We just assume that all possible
     60  * devices exists on each cpu. Fast & easy.
     61  */
     62 
     63 void
     64 autoconf()
     65 {
     66 
     67 	findcpu(); /* Configures CPU variables */
     68 	consinit(); /* Allow us to print out things */
     69 	scbinit(); /* Fix interval clock etc */
     70 
     71 	switch (vax_boardtype) {
     72 
     73 	case VAX_BTYP_46:
     74 	case VAX_BTYP_48:
     75 		{int *map, i;
     76 
     77 		/* Map all 16MB of I/O space to low 16MB of memory */
     78 		map = (int *)0x700000; /* XXX */
     79 		*(int *)0x20080008 = (int)map; /* XXX */
     80 		for (i = 0; i < 0x8000; i++)
     81 			map[i] = 0x80000000 | i;
     82 		}break;
     83 
     84 		break;
     85 	}
     86 }
     87 
     88 /*
     89  * Clock handling routines, needed to do timing in standalone programs.
     90  */
     91 
     92 volatile int tickcnt;
     93 
     94 int
     95 getsecs()
     96 {
     97 	return tickcnt/100;
     98 }
     99 
    100 struct ivec_dsp **scb;
    101 struct ivec_dsp *scb_vec;
    102 extern struct ivec_dsp idsptch;
    103 
    104 /*
    105  * Init the SCB and set up a handler for all vectors in the lower space,
    106  * to detect unwanted interrupts.
    107  */
    108 void
    109 scbinit()
    110 {
    111 	int i;
    112 
    113 	/*
    114 	 * Allocate space. We need one page for the SCB, and 128*16 == 2k
    115 	 * for the vectors. The SCB must be on a page boundary.
    116 	 */
    117 	i = (int)alloc(VAX_NBPG * 6) + VAX_PGOFSET;
    118 	i &= ~VAX_PGOFSET;
    119 
    120 	mtpr(i, PR_SCBB);
    121 	scb = (void *)i;
    122 	scb_vec = (struct ivec_dsp *)(i + VAX_NBPG);
    123 
    124 	for (i = 0; i < 128; i++) {
    125 		scb[i] = &scb_vec[i];
    126 		(int)scb[i] |= 1;	/* Only interrupt stack */
    127 		scb_vec[i] = idsptch;
    128 		scb_vec[i].hoppaddr = scb_stray;
    129 	}
    130 	scb_vec[0xc0/4].hoppaddr = rtimer;
    131 
    132 	mtpr(-10000, PR_NICR);		/* Load in count register */
    133 	mtpr(0x800000d1, PR_ICCS);	/* Start clock and enable interrupt */
    134 
    135 	mtpr(20, PR_IPL);
    136 }
    137 
    138 extern int jbuf[10];
    139 extern int sluttid, senast, skip;
    140 
    141 void
    142 rtimer(void *arg)
    143 {
    144 	mtpr(31, PR_IPL);
    145 	tickcnt++;
    146 	mtpr(0xc1, PR_ICCS);
    147 	if (skip)
    148 		return;
    149 	if ((vax_boardtype == VAX_BTYP_46) ||
    150 	    (vax_boardtype == VAX_BTYP_48) ||
    151 	    (vax_boardtype == VAX_BTYP_49)) {
    152 		int nu = sluttid - getsecs();
    153 		if (senast != nu) {
    154 			mtpr(20, PR_IPL);
    155 			longjmp(jbuf);
    156 		}
    157 	}
    158 }
    159 
    160 asm("
    161 	.globl  _idsptch, _eidsptch
    162 _idsptch:
    163 	pushr   $0x3f
    164 	pushl   $1
    165 	.long   0x9f01fb01
    166 	.long   0x12345678
    167 #
    168 #	gas do not accept this :-/ use hexcode instead
    169 #	nop
    170 #	calls   $1, *$0x12345678
    171 	popr    $0x3f
    172 	rei
    173 _eidsptch:
    174 ");
    175 
    176 /*
    177  * Stray interrupt handler.
    178  * This function must _not_ save any registers (in the reg save mask).
    179  */
    180 void
    181 scb_stray(void *arg)
    182 {
    183 	static struct callsframe *cf;
    184 	static int vector, ipl, *a;
    185 
    186 	cf = FRAMEOFFSET(arg);
    187 	a = &cf->ca_arg1;
    188 	ipl = mfpr(PR_IPL);
    189 	vector = ((cf->ca_pc - (u_int)scb_vec)/4) & ~3;
    190 	printf("stray interrupt: pc %x vector 0x%x, ipl %d\n",
    191 	    cf->ca_pc, vector, ipl);
    192 }
    193 
    194