diff options
Diffstat (limited to 'pbl/console.c')
-rw-r--r-- | pbl/console.c | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/pbl/console.c b/pbl/console.c index 007e4e4b83..d81bf580d5 100644 --- a/pbl/console.c +++ b/pbl/console.c @@ -1,12 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-only + #include <common.h> #include <debug_ll.h> +#include <asm/sections.h> #include <linux/err.h> /* * Put these in the data section so that they survive the clearing of the * BSS segment. */ -static __attribute__ ((section(".data"))) void (*__putc)(void *ctx, int c); +static __attribute__ ((section(".data"))) ulong putc_offset; static __attribute__ ((section(".data"))) void *putc_ctx; /** @@ -19,13 +22,19 @@ static __attribute__ ((section(".data"))) void *putc_ctx; */ void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx) { - __putc = putcf; + putc_offset = (ulong)putcf - (ulong)_text; putc_ctx = ctx; } +static void __putc(void *ctx, int c) +{ + void (*putc)(void *, int) = (void *)_text + putc_offset; + putc(ctx, c); +} + void console_putc(unsigned int ch, char c) { - if (__putc) + if (putc_offset) __putc(putc_ctx, c); else putc_ll(c); @@ -37,9 +46,9 @@ int console_puts(unsigned int ch, const char *str) while (*str) { if (*str == '\n') - console_putc(CONSOLE_STDOUT, '\r'); + console_putc(ch, '\r'); - console_putc(CONSOLE_STDOUT, *str); + console_putc(ch, *str); str++; n++; } @@ -54,7 +63,7 @@ int printf(const char *fmt, ...) char printbuffer[CFG_PBSIZE]; va_start(args, fmt); - i = vsprintf(printbuffer, fmt, args); + i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args); va_end(args); console_puts(CONSOLE_STDOUT, printbuffer); @@ -69,10 +78,25 @@ int pr_print(int level, const char *fmt, ...) char printbuffer[CFG_PBSIZE]; va_start(args, fmt); - i = vsprintf(printbuffer, fmt, args); + i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args); va_end(args); - console_puts(CONSOLE_STDOUT, printbuffer); + console_puts(CONSOLE_STDERR, printbuffer); + + return i; +} + +int dev_printf(int level, const struct device *dev, const char *fmt, ...) +{ + va_list args; + uint i; + char printbuffer[CFG_PBSIZE]; + + va_start(args, fmt); + i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args); + va_end(args); + + console_puts(CONSOLE_STDERR, printbuffer); return i; } |