iomem.c
4.46 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*************************************************************************
*
* File: iomem.c
*
* This file contains the generic routines to read/write/poll memory.
*
* $Header: /root/leakn64/depot/rf/sw/n64os20l/iosim/src/iomem.c,v 1.1.1.1 2002/05/30 05:41:20 whs Exp $
*
*/
#include <stdio.h>
#include "trace.h"
#include "iomap.h"
#include "iotest.h"
/***********************************************************************
* Routines
*/
int
MemRead(int addr, int a2, int a3, int a4)
{
unsigned int ret;
ret = IO_READ(addr);
_TRACE(DALL, fprintf(LogFp, "\n\tRead: %08x: %08x", addr, ret));
return(1);
} /* MemRead */
int
MemReadCompare(int addr, int data, int a3, int failExpected)
{
unsigned int ret;
errorCount = 0;
ret = IO_READ(addr);
if (data != ret) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* MemReadCompare */
int
MemWrite(int addr, int data, int a3, int a4)
{
IO_WRITE(addr, data);
return(1);
} /* MemWrite */
int
MemWriteRead(int addr, int data, int exp, int failExpected)
{
unsigned int ret;
errorCount = 0;
IO_WRITE(addr, data);
ret = IO_READ(addr);
if (exp != ret) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR(exp, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* MemWrite */
int
MemReadWrite(int addr1, int addr2, int a3, int a4)
{
unsigned int data;
data = IO_READ(addr1);
IO_WRITE(addr2, data);
return(1);
} /* MemWrite */
int
MemPollStatus(int addr, int bits, int cleared, int a4)
{
/* Poll a register status until the bits are either set or cleared */
int stat;
while (1) {
stat = IO_READ(addr);
_TRACE(DSTATUS, fprintf(LogFp, "\n\tStatus = 0x%08x\n",stat));
if (cleared) {
if (!(stat & bits)) break;
}
else {
if (stat & bits) break;
}
}
return(1);
} /* MemPollStatus */
int
MemCompare(int src, int dst, int nbytes, int failExpected)
{
/* Compare 'nbytes' bytes between source 'src' and destination 'dst' */
/* 'nbytes' must be even and addresses word-aligned */
int i;
unsigned int w1, w2;
errorCount = 0;
_TRACE(DCOMPARE, fprintf(LogFp,"\n\tSRC\t\t\t\tDST\n"));
src &= 0xFFFFFFFC; /* Ensure addresses are word-aligned */
dst &= 0xFFFFFFFC;
i = 0;
while (i < nbytes) {
w1 = IO_READ(src+i);
w2 = IO_READ(dst+i);
i += 4;
_TRACE(DCOMPARE, fprintf(LogFp,
"\n\t%08x: %08x\t%08x: %08x\t",
src+i, w1, dst+i, w2));
if (i > nbytes ) {
/* Here, compare the LSB 2 bytes only */
if ((w1 & 0xFFFF0000) != (w2 & 0xFFFF0000)) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR((w1 & 0xFFFF0000),
(w2 & 0xFFFF0000)));
break;
}
} else if (w1 != w2) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR(w1, w2));
break;
}
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* MemCompare */
int
MemDump(int addr, int nwords, int a3, int a4)
{
/* Dump data starting at address */
unsigned int i, d1;
addr &= 0xFFFFFFFC;
for (i = 0; i < nwords; i++) {
d1 = IO_READ((unsigned int)addr+(i*4));
_TRACE(DALL, fprintf(LogFp,"\n\t%08x: %08x", addr+(i*4), d1));
}
_TRACE(DALL, fprintf(LogFp,"\n"));
return(1);
} /* MemDump */
int
MemReadUntil(int addr, int mask, int data, int a4)
{
/* Poll a register status until the bits are either set or cleared */
int rdata;
while (1) {
rdata = IO_READ(addr);
_TRACE(DSTATUS, fprintf(LogFp, "\n\tData = 0x%08x\n", rdata));
if ((rdata & mask) == (data & mask)) break;
}
return(1);
} /* MemReadUntil */
int
MemReadCompMask(int addr, int data, int mask, int failExpected)
{
unsigned int ret;
errorCount = 0;
ret = IO_READ(addr);
if ((data & mask) != (ret & mask)) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* MemReadCompMask */
int
MemReadCompMaskNoError(int addr, int data, int mask, int failExpected)
{
unsigned int ret;
errorCount = 0;
ret = IO_READ(addr);
if ((data & mask) != (ret & mask)) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
return((errorCount == 0) ? 0 : -1);
} /* MemReadCompMaskNoError */