aboutsummaryrefslogtreecommitdiff
path: root/spm/common/sp_debug.c
blob: 396253b6a7af5cf4c1717f6209188f438a3f4b4a (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
/*
 * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

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

static int (*putc_impl)(int);

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

	return c;
}

static int putc_svccall(int c)
{
	/* TODO svc call */
	svc_args args = {
		.fid = SPM_DEBUG_LOG,
		.arg1 = c
	};
	sp_svc(&args);

	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 SVC_CALL_AS_STDOUT:
		putc_impl = putc_svccall;
		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);
}