XINU
Functions | Variables
xsh_memdump.c File Reference
#include <xinu.h>
#include <string.h>
#include <stdio.h>
Include dependency graph for xsh_memdump.c:

Go to the source code of this file.

Functions

static uint32 parseval (char *)
 
shellcmd xsh_memdump (int nargs, char *args[])
 

Variables

uint32 start
 

Function Documentation

◆ parseval()

static uint32 parseval ( char *  string)
static

Definition at line 126 of file xsh_memdump.c.

References NULLCH.

Referenced by xsh_memdump().

129 {
130  uint32 value; /* value to return */
131  char ch; /* next character */
132 
133 
134  value = 0;
135 
136  /* argument string must consists of decimal digits or */
137  /* 0x followed by hex digits */
138 
139  ch = *string++;
140  if (ch == '0') { /* hexadecimal */
141  if (*string++ != 'x') {
142  return 0;
143  }
144  for (ch = *string++; ch != NULLCH; ch = *string++) {
145  if ((ch >= '0') && (ch <= '9') ) {
146  value = 16*value + (ch - '0');
147  } else if ((ch >= 'a') && (ch <= 'f') ) {
148  value = 16*value + 10 + (ch - 'a');
149  } else if ((ch >= 'A') && (ch <= 'F') ) {
150  value = 16*value + 10 + (ch - 'A');
151  } else {
152  return 0;
153  }
154  }
155  } else { /* decimal */
156  while (ch != NULLCH) {
157  if ( (ch < '0') || (ch > '9') ) {
158  return 0;
159  }
160  value = 10*value + (ch - '0');
161  ch = *string++;
162  }
163  }
164  return value;
165 }
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the caller graph for this function:

◆ xsh_memdump()

shellcmd xsh_memdump ( int  nargs,
char *  args[] 
)

Definition at line 15 of file xsh_memdump.c.

References FALSE, fprintf(), maxheap, parseval(), printf(), start, stderr, stop(), strncmp(), and TRUE.

16 {
17  bool8 force = FALSE; /* ignore address sanity checks */
18  uint32 begin; /* begining address */
19  uint32 stop; /* last address to dump */
20  uint32 length; /* length of region to dump */
21  int32 arg; /* index into args array */
22  uint32 l; /* counts length during dump */
23  int32 i; /* counts words during dump */
24  uint32 *addr; /* address to dump */
25  char *chptr; /* character address to dump */
26  char ch; /* next character to print */
27 
28  /* For argument '--help', emit help about the 'memdump' command */
29 
30  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
31  printf("Use: %s [-f] Address Length\n\n", args[0]);
32  printf("Description:\n");
33  printf("\tDumps Length bytes of memory begining at the\n");
34  printf("\tspecified starting address (both the address\n");
35  printf("\tand length can be specified in decimal or hex)\n");
36  printf("Options:\n");
37  printf("\t-f ignore sanity checks for addresses\n");
38  printf("\tAddress memory address at which to start\n");
39  printf("\tLength the number of bytes to dump\n");
40  printf("\t--help display this help and exit\n");
41  return 0;
42  }
43 
44  /* Check for valid number of arguments */
45 
46  if (nargs < 3 || nargs > 4) {
47  fprintf(stderr, "%s: incorrect number of arguments\n",
48  args[0]);
49  fprintf(stderr, "Try '%s --help' for more information\n",
50  args[0]);
51  return 1;
52  }
53 
54  arg = 1;
55  if (strncmp(args[arg], "-f", 2) == 0) {
56  force = TRUE;
57  arg++;
58  nargs --;
59  }
60 
61  if (nargs != 3) {
62  fprintf(stderr, "%s: too few arguments\n", args[0]);
63  fprintf(stderr, "Try '%s --help' for more information\n",
64  args[0]);
65  return 1;
66  }
67 
68  if ( (begin=parseval(args[arg])) == 0 ) {
69  fprintf(stderr, "%s: invalid begining address\n",
70  args[0]);
71  return 1;
72  }
73  if ( (length =parseval(args[arg+1])) == 0 ) {
74  fprintf(stderr, "%s: invalid length address\n",
75  args[0]);
76  return 1;
77  }
78 
79  /* Round begining address down to multiple of four and round */
80  /* length up to a multiple of four */
81 
82  begin &= ~0x3;
83  length = (length + 3) & ~0x3;
84 
85  /* Add length to begin address */
86 
87  stop = begin + length;
88 
89  /* verify that the address and length are reasonable */
90 
91  if ( force || ( (begin >= (uint32)&start) && (stop > begin) &&
92  (((void *)stop) < maxheap)) ) {
93 
94  /* values are valid; perform dump */
95 
96  chptr = (char *)begin;
97  for (l=0; l<length; l+=16) {
98  printf("%08x: ", begin);
99  addr = (uint32 *)begin;
100  for (i=0; i<4; i++) {
101  printf("%08x ",*addr++);
102  }
103  printf(" *");
104  for (i=0; i<16; i++) {
105  ch = *chptr++;
106  if ( (ch >= 0x20) && (ch <= 0x7e) ) {
107  printf("%c",ch);
108  } else {
109  printf(".");
110  }
111  }
112  printf("*\n");
113  begin += 16;
114  }
115  return 0;
116  } else {
117  printf("Values are out of range; use -f to force\n");
118  }
119  return 1;
120 }
int32 strncmp(const char *, const char *, int32)
#define stderr
Definition: stdio.h:17
byte bool8
Boolean値
Definition: kernel.h:36
int32 printf(const char *,...)
Definition: printf.c:13
int32 stop(char *s)
処理を停止させる。無限ループによる停止のため、復帰にはリセットが必要である。
Definition: initialize.c:249
#define FALSE
Boolean False(0)
Definition: kernel.h:63
uint32 start
#define TRUE
Boolean True(1)
Definition: kernel.h:65
void * maxheap
最上位かつ正常なヒープアドレス
Definition: meminit.c:10
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
static uint32 parseval(char *)
Definition: xsh_memdump.c:126
Here is the call graph for this function:

Variable Documentation

◆ start

uint32 start

Referenced by qs1(), and xsh_memdump().