Skip to content

Commit 5c4352b

Browse files
committed
push/pop sections
Setting a section might leave other code in the wrong section. Also https://doc.rust-lang.org/beta/reference/inline-assembly.html#r-asm.directives.stateful says we should undo any stateful changes (like changing the section).
1 parent 861dc66 commit 5c4352b

File tree

11 files changed

+40
-22
lines changed

11 files changed

+40
-22
lines changed

aarch32-rt/src/arch_v4/abort.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ core::arch::global_asm!(
88
// Called from the vector table when we have an undefined exception.
99
// Saves state and calls a C-compatible handler like
1010
// `extern "C" fn _data_abort_handler(addr: usize);`
11-
.section .text._asm_default_data_abort_handler
11+
.pushsection .text._asm_default_data_abort_handler
1212
.arm
1313
.global _asm_default_data_abort_handler
1414
.type _asm_default_data_abort_handler, %function
@@ -36,6 +36,7 @@ core::arch::global_asm!(
3636
pop {{ r12 }} // restore R12
3737
movs pc, lr // return from exception
3838
.size _asm_default_data_abort_handler, . - _asm_default_data_abort_handler
39+
.popsection
3940
"#
4041
);
4142

@@ -47,7 +48,7 @@ core::arch::global_asm!(
4748
// Called from the vector table when we have a prefetch abort.
4849
// Saves state and calls a C-compatible handler like
4950
// `extern "C" fn _prefetch_abort_handler(addr: usize);`
50-
.section .text._asm_default_prefetch_abort_handler
51+
.pushsection .text._asm_default_prefetch_abort_handler
5152
.arm
5253
.global _asm_default_prefetch_abort_handler
5354
.type _asm_default_prefetch_abort_handler, %function
@@ -75,5 +76,6 @@ core::arch::global_asm!(
7576
pop {{ r12 }} // restore R12
7677
movs pc, lr // return from exception
7778
.size _asm_default_prefetch_abort_handler, . - _asm_default_prefetch_abort_handler
79+
.popsection
7880
"#,
7981
);

aarch32-rt/src/arch_v4/interrupt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ core::arch::global_asm!(
1414
//
1515
// See https://developer.arm.com/documentation/dui0203/j/handling-processor-exceptions/armv6-and-earlier--armv7-a-and-armv7-r-profiles/interrupt-handlers
1616
// for details on how we need to save LR_irq, SPSR_irq and LR_sys.
17-
.section .text._asm_default_irq_handler
17+
.pushsection .text._asm_default_irq_handler
1818
.arm
1919
.global _asm_default_irq_handler
2020
.type _asm_default_irq_handler, %function
@@ -43,6 +43,7 @@ core::arch::global_asm!(
4343
msr spsr, lr //
4444
ldmfd sp!, {{ pc }}^ // return from exception (^ => restore SPSR to CPSR)
4545
.size _asm_default_irq_handler, . - _asm_default_irq_handler
46+
.popsection
4647
"#,
4748
// sys mode with IRQ masked
4849
sys_mode = const {

aarch32-rt/src/arch_v4/svc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ core::arch::global_asm!(
99
// Called from the vector table when we have an software interrupt.
1010
// Saves state and calls a C-compatible handler like
1111
// `extern "C" fn _svc_handler(arg: u32, frame: &Frame) -> u32;`
12-
.section .text._asm_default_svc_handler
12+
.pushsection .text._asm_default_svc_handler
1313
.arm
1414
.global _asm_default_svc_handler
1515
.type _asm_default_svc_handler, %function
@@ -47,6 +47,7 @@ core::arch::global_asm!(
4747
msr spsr, lr //
4848
ldmfd sp!, {{ r12, pc }}^ // restore R12 and return from exception (^ => restore SPSR to CPSR)
4949
.size _asm_default_svc_handler, . - _asm_default_svc_handler
50+
.popsection
5051
"#,
5152
t_bit = const { crate::Cpsr::new_with_raw_value(0).with_t(true).raw_value() },
5253
);

aarch32-rt/src/arch_v4/undefined.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ core::arch::global_asm!(
1111
// `extern "C" fn _undefined_handler(addr: usize) -> usize;`
1212
// or
1313
// `extern "C" fn _undefined_handler(addr: usize) -> !;`
14-
.section .text._asm_default_undefined_handler
14+
.pushsection .text._asm_default_undefined_handler
1515
.arm
1616
.global _asm_default_undefined_handler
1717
.type _asm_default_undefined_handler, %function
@@ -42,6 +42,7 @@ core::arch::global_asm!(
4242
pop {{ r12 }} // restore R12
4343
movs pc, lr // return from exception (movs => restore SPSR to CPSR)
4444
.size _asm_default_undefined_handler, . - _asm_default_undefined_handler
45+
.popsection
4546
"#,
4647
t_bit = const { crate::Cpsr::new_with_raw_value(0).with_t(true).raw_value() },
4748
);

aarch32-rt/src/arch_v7/abort.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ core::arch::global_asm!(
99
// Called from the vector table when we have an undefined exception.
1010
// Saves state and calls a C-compatible handler like
1111
// `extern "C" fn _data_abort_handler(addr: usize);`
12-
.section .text._asm_default_data_abort_handler
12+
.pushsection .text._asm_default_data_abort_handler
1313
.arm
1414
.global _asm_default_data_abort_handler
1515
.type _asm_default_data_abort_handler, %function
@@ -35,6 +35,7 @@ core::arch::global_asm!(
3535
str lr, [sp] // overwrite the saved LR with the one from the C handler
3636
rfefd sp! // return from exception
3737
.size _asm_default_data_abort_handler, . - _asm_default_data_abort_handler
38+
.popsection
3839
"#,
3940
abt_mode = const crate::ProcessorMode::Abt as u8,
4041
);
@@ -47,7 +48,7 @@ core::arch::global_asm!(
4748
// Called from the vector table when we have a prefetch abort.
4849
// Saves state and calls a C-compatible handler like
4950
// `extern "C" fn _prefetch_abort_handler(addr: usize);`
50-
.section .text._asm_default_prefetch_abort_handler
51+
.pushsection .text._asm_default_prefetch_abort_handler
5152
.arm
5253
.global _asm_default_prefetch_abort_handler
5354
.type _asm_default_prefetch_abort_handler, %function
@@ -73,6 +74,7 @@ core::arch::global_asm!(
7374
str lr, [sp] // overwrite the saved LR with the one from the C handler
7475
rfefd sp! // return from exception
7576
.size _asm_default_prefetch_abort_handler, . - _asm_default_prefetch_abort_handler
77+
.popsection
7678
"#,
7779
abt_mode = const crate::ProcessorMode::Abt as u8,
7880
);

aarch32-rt/src/arch_v7/interrupt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ core::arch::global_asm!(
1212
//
1313
// See https://developer.arm.com/documentation/dui0203/j/handling-processor-exceptions/armv6-and-earlier--armv7-a-and-armv7-r-profiles/interrupt-handlers
1414
// for details on how we need to save LR_irq, SPSR_irq and LR_sys.
15-
.section .text._asm_default_irq_handler
15+
.pushsection .text._asm_default_irq_handler
1616
.arm
1717
.global _asm_default_irq_handler
1818
.type _asm_default_irq_handler, %function
@@ -36,6 +36,7 @@ core::arch::global_asm!(
3636
pop {{ lr }} // restore adjusted LR
3737
rfefd sp! // return from exception
3838
.size _asm_default_irq_handler, . - _asm_default_irq_handler
39+
.popsection
3940
"#,
4041
sys_mode = const crate::ProcessorMode::Sys as u8,
4142
);

aarch32-rt/src/arch_v7/svc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ core::arch::global_asm!(
99
// Called from the vector table when we have an software interrupt.
1010
// Saves state and calls a C-compatible handler like
1111
// `extern "C" fn _svc_handler(arg: u32, frame: &Frame) -> u32;`
12-
.section .text._asm_default_svc_handler
12+
.pushsection .text._asm_default_svc_handler
1313
.arm
1414
.global _asm_default_svc_handler
1515
.type _asm_default_svc_handler, %function
@@ -41,6 +41,7 @@ core::arch::global_asm!(
4141
pop {{ r12, lr }} // restore R12 and LR
4242
rfefd sp! // return from exception
4343
.size _asm_default_svc_handler, . - _asm_default_svc_handler
44+
.popsection
4445
"#,
4546
svc_mode = const crate::ProcessorMode::Svc as u8,
4647
t_bit = const { crate::Cpsr::new_with_raw_value(0).with_t(true).raw_value() },

aarch32-rt/src/arch_v7/undefined.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ core::arch::global_asm!(
1111
// `extern "C" fn _undefined_handler(addr: usize) -> usize;`
1212
// or
1313
// `extern "C" fn _undefined_handler(addr: usize) -> !;`
14-
.section .text._asm_default_undefined_handler
14+
.pushsection .text._asm_default_undefined_handler
1515
.arm
1616
.global _asm_default_undefined_handler
1717
.type _asm_default_undefined_handler, %function
@@ -41,6 +41,7 @@ core::arch::global_asm!(
4141
str lr, [sp] // overwrite the saved LR with the one from the C handler
4242
rfefd sp! // return from exception
4343
.size _asm_default_undefined_handler, . - _asm_default_undefined_handler
44+
.popsection
4445
"#,
4546
und_mode = const crate::ProcessorMode::Und as u8,
4647
t_bit = const { crate::Cpsr::new_with_raw_value(0).with_t(true).raw_value() },

aarch32-rt/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ pub extern "C" fn _default_handler() {
532532
#[cfg(target_arch = "arm")]
533533
core::arch::global_asm!(
534534
r#"
535-
.section .vector_table,"ax",%progbits
535+
.pushsection .vector_table,"ax",%progbits
536536
.arm
537537
.global _vector_table
538538
.type _vector_table, %function
@@ -547,6 +547,7 @@ core::arch::global_asm!(
547547
ldr pc, =_asm_irq_handler
548548
ldr pc, =_asm_fiq_handler
549549
.size _vector_table, . - _vector_table
550+
.popsection
550551
"#
551552
);
552553

@@ -699,14 +700,15 @@ macro_rules! restore_fpu_context {
699700
#[cfg(target_arch = "arm")]
700701
core::arch::global_asm!(
701702
r#"
702-
.section .text._asm_default_fiq_handler
703+
.pushsection .text._asm_default_fiq_handler
703704
704705
// Our default FIQ handler
705706
.global _asm_default_fiq_handler
706707
.type _asm_default_fiq_handler, %function
707708
_asm_default_fiq_handler:
708709
b _asm_default_fiq_handler
709710
.size _asm_default_fiq_handler, . - _asm_default_fiq_handler
711+
.popsection
710712
"#,
711713
);
712714

@@ -750,7 +752,7 @@ core::arch::global_asm!(
750752
751753
// Configure a stack for every mode. Leaves you in sys mode.
752754
//
753-
.section .text._stack_setup_preallocated
755+
.pushsection .text._stack_setup_preallocated
754756
.global _stack_setup_preallocated
755757
.type _stack_setup_preallocated, %function
756758
_stack_setup_preallocated:
@@ -783,9 +785,10 @@ core::arch::global_asm!(
783785
// return to caller
784786
bx r2
785787
.size _stack_setup_preallocated, . - _stack_setup_preallocated
788+
.popsection
786789
787790
// Initialises stacks, .data and .bss
788-
.section .text._init_segments
791+
.pushsection .text._init_segments
789792
.arm
790793
.global _init_segments
791794
.type _init_segments, %function
@@ -814,6 +817,7 @@ core::arch::global_asm!(
814817
// return to caller
815818
bx lr
816819
.size _init_segments, . - _init_segments
820+
.popsection
817821
"#,
818822
und_mode = const {
819823
Cpsr::new_with_raw_value(0)
@@ -873,7 +877,7 @@ core::arch::global_asm!(
873877
// Work around https://github.com/rust-lang/rust/issues/127269
874878
.fpu vfp2
875879
876-
.section .text.default_start
880+
.pushsection .text.default_start
877881
.arm
878882
.global _default_start
879883
.type _default_start, %function
@@ -904,6 +908,7 @@ core::arch::global_asm!(
904908
// In case the application returns, loop forever
905909
b .
906910
.size _default_start, . - _default_start
911+
.popsection
907912
"#
908913
);
909914

@@ -919,7 +924,7 @@ core::arch::global_asm!(
919924
// Work around https://github.com/rust-lang/rust/issues/127269
920925
.fpu vfp2
921926
922-
.section .text.default_start
927+
.pushsection .text.default_start
923928
.arm
924929
.global _default_start
925930
.type _default_start, %function
@@ -978,6 +983,7 @@ core::arch::global_asm!(
978983
// In case the application returns, loop forever
979984
b .
980985
.size _default_start, . - _default_start
986+
.popsection
981987
"#,
982988
cpsr_mode_hyp = const ProcessorMode::Hyp as u8,
983989
hactlr_bits = const {

examples/mps3-an536/src/bin/el2_hello.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ core::arch::global_asm!(
3838
// Work around https://github.com/rust-lang/rust/issues/127269
3939
.fpu vfp3-d16
4040
41-
.section .text.start
42-
41+
.pushsection .text.start
4342
.global _start
4443
.type _start, %function
4544
_start:
@@ -81,6 +80,7 @@ core::arch::global_asm!(
8180
// In case the application returns, loop forever
8281
b .
8382
.size _start, . - _start
83+
.popsection
8484
"#,
8585
hactlr_bits = const {
8686
Hactlr::new_with_raw_value(0)

0 commit comments

Comments
 (0)