alpha_trace.c
4.25 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
/*
* Copyright (C) 1998 by the Board of Trustees
* of Leland Stanford Junior University.
* Copyright (C) 1998 Digital Equipment Corporation
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*****************************************************************
*
* trace.c
*
*
****************************************************************/
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "sim_error.h"
#include "machine_params.h"
#include "simtypes.h"
#include "tcl_init.h"
#include "alpha.h"
#include "alpha_trace.h"
struct TracingState trace;
/*****************************************************************
* TraceInit
*****************************************************************/
static void TraceInit(void)
{
int i;
if (trace.active) return;
CPUWarning("\nInitializing ALPHA tracing... \n");
trace.active = 1;
trace.fd = open("trace.out",O_WRONLY|O_CREAT,0644);
ASSERT(trace.fd>0);
for (i=0; i< TOTAL_CPUS; i++) {
trace.cpuMask[i] = 0;
}
trace.buffer = malloc(TRACE_BUFFER_SIZE*sizeof(uint64));
trace.bufferPtr = &trace.buffer[0];
trace.bufferEnd = trace.bufferPtr + TRACE_BUFFER_SIZE;
ASSERT(TOTAL_CPUS < 1<<(56-52));
ASSERT(VA_BITS < 50);
}
void TraceDump(void)
{
int len;
int chk;
ASSERT (trace.active);
len = (trace.bufferPtr-trace.buffer)*sizeof(uint64);
while(1) {
chk = write(trace.fd,trace.buffer,len);
if (chk==-1 && errno==EINTR) {
CPUWarning("alpha_trace::TraceDump. system call interrupted. Retry \n");
continue;
}
ASSERT(chk==len);
break;
}
trace.bufferPtr = &trace.buffer[0];
}
void TraceLog(char *string)
{
uint64 empty=0;
uint64 code = TRACE_FORMAT(TRACE_ASCII,0,0);
size_t len = strlen(string);
int chk;
TraceInit();
TraceDump();
write(trace.fd,(char*)&code,sizeof(uint64));
if (len) {
while(1) {
chk = write(trace.fd,string,len);
if (chk==-1 && errno==EINTR) {
CPUWarning("alpha_trace::TraceLog. system call interrupted. Retry \n");
continue;
}
ASSERT(chk==len);
break;
}
}
len = len & 7;
write(trace.fd,(char*)&empty,8-len);
}
static int
TraceTclCmd(ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
#ifndef TRACING
Tcl_AppendResult(interp,
"traceDump not supported unless compiled -DTRACING",
NULL);
return TCL_ERROR;
#else
int i;
TraceInit();
if (argc < 2) {
Tcl_AppendResult(interp,
"Usage: traceDump <log|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 < SIM_MAXCPUS; i++) {
trace.cpuMask[i] = 0;
}
return TCL_OK;
}
if (!strcmp(argv[1], "all")) {
CPUWarning("traceDump: Turning trace dumping on for ALL cpus\n");
for (i = 0; i < SIM_MAXCPUS; i++) {
trace.cpuMask[i] = 1;
}
return TCL_OK;
}
if (!strcmp(argv[1],"log")) {
if (argc !=3) {
Tcl_AppendResult(interp,"'traceDump log string'. Wrong number of arguments \n",NULL);
return TCL_ERROR;
}
TraceLog(argv[2]);
return TCL_OK;
}
if (!strcmp(argv[1],"dump")) {
if (argc !=2) {
Tcl_AppendResult(interp,"'traceDump'. Wrong number of arguments \n",NULL);
return TCL_ERROR;
}
TraceDump();
return TCL_OK;
}
for (i=1; i<argc; i++) {
int cpuNum;
if ((Tcl_GetInt(interp, argv[i], &cpuNum) != TCL_OK)
|| cpuNum >= SIM_MAXCPUS ) {
Tcl_AppendResult(interp, "Bad cpu num to traceDump command",
NULL);
return TCL_ERROR;
}
trace.cpuMask[cpuNum] = 1;
CPUWarning("traceDump: Enabling trace dumping for cpu %d\n", cpuNum);
TraceLog("StartingTrace");
}
return TCL_OK;
#endif
}
void
AlphaTraceTclInit(Tcl_Interp *interp)
{
int i;
ASSERT(interp);
Tcl_CreateCommand(interp, "alphaTrace", TraceTclCmd,
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
}