From 49023b8ab95634cfb16bef4346e77461008c368e Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Fri, 28 Aug 2020 10:45:43 +0200 Subject: cortex-m/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: Id4099d2a205f5e6118e83514dc4b88c980054ea9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2381710 Reviewed-by: Jett Rink --- core/cortex-m/panic.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'core') diff --git a/core/cortex-m/panic.c b/core/cortex-m/panic.c index afdb3d858d..8fabaf4b21 100644 --- a/core/cortex-m/panic.c +++ b/core/cortex-m/panic.c @@ -289,6 +289,10 @@ void panic_data_print(const struct panic_data *pdata) void __keep report_panic(void) { + /* + * Don't need to get pointer via get_panic_data_write() + * because memory below pdata_ptr is stack now (see exception_panic()) + */ struct panic_data *pdata = pdata_ptr; uint32_t sp; @@ -372,14 +376,17 @@ void software_panic(uint32_t reason, uint32_t info) void panic_set_reason(uint32_t reason, uint32_t info, uint8_t exception) { - uint32_t *lregs = pdata_ptr->cm.regs; + struct panic_data * const pdata = get_panic_data_write(); + uint32_t *lregs; + + lregs = pdata->cm.regs; /* Setup panic data structure */ - memset(pdata_ptr, 0, sizeof(*pdata_ptr)); - pdata_ptr->magic = PANIC_DATA_MAGIC; - pdata_ptr->struct_size = sizeof(*pdata_ptr); - pdata_ptr->struct_version = 2; - pdata_ptr->arch = PANIC_ARCH_CORTEX_M; + memset(pdata, 0, CONFIG_PANIC_DATA_SIZE); + pdata->magic = PANIC_DATA_MAGIC; + pdata->struct_size = CONFIG_PANIC_DATA_SIZE; + pdata->struct_version = 2; + pdata->arch = PANIC_ARCH_CORTEX_M; /* Log panic cause */ lregs[1] = exception; @@ -389,10 +396,11 @@ void panic_set_reason(uint32_t reason, uint32_t info, uint8_t exception) void panic_get_reason(uint32_t *reason, uint32_t *info, uint8_t *exception) { - uint32_t *lregs = pdata_ptr->cm.regs; + struct panic_data * const pdata = panic_get_data(); + uint32_t *lregs; - if (pdata_ptr->magic == PANIC_DATA_MAGIC && - pdata_ptr->struct_version == 2) { + if (pdata && pdata->struct_version == 2) { + lregs = pdata->cm.regs; *exception = lregs[1]; *reason = lregs[3]; *info = lregs[4]; -- cgit v1.2.1