diff --git a/lib/CPUs/MIPS/bsp/examples/bootloader/libsys_boot.c b/lib/CPUs/MIPS/bsp/examples/bootloader/libsys_boot.c index 91a99ea..cf3ef5e 100644 --- a/lib/CPUs/MIPS/bsp/examples/bootloader/libsys_boot.c +++ b/lib/CPUs/MIPS/bsp/examples/bootloader/libsys_boot.c @@ -140,3 +140,75 @@ void print_word(int word) } } +// --------------------------------------------------------------------------------- +// PrintBuffer8() +// Prints byte buffer as hex and ascii interpretation +// --------------------------------------------------------------------------------- +// _Parameters : +// pBuf: : IN: Buffer to display +// nbpr : Number of bytes per row to display +// len : Length of input buffer +// _Return: none +// +// --------------------------------------------------------------------------- +void PrintBuffer8(UINT8 *pBuf, int nbpr, int len) +{ + memdump(pBuf, 1, nbpr, len); +} + +void memdump(UINT8 *pBuf, int print_offset_only, int num_bytes_per_row, int len) +{ + int i, j, cnt_hex, cnt_asc, base; + unsigned char c; + + i = j = 0; + cnt_hex = len; + cnt_asc = len; + base = 0; + if (!print_offset_only) + base = (int)pBuf; + + do + { + print_word(base + i); + sputs(": "); + for (j=0; j < num_bytes_per_row; j++) + { + if (cnt_hex) + { + print_byte(pBuf[i+j]); + sputs(" "); + cnt_hex--; + } + else + { + sputs(" "); + break; + } + + } + + sputs(" "); + for (j=0; j < num_bytes_per_row; j++) + { + if (cnt_asc) + { + c = pBuf[i+j]; + if((c < 0x20) || (c > 0x7F)) + c = '.'; + + _putchar(c); + cnt_asc--; + } + else + { + sputs(" "); + break; + } + } + sputs("\n"); + i += num_bytes_per_row; + + } while (cnt_hex); +} + diff --git a/lib/CPUs/MIPS/bsp/examples/bootloader/libsys_boot.h b/lib/CPUs/MIPS/bsp/examples/bootloader/libsys_boot.h index 31ab047..241103b 100644 --- a/lib/CPUs/MIPS/bsp/examples/bootloader/libsys_boot.h +++ b/lib/CPUs/MIPS/bsp/examples/bootloader/libsys_boot.h @@ -45,6 +45,8 @@ int write(int file, char *ptr, int len); int sputs(char *pStr); void print_byte(char byte); void print_word(int word); +void PrintBuffer8(UINT8 *pBuf, int nbpr, int len); +void memdump(UINT8 *pBuf, int print_offset_only, int num_bytes_per_row, int len); #endif // LIBSYS_H