[PATCH 13/19] ARM: exceptions: make in-binary exception table const
Sascha Hauer
s.hauer at pengutronix.de
Mon Jan 5 03:26:54 PST 2026
When making the .text section const we can no longer modify the code.
On ARMv5/v6 we finally use a copy of the exception table anyway, so
instead of modifying it in-place and copy afterwards, copy it first and
then modify it.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
arch/arm/cpu/exceptions_32.S | 40 ++++++--------------------------------
arch/arm/cpu/interrupts_32.c | 38 ++++++++++++++++++++++++++++++++++++
arch/arm/cpu/mmu_32.c | 3 +--
arch/arm/include/asm/barebox-arm.h | 4 ++--
4 files changed, 47 insertions(+), 38 deletions(-)
diff --git a/arch/arm/cpu/exceptions_32.S b/arch/arm/cpu/exceptions_32.S
index 302e4d030d6347e8fdb488db73a0a3a4bb1c0ec7..e4a54897bf9fe134fbc48a69a4c5a2efce2acbbc 100644
--- a/arch/arm/cpu/exceptions_32.S
+++ b/arch/arm/cpu/exceptions_32.S
@@ -92,24 +92,28 @@ do_abort_\@:
.arm
.align 5
+.globl undefined_instruction
undefined_instruction:
get_bad_stack
bad_save_user_regs
bl do_undefined_instruction
.align 5
+.globl software_interrupt
software_interrupt:
get_bad_stack
bad_save_user_regs
bl do_software_interrupt
.align 5
+.globl prefetch_abort
prefetch_abort:
get_bad_stack
bad_save_user_regs
bl do_prefetch_abort
.align 5
+.globl data_abort
data_abort:
try_data_abort
get_bad_stack
@@ -117,45 +121,19 @@ data_abort:
bl do_data_abort
.align 5
+.globl irq
irq:
get_bad_stack
bad_save_user_regs
bl do_irq
.align 5
+.globl fiq
fiq:
get_bad_stack
bad_save_user_regs
bl do_fiq
-#ifdef CONFIG_ARM_EXCEPTIONS
-/*
- * With relocatable binary support the runtime exception vectors do not match
- * the addresses in the binary. We have to fix them up during runtime
- */
-ENTRY(arm_fixup_vectors)
- ldr r0, =undefined_instruction
- ldr r1, =_undefined_instruction
- str r0, [r1]
- ldr r0, =software_interrupt
- ldr r1, =_software_interrupt
- str r0, [r1]
- ldr r0, =prefetch_abort
- ldr r1, =_prefetch_abort
- str r0, [r1]
- ldr r0, =data_abort
- ldr r1, =_data_abort
- str r0, [r1]
- ldr r0, =irq
- ldr r1, =_irq
- str r0, [r1]
- ldr r0, =fiq
- ldr r1, =_fiq
- str r0, [r1]
- bx lr
-ENDPROC(arm_fixup_vectors)
-#endif
-
.section .text_inplace_exceptions
1: b 1b /* barebox_arm_reset_vector */
#ifdef CONFIG_ARM_EXCEPTIONS
@@ -188,17 +166,11 @@ extable:
1: b 1b /* (reserved) */
ldr pc, _irq /* irq (interrupt) */
ldr pc, _fiq /* fiq (fast interrupt) */
-.globl _undefined_instruction
_undefined_instruction: .word undefined_instruction
-.globl _software_interrupt
_software_interrupt: .word software_interrupt
-.globl _prefetch_abort
_prefetch_abort: .word prefetch_abort
-.globl _data_abort
_data_abort: .word data_abort
-.globl _irq
_irq: .word irq
-.globl _fiq
_fiq: .word fiq
#else
1: b 1b /* undefined instruction */
diff --git a/arch/arm/cpu/interrupts_32.c b/arch/arm/cpu/interrupts_32.c
index 6ebcbcd8dc1299c0333da87e496bc57172691fa8..99a0bce9244e339f69548868ce6efcaf72194f47 100644
--- a/arch/arm/cpu/interrupts_32.c
+++ b/arch/arm/cpu/interrupts_32.c
@@ -184,3 +184,41 @@ void arm_pbl_init_exceptions(void)
set_vbar((unsigned long)__inplace_exceptions_start);
}
#endif
+
+/* This struct must match the assembly exception table in exceptions_32.S */
+struct extable {
+ uint32_t reset;
+ uint32_t undefined_instruction;
+ uint32_t software_interrupt;
+ uint32_t prefetch_abort;
+ uint32_t data_abort;
+ uint32_t reserved;
+ uint32_t irq;
+ uint32_t fiq;
+ void *undefined_instruction_ptr;
+ void *software_interrupt_ptr;
+ void *prefetch_abort_ptr;
+ void *data_abort_ptr;
+ void *reserved_ptr;
+ void *irq_ptr;
+ void *fiq_ptr;
+};
+
+void undefined_instruction(void);
+void software_interrupt(void);
+void prefetch_abort(void);
+void data_abort(void);
+void irq(void);
+void fiq(void);
+
+void arm_fixup_vectors(void *_table)
+{
+ struct extable *table = _table;
+
+ table->undefined_instruction_ptr = undefined_instruction;
+ table->software_interrupt_ptr = software_interrupt;
+ table->prefetch_abort_ptr = prefetch_abort;
+ table->data_abort_ptr = irq;
+ table->irq_ptr = irq;
+ table->fiq_ptr = fiq;
+}
diff --git a/arch/arm/cpu/mmu_32.c b/arch/arm/cpu/mmu_32.c
index 9ce77078d5e35810f2239d82f29f67e2aa2e4d8e..a1d10db009650c2f9322fa8f7e4a54a0430bb2fa 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -538,10 +538,9 @@ static void create_vector_table(unsigned long adr)
get_pte_flags(MAP_CACHED), true);
}
- arm_fixup_vectors();
-
memset(vectors, 0, PAGE_SIZE);
memcpy(vectors, __exceptions_start, __exceptions_stop - __exceptions_start);
+ arm_fixup_vectors(vectors);
}
/**
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index 11be8b85837ea3d1e56d3433b4b7e05eb9e15a47..6c30d9d22e3d3ef6943dd8bca67d8e1394e051d4 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -45,9 +45,9 @@ unsigned long arm_mem_membase_get(void);
unsigned long arm_mem_endmem_get(void);
#ifdef CONFIG_ARM_EXCEPTIONS
-void arm_fixup_vectors(void);
+void arm_fixup_vectors(void *table);
#else
-static inline void arm_fixup_vectors(void)
+static inline void arm_fixup_vectors(void *table)
{
}
#endif
--
2.47.3
More information about the barebox
mailing list