Copyright clean-up (part 1):
[AROS.git] / arch / m68k-all / kernel / bushandler.c
blob6c95489bf6f79c13a5aa6e504ceff3a4ecc4a2e8
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <exec/execbase.h>
8 #include <dos/dosextens.h>
9 #include <libraries/debug.h>
10 #include <proto/exec.h>
11 #include <proto/debug.h>
13 void DebugPutStr(register const char *buff);
14 void DebugPutHex(const char *what, ULONG val);
15 void DebugPutDec(const char *what, ULONG val);
16 void DebugPutHexVal(ULONG val);
18 struct busframe
20 APTR mmuframe;
21 ULONG type;
22 ULONG *usp;
23 ULONG *vbr;
24 ULONG regs[16];
27 #if AROS_SERIAL_DEBUG
28 static const UBYTE *sizes[] = { "LONG", "BYTE", "WORD", "?" };
30 extern BOOL mmu_valid_check_030(APTR);
31 extern BOOL mmu_valid_check_040(APTR);
32 extern BOOL mmu_valid_check_060(APTR);
34 static BOOL mmuisvalid(UWORD mmutype, APTR p)
36 UWORD valid = 0;
37 switch(mmutype)
39 case 0:
40 valid = mmu_valid_check_030(p);
41 break;
42 case 1:
43 valid = mmu_valid_check_040(p);
44 break;
45 case 2:
46 valid = mmu_valid_check_060(p);
47 break;
49 return valid == 0;
52 static void dumpline(UWORD mmutype, const UBYTE *label, ULONG *p)
54 WORD i;
55 DebugPutStr(label);
56 for (i = 0; i < 8; i++) {
57 if (mmuisvalid(mmutype, &p[i]) && mmuisvalid(mmutype, ((UBYTE*)(&p[i])) + 3))
58 DebugPutHexVal(p[i]);
59 else
60 DebugPutStr("???????? ");
62 DebugPutStr("\n");
65 static void dumpstr(UWORD mmutype, const UBYTE *label, const UBYTE *str)
67 DebugPutStr(label);
68 if (str) {
69 if (mmuisvalid(mmutype, (APTR)str)) {
70 DebugPutStr("\"");
71 DebugPutStr(str);
72 DebugPutStr("\"");
73 } else {
74 DebugPutStr("<INVALID>");
76 } else {
77 DebugPutStr("<NULL>");
80 static void dumpbstr(UWORD mmutype, const UBYTE *label, const UBYTE *str)
82 DebugPutStr(label);
83 if (str) {
84 if (mmuisvalid(mmutype, (APTR)str)) {
85 UBYTE tmp[258];
86 UBYTE i;
87 tmp[0] = '\"';
88 for (i = 0; i < str[0]; i++) {
89 tmp[i + 1] = '?';
90 if (mmuisvalid(mmutype, (APTR)&str[i + 1]))
91 tmp[i + 1] = str[i + 1];
93 tmp[i + 1] = '\"';
94 tmp[i + 2] = 0;
95 DebugPutStr(tmp);
96 } else {
97 DebugPutStr("<INVALID>");
99 } else {
100 DebugPutStr("<BNULL>");
103 static void dumpinfo(UWORD mmutype, struct ExecBase *SysBase, ULONG pc)
105 struct DebugBase *DebugBase;
106 struct Task *t;
108 if (SysBase == NULL)
109 return;
110 t = SysBase->ThisTask;
111 if (t && mmuisvalid(mmutype, t) && (t->tc_Node.ln_Type == NT_TASK || t->tc_Node.ln_Type == NT_PROCESS)) {
112 dumpstr(mmutype, "Name: ", t->tc_Node.ln_Name);
113 if (t->tc_Node.ln_Type == NT_PROCESS) {
114 struct Process *p = (struct Process*)t;
115 if (p->pr_CLI && mmuisvalid(mmutype, BADDR(p->pr_CLI))) {
116 struct CommandLineInterface *cli = (struct CommandLineInterface*)BADDR(p->pr_CLI);
117 dumpbstr(mmutype, " CLI: ", BADDR(cli->cli_CommandName));
120 DebugPutStr("\n");
122 /* Better way to find DebugBase in Supervisor mode? */
123 DebugBase = (struct DebugBase*)FindName(&SysBase->LibList, "debug.library");
124 if (DebugBase) {
125 ULONG segNum;
126 BPTR segPtr;
127 char *modName;
128 if (DecodeLocation(pc, DL_SegmentNumber, &segNum, DL_SegmentPointer, &segPtr, DL_ModuleName, &modName, TAG_DONE)) {
129 dumpstr(mmutype, "Module ", modName);
130 DebugPutStr(" Hunk ");
131 DebugPutHexVal(segNum);
132 DebugPutStr("Offset ");
133 DebugPutHexVal(pc - (ULONG)BADDR(segPtr));
134 DebugPutStr("Start ");
135 DebugPutHexVal((ULONG)BADDR(segPtr));
139 #endif
141 /* WARNING: Running in bus/address error exception.
142 * Can't call most system routines!
144 void bushandler(struct busframe *bf)
146 #if AROS_SERIAL_DEBUG
147 struct ExecBase *SysBase = (struct ExecBase*)(bf->vbr[1]);
148 UBYTE *mf = bf->mmuframe;
149 ULONG fa = 0;
150 ULONG sw = 0;
151 ULONG data;
152 ULONG pc;
153 UWORD size = 0;
154 UWORD fc = 0;
155 UWORD sr;
156 BOOL write = FALSE;
157 BOOL inst = FALSE;
158 BOOL hasdata = FALSE;
159 UWORD mmutype = bf->type;
160 char buf[16];
161 BOOL addrerror = (bf->type & 0x10) != 0;
163 DebugPutStr(addrerror ? "Address Error!\n" : "Bus Error!\n");
165 if (mmutype == 0 || mmutype == 0x10) {
166 // 68030
167 fa = ((ULONG*)(mf + 16))[0];
168 sw = ((UWORD*)(mf + 10))[0];
169 size = (sw >> 4) & 3;
170 write = (sw & 0x40) == 0;
171 fc = sw & 7;
172 if (write) {
173 data = ((ULONG*)(mf + 24))[0];
174 hasdata = TRUE;
176 } else if (mmutype == 1) {
177 // 68040
178 fa = ((ULONG*)(mf + 20))[0];
179 sw = ((UWORD*)(mf + 12))[0];
180 size = (sw >> 5) & 3;
181 write = (sw & 0x100) == 0;
182 fc = sw & 7;
183 if (write && (mf[15] & 0x80)) {
184 data = ((ULONG*)(mf + 28))[0];
185 hasdata = TRUE;
187 } else if (mmutype == 2) {
188 // 68060
189 fa = ((ULONG*)(mf + 8))[0];
190 sw = ((ULONG*)(mf + 12))[0];
191 size = (sw >> 21) & 3;
192 write = (sw & 0x800000) != 0;
193 fc = (sw >> 16) & 7;
194 } else if (mmutype == 0x11 || mmutype == 0x12) {
195 // 68040
196 fa = ((ULONG*)(mf + 8))[0];
197 sw = 0;
198 size = 0;
199 fc = (((UWORD*)mf)[0] & 0x2000) ? 6 : 2;
201 pc = ((ULONG*)(mf + 2))[0];
202 inst = (fc & 3) == 2;
203 sr = ((UWORD*)mf)[0];
205 if (!mmuisvalid(mmutype, SysBase) || !mmuisvalid(mmutype, SysBase + 1)) {
206 SysBase = NULL;
207 DebugPutStr("INVALID SYSBASE!\n");
210 DebugPutStr(sizes[size]);
211 DebugPutStr("-");
212 DebugPutStr(write ? "WRITE to " : "READ from ");
213 DebugPutHexVal(fa);
214 if (inst)
215 DebugPutStr("(INST)");
216 else
217 DebugPutStr(" ");
218 DebugPutStr(" data: ");
219 if (hasdata)
220 DebugPutHexVal(data);
221 else
222 DebugPutStr("-------- ");
223 DebugPutStr(" PC: ");
224 DebugPutHexVal(pc);
225 DebugPutStr("\n");
227 DebugPutStr("USP: ");
228 DebugPutHexVal((ULONG)bf->usp);
229 DebugPutStr("SR: ");
230 DebugPutHexVal(sr);
231 DebugPutStr(" SW: ");
232 DebugPutHexVal(sw);
233 buf[0] = '(';
234 buf[1] = (sr & 0x2000) ? 'S' : 'U';
235 buf[2] = ((sr >> 8) & 7) + '0';
236 buf[3] = ')';
237 buf[4] = '(';
238 buf[5] = SysBase ? (SysBase->TDNestCnt >= 0 ? 'F' : '-') : '?';
239 buf[6] = ')';
240 buf[7] = '(';
241 buf[8] = SysBase ? (SysBase->IDNestCnt >= 0 ? 'D' : '-') : '?';
242 buf[9] = ')';
243 buf[10] = 0;
244 DebugPutStr(buf);
245 DebugPutStr(" TCB: ");
246 DebugPutHexVal(SysBase ? 0xffffffff : (ULONG)SysBase->ThisTask);
247 DebugPutStr("\n");
249 dumpline(mmutype, "Data: ", &bf->regs[0]);
250 dumpline(mmutype, "Addr: ", &bf->regs[8]);
252 dumpline(mmutype, "Stck: ", bf->usp);
253 dumpline(mmutype, "Stck: ", bf->usp + 8);
255 dumpline(mmutype, "PC-8: ", (ULONG*)(pc - 8 * 4));
256 dumpline(mmutype, "PC *: ", (ULONG*)pc);
258 dumpinfo(mmutype, SysBase, pc);
260 DebugPutStr("\n");
261 #endif