summaryrefslogtreecommitdiffstats
path: root/pbl/console.c
blob: d81bf580d52fbba2da0ad6879df26fe6bae3c9c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// 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"))) ulong putc_offset;
static __attribute__ ((section(".data"))) void *putc_ctx;

/**
 * pbl_set_putc() - setup UART used for PBL console
 * @putc: The putc function.
 * @ctx: The context pointer passed back to putc
 *
 * This sets the putc function which is afterwards used to output
 * characters in the PBL.
 */
void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx)
{
	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_offset)
		__putc(putc_ctx, c);
	else
		putc_ll(c);
}

int console_puts(unsigned int ch, const char *str)
{
	int n = 0;

	while (*str) {
		if (*str == '\n')
			console_putc(ch, '\r');

		console_putc(ch, *str);
		str++;
		n++;
	}

	return n;
}

int printf(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_STDOUT, printbuffer);

	return i;
}

int pr_print(int level, 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;
}

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;
}

int ctrlc(void)
{
	return 0;
}