aboutsummaryrefslogtreecommitdiff
path: root/spm/cactus/cactus_debug.c
blob: 43093a6bb21668dce86d370fdb8da314c6a63a85 (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
/*
 * Copyright (c) 2020, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <drivers/arm/pl011.h>
#include <drivers/console.h>
#include <sp_helpers.h>

#include "cactus.h"

static int (*putc_impl)(int);

static int putc_hypcall(int c)
{
	spm_debug_log((char)c);

	return c;
}

static int putc_uart(int c)
{
	console_pl011_putc(c);

	return c;
}

void set_putc_impl(enum stdout_route route)
{
	switch (route) {

	case HVC_CALL_AS_STDOUT:
		putc_impl = putc_hypcall;
		return;

	case PL011_AS_STDOUT:
	default:
		break;
	}

	putc_impl = putc_uart;
}

int console_putc(int c)
{
	if (!putc_impl) {
		return -1;
	}

	return putc_impl(c);
}