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 <m.breithaupt@vogl-electronic.com>
This commit is contained in:
Matthias Breithaupt 2024-06-04 10:45:01 +02:00 committed by Fin Maaß
parent 03a0a6fd9b
commit 41b346d141
1 changed files with 10 additions and 5 deletions

View File

@ -18,18 +18,24 @@ extern unsigned int _ftext, _edata_rom;
#define NUMBER_OF_BYTES_ON_A_LINE 16 #define NUMBER_OF_BYTES_ON_A_LINE 16
void dump_bytes(unsigned int *ptr, int count, unsigned long addr) 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; int line_bytes = 0, i = 0;
fputs("Memory dump:", stdout); fputs("Memory dump:", stdout);
while (count > 0) { while (count > 0) {
line_bytes = line_bytes =
(count > NUMBER_OF_BYTES_ON_A_LINE)? (count > NUMBER_OF_BYTES_ON_A_LINE)?
NUMBER_OF_BYTES_ON_A_LINE : count; NUMBER_OF_BYTES_ON_A_LINE : count;
for (i = 0; i < line_bytes; i+=4){
*((uint32_t*)&data[i]) = *(dptr++);
}
printf("\n0x%08lx ", addr); printf("\n0x%08lx ", addr);
for (i = 0; i < line_bytes; i++) 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++) for (; i < NUMBER_OF_BYTES_ON_A_LINE; i++)
printf(" "); printf(" ");
@ -37,16 +43,15 @@ void dump_bytes(unsigned int *ptr, int count, unsigned long addr)
printf(" "); printf(" ");
for (i = 0; i<line_bytes; i++) { for (i = 0; i<line_bytes; i++) {
if ((*(data+i) < 0x20) || (*(data+i) > 0x7e)) if ((data[i] < 0x20) || (data[i] > 0x7e))
printf("."); printf(".");
else else
printf("%c", *(data+i)); printf("%c", data[i]);
} }
for (; i < NUMBER_OF_BYTES_ON_A_LINE; i++) for (; i < NUMBER_OF_BYTES_ON_A_LINE; i++)
printf(" "); printf(" ");
data += (char)line_bytes;
count -= line_bytes; count -= line_bytes;
addr += line_bytes; addr += line_bytes;
} }