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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [or1200/] [sim/] [or1200-dctest.c] - Blame information for rev 393

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

Line No. Rev Author Line
1 349 julius
/*
2
 * OR1200 Data cache test
3
 * Writes and checks various values in places to exercise data cache line
4
 * swaps.
5
 *
6
 * Change LOOPS define to alter length of test (2048 is OK size)
7
 */
8
 
9
 
10 393 julius
#include "cpu-utils.h"
11
#include "lib-utils.h"
12 349 julius
#include "spr-defs.h"
13
 
14
#define LOOPS 64
15
#define WORD_STRIDE 8
16
 
17
 
18
 
19
unsigned long int my_lfsr;
20
 
21
unsigned long int next_rand()
22
{
23
  my_lfsr = (my_lfsr >> 1) ^ (unsigned long int)((0 - (my_lfsr & 1u)) & 0xd0000001u);
24
  return my_lfsr;
25
}
26
 
27
int
28
main()
29
{
30
 
31
  // Check data cache is present and enabled
32
  if (!(mfspr(SPR_UPR)& SPR_UPR_DCP))
33
    return 0x8000000d;
34
 
35
  if (!(mfspr(SPR_SR) & SPR_SR_DCE))
36
    return 0x8000000d;
37
 
38
  volatile char* ptr = (volatile char*) 0xe00000;
39
  int i;
40
 
41
  ptr[0] = 0xab;
42
 
43
  ptr[4096] = 0xcd;
44
 
45
  ptr[8192] = 0xef;
46
 
47
  report(ptr[0]);
48
 
49
  report(ptr[4096]);
50
 
51
  report(ptr[8192]);
52
 
53
  // If cache is write back, then test flush and writeback functionalities
54
  // Check cache write stategy bit (CWS) for write back
55
  if (mfspr(SPR_DCCFGR) & SPR_DCCFGR_CWS)
56
    {
57
      // TODO: Check flush and write back actually work by mapping the same
58
      // space as CI through DMMU. For now the following will aid checking on
59
      // waveform.
60
      volatile int * test_addr = (int *) 0xefaa10;
61
 
62
      // Fill some lines with data
63
      for (i=0;i<64;i++)
64
        test_addr[i] = 1+(i<<i)/(i+1);
65
 
66
      // Flush the lines
67
      int spr_addr = SPR_DCBFR;
68
 
69
      for (i=0;i<16;i++)
70
        asm("l.mtspr\t\t%0,%1,0": : "r" (spr_addr), "r" (test_addr+(i*4)));
71
 
72
      // Check the data
73
      for (i=0;i<64;i++)
74
        if (test_addr[i] != (1+(i<<i)/(i+1)))
75
          return i;
76
 
77
      // Fill some lines with data
78
      for (i=0;i<64;i++)
79
        test_addr[i] = ~i;
80
 
81
      // Force writeback of the lines
82
      spr_addr = SPR_DCBWR;
83
 
84
      for (i=0;i<16;i++)
85
        asm("l.mtspr\t\t%0,%1,0": : "r" (spr_addr), "r" (test_addr+(i*4)));
86
 
87
      // Check the data
88
      for (i=0;i<64;i++)
89
        if (test_addr[i] != ~i)
90
          return ~i;
91
 
92
 
93
    }
94
 
95
  // Now generate some random numbers, write them in in strides that should 
96
  // execercise the cache's line reloading/storing mechanism.
97
 
98
  // init LFSR
99
  my_lfsr = RAND_LFSR_SEED;
100
  volatile unsigned long int *lptr = (volatile unsigned long int*) 0xa00000;
101
  for(i=0;i<LOOPS;i++)
102
    {
103
      lptr[(i*WORD_STRIDE)-1] = next_rand();
104
      lptr[(i*WORD_STRIDE)+0] = next_rand();
105
      lptr[(i*WORD_STRIDE)+1] = next_rand();
106
      lptr[(i*WORD_STRIDE)+2] = next_rand();
107
      lptr[(i*WORD_STRIDE)+3] = next_rand();
108
      lptr[(i*WORD_STRIDE)+4] = next_rand();
109
    }
110
 
111
  report(next_rand());
112
 
113
#define CHECK(off) expected=next_rand(); \
114
  if (lptr[(i*WORD_STRIDE)+off] != expected)
115
 
116
#define FAILURE(x,y) report(y); report(expected); \
117
  report(lptr[(i*WORD_STRIDE)+y]);exit(0xbaaaaaad)
118
 
119
  // reset lfsr seed
120
  my_lfsr = RAND_LFSR_SEED;
121
  unsigned long int expected;
122
  for (i=0;i<LOOPS;i++)
123
    {
124
      report(i);
125
      CHECK(-1)
126
        {
127
          FAILURE(i,-1);
128
        }
129
      CHECK(0)
130
        {
131
          FAILURE(i,0);
132
        }
133
      CHECK(1)
134
        {
135
          FAILURE(i,1);
136
        }
137
      CHECK(2)
138
        {
139
          FAILURE(i,2);
140
        }
141
      CHECK(3)
142
        {
143
          FAILURE(i,3);
144
        }
145
      CHECK(4)
146
        {
147
          FAILURE(i,4);
148
        }
149
    }
150
 
151
  report(next_rand());
152
 
153
  return 0x8000000d;
154
}
155
 
156
 
157
 
158
 
159
 
160
 

powered by: WebSVN 2.1.0

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