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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [loop/] [loop-report.c] - Blame information for rev 608

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

Line No. Rev Author Line
1 98 jeremybenn
/* loop-report.c. Or1ksim simple C loop program which reports changes.
2
 
3
   Copyright (C) 1999-2006 OpenCores
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributors various OpenCores participants
7
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
   This file is part of OpenRISC 1000 Architectural Simulator.
10
 
11
   This program is free software; you can redistribute it and/or modify it
12
   under the terms of the GNU General Public License as published by the Free
13
   Software Foundation; either version 3 of the License, or (at your option)
14
   any later version.
15
 
16
   This program is distributed in the hope that it will be useful, but WITHOUT
17
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
   more details.
20
 
21
   You should have received a copy of the GNU General Public License along
22
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
23
 
24
/* ----------------------------------------------------------------------------
25
   This code is commented throughout for use with Doxygen.
26
   --------------------------------------------------------------------------*/
27
 
28
/* A program which initializes memory and SPR, then just loops. Used in
29
   testing libor1ksim JTAG read functionality. */
30
 
31
#include "support.h"
32
#include "spr-defs.h"
33
 
34
/*---------------------------------------------------------------------------*/
35
/*!main program
36
 
37
   We have two blocks of memory of interest (0x00000000 - 0x00200000,
38
   0xffe0000 - 0xffffffff) and two SPRs of interest (MACLO, 0x2801 and MACHI,
39
   0x2802). We monitor for any changes in the first 16 and last 16 bytes of
40
   each memory block, the middle 16 of the first memory block and both SPRs,
41
   having first initialized them to zero.
42
 
43
   We have to be careful about strobing. We sit in a loop looking for changes,
44
   but only print out the changes after we have had one loop with no changes.
45
 
46
   @return  The return code from the program (of no interest to us).         */
47
/*---------------------------------------------------------------------------*/
48
int
49
main ()
50
{
51
  /* Useful constants */
52
  unsigned char *b0_start_addr = (unsigned char *) 0x00000000;
53
  unsigned char *b0_mid_addr   = (unsigned char *) 0x00100000;
54
  unsigned char *b0_end_addr   = (unsigned char *) 0x001ffff0;
55
  unsigned char *b1_start_addr = (unsigned char *) 0xffe00000;
56
  unsigned char *b1_end_addr   = (unsigned char *) 0xfffffff0;
57
 
58
  /* General purpose */
59
  unsigned long int  r;
60
  int                i;
61
 
62
  /* Values remembered */
63
  unsigned long int  maclo;
64
  unsigned long int  machi;
65
 
66
  unsigned char      b0_start[16];
67
  unsigned char      b0_mid[16];
68
  unsigned char      b0_end[16];
69
  unsigned char      b1_start[16];
70
  unsigned char      b1_end[16];
71
 
72
  /* Flags indicating change */
73
  int  maclo_f;
74
  int  machi_f;
75
 
76
  int  b0_start_f[16];
77
  int  b0_mid_f[16];
78
  int  b0_end_f[16];
79
  int  b1_start_f[16];
80
  int  b1_end_f[16];
81
 
82
  int  changed_since_print;
83
 
84
  /* Set the SR to have SUMRA bit set, so that we can access certain regs in
85
     user mode. */
86
  r = mfspr (SPR_SR);
87
  mtspr (SPR_SR, r | SPR_SR_SUMRA);
88
 
89
  /* Initialize remembered values and flags */
90
  maclo = 0;
91
  machi = 0;
92
 
93
  maclo_f = 0;
94
  machi_f = 0;
95
 
96
  for (i = 0; i < 16; i++)
97
    {
98
      b0_start[i] = 0;
99
      b0_mid[i]   = 0;
100
      b0_end[i]   = 0;
101
      b1_start[i] = 0;
102
      b1_end[i]   = 0;
103
 
104
      b0_start_f[i] = 0;
105
      b0_mid_f[i]   = 0;
106
      b0_end_f[i]   = 0;
107
      b1_start_f[i] = 0;
108
      b1_end_f[i]   = 0;
109
    }
110
 
111
  /* Set the values in SPR and memory */
112
  mtspr (SPR_MACLO, maclo);
113
  mtspr (SPR_MACHI, machi);
114
 
115
  for (i = 0; i < 16; i++)
116
    {
117
      b0_start_addr[i] = b0_start[i];
118
      b0_mid_addr[i]   = b0_mid[i];
119
      b0_end_addr[i]   = b0_end[i];
120
      b1_start_addr[i] = b1_start[i];
121
      b1_end_addr[i]   = b1_end[i];
122
    }
123
 
124
  /* Loop for ever checking if any values have changed. */
125
  changed_since_print = 0;
126
 
127
  while (1)
128
    {
129
      int  changed_this_loop = 0;
130
 
131
      /* Check SPRs */
132
      if (mfspr (SPR_MACLO) != maclo)
133
        {
134
          maclo               = mfspr (SPR_MACLO);
135
          maclo_f             = 1;
136
          changed_since_print = 1;
137
          changed_this_loop   = 1;
138
        }
139
 
140
      if (mfspr (SPR_MACHI) != machi)
141
        {
142
          machi               = mfspr (SPR_MACHI);
143
          machi_f             = 1;
144
          changed_since_print = 1;
145
          changed_this_loop   = 1;
146
        }
147
 
148
      /* Check memory blocks */
149
      for (i = 0; i < 16; i++)
150
        {
151
          if (b0_start_addr[i] != b0_start[i])
152
            {
153
              b0_start[i]         = b0_start_addr[i];
154
              b0_start_f[i]       = 1;
155
              changed_since_print = 1;
156
              changed_this_loop   = 1;
157
            }
158
 
159
          if (b0_mid_addr[i] != b0_mid[i])
160
            {
161
              b0_mid[i]           = b0_mid_addr[i];
162
              b0_mid_f[i]         = 1;
163
              changed_since_print = 1;
164
              changed_this_loop   = 1;
165
            }
166
 
167
          if (b0_end_addr[i] != b0_end[i])
168
            {
169
              b0_end[i]           = b0_end_addr[i];
170
              b0_end_f[i]         = 1;
171
              changed_since_print = 1;
172
              changed_this_loop   = 1;
173
            }
174
 
175
          if (b1_start_addr[i] != b1_start[i])
176
            {
177
              b1_start[i]         = b1_start_addr[i];
178
              b1_start_f[i]       = 1;
179
              changed_since_print = 1;
180
              changed_this_loop   = 1;
181
            }
182
 
183
          if (b1_end_addr[i] != b1_end[i])
184
            {
185
              b1_end[i]           = b1_end_addr[i];
186
              b1_end_f[i]         = 1;
187
              changed_since_print = 1;
188
              changed_this_loop   = 1;
189
            }
190
        }
191
 
192
      /* Only print out if there have been changes since the last print, but
193
         not during this loop. This makes sure we don't strobe with writing
194
         from JTAG. */
195
      if (changed_since_print && !changed_this_loop)
196
        {
197
          /* Print any changed SPRs */
198
          if (maclo_f)
199
            {
200
              printf ("New MACLO 0x%08lx\n", maclo);
201
              maclo_f = 0;
202
            }
203
 
204
          if (machi_f)
205
            {
206
              printf ("New MACHI 0x%08lx\n", machi);
207
              machi_f = 0;
208
            }
209
 
210
          /* Print any changed memory. Each in its own loop to give ascending
211
             order. */
212
          for (i = 0; i < 16; i++)
213
            {
214
              if (b0_start_f[i])
215
                {
216
                  printf ("New byte at 0x%08lx = 0x%02x\n",
217
                          (unsigned long int) &b0_start_addr[i], b0_start[i]);
218
                  b0_start_f[i] = 0;
219
                }
220
            }
221
 
222
          for (i = 0; i < 16; i++)
223
            {
224
              if (b0_mid_f[i])
225
                {
226
                  printf ("New byte at 0x%08lx = 0x%02x\n",
227
                          (unsigned long int) &b0_mid_addr[i], b0_mid[i]);
228
                  b0_mid_f[i] = 0;
229
                }
230
            }
231
 
232
          for (i = 0; i < 16; i++)
233
            {
234
              if (b0_end_f[i])
235
                {
236
                  printf ("New byte at 0x%08lx = 0x%02x\n",
237
                          (unsigned long int) &b0_end_addr[i], b0_end[i]);
238
                  b0_end_f[i] = 0;
239
                }
240
            }
241
 
242
          for (i = 0; i < 16; i++)
243
            {
244
              if (b1_start_f[i])
245
                {
246
                  printf ("New byte at 0x%08lx = 0x%02x\n",
247
                          (unsigned long int) &b1_start_addr[i], b1_start[i]);
248
                  b1_start_f[i] = 0;
249
                }
250
            }
251
 
252
          for (i = 0; i < 16; i++)
253
            {
254
              if (b1_end_f[i])
255
                {
256
                  printf ("New byte at 0x%08lx = 0x%02x\n",
257
                          (unsigned long int) &b1_end_addr[i], b1_end[i]);
258
                  b1_end_f[i] = 0;
259
                }
260
            }
261
 
262
          changed_since_print = 0;       /* Start it all again */
263
        }
264
    }
265
}       /* main () */

powered by: WebSVN 2.1.0

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