Skip to content

Commit

Permalink
rt: use core::arch::naked_asm in naked functions to ensure build unde…
Browse files Browse the repository at this point in the history
…r rustc nightly 2024-10-07

Ref: rust-lang/rust#128651
Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
  • Loading branch information
luojia65 committed Oct 10, 2024
1 parent 6ee8ebf commit bfda4cb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bouffalo-rt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Bouffalo chip ROM runtime library.
#![feature(naked_functions, asm_const)]
#![feature(naked_functions)]
#![no_std]

#[macro_use]
Expand Down
5 changes: 2 additions & 3 deletions bouffalo-rt/src/soc/bl616.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use core::ops::Deref;
#[link_section = ".text.entry"]
#[export_name = "_start"]
unsafe extern "C" fn start() -> ! {
use {crate::Stack, core::arch::asm};
use {crate::Stack, core::arch::naked_asm};
const LEN_STACK: usize = 1 * 1024;
#[link_section = ".bss.uninit"]
static mut STACK: Stack<LEN_STACK> = Stack([0; LEN_STACK]);
asm!(
naked_asm!(
" la sp, {stack}
li t0, {hart_stack_size}
add sp, sp, t0",
Expand All @@ -37,7 +37,6 @@ unsafe extern "C" fn start() -> ! {
stack = sym STACK,
hart_stack_size = const LEN_STACK,
main = sym main,
options(noreturn)
)
}

Expand Down
5 changes: 2 additions & 3 deletions bouffalo-rt/src/soc/bl702.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::HalFlashConfig;
use crate::Stack;

#[cfg(feature = "bl702")]
use core::arch::asm;
use core::arch::naked_asm;
use core::ops::Deref;

#[cfg(feature = "bl702")]
Expand All @@ -21,7 +21,7 @@ const LEN_STACK: usize = 1 * 1024;
unsafe extern "C" fn start() -> ! {
#[link_section = ".bss.uninit"]
static mut STACK: Stack<LEN_STACK> = Stack([0; LEN_STACK]);
asm!(
naked_asm!(
" la sp, {stack}
li t0, {hart_stack_size}
add sp, sp, t0",
Expand All @@ -46,7 +46,6 @@ unsafe extern "C" fn start() -> ! {
stack = sym STACK,
hart_stack_size = const LEN_STACK,
main = sym main,
options(noreturn)
)
}

Expand Down
19 changes: 7 additions & 12 deletions bouffalo-rt/src/soc/bl808.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{HalBasicConfig, HalFlashConfig, HalPatchCfg};
all(feature = "bl808-mcu", target_arch = "riscv32"),
all(feature = "bl808-dsp", target_arch = "riscv64")
))]
use core::arch::asm;
use core::arch::naked_asm;
use core::ops::Deref;

#[cfg(all(feature = "bl808-mcu", target_arch = "riscv32"))]
Expand All @@ -17,7 +17,7 @@ unsafe extern "C" fn start() -> ! {
const LEN_STACK_MCU: usize = 1 * 1024;
#[link_section = ".bss.uninit"]
static mut STACK: Stack<LEN_STACK_MCU> = Stack([0; LEN_STACK_MCU]);
asm!(
naked_asm!(
" la sp, {stack}
li t0, {hart_stack_size}
add sp, sp, t0",
Expand Down Expand Up @@ -57,7 +57,6 @@ unsafe extern "C" fn start() -> ! {
stack_protect_pmp_address_end = const {0x62030000},
stack_protect_pmp_flags = const 0b00001000, // -r, -w, -x, tor, not locked
main = sym main,
options(noreturn)
)
}

Expand All @@ -70,7 +69,7 @@ unsafe extern "C" fn start() -> ! {
const LEN_STACK_DSP: usize = 4 * 1024;
#[link_section = ".bss.uninit"]
static mut STACK: Stack<LEN_STACK_DSP> = Stack([0; LEN_STACK_DSP]);
asm!(
naked_asm!(
" la sp, {stack}
li t0, {hart_stack_size}
add sp, sp, t0",
Expand Down Expand Up @@ -106,7 +105,6 @@ unsafe extern "C" fn start() -> ! {
stack_protect_pmp_address = const {(0x3E000000 >> 2) + (16 * 1024 * 1024 >> 3) - 1},
stack_protect_pmp_flags = const 0b00011000, // -r, -w, -x, napot, not locked
main = sym main,
options(noreturn)
)
}

Expand All @@ -127,7 +125,7 @@ extern "Rust" {
#[link_section = ".trap.trap-entry"]
#[naked]
unsafe extern "C" fn trap_vectored() -> ! {
asm!(
naked_asm!(
".p2align 2",
"j {exceptions}",
"j {supervisor_software}",
Expand Down Expand Up @@ -156,7 +154,6 @@ unsafe extern "C" fn trap_vectored() -> ! {
supervisor_external = sym reserved,
thead_hpm_overflow = sym reserved,
reserved = sym reserved,
options(noreturn)
)
}

Expand All @@ -166,7 +163,7 @@ unsafe extern "C" fn trap_vectored() -> ! {
))]
#[naked]
unsafe extern "C" fn reserved() -> ! {
asm!("1: j 1b", options(noreturn))
naked_asm!("1: j 1b")
}

#[cfg(any(
Expand All @@ -183,7 +180,7 @@ extern "C" {
))]
#[naked]
unsafe extern "C" fn exceptions_trampoline() -> ! {
asm!(
naked_asm!(
"addi sp, sp, -19*8",
"sd ra, 0*8(sp)",
"sd t0, 1*8(sp)",
Expand Down Expand Up @@ -235,7 +232,6 @@ unsafe extern "C" fn exceptions_trampoline() -> ! {
"addi sp, sp, 19*8",
"mret",
rust_exceptions = sym exceptions,
options(noreturn)
)
}

Expand All @@ -245,7 +241,7 @@ unsafe extern "C" fn exceptions_trampoline() -> ! {
))]
#[naked]
unsafe extern "C" fn machine_external_trampoline() -> ! {
asm!(
naked_asm!(
"addi sp, sp, -19*8",
"sd ra, 0*8(sp)",
"sd t0, 1*8(sp)",
Expand Down Expand Up @@ -297,7 +293,6 @@ unsafe extern "C" fn machine_external_trampoline() -> ! {
"addi sp, sp, 19*8",
"mret",
rust_all_traps = sym rust_bl808_dsp_machine_external,
options(noreturn)
)
}

Expand Down

0 comments on commit bfda4cb

Please sign in to comment.