trace.c
5.83 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* Copyright (C) 1996-1998 by the Board of Trustees
* of Leland Stanford Junior University.
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*****************************************************************
*
* trace.c
*
* ISSUES -
* Exception: cause, epc (check branch delay slot issue), badVaddr
* Don't send asid with each subtype
* send uncached too
****************************************************************/
#include "sim_error.h"
#include "machine_params.h"
#include "cpu_state.h"
#include "simtypes.h"
#include "TraceDef.h"
#include "tcl_init.h"
#define MAX_CPUS 128
void *packetManager;
TracePacket_t *packet;
int asid[MAX_CPUS];
int tracingActive = 1;
struct {
Boolean active;
VA dataVA;
PA dataPA;
VA dataInstPC;
} dataEvent[MAX_CPUS];
char traceDumpMask[MAX_CPUS];
extern CPUState *PE;
/*****************************************************************
* TraceInit
*****************************************************************/
void
TraceInit()
{
int i;
packetManager = (void *)InitTrace("trace.out", TRUE);
packet = (TracePacket_t *)InitPacket();
for (i=0; i< TOTAL_CPUS; i++) {
asid[i] = GET_ASID(PE[i].CP0[C0_TLBHI]);
dataEvent[i].active = FALSE;
traceDumpMask[i] = 0;
}
}
/*****************************************************************
* TraceInstruction
*****************************************************************/
void
TraceInstruction(CPUState *P, Inst instr)
{
int cpuNum = P->myNum;
if (!traceDumpMask[cpuNum]) return;
packet->Id = Instr_e;
packet->processorId = cpuNum;
packet->instWord = instr;
packet->instVAddr = P->PC;
packet->instPAddr = P->pcPaddrcache + PAGE_OFFSET(P->PC);
packet->instASID = asid[cpuNum];
if (P->branchStatus == BranchStatus_taken) {
packet->Id = JumpBranchTaken_e;
} else if (dataEvent[cpuNum].active) {
ASSERT(P->PC == dataEvent[cpuNum].dataInstPC);
packet->Id = MemRef_e;
packet->packetValue.memRef.dataVAddr = dataEvent[cpuNum].dataVA;
packet->packetValue.memRef.dataPAddr = dataEvent[cpuNum].dataPA;
packet->packetValue.memRef.dataASID = asid[cpuNum];
dataEvent[cpuNum].active = FALSE;
}
SendPacket(packet, packetManager);
}
/*****************************************************************
* TraceDataRef
*****************************************************************/
void
TraceDataRef(CPUState *P, VA vAddr, PA pAddr)
{
int cpuNum = P->myNum;
if (!traceDumpMask[cpuNum]) return;
if (dataEvent[cpuNum].active != FALSE) {
/* The implementation of sdl and sdr cause two memory references
*/
ASSERT(dataEvent[cpuNum].dataInstPC == P->PC);
}
dataEvent[cpuNum].active = TRUE;
dataEvent[cpuNum].dataVA = vAddr;
dataEvent[cpuNum].dataPA = pAddr;
dataEvent[cpuNum].dataInstPC = P->PC;
}
void
TraceUncachedDataRef(CPUState *P, VA vAddr, PA pAddr)
{
int cpuNum = P->myNum;
if (!traceDumpMask[cpuNum]) return;
if (dataEvent[cpuNum].active != FALSE) {
/* The implementation of sdl and sdr cause two memory references
*/
ASSERT(dataEvent[cpuNum].dataInstPC == P->PC);
}
dataEvent[cpuNum].active = TRUE;
dataEvent[cpuNum].dataVA = vAddr;
dataEvent[cpuNum].dataPA = pAddr;
dataEvent[cpuNum].dataInstPC = P->PC;
}
void
TraceCheckASID(CPUState *P)
{
int cpuNum = P->myNum;
int newASID = GET_ASID(P->CP0[C0_TLBHI]);
asid[cpuNum] = GET_ASID(P->CP0[C0_TLBHI]);
if (!traceDumpMask[cpuNum]) return;
if (asid[cpuNum] != newASID) {
CPUWarning("ASID[%d]:\t %d to %d at %#x\n", P->myNum, asid[P->myNum],
GET_ASID(P->CP0[C0_TLBHI]), P->PC);
}
}
void
TraceException(CPUState *P, int code)
{
int cpuNum = 0;
if (!traceDumpMask[cpuNum]) return;
packet->Id = Event_e;
packet->processorId = cpuNum;
/* PROBLEM -> hard to get this field again*/
packet->instWord = 0;
packet->instVAddr = P->PC;
/* this might not be right for interrupts */
packet->instPAddr = P->pcPaddrcache + PAGE_OFFSET(P->PC);
packet->instASID = asid[cpuNum];
/* Treat interrupts differently? */
packet->packetValue.event.event = code >> 2;
/* Clear cached load or store address */
dataEvent[cpuNum].active = FALSE;
SendPacket(packet, packetManager);
}
int
TraceDumpTclCmd(ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
#ifndef TRACING
Tcl_AppendResult(interp,
"traceDump not supported unless mipsy compiled -DTRACING",
NULL);
return TCL_ERROR;
#else
int i;
#ifndef SOLO
if (simosCPUType != MIPSY) {
Tcl_AppendResult(interp, "traceDump only supported in mipsy",
NULL);
return TCL_ERROR;
}
#endif
if (argc < 2) {
Tcl_AppendResult(interp,
"Usage: traceDump <all|off|list of cpunumbers>",
NULL);
return TCL_ERROR;
}
if (!strcmp(argv[1], "off")) {
CPUWarning("traceDump: Turning trace dumping OFF\n");
for (i = 0; i < MAX_CPUS; i++) {
traceDumpMask[i] = 0;
}
} else if (!strcmp(argv[1], "all")) {
CPUWarning("traceDump: Turning trace dumping on for ALL cpus\n");
for (i = 0; i < MAX_CPUS; i++) {
traceDumpMask[i] = 1;
}
} else {
for (i=1; i<argc; i++) {
int cpuNum;
if ((Tcl_GetInt(interp, argv[i], &cpuNum) != TCL_OK)
|| cpuNum >= MAX_CPUS ) {
Tcl_AppendResult(interp, "Bad cpu num to traceDump command",
NULL);
return TCL_ERROR;
}
traceDumpMask[cpuNum] = 1;
CPUWarning("traceDump: Enabling trace dumping for cpu %d\n", cpuNum);
}
}
return TCL_OK;
#endif
}