mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Cc: "Claude Sonnet 4.5" <noreply@anthropic.com>
Subject: [PATCH v2 14/21] ARM: exceptions: make in-binary exception table const
Date: Tue, 06 Jan 2026 13:53:17 +0100	[thread overview]
Message-ID: <20260106-pbl-load-elf-v2-14-487bc760f045@pengutronix.de> (raw)
In-Reply-To: <20260106-pbl-load-elf-v2-0-487bc760f045@pengutronix.de>

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@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 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




  parent reply	other threads:[~2026-01-06 13:02 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-06 12:53 [PATCH v2 00/21] PBL: Add PBL ELF loading support with dynamic relocations Sascha Hauer
2026-01-06 12:53 ` [PATCH v2 01/21] elf: only accept images matching the native ELF_CLASS Sascha Hauer
2026-01-06 12:58   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 02/21] elf: build for PBL as well Sascha Hauer
2026-01-06 13:26   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 03/21] elf: add dynamic relocation support Sascha Hauer
2026-01-06 13:51   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 04/21] ARM: implement elf_apply_relocations() for ELF " Sascha Hauer
2026-01-06 13:07   ` Ahmad Fatoum
2026-01-06 14:25     ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 05/21] riscv: define generic relocate_image Sascha Hauer
2026-01-06 13:10   ` Ahmad Fatoum
2026-01-06 13:11     ` Sascha Hauer
2026-01-06 12:53 ` [PATCH v2 06/21] riscv: implement elf_apply_relocations() for ELF relocation support Sascha Hauer
2026-01-06 13:11   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 07/21] elf: implement elf_load_inplace() Sascha Hauer
2026-01-06 13:53   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 08/21] elf: create elf_open_binary_into() Sascha Hauer
2026-01-06 13:55   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 09/21] Makefile: add barebox.elf build target Sascha Hauer
2026-01-06 13:13   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 10/21] PBL: allow to link ELF image into PBL Sascha Hauer
2026-01-06 13:18   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 11/21] mmu: add MAP_CACHED_RO mapping type Sascha Hauer
2026-01-06 13:14   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 12/21] mmu: introduce pbl_remap_range() Sascha Hauer
2026-01-06 13:15   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 13/21] ARM: use relative jumps in exception table Sascha Hauer
2026-01-06 13:57   ` Ahmad Fatoum
2026-01-06 12:53 ` Sascha Hauer [this message]
2026-01-06 14:00   ` [PATCH v2 14/21] ARM: exceptions: make in-binary exception table const Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 15/21] ARM: linker script: create separate PT_LOAD segments for text, rodata, and data Sascha Hauer
2026-01-06 14:05   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 16/21] ARM: link ELF image into PBL Sascha Hauer
2026-01-06 14:06   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 17/21] ARM: PBL: setup MMU with proper permissions from ELF segments Sascha Hauer
2026-01-06 14:10   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 18/21] riscv: link ELF image into PBL Sascha Hauer
2026-01-06 14:11   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 19/21] riscv: linker script: create separate PT_LOAD segments for text, rodata, and data Sascha Hauer
2026-01-06 14:12   ` Ahmad Fatoum
2026-01-08 15:25     ` Sascha Hauer
2026-01-06 12:53 ` [PATCH v2 20/21] riscv: Allwinner D1: Drop M-Mode Sascha Hauer
2026-01-06 13:11   ` Ahmad Fatoum
2026-01-06 12:53 ` [PATCH v2 21/21] riscv: add ELF segment-based memory protection with MMU Sascha Hauer
2026-01-06 14:20   ` Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260106-pbl-load-elf-v2-14-487bc760f045@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=noreply@anthropic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox