summaryrefslogtreecommitdiffstats
path: root/pbl/console.c
diff options
context:
space:
mode:
Diffstat (limited to 'pbl/console.c')
-rw-r--r--pbl/console.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/pbl/console.c b/pbl/console.c
index fc8e8cdf13..d81bf580d5 100644
--- a/pbl/console.c
+++ b/pbl/console.c
@@ -2,13 +2,14 @@
#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;
/**
@@ -21,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);
@@ -39,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++;
}
@@ -74,7 +81,22 @@ int pr_print(int level, const char *fmt, ...)
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;
}