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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [hwtests/] [tlbtest/] [main.c] - Blame information for rev 14

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

Line No. Rev Author Line
1 14 hellwig
/*
2
 * main.c -- the main program
3
 */
4
 
5
 
6
#include "common.h"
7
#include "lib.h"
8
#include "start.h"
9
 
10
 
11
#define NUM_ENTRIES     32
12
#define NUM_FIXED       4
13
 
14
 
15
struct {
16
  Word hi;
17
  Word lo;
18
} randomEntries[NUM_ENTRIES] = {
19
  { 0x25FACEE3, 0x8ACF75B6 },
20
  { 0xCCDC1C4C, 0x524499EF },
21
  { 0x81CB5C0B, 0x7E098E5D },
22
  { 0xEB6F7F76, 0xAAA301DB },
23
  { 0x6FB1A2B8, 0x4E206502 },
24
  { 0x7FE39DFD, 0x3E74D858 },
25
  { 0x0422E083, 0x73B2D23A },
26
  { 0x71144B0A, 0xE623F4AF },
27
  { 0x5AAED767, 0xC34BEB52 },
28
  { 0x35A8D36A, 0x8E584748 },
29
  { 0x41B6B347, 0x544A9B0D },
30
  { 0x039AED34, 0x6927DF69 },
31
  { 0x3E3EEC16, 0xF7585602 },
32
  { 0x339AC351, 0xDD43F704 },
33
  { 0xA14C0101, 0x81FC5D62 },
34
  { 0x5B522D47, 0x9BC2EF2D },
35
  { 0x61235741, 0x67377AE9 },
36
  { 0x45BDFCA7, 0x4CDBDCF1 },
37
  { 0x2E044D77, 0xF70E7CE1 },
38
  { 0x33FC4126, 0x18B3D47C },
39
  { 0xF5F3CBEA, 0x9583DCC8 },
40
  { 0xA6B7454B, 0x887C5270 },
41
  { 0xED805C94, 0x9A6D6F8F },
42
  { 0xF27359EC, 0x2FC185D8 },
43
  { 0x0DDD34A3, 0x47B5D83A },
44
  { 0xEFDB299A, 0xC784294A },
45
  { 0x17A4E2F6, 0x5EAEFA99 },
46
  { 0x6EE1B054, 0xD716C16C },
47
  { 0xA34AF381, 0x8F775888 },
48
  { 0x2F48D37B, 0x46D72169 },
49
  { 0x97FC2065, 0xC3685619 },
50
  { 0x48B21FA3, 0x976B4EFB },
51
};
52
 
53
 
54
struct {
55
  Word hi;
56
  Word lo;
57
} mappingEntries[NUM_ENTRIES] = {
58
  { 0x00006000, 0x000F8001 },
59
  { 0x00017000, 0x00099001 },
60
  { 0x00004000, 0x0001A001 },
61
  { 0x0000D000, 0x000DB001 },
62
  { 0x00012000, 0x0009C001 },
63
  { 0x00013000, 0x0007D001 },
64
  { 0x00010000, 0x0001E001 },
65
  { 0x00009000, 0x0009F001 },
66
  { 0x0001E000, 0x00000001 },
67
  { 0x0000F000, 0x00021001 },
68
  { 0x0001C000, 0x000E2001 },
69
  { 0x00005000, 0x00023001 },
70
  { 0x0000A000, 0x000C4001 },
71
  { 0x0000B000, 0x00085001 },
72
  { 0x00008000, 0x00006001 },
73
  { 0x00001000, 0x00067001 },
74
  { 0x00016000, 0x000A8001 },
75
  { 0x00007000, 0x000A9001 },
76
  { 0x00014000, 0x0004A001 },
77
  { 0x0001D000, 0x0004B001 },
78
  { 0x00002000, 0x000EC001 },
79
  { 0x00003000, 0x0008D001 },
80
  { 0x00000000, 0x000EE001 },
81
  { 0x00019000, 0x0000F001 },
82
  { 0x0000E000, 0x00050001 },
83
  { 0x0001F000, 0x00011001 },
84
  { 0x0000C000, 0x000B2001 },
85
  { 0x00015000, 0x00093001 },
86
  { 0x0001A000, 0x00074001 },
87
  { 0x0001B000, 0x00075001 },
88
  { 0x00018000, 0x00036001 },
89
  { 0x00011000, 0x000D7001 },
90
};
91
 
92
 
93
void flushTLB(void) {
94
  unsigned int invalPage;
95
  int i;
96
 
97
  invalPage = 0xC0000000;
98
  for (i = 0; i < NUM_ENTRIES; i++) {
99
    setTLB(i, invalPage, 0);
100
    invalPage += (1 << 12);
101
  }
102
}
103
 
104
 
105
int countTLB(void) {
106
  int i;
107
  int n;
108
  Word hi;
109
 
110
  n = 0;
111
  for (i = 0; i < NUM_ENTRIES; i++) {
112
    hi = getTLB_HI(i);
113
    if ((hi & 0xC0000000) != 0xC0000000) {
114
      n++;
115
    }
116
  }
117
  return n;
118
}
119
 
120
 
121
/**************************************************************/
122
 
123
 
124
void indexedReadWriteTest(void) {
125
  int i;
126
  Word hi, lo;
127
  Bool fail;
128
 
129
  printf("Indexed R/W test\t\t");
130
  for (i = 0; i < NUM_ENTRIES; i++) {
131
    setTLB(i, randomEntries[i].hi, randomEntries[i].lo);
132
  }
133
  fail = false;
134
  for (i = 0; i < NUM_ENTRIES; i++) {
135
    hi = getTLB_HI(i);
136
    lo = getTLB_LO(i);
137
    if ((hi & 0xFFFFF000) != (randomEntries[i].hi & 0xFFFFF000) ||
138
        (lo & 0x3FFFF003) != (randomEntries[i].lo & 0x3FFFF003)) {
139
      fail = true;
140
    }
141
  }
142
  if (fail) {
143
    printf("failed\n");
144
  } else {
145
    printf("ok\n");
146
  }
147
}
148
 
149
 
150
void writeRandomTest(void) {
151
  int i;
152
  int n;
153
  int i04, i08, i12, i16;
154
  int i20, i24, i28;
155
 
156
  printf("Write random test\n");
157
  flushTLB();
158
  i04 = 0;
159
  i08 = 0;
160
  i12 = 0;
161
  i16 = 0;
162
  i20 = 0;
163
  i24 = 0;
164
  i28 = 0;
165
  for (i = 1; i <= 100 * NUM_ENTRIES; i++) {
166
    wrtRndTLB(i << 12, i << 12);
167
    n = countTLB();
168
    if (n == 4 && i04 == 0) {
169
      i04 = i;
170
    }
171
    if (n == 8 && i08 == 0) {
172
      i08 = i;
173
    }
174
    if (n == 12 && i12 == 0) {
175
      i12 = i;
176
    }
177
    if (n == 16 && i16 == 0) {
178
      i16 = i;
179
    }
180
    if (n == 20 && i20 == 0) {
181
      i20 = i;
182
    }
183
    if (n == 24 && i24 == 0) {
184
      i24 = i;
185
    }
186
    if (n == 28 && i28 == 0) {
187
      i28 = i;
188
    }
189
    wait(randomEntries[i % NUM_ENTRIES].hi & 0xFF);
190
  }
191
  if (i04 > 0) {
192
    printf("     4 entries filled after %3d random writes\n", i04);
193
  } else {
194
    printf("     4 entries never filled\n");
195
  }
196
  if (i08 > 0) {
197
    printf("     8 entries filled after %3d random writes\n", i08);
198
  } else {
199
    printf("     8 entries never filled\n");
200
  }
201
  if (i12 > 0) {
202
    printf("    12 entries filled after %3d random writes\n", i12);
203
  } else {
204
    printf("    12 entries never filled\n");
205
  }
206
  if (i16 > 0) {
207
    printf("    16 entries filled after %3d random writes\n", i16);
208
  } else {
209
    printf("    16 entries never filled\n");
210
  }
211
  if (i20 > 0) {
212
    printf("    20 entries filled after %3d random writes\n", i20);
213
  } else {
214
    printf("    20 entries never filled\n");
215
  }
216
  if (i24 > 0) {
217
    printf("    24 entries filled after %3d random writes\n", i24);
218
  } else {
219
    printf("    24 entries never filled\n");
220
  }
221
  if (i28 > 0) {
222
    printf("    28 entries filled after %3d random writes\n", i28);
223
  } else {
224
    printf("    28 entries never filled\n");
225
  }
226
}
227
 
228
 
229
void searchTest(void) {
230
  int i;
231
  Word index;
232
  Bool fail;
233
 
234
  printf("Search test\t\t\t");
235
  for (i = 0; i < NUM_ENTRIES; i++) {
236
    setTLB(i, randomEntries[i].hi, randomEntries[i].lo);
237
  }
238
  fail = false;
239
  for (i = 0; i < NUM_ENTRIES; i++) {
240
    index = probeTLB(randomEntries[i].hi);
241
    if (index != i) {
242
      fail = true;
243
    }
244
  }
245
  index = probeTLB(0xDEADBEEF);
246
  if ((index & 0x80000000) == 0) {
247
    fail = true;
248
  }
249
  if (fail) {
250
    printf("failed\n");
251
  } else {
252
    printf("ok\n");
253
  }
254
}
255
 
256
 
257
void mapTest(void) {
258
  int i;
259
  Word page, offset;
260
  Word virt;
261
  int index;
262
  Word frame;
263
  Word phys;
264
  Word cont;
265
  Bool fail;
266
 
267
  printf("Map test\t\t\t");
268
  /* preset each memory word (below 1M) with its physical address */
269
  for (i = 0; i < 0x100000; i += 4) {
270
    *(Word *)(0xC0000000 | i) = i;
271
  }
272
  /* preset TLB */
273
  for (i = 0; i < NUM_ENTRIES; i++) {
274
    setTLB(i, mappingEntries[i].hi, mappingEntries[i].lo);
275
  }
276
  /* now access memory and check if addresses are mapped correctly */
277
  fail = false;
278
  page = 7;
279
  offset = 0x123;
280
  for (i = 0; i < 100000; i++) {
281
    /* compute pseudo-random virtual word address (page number 0..31) */
282
    page = (page * 13 + 1) & 0x1F;
283
    offset = (offset * 109) & 0x00000FFF;
284
    virt = (page << 12) | (offset & ~0x3);
285
    /* lookup frame number in TLB and construct physical word address */
286
    index = probeTLB(virt);
287
    if (index & 0x80000000) {
288
      fail = true;
289
      break;
290
    }
291
    frame = getTLB_LO(index) & 0xFFFFF000;
292
    phys = frame | (offset & ~0x3);
293
    /* access memory by dereferencing the virtual address */
294
    cont = *(Word *)virt;
295
    /* word read should equal physical address */
296
    if (cont != phys) {
297
      fail = true;
298
    }
299
  }
300
  if (fail) {
301
    printf("failed\n");
302
  } else {
303
    printf("ok\n");
304
  }
305
}
306
 
307
 
308
/**************************************************************/
309
 
310
 
311
int main(void) {
312
  printf("\nStart of TLB tests.\n\n");
313
  indexedReadWriteTest();
314
  writeRandomTest();
315
  searchTest();
316
  mapTest();
317
  printf("\nEnd of TLB tests.\n");
318
  while (1) ;
319
  return 0;
320
}

powered by: WebSVN 2.1.0

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