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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [mc-common/] [mc-common.c] - Blame information for rev 132

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

Line No. Rev Author Line
1 90 jeremybenn
/* mc_common.c -- Memory Controller testbenck common routines
2
 
3
   Copyright (C) 2001 Ivan Guzvinec
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributor Ivan Guzvinec <ivang@opencores.org>
7
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
   This file is part of OpenRISC 1000 Architectural Simulator.
10
 
11
   This program is free software; you can redistribute it and/or modify it
12
   under the terms of the GNU General Public License as published by the Free
13
   Software Foundation; either version 3 of the License, or (at your option)
14
   any later version.
15
 
16
   This program is distributed in the hope that it will be useful, but WITHOUT
17
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
   more details.
20
 
21
   You should have received a copy of the GNU General Public License along
22
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
23
 
24
/* ----------------------------------------------------------------------------
25
   This code is commented throughout for use with Doxygen.
26
   --------------------------------------------------------------------------*/
27
 
28
#include "support.h"
29
#include "mc-common.h"
30
 
31
static int r_Xn;
32
static int r_mod;
33
 
34
void randomin(unsigned long seed)
35
{
36
  r_Xn = seed;
37
  r_mod = 33554431; /* 2^25 - 1*/
38
}
39
 
40
unsigned long random(unsigned long max)
41
{
42
  r_Xn = ((r_Xn * (r_Xn + 1))%r_mod);
43
  if (r_Xn == 0) r_Xn = 42+1;
44
  return r_Xn%max;
45
}
46
 
47
void mc_clear_row(unsigned long nFrom, unsigned long nTo)
48
{
49
  MEMLOC32 mem32 = 0;
50
  unsigned long i;
51
 
52
  for(i=nFrom; i<nTo; i+=4) {
53
    mem32  = (unsigned long*)i;
54
    *mem32 = 0UL;
55
  }
56
}
57
 
58
unsigned long mc_test_row_8(int run, int seq, unsigned long nFrom,
59
                            unsigned long nTo)
60
{
61
    MEMLOC8  mem8  = 0;
62
    MEMLOC16 mem16 = 0;
63
    MEMLOC32 mem32 = 0;
64
 
65
    unsigned char pattern    = 0;
66
    unsigned short pattern16 = 0;
67
    unsigned long pattern32  = 0;
68
    unsigned char read;
69
    unsigned short read16;
70
    unsigned long read32;
71
    int inc = 0;
72
 
73
    unsigned long i;
74
 
75
    /* number of locations to test */
76
    unsigned long nWords = nTo - nFrom;
77
 
78
    /* JPB. Switch split due to bug in GCC with PIC and larger switches */
79
    switch (run) {
80
    case 0:
81
        pattern = MC_TEST_PAT1_8;
82
        pattern16 = (pattern << 8);
83
        pattern32 = (pattern16 << 16); break;
84
    case 1:
85
        pattern = MC_TEST_PAT2_8;
86
        pattern16 = (pattern << 8);
87
        pattern32 = (pattern16 << 16); break;
88
    case 2:
89
        pattern = MC_TEST_PAT3_8;
90
        pattern16 = (pattern << 8);
91
        pattern32 = (pattern16 << 16); break;
92
    } /*switch*/
93
 
94
    switch (run) {
95
    case 3:
96
        pattern = MC_TEST_PAT4_8;
97
        pattern16 = (pattern << 8);
98
        pattern32 = (pattern16 << 16); break;
99
    case 4:
100
        pattern32 = pattern16 = pattern = 0; inc = 1; break;
101
    } /*switch*/
102
 
103
    printf ("\tmc_test_row_8(0x%02dX, %d, 0x%08lX, 0x%08lX);\n", pattern, seq,
104
            nFrom, nTo);
105
 
106
    switch (seq) {
107
    case 0: /*seq. row write, row read*/
108
        for (i=nFrom; i<nTo; i++) {
109
            mem8  = (unsigned char*)i;
110
            *mem8 = pattern;
111
            if (inc) pattern++;
112
        } /*for*/
113
 
114
        if (inc) pattern = 0;
115
        for (i=nFrom; i<nTo; i++) {
116
            mem8 = (unsigned char*)i;
117
            read = *mem8;
118
 
119
            if ( read != pattern ) {
120
                printf("\ti=%lX, read=0x%02dX, pattern=0x%02dX\n", i, read,
121
                       pattern);
122
                return (unsigned long)mem8;
123
            }
124
 
125
            if (inc) pattern++;
126
        } /*for*/
127
        break;
128
    case 1: /*seq. word write, word read*/
129
        for (i=nFrom; i<nTo; i++) {
130
            mem8  = (unsigned char*)i;
131
            *mem8 = pattern;
132
            read = *mem8;
133
 
134
            if (read != pattern ) {
135
                printf("\ti=%lX, read=0x%02dX, pattern=0x%02dX\n", i, read,
136
                       pattern);
137
                return (unsigned long)mem8;
138
            }
139
 
140
            mem16  = (unsigned short*)(i & 0xFFFFFFFELU);
141
            read16 = *mem16;
142
            if (read16 != pattern16) {
143
                printf("\ti=%lX, read16=0x%04dX, pattern16=0x%04dX\n", i,
144
                       read16, pattern16);
145
                return (unsigned long)mem16;
146
            }
147
            mem32  = (unsigned long*)(i & 0xFFFFFFFCLU);
148
            read32 = *mem32;
149
            if (read32 != pattern32) {
150
                printf("\ti=%lX, read32=0x%08lX, pattern32=0x%08lX\n", i,
151
                       read32, pattern32);
152
                return (unsigned long)mem32;
153
            }
154
 
155
            if (inc) pattern++;
156
            switch ((i+1)%4) {
157
            case 0:
158
                pattern16 = (pattern << 8);
159
                pattern32 = (pattern << 24); break;
160
            case 1:
161
                pattern16 += pattern;
162
                pattern32 = pattern16 << 16; break;
163
            case 2:
164
                pattern16 = (pattern << 8);
165
                pattern32 += pattern16;break;
166
            case 3:
167
                pattern16 += pattern;
168
                pattern32 += pattern; break;
169
            } /*switch i%4*/
170
        } /*for*/
171
        break;
172
    case 2: /*rand. word write, word read*/
173
        for (i=0; i<nWords; i++) {
174
            mem8  = (unsigned char*)(nFrom + random(nWords));
175
            *mem8 = pattern;
176
            read  = *mem8;
177
 
178
            if (read != pattern ) {
179
                printf("\ti=%lX, read=0x%02dX, pattern=0x%02dX\n", i, read,
180
                       pattern);
181
                return (unsigned long)mem8;
182
            }
183
 
184
            if (inc) pattern++;
185
        }
186
        break;
187
    } /*switch seq*/
188
 
189
    return 0;
190
} /* mc_test_row_8 */
191
 
192
unsigned long mc_test_row_16(int run, int seq, unsigned long nFrom,
193
                             unsigned long nTo)
194
{
195
    MEMLOC16 mem16 = 0;
196
    MEMLOC32 mem32 = 0;
197
 
198
    unsigned short pattern16 = 0;
199
    unsigned long pattern32  = 0;
200
    unsigned short read16;
201
    unsigned long read32;
202
    int inc = 0;
203
 
204
    unsigned long i;
205
 
206
    unsigned long nWords = (nTo - nFrom)/2;
207
 
208
    /* JPB. Switch split due to bug in GCC with PIC and larger switches */
209
    switch (run) {
210
    case 0:
211
        pattern16 = MC_TEST_PAT1_16;
212
        pattern32 = (pattern16 << 16); break;
213
    case 1:
214
        pattern16 = MC_TEST_PAT2_16;
215
        pattern32 = (pattern16 << 16); break;
216
    case 2:
217
        pattern16 = MC_TEST_PAT3_16;
218
        pattern32 = (pattern16 << 16);break;
219
    } /*switch*/
220
 
221
    switch (run) {
222
    case 3:
223
        pattern16 = MC_TEST_PAT4_16;
224
        pattern32 = (pattern16 << 16); break;
225
    case 4:
226
        pattern16 = pattern32 = 0; inc = 1; break;
227
    } /*switch*/
228
 
229
    printf ("\tmc_test_row_16(0x%04dX, %d, 0x%08lX, 0x%08lX);\n", pattern16,
230
            seq, nFrom, nTo);
231
 
232
    switch (seq) {
233
    case 0: /*seq. row write, row read*/
234
        for (i=nFrom; i<nTo; i+=2) {
235
            mem16  = (unsigned short*)i;
236
            *mem16 = pattern16;
237
            if (inc) pattern16++;
238
        } /*for*/
239
 
240
        if (inc) pattern16 = 0;
241
        for (i=nFrom; i<nTo; i+=2) {
242
            mem16  = (unsigned short*)i;
243
            read16 = *mem16;
244
 
245
            if ( read16 != pattern16 ) {
246
                printf("\ti=%lX, read16=0x%04dX, pattern16=0x%04dX\n", i,
247
                       read16, pattern16);
248
                return (unsigned long)mem16;
249
            }
250
 
251
            if (inc) pattern16++;
252
        } /*for*/
253
        break;
254
    case 1: /*seq. word write, word read*/
255
        for (i=nFrom; i<nTo; i+=2) {
256
            mem16  = (unsigned short*)i;
257
            *mem16 = pattern16;
258
            read16 = *mem16;
259
 
260
            if (read16 != pattern16 ) {
261
                printf("\ti=%lX, read16=0x%04dX, pattern16=0x%04dX\n", i,
262
                       read16, pattern16);
263
                return (unsigned long)mem16;
264
            }
265
 
266
            mem32  = (unsigned long*)(i & 0xFFFFFFFCLU);
267
            read32 = *mem32;
268
            if (read32 != pattern32) {
269
                printf("\ti=%lX, read32=0x%08lX, pattern32=0x%08lX\n", i,
270
                       read32, pattern32);
271
                return (unsigned long)mem32;
272
            }
273
 
274
            if (inc) pattern16++;
275
            switch ((i+2)%4) {
276
            case 0:
277
                pattern32 = (pattern16 << 16); break;
278
            case 2:
279
                pattern32 += pattern16;
280
            } /*switch i%4*/
281
        } /*for*/
282
        break;
283
    case 2: /*rand. word write, word read*/
284
        for (i=0; i<nWords; i++) {
285
            mem16  = (unsigned short*)(nFrom + random(nWords)*2);
286
            *mem16 = pattern16;
287
            read16 = *mem16;
288
 
289
            if (read16 != pattern16 ) {
290
                printf("\ti=%lX, read16=0x%04dX, pattern16=0x%04dX\n", i,
291
                       read16, pattern16);
292
                return (unsigned long)mem16;
293
            }
294
 
295
            if (inc) pattern16++;
296
        }
297
        break;
298
    } /*switch seq*/
299
    return 0;
300
} /* mc_test_row_16 */
301
 
302
unsigned long mc_test_row_32(int run, int seq, unsigned long nFrom,
303
                             unsigned long nTo)
304
{
305
    MEMLOC32 mem32 = 0;
306
 
307
    unsigned long pattern32 = 0;
308
    unsigned long read32;
309
    int inc = 0;
310
 
311
    unsigned long i;
312
 
313
    unsigned long nWords = (nTo - nFrom)/4;
314
 
315
    /* JPB. Switch split due to bug in GCC with PIC and larger switches */
316
    switch (run) {
317
    case 0:
318
        pattern32 = MC_TEST_PAT1_32; break;
319
    case 1:
320
        pattern32 = MC_TEST_PAT2_32; break;
321
    case 2:
322
        pattern32 = MC_TEST_PAT3_32; break;
323
    } /*switch*/
324
 
325
    switch (run) {
326
    case 3:
327
        pattern32 = MC_TEST_PAT4_32; break;
328
    case 4:
329
        pattern32 = nFrom; inc = 1; break;
330
    } /*switch*/
331
 
332
    printf ("\tmc_test_row_32(0x%08lX, %d, 0x%08lX, 0x%08lX);\n", pattern32,
333
            seq, nFrom, nTo);
334
 
335
    switch (seq) {
336
    case 0: /*seq. row write, row read*/
337
        for (i=nFrom; i<nTo; i+=4) {
338
            mem32  = (unsigned long*)i;
339
            *mem32 = pattern32;
340
            if (inc) pattern32 += 4;
341
        } /*for*/
342
 
343
        if (inc) pattern32 = nFrom;
344
        for (i=nFrom; i<nTo; i+=4) {
345
            mem32 = (unsigned long *)i;
346
            read32 = *mem32;
347
 
348
            if ( read32 != pattern32 ) {
349
                printf("\ti=%lX, read32=0x%08lX, pattern32=0x%08lX\n", i,
350
                       read32, pattern32);
351
                return (unsigned long)mem32;
352
            }
353
 
354
            if (inc) pattern32 += 4;
355
        } /*for*/
356
        break;
357
    case 1: /*seq. word write, word read*/
358
        for (i=nFrom; i<nTo; i+=4) {
359
            mem32  = (unsigned long*)i;
360
            *mem32 = pattern32;
361
            read32 = *mem32;
362
 
363
            if (read32 != pattern32 ) {
364
                printf("\ti=%lX, read32=0x%08lX, pattern32=0x%08lX\n", i,
365
                       read32, pattern32);
366
                return (unsigned long)mem32;
367
            }
368
 
369
            if (inc) pattern32 += 4;
370
 
371
        }
372
        break;
373
    case 2: /*rand. word write, word read*/
374
        for (i=0; i<nWords; i++) {
375
            mem32 = (unsigned long*)(nFrom + random(nWords)*4);
376
            if (inc)
377
                pattern32 = (unsigned long)mem32;
378
            *mem32 = pattern32;
379
            read32  = *mem32;
380
 
381
            if (read32 != pattern32 ) {
382
                printf("\ti=%lX, read32=0x%08lX, pattern32=0x%08lX\n", i,
383
                       read32, pattern32);
384
                return (unsigned long)mem32;
385
            }
386
        } /*for*/
387
        break;
388
    } /*switch seq*/
389
    return 0;
390
} /* mc_test_row_32 */
391
 
392
 
393
/*---------------------------------------------------------------------------*/
394
 
395
 
396
/*-----[ Common Functions ]--------------------------------------------------*/
397
unsigned long mc_test_row(unsigned long nFrom, unsigned long nTo,
398
                          unsigned long flags)
399
{
400
    int nRun, nSize, nSeq;
401
    int ret = 0;
402
 
403
    printf("\nmc_test_row(0x%08lX, 0x%08lX)\n", nFrom, nTo);
404
 
405
    for (nRun = 0; nRun < 5; nRun++) {
406
      /* JPB. Switch split due to bug in GCC with PIC and larger switches */
407
        switch (nRun) {
408
        case 0:
409
            if ( (flags & MC_TEST_RUN0) != MC_TEST_RUN0 )
410
                continue;
411
            break;
412
        case 1:
413
            if ( (flags & MC_TEST_RUN1) != MC_TEST_RUN1 )
414
                continue;
415
            break;
416
        case 2:
417
            if ( (flags & MC_TEST_RUN01) != MC_TEST_RUN01 )
418
                continue;
419
            break;
420
        } /*switch*/
421
 
422
        switch (nRun) {
423
        case 3:
424
            if ( (flags & MC_TEST_RUN10) != MC_TEST_RUN10 )
425
                continue;
426
            break;
427
        case 4:
428
            if ( (flags & MC_TEST_RUNINC) != MC_TEST_RUNINC )
429
                continue;
430
        } /*switch*/
431
 
432
        for (nSeq = 0; nSeq < 3; nSeq++) {
433
            switch (nSeq) {
434
            case 0:
435
                if ( (flags & MC_TEST_SEQ) != MC_TEST_SEQ )
436
                    continue;
437
                break;
438
            case 1:
439
                if ( (flags & MC_TEST_SEQ1) != MC_TEST_SEQ1 )
440
                    continue;
441
                break;
442
            case 2:
443
              if ( (flags & MC_TEST_RAND) != MC_TEST_RAND )
444
                    continue;
445
            } /*switch*/
446
 
447
            for (nSize = 0; nSize < 3; nSize++) {
448
                switch (nSize) {
449
                case 0:
450
                    if ( (flags & MC_TEST_8) != MC_TEST_8 )
451
                        continue;
452
                    ret = mc_test_row_8(nRun, nSeq, nFrom, nTo);
453
                    break;
454
                case 1:
455
                    if ( (flags & MC_TEST_16) != MC_TEST_16)
456
                        continue;
457
                    ret = mc_test_row_16(nRun, nSeq, nFrom, nTo);
458
                    break;
459
                case 2:
460
                    if ( (flags & MC_TEST_32) != MC_TEST_32)
461
                        continue;
462
                    ret = mc_test_row_32(nRun, nSeq, nFrom, nTo);
463
                } /*switch*/
464
 
465
                if (ret) return ret;
466
                mc_clear_row(nFrom, nTo);
467
            } /*for nSize*/
468
        } /*for nSeq*/
469
        /*report(0xDEADDEAD);*/
470
    } /*for nRun*/
471
 
472
    return 0;
473
} /* mc_test_row */

powered by: WebSVN 2.1.0

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