summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatryk Duda <pdk@semihalf.com>2020-08-28 10:45:43 +0200
committerCommit Bot <commit-bot@chromium.org>2020-10-01 14:48:13 +0000
commit49023b8ab95634cfb16bef4346e77461008c368e (patch)
treefe6effa2924c061899fef59c703aeff2b72967e6
parent614d1069dc6ca73840c0b2039507c66c583a9bd3 (diff)
downloadchrome-ec-49023b8ab95634cfb16bef4346e77461008c368e.tar.gz
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 <pdk@semihalf.com> Change-Id: Id4099d2a205f5e6118e83514dc4b88c980054ea9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2381710 Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--core/cortex-m/panic.c26
1 files changed, 17 insertions, 9 deletions
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];