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 502

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

powered by: WebSVN 2.1.0

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