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 <[email protected]>
---
 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 
85ee4ca3fd4e5aff8e1e02aa3d7375173a923072..386cf72e7ada73547d811e07b009ffc7fe1c4c0a
 100644
--- a/arch/arm/cpu/exceptions_32.S
+++ b/arch/arm/cpu/exceptions_32.S
@@ -91,24 +91,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
@@ -116,45 +120,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
@@ -187,17 +165,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 
5dc4802fafbfdbcd54707b84835f40177e10742b..385504834d8195201db8028073f76628198fdd1e
 100644
--- a/arch/arm/cpu/interrupts_32.c
+++ b/arch/arm/cpu/interrupts_32.c
@@ -265,3 +265,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 
54371e3e5973c9fe98cadef63499105134e09539..ff52e1d2b6fc763d6210630d181c7d4ed15cdadd
 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -535,10 +535,9 @@ 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);
 }
 
 static void create_zero_page(void)
diff --git a/arch/arm/include/asm/barebox-arm.h 
b/arch/arm/include/asm/barebox-arm.h
index 
e1d89d5684d36f003ba8da3651ae86bda1d9b34c..276807dc484f429f22859e1eda4c88644235c57d
 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -45,10 +45,10 @@ 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);
 ulong arm_get_vector_table(void);
 #else
-static inline void arm_fixup_vectors(void)
+static inline void arm_fixup_vectors(void *table)
 {
 }
 static inline ulong arm_get_vector_table(void)

-- 
2.47.3


Reply via email to