SPM: Extract common debug code used for SPs
In later patches we will want to use the debug code defined in
cactus_debug.c for the Ivy partition, so create a common sp_debug
file for code re-use.
Signed-off-by: Ruari Phipps <ruari.phipps@arm.com>
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
Change-Id: Ifc9cf0043f3f7549b1668623b44d10cae64ddab0
diff --git a/spm/common/sp_debug.c b/spm/common/sp_debug.c
new file mode 100644
index 0000000..64ea9c5
--- /dev/null
+++ b/spm/common/sp_debug.c
@@ -0,0 +1,51 @@
+/*
+ * 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 <spm_helpers.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);
+}