Skip to content

Commit ef15d19

Browse files
committed
fix(rt): use stablized #[unsafe(naked)] attribute on ROM runtime
The feature `naked_functions` is stabilized in rustc on this pull request: rust-lang/rust#134213 Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
1 parent a65e3b0 commit ef15d19

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

allwinner-rt/src/lib.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//! /* code */
1313
//! }
1414
//! ```
15-
#![feature(naked_functions)]
1615
#![no_std]
1716

1817
#[macro_use]
@@ -53,25 +52,24 @@ pub struct EgonHead {
5352
///
5453
/// NOTE: `mxstatus` is a custom T-Head register. Do not confuse with `mstatus`.
5554
/// It allows for configuring special eXtensions. See further below for details.
56-
#[naked]
55+
#[unsafe(naked)]
5756
#[unsafe(link_section = ".text.entry")]
5857
unsafe extern "C" fn start() -> ! {
59-
unsafe {
60-
const STACK_SIZE: usize = 4 * 1024;
61-
#[unsafe(link_section = ".bss.uninit")]
62-
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
63-
core::arch::naked_asm!(
64-
// Enable T-Head ISA extension
65-
"li t1, 1 << 22",
66-
"csrs 0x7C0, t1",
67-
// Invalidate instruction and data cache, branch history table
68-
// and branch target buffer table
69-
"li t1, 0x30013",
70-
"csrs 0x7C2, t1",
71-
// Disable interrupt
72-
"csrw mie, zero",
73-
// Prepare programming language stack
74-
"la sp, {stack}
58+
const STACK_SIZE: usize = 4 * 1024;
59+
#[unsafe(link_section = ".bss.uninit")]
60+
static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE];
61+
core::arch::naked_asm!(
62+
// Enable T-Head ISA extension
63+
"li t1, 1 << 22",
64+
"csrs 0x7C0, t1",
65+
// Invalidate instruction and data cache, branch history table
66+
// and branch target buffer table
67+
"li t1, 0x30013",
68+
"csrs 0x7C2, t1",
69+
// Disable interrupt
70+
"csrw mie, zero",
71+
// Prepare programming language stack
72+
"la sp, {stack}
7573
li t0, {stack_size}
7674
add sp, sp, t0",
7775
// Clear `.bss` section
@@ -82,16 +80,15 @@ unsafe extern "C" fn start() -> ! {
8280
addi t1, t1, 8
8381
j 3b
8482
3: ",
85-
// Start Rust main function
86-
"call {main}",
87-
// Platform halt if main function returns
88-
"3: wfi
89-
j 3b",
90-
stack = sym STACK,
91-
stack_size = const STACK_SIZE,
92-
main = sym main,
93-
)
94-
}
83+
// Start Rust main function
84+
"call {main}",
85+
// Platform halt if main function returns
86+
"3: wfi
87+
j 3b",
88+
stack = sym STACK,
89+
stack_size = const STACK_SIZE,
90+
main = sym main,
91+
)
9592
}
9693

9794
#[rustfmt::skip]

0 commit comments

Comments
 (0)