Home | History | Annotate | Line # | Download | only in arm32
stubs.c revision 1.1
      1  1.1  chris /*	$NetBSD: stubs.c,v 1.1 2001/07/28 13:28:04 chris Exp $	*/
      2  1.1  chris 
      3  1.1  chris /*
      4  1.1  chris  * Copyright (c) 1994-1998 Mark Brinicombe.
      5  1.1  chris  * Copyright (c) 1994 Brini.
      6  1.1  chris  * All rights reserved.
      7  1.1  chris  *
      8  1.1  chris  * This code is derived from software written for Brini by Mark Brinicombe
      9  1.1  chris  *
     10  1.1  chris  * Redistribution and use in source and binary forms, with or without
     11  1.1  chris  * modification, are permitted provided that the following conditions
     12  1.1  chris  * are met:
     13  1.1  chris  * 1. Redistributions of source code must retain the above copyright
     14  1.1  chris  *    notice, this list of conditions and the following disclaimer.
     15  1.1  chris  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  chris  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  chris  *    documentation and/or other materials provided with the distribution.
     18  1.1  chris  * 3. All advertising materials mentioning features or use of this software
     19  1.1  chris  *    must display the following acknowledgement:
     20  1.1  chris  *	This product includes software developed by Mark Brinicombe
     21  1.1  chris  *	for the NetBSD Project.
     22  1.1  chris  * 4. The name of the company nor the name of the author may be used to
     23  1.1  chris  *    endorse or promote products derived from this software without specific
     24  1.1  chris  *    prior written permission.
     25  1.1  chris  *
     26  1.1  chris  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     27  1.1  chris  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     28  1.1  chris  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     29  1.1  chris  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     30  1.1  chris  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     31  1.1  chris  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     32  1.1  chris  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1  chris  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1  chris  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1  chris  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1  chris  * SUCH DAMAGE.
     37  1.1  chris  *
     38  1.1  chris  * Routines that are temporary or do not have a home yet.
     39  1.1  chris  *
     40  1.1  chris  * Created      : 17/09/94
     41  1.1  chris  */
     42  1.1  chris 
     43  1.1  chris #include <sys/param.h>
     44  1.1  chris #include <sys/systm.h>
     45  1.1  chris #include <sys/errno.h>
     46  1.1  chris #include <sys/proc.h>
     47  1.1  chris #include <sys/conf.h>
     48  1.1  chris #include <sys/msgbuf.h>
     49  1.1  chris #include <uvm/uvm_extern.h>
     50  1.1  chris #include <machine/cpu.h>
     51  1.1  chris #include <machine/irqhandler.h>
     52  1.1  chris #include <machine/bootconfig.h>
     53  1.1  chris #include <machine/pcb.h>
     54  1.1  chris 
     55  1.1  chris extern dev_t dumpdev;
     56  1.1  chris extern BootConfig bootconfig;
     57  1.1  chris 
     58  1.1  chris /* These queue functions are candiates for arm32/machdep.c */
     59  1.1  chris struct queue {
     60  1.1  chris 	struct queue *q_next, *q_prev;
     61  1.1  chris };
     62  1.1  chris 
     63  1.1  chris /*
     64  1.1  chris  * insert an element into a queue
     65  1.1  chris  */
     66  1.1  chris 
     67  1.1  chris void
     68  1.1  chris _insque(v1, v2)
     69  1.1  chris 	void *v1;
     70  1.1  chris 	void *v2;
     71  1.1  chris {
     72  1.1  chris 	struct queue *elem = v1, *head = v2;
     73  1.1  chris 	struct queue *next;
     74  1.1  chris 
     75  1.1  chris 	next = head->q_next;
     76  1.1  chris 	elem->q_next = next;
     77  1.1  chris 	head->q_next = elem;
     78  1.1  chris 	elem->q_prev = head;
     79  1.1  chris 	next->q_prev = elem;
     80  1.1  chris }
     81  1.1  chris 
     82  1.1  chris /*
     83  1.1  chris  * remove an element from a queue
     84  1.1  chris  */
     85  1.1  chris 
     86  1.1  chris void
     87  1.1  chris _remque(v)
     88  1.1  chris 	void *v;
     89  1.1  chris {
     90  1.1  chris 	struct queue *elem = v;
     91  1.1  chris 	struct queue *next, *prev;
     92  1.1  chris 
     93  1.1  chris 	next = elem->q_next;
     94  1.1  chris 	prev = elem->q_prev;
     95  1.1  chris 	next->q_prev = prev;
     96  1.1  chris 	prev->q_next = next;
     97  1.1  chris 	elem->q_prev = 0;
     98  1.1  chris }
     99  1.1  chris 
    100  1.1  chris 
    101  1.1  chris /*
    102  1.1  chris  * These variables are needed by /sbin/savecore
    103  1.1  chris  */
    104  1.1  chris u_long	dumpmag = 0x8fca0101;	/* magic number */
    105  1.1  chris int 	dumpsize = 0;		/* pages */
    106  1.1  chris long	dumplo = 0; 		/* blocks */
    107  1.1  chris 
    108  1.1  chris struct pcb dumppcb;
    109  1.1  chris 
    110  1.1  chris /*
    111  1.1  chris  * This is called by main to set dumplo and dumpsize.
    112  1.1  chris  * Dumps always skip the first CLBYTES of disk space
    113  1.1  chris  * in case there might be a disk label stored there.
    114  1.1  chris  * If there is extra space, put dump at the end to
    115  1.1  chris  * reduce the chance that swapping trashes it.
    116  1.1  chris  */
    117  1.1  chris 
    118  1.1  chris void
    119  1.1  chris cpu_dumpconf()
    120  1.1  chris {
    121  1.1  chris 	int nblks;	/* size of dump area */
    122  1.1  chris 	int maj;
    123  1.1  chris 
    124  1.1  chris 	if (dumpdev == NODEV)
    125  1.1  chris 		return;
    126  1.1  chris 	maj = major(dumpdev);
    127  1.1  chris 	if (maj < 0 || maj >= nblkdev)
    128  1.1  chris 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
    129  1.1  chris 	if (bdevsw[maj].d_psize == NULL)
    130  1.1  chris 		return;
    131  1.1  chris 	nblks = (*bdevsw[maj].d_psize)(dumpdev);
    132  1.1  chris 	if (nblks <= ctod(1))
    133  1.1  chris 		return;
    134  1.1  chris 
    135  1.1  chris 	dumpsize = physmem;
    136  1.1  chris 
    137  1.1  chris 	/* Always skip the first CLBYTES, in case there is a label there. */
    138  1.1  chris 	if (dumplo < ctod(1))
    139  1.1  chris 		dumplo = ctod(1);
    140  1.1  chris 
    141  1.1  chris 	/* Put dump at end of partition, and make it fit. */
    142  1.1  chris 	if (dumpsize > dtoc(nblks - dumplo))
    143  1.1  chris 		dumpsize = dtoc(nblks - dumplo);
    144  1.1  chris 	if (dumplo < nblks - ctod(dumpsize))
    145  1.1  chris 		dumplo = nblks - ctod(dumpsize);
    146  1.1  chris }
    147  1.1  chris 
    148  1.1  chris /* This should be moved to machdep.c */
    149  1.1  chris 
    150  1.1  chris extern pagehook_t page_hook0;
    151  1.1  chris 
    152  1.1  chris /*
    153  1.1  chris  * Doadump comes here after turning off memory management and
    154  1.1  chris  * getting on the dump stack, either when called above, or by
    155  1.1  chris  * the auto-restart code.
    156  1.1  chris  */
    157  1.1  chris 
    158  1.1  chris void
    159  1.1  chris dumpsys()
    160  1.1  chris {
    161  1.1  chris 	daddr_t blkno;
    162  1.1  chris 	int psize;
    163  1.1  chris 	int error;
    164  1.1  chris 	int addr;
    165  1.1  chris 	int block;
    166  1.1  chris 	int len;
    167  1.1  chris 	vaddr_t dumpspace;
    168  1.1  chris 
    169  1.1  chris 	/* Save registers. */
    170  1.1  chris 	savectx(&dumppcb);
    171  1.1  chris 
    172  1.1  chris 	if (dumpdev == NODEV)
    173  1.1  chris 		return;
    174  1.1  chris 	if (dumpsize == 0) {
    175  1.1  chris 		cpu_dumpconf();
    176  1.1  chris 		if (dumpsize == 0)
    177  1.1  chris 			return;
    178  1.1  chris 	}
    179  1.1  chris 	if (dumplo <= 0) {
    180  1.1  chris 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
    181  1.1  chris 		    minor(dumpdev));
    182  1.1  chris 		return;
    183  1.1  chris 	}
    184  1.1  chris 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
    185  1.1  chris 	    minor(dumpdev), dumplo);
    186  1.1  chris 
    187  1.1  chris 	blkno = dumplo;
    188  1.1  chris 	dumpspace = page_hook0.va;
    189  1.1  chris 
    190  1.1  chris 	psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
    191  1.1  chris 	printf("dump ");
    192  1.1  chris 	if (psize == -1) {
    193  1.1  chris 		printf("area unavailable\n");
    194  1.1  chris 		return;
    195  1.1  chris 	}
    196  1.1  chris 
    197  1.1  chris 	error = 0;
    198  1.1  chris 	len = 0;
    199  1.1  chris 
    200  1.1  chris 	for (block = 0; block < bootconfig.dramblocks && error == 0; ++block) {
    201  1.1  chris 		addr = bootconfig.dram[block].address;
    202  1.1  chris 		for (;addr < (bootconfig.dram[block].address
    203  1.1  chris 		    + (bootconfig.dram[block].pages * NBPG)); addr += NBPG) {
    204  1.1  chris 		    	if ((len % (1024*1024)) == 0)
    205  1.1  chris 		    		printf("%d ", len / (1024*1024));
    206  1.1  chris 	                pmap_map(dumpspace, addr, addr + NBPG, VM_PROT_READ);
    207  1.1  chris 			error = (*bdevsw[major(dumpdev)].d_dump)(dumpdev,
    208  1.1  chris 			    blkno, (caddr_t) dumpspace, NBPG);
    209  1.1  chris 			if (error) break;
    210  1.1  chris 			blkno += btodb(NBPG);
    211  1.1  chris 			len += NBPG;
    212  1.1  chris 		}
    213  1.1  chris 	}
    214  1.1  chris 
    215  1.1  chris 	switch (error) {
    216  1.1  chris 	case ENXIO:
    217  1.1  chris 		printf("device bad\n");
    218  1.1  chris 		break;
    219  1.1  chris 
    220  1.1  chris 	case EFAULT:
    221  1.1  chris 		printf("device not ready\n");
    222  1.1  chris 		break;
    223  1.1  chris 
    224  1.1  chris 	case EINVAL:
    225  1.1  chris 		printf("area improper\n");
    226  1.1  chris 		break;
    227  1.1  chris 
    228  1.1  chris 	case EIO:
    229  1.1  chris 		printf("i/o error\n");
    230  1.1  chris 		break;
    231  1.1  chris 
    232  1.1  chris 	case EINTR:
    233  1.1  chris 		printf("aborted from console\n");
    234  1.1  chris 		break;
    235  1.1  chris 
    236  1.1  chris 	default:
    237  1.1  chris 		printf("succeeded\n");
    238  1.1  chris 		break;
    239  1.1  chris 	}
    240  1.1  chris 	printf("\n\n");
    241  1.1  chris 	delay(1000000);
    242  1.1  chris }
    243  1.1  chris 
    244  1.1  chris /* This is interrupt / SPL related */
    245  1.1  chris 
    246  1.1  chris int current_spl_level = _SPL_HIGH;
    247  1.1  chris u_int spl_masks[_SPL_LEVELS + 1];
    248  1.1  chris u_int spl_smasks[_SPL_LEVELS];
    249  1.1  chris int safepri = _SPL_0;
    250  1.1  chris 
    251  1.1  chris void
    252  1.1  chris set_spl_masks()
    253  1.1  chris {
    254  1.1  chris 	int loop;
    255  1.1  chris 
    256  1.1  chris 	for (loop = 0; loop < _SPL_LEVELS; ++loop) {
    257  1.1  chris 		spl_masks[loop] = 0xffffffff;
    258  1.1  chris 		spl_smasks[loop] = 0;
    259  1.1  chris 	}
    260  1.1  chris 
    261  1.1  chris 	spl_masks[_SPL_BIO]	   = irqmasks[IPL_BIO];
    262  1.1  chris 	spl_masks[_SPL_NET]	   = irqmasks[IPL_NET];
    263  1.1  chris 	spl_masks[_SPL_SOFTSERIAL] = irqmasks[IPL_TTY];
    264  1.1  chris 	spl_masks[_SPL_TTY]	   = irqmasks[IPL_TTY];
    265  1.1  chris 	spl_masks[_SPL_IMP]	   = irqmasks[IPL_IMP];
    266  1.1  chris 	spl_masks[_SPL_AUDIO]	   = irqmasks[IPL_AUDIO];
    267  1.1  chris 	spl_masks[_SPL_CLOCK]	   = irqmasks[IPL_CLOCK];
    268  1.1  chris 	spl_masks[_SPL_HIGH]	   = irqmasks[IPL_HIGH];
    269  1.1  chris 	spl_masks[_SPL_SERIAL]	   = irqmasks[IPL_SERIAL];
    270  1.1  chris 	spl_masks[_SPL_LEVELS]	   = 0;
    271  1.1  chris 
    272  1.1  chris 	spl_smasks[_SPL_0] = 0xffffffff;
    273  1.1  chris 	for (loop = 0; loop < _SPL_SOFTSERIAL; ++loop)
    274  1.1  chris 		spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_SERIAL);
    275  1.1  chris 	for (loop = 0; loop < _SPL_SOFTNET; ++loop)
    276  1.1  chris 		spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_NET);
    277  1.1  chris 	for (loop = 0; loop < _SPL_SOFTCLOCK; ++loop)
    278  1.1  chris 		spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_CLOCK);
    279  1.1  chris }
    280  1.1  chris 
    281  1.1  chris #ifdef DIAGNOSTIC
    282  1.1  chris void
    283  1.1  chris dump_spl_masks()
    284  1.1  chris {
    285  1.1  chris 	int loop;
    286  1.1  chris 
    287  1.1  chris 	for (loop = 0; loop < _SPL_LEVELS; ++loop) {
    288  1.1  chris 		printf("spl_mask[%d]=%08x splsmask[%d]=%08x\n", loop,
    289  1.1  chris 		    spl_masks[loop], loop, spl_smasks[loop]);
    290  1.1  chris 	}
    291  1.1  chris }
    292  1.1  chris #endif
    293  1.1  chris 
    294  1.1  chris /* End of stubs.c */
    295