2015-04-10 16:44:37 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2014 Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-10 16:44:37 -07:00
|
|
|
*/
|
|
|
|
|
2015-12-04 10:09:39 -05:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Cortex-M public error handling
|
|
|
|
*
|
2016-12-23 07:32:56 -05:00
|
|
|
* ARM-specific kernel error handling interface. Included by arm/arch.h.
|
2015-07-01 17:22:39 -04:00
|
|
|
*/
|
2015-04-10 16:44:37 -07:00
|
|
|
|
2019-10-25 00:08:21 +09:00
|
|
|
#ifndef ZEPHYR_INCLUDE_ARCH_ARM_ERROR_H_
|
|
|
|
#define ZEPHYR_INCLUDE_ARCH_ARM_ERROR_H_
|
2015-04-10 16:44:37 -07:00
|
|
|
|
2018-07-31 12:42:59 -05:00
|
|
|
#include <arch/arm/syscall.h>
|
2018-06-08 16:34:16 -04:00
|
|
|
#include <arch/arm/exc.h>
|
2018-09-18 12:32:27 -07:00
|
|
|
#include <stdbool.h>
|
2015-04-10 16:44:37 -07:00
|
|
|
|
2016-01-22 12:38:49 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-02-06 23:47:58 +01:00
|
|
|
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
|
2017-06-01 15:52:30 -07:00
|
|
|
/* ARMv6 will hard-fault if SVC is called with interrupts locked. Just
|
|
|
|
* force them unlocked, the thread is in an undefined state anyway
|
2017-06-07 14:44:58 -07:00
|
|
|
*
|
2019-02-07 10:05:30 +01:00
|
|
|
* On ARMv7m we won't get a HardFault, but if interrupts were locked the
|
2017-06-07 14:44:58 -07:00
|
|
|
* thread will continue executing after the exception and forbid PendSV to
|
|
|
|
* schedule a new thread until they are unlocked which is not what we want.
|
|
|
|
* Force them unlocked as well.
|
2017-06-01 15:52:30 -07:00
|
|
|
*/
|
2019-10-15 19:45:33 +02:00
|
|
|
#define Z_ARCH_EXCEPT(reason_p) \
|
|
|
|
register u32_t r0 __asm__("r0") = reason_p; \
|
|
|
|
do { \
|
2017-06-01 15:52:30 -07:00
|
|
|
__asm__ volatile ( \
|
|
|
|
"cpsie i\n\t" \
|
|
|
|
"svc %[id]\n\t" \
|
|
|
|
: \
|
2019-10-15 19:45:33 +02:00
|
|
|
: "r" (r0), [id] "i" (_SVC_CALL_RUNTIME_EXCEPT) \
|
2017-06-01 15:52:30 -07:00
|
|
|
: "memory"); \
|
2018-09-18 12:32:27 -07:00
|
|
|
} while (false)
|
2018-02-06 23:47:58 +01:00
|
|
|
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
|
2019-03-08 14:19:05 -07:00
|
|
|
#define Z_ARCH_EXCEPT(reason_p) do { \
|
2017-04-19 12:53:48 -07:00
|
|
|
__asm__ volatile ( \
|
2017-06-07 14:44:58 -07:00
|
|
|
"eors.n r0, r0\n\t" \
|
|
|
|
"msr BASEPRI, r0\n\t" \
|
2017-04-19 12:53:48 -07:00
|
|
|
"mov r0, %[reason]\n\t" \
|
|
|
|
"svc %[id]\n\t" \
|
|
|
|
: \
|
|
|
|
: [reason] "i" (reason_p), [id] "i" (_SVC_CALL_RUNTIME_EXCEPT) \
|
|
|
|
: "memory"); \
|
2018-09-18 12:32:27 -07:00
|
|
|
} while (false)
|
2018-06-25 09:15:14 -04:00
|
|
|
#elif defined(CONFIG_ARMV7_R)
|
|
|
|
/* Pick up the default definition in kernel.h for now */
|
2017-06-01 15:52:30 -07:00
|
|
|
#else
|
|
|
|
#error Unknown ARM architecture
|
2018-02-06 23:47:58 +01:00
|
|
|
#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */
|
2017-04-19 12:53:48 -07:00
|
|
|
|
2016-01-22 12:38:49 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-10-25 00:08:21 +09:00
|
|
|
#endif /* ZEPHYR_INCLUDE_ARCH_ARM_ERROR_H_ */
|