From 8e4202ced136f4d997a500061d3089bffa30c4ac Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Mon, 8 Feb 2021 13:27:56 +0100 Subject: [PATCH 1/2] software/bios/readline: Fix warnings if char is signed When building with --cpu-type=mor1kx: litex/soc/software/bios/readline.c: In function 'readline': litex/soc/software/bios/readline.c:271:3: warning: case label value exceeds maximum value for type [-Wswitch-outside-range] 271 | case KEY_END: | ^~~~ litex/soc/software/bios/readline.c:297:3: warning: case label value exceeds maximum value for type [-Wswitch-outside-range] 297 | case KEY_DEL: | ^~~~ litex/soc/software/bios/readline.c:281:3: warning: case label value exceeds maximum value for type [-Wswitch-outside-range] 281 | case DEL: | ^~~~ The C standard does not specify the signedness of "char", hence this depends on the implementation. On e.g. RISC-V, "char" is unsigned, but on OpenRISC, it is signed. Fix this by making the "ichar" variable explicitly unsigned. Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/software/bios/readline.c b/litex/soc/software/bios/readline.c index f507f1a65..a255ebfaa 100644 --- a/litex/soc/software/bios/readline.c +++ b/litex/soc/software/bios/readline.c @@ -190,7 +190,7 @@ int readline(char *buf, int len) unsigned int eol_num = 0; unsigned int wlen; int insert = 1; - char ichar; + unsigned char ichar; #ifndef TERM_NO_COMPLETE char tmp; From 84e5130ac5fe2837a5bce8ca014e0000f1d596f5 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Mon, 8 Feb 2021 13:31:54 +0100 Subject: [PATCH 2/2] software/bios/console: Call putsnonl() from puts() puts() and putsnonl() are very similar, and can share code. Reduce code size by making the former call the latter. Impact for a RISC-V build: $ size console.o.orig console.o text data bss dec hex filename 868 0 12 880 370 console.o.orig 832 0 12 844 34c console.o Signed-off-by: Geert Uytterhoeven --- litex/soc/software/libbase/console.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/litex/soc/software/libbase/console.c b/litex/soc/software/libbase/console.c index ec434643b..cd62b5c68 100644 --- a/litex/soc/software/libbase/console.c +++ b/litex/soc/software/libbase/console.c @@ -75,10 +75,7 @@ int readchar_nonblock(void) int puts(const char *s) { - while(*s) { - putchar(*s); - s++; - } + putsnonl(s); putchar('\n'); return 1; }