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 439

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

powered by: WebSVN 2.1.0

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