From: Aaro Koskinen <[email protected]> Add 128-bit width if the compiler provides the needed type.
function old new delta devmem_main 412 517 +105 usage_messages 247 313 +66 .rodata 3553 3571 +18 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 3/0 up/down: 189/0) Total: 189 bytes Signed-off-by: Aaro Koskinen <[email protected]> Signed-off-by: Aaro Koskinen <[email protected]> --- miscutils/devmem.c | 113 +++++++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/miscutils/devmem.c b/miscutils/devmem.c index f9f0276bc..a6991886a 100644 --- a/miscutils/devmem.c +++ b/miscutils/devmem.c @@ -15,12 +15,15 @@ //kbuild:lib-$(CONFIG_DEVMEM) += devmem.o //usage:#define devmem_trivial_usage -//usage: "ADDRESS [WIDTH [VALUE]]" +//usage: "ADDRESS [WIDTH [VALUE]...]" //usage:#define devmem_full_usage "\n\n" //usage: "Read/write from physical address\n" //usage: "\n ADDRESS Address to act upon" //usage: "\n WIDTH Width (8/16/...)" //usage: "\n VALUE Data to be written" +#ifdef __SIZEOF_INT128__ +//usage: "\n For 128-bit data, provide 64-bit values (LOW, or HI and LOW)" +#endif #include "libbb.h" @@ -28,7 +31,7 @@ int devmem_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int devmem_main(int argc UNUSED_PARAM, char **argv) { void *map_base, *virt_addr; - uint64_t read_result; + uint64_t read_result = read_result; /* for compiler */ uint64_t writeval = writeval; /* for compiler */ off_t target; unsigned page_size, mapped_size, offset_in_page; @@ -96,51 +99,73 @@ int devmem_main(int argc UNUSED_PARAM, char **argv) virt_addr = (char*)map_base + offset_in_page; if (!argv[3]) { - switch (width) { - case 8: - read_result = *(volatile uint8_t*)virt_addr; - break; - case 16: - read_result = *(volatile uint16_t*)virt_addr; - break; - case 32: - read_result = *(volatile uint32_t*)virt_addr; - break; - case 64: - read_result = *(volatile uint64_t*)virt_addr; - break; - default: - bb_simple_error_msg_and_die("bad width"); +#ifdef __SIZEOF_INT128__ + if (width == 128) { + unsigned __int128 rd = + *(volatile unsigned __int128 *)virt_addr; + printf("0x%016llX%016llX\n", (uint64_t)(rd >> 64), + (uint64_t)rd); + } else +#endif + { + switch (width) { + case 8: + read_result = *(volatile uint8_t*)virt_addr; + break; + case 16: + read_result = *(volatile uint16_t*)virt_addr; + break; + case 32: + read_result = *(volatile uint32_t*)virt_addr; + break; + case 64: + read_result = *(volatile uint64_t*)virt_addr; + break; + default: + bb_simple_error_msg_and_die("bad width"); + } +// printf("Value at address 0x%"OFF_FMT"X (%p): 0x%llX\n", +// target, virt_addr, +// (unsigned long long)read_result); + /* Zero-padded output shows the width of access just done */ + printf("0x%0*llX\n", (width >> 2), (unsigned long long)read_result); } -// printf("Value at address 0x%"OFF_FMT"X (%p): 0x%llX\n", -// target, virt_addr, -// (unsigned long long)read_result); - /* Zero-padded output shows the width of access just done */ - printf("0x%0*llX\n", (width >> 2), (unsigned long long)read_result); } else { - switch (width) { - case 8: - *(volatile uint8_t*)virt_addr = writeval; -// read_result = *(volatile uint8_t*)virt_addr; - break; - case 16: - *(volatile uint16_t*)virt_addr = writeval; -// read_result = *(volatile uint16_t*)virt_addr; - break; - case 32: - *(volatile uint32_t*)virt_addr = writeval; -// read_result = *(volatile uint32_t*)virt_addr; - break; - case 64: - *(volatile uint64_t*)virt_addr = writeval; -// read_result = *(volatile uint64_t*)virt_addr; - break; - default: - bb_simple_error_msg_and_die("bad width"); +#ifdef __SIZEOF_INT128__ + if (width == 128) { + unsigned __int128 wr; + + wr = writeval; + if (argv[4]) + wr = (wr << 64) | bb_strtoull(argv[4], NULL, 0); + *(volatile unsigned __int128 *)virt_addr = wr; + } else +#endif + { + switch (width) { + case 8: + *(volatile uint8_t*)virt_addr = writeval; +// read_result = *(volatile uint8_t*)virt_addr; + break; + case 16: + *(volatile uint16_t*)virt_addr = writeval; +// read_result = *(volatile uint16_t*)virt_addr; + break; + case 32: + *(volatile uint32_t*)virt_addr = writeval; +// read_result = *(volatile uint32_t*)virt_addr; + break; + case 64: + *(volatile uint64_t*)virt_addr = writeval; +// read_result = *(volatile uint64_t*)virt_addr; + break; + default: + bb_simple_error_msg_and_die("bad width"); + } +// printf("Written 0x%llX; readback 0x%llX\n", +// (unsigned long long)writeval, +// (unsigned long long)read_result); } -// printf("Written 0x%llX; readback 0x%llX\n", -// (unsigned long long)writeval, -// (unsigned long long)read_result); } if (ENABLE_FEATURE_CLEAN_UP) { -- 2.17.0 _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
