Home | History | Annotate | Line # | Download | only in boot
machdep.c revision 1.4
      1  1.4  christos /*	$NetBSD: machdep.c,v 1.4 2002/07/11 16:03:19 christos Exp $	*/
      2  1.1       dbj /*
      3  1.1       dbj  * Copyright (c) 1998 Darrin Jewell
      4  1.1       dbj  * Copyright (c) 1994 Rolf Grossmann
      5  1.1       dbj  * All rights reserved.
      6  1.1       dbj  *
      7  1.1       dbj  * Redistribution and use in source and binary forms, with or without
      8  1.1       dbj  * modification, are permitted provided that the following conditions
      9  1.1       dbj  * are met:
     10  1.1       dbj  * 1. Redistributions of source code must retain the above copyright
     11  1.1       dbj  *    notice, this list of conditions and the following disclaimer.
     12  1.1       dbj  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1       dbj  *    notice, this list of conditions and the following disclaimer in the
     14  1.1       dbj  *    documentation and/or other materials provided with the distribution.
     15  1.1       dbj  * 3. All advertising materials mentioning features or use of this software
     16  1.1       dbj  *    must display the following acknowledgement:
     17  1.1       dbj  *      This product includes software developed by Rolf Grossmann.
     18  1.1       dbj  * 4. The name of the author may not be used to endorse or promote products
     19  1.1       dbj  *    derived from this software without specific prior written permission
     20  1.1       dbj  *
     21  1.1       dbj  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1       dbj  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1       dbj  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1       dbj  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1       dbj  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1       dbj  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1       dbj  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1       dbj  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1       dbj  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1       dbj  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1       dbj  */
     32  1.1       dbj 
     33  1.1       dbj #include <sys/types.h>
     34  1.1       dbj 
     35  1.1       dbj #include <stand.h>
     36  1.1       dbj #include <next68k/next68k/nextrom.h>
     37  1.1       dbj 
     38  1.1       dbj char *mg;
     39  1.1       dbj 
     40  1.1       dbj #define	MON(type, off) (*(type *)((u_int) (mg) + off))
     41  1.1       dbj 
     42  1.3       chs extern int entry_point;
     43  1.1       dbj 
     44  1.1       dbj #ifdef DEBUG
     45  1.1       dbj int debug = 1;
     46  1.1       dbj #else
     47  1.1       dbj int debug = 0;
     48  1.1       dbj #endif
     49  1.1       dbj 
     50  1.1       dbj #ifdef DEBUG
     51  1.1       dbj #define DPRINTF(x) printf x
     52  1.1       dbj #else
     53  1.1       dbj #define DPRINTF(x)
     54  1.1       dbj #endif
     55  1.1       dbj 
     56  1.1       dbj void
     57  1.1       dbj machdep_start(char *entry, int howto, char *loadaddr, char *ssym, char *esym)
     58  1.1       dbj {
     59  1.3       chs 	DPRINTF(("machdep_start(entry=%p,howto=0x%x,loadaddr=%p,ssym=%p,esym=%p\n",
     60  1.3       chs 		 entry, howto, loadaddr, ssym, esym));
     61  1.3       chs 	MON(int,MG_boot_how) = howto;
     62  1.3       chs 	entry_point = (int)entry + (int)loadaddr;
     63  1.3       chs 	DPRINTF(("start=0x%lx\n", (u_long)entry_point));
     64  1.3       chs 
     65  1.3       chs 	/* @@@ hack to pass esym to kernel */
     66  1.3       chs 	*((u_int *)loadaddr) = (u_int)esym;
     67  1.1       dbj 
     68  1.3       chs 	/* return to exec, so that main can return entry point */
     69  1.1       dbj }
     70  1.1       dbj 
     71  1.1       dbj typedef int (*getcptr)(void);
     72  1.1       dbj typedef int (*putcptr)(int);
     73  1.1       dbj 
     74  1.1       dbj int
     75  1.1       dbj getchar(void)
     76  1.1       dbj {
     77  1.3       chs 	return(MON(getcptr,MG_getc)());
     78  1.1       dbj }
     79  1.1       dbj 
     80  1.1       dbj void
     81  1.1       dbj putchar(int c)
     82  1.1       dbj {
     83  1.3       chs 	MON(putcptr,MG_putc)(c);
     84  1.1       dbj }
     85  1.1       dbj 
     86  1.1       dbj __dead void
     87  1.1       dbj _rtt(void)
     88  1.1       dbj {
     89  1.3       chs 	extern __dead void _halt __P((void)) __attribute__((noreturn));
     90  1.1       dbj 
     91  1.3       chs 	printf("Press any key to halt.\n");
     92  1.3       chs 	getchar();
     93  1.3       chs 	_halt();
     94  1.3       chs 	/* NOTREACHED */
     95  1.1       dbj }
     96  1.1       dbj 
     97  1.1       dbj struct trapframe {
     98  1.3       chs 	int dregs[8];
     99  1.3       chs 	int aregs[8];
    100  1.3       chs 	short sr;
    101  1.3       chs 	int pc;
    102  1.4  christos 	u_short fmt:4,
    103  1.4  christos 		vec:12;
    104  1.3       chs 	char info[0];
    105  1.4  christos } __attribute__ ((packed));
    106  1.2       dbj 
    107  1.2       dbj int trap __P((struct trapframe *fp));
    108  1.1       dbj 
    109  1.1       dbj int
    110  1.1       dbj trap(struct trapframe *fp)
    111  1.1       dbj {
    112  1.3       chs 	static int intrap = 0;
    113  1.1       dbj 
    114  1.3       chs 	if (intrap)
    115  1.3       chs 		return 0;
    116  1.3       chs 	intrap = 1;
    117  1.3       chs 	printf("Got unexpected trap: format=%x vector=%x sr=%x pc=%x\n",
    118  1.4  christos 	       fp->fmt, fp->vec, fp->sr, fp->pc);
    119  1.3       chs 	printf("dregs: %x %x %x %x %x %x %x %x\n",
    120  1.3       chs 	       fp->dregs[0], fp->dregs[1], fp->dregs[2], fp->dregs[3],
    121  1.3       chs 	       fp->dregs[4], fp->dregs[5], fp->dregs[6], fp->dregs[7]);
    122  1.3       chs 	printf("aregs: %x %x %x %x %x %x %x %x\n",
    123  1.3       chs 	       fp->aregs[0], fp->aregs[1], fp->aregs[2], fp->aregs[3],
    124  1.3       chs 	       fp->aregs[4], fp->aregs[5], fp->aregs[6], fp->aregs[7]);
    125  1.3       chs 	intrap = 0;
    126  1.4  christos #ifdef DEBUG
    127  1.4  christos 	if (debug)
    128  1.4  christos 	{
    129  1.4  christos 		int i;
    130  1.4  christos 		int *p;
    131  1.4  christos 		p = (int *)(fp->pc);
    132  1.4  christos 		for (i = 0; i < 64; i++) {
    133  1.4  christos 			if ((i % 8) == 0)
    134  1.4  christos 				printf ("\npc %x: ", (int)&p[i-16]);
    135  1.4  christos 			printf ("%x ", p[i]);
    136  1.4  christos 		}
    137  1.4  christos 		p = (int *)(fp->info);
    138  1.4  christos 		for (i = 0; i < 64; i++) {
    139  1.4  christos 			if ((i % 8) == 0)
    140  1.4  christos 				printf ("\nstk %x: ", (int)&p[i-16]);
    141  1.4  christos 			printf ("%x ", p[i]);
    142  1.4  christos 		}
    143  1.4  christos 		printf ("\n");
    144  1.4  christos 	}
    145  1.4  christos #endif
    146  1.3       chs 	printf("Halting.\n");
    147  1.1       dbj 	return 0;
    148  1.1       dbj }
    149