-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.c
103 lines (82 loc) · 2.45 KB
/
dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* memory.c:
*
* Functions for dealing with the on board memory
*/
#include <stdio.h>
#include <stdint.h>
#include <ctype.h>
#include "common.h"
#define BYTES_PER_LINE 16
/* Dump a buffer in HEX with the address as given */
void DumpBuffer(uint8_t *buffer, uint32_t count, uint32_t address)
{
uint32_t i;
uint8_t buf[BYTES_PER_LINE+1],*bufp; /* Buffer to assemble printed chars */
uint8_t *p,c;
if(count == 0) return;
p = buffer;
bufp = buf;
/* dump the requested number of bytes in hex. */
for(i=0; i<count; i++) {
if((i% BYTES_PER_LINE) == 0) {
printf("%08x:",(unsigned int)address);
bufp = buf;
}
/* Read the value to print */
c = *p++;
address++;
/* Stash the appropriate chacter to print at EOL */
if(isprint(c)) {
*bufp++ = c; /* Stick in the character */
} else {
*bufp++ = '.';
}
printf(" %02x",((unsigned int)c) & 0xff);
/* At end of line ? */
if((i % BYTES_PER_LINE) == (BYTES_PER_LINE-1)) {
*bufp = '\0'; /* NULL terminate buffer */
/* Yes, print buffer */
printf(" %s\n",buf);
}
}
/* dump out to EOL */
*bufp='\0';
if(count % BYTES_PER_LINE) {
for(i=0; i<(BYTES_PER_LINE - (count % BYTES_PER_LINE)); i++) {
printf(" ");
}
/* Yes, print buffer */
printf(" %s\n",buf);
}
}
void CmdDump(int action)
{
int rc;
static uint32_t address=0, count=0x100;
if(action==CMD_SHORT_HELP) return;
if(action==CMD_LONG_HELP) {
printf("dump {<address> {<count>}}\n\n"
"This command dumps the contents of local memory to the terminal.\n"
"\n"
"<address> can be any value from 0x00000000 to 0xFFFFFFFF.\n"
"Invalid accesses will be trapped. If address is unspecified,\n"
"continues from last printed address. Default value is 0.\n"
"\n"
"<count> is the number of bytes to dump to the terminal.\n"
"If the count is unspecified uses last count. The default\n"
"count is 0x100 bytes.\n\n");
printf("Current address is 0x%08x, current count is 0x%x\n",
(unsigned int)address, (unsigned int)count);
return;
}
/* Fetch address, defaut to last address if missing */
rc = fetch_uint32_arg(&address);
if(rc == 0) {
/* Fetch count, default to last count if missing */
fetch_uint32_arg(&count);
}
DumpBuffer((uint8_t *)address, count, address);
/* Update parameters for next time */
address = address+count;
}
ADD_CMD("d",CmdDump,"<addr> <count> Dump memory")