Skip to content

Commit

Permalink
bios: mem_read: reduce number of reads on mapped registers (only supp…
Browse files Browse the repository at this point in the history
…orts 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 <[email protected]>
  • Loading branch information
m-byte committed Jun 4, 2024
1 parent 4bbd103 commit fea4165
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions litex/soc/software/bios/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,40 @@ 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(" ");

printf(" ");

for (i = 0; i<line_bytes; i++) {
if ((*(data+i) < 0x20) || (*(data+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;
}
Expand Down

0 comments on commit fea4165

Please sign in to comment.