From owner-svn-src-head@freebsd.org Thu Aug 3 13:50:47 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A2FBDDBDC68; Thu, 3 Aug 2017 13:50:47 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7ED427C91A; Thu, 3 Aug 2017 13:50:47 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v73DokNK045972; Thu, 3 Aug 2017 13:50:46 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v73DokLX045966; Thu, 3 Aug 2017 13:50:46 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201708031350.v73DokLX045966@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Thu, 3 Aug 2017 13:50:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r321991 - in head/sys/boot: arm/at91/libat91 arm/ixp425/boot2 i386/boot2 X-SVN-Group: head X-SVN-Commit-Author: ngie X-SVN-Commit-Paths: in head/sys/boot: arm/at91/libat91 arm/ixp425/boot2 i386/boot2 X-SVN-Commit-Revision: 321991 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Aug 2017 13:50:47 -0000 Author: ngie Date: Thu Aug 3 13:50:46 2017 New Revision: 321991 URL: https://svnweb.freebsd.org/changeset/base/321991 Log: Revert r321969 My change had good intentions, but the implementation was incorrect: - printf was returning the number of characters in the format string plus the NUL, but failed in two regards implementation wise: -- the pathological case, printf(""), wasn't being handled properly since the pointer is always incremented, so the value returned would be off-by-one. -- printf(3) reports the number of characters printed post-conversion via vfprintf, etc. - putchar(3) should return the character printed or EOF, not the number of characters output to the screen. My goal in making the change (again) was to increase parity, but as bde pointed out these are freestanding functions, so they don't have to conform to libc/POSIX. I argued that the functions should be named differently since the implementation is different enough to warrant it and to allow boot2 code to be usable when linked against sys/boot and libstand and other libraries in base. I have no interest in pushing this change forward more though, as the original concern I had behind the change with zfsboottest was resolved in r321849 and r321852. The next person that updates the toolchain gets to deal with the inconsistency if it's flagged by a newer compiler. MFC after: 1 month Reported by: ed, markj Modified: head/sys/boot/arm/at91/libat91/lib.h head/sys/boot/arm/at91/libat91/printf.c head/sys/boot/arm/at91/libat91/putchar.c head/sys/boot/arm/ixp425/boot2/ixp425_board.c head/sys/boot/arm/ixp425/boot2/lib.h head/sys/boot/i386/boot2/boot2.c Modified: head/sys/boot/arm/at91/libat91/lib.h ============================================================================== --- head/sys/boot/arm/at91/libat91/lib.h Thu Aug 3 13:45:26 2017 (r321990) +++ head/sys/boot/arm/at91/libat91/lib.h Thu Aug 3 13:50:46 2017 (r321991) @@ -28,9 +28,9 @@ #define ARM_BOOT_LIB_H int getc(int); -int putchar(int); -int xputchar(int); -int printf(const char *fmt,...); +void putchar(int); +void xputchar(int); +void printf(const char *fmt,...); /* The following function write eeprom at ee_addr using data */ /* from data_add for size bytes. */ Modified: head/sys/boot/arm/at91/libat91/printf.c ============================================================================== --- head/sys/boot/arm/at91/libat91/printf.c Thu Aug 3 13:45:26 2017 (r321990) +++ head/sys/boot/arm/at91/libat91/printf.c Thu Aug 3 13:50:46 2017 (r321991) @@ -20,13 +20,12 @@ #include #include "lib.h" -int +void printf(const char *fmt,...) { va_list ap; const char *hex = "0123456789abcdef"; char buf[10]; - const char *fmt_orig = fmt; char *s; unsigned u; int c; @@ -67,5 +66,5 @@ printf(const char *fmt,...) } va_end(ap); - return (int)(fmt - fmt_orig); + return; } Modified: head/sys/boot/arm/at91/libat91/putchar.c ============================================================================== --- head/sys/boot/arm/at91/libat91/putchar.c Thu Aug 3 13:45:26 2017 (r321990) +++ head/sys/boot/arm/at91/libat91/putchar.c Thu Aug 3 13:50:46 2017 (r321991) @@ -39,11 +39,11 @@ #include "lib.h" /* - * int putchar(int ch) + * void putchar(int ch) * Writes a character to the DBGU port. It assumes that DBGU has * already been initialized. */ -int +void putchar(int ch) { AT91PS_USART pUSART = (AT91PS_USART)AT91C_BASE_DBGU; @@ -51,14 +51,12 @@ putchar(int ch) while (!(pUSART->US_CSR & AT91C_US_TXRDY)) continue; pUSART->US_THR = (ch & 0xFF); - return (1); } -int +void xputchar(int ch) { - if (ch == '\n') - putchar('\r'); - putchar(ch); - return (ch == '\n' ? 2 : 1); + if (ch == '\n') + putchar('\r'); + putchar(ch); } Modified: head/sys/boot/arm/ixp425/boot2/ixp425_board.c ============================================================================== --- head/sys/boot/arm/ixp425/boot2/ixp425_board.c Thu Aug 3 13:45:26 2017 (r321990) +++ head/sys/boot/arm/ixp425/boot2/ixp425_board.c Thu Aug 3 13:50:46 2017 (r321991) @@ -165,7 +165,7 @@ getc(int seconds) return c; } -int +void putchar(int ch) { int delay, limit; @@ -179,16 +179,14 @@ putchar(int ch) limit = 40; while ((uart_getreg(ubase, REG_LSR) & LSR_TEMT) == 0 && --limit) DELAY(delay); - return (1); } -int +void xputchar(int ch) { if (ch == '\n') putchar('\r'); putchar(ch); - return (ch == '\n' ? 2 : 1); } void Modified: head/sys/boot/arm/ixp425/boot2/lib.h ============================================================================== --- head/sys/boot/arm/ixp425/boot2/lib.h Thu Aug 3 13:45:26 2017 (r321990) +++ head/sys/boot/arm/ixp425/boot2/lib.h Thu Aug 3 13:50:46 2017 (r321991) @@ -35,12 +35,12 @@ int main(void); void DELAY(int); int getc(int); -int putchar(int); -int xputchar(int); +void putchar(int); +void xputchar(int); void putstr(const char *); void puthex8(u_int8_t); void puthexlist(const u_int8_t *, int); -int printf(const char *fmt,...); +void printf(const char *fmt,...); void bzero(void *, size_t); char *strcpy(char *to, const char *from); Modified: head/sys/boot/i386/boot2/boot2.c ============================================================================== --- head/sys/boot/i386/boot2/boot2.c Thu Aug 3 13:45:26 2017 (r321990) +++ head/sys/boot/i386/boot2/boot2.c Thu Aug 3 13:50:46 2017 (r321991) @@ -114,8 +114,8 @@ void exit(int); static void load(void); static int parse(void); static int dskread(void *, unsigned, unsigned); -static int printf(const char *,...); -static int putchar(int); +static void printf(const char *,...); +static void putchar(int); static int drvread(void *, unsigned, unsigned); static int keyhit(unsigned); static int xputc(int); @@ -521,12 +521,11 @@ error: return -1; } -static int +static void printf(const char *fmt,...) { va_list ap; static char buf[10]; - const char *fmt_orig = fmt; char *s; unsigned u; int c; @@ -557,16 +556,15 @@ printf(const char *fmt,...) putchar(c); } va_end(ap); - return (int)(fmt - fmt_orig); + return; } -static int +static void putchar(int c) { if (c == '\n') xputc('\r'); xputc(c); - return (c == '\n' ? 2 : 1); } static int