diff options
author | Yuval Peress <peress@chromium.org> | 2021-02-12 13:33:48 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-17 22:57:46 +0000 |
commit | 717b8cb62ba1d15ce070ffb35474184672ed8010 (patch) | |
tree | 4ff89109907ecae23707dba5bc545b1448f7a27d | |
parent | 0403bb098edd006d4c0c1b483e8ba591af21b91c (diff) | |
download | chrome-ec-717b8cb62ba1d15ce070ffb35474184672ed8010.tar.gz |
zephyr: cortex-m: Add software panic support
Software panic implementation is needed to support system.c's
system_common_pre_init. For reference, this code was taken from
core/cortex-m/panic.c.
BRANCH=none
BUG=b:167392037
TEST=zmake testall
Change-Id: I91232b297c9933d48e3b7c59d7d8befe84cdecc5
Signed-off-by: Yuval Peress <peress@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2693687
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | include/panic.h | 10 | ||||
-rw-r--r-- | zephyr/shim/CMakeLists.txt | 3 | ||||
-rw-r--r-- | zephyr/shim/core/CMakeLists.txt | 7 | ||||
-rw-r--r-- | zephyr/shim/core/cortex-m/CMakeLists.txt | 5 | ||||
-rw-r--r-- | zephyr/shim/core/cortex-m/software_panic.c | 28 | ||||
-rw-r--r-- | zephyr/shim/src/panic.c | 47 |
6 files changed, 98 insertions, 2 deletions
diff --git a/include/panic.h b/include/panic.h index 664c3c58f0..4d462a1bfb 100644 --- a/include/panic.h +++ b/include/panic.h @@ -192,7 +192,15 @@ void panic_set_reason(uint32_t reason, uint32_t info, uint8_t exception); * Retrieve the currently stored panic reason + info. */ void panic_get_reason(uint32_t *reason, uint32_t *info, uint8_t *exception); -#endif + +#ifdef CONFIG_ZEPHYR +/** + * Zephyr utility for architecture specific logic to run when setting panic + * reason. + */ +void arch_panic_set_reason(uint32_t reason, uint32_t info, uint8_t exception); +#endif /* CONFIG_ZEPHYR */ +#endif /* CONFIG_SOFTWARE_PANIC */ /** * Enable/disable bus fault handler diff --git a/zephyr/shim/CMakeLists.txt b/zephyr/shim/CMakeLists.txt index 3add679c23..e36101756a 100644 --- a/zephyr/shim/CMakeLists.txt +++ b/zephyr/shim/CMakeLists.txt @@ -2,5 +2,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -add_subdirectory("src") add_subdirectory("chip") +add_subdirectory("core") +add_subdirectory("src") diff --git a/zephyr/shim/core/CMakeLists.txt b/zephyr/shim/core/CMakeLists.txt new file mode 100644 index 0000000000..e1b13f21f4 --- /dev/null +++ b/zephyr/shim/core/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +if (DEFINED CONFIG_CPU_CORTEX_M) + add_subdirectory(cortex-m) +endif() diff --git a/zephyr/shim/core/cortex-m/CMakeLists.txt b/zephyr/shim/core/cortex-m/CMakeLists.txt new file mode 100644 index 0000000000..9dc2defce4 --- /dev/null +++ b/zephyr/shim/core/cortex-m/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_SOFTWARE_PANIC software_panic.c) diff --git a/zephyr/shim/core/cortex-m/software_panic.c b/zephyr/shim/core/cortex-m/software_panic.c new file mode 100644 index 0000000000..6bedce5506 --- /dev/null +++ b/zephyr/shim/core/cortex-m/software_panic.c @@ -0,0 +1,28 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* + * Content of this file are taken directly from + * platform/ec/core/cortex-m/panic.c. The code is replicated deliberately to + * allow future refactors into Zephyr specific APIs. + */ + +#include "common.h" +#include "panic.h" + +void software_panic(uint32_t reason, uint32_t info) +{ + /* TODO(b:180422087) Zephyrize this. */ + __asm__("mov " STRINGIFY(SOFTWARE_PANIC_INFO_REG) ", %0\n" + "mov " STRINGIFY(SOFTWARE_PANIC_REASON_REG) ", %1\n" + "bl exception_panic\n" + : : "r"(info), "r"(reason)); + __builtin_unreachable(); +} + +void arch_panic_set_reason(uint32_t reason, uint32_t info, uint8_t exception) +{ + /* No cortex-m architecture specific logic. */ +} diff --git a/zephyr/shim/src/panic.c b/zephyr/shim/src/panic.c index e556fcbcca..6d39ada928 100644 --- a/zephyr/shim/src/panic.c +++ b/zephyr/shim/src/panic.c @@ -9,6 +9,7 @@ #include <logging/log_ctrl.h> #include <zephyr.h> +#include "common.h" #include "panic.h" /* @@ -35,10 +36,21 @@ M(basic.lr, cm.frame[5], lr) \ M(basic.pc, cm.frame[6], pc) \ M(basic.xpsr, cm.frame[7], xpsr) +#define PANIC_REG_EXCEPTION(pdata) pdata->cm.regs[1] +#define PANIC_REG_REASON(pdata) pdata->cm.regs[3] +#define PANIC_REG_INFO(pdata) pdata->cm.regs[4] #else /* Not implemented for this arch */ #define PANIC_ARCH 0 #define PANIC_REG_LIST(M) +#ifdef CONFIG_PLATFORM_EC_SOFTWARE_PANIC +static uint8_t placeholder_exception_reg; +static uint32_t placeholder_reason_reg; +static uint32_t placeholder_info_reg; +#define PANIC_REG_EXCEPTION(unused) placeholder_exception_reg +#define PANIC_REG_REASON(unused) placeholder_reason_reg +#define PANIC_REG_INFO(unused) placeholder_info_reg +#endif /* CONFIG_PLATFORM_EC_SOFTWARE_PANIC */ #endif /* Macros to be applied to PANIC_REG_LIST as M */ @@ -78,3 +90,38 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf) k_fatal_halt(reason); CODE_UNREACHABLE; } + +#ifdef CONFIG_PLATFORM_EC_SOFTWARE_PANIC +void panic_set_reason(uint32_t reason, uint32_t info, uint8_t exception) +{ + struct panic_data * const pdata = get_panic_data_write(); + + /* Setup panic data structure */ + 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; + + /* Log panic cause */ + PANIC_REG_EXCEPTION(pdata) = exception; + PANIC_REG_REASON(pdata) = reason; + PANIC_REG_INFO(pdata) = info; + + /* Allow architecture specific logic */ + arch_panic_set_reason(reason, info, exception); +} + +void panic_get_reason(uint32_t *reason, uint32_t *info, uint8_t *exception) +{ + struct panic_data * const pdata = panic_get_data(); + + if (pdata && pdata->struct_version == 2) { + *exception = PANIC_REG_EXCEPTION(pdata); + *reason = PANIC_REG_REASON(pdata); + *info = PANIC_REG_INFO(pdata); + } else { + *exception = *reason = *info = 0; + } +} +#endif /* CONFIG_PLATFORM_EC_SOFTWARE_PANIC */ |