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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [orpmon/] [cmds/] [memory.c] - Blame information for rev 1768

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 818 markom
void show_mem (int start, int stop)
6 809 simons
{
7 818 markom
  unsigned long i = start;
8
  if ((i & 0xf) != 0x0) printf ("\n%08lx: ", i);
9
  for(; i <= stop; i += 4) {
10
    if ((i & 0xf) == 0x0) printf ("\n%08lx: ", i);
11 809 simons
    /* Read one word */
12
    printf ("%08lx ", REG32(i));
13
  }
14
  printf ("\n");
15
}
16
 
17
void testram (unsigned long start_addr, unsigned long stop_addr, unsigned long testno)
18
{
19
  unsigned long addr;
20
  unsigned long err_addr = 0;
21
  unsigned long err_no = 0;
22
 
23
  /* Test 1: Write locations with their addresses */
24 818 markom
  if ((testno == 1) || (testno == 0)) {
25 809 simons
    printf ("\n1. Writing locations with their addresses: ");
26
    for (addr = start_addr; addr <= stop_addr; addr += 4)
27
      REG32(addr) = addr;
28
 
29
    /* Verify */
30
    for (addr = start_addr; addr <= stop_addr; addr += 4)
31 818 markom
      if (REG32(addr) != addr) {
32 809 simons
        err_no++;
33
        err_addr = addr;
34
      }
35 818 markom
    if (err_no) printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
36
    else printf ("Passed");
37 809 simons
    err_no = 0;
38
  }
39
 
40
  /* Test 2: Write locations with their inverse address */
41 818 markom
  if ((testno == 2) || (testno == 0)) {
42 809 simons
    printf ("\n2. Writing locations with their inverse addresses: ");
43
    for (addr = start_addr; addr <= stop_addr; addr += 4)
44
      REG32(addr) = ~addr;
45
 
46
    /* Verify */
47
    for (addr = start_addr; addr <= stop_addr; addr += 4)
48 818 markom
      if (REG32(addr) != ~addr) {
49 809 simons
        err_no++;
50
        err_addr = addr;
51
      }
52 818 markom
    if (err_no) printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
53
    else printf ("Passed");
54 809 simons
    err_no = 0;
55
  }
56
 
57
  /* Test 3: Write locations with walking ones */
58 818 markom
  if ((testno == 3) || (testno == 0)) {
59 809 simons
    printf ("\n3. Writing locations with walking ones: ");
60
    for (addr = start_addr; addr <= stop_addr; addr += 4)
61
      REG32(addr) = 1 << (addr >> 2);
62
 
63
    /* Verify */
64
    for (addr = start_addr; addr <= stop_addr; addr += 4)
65 818 markom
      if (REG32(addr) != (1 << (addr >> 2))) {
66 809 simons
        err_no++;
67
        err_addr = addr;
68
      }
69 818 markom
    if (err_no) printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
70
    else printf ("Passed");
71 809 simons
    err_no = 0;
72
  }
73
 
74
  /* Test 4: Write locations with walking zeros */
75 818 markom
  if ((testno == 4) || (testno == 0)) {
76 809 simons
    printf ("\n4. Writing locations with walking zeros: ");
77
    for (addr = start_addr; addr <= stop_addr; addr += 4)
78
      REG32(addr) = ~(1 << (addr >> 2));
79 818 markom
 
80 809 simons
    /* Verify */
81
    for (addr = start_addr; addr <= stop_addr; addr += 4)
82 818 markom
      if (REG32(addr) != ~(1 << (addr >> 2))) {
83 809 simons
        err_no++;
84
        err_addr = addr;
85
      }
86 818 markom
    if (err_no) printf ("%04lx times failed. Last at location %08lx", err_no, err_addr);
87
    else printf ("Passed");
88 809 simons
    err_no = 0;
89
  }
90
}
91
 
92
int dm_cmd (int argc, char *argv[])
93
{
94 1312 jurem
  unsigned long a1,a2;
95
  a1 = strtoul(argv[0], 0, 0);
96 818 markom
  switch (argc) {
97 1312 jurem
    case 1: show_mem (a1, a1); return 0;
98
    case 2:
99
      a2 = strtoul(argv[1], 0, 0);
100
      show_mem (a1, a2); return 0;
101 818 markom
    default: return -1;
102
  }
103 809 simons
}
104
 
105
int pm_cmd (int argc, char *argv[])
106
{
107 818 markom
  unsigned long addr, stop_addr, value;
108 812 markom
  if ((argc == 3) || (argc == 2)) {
109 818 markom
    addr = strtoul (argv[0], 0, 0);
110
 
111
    if (argc == 2) {
112
      stop_addr = strtoul (argv[0], 0, 0);
113
      value = strtoul (argv[1], 0, 0);
114
    } else {
115
      stop_addr = strtoul (argv[1], 0, 0);
116
      value = strtoul (argv[2], 0, 0);
117
    }
118
 
119
    for (; addr <= stop_addr; addr += 4) REG32(addr) = value;
120
 
121
    /*show_mem(strtoul (argv[0], 0, 0), stop_addr);*/
122
  } else return -1;
123
  return 0;
124
}
125 809 simons
 
126 818 markom
int ram_test_cmd (int argc, char *argv[])
127
{
128
  switch (argc) {
129
    case 2: testram(strtoul (argv[0], 0, 0), strtoul (argv[1], 0, 0), 0); return 0;
130
    case 3: testram(strtoul (argv[0], 0, 0), strtoul (argv[1], 0, 0), strtoul (argv[2], 0, 0)); return 0;
131
    default: return -1;
132
  }
133
}
134 809 simons
 
135 818 markom
unsigned long crc32 (unsigned long crc, const unsigned char *buf, unsigned long len)
136
{
137
  /* Create bitwise CRC table first */
138
  unsigned long crc_table[256];
139
  int i, k;
140
  for (i = 0; i < 256; i++) {
141
    unsigned long c = (unsigned long)i;
142
    for (k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >> 1) : c >> 1;
143
    crc_table[i] = c;
144
  }
145
 
146
  /* Calculate crc on buf */
147
  crc = crc ^ 0xffffffffL;
148
  while (len--) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
149
  return crc ^ 0xffffffffL;
150 809 simons
}
151
 
152 818 markom
int crc_cmd (int argc, char *argv[])
153 809 simons
{
154 818 markom
  unsigned long addr = global.src_addr;
155
  unsigned long len = global.length;
156
  unsigned long init_crc = 0;
157
 
158
  switch (argc) {
159
    case 3: init_crc = strtoul (argv[2], 0, 0);
160
    case 2: len = strtoul (argv[1], 0, 0);
161
    case 1: addr = strtoul (argv[0], 0, 0);
162
    case 0:
163 828 markom
      printf ("CRC [%08lx-%08lx] = %08lx\n", addr, addr + len - 1, crc32 (init_crc, (unsigned char *)addr, len));
164 818 markom
      return 0;
165
  }
166
  return -1;
167 809 simons
}
168
 
169
void module_memory_init (void)
170
{
171 818 markom
  register_command ("dm", "<start addr> [<end addr>]", "display 32-bit memory location(s)", dm_cmd);
172
  register_command ("pm", "<addr> [<stop_addr>] <value>", "patch 32-bit memory location(s)", pm_cmd);
173 832 markom
  register_command ("ram_test", "<start_addr> <stop_addr> [<test_no>]", "run a simple RAM test", ram_test_cmd);
174
  register_command ("crc", "[<src_addr> [<length> [<init_crc>]]]", "Calculates a 32-bit CRC on specified memory region", crc_cmd);
175 809 simons
}

powered by: WebSVN 2.1.0

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