Mercurial > ecos
annotate packages/redboot/current/src/mcopy.c @ 3249:6e9f1cd4ed38
Fix compiler warning about variable set but not used. [ Bugzilla 1001865 ]
| author | vae |
|---|---|
| date | Sat, 15 Jun 2013 20:22:36 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 1087 | 1 //========================================================================== |
| 2 // | |
| 3 // mcopy.c | |
| 4 // | |
| 5 // RedBoot memory copy (mcopy) routine | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1513
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1513
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1513
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:
1513
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
| 1087 | 12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1513
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:
1513
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:
1513
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:
1513
diff
changeset
|
16 // version. |
| 1087 | 17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1513
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:
1513
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:
1513
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:
1513
diff
changeset
|
21 // for more details. |
| 1087 | 22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1513
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:
1513
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:
1513
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 1087 | 26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1513
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:
1513
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:
1513
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:
1513
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:
1513
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:
1513
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:
1513
diff
changeset
|
33 // General Public License v2. |
| 1087 | 34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1513
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:
1513
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:
1513
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1513
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 1087 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author(s): msalter | |
| 43 // Contributors: msalter | |
| 44 // Date: 2003-07-01 | |
| 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 static void | |
| 57 do_mcopy(int argc, char *argv[]) | |
| 58 { | |
| 59 struct option_info opts[6]; | |
| 60 unsigned long src, dst, len, end; | |
| 61 bool src_set, dst_set, len_set; | |
| 62 bool sz32, sz16, sz8; | |
| 63 int incr = 1; | |
| 64 | |
| 65 init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM, | |
| 1513 | 66 (void *)&src, (bool *)&src_set, "base address"); |
| 1087 | 67 init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM, |
| 1513 | 68 (void *)&len, (bool *)&len_set, "length"); |
| 1087 | 69 init_opts(&opts[2], 'd', true, OPTION_ARG_TYPE_NUM, |
| 1513 | 70 (void *)&dst, (bool *)&dst_set, "base address"); |
| 1087 | 71 init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG, |
| 72 (void *)&sz32, (bool *)0, "copy 32 bit data"); | |
| 73 init_opts(&opts[4], '2', false, OPTION_ARG_TYPE_FLG, | |
| 1513 | 74 (void *)&sz16, (bool *)0, "copy 16 bit data"); |
| 1087 | 75 init_opts(&opts[5], '1', false, OPTION_ARG_TYPE_FLG, |
| 1513 | 76 (void *)&sz8, (bool *)0, "copy 8 bit data"); |
| 1087 | 77 if (!scan_opts(argc, argv, 1, opts, 6, 0, 0, "")) { |
| 78 return; | |
| 79 } | |
| 80 | |
| 81 // Must have src, dst, len. No more than one size specifier. | |
| 82 if (!src_set || !dst_set || !len_set || (sz32 + sz16 + sz8) > 1) { | |
| 83 diag_printf("usage: mcopy -s <addr> -d <addr> -l <length> [-1|-2|-4]\n"); | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 // adjust incr and len for data size | |
| 88 if (sz16) { | |
| 89 len = (len + 1) & ~1; | |
| 90 incr = 2; | |
| 91 } else if (sz32 || !sz8) { | |
| 92 len = (len + 3) & ~3; | |
| 93 incr = 4; | |
| 94 } | |
| 95 | |
| 96 end = src + len; | |
| 97 | |
| 98 // If overlapping areas, must copy backwards. | |
| 99 if (dst > src && dst < (src + len)) { | |
| 100 end = src - incr; | |
| 101 src += (len - incr); | |
| 102 dst += (len - incr); | |
| 103 incr = -incr; | |
| 104 } | |
| 105 | |
| 106 if (sz8) { | |
| 107 while (src != end) { | |
| 108 *(cyg_uint8 *)dst = *(cyg_uint8 *)src; | |
| 109 src += incr; | |
| 110 dst += incr; | |
| 111 } | |
| 112 } else if (sz16) { | |
| 113 while (src != end) { | |
| 114 *(cyg_uint16 *)dst = *(cyg_uint16 *)src; | |
| 115 src += incr; | |
| 116 dst += incr; | |
| 117 } | |
| 118 } else { | |
| 119 // Default - 32 bits | |
| 120 while (src != end) { | |
| 121 *(cyg_uint32 *)dst = *(cyg_uint32 *)src; | |
| 122 src += incr; | |
| 123 dst += incr; | |
| 124 } | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 | |
| 129 RedBoot_cmd("mcopy", | |
| 130 "Copy memory from one address to another", | |
| 131 "-s <location> -d <location> -l <length> [-1|-2|-4]", | |
| 132 do_mcopy | |
| 133 ); |
