Re: hexdump in boot loader

2019-11-27 Thread Theo de Raadt
Alexander Bluhm  wrote:

> On Tue, Nov 26, 2019 at 04:51:36PM -0700, Theo de Raadt wrote:
> > ok with me
> 
> So here is the full diff with all architecture makefiles that may
> be affected.
> 
> I have done a build release on amd64.  Boot loader on i386, armv7,
> arm64, macppc compiles and links.  hppa, landisk, octeon is just a
> guess what should be done.

i386 floppy tends to be the tight one.  If it fits, the others should also.

> Is more testing needed?

no, it's fine.  I'll keen an eye out for errors during all-arch builds soon.



Re: hexdump in boot loader

2019-11-27 Thread Alexander Bluhm
On Tue, Nov 26, 2019 at 04:51:36PM -0700, Theo de Raadt wrote:
> ok with me

So here is the full diff with all architecture makefiles that may
be affected.

I have done a build release on amd64.  Boot loader on i386, armv7,
arm64, macppc compiles and links.  hppa, landisk, octeon is just a
guess what should be done.

Is more testing needed?

bluhm

Index: arch/amd64/stand/boot/Makefile
===
RCS file: /data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/boot/Makefile,v
retrieving revision 1.43
diff -u -p -r1.43 Makefile
--- arch/amd64/stand/boot/Makefile  29 Oct 2019 02:55:50 -  1.43
+++ arch/amd64/stand/boot/Makefile  27 Nov 2019 14:17:56 -
@@ -32,7 +32,8 @@ SRCS+=softraid_amd64.c
 .endif

 .PATH: ${S}/lib/libsa
-SRCS+= alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memmove.c memset.c 
printf.c \
+SRCS+= alloc.c ctime.c exit.c getchar.c hexdump.c \
+   memcmp.c memcpy.c memmove.c memset.c printf.c \
putchar.c snprintf.c strcmp.c strerror.c strlen.c strncmp.c strncpy.c \
strtol.c strtoll.c
 SRCS+= close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c fchmod.c \
Index: arch/amd64/stand/cdboot/Makefile
===
RCS file: /data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/cdboot/Makefile,v
retrieving revision 1.38
diff -u -p -r1.38 Makefile
--- arch/amd64/stand/cdboot/Makefile29 Oct 2019 02:55:50 -  1.38
+++ arch/amd64/stand/cdboot/Makefile27 Nov 2019 14:17:56 -
@@ -25,7 +25,7 @@ SRCS+=softraid_amd64.c
 SRCS+= cmd.c vars.c bootarg.c

 .PATH: ${S}/lib/libsa
-SRCS+= alloc.c exit.c getchar.c putchar.c strcmp.c strlen.c \
+SRCS+= alloc.c exit.c getchar.c hexdump.c putchar.c strcmp.c strlen.c \
strncmp.c memcmp.c memcpy.c memmove.c memset.c printf.c snprintf.c \
strerror.c strncpy.c strtol.c strtoll.c ctime.c strlcpy.c
 SRCS+= close.c closeall.c dev.c disklabel.c dkcksum.c fchmod.c fstat.c \
Index: arch/amd64/stand/efi32/Makefile.common
===
RCS file: 
/data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/efi32/Makefile.common,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile.common
--- arch/amd64/stand/efi32/Makefile.common  29 Oct 2019 02:55:50 -  
1.3
+++ arch/amd64/stand/efi32/Makefile.common  27 Nov 2019 14:17:56 -
@@ -32,7 +32,8 @@ SRCS+=memprobe.c
 SRCS+= boot.c bootarg.c cmd.c vars.c

 .PATH: ${S}/lib/libsa
-SRCS+= alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memmove.c memset.c 
printf.c \
+SRCS+= alloc.c ctime.c exit.c getchar.c hexdump.c \
+   memcmp.c memcpy.c memmove.c memset.c printf.c \
putchar.c snprintf.c strcmp.c strerror.c strlen.c strncmp.c strncpy.c \
strtol.c strtoll.c
 SRCS+= close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c fchmod.c \
Index: arch/amd64/stand/efi64/Makefile.common
===
RCS file: 
/data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/efi64/Makefile.common,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile.common
--- arch/amd64/stand/efi64/Makefile.common  29 Oct 2019 02:55:50 -  
1.3
+++ arch/amd64/stand/efi64/Makefile.common  27 Nov 2019 14:17:56 -
@@ -32,7 +32,8 @@ SRCS+=memprobe.c
 SRCS+= boot.c bootarg.c cmd.c vars.c

 .PATH: ${S}/lib/libsa
-SRCS+= alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memmove.c memset.c 
printf.c \
+SRCS+= alloc.c ctime.c exit.c getchar.c hexdump.c \
+   memcmp.c memcpy.c memmove.c memset.c printf.c \
putchar.c snprintf.c strcmp.c strerror.c strlen.c strncmp.c strncpy.c \
strtol.c strtoll.c
 SRCS+= close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c fchmod.c \
Index: arch/amd64/stand/efiboot/Makefile.common
===
RCS file: 
/data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/efiboot/Makefile.common,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile.common
--- arch/amd64/stand/efiboot/Makefile.common29 Oct 2019 02:55:51 -  
1.18
+++ arch/amd64/stand/efiboot/Makefile.common27 Nov 2019 14:17:56 -
@@ -32,7 +32,8 @@ SRCS+=memprobe.c
 SRCS+= boot.c bootarg.c cmd.c vars.c

 .PATH: ${S}/lib/libsa
-SRCS+= alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memmove.c memset.c 
printf.c \
+SRCS+= alloc.c ctime.c exit.c getchar.c hexdump.c \
+   memcmp.c memcpy.c memmove.c memset.c printf.c \
putchar.c snprintf.c strcmp.c strerror.c strlen.c strncmp.c strncpy.c \
strtol.c strtoll.c
 SRCS+= close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c \
Index: arch/amd64/stand/pxeboot/Makefile
===
RCS file: /data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/pxeboot/Makefile,v
retrieving revision 1.36
diff -u -p -r1.36 Makefile
-

Re: hexdump in boot loader

2019-11-26 Thread Theo de Raadt
>This strtoll() version has less error checking, does not work with
>addresses >=3D 0x8000, but reduces stripped boot size by
>64 bytes.

easier to read.

that type of compromise is very common in the bootblocks.

ok with me



Re: hexdump in boot loader

2019-11-26 Thread Alexander Bluhm
On Tue, Nov 26, 2019 at 04:05:34PM -0700, Theo de Raadt wrote:
> >On Tue, Nov 26, 2019 at 05:27:03PM -0500, Ted Unangst wrote:
> >> why not use strtol here?
> >
> >Basically I was not aware that it is available in the boot loader.
> >And I need an unsigned long.  Should I change the diff anyway?
>
> bootblocks can be tight on some media, so use the smallest code.

This strtoll() version has less error checking, does not work with
addresses >= 0x8000, but reduces stripped boot size by
64 bytes.

bluhm

Index: arch/amd64/stand/efiboot/Makefile.common
===
RCS file: 
/data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/efiboot/Makefile.common,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile.common
--- arch/amd64/stand/efiboot/Makefile.common29 Oct 2019 02:55:51 -  
1.18
+++ arch/amd64/stand/efiboot/Makefile.common26 Nov 2019 21:57:05 -
@@ -32,7 +32,8 @@ SRCS+=memprobe.c
 SRCS+= boot.c bootarg.c cmd.c vars.c

 .PATH: ${S}/lib/libsa
-SRCS+= alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memmove.c memset.c 
printf.c \
+SRCS+= alloc.c ctime.c exit.c hexdump.c getchar.c \
+   memcmp.c memcpy.c memmove.c memset.c printf.c \
putchar.c snprintf.c strcmp.c strerror.c strlen.c strncmp.c strncpy.c \
strtol.c strtoll.c
 SRCS+= close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c \
Index: lib/libsa/hexdump.c
===
RCS file: lib/libsa/hexdump.c
diff -N lib/libsa/hexdump.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ lib/libsa/hexdump.c 26 Nov 2019 23:42:22 -
@@ -0,0 +1,52 @@
+/* $OpenBSD$   */
+/*
+ * Copyright (c) 2019 Alexander Bluhm 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+
+#include "stand.h"
+
+void
+hexdump(const void *addr, size_t size)
+{
+   const unsigned char *line, *end;
+   int byte;
+
+   end = (const char *)addr + size;
+   for (line = addr; line < end; line += 16) {
+   printf("%08lx  ", line);
+   for (byte = 0; byte < 16; byte++) {
+   if (&line[byte] < end)
+   printf("%02x ", line[byte]);
+   else
+   printf("   ");
+   if (byte == 7)
+   printf(" ");
+   }
+   printf(" |");
+   for (byte = 0; byte < 16; byte++) {
+   if (&line[byte] < end) {
+   if (line[byte] >= ' ' && line[byte] <= '~')
+   printf("%c", line[byte]);
+   else
+   printf(".");
+   } else
+   break;
+   }
+   printf("|\n");
+   }
+   printf("%08lx\n", end);
+}
Index: lib/libsa/stand.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/lib/libsa/stand.h,v
retrieving revision 1.68
diff -u -p -r1.68 stand.h
--- lib/libsa/stand.h   1 Nov 2019 20:54:52 -   1.68
+++ lib/libsa/stand.h   26 Nov 2019 21:57:05 -
@@ -146,6 +146,7 @@ __dead void _rtt(void) __attribute__((no
 #define bcmp(s1,s2,n)  (memcmp((s2),(s1),(n)))
 #definebcopy(s1,s2,n)  ((void)memmove((s2),(s1),(n)))
 void   explicit_bzero(void *, size_t);
+void   hexdump(const void *, size_t);
 void   *memcpy(void *, const void *, size_t);
 void   *memmove(void *, const void *, size_t);
 intmemcmp(const void *, const void *, size_t);
Index: stand/boot/cmd.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/stand/boot/cmd.c,v
retrieving revision 1.65
diff -u -p -r1.65 cmd.c
--- stand/boot/cmd.c3 Aug 2019 15:22:19 -   1.65
+++ stand/boot/cmd.c26 Nov 2019 23:42:22 -
@@ -39,6 +39,7 @@
 static int Xboot(void);
 static int Xecho(void);
 static int Xhelp(void);
+static int Xhexdump(void);
 static int Xls(void);
 static int Xnop(void);
 static int Xreboot(void);
@@ -62,6 +63,7 @@ const struct cmd_table cmd_table[] = {
{"echo",   CMDT_CMD, Xecho},
{"env",CMDT_CMD

Re: hexdump in boot loader

2019-11-26 Thread Mark Kettenis
> Date: Tue, 26 Nov 2019 23:22:14 +0100
> From: Alexander Bluhm 
> 
> Hi,
> 
> I am currently debugging an UEFI boot problem.  A hexdump in the
> boot loader would be convenient.
> 
> boot> hexdump 0x10 20
> 0010  53 ff 00 f0 54 ff 00 f0  53 ff 00 f0 53 ff 00 f0  |S...T...S...S...|
> 0020  a5 fe 00 f0   ||
> 0024
> 
> Do we want such a feature?

Sounds useful to me.

> If so, I would adapt the other's architectures Makefiles.
> 
> bluhm
> 
> Index: arch/amd64/stand/boot/Makefile
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/boot/Makefile,v
> retrieving revision 1.43
> diff -u -p -r1.43 Makefile
> --- arch/amd64/stand/boot/Makefile29 Oct 2019 02:55:50 -  1.43
> +++ arch/amd64/stand/boot/Makefile26 Nov 2019 22:19:50 -
> @@ -32,7 +32,8 @@ SRCS+=  softraid_amd64.c
>  .endif
> 
>  .PATH:   ${S}/lib/libsa
> -SRCS+=   alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memmove.c 
> memset.c printf.c \
> +SRCS+=   alloc.c ctime.c exit.c hexdump.c getchar.c \
> + memcmp.c memcpy.c memmove.c memset.c printf.c \
>   putchar.c snprintf.c strcmp.c strerror.c strlen.c strncmp.c strncpy.c \
>   strtol.c strtoll.c
>  SRCS+=   close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c 
> fchmod.c \
> Index: arch/amd64/stand/efiboot/Makefile.common
> ===
> RCS file: 
> /data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/efiboot/Makefile.common,v
> retrieving revision 1.18
> diff -u -p -r1.18 Makefile.common
> --- arch/amd64/stand/efiboot/Makefile.common  29 Oct 2019 02:55:51 -  
> 1.18
> +++ arch/amd64/stand/efiboot/Makefile.common  26 Nov 2019 21:57:05 -
> @@ -32,7 +32,8 @@ SRCS+=  memprobe.c
>  SRCS+=   boot.c bootarg.c cmd.c vars.c
> 
>  .PATH:   ${S}/lib/libsa
> -SRCS+=   alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memmove.c 
> memset.c printf.c \
> +SRCS+=   alloc.c ctime.c exit.c hexdump.c getchar.c \
> + memcmp.c memcpy.c memmove.c memset.c printf.c \
>   putchar.c snprintf.c strcmp.c strerror.c strlen.c strncmp.c strncpy.c \
>   strtol.c strtoll.c
>  SRCS+=   close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c \
> Index: lib/libsa/hexdump.c
> ===
> RCS file: lib/libsa/hexdump.c
> diff -N lib/libsa/hexdump.c
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ lib/libsa/hexdump.c   26 Nov 2019 22:17:53 -
> @@ -0,0 +1,52 @@
> +/*   $OpenBSD$   */
> +/*
> + * Copyright (c) 2019 Alexander Bluhm 
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include 
> +
> +#include "stand.h"
> +
> +void
> +hexdump(const void *addr, size_t size)
> +{
> + const unsigned char *line, *end;
> + int byte;
> +
> + end = (const char *)addr + size;
> + for (line = addr; line < end; line += 16) {
> + printf("%08x  ", line);
> + for (byte = 0; byte < 16; byte++) {
> + if (&line[byte] < end)
> + printf("%02x ", line[byte]);
> + else
> + printf("   ");
> + if (byte == 7)
> + printf(" ");
> + }
> + printf(" |");
> + for (byte = 0; byte < 16; byte++) {
> + if (&line[byte] < end) {
> + if (line[byte] >= ' ' && line[byte] <= '~')
> + printf("%c", line[byte]);
> + else
> + printf(".");
> + } else
> + break;
> + }
> + printf("|\n");
> + }
> + printf("%08x\n", end);
> +}
> Index: lib/libsa/stand.h
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/lib/libsa/stand.h,v
> retrieving revision 1.68
> diff -u -p -r1.68 stand.h
> --- lib/libsa/stand.h 1 Nov 2019 20:54:52 -   1.68
> +++ lib/libsa/stand.h 26 Nov 2019 21:57:05 -
> @@ -146,6 +146,7 @@

Re: hexdump in boot loader

2019-11-26 Thread Theo de Raadt
>On Tue, Nov 26, 2019 at 05:27:03PM -0500, Ted Unangst wrote:
>> why not use strtol here?
>
>Basically I was not aware that it is available in the boot loader.
>And I need an unsigned long.  Should I change the diff anyway?

bootblocks can be tight on some media, so use the smallest code.



Re: hexdump in boot loader

2019-11-26 Thread Alexander Bluhm
On Tue, Nov 26, 2019 at 05:27:03PM -0500, Ted Unangst wrote:
> why not use strtol here?

Basically I was not aware that it is available in the boot loader.
And I need an unsigned long.  Should I change the diff anyway?

bluhm



Re: hexdump in boot loader

2019-11-26 Thread Ted Unangst
Alexander Bluhm wrote:
> +
> + for (n = 1; n < cmd.argc; n++) {
> + p = cmd.argv[n];
> + if (*p == '0') {
> + p++;
> + if (*p == 'x' || *p == 'X') {
> + p++;
> + b = 16;
> + } else
> + b = 8;
> + } else
> + b = 10;
> + val[n-1] = 0;
> + for (; *p != '\0'; p++) {
> + if (*p >= '0' && *p <= '9')
> + d = *p - '0';
> + else if (*p >= 'a' && *p <= 'z')
> + d = *p - 'a' + 10;
> + else if (*p >= 'A' && *p <= 'Z')
> + d = *p - 'A' + 10;
> + else
> + goto err;
> + if (d >= b)
> + goto err;
> + val[n-1] = val[n-1] * b + d;

why not use strtol here?



hexdump in boot loader

2019-11-26 Thread Alexander Bluhm
Hi,

I am currently debugging an UEFI boot problem.  A hexdump in the
boot loader would be convenient.

boot> hexdump 0x10 20
0010  53 ff 00 f0 54 ff 00 f0  53 ff 00 f0 53 ff 00 f0  |S...T...S...S...|
0020  a5 fe 00 f0   ||
0024

Do we want such a feature?

If so, I would adapt the other's architectures Makefiles.

bluhm

Index: arch/amd64/stand/boot/Makefile
===
RCS file: /data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/boot/Makefile,v
retrieving revision 1.43
diff -u -p -r1.43 Makefile
--- arch/amd64/stand/boot/Makefile  29 Oct 2019 02:55:50 -  1.43
+++ arch/amd64/stand/boot/Makefile  26 Nov 2019 22:19:50 -
@@ -32,7 +32,8 @@ SRCS+=softraid_amd64.c
 .endif

 .PATH: ${S}/lib/libsa
-SRCS+= alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memmove.c memset.c 
printf.c \
+SRCS+= alloc.c ctime.c exit.c hexdump.c getchar.c \
+   memcmp.c memcpy.c memmove.c memset.c printf.c \
putchar.c snprintf.c strcmp.c strerror.c strlen.c strncmp.c strncpy.c \
strtol.c strtoll.c
 SRCS+= close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c fchmod.c \
Index: arch/amd64/stand/efiboot/Makefile.common
===
RCS file: 
/data/mirror/openbsd/cvs/src/sys/arch/amd64/stand/efiboot/Makefile.common,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile.common
--- arch/amd64/stand/efiboot/Makefile.common29 Oct 2019 02:55:51 -  
1.18
+++ arch/amd64/stand/efiboot/Makefile.common26 Nov 2019 21:57:05 -
@@ -32,7 +32,8 @@ SRCS+=memprobe.c
 SRCS+= boot.c bootarg.c cmd.c vars.c

 .PATH: ${S}/lib/libsa
-SRCS+= alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memmove.c memset.c 
printf.c \
+SRCS+= alloc.c ctime.c exit.c hexdump.c getchar.c \
+   memcmp.c memcpy.c memmove.c memset.c printf.c \
putchar.c snprintf.c strcmp.c strerror.c strlen.c strncmp.c strncpy.c \
strtol.c strtoll.c
 SRCS+= close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c \
Index: lib/libsa/hexdump.c
===
RCS file: lib/libsa/hexdump.c
diff -N lib/libsa/hexdump.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ lib/libsa/hexdump.c 26 Nov 2019 22:17:53 -
@@ -0,0 +1,52 @@
+/* $OpenBSD$   */
+/*
+ * Copyright (c) 2019 Alexander Bluhm 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+
+#include "stand.h"
+
+void
+hexdump(const void *addr, size_t size)
+{
+   const unsigned char *line, *end;
+   int byte;
+
+   end = (const char *)addr + size;
+   for (line = addr; line < end; line += 16) {
+   printf("%08x  ", line);
+   for (byte = 0; byte < 16; byte++) {
+   if (&line[byte] < end)
+   printf("%02x ", line[byte]);
+   else
+   printf("   ");
+   if (byte == 7)
+   printf(" ");
+   }
+   printf(" |");
+   for (byte = 0; byte < 16; byte++) {
+   if (&line[byte] < end) {
+   if (line[byte] >= ' ' && line[byte] <= '~')
+   printf("%c", line[byte]);
+   else
+   printf(".");
+   } else
+   break;
+   }
+   printf("|\n");
+   }
+   printf("%08x\n", end);
+}
Index: lib/libsa/stand.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/lib/libsa/stand.h,v
retrieving revision 1.68
diff -u -p -r1.68 stand.h
--- lib/libsa/stand.h   1 Nov 2019 20:54:52 -   1.68
+++ lib/libsa/stand.h   26 Nov 2019 21:57:05 -
@@ -146,6 +146,7 @@ __dead void _rtt(void) __attribute__((no
 #define bcmp(s1,s2,n)  (memcmp((s2),(s1),(n)))
 #definebcopy(s1,s2,n)  ((void)memmove((s2),(s1),(n)))
 void   explicit_bzero(void *, size_t);
+void   hexdump(const void *, size_t);
 void   *memcpy(void *, const void *, size_t);
 void   *memmove(void *, const