Skip to content

Commit be1b69f

Browse files
vhscamposkeith-packard
authored andcommitted
Set up exception table base address in AArch32
The exception vector table base address can be different from 0x0 in AArch32 architectures starting from Armv7. In these cases, the register VBAR has the address. This patch initializes VBAR with this base address. So if startup code wants to place the exception vector table at an arbitrary address, exception handling will continue to work.
1 parent da2785b commit be1b69f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

picocrt/machine/arm/crt0.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ _set_stacks(void)
232232
* and then branches here.
233233
*/
234234

235+
extern void __vector_table(void);
236+
235237
static _Noreturn __attribute__((used)) __section(".init") void
236238
_cstart(void)
237239
{
@@ -255,6 +257,12 @@ _cstart(void)
255257
__asm__("vmsr fpexc, %0" : : "r" (0x40000000));
256258
#endif
257259

260+
/* Set up exception table base address (register VBAR_ELx).
261+
Architectures earlier than v7 have the base address fixed. */
262+
#if __ARM_ARCH >= 7
263+
__asm__("mcr p15, #0, %0, c12, c0, 0" : : "r"(__vector_table) :);
264+
#endif
265+
258266
#ifdef _PICOCRT_ENABLE_MMU
259267

260268
#if __ARM_ARCH >= 7 && __ARM_ARCH_PROFILE != 'R'

0 commit comments

Comments
 (0)