@@ -0,0 +1,5 @@
+config EARLY_PRINTK
+ bool "Enable early printk"
+ default DEBUG
+ help
+ Enables early printk debug messages
@@ -1,3 +1,4 @@
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-$(CONFIG_RISCV_64) += riscv64/
obj-y += sbi.o
obj-y += setup.o
new file mode 100644
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * RISC-V early printk using SBI
+ *
+ * Copyright (C) 2021 Bobby Eshleman <bobbyeshleman@gmail.com>
+ */
+#include <asm/early_printk.h>
+#include <asm/sbi.h>
+
+/*
+ * TODO:
+ * sbi_console_putchar is already planned for deprecation
+ * so it should be reworked to use UART directly.
+*/
+void early_puts(const char *s, size_t nr)
+{
+ while ( nr-- > 0 )
+ {
+ if ( *s == '\n' )
+ sbi_console_putchar('\r');
+ sbi_console_putchar(*s);
+ s++;
+ }
+}
+
+void early_printk(const char *str)
+{
+ while ( *str )
+ {
+ early_puts(str, 1);
+ str++;
+ }
+}
new file mode 100644
@@ -0,0 +1,12 @@
+#ifndef __EARLY_PRINTK_H__
+#define __EARLY_PRINTK_H__
+
+#include <xen/early_printk.h>
+
+#ifdef CONFIG_EARLY_PRINTK
+void early_printk(const char *str);
+#else
+static inline void early_printk(const char *s) {};
+#endif
+
+#endif /* __EARLY_PRINTK_H__ */
@@ -1,12 +1,16 @@
#include <xen/compile.h>
#include <xen/init.h>
+#include <asm/early_printk.h>
+
/* Xen stack for bringing up the first CPU. */
unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
__aligned(STACK_SIZE);
void __init noreturn start_xen(void)
{
+ early_printk("Hello from C env\n");
+
for ( ;; )
asm volatile ("wfi");