From ecb4857cbb1c3210b17c947e6932461853762ea7 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Wed, 31 Jul 2019 02:30:17 +0200 Subject: [PATCH] thermosphere: seriaLog => debugLog, add DEBUG macro --- thermosphere/src/{log.c => debug_log.c} | 4 ++-- thermosphere/src/{log.h => debug_log.h} | 8 +++++++- thermosphere/src/exceptions.c | 25 ++++++++++++++----------- thermosphere/src/hvc.c | 4 ++-- thermosphere/src/main.c | 6 +++--- 5 files changed, 28 insertions(+), 19 deletions(-) rename thermosphere/src/{log.c => debug_log.c} (93%) rename thermosphere/src/{log.h => debug_log.h} (84%) diff --git a/thermosphere/src/log.c b/thermosphere/src/debug_log.c similarity index 93% rename from thermosphere/src/log.c rename to thermosphere/src/debug_log.c index 7882b0225..776ffb57c 100644 --- a/thermosphere/src/log.c +++ b/thermosphere/src/debug_log.c @@ -15,12 +15,12 @@ */ #include -#include "log.h" +#include "debug_log.h" #include "platform/uart.h" #include "utils.h" // NOTE: UNSAFE! -int serialLog(const char *fmt, ...) +int debugLog(const char *fmt, ...) { char buf[128]; va_list args; diff --git a/thermosphere/src/log.h b/thermosphere/src/debug_log.h similarity index 84% rename from thermosphere/src/log.h rename to thermosphere/src/debug_log.h index 32b89ce08..d8c46df85 100644 --- a/thermosphere/src/log.h +++ b/thermosphere/src/debug_log.h @@ -17,4 +17,10 @@ #pragma once #include -int serialLog(const char *fmt, ...); +#ifndef NDEBUG +#define DEBUG(...) debugLog(__VA_ARGS__) +#else +#define DEBUG(...) +#endif + +int debugLog(const char *fmt, ...); diff --git a/thermosphere/src/exceptions.c b/thermosphere/src/exceptions.c index 1caf96c51..e1109e077 100644 --- a/thermosphere/src/exceptions.c +++ b/thermosphere/src/exceptions.c @@ -20,7 +20,7 @@ #include "smc.h" #include "core_ctx.h" -#include "log.h" +#include "debug_log.h" bool spsrEvaluateConditionCode(u64 spsr, u32 conditionCode) { @@ -50,18 +50,21 @@ void dumpStackFrame(const ExceptionStackFrame *frame, bool sameEl) { #ifndef NDEBUG for (u32 i = 0; i < 30; i += 2) { - serialLog("x%u\t\t%016llx\t\tx%u\t\t%016llx\n", i, frame->x[i], i + 1, frame->x[i + 1]); + DEBUG("x%u\t\t%016llx\t\tx%u\t\t%016llx\n", i, frame->x[i], i + 1, frame->x[i + 1]); } - serialLog("x30\t\t%016llx\n\n", frame->x[30]); - serialLog("elr_el2\t\t%016llx\n", frame->elr_el2); - serialLog("spsr_el2\t%016llx\n", frame->spsr_el2); + DEBUG("x30\t\t%016llx\n\n", frame->x[30]); + DEBUG("elr_el2\t\t%016llx\n", frame->elr_el2); + DEBUG("spsr_el2\t%016llx\n", frame->spsr_el2); if (sameEl) { - serialLog("sp_el2\t\t%016llx\n", frame->sp_el2); + DEBUG("sp_el2\t\t%016llx\n", frame->sp_el2); } else { - serialLog("sp_el0\t\t%016llx\n", frame->sp_el0); + DEBUG("sp_el0\t\t%016llx\n", frame->sp_el0); } - serialLog("sp_el1\t\t%016llx\n", frame->sp_el1); + DEBUG("sp_el1\t\t%016llx\n", frame->sp_el1); +#else + (void)frame; + (void)sameEl; #endif } @@ -119,7 +122,7 @@ void handleLowerElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeReg break; default: - serialLog("Lower EL sync exception, EC = 0x%02llx IL=%llu ISS=0x%06llx\n", (u64)esr.ec, esr.il, esr.iss); + DEBUG("Lower EL sync exception, EC = 0x%02llx IL=%llu ISS=0x%06llx\n", (u64)esr.ec, esr.il, esr.iss); dumpStackFrame(frame, false); break; } @@ -127,11 +130,11 @@ void handleLowerElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeReg void handleSameElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr) { - serialLog("Same EL sync exception on core %x, EC = 0x%02llx IL=%llu ISS=0x%06llx\n", currentCoreCtx->coreId, (u64)esr.ec, esr.il, esr.iss); + DEBUG("Same EL sync exception on core %x, EC = 0x%02llx IL=%llu ISS=0x%06llx\n", currentCoreCtx->coreId, (u64)esr.ec, esr.il, esr.iss); dumpStackFrame(frame, true); } void handleUnknownException(u32 offset) { - serialLog("Unknown exception on core %x! (offset 0x%03lx)\n", offset, currentCoreCtx->coreId); + DEBUG("Unknown exception on core %x! (offset 0x%03lx)\n", offset, currentCoreCtx->coreId); } diff --git a/thermosphere/src/hvc.c b/thermosphere/src/hvc.c index 503374c03..5292ae019 100644 --- a/thermosphere/src/hvc.c +++ b/thermosphere/src/hvc.c @@ -15,14 +15,14 @@ */ #include "hvc.h" -#include "log.h" +#include "debug_log.h" void handleHypercall(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr) { u32 id = esr.iss; switch (id) { default: - serialLog("Unhandled hypercall: 0x%x.\n"); + DEBUG("Unhandled hypercall: 0x%x.\n"); dumpStackFrame(frame, false); break; } diff --git a/thermosphere/src/main.c b/thermosphere/src/main.c index ebad686e8..5c940adfe 100644 --- a/thermosphere/src/main.c +++ b/thermosphere/src/main.c @@ -1,6 +1,6 @@ #include "utils.h" #include "core_ctx.h" -#include "log.h" +#include "debug_log.h" #include "platform/uart.h" #include "traps.h" @@ -10,11 +10,11 @@ int main(void) if (currentCoreCtx->coreId == 0) { uartInit(115200); - serialLog("Hello from Thermosphere!\n"); + DEBUG("Hello from Thermosphere!\n"); __builtin_trap(); } else { - serialLog("Core %u booted\n", currentCoreCtx->coreId); + DEBUG("Core %u booted\n", currentCoreCtx->coreId); } return 0;