OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [sim/] [trace.c] - Blame information for rev 299

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 275 hellwig
/*
2
 * trace.c -- trace buffer
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include <setjmp.h>
10
 
11
#include "common.h"
12
#include "console.h"
13
#include "error.h"
14
#include "except.h"
15
#include "disasm.h"
16
#include "trace.h"
17
 
18
 
19
#define TRACE_EMPTY             0
20
#define TRACE_FETCH             1
21
#define TRACE_EXEC              2
22
#define TRACE_LOAD_WORD         3
23
#define TRACE_LOAD_HALF         4
24
#define TRACE_LOAD_BYTE         5
25
#define TRACE_STORE_WORD        6
26
#define TRACE_STORE_HALF        7
27
#define TRACE_STORE_BYTE        8
28
#define TRACE_EXCEPTION         9
29
 
30
 
31
typedef struct {
32
  unsigned char type;
33
  Word data1;
34
  Word data2;
35
} TraceEntry;
36
 
37
 
38
static TraceEntry traceBuffer[TRACE_BUF_SIZE];
39
static int nextWrite;
40
 
41
 
42
/**************************************************************/
43
 
44
 
45
void traceFetch(Word pc) {
46
  traceBuffer[nextWrite].type = TRACE_FETCH;
47
  traceBuffer[nextWrite].data1 = pc;
48
  nextWrite = (nextWrite + 1) & TRACE_BUF_MASK;
49
}
50
 
51
 
52
void traceExec(Word instr, Word locus) {
53
  traceBuffer[nextWrite].type = TRACE_EXEC;
54
  traceBuffer[nextWrite].data1 = instr;
55
  traceBuffer[nextWrite].data2 = locus;
56
  nextWrite = (nextWrite + 1) & TRACE_BUF_MASK;
57
}
58
 
59
 
60
void traceLoadWord(Word addr) {
61
  traceBuffer[nextWrite].type = TRACE_LOAD_WORD;
62
  traceBuffer[nextWrite].data1 = addr;
63
  nextWrite = (nextWrite + 1) & TRACE_BUF_MASK;
64
}
65
 
66
 
67
void traceLoadHalf(Word addr) {
68
  traceBuffer[nextWrite].type = TRACE_LOAD_HALF;
69
  traceBuffer[nextWrite].data1 = addr;
70
  nextWrite = (nextWrite + 1) & TRACE_BUF_MASK;
71
}
72
 
73
 
74
void traceLoadByte(Word addr) {
75
  traceBuffer[nextWrite].type = TRACE_LOAD_BYTE;
76
  traceBuffer[nextWrite].data1 = addr;
77
  nextWrite = (nextWrite + 1) & TRACE_BUF_MASK;
78
}
79
 
80
 
81
void traceStoreWord(Word addr) {
82
  traceBuffer[nextWrite].type = TRACE_STORE_WORD;
83
  traceBuffer[nextWrite].data1 = addr;
84
  nextWrite = (nextWrite + 1) & TRACE_BUF_MASK;
85
}
86
 
87
 
88
void traceStoreHalf(Word addr) {
89
  traceBuffer[nextWrite].type = TRACE_STORE_HALF;
90
  traceBuffer[nextWrite].data1 = addr;
91
  nextWrite = (nextWrite + 1) & TRACE_BUF_MASK;
92
}
93
 
94
 
95
void traceStoreByte(Word addr) {
96
  traceBuffer[nextWrite].type = TRACE_STORE_BYTE;
97
  traceBuffer[nextWrite].data1 = addr;
98
  nextWrite = (nextWrite + 1) & TRACE_BUF_MASK;
99
}
100
 
101
 
102
void traceException(Word priority) {
103
  traceBuffer[nextWrite].type = TRACE_EXCEPTION;
104
  traceBuffer[nextWrite].data1 = priority;
105
  nextWrite = (nextWrite + 1) & TRACE_BUF_MASK;
106
}
107
 
108
 
109
char *traceShow(int back) {
110
  static char answer[100];
111
  int index;
112
 
113
  if (back < 1 || back > TRACE_BUF_SIZE) {
114
    return NULL;
115
  }
116
  index = (nextWrite - back) & TRACE_BUF_MASK;
117
  switch (traceBuffer[index].type) {
118
    case TRACE_EMPTY:
119
      sprintf(answer, "-- empty --");
120
      break;
121
    case TRACE_FETCH:
122
      sprintf(answer, "instr fetch, addr = %08X",
123
              traceBuffer[index].data1);
124
      break;
125
    case TRACE_EXEC:
126
      sprintf(answer, "instr exec, instr = %08X    %s",
127
              traceBuffer[index].data1,
128
              disasm(traceBuffer[index].data1,
129
                     traceBuffer[index].data2));
130
      break;
131
    case TRACE_LOAD_WORD:
132
      sprintf(answer, "load word, addr   = %08X",
133
              traceBuffer[index].data1);
134
      break;
135
    case TRACE_LOAD_HALF:
136
      sprintf(answer, "load half, addr   = %08X",
137
              traceBuffer[index].data1);
138
      break;
139
    case TRACE_LOAD_BYTE:
140
      sprintf(answer, "load byte, addr   = %08X",
141
              traceBuffer[index].data1);
142
      break;
143
    case TRACE_STORE_WORD:
144
      sprintf(answer, "store word, addr  = %08X",
145
              traceBuffer[index].data1);
146
      break;
147
    case TRACE_STORE_HALF:
148
      sprintf(answer, "store half, addr  = %08X",
149
              traceBuffer[index].data1);
150
      break;
151
    case TRACE_STORE_BYTE:
152
      sprintf(answer, "store byte, addr  = %08X",
153
              traceBuffer[index].data1);
154
      break;
155
    case TRACE_EXCEPTION:
156
      sprintf(answer, "****  exception %2d (%s)  ****",
157
              traceBuffer[index].data1,
158
              exceptionToString(traceBuffer[index].data1));
159
      break;
160
    default:
161
      error("unknown trace buffer entry");
162
  }
163
  return answer;
164
}
165
 
166
 
167
/**************************************************************/
168
 
169
 
170
void traceReset(void) {
171
  int i;
172
 
173
  cPrintf("Resetting Trace Buffer...\n");
174
  for (i = 0; i < TRACE_BUF_SIZE; i++) {
175
    traceBuffer[i].type = TRACE_EMPTY;
176
  }
177
  nextWrite = 0;
178
}
179
 
180
 
181
void traceInit(void) {
182
  traceReset();
183
}
184
 
185
 
186
void traceExit(void) {
187
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.