Skip to content

Commit 0077dc6

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 a3c01a7 commit 0077dc6

File tree

13 files changed

+42
-22
lines changed

13 files changed

+42
-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/hvc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ core::arch::global_asm!(
77
.fpu vfp2
88
99
// Never called but makes the linker happy
10-
.section .text._asm_default_hvc_handler
10+
.pushsection .text._asm_default_hvc_handler
1111
.arm
1212
.global _asm_default_hvc_handler
1313
.type _asm_default_hvc_handler, %function
1414
_asm_default_hvc_handler:
1515
b .
1616
.size _asm_default_hvc_handler, . - _asm_default_hvc_handler
17+
.popsection
1718
"#,
1819
);

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
@@ -46,6 +46,7 @@ core::arch::global_asm!(
4646
msr spsr, lr //
4747
ldmfd sp!, {{ r12, pc }}^ // restore R12 and return from exception (^ => restore SPSR to CPSR)
4848
.size _asm_default_svc_handler, . - _asm_default_svc_handler
49+
.popsection
4950
"#,
5051
t_bit = const { crate::Cpsr::new_with_raw_value(0).with_t(true).raw_value() },
5152
);

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/hvc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ core::arch::global_asm!(
77
// Work around https://github.com/rust-lang/rust/issues/127269
88
.fpu vfp3
99
10-
.section .text._asm_default_hvc_handler
10+
.pushsection .text._asm_default_hvc_handler
1111
1212
// Called from the vector table when we have an hypervisor call.
1313
// Saves state and calls a C-compatible handler like
@@ -33,6 +33,7 @@ core::arch::global_asm!(
3333
pop {{ r12, lr }} // pop state from stack
3434
eret // Return from the asm handler
3535
.size _asm_default_hvc_handler, . - _asm_default_hvc_handler
36+
.popsection
3637
"#,
3738
);
3839

@@ -45,12 +46,13 @@ core::arch::global_asm!(
4546
4647
4748
// Never called but makes the linker happy
48-
.section .text._asm_default_hvc_handler
49+
.pushsection .text._asm_default_hvc_handler
4950
.arm
5051
.global _asm_default_hvc_handler
5152
.type _asm_default_hvc_handler, %function
5253
_asm_default_hvc_handler:
5354
b .
5455
.size _asm_default_hvc_handler, . - _asm_default_hvc_handler
56+
.popsection
5557
"#,
5658
);

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
@@ -40,6 +40,7 @@ core::arch::global_asm!(
4040
pop {{ r12, lr }} // restore R12 and LR
4141
rfefd sp! // return from exception
4242
.size _asm_default_svc_handler, . - _asm_default_svc_handler
43+
.popsection
4344
"#,
4445
svc_mode = const crate::ProcessorMode::Svc as u8,
4546
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() },

0 commit comments

Comments
 (0)