Skip to content

Commit ac2de3f

Browse files
wearyzennashif
authored andcommitted
arch: arm: cortex_a_r: Set VBAR for all cores
What is changed? Secondary cores can now boot successfully on cache and non-cache coherent systems if the Zephyr image/vector table is loaded at an address other than the default address 0x0. How is it changed? 1. By calling the relocate_vector() from reset.S as part of EL1 reset initialization instead of prep_c to have VBAR set for all cores and not just for the primary core. 2. Remove dead code under CONFIG_SW_VECTOR_RELAY and CONFIG_SW_VECTOR_RELAY_CLIENT. Why do we need this change? 1. As reported in issue #76182, on Cortex_ar, VBAR is set only for the primary cores while VBAR for the secondary cores are left with default value 0. This results in Zephyr not booting on secondary cores if the vector table for secondary cores is loaded at an address other than 0x0. VBAR is set in relocate_vector() so we move it to reboot.c which is better suited to have configs related to system control block. 2. The two SW_VECTOR_RELAY configs have a direct dependency on CONFIG_CPU_CORTEX_M, which is disabled while compiling for Cortex-A and Cortex-R hence leading to a dead code. How is the change verified? Verified with fvp_baser_aemv8r/fvp_aemv8r_aarch32/smp. Signed-off-by: Sudan Landge <[email protected]>
1 parent 2c95978 commit ac2de3f

File tree

3 files changed

+55
-51
lines changed

3 files changed

+55
-51
lines changed

arch/arm/core/cortex_a_r/prep_c.c

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2013-2014 Wind River Systems, Inc.
3+
* Copyright 2024 Arm Limited and/or its affiliates <[email protected]>
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -28,63 +29,13 @@
2829
#include <cortex_a_r/stack.h>
2930
#endif
3031

31-
#if defined(__GNUC__)
32-
/*
33-
* GCC can detect if memcpy is passed a NULL argument, however one of
34-
* the cases of relocate_vector_table() it is valid to pass NULL, so we
35-
* suppress the warning for this case. We need to do this before
36-
* string.h is included to get the declaration of memcpy.
37-
*/
38-
#pragma GCC diagnostic push
39-
#pragma GCC diagnostic ignored "-Wnonnull"
40-
#endif
41-
42-
#include <string.h>
43-
44-
#if defined(CONFIG_SW_VECTOR_RELAY) || defined(CONFIG_SW_VECTOR_RELAY_CLIENT)
45-
Z_GENERIC_SECTION(.vt_pointer_section) __attribute__((used))
46-
void *_vector_table_pointer;
47-
#endif
48-
4932
#ifdef CONFIG_ARM_MPU
5033
extern void z_arm_mpu_init(void);
5134
extern void z_arm_configure_static_mpu_regions(void);
5235
#elif defined(CONFIG_ARM_AARCH32_MMU)
5336
extern int z_arm_mmu_init(void);
5437
#endif
5538

56-
#if defined(CONFIG_AARCH32_ARMV8_R)
57-
58-
#define VECTOR_ADDRESS ((uintptr_t)_vector_start)
59-
60-
static inline void relocate_vector_table(void)
61-
{
62-
write_sctlr(read_sctlr() & ~HIVECS);
63-
write_vbar(VECTOR_ADDRESS & VBAR_MASK);
64-
barrier_isync_fence_full();
65-
}
66-
67-
#else
68-
#define VECTOR_ADDRESS 0
69-
70-
void __weak relocate_vector_table(void)
71-
{
72-
#if defined(CONFIG_XIP) && (CONFIG_FLASH_BASE_ADDRESS != 0) || \
73-
!defined(CONFIG_XIP) && (CONFIG_SRAM_BASE_ADDRESS != 0)
74-
write_sctlr(read_sctlr() & ~HIVECS);
75-
size_t vector_size = (size_t)_vector_end - (size_t)_vector_start;
76-
(void)memcpy(VECTOR_ADDRESS, _vector_start, vector_size);
77-
#elif defined(CONFIG_SW_VECTOR_RELAY) || defined(CONFIG_SW_VECTOR_RELAY_CLIENT)
78-
_vector_table_pointer = _vector_start;
79-
#endif
80-
}
81-
82-
#if defined(__GNUC__)
83-
#pragma GCC diagnostic pop
84-
#endif
85-
86-
#endif /* CONFIG_AARCH32_ARMV8_R */
87-
8839
#if defined(CONFIG_CPU_HAS_FPU)
8940

9041
static inline void z_arm_floating_point_init(void)
@@ -155,7 +106,6 @@ void z_prep_c(void)
155106
/* Initialize tpidruro with our struct _cpu instance address */
156107
write_tpidruro((uintptr_t)&_kernel.cpus[0]);
157108

158-
relocate_vector_table();
159109
#if defined(CONFIG_CPU_HAS_FPU)
160110
z_arm_floating_point_init();
161111
#endif

arch/arm/core/cortex_a_r/reboot.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2013-2014 Wind River Systems, Inc.
3+
* Copyright 2024 Arm Limited and/or its affiliates <[email protected]>
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -12,6 +13,56 @@
1213
#include <zephyr/kernel.h>
1314
#include <zephyr/arch/cpu.h>
1415
#include <zephyr/sys/util.h>
16+
#include <zephyr/linker/linker-defs.h>
17+
18+
#if defined(CONFIG_AARCH32_ARMV8_R)
19+
20+
#define VECTOR_ADDRESS ((uintptr_t)_vector_start)
21+
22+
static inline void relocate_vector_table(void)
23+
{
24+
write_sctlr(read_sctlr() & ~HIVECS);
25+
write_vbar(VECTOR_ADDRESS & VBAR_MASK);
26+
barrier_isync_fence_full();
27+
}
28+
29+
#else
30+
31+
#if defined(__GNUC__)
32+
/*
33+
* GCC can detect if memcpy is passed a NULL argument, however one of
34+
* the cases of relocate_vector_table() it is valid to pass NULL, so we
35+
* suppress the warning for this case. We need to do this before
36+
* string.h is included to get the declaration of memcpy.
37+
*/
38+
#pragma GCC diagnostic push
39+
#pragma GCC diagnostic ignored "-Wnonnull"
40+
#endif /* __GNUC__ */
41+
42+
#include <string.h>
43+
44+
#define VECTOR_ADDRESS 0
45+
46+
void __weak relocate_vector_table(void)
47+
{
48+
#if defined(CONFIG_XIP) && (CONFIG_FLASH_BASE_ADDRESS != 0) || \
49+
!defined(CONFIG_XIP) && (CONFIG_SRAM_BASE_ADDRESS != 0)
50+
write_sctlr(read_sctlr() & ~HIVECS);
51+
size_t vector_size = (size_t)_vector_end - (size_t)_vector_start;
52+
(void)memcpy(VECTOR_ADDRESS, _vector_start, vector_size);
53+
#endif
54+
}
55+
56+
#if defined(__GNUC__)
57+
#pragma GCC diagnostic pop
58+
#endif
59+
60+
#endif /* !CONFIG_AARCH32_ARMV8_R */
61+
62+
void z_arm_relocate_vector_table(void)
63+
{
64+
relocate_vector_table();
65+
}
1566

1667
/**
1768
*

arch/arm/core/cortex_a_r/reset.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2013-2014 Wind River Systems, Inc.
33
* Copyright (c) 2019 Stephanos Ioannidis <[email protected]>
4+
* Copyright 2024 Arm Limited and/or its affiliates <open-source-[email protected]>
45
*
56
* SPDX-License-Identifier: Apache-2.0
67
*/
@@ -319,4 +320,6 @@ _primary_core:
319320
bl z_arm_tcm_disable_ecc
320321
#endif
321322

323+
bl z_arm_relocate_vector_table
324+
322325
bx r4

0 commit comments

Comments
 (0)