1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// mcmp.c
|
4 |
|
|
//
|
5 |
|
|
// RedBoot memory compare (mcmp) routine
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): gthomas
|
43 |
|
|
// Contributors: gthomas
|
44 |
|
|
// Date: 2002-08-06
|
45 |
|
|
// Purpose:
|
46 |
|
|
// Description:
|
47 |
|
|
//
|
48 |
|
|
// This code is part of RedBoot (tm).
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
#include <redboot.h>
|
55 |
|
|
|
56 |
|
|
RedBoot_cmd("mcmp",
|
57 |
|
|
"Compare two blocks of memory",
|
58 |
|
|
"-s <location> -d <location> -l <length> [-1|-2|-4]",
|
59 |
|
|
do_mcmp
|
60 |
|
|
);
|
61 |
|
|
|
62 |
|
|
void
|
63 |
|
|
do_mcmp(int argc, char *argv[])
|
64 |
|
|
{
|
65 |
|
|
// Fill a region of memory with a pattern
|
66 |
|
|
struct option_info opts[6];
|
67 |
|
|
unsigned long src_base, dst_base;
|
68 |
|
|
long len;
|
69 |
|
|
bool src_base_set, dst_base_set, len_set;
|
70 |
|
|
bool set_32bit, set_16bit, set_8bit;
|
71 |
|
|
|
72 |
|
|
init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
|
73 |
|
|
(void *)&src_base, (bool *)&src_base_set, "base address");
|
74 |
|
|
init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
|
75 |
|
|
(void *)&len, (bool *)&len_set, "length");
|
76 |
|
|
init_opts(&opts[2], 'd', true, OPTION_ARG_TYPE_NUM,
|
77 |
|
|
(void *)&dst_base, (bool *)&dst_base_set, "base address");
|
78 |
|
|
init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG,
|
79 |
|
|
(void *)&set_32bit, (bool *)0, "fill 32 bit units");
|
80 |
|
|
init_opts(&opts[4], '2', false, OPTION_ARG_TYPE_FLG,
|
81 |
|
|
(void *)&set_16bit, (bool *)0, "fill 16 bit units");
|
82 |
|
|
init_opts(&opts[5], '1', false, OPTION_ARG_TYPE_FLG,
|
83 |
|
|
(void *)&set_8bit, (bool *)0, "fill 8 bit units");
|
84 |
|
|
if (!scan_opts(argc, argv, 1, opts, 6, 0, 0, "")) {
|
85 |
|
|
return;
|
86 |
|
|
}
|
87 |
|
|
if (!src_base_set || !dst_base_set || !len_set) {
|
88 |
|
|
diag_printf("usage: mcmp -s <addr> -d <addr> -l <length> [-1|-2|-4]\n");
|
89 |
|
|
return;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
if (set_8bit) {
|
95 |
|
|
cyg_uint8 *s = (cyg_uint8 *)src_base;
|
96 |
|
|
cyg_uint8 *d = (cyg_uint8 *)dst_base;
|
97 |
|
|
while ((len -= sizeof(cyg_uint8)) >= 0) {
|
98 |
|
|
if (*s++ != *d++) {
|
99 |
|
|
s--;
|
100 |
|
|
d--;
|
101 |
|
|
diag_printf("Buffers don't match - %p=0x%02x, %p=0x%02x\n",
|
102 |
|
|
s, *s, d, *d);
|
103 |
|
|
return;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
}
|
107 |
|
|
} else if (set_16bit) {
|
108 |
|
|
cyg_uint16 *s = (cyg_uint16 *)src_base;
|
109 |
|
|
cyg_uint16 *d = (cyg_uint16 *)dst_base;
|
110 |
|
|
while ((len -= sizeof(cyg_uint16)) >= 0) {
|
111 |
|
|
if (*s++ != *d++) {
|
112 |
|
|
s--;
|
113 |
|
|
d--;
|
114 |
|
|
diag_printf("Buffers don't match - %p=0x%04x, %p=0x%04x\n",
|
115 |
|
|
s, *s, d, *d);
|
116 |
|
|
return;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
}
|
120 |
|
|
} else {
|
121 |
|
|
cyg_uint32 *s = (cyg_uint32 *)src_base;
|
122 |
|
|
cyg_uint32 *d = (cyg_uint32 *)dst_base;
|
123 |
|
|
while ((len -= sizeof(cyg_uint32)) >= 0) {
|
124 |
|
|
if (*s++ != *d++) {
|
125 |
|
|
s--;
|
126 |
|
|
d--;
|
127 |
|
|
diag_printf("Buffers don't match - %p=0x%08x, %p=0x%08x\n",
|
128 |
|
|
s, *s, d, *d);
|
129 |
|
|
return;
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
}
|