From ba0e5b71a78f3875a723cc85483ec47a5057d391 Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Fri, 28 Aug 2020 12:29:09 +0200 Subject: riscv-rv32i/panic: Use newly provided functions to access panic data This change removes usage of PANIC_DATA_PTR where possible. Now panic data is accessed through functions that performs more checks and in case of writing also moves other data when necessary. BUG=b:165773837, b:162254118 BRANCH=none TEST=make -j buildall Signed-off-by: Patryk Duda Change-Id: I156225d90ea3c7bc5a09e899afd0935e04d71680 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2381713 Reviewed-by: Jett Rink --- core/riscv-rv32i/panic.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/core/riscv-rv32i/panic.c b/core/riscv-rv32i/panic.c index 75a6a5f261..3d8cec1b06 100644 --- a/core/riscv-rv32i/panic.c +++ b/core/riscv-rv32i/panic.c @@ -8,9 +8,6 @@ #include "task.h" #include "util.h" -/* Panic data goes at the end of RAM. */ -static struct panic_data * const pdata_ptr = PANIC_DATA_PTR; - #ifdef CONFIG_DEBUG_EXCEPTIONS /** * bit[3-0] @ mcause, general exception type information. @@ -55,35 +52,44 @@ void software_panic(uint32_t reason, uint32_t info) void panic_set_reason(uint32_t reason, uint32_t info, uint8_t exception) { - uint32_t *regs = pdata_ptr->riscv.regs; + /* + * It is safe to get pointer using get_panic_data_write(). + * If it was called earlier (eg. when saving riscv.mepc) calling it + * once again won't remove any data + */ + struct panic_data * const pdata = get_panic_data_write(); uint32_t warning_mepc; + uint32_t *regs; + + regs = pdata->riscv.regs; /* Setup panic data structure */ if (reason != PANIC_SW_WATCHDOG) { - memset(pdata_ptr, 0, sizeof(*pdata_ptr)); + memset(pdata, 0, CONFIG_PANIC_DATA_SIZE); } else { - warning_mepc = pdata_ptr->riscv.mepc; - memset(pdata_ptr, 0, sizeof(*pdata_ptr)); - pdata_ptr->riscv.mepc = warning_mepc; + warning_mepc = pdata->riscv.mepc; + memset(pdata, 0, CONFIG_PANIC_DATA_SIZE); + pdata->riscv.mepc = warning_mepc; } - pdata_ptr->magic = PANIC_DATA_MAGIC; - pdata_ptr->struct_size = sizeof(*pdata_ptr); - pdata_ptr->struct_version = 2; - pdata_ptr->arch = PANIC_ARCH_RISCV_RV32I; + pdata->magic = PANIC_DATA_MAGIC; + pdata->struct_size = CONFIG_PANIC_DATA_SIZE; + pdata->struct_version = 2; + pdata->arch = PANIC_ARCH_RISCV_RV32I; /* Log panic cause */ - pdata_ptr->riscv.mcause = exception; + pdata->riscv.mcause = exception; regs[SOFT_PANIC_GPR_REASON] = reason; regs[SOFT_PANIC_GPR_INFO] = info; } void panic_get_reason(uint32_t *reason, uint32_t *info, uint8_t *exception) { - uint32_t *regs = pdata_ptr->riscv.regs; + struct panic_data * const pdata = panic_get_data(); + uint32_t *regs; - if (pdata_ptr->magic == PANIC_DATA_MAGIC && - pdata_ptr->struct_version == 2) { - *exception = pdata_ptr->riscv.mcause; + if (pdata && pdata->struct_version == 2) { + regs = pdata->riscv.regs; + *exception = pdata->riscv.mcause; *reason = regs[SOFT_PANIC_GPR_REASON]; *info = regs[SOFT_PANIC_GPR_INFO]; } else { @@ -131,13 +137,13 @@ static void print_panic_information(uint32_t *regs, uint32_t mcause, void report_panic(uint32_t *regs) { uint32_t i, mcause, mepc; - struct panic_data *pdata = pdata_ptr; + struct panic_data * const pdata = get_panic_data_write(); mepc = get_mepc(); mcause = get_mcause(); pdata->magic = PANIC_DATA_MAGIC; - pdata->struct_size = sizeof(*pdata); + pdata->struct_size = CONFIG_PANIC_DATA_SIZE; pdata->struct_version = 2; pdata->arch = PANIC_ARCH_RISCV_RV32I; pdata->flags = 0; -- cgit v1.2.1