diff options
author | msmith <msmith@FreeBSD.org> | 1998-09-19 01:31:28 +0000 |
---|---|---|
committer | msmith <msmith@FreeBSD.org> | 1998-09-19 01:31:28 +0000 |
commit | c820301756f1a0e998ef6a618030c9c195207a32 (patch) | |
tree | 2e77cfab0494af5416a73c04240747f9f9613a7f /sys/boot/common/misc.c | |
parent | fb53c69912b8cf3f11b3513f209c78221a194560 (diff) | |
download | FreeBSD-src-c820301756f1a0e998ef6a618030c9c195207a32.zip FreeBSD-src-c820301756f1a0e998ef6a618030c9c195207a32.tar.gz |
Add a generic hexdump tool for debugging purposes.
Diffstat (limited to 'sys/boot/common/misc.c')
-rw-r--r-- | sys/boot/common/misc.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/sys/boot/common/misc.c b/sys/boot/common/misc.c index 2999da5..6333eaf 100644 --- a/sys/boot/common/misc.c +++ b/sys/boot/common/misc.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: misc.c,v 1.1.1.1 1998/08/21 03:17:41 msmith Exp $ + * $Id: misc.c,v 1.2 1998/09/03 02:10:07 msmith Exp $ */ #include <string.h> @@ -87,3 +87,43 @@ strdupout(vm_offset_t str) } return(result); } + +/* + * Display a region in traditional hexdump format. + */ +void +hexdump(caddr_t region, size_t len) +{ + caddr_t line; + int x, c; + char lbuf[80]; +#define emit(fmt, args...) {sprintf(lbuf, fmt , ## args); pager_output(lbuf);} + + pager_open(); + for (line = region; line < (region + len); line += 16) { + emit("%08x ", line); + + for (x = 0; x < 16; x++) { + if ((line + x) < (region + len)) { + emit("%02x ", *(u_int8_t *)(line + x)); + } else { + emit("-- "); + } + if (x == 7) + emit(" "); + } + emit(" |"); + for (x = 0; x < 16; x++) { + if ((line + x) < (region + len)) { + c = *(u_int8_t *)(line + x); + if ((c < ' ') || (c > '~')) /* !isprint(c) */ + c = '.'; + emit("%c", c); + } else { + emit(" "); + } + } + emit("|\n"); + } + pager_close(); +} |