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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [cli/] [util/] [util_mem.c] - Blame information for rev 43

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

Line No. Rev Author Line
1 24 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2015 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27 22 qaztronic
 
28
#include "util_mem.h"
29
 
30
 
31
/*-----------------------------------------------------------*/
32
 
33
/* Display values from last command.
34
 * Memory modify remembered values are different from display memory.
35
 */
36
static ulong    dp_last_addr, dp_last_size;
37
static ulong    dp_last_length = 0x40;
38
// static ulong mm_last_addr, mm_last_size;
39
 
40
static  ulong   base_address = 0;
41
 
42
/* Memory Display
43
 *
44
 * Syntax:
45
 *      md{.b, .w, .l, .q} {addr} {len}
46
 */
47
#define DISP_LINE_LEN   16
48
static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, const char * argv[])
49
{
50
        ulong   addr, length;
51
#if defined(CONFIG_HAS_DATAFLASH)
52
        ulong   nbytes, linebytes;
53
#endif
54
        int     size;
55
        int rc = 0;
56
 
57
        /* We use the last specified parameters, unless new ones are
58
         * entered.
59
         */
60
        addr = dp_last_addr;
61
        size = dp_last_size;
62
        length = dp_last_length;
63
 
64
        if (argc < 2)
65
                return CMD_RET_USAGE;
66
 
67
        if ((flag & CMD_FLAG_REPEAT) == 0) {
68
                /* New command specified.  Check for a size specification.
69
                 * Defaults to long if no or incorrect specification.
70
                 */
71
                if ((size = cmd_get_data_size(argv[0], 4)) < 0)
72
                        return 1;
73
 
74
                /* Address is specified since argc > 1
75
                */
76
                addr = simple_strtoul(argv[1], NULL, 16);
77
                addr += base_address;
78
 
79
                /* If another parameter, it is the length to display.
80
                 * Length is the number of objects, not number of bytes.
81
                 */
82
                if (argc > 2)
83
                        length = simple_strtoul(argv[2], NULL, 16);
84
        }
85
 
86
#if defined(CONFIG_HAS_DATAFLASH)
87
        /* Print the lines.
88
         *
89
         * We buffer all read data, so we can make sure data is read only
90
         * once, and all accesses are with the specified bus width.
91
         */
92
        nbytes = length * size;
93
        do {
94
                char    linebuf[DISP_LINE_LEN];
95
                void* p;
96
                linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
97
 
98
                rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
99
                p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
100
                print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
101
 
102
                nbytes -= linebytes;
103
                addr += linebytes;
104
                if (ctrlc()) {
105
                        rc = 1;
106
                        break;
107
                }
108
        } while (nbytes > 0);
109
#else
110
 
111
# if defined(CONFIG_BLACKFIN)
112
        /* See if we're trying to display L1 inst */
113
        if (addr_bfin_on_chip_mem(addr)) {
114
                char linebuf[DISP_LINE_LEN];
115
                ulong linebytes, nbytes = length * size;
116
                do {
117
                        linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
118
                        memcpy(linebuf, (void *)addr, linebytes);
119
                        print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
120
 
121
                        nbytes -= linebytes;
122
                        addr += linebytes;
123
                        if (ctrlc()) {
124
                                rc = 1;
125
                                break;
126
                        }
127
                } while (nbytes > 0);
128
        } else
129
# endif
130
 
131
        {
132
                ulong bytes = size * length;
133
                const void *buf = map_sysmem(addr, bytes);
134
 
135
                /* Print the lines. */
136
                print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
137
                addr += bytes;
138
                unmap_sysmem(buf);
139
        }
140
#endif
141
 
142
        dp_last_addr = addr;
143
        dp_last_length = length;
144
        dp_last_size = size;
145
        return (rc);
146
}
147
 
148
 
149
/*-----------------------------------------------------------*/
150
static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, const char * argv[])
151
{
152
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
153
        u64 writeval;
154
#else
155
        ulong writeval;
156
#endif
157
        ulong   addr, count;
158
        int     size;
159
        void *buf, *start;
160
        ulong bytes;
161
 
162
        if ((argc < 3) || (argc > 4))
163
                return CMD_RET_USAGE;
164
 
165
        /* Check for size specification.
166
        */
167
        if ((size = cmd_get_data_size(argv[0], 4)) < 1)
168
                return 1;
169
 
170
        /* Address is specified since argc > 1
171
        */
172
        addr = simple_strtoul(argv[1], NULL, 16);
173
        addr += base_address;
174
 
175
        /* Get the value to write.
176
        */
177
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
178
        writeval = simple_strtoull(argv[2], NULL, 16);
179
#else
180
        writeval = simple_strtoul(argv[2], NULL, 16);
181
#endif
182
 
183
        /* Count ? */
184
        if (argc == 4) {
185
                count = simple_strtoul(argv[3], NULL, 16);
186
        } else {
187
                count = 1;
188
        }
189
 
190
        bytes = size * count;
191
        start = map_sysmem(addr, bytes);
192
        buf = start;
193
        while (count-- > 0) {
194
                if (size == 4)
195
                        *((u32 *)buf) = (u32)writeval;
196
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
197
                else if (size == 8)
198
                        *((u64 *)buf) = (u64)writeval;
199
#endif
200
                else if (size == 2)
201
                        *((u16 *)buf) = (u16)writeval;
202
                else
203
                        *((u8 *)buf) = (u8)writeval;
204
                buf += size;
205
        }
206
        unmap_sysmem(start);
207
        return 0;
208
}
209
 
210
 
211
/*-----------------------------------------------------------*/
212
char func_mw( const unsigned char argc, const char *argv[] )
213
{
214
  return do_mem_mw(0, 0, argc, argv);
215
}
216
 
217
 
218
/*-----------------------------------------------------------*/
219
char func_md( const unsigned char argc, const char *argv[] )
220
{
221
  return do_mem_md(0, 0, argc, argv);
222
}
223
 
224
 
225
 
226
 
227
 
228
 

powered by: WebSVN 2.1.0

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