aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Koskinen <aaro.koskinen@nokia.com>2022-08-25 18:47:02 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2022-08-26 17:09:47 +0200
commitd432049f288c9acdc4a7caa729c68ceba3c5dca1 (patch)
tree15dd1779c05b7029b568958107c7cf36f9d3e13c
parent1a1220a5b05ca7fd86fde22c4a8bb9692a06670e (diff)
downloadbusybox-w32-d432049f288c9acdc4a7caa729c68ceba3c5dca1.tar.gz
busybox-w32-d432049f288c9acdc4a7caa729c68ceba3c5dca1.tar.bz2
busybox-w32-d432049f288c9acdc4a7caa729c68ceba3c5dca1.zip
devmem: add 128-bit width
Add 128-bit width if the compiler provides the needed type. function old new delta devmem_main 405 464 +59 .rodata 109025 109043 +18 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 77/0) Total: 77 bytes Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/devmem.c68
1 files changed, 44 insertions, 24 deletions
diff --git a/miscutils/devmem.c b/miscutils/devmem.c
index f9f0276bc..f21621bd6 100644
--- a/miscutils/devmem.c
+++ b/miscutils/devmem.c
@@ -29,7 +29,6 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
29{ 29{
30 void *map_base, *virt_addr; 30 void *map_base, *virt_addr;
31 uint64_t read_result; 31 uint64_t read_result;
32 uint64_t writeval = writeval; /* for compiler */
33 off_t target; 32 off_t target;
34 unsigned page_size, mapped_size, offset_in_page; 33 unsigned page_size, mapped_size, offset_in_page;
35 int fd; 34 int fd;
@@ -64,9 +63,6 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
64 width = strchrnul(bhwl, (argv[2][0] | 0x20)) - bhwl; 63 width = strchrnul(bhwl, (argv[2][0] | 0x20)) - bhwl;
65 width = sizes[width]; 64 width = sizes[width];
66 } 65 }
67 /* VALUE */
68 if (argv[3])
69 writeval = bb_strtoull(argv[3], NULL, 0);
70 } else { /* argv[2] == NULL */ 66 } else { /* argv[2] == NULL */
71 /* make argv[3] to be a valid thing to fetch */ 67 /* make argv[3] to be a valid thing to fetch */
72 argv--; 68 argv--;
@@ -96,28 +92,46 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
96 virt_addr = (char*)map_base + offset_in_page; 92 virt_addr = (char*)map_base + offset_in_page;
97 93
98 if (!argv[3]) { 94 if (!argv[3]) {
99 switch (width) { 95#ifdef __SIZEOF_INT128__
100 case 8: 96 if (width == 128) {
101 read_result = *(volatile uint8_t*)virt_addr; 97 unsigned __int128 rd =
102 break; 98 *(volatile unsigned __int128 *)virt_addr;
103 case 16: 99 printf("0x%016llX%016llX\n",
104 read_result = *(volatile uint16_t*)virt_addr; 100 (unsigned long long)(uint64_t)(rd >> 64),
105 break; 101 (unsigned long long)(uint64_t)rd
106 case 32: 102 );
107 read_result = *(volatile uint32_t*)virt_addr; 103 } else
108 break; 104#endif
109 case 64: 105 {
110 read_result = *(volatile uint64_t*)virt_addr; 106 switch (width) {
111 break; 107 case 8:
112 default: 108 read_result = *(volatile uint8_t*)virt_addr;
113 bb_simple_error_msg_and_die("bad width"); 109 break;
110 case 16:
111 read_result = *(volatile uint16_t*)virt_addr;
112 break;
113 case 32:
114 read_result = *(volatile uint32_t*)virt_addr;
115 break;
116 case 64:
117 read_result = *(volatile uint64_t*)virt_addr;
118 break;
119 default:
120 bb_simple_error_msg_and_die("bad width");
121 }
122// printf("Value at address 0x%"OFF_FMT"X (%p): 0x%llX\n",
123// target, virt_addr,
124// (unsigned long long)read_result);
125 /* Zero-padded output shows the width of access just done */
126 printf("0x%0*llX\n", (width >> 2), (unsigned long long)read_result);
114 } 127 }
115// printf("Value at address 0x%"OFF_FMT"X (%p): 0x%llX\n",
116// target, virt_addr,
117// (unsigned long long)read_result);
118 /* Zero-padded output shows the width of access just done */
119 printf("0x%0*llX\n", (width >> 2), (unsigned long long)read_result);
120 } else { 128 } else {
129 /* parse VALUE */
130#ifdef __SIZEOF_INT128__
131 unsigned __int128 writeval = strtoumax(argv[3], NULL, 0);
132#else
133 uint64_t writeval = bb_strtoull(argv[3], NULL, 0);
134#endif
121 switch (width) { 135 switch (width) {
122 case 8: 136 case 8:
123 *(volatile uint8_t*)virt_addr = writeval; 137 *(volatile uint8_t*)virt_addr = writeval;
@@ -135,6 +149,12 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
135 *(volatile uint64_t*)virt_addr = writeval; 149 *(volatile uint64_t*)virt_addr = writeval;
136// read_result = *(volatile uint64_t*)virt_addr; 150// read_result = *(volatile uint64_t*)virt_addr;
137 break; 151 break;
152#ifdef __SIZEOF_INT128__
153 case 128:
154 *(volatile unsigned __int128 *)virt_addr = writeval;
155// read_result = *(volatile uint64_t*)virt_addr;
156 break;
157#endif
138 default: 158 default:
139 bb_simple_error_msg_and_die("bad width"); 159 bb_simple_error_msg_and_die("bad width");
140 } 160 }