1 /* $NetBSD: machdep.c,v 1.9 2023/02/12 08:25:09 tsutsui 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 #include "samachdep.h"
39
40 char *mg;
41
42 #define MON(type, off) (*(type *)((u_int) (mg) + off))
43
44 #ifdef DEBUG
45 int debug = 1;
46 #else
47 int debug = 0;
48 #endif
49
50 #ifdef DEBUG
51 #define DPRINTF(x) printf x
52 #else
53 #define DPRINTF(x)
54 #endif
55
56 void
machdep_start(char * entry,int howto,char * loadaddr,char * ssym,char * esym)57 machdep_start(char *entry, int howto, char *loadaddr, char *ssym, char *esym)
58 {
59 DPRINTF(("machdep_start(entry=%p,howto=0x%x,loadaddr=%p,ssym=%p,esym=%p\n",
60 entry, howto, loadaddr, ssym, esym));
61 MON(int,MG_boot_how) = howto;
62 entry_point = (int)entry + (int)loadaddr;
63 DPRINTF(("start=0x%lx\n", (u_long)entry_point));
64
65 /* @@@ hack to pass esym to kernel */
66 *((u_int *)loadaddr) = (u_int)esym;
67
68 /* return to exec, so that main can return entry point */
69 }
70
71 typedef int (*getcptr)(void);
72 typedef int (*putcptr)(int);
73
74 int
getchar(void)75 getchar(void)
76 {
77 return(MON(getcptr,MG_getc)());
78 }
79
80 void
putchar(int c)81 putchar(int c)
82 {
83 MON(putcptr,MG_putc)(c);
84 }
85
86 __dead void
_rtt(void)87 _rtt(void)
88 {
89
90 printf("Press any key to halt.\n");
91 getchar();
92 _halt();
93 /* NOTREACHED */
94 }
95
96 struct trapframe {
97 int dregs[8];
98 int aregs[8];
99 short sr;
100 int pc;
101 u_short fmt:4,
102 vec:12;
103 char info[0];
104 } __attribute__ ((packed));
105
106 int trap(struct trapframe *);
107
108 int
trap(struct trapframe * fp)109 trap(struct trapframe *fp)
110 {
111 static int intrap = 0;
112
113 if (intrap)
114 return 0;
115 intrap = 1;
116 printf("Got unexpected trap: format=%x vector=%x sr=%x pc=%x\n",
117 fp->fmt, fp->vec, fp->sr, fp->pc);
118 printf("dregs: %x %x %x %x %x %x %x %x\n",
119 fp->dregs[0], fp->dregs[1], fp->dregs[2], fp->dregs[3],
120 fp->dregs[4], fp->dregs[5], fp->dregs[6], fp->dregs[7]);
121 printf("aregs: %x %x %x %x %x %x %x %x\n",
122 fp->aregs[0], fp->aregs[1], fp->aregs[2], fp->aregs[3],
123 fp->aregs[4], fp->aregs[5], fp->aregs[6], fp->aregs[7]);
124 intrap = 0;
125 #ifdef DEBUG
126 if (debug)
127 {
128 int i;
129 int *p;
130 p = (int *)(fp->pc);
131 for (i = 0; i < 64; i++) {
132 if ((i % 8) == 0)
133 printf ("\npc %x: ", (int)&p[i-16]);
134 printf ("%x ", p[i]);
135 }
136 p = (int *)(fp->info);
137 for (i = 0; i < 64; i++) {
138 if ((i % 8) == 0)
139 printf ("\nstk %x: ", (int)&p[i-16]);
140 printf ("%x ", p[i]);
141 }
142 printf ("\n");
143 }
144 #endif
145 printf("Halting.\n");
146 return 0;
147 }
148