2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
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
);
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
)
40 valid
= mmu_valid_check_030(p
);
43 valid
= mmu_valid_check_040(p
);
46 valid
= mmu_valid_check_060(p
);
52 static void dumpline(UWORD mmutype
, const UBYTE
*label
, ULONG
*p
)
56 for (i
= 0; i
< 8; i
++) {
57 if (mmuisvalid(mmutype
, &p
[i
]) && mmuisvalid(mmutype
, ((UBYTE
*)(&p
[i
])) + 3))
60 DebugPutStr("???????? ");
65 static void dumpstr(UWORD mmutype
, const UBYTE
*label
, const UBYTE
*str
)
69 if (mmuisvalid(mmutype
, (APTR
)str
)) {
74 DebugPutStr("<INVALID>");
77 DebugPutStr("<NULL>");
80 static void dumpbstr(UWORD mmutype
, const UBYTE
*label
, const UBYTE
*str
)
84 if (mmuisvalid(mmutype
, (APTR
)str
)) {
88 for (i
= 0; i
< str
[0]; i
++) {
90 if (mmuisvalid(mmutype
, (APTR
)&str
[i
+ 1]))
91 tmp
[i
+ 1] = str
[i
+ 1];
97 DebugPutStr("<INVALID>");
100 DebugPutStr("<BNULL>");
103 static void dumpinfo(UWORD mmutype
, struct ExecBase
*SysBase
, ULONG pc
)
105 struct DebugBase
*DebugBase
;
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
));
122 /* Better way to find DebugBase in Supervisor mode? */
123 DebugBase
= (struct DebugBase
*)FindName(&SysBase
->LibList
, "debug.library");
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
));
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
;
158 BOOL hasdata
= FALSE
;
159 UWORD mmutype
= bf
->type
;
161 BOOL addrerror
= (bf
->type
& 0x10) != 0;
163 DebugPutStr(addrerror
? "Address Error!\n" : "Bus Error!\n");
165 if (mmutype
== 0 || mmutype
== 0x10) {
167 fa
= ((ULONG
*)(mf
+ 16))[0];
168 sw
= ((UWORD
*)(mf
+ 10))[0];
169 size
= (sw
>> 4) & 3;
170 write
= (sw
& 0x40) == 0;
173 data
= ((ULONG
*)(mf
+ 24))[0];
176 } else if (mmutype
== 1) {
178 fa
= ((ULONG
*)(mf
+ 20))[0];
179 sw
= ((UWORD
*)(mf
+ 12))[0];
180 size
= (sw
>> 5) & 3;
181 write
= (sw
& 0x100) == 0;
183 if (write
&& (mf
[15] & 0x80)) {
184 data
= ((ULONG
*)(mf
+ 28))[0];
187 } else if (mmutype
== 2) {
189 fa
= ((ULONG
*)(mf
+ 8))[0];
190 sw
= ((ULONG
*)(mf
+ 12))[0];
191 size
= (sw
>> 21) & 3;
192 write
= (sw
& 0x800000) != 0;
194 } else if (mmutype
== 0x11 || mmutype
== 0x12) {
196 fa
= ((ULONG
*)(mf
+ 8))[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)) {
207 DebugPutStr("INVALID SYSBASE!\n");
210 DebugPutStr(sizes
[size
]);
212 DebugPutStr(write
? "WRITE to " : "READ from ");
215 DebugPutStr("(INST)");
218 DebugPutStr(" data: ");
220 DebugPutHexVal(data
);
222 DebugPutStr("-------- ");
223 DebugPutStr(" PC: ");
227 DebugPutStr("USP: ");
228 DebugPutHexVal((ULONG
)bf
->usp
);
231 DebugPutStr(" SW: ");
234 buf
[1] = (sr
& 0x2000) ? 'S' : 'U';
235 buf
[2] = ((sr
>> 8) & 7) + '0';
238 buf
[5] = SysBase
? (SysBase
->TDNestCnt
>= 0 ? 'F' : '-') : '?';
241 buf
[8] = SysBase
? (SysBase
->IDNestCnt
>= 0 ? 'D' : '-') : '?';
245 DebugPutStr(" TCB: ");
246 DebugPutHexVal(SysBase
? 0xffffffff : (ULONG
)SysBase
->ThisTask
);
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
);