From 8665031bb4c9f9874691397b3c6a0c63870bd3cb Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Thu, 16 Mar 2023 14:07:21 +0100 Subject: [PATCH] fw/testfw: Simplify hexdump --- hw/application_fpga/fw/testfw/main.c | 21 +++++++++++---------- hw/application_fpga/fw/tk1/lib.c | 23 +++++++++++++---------- hw/application_fpga/fw/tk1/lib.h | 2 +- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/hw/application_fpga/fw/testfw/main.c b/hw/application_fpga/fw/testfw/main.c index 5c49adb..233eaf2 100644 --- a/hw/application_fpga/fw/testfw/main.c +++ b/hw/application_fpga/fw/testfw/main.c @@ -71,21 +71,22 @@ void puthexn(uint8_t *p, int n) } } -void hexdump(uint8_t *buf, int len) +void hexdump(void *buf, int len) { - uint8_t *row; - uint8_t *byte; - uint8_t *max; + uint8_t *byte_buf = (uint8_t *)buf; - row = buf; - max = &buf[len]; - for (byte = 0; byte != max; row = byte) { - for (byte = row; byte != max && byte != (row + 16); byte++) { - puthex(*byte); + for (int i = 0; i < len; i ++) { + puthex(byte_buf[i]); + if (i % 2 == 1) { + writebyte(' '); } - puts("\r\n"); + if (i != 1 && i % 16 == 1) { + puts("\r\n"); + } } + + puts("\r\n"); } void reverseword(uint32_t *wordp) diff --git a/hw/application_fpga/fw/tk1/lib.c b/hw/application_fpga/fw/tk1/lib.c index eccab57..a91b086 100644 --- a/hw/application_fpga/fw/tk1/lib.c +++ b/hw/application_fpga/fw/tk1/lib.c @@ -30,8 +30,10 @@ static void htif_set_tohost(uint8_t dev, uint8_t cmd, int64_t data) { /* send data with specified device and command */ while (tohost.arr[0]) { +#ifndef S_SPLINT_S asm volatile("" : : "r"(fromhost.arr[0])); asm volatile("" : : "r"(fromhost.arr[1])); +#endif } htif_send(dev, cmd, data); } @@ -49,21 +51,22 @@ int htif_puts(const char *s) return 0; } -void htif_hexdump(uint8_t *buf, int len) +void htif_hexdump(void *buf, int len) { - uint8_t *row; - uint8_t *byte; - uint8_t *max; + uint8_t *byte_buf = (uint8_t *)buf; - row = buf; - max = &buf[len]; - for (byte = 0; byte != max; row = byte) { - for (byte = row; byte != max && byte != (row + 16); byte++) { - htif_puthex(*byte); + for (int i = 0; i < len; i++) { + htif_puthex(byte_buf[i]); + if (i % 2 == 1) { + (void)htif_putchar(' '); } - htif_lf(); + if (i != 1 && i % 16 == 1) { + htif_lf(); + } } + + htif_lf(); } void htif_putc(int ch) diff --git a/hw/application_fpga/fw/tk1/lib.h b/hw/application_fpga/fw/tk1/lib.h index 57a8dc0..39adf95 100644 --- a/hw/application_fpga/fw/tk1/lib.h +++ b/hw/application_fpga/fw/tk1/lib.h @@ -21,7 +21,7 @@ void htif_lf(); void htif_puthex(uint8_t c); void htif_putinthex(const uint32_t n); int htif_puts(const char *s); -void htif_hexdump(uint8_t *buf, int len); +void htif_hexdump(void *buf, int len); #endif void *memset(void *dest, int c, unsigned n);