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