diff options
author | Helge Deller <deller@gmx.de> | 2018-01-01 13:31:50 +0100 |
---|---|---|
committer | Helge Deller <deller@gmx.de> | 2018-01-01 19:54:53 +0100 |
commit | 0b29d0ca4721368c36e3ff51df106b109c554548 (patch) | |
tree | 1810ca91598e86a9b0d7a8773bb24eb8d1903b72 | |
parent | 77328e5288ed2c5f91ec13d9df587536a6b5a526 (diff) | |
download | palo-0b29d0ca4721368c36e3ff51df106b109c554548.tar.gz |
Fix up boot messages with regard to newline behaviour
Our puts() implemenation behaved non-conforming to the standard, since we
didn't added a newline after having printed the string. This leads to some
strange behaviour, because gcc optimizes (and replaces) some printf() calls to
puts() and dropped the trailing newline, which then wasn't added back by our
puts() implementation. As such we were missing newlines although our printf()
calls seemed correct.
Fix it by rewriting puts() to behave as expected by the standard, and as such
avoid such problems.
The other solution could have been to add the -fno-builtin-printf gcc
option but I prefer to conform to the standard.
Signed-off-by: Helge Deller <deller@gmx.de>
-rw-r--r-- | ipl/ipl.c | 20 | ||||
-rw-r--r-- | ipl/pdc_bootio.c | 4 | ||||
-rw-r--r-- | ipl/pdc_cons.c | 54 | ||||
-rw-r--r-- | ipl/pdc_misc.c | 1 |
4 files changed, 45 insertions, 34 deletions
@@ -231,7 +231,7 @@ load_rd(int fd, int size) rd_end = rd + size; } flush_data_cache((char *)rd, size); - puts("\n"); + printf("\n"); return (rd_start != 0); } @@ -348,9 +348,9 @@ interact(int *ok) while (1) { - puts("Current command line:\n"); - puts(commandline); - puts("\n"); + printf("Current command line:\n"); + printf(commandline); + printf("\n"); p = commandline; argc = 0; @@ -373,7 +373,7 @@ interact(int *ok) { printf("%2d: %s\n", i, argv[i]); } - puts("\n" + printf("\n" "<#> edit the numbered field\n" "'b' boot with this command line\n" "'r' restore command line\n" @@ -386,7 +386,7 @@ interact(int *ok) numbuf[0] = '0'; numbuf[1] = '\0'; enter_text(numbuf, sizeof numbuf - 1); - puts("\n"); + printf("\n"); if (numbuf[0] == 'b') { @@ -424,14 +424,14 @@ interact(int *ok) if (editfield >= MAX_ARGV) { - puts("Too many input fields.\n"); + printf("Too many input fields.\n"); } else if (editfield < argc) { strncpy(fieldbuf, argv[editfield], sizeof(fieldbuf)); fieldbuf[sizeof(fieldbuf)-1] = '\0'; enter_text(fieldbuf, sizeof fieldbuf - 1); - puts("\n"); + printf("\n"); argv[editfield] = fieldbuf; } @@ -496,9 +496,7 @@ iplmain(int is_interactive, char *initialstackptr, int started_wide) firmware_init(started_wide); putchar('p'); /* if you get this p and no more, string storage */ /* in $GLOBAL$ is wrong or %dp is wrong */ - puts("alo ipl " PALOVERSION " "); - puts(bld_info); - puts("\n"); + printf("alo ipl " PALOVERSION " %s\n", bld_info); interactive = is_interactive; if (Debug) { printf("iplmain(%d, started %s)\n", interactive, diff --git a/ipl/pdc_bootio.c b/ipl/pdc_bootio.c index e527c5e..3810fb4 100644 --- a/ipl/pdc_bootio.c +++ b/ipl/pdc_bootio.c @@ -65,7 +65,7 @@ static int pdc_bootdev_read(int fd, devaddr += nseek; abort_with_warning: if (devaddr > 30*1024*1024) /* 30MB */ - puts("If you boot via tftp you probably reached the 32MB limit.\n"); + printf("If you boot via tftp you probably reached the 32MB limit.\n"); pdc_do_reset(); return -1; } @@ -95,7 +95,7 @@ abort_with_warning: for (i = 0; i < 16; i++) printf(" %02x", dest[nbytes + i] & 0xff); } - puts("\n"); + printf("\n"); } if (count == 0) diff --git a/ipl/pdc_cons.c b/ipl/pdc_cons.c index 5135081..c36b55a 100644 --- a/ipl/pdc_cons.c +++ b/ipl/pdc_cons.c @@ -28,32 +28,46 @@ getchar(void) } } +static int +putstring(const char *s) +{ + const int len = strlen(s); + + if (len == 0) + return 0; + + if (strchr(s, '\n') == NULL) + pdc_iodc_cout(s, len); + else { + while (*s) + putchar(*s++); + } + + return len; +} + int puts(const char *s) { - const char *nuline = s; + int len; - while ((nuline = strchr(s, '\n')) != NULL) - { - if (nuline != s) - pdc_iodc_cout(s, nuline - s); - pdc_iodc_cout("\r\n", 2); - s = nuline + 1; - } - if (*s != '\0') - pdc_iodc_cout(s, strlen(s)); - return 0; + len = putstring(s); + + /* puts() always adds a trailing '\n' */ + putchar('\n'); + + return len; } int putchar(int c) { - char buf[2]; - - buf[0] = c; - buf[1] = '\0'; - puts(buf); - return c; + char ch = c; + if (ch == '\n') + pdc_iodc_cout("\r\n", 2); + else + pdc_iodc_cout(&ch, 1); + return (unsigned char)ch; } int printf(const char *fmt, ...) @@ -62,12 +76,12 @@ int printf(const char *fmt, ...) va_list args; int i; - if (fmt == 0 || fmt[0] == 0) + if (fmt[0] == 0) asm("\nprintf_test1: b,n ."); va_start(args, fmt); - i = vsprintf(buf, fmt, args); + vsprintf(buf, fmt, args); va_end(args); - puts(buf); + i = putstring(buf); return i; } diff --git a/ipl/pdc_misc.c b/ipl/pdc_misc.c index e14d1c1..d0dfb91 100644 --- a/ipl/pdc_misc.c +++ b/ipl/pdc_misc.c @@ -30,7 +30,6 @@ void die(const char *s) { puts(s); - puts("\n"); } static int firmware_is_wide; |