-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.c
196 lines (157 loc) · 3.43 KB
/
trace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
* (c) UQLX - see COPYRIGHT
*/
#include "QL68000.h"
#include <stdio.h>
#ifdef TRACE
uw16 *tracelo;
uw16 *tracehi;
struct TRT
{
uw16 *low;
uw16 *high;
char *comment;
} tracetable[]={
#if 1 // ROM
{0,16384*3,"ROM"},
#endif
#if 0
{0xf7938,0xf7a38,"Qsave"},
#endif
#if 0
{0x1fb800,0x1ff14a,"Ptr_gen"},
#endif
#if 0
{0x36d4,0x3720,"Verify Name"},
{0x32a2,0x3378,"trap#2"},
{0x355a,0x36b6,"dirdev open"},
#endif
#if 0
{0x3ef6,0x405e,"vect $F0"},
{0x4a0c,0x4a4a,"RI.NEG"},
{0x497e,0x4a00,"RI.DIV"},
{0x48de,0x497e,"RI.MULT"},
{0x3e54,0x3ea8,"CN.ITOD"},
#endif
/* the end marker, always should be there */
{0,0,0}};
/* Ptr Backtrace: */
struct TRT *curr=NULL;
struct BTE {
uw16 *where; /* absolute address */
uw16 *to; /* relative address */
int what; /* event type */
} backtrace[100];
#define BACKTRSIZE 100
struct BTE *btcurr=backtrace;
int btnochng=1;
void TraceInit()
{
CheckTrace();
}
void AddBackTrace(Ptr p, int type)
{
uw16 *lpc=(uw16*)((Ptr)pc-(Ptr)theROM);
if (btcurr>backtrace+BACKTRSIZE) btcurr=backtrace;
btcurr->where=p;
btcurr->to=lpc;
btcurr->what=type;
btcurr++;
btnochng=0;
}
void CheckTrace()
{
struct TRT *p;
uw16 *lpc=(uw16*)((Ptr)pc-(Ptr)theROM);
p=tracetable;
curr=0;
while((p->low) || (p->high))
{
if ( ((p->low <=lpc) && (p->high >=lpc)) ||
(p->low >= lpc) && ( curr==NULL || ((p->low) <= (curr->low))))
curr=p;
p++;
}
if (curr)
{
tracelo=(uw16*)((Ptr)(curr->low)+(long)theROM);
tracehi=(uw16*)((Ptr)(curr->high)+(long)theROM);
}
else tracelo=(uw16*)((Ptr)RTOP+(long)theROM);
}
void DoTrace()
{
/*printf("entering Dotrace, pcl %x pch %x pc%x\n",tracelo,tracehi,pc);*/
if (pc>tracehi)
{
CheckTrace();
return;
}
printf("Trace : %s+%x\n",curr->comment,(Ptr)pc-(Ptr)(curr->low)-(long)theROM);
DbgInfo();
}
void BTShowException(int xc)
{
short i;
int p1,p4;
unsigned char *p3;
long ixc=xc;
if(ixc==4)
{
p3="Illegal code";
}
else
{
p3="";
if(ixc==2) p3="bus error";
if(ixc==3) p3="address error";
if(ixc==5) p3="divide by zero";
if(ixc==6) p3="CHK instruction";
if(ixc==7) p3="TRAPV instruction";
if(ixc==8) p3="privilege violation";
if(ixc==9) p3="trace xc";
if(ixc==10) p3="Axxx instruction code";
if(ixc==11) p3="Fxxx instruction code";
if(xc>=32 && xc<=32+15) {printf("\tTRAP #%d\t",xc-32);return;}
if(xc>=24 && xc<=24+7){printf("\tInterrupt #%d\t",xc-24);return;}
}
printf("\tException %s \t",p3);
}
void BackTrace(int depth)
{
struct BTE *p;
char *evname;
int what,x=0;
printf("BackTrace:\n");
if (btnochng) {
printf("\tunchanged\n");
return;
}
btnochng=1;
p=btcurr;
if (depth>BACKTRSIZE) depth=BACKTRSIZE;
for(;depth--;p--)
{
if (p<backtrace) p=backtrace+BACKTRSIZE;
what=p->what;
if (what>0){
switch(p->what){
case RTS : evname="RTS";
break;
case RTE : evname="RTE";
break;
case RTR : evname="RTR";
break;
case JSR : evname="JSR";
break;
case BSR : evname="BSR";
break;
default : evname="unknown";
}
printf("\t %s\t",evname);
}
else BTShowException(-what);
printf("at PC=%x, new pc=%x\n",(Ptr)(p->where)-(Ptr)theROM,p->to);
}
}
#endif /* TRACE */