From a87b86e54ffe22c12090d2233ad9036d9f53e61e Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Thu, 14 May 2020 12:03:01 +1000 Subject: [PATCH] console: Replace putstr with puts It makes things a bit more standard and a bit nicer to read without all those strlen(). Also console.c takes care of adding the carriage returns before the linefeeds. Signed-off-by: Benjamin Herrenschmidt --- hello_world/hello_world.c | 4 +-- rust_lib_demo/hello_world.c | 4 +-- tests/decrementer/decrementer.c | 20 ++++++------- tests/illegal/illegal.c | 12 ++++---- tests/sc/sc.c | 12 ++++---- tests/xics/xics.c | 50 ++++++++++++++++----------------- 6 files changed, 51 insertions(+), 51 deletions(-) diff --git a/hello_world/hello_world.c b/hello_world/hello_world.c index 7e853d8..6575667 100644 --- a/hello_world/hello_world.c +++ b/hello_world/hello_world.c @@ -3,13 +3,13 @@ #include "console.h" -#define HELLO_WORLD "Hello World\r\n" +#define HELLO_WORLD "Hello World\n" int main(void) { potato_uart_init(); - putstr(HELLO_WORLD, strlen(HELLO_WORLD)); + puts(HELLO_WORLD); while (1) { unsigned char c = getchar(); diff --git a/rust_lib_demo/hello_world.c b/rust_lib_demo/hello_world.c index f46140d..c8797fd 100644 --- a/rust_lib_demo/hello_world.c +++ b/rust_lib_demo/hello_world.c @@ -20,14 +20,14 @@ void init_bss() } } -#define HELLO_WORLD "Hello World\r\n" +#define HELLO_WORLD "Hello World\n" int main(void) { init_bss(); potato_uart_init(); - putstr(HELLO_WORLD, strlen(HELLO_WORLD)); + puts(HELLO_WORLD); rust_main(); crash(); diff --git a/tests/decrementer/decrementer.c b/tests/decrementer/decrementer.c index 2617a94..e6cff2c 100644 --- a/tests/decrementer/decrementer.c +++ b/tests/decrementer/decrementer.c @@ -5,8 +5,8 @@ #include "console.h" #define TEST "Test " -#define PASS "PASS\r\n" -#define FAIL "FAIL\r\n" +#define PASS "PASS\n" +#define FAIL "FAIL\n" extern int dec_test_1(void); extern int dec_test_2(void); @@ -15,10 +15,10 @@ extern int dec_test_3(void); // i < 100 void print_test_number(int i) { - putstr(TEST, strlen(TEST)); + puts(TEST); putchar(48 + i/10); putchar(48 + i%10); - putstr(":", 1); + putchar(':'); } int main(void) @@ -30,24 +30,24 @@ int main(void) print_test_number(1); if (dec_test_1() != 0) { fail = 1; - putstr(FAIL, strlen(FAIL)); + puts(FAIL); } else - putstr(PASS, strlen(PASS)); + puts(PASS); print_test_number(2); if (dec_test_2() != 0) { fail = 1; - putstr(FAIL, strlen(FAIL)); + puts(FAIL); } else - putstr(PASS, strlen(PASS)); + puts(PASS); print_test_number(3); if (dec_test_3() != 0) { fail = 1; - putstr(FAIL, strlen(FAIL)); + puts(FAIL); } else - putstr(PASS, strlen(PASS)); + puts(PASS); return fail; } diff --git a/tests/illegal/illegal.c b/tests/illegal/illegal.c index a1ea325..af0c04b 100644 --- a/tests/illegal/illegal.c +++ b/tests/illegal/illegal.c @@ -5,18 +5,18 @@ #include "console.h" #define TEST "Test " -#define PASS "PASS\r\n" -#define FAIL "FAIL\r\n" +#define PASS "PASS\n" +#define FAIL "FAIL\n" extern int ill_test_1(void); // i < 100 void print_test_number(int i) { - putstr(TEST, strlen(TEST)); + puts(TEST); putchar(48 + i/10); putchar(48 + i%10); - putstr(":", 1); + putchar(':'); } int main(void) @@ -28,9 +28,9 @@ int main(void) print_test_number(1); if (ill_test_1() != 0) { fail = 1; - putstr(FAIL, strlen(FAIL)); + puts(FAIL); } else - putstr(PASS, strlen(PASS)); + puts(PASS); return fail; } diff --git a/tests/sc/sc.c b/tests/sc/sc.c index 2914291..a705d19 100644 --- a/tests/sc/sc.c +++ b/tests/sc/sc.c @@ -5,18 +5,18 @@ #include "console.h" #define TEST "Test " -#define PASS "PASS\r\n" -#define FAIL "FAIL\r\n" +#define PASS "PASS\n" +#define FAIL "FAIL\n" extern int sc_test_1(void); // i < 100 void print_test_number(int i) { - putstr(TEST, strlen(TEST)); + puts(TEST); putchar(48 + i/10); putchar(48 + i%10); - putstr(":", 1); + putchar(':'); } int main(void) @@ -28,9 +28,9 @@ int main(void) print_test_number(1); if (sc_test_1() != 0) { fail = 1; - putstr(FAIL, strlen(FAIL)); + puts(FAIL); } else - putstr(PASS, strlen(PASS)); + puts(PASS); return fail; } diff --git a/tests/xics/xics.c b/tests/xics/xics.c index 6652cbf..2ff4c54 100644 --- a/tests/xics/xics.c +++ b/tests/xics/xics.c @@ -29,29 +29,29 @@ void print_number(unsigned int i) // only for i = 0-999 } #ifdef DEBUG -#define DEBUG_STR "\r\nDEBUG: " +#define DEBUG_STR "\nDEBUG: " void debug_print(int i) { - putstr(DEBUG_STR, strlen(DEBUG_STR)); + puts(DEBUG_STR); print_number(i); - putstr("\r\n", 2); + puts("\n"); } -#define debug_putstr(a, b) putstr(a,b) +#define debug_puts(a) puts(a) #else -#define debug_putstr(a, b) +#define debug_puts(a) #define debug_print(i) #endif -#define ASSERT_FAIL "() ASSERT_FAILURE!\r\n " +#define ASSERT_FAIL "() ASSERT_FAILURE!\n " #define assert(cond) \ if (!(cond)) { \ - putstr(__FILE__, strlen(__FILE__)); \ - putstr(":", 1); \ + puts(__FILE__); \ + putchar(':'); \ print_number(__LINE__); \ - putstr(":", 1); \ - putstr(__FUNCTION__, strlen(__FUNCTION__));\ - putstr(ASSERT_FAIL, strlen(ASSERT_FAIL)); \ + putchar(':'); \ + puts(__FUNCTION__);\ + puts(ASSERT_FAIL); \ __asm__ ("attn"); \ } @@ -62,17 +62,17 @@ volatile uint64_t isrs_run; #define ISR_UART 0x0000000000000002 #define ISR_SPURIOUS 0x0000000000000004 -#define IPI "IPI\r\n" +#define IPI "IPI\n" void ipi_isr(void) { - debug_putstr(IPI, strlen(IPI)); + debug_puts(IPI); isrs_run |= ISR_IPI; } -#define UART "UART\r\n" +#define UART "UART\n" void uart_isr(void) { - debug_putstr(UART, strlen(UART)); + debug_puts(UART); potato_uart_irq_dis(); // disable interrupt to ack it @@ -80,9 +80,9 @@ void uart_isr(void) { } // The hardware doesn't support this but it's part of XICS so add it. -#define SPURIOUS "SPURIOUS\r\n" +#define SPURIOUS "SPURIOUS\n" void spurious_isr(void) { - debug_putstr(SPURIOUS, strlen(SPURIOUS)); + debug_puts(SPURIOUS); isrs_run |= ISR_SPURIOUS; } @@ -113,9 +113,9 @@ void isr(void) xirr = xics_read32(XICS_XIRR); // read hardware irq source #ifdef DEBUG - putstr(ISR, strlen(ISR)); + puts(ISR); print_number(xirr & 0xff); - putstr("\r\n", 2); + puts("\n"); #endif op = isr_table; @@ -221,8 +221,8 @@ int xics_test_2(void) } #define TEST "Test " -#define PASS "PASS\r\n" -#define FAIL "FAIL\r\n" +#define PASS "PASS\n" +#define FAIL "FAIL\n" int (*tests[])(void) = { xics_test_0, @@ -246,14 +246,14 @@ int main(void) if (!t) break; - putstr(TEST, strlen(TEST)); + puts(TEST); print_number(i); - putstr(": ", 1); + putchar(':'); if (t() != 0) { fail = 1; - putstr(FAIL, strlen(FAIL)); + puts(FAIL); } else - putstr(PASS, strlen(PASS)); + puts(PASS); i++; } -- 2.30.2