Home | History | Annotate | Line # | Download | only in boot
machdep.c revision 1.1
      1  1.1  dbj /*	$NetBSD: machdep.c,v 1.1 1998/06/09 07:53:06 dbj 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.1  dbj extern char *entry_point;
     43  1.1  dbj 
     44  1.1  dbj 
     45  1.1  dbj #ifdef DEBUG
     46  1.1  dbj int debug = 1;
     47  1.1  dbj #else
     48  1.1  dbj int debug = 0;
     49  1.1  dbj #endif
     50  1.1  dbj 
     51  1.1  dbj #ifdef DEBUG
     52  1.1  dbj #define DPRINTF(x) printf x
     53  1.1  dbj #else
     54  1.1  dbj #define DPRINTF(x)
     55  1.1  dbj #endif
     56  1.1  dbj 
     57  1.1  dbj void
     58  1.1  dbj machdep_start(char *entry, int howto, char *loadaddr, char *ssym, char *esym)
     59  1.1  dbj {
     60  1.1  dbj   DPRINTF(("machdep_start(entry=0x%lx,howto=0x%x,loadaddr=0x%lx,ssym=0x%lx,esym=0x%lx\n",
     61  1.1  dbj            (u_long)entry,howto,(u_long)loadaddr,(u_long)ssym,(u_long)esym));
     62  1.1  dbj   MON(int,MG_boot_how) = howto;
     63  1.1  dbj   entry_point = entry + (long)loadaddr;
     64  1.1  dbj   DPRINTF(("start=0x%lx\n", (u_long)entry_point));
     65  1.1  dbj 
     66  1.1  dbj   /* @@@ hack to pass esym to kernel */
     67  1.1  dbj   *((u_int *)loadaddr) = (u_int)esym;
     68  1.1  dbj 
     69  1.1  dbj   /* return to exec, so that main can return entry point */
     70  1.1  dbj }
     71  1.1  dbj 
     72  1.1  dbj typedef int (*getcptr)(void);
     73  1.1  dbj typedef int (*putcptr)(int);
     74  1.1  dbj 
     75  1.1  dbj int
     76  1.1  dbj getchar(void)
     77  1.1  dbj {
     78  1.1  dbj   return(MON(getcptr,MG_getc)());
     79  1.1  dbj }
     80  1.1  dbj 
     81  1.1  dbj void
     82  1.1  dbj putchar(int c)
     83  1.1  dbj {
     84  1.1  dbj   MON(putcptr,MG_putc)(c);
     85  1.1  dbj }
     86  1.1  dbj 
     87  1.1  dbj __dead void
     88  1.1  dbj _rtt(void)
     89  1.1  dbj {
     90  1.1  dbj     extern __dead void _halt __P((void)) __attribute__((noreturn));
     91  1.1  dbj 
     92  1.1  dbj     printf("Press any key to halt.\n");
     93  1.1  dbj     getchar();
     94  1.1  dbj     _halt();
     95  1.1  dbj     /* NOTREACHED */
     96  1.1  dbj }
     97  1.1  dbj 
     98  1.1  dbj struct trapframe {
     99  1.1  dbj     int dregs[8];
    100  1.1  dbj     int aregs[8];
    101  1.1  dbj     short sr;
    102  1.1  dbj     int pc;
    103  1.1  dbj     short frame;
    104  1.1  dbj     char info[0];
    105  1.1  dbj };
    106  1.1  dbj 
    107  1.1  dbj int
    108  1.1  dbj trap(struct trapframe *fp)
    109  1.1  dbj {
    110  1.1  dbj     static int intrap = 0;
    111  1.1  dbj 
    112  1.1  dbj     if (intrap)
    113  1.1  dbj 	return 0;
    114  1.1  dbj     intrap = 1;
    115  1.1  dbj     printf("Got unexpected trap: format=%x vector=%x sr=%x pc=%x\n",
    116  1.1  dbj 	   (fp->frame>>12)&0xF, fp->frame&0xFFF, fp->sr, fp->pc);
    117  1.1  dbj     printf("dregs: %x %x %x %x %x %x %x %x\n",
    118  1.1  dbj 	   fp->dregs[0], fp->dregs[1], fp->dregs[2], fp->dregs[3],
    119  1.1  dbj 	   fp->dregs[4], fp->dregs[5], fp->dregs[6], fp->dregs[7]);
    120  1.1  dbj     printf("aregs: %x %x %x %x %x %x %x %x\n",
    121  1.1  dbj 	   fp->aregs[0], fp->aregs[1], fp->aregs[2], fp->aregs[3],
    122  1.1  dbj 	   fp->aregs[4], fp->aregs[5], fp->aregs[6], fp->aregs[7]);
    123  1.1  dbj     intrap = 0;
    124  1.1  dbj     printf("Halting.\n");
    125  1.1  dbj     return 0;
    126  1.1  dbj }
    127