fw/testfw: Simplify hexdump

This commit is contained in:
Michael Cardell Widerkrantz 2023-03-16 14:07:21 +01:00
parent 7ce1d9fe06
commit 8665031bb4
No known key found for this signature in database
GPG Key ID: D3DB3DDF57E704E5
3 changed files with 25 additions and 21 deletions

View File

@ -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_buf = (uint8_t *)buf;
uint8_t *byte;
uint8_t *max;
row = buf; for (int i = 0; i < len; i ++) {
max = &buf[len]; puthex(byte_buf[i]);
for (byte = 0; byte != max; row = byte) { if (i % 2 == 1) {
for (byte = row; byte != max && byte != (row + 16); byte++) { writebyte(' ');
puthex(*byte);
} }
puts("\r\n"); if (i != 1 && i % 16 == 1) {
puts("\r\n");
}
} }
puts("\r\n");
} }
void reverseword(uint32_t *wordp) void reverseword(uint32_t *wordp)

View File

@ -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 */ /* send data with specified device and command */
while (tohost.arr[0]) { while (tohost.arr[0]) {
#ifndef S_SPLINT_S
asm volatile("" : : "r"(fromhost.arr[0])); asm volatile("" : : "r"(fromhost.arr[0]));
asm volatile("" : : "r"(fromhost.arr[1])); asm volatile("" : : "r"(fromhost.arr[1]));
#endif
} }
htif_send(dev, cmd, data); htif_send(dev, cmd, data);
} }
@ -49,21 +51,22 @@ int htif_puts(const char *s)
return 0; return 0;
} }
void htif_hexdump(uint8_t *buf, int len) void htif_hexdump(void *buf, int len)
{ {
uint8_t *row; uint8_t *byte_buf = (uint8_t *)buf;
uint8_t *byte;
uint8_t *max;
row = buf; for (int i = 0; i < len; i++) {
max = &buf[len]; htif_puthex(byte_buf[i]);
for (byte = 0; byte != max; row = byte) { if (i % 2 == 1) {
for (byte = row; byte != max && byte != (row + 16); byte++) { (void)htif_putchar(' ');
htif_puthex(*byte);
} }
htif_lf(); if (i != 1 && i % 16 == 1) {
htif_lf();
}
} }
htif_lf();
} }
void htif_putc(int ch) void htif_putc(int ch)

View File

@ -21,7 +21,7 @@ void htif_lf();
void htif_puthex(uint8_t c); void htif_puthex(uint8_t c);
void htif_putinthex(const uint32_t n); void htif_putinthex(const uint32_t n);
int htif_puts(const char *s); int htif_puts(const char *s);
void htif_hexdump(uint8_t *buf, int len); void htif_hexdump(void *buf, int len);
#endif #endif
void *memset(void *dest, int c, unsigned n); void *memset(void *dest, int c, unsigned n);