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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [testbench/] [mc_common.c] - Blame information for rev 1777

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

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

powered by: WebSVN 2.1.0

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