annotate packages/redboot/current/src/mcmp.c @ 2863:7d8c61e6225c default tip

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