aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan McIntyre <me@mciantyre.dev>2025-06-14 11:23:18 -0400
committerIan McIntyre <me@mciantyre.dev>2025-09-16 07:48:07 -0400
commitaed7296b291c6430e24e6bd4c787cd724830d956 (patch)
tree54fb0b6786ae695f625226481490825d6731d331 /src
parentb91a6a6f11e014f96c91e5a67bef805349de7b43 (diff)
Use a macro for assembly copy loops
Make it easier to write loops for other sections. Since the macro expands to the same instructions that we previously had, we can show that a binary is equivalent before and after this change. Let's use the binaries generated in this test suite. Before this change, run the bash script below. Re-run this script with this change, and show that the hashes for the binaries are the same. cargo clean cargo test inspect_elf -- --include-ignored --exact imxrt1010evk imxrt1170evk_cm7 imxrt1170evk_cm7_nonboot teensy4 teensy4_fake_dcd 2> /dev/null 1>/dev/null for test_binary in imxrt1010evk imxrt1170evk-cm7 imxrt1170evk-cm7-nonboot teensy4 __dcd; do cat target/${test_binary}/thumbv7em-none-eabihf/debug/examples/blink-rtic | sha256sum -; done
Diffstat (limited to 'src')
-rw-r--r--src/target.rs63
1 files changed, 19 insertions, 44 deletions
diff --git a/src/target.rs b/src/target.rs
index 90b89c3..96ae9f7 100644
--- a/src/target.rs
+++ b/src/target.rs
@@ -39,6 +39,22 @@ global_asm! {r#"
.thumb_func
.cfi_startproc
+.macro copy_section dst, src, end
+ ldr r0, =\dst
+ ldr r2, =\src
+ cmp r2, r0
+ beq 999f
+
+ ldr r1, =\end
+ 888:
+ cmp r1, r0
+ beq 999f
+ ldm r2!, {{r3}}
+ stm r0!, {{r3}}
+ b 888b
+ 999:
+.endm
+
__pre_init:
ldr r0, =__imxrt_rt_v0.2 @ Need to know which chip family we're initializing.
ldr r1, =0x1180
@@ -77,50 +93,9 @@ __pre_init:
str r1, [r0, #0]
1000:
- # Conditionally copy text.
- ldr r0, =__stext
- ldr r2, =__sitext
- cmp r2, r0
- beq 42f
-
- ldr r1, =__etext
- 43:
- cmp r1, r0
- beq 42f
- ldm r2!, {{r3}}
- stm r0!, {{r3}}
- b 43b
- 42:
-
- # Conditionally copy the vector table.
- ldr r0, =__svector_table
- ldr r2, =__sivector_table
- cmp r2, r0
- beq 52f
-
- ldr r1, =__evector_table
- 53:
- cmp r1, r0
- beq 52f
- ldm r2!, {{r3}}
- stm r0!, {{r3}}
- b 53b
- 52:
-
- # Conditionally copy read-only data.
- ldr r0, =__srodata
- ldr r2, =__sirodata
- cmp r2, r0
- beq 62f
-
- ldr r1, =__erodata
- 63:
- cmp r1, r0
- beq 62f
- ldm r2!, {{r3}}
- stm r0!, {{r3}}
- b 63b
- 62:
+ copy_section __stext , __sitext , __etext
+ copy_section __svector_table , __sivector_table , __evector_table
+ copy_section __srodata , __sirodata , __erodata
# All done; back to the reset handler.
bx lr