From 41b346d141d9a873b6e8304fe4bcf10ece668e96 Mon Sep 17 00:00:00 2001 From: Matthias Breithaupt Date: Tue, 4 Jun 2024 10:45:01 +0200 Subject: [PATCH] bios: mem_read: reduce number of reads on mapped registers (only supports 32-bit aligned addresses) Instead of reading each individual byte, causing multiple 4-byte requests to each address, this change results in a single read for each address. Signed-off-by: Matthias Breithaupt --- litex/soc/software/bios/helpers.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/litex/soc/software/bios/helpers.c b/litex/soc/software/bios/helpers.c index 0f8e9bfab..6b384ec0e 100644 --- a/litex/soc/software/bios/helpers.c +++ b/litex/soc/software/bios/helpers.c @@ -18,18 +18,24 @@ extern unsigned int _ftext, _edata_rom; #define NUMBER_OF_BYTES_ON_A_LINE 16 void dump_bytes(unsigned int *ptr, int count, unsigned long addr) { - char *data = (char *)ptr; + uint32_t *dptr = (uint32_t *)ptr; + char data[NUMBER_OF_BYTES_ON_A_LINE]; int line_bytes = 0, i = 0; + fputs("Memory dump:", stdout); while (count > 0) { line_bytes = (count > NUMBER_OF_BYTES_ON_A_LINE)? NUMBER_OF_BYTES_ON_A_LINE : count; + for (i = 0; i < line_bytes; i+=4){ + *((uint32_t*)&data[i]) = *(dptr++); + } + printf("\n0x%08lx ", addr); for (i = 0; i < line_bytes; i++) - printf("%02x ", *(unsigned char *)(data+i)); + printf("%02x ", (unsigned char)data[i]); for (; i < NUMBER_OF_BYTES_ON_A_LINE; i++) printf(" "); @@ -37,16 +43,15 @@ void dump_bytes(unsigned int *ptr, int count, unsigned long addr) printf(" "); for (i = 0; i 0x7e)) + if ((data[i] < 0x20) || (data[i] > 0x7e)) printf("."); else - printf("%c", *(data+i)); + printf("%c", data[i]); } for (; i < NUMBER_OF_BYTES_ON_A_LINE; i++) printf(" "); - data += (char)line_bytes; count -= line_bytes; addr += line_bytes; }