| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- /* peek command: hex dump of physical memory, including MMIO registers.
- *
- * peek <addr> [len] default len 64, max 256
- * poke <addr> <val> write one dword (e.g. an MMIO register), print
- * the read-back
- *
- * Addresses are physical. Lowmem is read through the identity map, RAM
- * above it (highmem) through a temporary kmap, and anything else (MMIO)
- * through its ioremap() window mapping, created on demand (4 KB,
- * uncached) when no driver mapped it yet.
- */
- #include "io.h"
- #include "paging.h"
- static void put_hex2(unsigned int v)
- {
- static const char hex[] = "0123456789ABCDEF";
- io_putchar(hex[(v >> 4) & 0xF]);
- io_putchar(hex[v & 0xF]);
- }
- static void put_hex8(unsigned int v)
- {
- put_hex2((v >> 24) & 0xFF);
- put_hex2((v >> 16) & 0xFF);
- put_hex2((v >> 8) & 0xFF);
- put_hex2(v & 0xFF);
- }
- static int hexval(char c)
- {
- if (c >= '0' && c <= '9')
- return c - '0';
- if (c >= 'a' && c <= 'f')
- return c - 'a' + 10;
- if (c >= 'A' && c <= 'F')
- return c - 'A' + 10;
- return -1;
- }
- static int parse_hex(const char *s, unsigned int *out, const char **endp)
- {
- unsigned int v = 0;
- int digits = 0, d;
- if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
- s += 2;
- while ((d = hexval(*s)) >= 0) {
- v = (v << 4) | (unsigned int)d;
- digits++;
- s++;
- }
- if (!digits)
- return -1;
- *out = v;
- *endp = s;
- return 0;
- }
- void program_peek_main(const char *arg)
- {
- const char *p = arg;
- const volatile unsigned char *mem;
- unsigned int addr, len = 64, i, j;
- if (parse_hex(p, &addr, &p) != 0) {
- io_putstr("peek: usage peek <hexaddr> [len<=256]\n");
- return;
- }
- while (*p == ' ')
- p++;
- if (*p) {
- if (parse_hex(p, &len, &p) != 0 || len == 0 || len > 256) {
- io_putstr("peek: usage peek <hexaddr> [len<=256]\n");
- return;
- }
- }
- while (*p == ' ')
- p++;
- if (*p) {
- io_putstr("peek: usage peek <hexaddr> [len<=256]\n");
- return;
- }
- for (i = 0; i < len; i += 16) {
- put_hex8(addr + i);
- io_putstr(": ");
- for (j = 0; j < 16 && i + j < len; j++) {
- void *km;
- mem = paging_debug_map(addr + i + j, &km);
- if (!mem) {
- io_putstr("?? ");
- continue;
- }
- put_hex2(*mem);
- if (km)
- kunmap(km);
- io_putchar(' ');
- }
- io_putchar('\n');
- }
- }
- /* poke <addr> <val>: write one 32-bit dword and print the read-back. Used to
- * drive MMIO experiments (e.g. the GPU's PIO method interface) from the
- * shell. */
- void program_poke_main(const char *arg)
- {
- const char *p = arg;
- volatile unsigned int *mem;
- unsigned int addr, val, back;
- if (parse_hex(p, &addr, &p) != 0) {
- io_putstr("poke: usage poke <hexaddr> <hexval>\n");
- return;
- }
- while (*p == ' ')
- p++;
- if (parse_hex(p, &val, &p) != 0) {
- io_putstr("poke: usage poke <hexaddr> <hexval>\n");
- return;
- }
- while (*p == ' ')
- p++;
- if (*p) {
- io_putstr("poke: usage poke <hexaddr> <hexval>\n");
- return;
- }
- {
- void *km;
- mem = (volatile unsigned int *)paging_debug_map(addr & ~3u, &km);
- if (!mem) {
- io_putstr("poke: cannot map that address\n");
- return;
- }
- *mem = val;
- back = *mem;
- if (km)
- kunmap(km);
- }
- io_putstr("poke ");
- put_hex8(addr & ~3u);
- io_putstr(" <- ");
- put_hex8(val);
- io_putstr(" reads ");
- put_hex8(back);
- io_putchar('\n');
- }
|