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 >= 0x8000000000000000, 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.common 29 Oct 2019 02:55:51 -0000
1.18
+++ arch/amd64/stand/efiboot/Makefile.common 26 Nov 2019 21:57:05 -0000
@@ -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 -0000
+++ lib/libsa/hexdump.c 26 Nov 2019 23:42:22 -0000
@@ -0,0 +1,52 @@
+/* $OpenBSD$ */
+/*
+ * Copyright (c) 2019 Alexander Bluhm <[email protected]>
+ *
+ * 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 <sys/types.h>
+
+#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 -0000 1.68
+++ lib/libsa/stand.h 26 Nov 2019 21:57:05 -0000
@@ -146,6 +146,7 @@ __dead void _rtt(void) __attribute__((no
#define bcmp(s1,s2,n) (memcmp((s2),(s1),(n)))
#define bcopy(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);
int memcmp(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.c 3 Aug 2019 15:22:19 -0000 1.65
+++ stand/boot/cmd.c 26 Nov 2019 23:42:22 -0000
@@ -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, Xenv},
{"help", CMDT_CMD, Xhelp},
+ {"hexdump",CMDT_CMD, Xhexdump},
{"ls", CMDT_CMD, Xls},
#ifdef MACHINE_CMD
{"machine",CMDT_MDC, Xmachine},
@@ -345,6 +347,29 @@ Xhelp(void)
#else
return 0;
#endif
+}
+
+static int
+Xhexdump(void)
+{
+ long long val[2];
+ char *ep;
+ int i;
+
+ if (cmd.argc != 3) {
+ printf("hexdump addr size\n");
+ return 0;
+ }
+
+ for (i = 1; i < cmd.argc; i++) {
+ val[i-1] = strtoll(cmd.argv[i], &ep, 0);
+ if (cmd.argv[i][0] == '\0' && *ep != '\0') {
+ printf("bad arg %s\n", cmd.argv[i]);
+ return 0;
+ }
+ }
+ hexdump((void *)val[0], val[1]);
+ return 0;
}
#ifdef MACHINE_CMD