svn commit: r293460 - head/sys/boot/efi/boot1

Steven Hartland smh at FreeBSD.org
Sat Jan 9 03:20:02 UTC 2016


Author: smh
Date: Sat Jan  9 03:20:01 2016
New Revision: 293460
URL: https://svnweb.freebsd.org/changeset/base/293460

Log:
  Switch EFT boot1 to use libstand
  
  ARM and i386 already required libstand so switch to using it for all
  patforms, allowing the removal of custom print and memory methods.
  
  This is also a pre-cursor to enabling WARNS which highlighted a number
  of issues with the removed methods.
  
  MFC after:	2 weeks
  X-MFC-With:	r293268
  Sponsored by:	Multiplay

Modified:
  head/sys/boot/efi/boot1/Makefile
  head/sys/boot/efi/boot1/boot1.c

Modified: head/sys/boot/efi/boot1/Makefile
==============================================================================
--- head/sys/boot/efi/boot1/Makefile	Sat Jan  9 03:08:21 2016	(r293459)
+++ head/sys/boot/efi/boot1/Makefile	Sat Jan  9 03:20:01 2016	(r293460)
@@ -41,14 +41,13 @@ CFLAGS+=	-fPIC
 LDFLAGS+=	-Wl,-znocombreloc
 .endif
 
-.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "i386"
 #
 # Add libstand for the runtime functions used by the compiler - for example
 # __aeabi_* (arm) or __divdi3 (i386).
+# as well as required string and memory functions for all platforms.
 #
 DPADD+=		${LIBSTAND}
 LDADD+=		-lstand
-.endif
 
 DPADD+=		${LDSCRIPT}
 

Modified: head/sys/boot/efi/boot1/boot1.c
==============================================================================
--- head/sys/boot/efi/boot1/boot1.c	Sat Jan  9 03:08:21 2016	(r293459)
+++ head/sys/boot/efi/boot1/boot1.c	Sat Jan  9 03:20:01 2016	(r293460)
@@ -24,6 +24,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/dirent.h>
 #include <machine/elf.h>
 #include <machine/stdarg.h>
+#include <stand.h>
 
 #include <efi.h>
 #include <eficonsctl.h>
@@ -33,28 +34,8 @@ __FBSDID("$FreeBSD$");
 
 #define BSIZEMAX	16384
 
-typedef int putc_func_t(char c, void *arg);
-
-struct sp_data {
-	char	*sp_buf;
-	u_int	sp_len;
-	u_int	sp_size;
-};
-
-static const char digits[] = "0123456789abcdef";
-
-static void panic(const char *fmt, ...) __dead2;
-static int printf(const char *fmt, ...);
-static int putchar(char c, void *arg);
-static int vprintf(const char *fmt, va_list ap);
-static int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap);
-
-static int __printf(const char *fmt, putc_func_t *putc, void *arg, va_list ap);
-static int __putc(char c, void *arg);
-static int __puts(const char *s, putc_func_t *putc, void *arg);
-static int __sputc(char c, void *arg);
-static char *__uitoa(char *buf, u_int val, int base);
-static char *__ultoa(char *buf, u_long val, int base);
+void panic(const char *fmt, ...) __dead2;
+void putchar(int c);
 
 static int domount(EFI_DEVICE_PATH *device, EFI_BLOCK_IO *blkio, int quiet);
 static void load(const char *fname);
@@ -62,39 +43,6 @@ static void load(const char *fname);
 static EFI_SYSTEM_TABLE *systab;
 static EFI_HANDLE *image;
 
-static void
-bcopy(const void *src, void *dst, size_t len)
-{
-	const char *s = src;
-	char *d = dst;
-
-	while (len-- != 0)
-		*d++ = *s++;
-}
-
-static void
-memcpy(void *dst, const void *src, size_t len)
-{
-	bcopy(src, dst, len);
-}
-
-static void
-bzero(void *b, size_t len)
-{
-	char *p = b;
-
-	while (len-- != 0)
-		*p++ = 0;
-}
-
-static int
-strcmp(const char *s1, const char *s2)
-{
-	for (; *s1 == *s2 && *s1; s1++, s2++)
-		;
-	return ((u_char)*s1 - (u_char)*s2);
-}
-
 static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL;
 static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL;
 static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL;
@@ -346,38 +294,22 @@ load(const char *fname)
 		    EFI_ERROR_CODE(status));
 }
 
-static void
+void
 panic(const char *fmt, ...)
 {
-	char buf[128];
 	va_list ap;
 
+	printf("panic: ");
 	va_start(ap, fmt);
-	vsnprintf(buf, sizeof buf, fmt, ap);
-	printf("panic: %s\n", buf);
+	vprintf(fmt, ap);
 	va_end(ap);
+	printf("\n");
 
 	while (1) {}
 }
 
-static int
-printf(const char *fmt, ...)
-{
-	va_list ap;
-	int ret;
-
-	/* Don't annoy the user as we probe for partitions */
-	if (strcmp(fmt,"Not ufs\n") == 0)
-		return 0;
-
-	va_start(ap, fmt);
-	ret = vprintf(fmt, ap);
-	va_end(ap);
-	return (ret);
-}
-
-static int
-putchar(char c, void *arg)
+void
+putchar(int c)
 {
 	CHAR16 buf[2];
 
@@ -389,187 +321,4 @@ putchar(char c, void *arg)
 	buf[0] = c;
 	buf[1] = 0;
 	systab->ConOut->OutputString(systab->ConOut, buf);
-	return (1);
-}
-
-static int
-vprintf(const char *fmt, va_list ap)
-{
-	int ret;
-
-	ret = __printf(fmt, putchar, 0, ap);
-	return (ret);
-}
-
-static int
-vsnprintf(char *str, size_t sz, const char *fmt, va_list ap)
-{
-	struct sp_data sp;
-	int ret;
-
-	sp.sp_buf = str;
-	sp.sp_len = 0;
-	sp.sp_size = sz;
-	ret = __printf(fmt, __sputc, &sp, ap);
-	return (ret);
-}
-
-static int
-__printf(const char *fmt, putc_func_t *putc, void *arg, va_list ap)
-{
-	char buf[(sizeof(long) * 8) + 1];
-	char *nbuf;
-	u_long ul;
-	u_int ui;
-	int lflag;
-	int sflag;
-	char *s;
-	int pad;
-	int ret;
-	int c;
-
-	nbuf = &buf[sizeof buf - 1];
-	ret = 0;
-	while ((c = *fmt++) != 0) {
-		if (c != '%') {
-			ret += putc(c, arg);
-			continue;
-		}
-		lflag = 0;
-		sflag = 0;
-		pad = 0;
-reswitch:	c = *fmt++;
-		switch (c) {
-		case '#':
-			sflag = 1;
-			goto reswitch;
-		case '%':
-			ret += putc('%', arg);
-			break;
-		case 'c':
-			c = va_arg(ap, int);
-			ret += putc(c, arg);
-			break;
-		case 'd':
-			if (lflag == 0) {
-				ui = (u_int)va_arg(ap, int);
-				if (ui < (int)ui) {
-					ui = -ui;
-					ret += putc('-', arg);
-				}
-				s = __uitoa(nbuf, ui, 10);
-			} else {
-				ul = (u_long)va_arg(ap, long);
-				if (ul < (long)ul) {
-					ul = -ul;
-					ret += putc('-', arg);
-				}
-				s = __ultoa(nbuf, ul, 10);
-			}
-			ret += __puts(s, putc, arg);
-			break;
-		case 'l':
-			lflag = 1;
-			goto reswitch;
-		case 'o':
-			if (lflag == 0) {
-				ui = (u_int)va_arg(ap, u_int);
-				s = __uitoa(nbuf, ui, 8);
-			} else {
-				ul = (u_long)va_arg(ap, u_long);
-				s = __ultoa(nbuf, ul, 8);
-			}
-			ret += __puts(s, putc, arg);
-			break;
-		case 'p':
-			ul = (u_long)va_arg(ap, void *);
-			s = __ultoa(nbuf, ul, 16);
-			ret += __puts("0x", putc, arg);
-			ret += __puts(s, putc, arg);
-			break;
-		case 's':
-			s = va_arg(ap, char *);
-			ret += __puts(s, putc, arg);
-			break;
-		case 'u':
-			if (lflag == 0) {
-				ui = va_arg(ap, u_int);
-				s = __uitoa(nbuf, ui, 10);
-			} else {
-				ul = va_arg(ap, u_long);
-				s = __ultoa(nbuf, ul, 10);
-			}
-			ret += __puts(s, putc, arg);
-			break;
-		case 'x':
-			if (lflag == 0) {
-				ui = va_arg(ap, u_int);
-				s = __uitoa(nbuf, ui, 16);
-			} else {
-				ul = va_arg(ap, u_long);
-				s = __ultoa(nbuf, ul, 16);
-			}
-			if (sflag)
-				ret += __puts("0x", putc, arg);
-			ret += __puts(s, putc, arg);
-			break;
-		case '0': case '1': case '2': case '3': case '4':
-		case '5': case '6': case '7': case '8': case '9':
-			pad = pad * 10 + c - '0';
-			goto reswitch;
-		default:
-			break;
-		}
-	}
-	return (ret);
-}
-
-static int
-__sputc(char c, void *arg)
-{
-	struct sp_data *sp;
-
-	sp = arg;
-	if (sp->sp_len < sp->sp_size)
-		sp->sp_buf[sp->sp_len++] = c;
-	sp->sp_buf[sp->sp_len] = '\0';
-	return (1);
-}
-
-static int
-__puts(const char *s, putc_func_t *putc, void *arg)
-{
-	const char *p;
-	int ret;
-
-	ret = 0;
-	for (p = s; *p != '\0'; p++)
-		ret += putc(*p, arg);
-	return (ret);
-}
-
-static char *
-__uitoa(char *buf, u_int ui, int base)
-{
-	char *p;
-
-	p = buf;
-	*p = '\0';
-	do
-		*--p = digits[ui % base];
-	while ((ui /= base) != 0);
-	return (p);
-}
-
-static char *
-__ultoa(char *buf, u_long ul, int base)
-{
-	char *p;
-
-	p = buf;
-	*p = '\0';
-	do
-		*--p = digits[ul % base];
-	while ((ul /= base) != 0);
-	return (p);
 }


More information about the svn-src-all mailing list