Skip to content

Commit a97a908

Browse files
author
Bradley Bolen
committed
arch: arm: Add Cortex-R support
This adds initial Cortex-R support for interrupts and context switching. Signed-off-by: Bradley Bolen <[email protected]>
1 parent 688196d commit a97a908

34 files changed

+1247
-75
lines changed

arch/arm/core/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S)
2525
add_subdirectory_ifdef(CONFIG_CPU_CORTEX_M cortex_m)
2626
add_subdirectory_ifdef(CONFIG_ARM_CORE_MPU cortex_m/mpu)
2727
add_subdirectory_ifdef(CONFIG_CPU_CORTEX_M_HAS_CMSE cortex_m/cmse)
28+
29+
add_subdirectory_ifdef(CONFIG_CPU_CORTEX_R cortex_r)

arch/arm/core/Kconfig

+93
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,66 @@ config CPU_CORTEX_M
2626
help
2727
This option signifies the use of a CPU of the Cortex-M family.
2828

29+
config CPU_CORTEX_R
30+
bool
31+
select CPU_CORTEX
32+
select ARCH_HAS_CUSTOM_SWAP_TO_MAIN
33+
select HAS_FLASH_LOAD_OFFSET
34+
select HAS_DTS
35+
select ARCH_HAS_STACK_PROTECTION if ARM_CORE_MPU
36+
select ARCH_HAS_USERSPACE if ARM_CORE_MPU
37+
help
38+
This option signifies the use of a CPU of the Cortex-R family.
39+
40+
config ISA_THUMB2
41+
bool
42+
help
43+
From: http://www.arm.com/products/processors/technologies/instruction-set-architectures.php
44+
45+
Thumb-2 technology is the instruction set underlying the ARM Cortex
46+
architecture which provides enhanced levels of performance, energy
47+
efficiency, and code density for a wide range of embedded
48+
applications.
49+
50+
Thumb-2 technology builds on the success of Thumb, the innovative
51+
high code density instruction set for ARM microprocessor cores, to
52+
increase the power of the ARM microprocessor core available to
53+
developers of low cost, high performance systems.
54+
55+
The technology is backwards compatible with existing ARM and Thumb
56+
solutions, while significantly extending the features available to
57+
the Thumb instructions set. This allows more of the application to
58+
benefit from the best in class code density of Thumb.
59+
60+
For performance optimized code Thumb-2 technology uses 31 percent
61+
less memory to reduce system cost, while providing up to 38 percent
62+
higher performance than existing high density code, which can be used
63+
to prolong battery-life or to enrich the product feature set. Thumb-2
64+
technology is featured in the processor, and in all ARMv7
65+
architecture-based processors.
66+
67+
config ISA_ARM
68+
bool
69+
help
70+
From: https://developer.arm.com/products/architecture/instruction-sets/a32-and-t32-instruction-sets
71+
72+
A32 instructions, known as Arm instructions in pre-Armv8 architectures,
73+
are 32 bits wide, and are aligned on 4-byte boundaries. A32 instructions
74+
are supported by both A-profile and R-profile architectures.
75+
76+
A32 was traditionally used in applications requiring the highest
77+
performance, or for handling hardware exceptions such as interrupts and
78+
processor start-up. Much of its functionality was subsumed into T32 with
79+
the introduction of Thumb-2 technology.
80+
81+
config DATA_ENDIANNESS_LITTLE
82+
bool
83+
default y if CPU_CORTEX
84+
help
85+
This is driven by the processor implementation, since it is fixed in
86+
hardware. The board should set this value to 'n' if the data is
87+
implemented as big endian.
88+
2989
config CPU_HAS_SYSTICK
3090
bool
3191
# Omit prompt to signify "hidden" option
@@ -94,6 +154,38 @@ config ARM_NONSECURE_FIRMWARE
94154
resources of the Cortex-M MCU, and, therefore, it shall avoid
95155
accessing them.
96156

157+
config STACK_ALIGN_DOUBLE_WORD
158+
bool "Align stacks on double-words (8 octets)"
159+
default y
160+
help
161+
This is needed to conform to AAPCS, the procedure call standard for
162+
the ARM. It wastes stack space.
163+
164+
config RUNTIME_NMI
165+
bool
166+
prompt "Attach an NMI handler at runtime"
167+
select REBOOT
168+
help
169+
The kernel provides a simple NMI handler that simply hangs in a tight
170+
loop if triggered. This fills the requirement that there must be an
171+
NMI handler installed when the CPU boots. If a custom handler is
172+
needed, enable this option and attach it via _NmiHandlerSet().
173+
174+
config FAULT_DUMP
175+
int "Fault dump level"
176+
default 2
177+
range 0 2
178+
help
179+
Different levels for display information when a fault occurs.
180+
181+
2: The default. Display specific and verbose information. Consumes
182+
the most memory (long strings).
183+
184+
1: Display general and short information. Consumes less memory
185+
(short strings).
186+
187+
0: Off.
188+
97189
menu "Architecture Floating Point Options"
98190
depends on CPU_HAS_FPU
99191

@@ -122,6 +214,7 @@ endchoice
122214
endmenu
123215

124216
source "arch/arm/core/cortex_m/Kconfig"
217+
source "arch/arm/core/cortex_r/Kconfig"
125218

126219
if CPU_HAS_MPU
127220
source "arch/arm/core/cortex_m/mpu/Kconfig"

arch/arm/core/cortex_m/Kconfig

+1-70
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,6 @@ config CPU_CORTEX_M7
7373

7474
if CPU_CORTEX_M
7575

76-
config ISA_THUMB2
77-
bool
78-
# Omit prompt to signify "hidden" option
79-
help
80-
From: http://www.arm.com/products/processors/technologies/instruction-set-architectures.php
81-
82-
Thumb-2 technology is the instruction set underlying the ARM Cortex
83-
architecture which provides enhanced levels of performance, energy
84-
efficiency, and code density for a wide range of embedded
85-
applications.
86-
87-
Thumb-2 technology builds on the success of Thumb, the innovative
88-
high code density instruction set for ARM microprocessor cores, to
89-
increase the power of the ARM microprocessor core available to
90-
developers of low cost, high performance systems.
91-
92-
The technology is backwards compatible with existing ARM and Thumb
93-
solutions, while significantly extending the features available to
94-
the Thumb instructions set. This allows more of the application to
95-
benefit from the best in class code density of Thumb.
96-
97-
For performance optimized code Thumb-2 technology uses 31 percent
98-
less memory to reduce system cost, while providing up to 38 percent
99-
higher performance than existing high density code, which can be used
100-
to prolong battery-life or to enrich the product feature set. Thumb-2
101-
technology is featured in the processor, and in all ARMv7
102-
architecture-based processors.
103-
10476
config CPU_CORTEX_M_HAS_BASEPRI
10577
bool
10678
# Omit prompt to signify "hidden" option
@@ -267,50 +239,9 @@ config LDREX_STREX_AVAILABLE
267239
bool
268240
default y
269241

270-
config DATA_ENDIANNESS_LITTLE
271-
bool
272-
default y
273-
help
274-
This is driven by the processor implementation, since it is fixed in
275-
hardware. The board should set this value to 'n' if the data is
276-
implemented as big endian.
277-
278-
config STACK_ALIGN_DOUBLE_WORD
279-
bool
280-
prompt "Align stacks on double-words (8 octets)"
281-
default y
282-
help
283-
This is needed to conform to AAPCS, the procedure call standard for
284-
the ARM. It wastes stack space.
285-
286-
config RUNTIME_NMI
287-
bool
288-
prompt "Attach an NMI handler at runtime"
289-
select REBOOT
290-
help
291-
The kernel provides a simple NMI handler that simply hangs in a tight
292-
loop if triggered. This fills the requirement that there must be an
293-
NMI handler installed when the CPU boots. If a custom handler is
294-
needed, enable this option and attach it via _NmiHandlerSet().
295-
296-
config FAULT_DUMP
297-
int
298-
prompt "Fault dump level"
299-
default 2
300-
range 0 2
301-
help
302-
Different levels for display information when a fault occurs.
303-
304-
2: The default. Display specific and verbose information. Consumes
305-
the most memory (long strings).
306-
307-
1: Display general and short information. Consumes less memory
308-
(short strings).
309-
310-
0: Off.
311-
312242
config XIP
313243
default y
244+
314245
endmenu
315246

316247
menu "ARM Cortex-M0/M0+/M3/M4/M7/M23/M33 options"

arch/arm/core/cortex_r/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
zephyr_library()
2+
3+
zephyr_library_sources(
4+
vector_table.S
5+
reset.S
6+
fault.c
7+
exceptions.c
8+
)

arch/arm/core/cortex_r/Kconfig

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Kconfig - ARM Cortex-R platform configuration options
2+
3+
#
4+
# Copyright (c) 2018 Marvell
5+
# Copyright (c) 2018 Lexmark International, Inc.
6+
#
7+
# SPDX-License-Identifier: Apache-2.0
8+
#
9+
10+
# NOTE: We have the specific core implementations first and outside of the
11+
# if CPU_CORTEX_R block so that SoCs can select which core they are using
12+
# without having to select all the options related to that core. Everything
13+
# else is captured inside the if CPU_CORTEX_R block so they are not exposed
14+
# if one selects a different ARM Cortex Family (Cortex-A or Cortex-M)
15+
16+
17+
config CPU_CORTEX_R4
18+
bool
19+
select CPU_CORTEX_R
20+
select ARMV7_R
21+
select ARMV7_M_ARMV8_M_FP if CPU_HAS_FPU
22+
help
23+
This option signifies the use of a Cortex-R4 CPU
24+
25+
if CPU_CORTEX_R
26+
27+
config ARMV7_R
28+
bool
29+
select ATOMIC_OPERATIONS_BUILTIN
30+
select ISA_ARM
31+
help
32+
This option signifies the use of an ARMv7-R processor
33+
implementation, or the use of an ARMv8-R processor
34+
implementation supporting the Main Extension.
35+
36+
Notes:
37+
- A Processing Element (PE) with the Main Extension is also
38+
referred to as a Mainline Implementation.
39+
- ARMv7-R compatibility requires the Main Extension.
40+
41+
From https://developer.arm.com/products/architecture/m-profile:
42+
The Main Extension provides backwards compatibility
43+
with ARMv7-R.
44+
45+
config ARMV7_R_FP
46+
bool
47+
depends on ARMV7_R
48+
help
49+
This option signifies the use of an ARMv7-R processor
50+
implementation, or the use of an ARMv8-R processor
51+
implementation supporting the Floating-Point Extension.
52+
53+
config ARMV7_EXCEPTION_STACK_SIZE
54+
int "Undefined Instruction and Abort stack size (in bytes)"
55+
default 256
56+
help
57+
This option specifies the size of the stack used by the undefined
58+
instruction and data abort exception handlers.
59+
60+
config ARMV7_FIQ_STACK_SIZE
61+
int "FIQ stack size (in bytes)"
62+
default 256
63+
help
64+
This option specifies the size of the stack used by the FIQ handler.
65+
66+
config ARMV7_SVC_STACK_SIZE
67+
int "SVC stack size (in bytes)"
68+
default 512
69+
help
70+
This option specifies the size of the stack used by the SVC handler.
71+
72+
config ARMV7_SYS_STACK_SIZE
73+
int "SYS stack size (in bytes)"
74+
default 1024
75+
help
76+
This option specifies the size of the stack used by the system mode.
77+
78+
menu "ARM Cortex-R options"
79+
depends on CPU_CORTEX_R
80+
81+
config RUNTIME_NMI
82+
def_bool y
83+
84+
config LDREX_STREX_AVAILABLE
85+
def_bool y
86+
87+
config GEN_ISR_TABLES
88+
default y
89+
90+
config GEN_IRQ_VECTOR_TABLE
91+
default n
92+
93+
config XIP
94+
default y
95+
96+
endmenu
97+
98+
endif # CPU_CORTEX_R

arch/arm/core/cortex_r/exceptions.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2018 Lexmark International, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <kernel.h>
8+
9+
K_THREAD_STACK_DEFINE(_fiq_stack, CONFIG_ARMV7_FIQ_STACK_SIZE);
10+
K_THREAD_STACK_DEFINE(_abort_stack, CONFIG_ARMV7_EXCEPTION_STACK_SIZE);
11+
K_THREAD_STACK_DEFINE(_undef_stack, CONFIG_ARMV7_EXCEPTION_STACK_SIZE);
12+
K_THREAD_STACK_DEFINE(_svc_stack, CONFIG_ARMV7_SVC_STACK_SIZE);
13+
K_THREAD_STACK_DEFINE(_sys_stack, CONFIG_ARMV7_SYS_STACK_SIZE);

arch/arm/core/cortex_r/fault.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2018 Lexmark International, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <kernel.h>
8+
9+
/**
10+
*
11+
* @brief Fault handler
12+
*
13+
* This routine is called when fatal error conditions are detected by hardware
14+
* and is responsible only for reporting the error. Once reported, it then
15+
* invokes the user provided routine _SysFatalErrorHandler() which is
16+
* responsible for implementing the error handling policy.
17+
*
18+
* This is a stub for more exception handling code to be added later.
19+
*/
20+
void _Fault(const NANO_ESF *esf)
21+
{
22+
_SysFatalErrorHandler(_NANO_ERR_HW_EXCEPTION, esf);
23+
}
24+
25+
void _FaultInit(void)
26+
{
27+
}

0 commit comments

Comments
 (0)