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

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [orpmon/] [cmds/] [memory.c] - Blame information for rev 809

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

Line No. Rev Author Line
1 809 simons
#include "common.h"
2
#include "support.h"
3
#include "spr_defs.h"
4
 
5
#define printf(...)
6
//#define strtoul(x) 0
7
#define register_command(...)
8
 
9
void show_mem(int start, int stop)
10
{
11
  unsigned long i;
12
  getc();
13
  if (((i = start) & 0xf) != 0x0)
14
    printf ("\n%08lx: ", i);
15
  for(; i<=stop; i += 4){
16
    if ((i & 0xf) == 0x0)
17
      printf ("\n%08lx: ", i);
18
 
19
    /* Read one word */
20
    printf ("%08lx ", REG32(i));
21
  }
22
  printf ("\n");
23
}
24
 
25
void testram (unsigned long start_addr, unsigned long stop_addr, unsigned long testno)
26
{
27
  unsigned long addr;
28
  unsigned long err_addr = 0;
29
  unsigned long err_no = 0;
30
 
31
  /* Test 1: Write locations with their addresses */
32
  if ((testno == 1) || (testno == 0))
33
  {
34
    printf ("\n1. Writing locations with their addresses: ");
35
    for (addr = start_addr; addr <= stop_addr; addr += 4)
36
      REG32(addr) = addr;
37
 
38
    /* Verify */
39
    for (addr = start_addr; addr <= stop_addr; addr += 4)
40
      if (REG32(addr) != addr)
41
      {
42
        err_no++;
43
        err_addr = addr;
44
      }
45
    if (err_no)
46
    {
47
      printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
48
    } else
49
      printf ("Passed");
50
    err_no = 0;
51
  }
52
 
53
  /* Test 2: Write locations with their inverse address */
54
  if ((testno == 2) || (testno == 0))
55
  {
56
    printf ("\n2. Writing locations with their inverse addresses: ");
57
    for (addr = start_addr; addr <= stop_addr; addr += 4)
58
      REG32(addr) = ~addr;
59
 
60
    /* Verify */
61
    for (addr = start_addr; addr <= stop_addr; addr += 4)
62
      if (REG32(addr) != ~addr)
63
      {
64
        err_no++;
65
        err_addr = addr;
66
      }
67
    if (err_no)
68
    {
69
      printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
70
    } else
71
      printf ("Passed");
72
    err_no = 0;
73
  }
74
 
75
  /* Test 3: Write locations with walking ones */
76
  if ((testno == 3) || (testno == 0))
77
  {
78
    printf ("\n3. Writing locations with walking ones: ");
79
    for (addr = start_addr; addr <= stop_addr; addr += 4)
80
      REG32(addr) = 1 << (addr >> 2);
81
 
82
    /* Verify */
83
    for (addr = start_addr; addr <= stop_addr; addr += 4)
84
      if (REG32(addr) != (1 << (addr >> 2)))
85
      {
86
        err_no++;
87
        err_addr = addr;
88
      }
89
    if (err_no)
90
    {
91
      printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
92
    } else
93
      printf ("Passed");
94
    err_no = 0;
95
  }
96
 
97
  /* Test 4: Write locations with walking zeros */
98
  if ((testno == 4) || (testno == 0))
99
  {
100
    printf ("\n4. Writing locations with walking zeros: ");
101
    for (addr = start_addr; addr <= stop_addr; addr += 4)
102
      REG32(addr) = ~(1 << (addr >> 2));
103
 
104
    /* Verify */
105
    for (addr = start_addr; addr <= stop_addr; addr += 4)
106
      if (REG32(addr) != ~(1 << (addr >> 2)))
107
      {
108
        err_no++;
109
        err_addr = addr;
110
      }
111
    if (err_no)
112
    {
113
      printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
114
    } else
115
      printf ("Passed");
116
    err_no = 0;
117
  }
118
}
119
 
120
int dm_cmd (int argc, char *argv[])
121
{
122
        if (argc ==     1) show_mem (strtoul (argv[0]), strtoul (argv[0]));
123
        else if (argc   == 2) show_mem (strtoul (argv[0]), strtoul (argv[1]));
124
        else return -1;
125
        return 0;
126
}
127
 
128
int pm_cmd (int argc, char *argv[])
129
{
130
  if ((argc     == 3)   || (argc ==     2)) {
131
          unsigned long addr = strtoul (argv[0]);
132
          unsigned long stop_addr       =       strtoul (argv[1]);
133
          unsigned long value   =       strtoul (argv[2]);
134
 
135
          if (argc ==   2) {
136
                  stop_addr     =       strtoul (argv[0]);
137
                  value =       strtoul (argv[1]);
138
          }
139
 
140
          for (; addr <= stop_addr; addr += 4) REG32(addr)      =       value;
141
          show_mem(strtoul (argv[0]),    stop_addr);
142
        }       else return -1;
143
        return 0;
144
}
145
 
146
int ram_test_cmd (int argc, char *argv[])
147
{
148
  if (argc == 2) testram(strtoul (argv[0]), strtoul (argv[1]), 0);
149
  else if (argc == 3) testram(strtoul (argv[0]), strtoul (argv[1]), strtoul (argv[2]));
150
  else return -1;
151
  return 0;
152
}
153
 
154
void module_memory_init (void)
155
{
156
  register_command ("dm", "<start addr> [<end addr>]", "display memory location 32-bit", dm_cmd);
157
  register_command ("pm", "<addr> [<stop_addr>] <value>", "patch memory location 32-bit", pm_cmd);
158
  register_command ("ram_test", "<start_addr> <stop_addr> [<test_no>]", "run a simple RAM test\n", ram_test_cmd);
159
}

powered by: WebSVN 2.1.0

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