Changeset 4544
- Timestamp:
- 07/20/08 22:34:37 (5 years ago)
- File:
-
- 1 edited
-
developers/werner/poke/poke.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
developers/werner/poke/poke.c
r4543 r4544 16 16 #include <stdlib.h> 17 17 #include <stdio.h> 18 #include <string.h> 18 19 #include <fcntl.h> 19 20 #include <sys/mman.h> … … 21 22 22 23 #define PAGE_SIZE 4096 23 #define MEM( addr) (*(uint32_t *) (mem+((addr) & (PAGE_SIZE-1))))24 #define MEM(bits, addr) (*(uint##bits##_t *) (mem+((addr) & (PAGE_SIZE-1)))) 24 25 25 26 static volatile void *mem; … … 31 32 static void __attribute__((noreturn)) usage(const char *name) 32 33 { 33 fprintf(stderr, "usage: %s hex_address [value]\n", name);34 fprintf(stderr, "usage: %s [-8|-16|-32] hex_address [value]\n", name); 34 35 exit(1); 35 36 } … … 42 43 unsigned long addr; 43 44 uint32_t val; 45 int bits = 32; 46 char **args = argv+1; 44 47 45 48 fd = open("/dev/mem", O_RDWR); … … 48 51 exit(1); 49 52 } 53 if (argc > 1 && *argv[1] == '-') { 54 if (!strcmp(argv[1], "-8")) 55 bits = 8; 56 else if (!strcmp(argv[1], "-16")) 57 bits = 16; 58 else if (!strcmp(argv[1], "-32")) 59 bits = 32; 60 else 61 usage(*argv); 62 args++; 63 argc--; /* dirty */ 64 } 50 65 switch (argc) { 51 66 case 3: 52 val = strtoul(arg v[2], &end, 0);67 val = strtoul(args[1], &end, 0); 53 68 if (*end) 54 69 usage(*argv); 55 70 /* fall through */ 56 71 case 2: 57 addr = strtoul(arg v[1], &end, 16);72 addr = strtoul(args[0], &end, 16); 58 73 if (*end) 59 74 usage(*argv); … … 68 83 exit(1); 69 84 } 70 if (argc == 2) 71 printf("0x%08lx\n", (unsigned long) MEM(addr)); 72 else 73 MEM(addr) = val; 85 if (argc == 2) { 86 switch (bits) { 87 case 8: 88 printf("0x%02lx\n", (unsigned long) MEM(8, addr)); 89 break; 90 case 16: 91 printf("0x%04lx\n", (unsigned long) MEM(16, addr)); 92 break; 93 case 32: 94 printf("0x%08lx\n", (unsigned long) MEM(32, addr)); 95 break; 96 } 97 } 98 else { 99 switch (bits) { 100 case 8: 101 MEM(8, addr) = val; 102 break; 103 case 16: 104 MEM(16, addr) = val; 105 break; 106 case 32: 107 MEM(32, addr) = val; 108 break; 109 } 110 } 74 111 return 0; 75 112 }
Note: See TracChangeset
for help on using the changeset viewer.
