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 425

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 425 julius
  if (!(mfspr(SPR_UPR)& SPR_UPR_DCP) | !(mfspr(SPR_SR) & SPR_SR_DCE))
33
    {
34
      // Not really a pass, but not really a fail, either.
35
      report(0x8000000d);
36
      return 0;
37
    }
38 349 julius
 
39
  volatile char* ptr = (volatile char*) 0xe00000;
40
  int i;
41
 
42
  ptr[0] = 0xab;
43
 
44
  ptr[4096] = 0xcd;
45
 
46
  ptr[8192] = 0xef;
47
 
48
  report(ptr[0]);
49
 
50
  report(ptr[4096]);
51
 
52
  report(ptr[8192]);
53
 
54
  // If cache is write back, then test flush and writeback functionalities
55
  // Check cache write stategy bit (CWS) for write back
56
  if (mfspr(SPR_DCCFGR) & SPR_DCCFGR_CWS)
57
    {
58
      // TODO: Check flush and write back actually work by mapping the same
59
      // space as CI through DMMU. For now the following will aid checking on
60
      // waveform.
61
      volatile int * test_addr = (int *) 0xefaa10;
62
 
63
      // Fill some lines with data
64
      for (i=0;i<64;i++)
65
        test_addr[i] = 1+(i<<i)/(i+1);
66
 
67
      // Flush the lines
68
      int spr_addr = SPR_DCBFR;
69
 
70
      for (i=0;i<16;i++)
71
        asm("l.mtspr\t\t%0,%1,0": : "r" (spr_addr), "r" (test_addr+(i*4)));
72
 
73
      // Check the data
74
      for (i=0;i<64;i++)
75
        if (test_addr[i] != (1+(i<<i)/(i+1)))
76
          return i;
77
 
78
      // Fill some lines with data
79
      for (i=0;i<64;i++)
80
        test_addr[i] = ~i;
81
 
82
      // Force writeback of the lines
83
      spr_addr = SPR_DCBWR;
84
 
85
      for (i=0;i<16;i++)
86
        asm("l.mtspr\t\t%0,%1,0": : "r" (spr_addr), "r" (test_addr+(i*4)));
87
 
88
      // Check the data
89
      for (i=0;i<64;i++)
90
        if (test_addr[i] != ~i)
91
          return ~i;
92
 
93
 
94
    }
95
 
96
  // Now generate some random numbers, write them in in strides that should 
97
  // execercise the cache's line reloading/storing mechanism.
98
 
99
  // init LFSR
100
  my_lfsr = RAND_LFSR_SEED;
101
  volatile unsigned long int *lptr = (volatile unsigned long int*) 0xa00000;
102
  for(i=0;i<LOOPS;i++)
103
    {
104
      lptr[(i*WORD_STRIDE)-1] = next_rand();
105
      lptr[(i*WORD_STRIDE)+0] = next_rand();
106
      lptr[(i*WORD_STRIDE)+1] = next_rand();
107
      lptr[(i*WORD_STRIDE)+2] = next_rand();
108
      lptr[(i*WORD_STRIDE)+3] = next_rand();
109
      lptr[(i*WORD_STRIDE)+4] = next_rand();
110
    }
111
 
112
  report(next_rand());
113
 
114
#define CHECK(off) expected=next_rand(); \
115
  if (lptr[(i*WORD_STRIDE)+off] != expected)
116
 
117
#define FAILURE(x,y) report(y); report(expected); \
118
  report(lptr[(i*WORD_STRIDE)+y]);exit(0xbaaaaaad)
119
 
120
  // reset lfsr seed
121
  my_lfsr = RAND_LFSR_SEED;
122
  unsigned long int expected;
123
  for (i=0;i<LOOPS;i++)
124
    {
125
      report(i);
126
      CHECK(-1)
127
        {
128
          FAILURE(i,-1);
129
        }
130
      CHECK(0)
131
        {
132
          FAILURE(i,0);
133
        }
134
      CHECK(1)
135
        {
136
          FAILURE(i,1);
137
        }
138
      CHECK(2)
139
        {
140
          FAILURE(i,2);
141
        }
142
      CHECK(3)
143
        {
144
          FAILURE(i,3);
145
        }
146
      CHECK(4)
147
        {
148
          FAILURE(i,4);
149
        }
150
    }
151
 
152
  report(next_rand());
153
 
154 425 julius
  report(0x8000000d);
155
 
156
  exit(0);
157 349 julius
}
158
 
159
 
160
 
161
 
162
 
163
 

powered by: WebSVN 2.1.0

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