/* * Crusty Old Ram Dump code - circa 1996, hacked for CS560 * A. J. Wright - * For free use in the CS560 class. * * Two Arguments: * 1. An offset from the beginning of main_memory to start printing * 2. The number of bytes to print. * * Output: pretty-printed RAM dump to stdout * * Example ... and perhaps a hint. * dumpRam (pcb->base + pcb->limit - 160, 160); * * Your milage may vary. Good luck. * * NOTE: This does not meet the coding standards for CS560. */ /* You may need to modify these, depending on your code. */ #include #include "jos.h" void dumpRam (size_t start, size_t length) { unsigned char *aBuf = &main_memory[start]; int Current = 0, Begin = 0, i; while (Current < length) { printf (" %.8x ", (unsigned int) Current + start); Begin = Current; for (i = 0; i < 8; i++) { printf ("%.2hx ", aBuf[Current++]); if (Current > length) { while (++i < 8) printf (" "); break; } } if (Current <= length) { printf ("- "); for (i = 0; i < 8; i++) { printf ("%.2hx ", aBuf[Current++]); if (Current > length) { while (++i < 8) printf (" "); break; } } printf (" "); } else printf (" "); for (i = 0; i < 16; i++) { if (isprint ((int) aBuf[Begin])) printf ("%c", aBuf[Begin]); else printf ("_"); Begin++; if (Begin > length) { printf ("\n"); return; } } printf ("\n"); } }