Logging without locking before the MMU is initialized.
Some architectures require MMU to be initialized before atomic
operations are functional.
Change-Id: Ibebae7a811f5710a387d058bf78c046057e2df45
diff --git a/inc/hf/dlog.h b/inc/hf/dlog.h
index 0e77d9b..18872ae 100644
--- a/inc/hf/dlog.h
+++ b/inc/hf/dlog.h
@@ -19,9 +19,13 @@
#include <stdarg.h>
#if DEBUG
+void dlog_nosync(const char *fmt, ...);
+void vdlog_nosync(const char *fmt, va_list args);
void dlog(const char *fmt, ...);
void vdlog(const char *fmt, va_list args);
#else
+#define dlog_nosync(...)
+#define vdlog_nosync(fmt, args)
#define dlog(...)
#define vdlog(fmt, args)
#endif
diff --git a/src/arch/aarch64/mm.c b/src/arch/aarch64/mm.c
index 2867fd9..e6c723b 100644
--- a/src/arch/aarch64/mm.c
+++ b/src/arch/aarch64/mm.c
@@ -183,19 +183,21 @@
/* Check that 4KB granules are supported. */
if ((features >> 28) & 0xf) {
- dlog("4KB granules are not supported\n");
+ dlog_nosync("4KB granules are not supported\n");
return false;
}
/* Check the physical address range. */
if (!pa_bits) {
- dlog("Unsupported value of id_aa64mmfr0_el1.PARange: %x\n",
- features & 0xf);
+ dlog_nosync(
+ "Unsupported value of id_aa64mmfr0_el1.PARange: %x\n",
+ features & 0xf);
return false;
}
if (first) {
- dlog("Supported bits in physical address: %d\n", pa_bits);
+ dlog_nosync("Supported bits in physical address: %d\n",
+ pa_bits);
}
/*
@@ -211,7 +213,8 @@
}
if (first) {
- dlog("Number of page table levels: %d\n", mm_max_s2_level + 1);
+ dlog_nosync("Number of page table levels: %d\n",
+ mm_max_s2_level + 1);
}
v = (1u << 31) | /* RES1. */
diff --git a/src/dlog.c b/src/dlog.c
index e9643c5..9737805 100644
--- a/src/dlog.c
+++ b/src/dlog.c
@@ -176,18 +176,17 @@
}
/**
- * Same as "dlog", except that arguments are passed as a va_list.
+ * Same as "dlog_nosync", except that arguments are passed as a va_list. This
+ * must only be used before the MMU has been initialized so that the atomic
+ * operations needed for locking are operational.
*/
-void vdlog(const char *fmt, va_list args)
+void vdlog_nosync(const char *fmt, va_list args)
{
- static struct spinlock sl = SPINLOCK_INIT;
const char *p;
size_t w;
int flags;
char buf[2];
- sl_lock(&sl);
-
for (p = fmt; *p; p++) {
switch (*p) {
default:
@@ -281,7 +280,31 @@
break;
}
}
+}
+/**
+ * Prints the given format string to the debug log without locking. This must
+ * only be used before the MMU has been initialized so that the atomic
+ * operations needed for locking are operational.
+ */
+void dlog_nosync(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vdlog_nosync(fmt, args);
+ va_end(args);
+}
+
+/**
+ * Same as "dlog", except that arguments are passed as a va_list.
+ */
+void vdlog(const char *fmt, va_list args)
+{
+ static struct spinlock sl = SPINLOCK_INIT;
+
+ sl_lock(&sl);
+ vdlog_nosync(fmt, args);
sl_unlock(&sl);
}
diff --git a/src/main.c b/src/main.c
index 734caf5..7c02e6d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -44,13 +44,13 @@
/* TODO: Block all CPUs. */
- dlog("Panic: ");
+ dlog_nosync("Panic: ");
va_start(args, fmt);
- vdlog(fmt, args);
+ vdlog_nosync(fmt, args);
va_end(args);
- dlog("\n");
+ dlog_nosync("\n");
for (;;) {
}
@@ -68,7 +68,7 @@
void *initrd;
size_t i;
- dlog("Initialising hafnium\n");
+ dlog_nosync("Initialising hafnium\n");
cpu_module_init();
halloc_init((size_t)ptable_buf, sizeof(ptable_buf));
diff --git a/src/mm.c b/src/mm.c
index 3e17f47..9aa21be 100644
--- a/src/mm.c
+++ b/src/mm.c
@@ -711,15 +711,15 @@
*/
bool mm_init(void)
{
- dlog("text: 0x%x - 0x%x\n", pa_addr(layout_text_begin()),
- pa_addr(layout_text_end()));
- dlog("rodata: 0x%x - 0x%x\n", pa_addr(layout_rodata_begin()),
- pa_addr(layout_rodata_end()));
- dlog("data: 0x%x - 0x%x\n", pa_addr(layout_data_begin()),
- pa_addr(layout_data_end()));
+ dlog_nosync("text: 0x%x - 0x%x\n", pa_addr(layout_text_begin()),
+ pa_addr(layout_text_end()));
+ dlog_nosync("rodata: 0x%x - 0x%x\n", pa_addr(layout_rodata_begin()),
+ pa_addr(layout_rodata_end()));
+ dlog_nosync("data: 0x%x - 0x%x\n", pa_addr(layout_data_begin()),
+ pa_addr(layout_data_end()));
if (!mm_ptable_init(&ptable, MM_MODE_NOSYNC | MM_MODE_STAGE1)) {
- dlog("Unable to allocate memory for page table.\n");
+ dlog_nosync("Unable to allocate memory for page table.\n");
return false;
}