2015-08-20 16:46:11 -04:00
|
|
|
/* ARM Cortex-M GCC specific public inline assembler functions and macros */
|
2015-04-27 13:40:11 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-27 13:40:11 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Either public functions or macros or invoked by public functions */
|
|
|
|
|
2019-11-09 18:48:15 +00:00
|
|
|
#ifndef ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_ASM_INLINE_GCC_H_
|
|
|
|
#define ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_ASM_INLINE_GCC_H_
|
2015-04-27 13:40:11 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The file must not be included directly
|
2015-10-04 09:37:29 -04:00
|
|
|
* Include arch/cpu.h instead
|
2015-04-27 13:40:11 -04:00
|
|
|
*/
|
|
|
|
|
2018-08-10 11:49:06 -04:00
|
|
|
#ifndef _ASMLANGUAGE
|
2015-04-27 13:40:11 -04:00
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 10:32:08 -05:00
|
|
|
#include <zephyr/types.h>
|
2019-11-09 17:49:36 +00:00
|
|
|
#include <arch/arm/aarch32/exc.h>
|
2016-02-25 13:21:02 -08:00
|
|
|
#include <irq.h>
|
2015-04-27 13:40:11 -04:00
|
|
|
|
2019-08-12 12:52:55 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-10-03 10:08:13 -07:00
|
|
|
/* On ARMv7-M and ARMv8-M Mainline CPUs, this function prevents regular
|
2019-02-07 10:01:55 +01:00
|
|
|
* exceptions (i.e. with interrupt priority lower than or equal to
|
|
|
|
* _EXC_IRQ_DEFAULT_PRIO) from interrupting the CPU. NMI, Faults, SVC,
|
|
|
|
* and Zero Latency IRQs (if supported) may still interrupt the CPU.
|
|
|
|
*
|
|
|
|
* On ARMv6-M and ARMv8-M Baseline CPUs, this function reads the value of
|
|
|
|
* PRIMASK which shows if interrupts are enabled, then disables all interrupts
|
|
|
|
* except NMI.
|
2015-07-01 17:22:39 -04:00
|
|
|
*/
|
2015-04-27 13:40:11 -04:00
|
|
|
|
2019-11-07 12:43:29 -08:00
|
|
|
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
|
2015-04-27 13:40:11 -04:00
|
|
|
{
|
|
|
|
unsigned int key;
|
|
|
|
|
2018-02-06 23:47:58 +01:00
|
|
|
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
|
2016-12-02 23:30:45 +00:00
|
|
|
__asm__ volatile("mrs %0, PRIMASK;"
|
|
|
|
"cpsid i"
|
2016-12-02 12:18:04 +00:00
|
|
|
: "=r" (key)
|
|
|
|
:
|
|
|
|
: "memory");
|
2018-02-06 23:47:58 +01:00
|
|
|
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
|
2016-12-02 23:28:49 +00:00
|
|
|
unsigned int tmp;
|
|
|
|
|
2015-04-27 13:40:11 -04:00
|
|
|
__asm__ volatile(
|
2016-12-02 23:30:45 +00:00
|
|
|
"mov %1, %2;"
|
|
|
|
"mrs %0, BASEPRI;"
|
2019-03-06 14:33:58 +01:00
|
|
|
"msr BASEPRI, %1;"
|
|
|
|
"isb;"
|
2016-12-02 23:28:49 +00:00
|
|
|
: "=r"(key), "=r"(tmp)
|
2015-04-27 13:40:11 -04:00
|
|
|
: "i"(_EXC_IRQ_DEFAULT_PRIO)
|
2016-12-02 23:28:49 +00:00
|
|
|
: "memory");
|
2018-06-25 09:15:14 -04:00
|
|
|
#elif defined(CONFIG_ARMV7_R)
|
|
|
|
__asm__ volatile("mrs %0, cpsr;"
|
|
|
|
"cpsid i"
|
|
|
|
: "=r" (key)
|
|
|
|
:
|
|
|
|
: "memory", "cc");
|
2016-12-31 13:18:25 +00:00
|
|
|
#else
|
|
|
|
#error Unknown ARM architecture
|
2018-02-06 23:47:58 +01:00
|
|
|
#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */
|
2015-04-27 13:40:11 -04:00
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-03 10:08:13 -07:00
|
|
|
/* On Cortex-M0/M0+, this enables all interrupts if they were not
|
2016-10-05 19:43:36 -03:00
|
|
|
* previously disabled.
|
2015-07-01 17:22:39 -04:00
|
|
|
*/
|
2015-04-27 13:40:11 -04:00
|
|
|
|
2019-11-07 12:43:29 -08:00
|
|
|
static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
|
2015-04-27 13:40:11 -04:00
|
|
|
{
|
2018-02-06 23:47:58 +01:00
|
|
|
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
|
2016-10-05 19:43:36 -03:00
|
|
|
if (key) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-06 20:12:26 +01:00
|
|
|
__asm__ volatile(
|
|
|
|
"cpsie i;"
|
|
|
|
"isb"
|
|
|
|
: : : "memory");
|
2018-02-06 23:47:58 +01:00
|
|
|
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
|
2019-03-06 20:12:26 +01:00
|
|
|
__asm__ volatile(
|
|
|
|
"msr BASEPRI, %0;"
|
|
|
|
"isb;"
|
|
|
|
: : "r"(key) : "memory");
|
2018-06-25 09:15:14 -04:00
|
|
|
#elif defined(CONFIG_ARMV7_R)
|
|
|
|
__asm__ volatile("msr cpsr_c, %0"
|
|
|
|
:
|
|
|
|
: "r" (key)
|
|
|
|
: "memory", "cc");
|
2016-12-31 13:18:25 +00:00
|
|
|
#else
|
|
|
|
#error Unknown ARM architecture
|
2018-02-06 23:47:58 +01:00
|
|
|
#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */
|
2015-04-27 13:40:11 -04:00
|
|
|
}
|
|
|
|
|
2019-11-07 12:43:29 -08:00
|
|
|
static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
|
2019-05-24 09:24:35 -07:00
|
|
|
{
|
|
|
|
/* This convention works for both PRIMASK and BASEPRI */
|
|
|
|
return key == 0;
|
|
|
|
}
|
2015-04-27 13:40:11 -04:00
|
|
|
|
2016-01-22 12:38:49 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-12 12:52:55 -05:00
|
|
|
#endif /* _ASMLANGUAGE */
|
|
|
|
|
2019-11-09 18:48:15 +00:00
|
|
|
#endif /* ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_ASM_INLINE_GCC_H_ */
|