Skip to content

feat: update rust edition to 2024 and change asm! to naked_asm! #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 136 additions & 76 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bench-kernel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bench-kernel"
version = "0.0.1"
edition = "2021"
edition = "2024"
authors = ["YdrMaster <ydrml@hotmail.com>"]
publish = false

Expand Down
29 changes: 15 additions & 14 deletions bench-kernel/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
#![no_std]
#![no_main]
#![feature(naked_functions, asm_const)]
#![feature(naked_functions)]
#![deny(warnings)]
#![allow(static_mut_refs)]

use rcore_console::log;
use riscv::register::*;
use sbi_rt::*;
use uart16550::Uart16550;

#[naked]
#[no_mangle]
#[link_section = ".text.entry"]
#[unsafe(no_mangle)]
#[unsafe(link_section = ".text.entry")]
unsafe extern "C" fn _start(hartid: usize, device_tree_paddr: usize) -> ! {
const STACK_SIZE: usize = 16384; // 16 KiB

#[link_section = ".bss.uninit"]
#[unsafe(link_section = ".bss.uninit")]
static mut STACK: [u8; STACK_SIZE] = [0u8; STACK_SIZE];

core::arch::asm!(
"la sp, {stack} + {stack_size}",
"j {main}",
stack_size = const STACK_SIZE,
stack = sym STACK,
main = sym rust_main,
options(noreturn),
)
unsafe{
core::arch::naked_asm!(
"la sp, {stack} + {stack_size}",
"j {main}",
stack_size = const STACK_SIZE,
stack = sym STACK,
main = sym rust_main,
)
}
}

extern "C" fn rust_main(hartid: usize, _dtb_pa: usize) -> ! {
extern "C" {
unsafe extern "C" {
static mut sbss: u64;
static mut ebss: u64;
}
Expand Down
2 changes: 1 addition & 1 deletion hsm-cell/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hsm-cell"
version = "0.1.0"
edition = "2021"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
6 changes: 3 additions & 3 deletions rustsbi-qemu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MulanPSL-2.0 OR MIT"
readme = "README.md"
keywords = ["riscv", "sbi", "rustsbi"]
categories = ["os", "embedded", "hardware-support", "no-std"]
edition = "2021"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -22,10 +22,10 @@ sbi-spec = { version = "0.0.7", features = ["legacy"] }
riscv = "0.10.1"
spin = "0.9"
rcore-console = "0.0.0"
aclint = "0.0.0"
aclint = "0.1.0"
sifive-test-device = "0.0.0"
dtb-walker = "=0.2.0-alpha.3"
uart16550 = "0.0.1"

hsm-cell = { path = "../hsm-cell" }
fast-trap = { version = "=0.0.1", features = ["riscv-m"] }
fast-trap = { version = "=0.1.0", features = ["riscv-m"] }
31 changes: 17 additions & 14 deletions rustsbi-qemu/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![no_std]
#![no_main]
#![feature(naked_functions, asm_const)]
#![feature(naked_functions)]
#![deny(warnings)]
#![allow(static_mut_refs)]

mod clint;
mod dbcn;
Expand Down Expand Up @@ -38,26 +39,28 @@ use rustsbi::{RustSBI, SbiRet};
use spin::Once;
use trap_stack::{local_hsm, local_remote_hsm, remote_hsm};
use trap_vec::trap_vec;
use core::arch::naked_asm;

/// 入口。
///
/// # Safety
///
/// 裸函数。
#[naked]
#[no_mangle]
#[link_section = ".text.entry"]
#[unsafe(no_mangle)]
#[unsafe(link_section = ".text.entry")]
unsafe extern "C" fn _start() -> ! {
asm!(
" call {locate_stack}
call {rust_main}
j {trap}
",
locate_stack = sym trap_stack::locate,
rust_main = sym rust_main,
trap = sym trap_vec,
options(noreturn),
)
unsafe{
naked_asm!(
" call {locate_stack}
call {rust_main}
j {trap}
",
locate_stack = sym trap_stack::locate,
rust_main = sym rust_main,
trap = sym trap_vec,
)
}
}

/// rust 入口。
Expand All @@ -67,7 +70,7 @@ extern "C" fn rust_main(hartid: usize, opaque: usize) {

// 全局初始化过程
if GENESIS.swap(false, Ordering::AcqRel) {
extern "C" {
unsafe extern "C" {
static mut sbss: u64;
static mut ebss: u64;
}
Expand Down
35 changes: 18 additions & 17 deletions rustsbi-qemu/src/trap_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ use fast_trap::{FlowContext, FreeTrapStack};
use hsm_cell::{HsmCell, LocalHsmCell, RemoteHsmCell};

/// 栈空间。
#[link_section = ".bss.uninit"]
#[unsafe(link_section = ".bss.uninit")]
static mut ROOT_STACK: [Stack; NUM_HART_MAX] = [Stack::ZERO; NUM_HART_MAX];

/// 定位每个 hart 的栈。
#[naked]
pub(crate) unsafe extern "C" fn locate() {
core::arch::asm!(
" la sp, {stack}
li t0, {per_hart_stack_size}
csrr t1, mhartid
addi t1, t1, 1
1: add sp, sp, t0
addi t1, t1, -1
bnez t1, 1b
call t1, {move_stack}
ret
",
per_hart_stack_size = const LEN_STACK_PER_HART,
stack = sym ROOT_STACK,
move_stack = sym fast_trap::reuse_stack_for_trap,
options(noreturn),
)
unsafe{
core::arch::naked_asm!(
" la sp, {stack}
li t0, {per_hart_stack_size}
csrr t1, mhartid
addi t1, t1, 1
1: add sp, sp, t0
addi t1, t1, -1
bnez t1, 1b
call t1, {move_stack}
ret
",
per_hart_stack_size = const LEN_STACK_PER_HART,
stack = sym ROOT_STACK,
move_stack = sym fast_trap::reuse_stack_for_trap,
)
}
}

/// 预备陷入栈。
Expand Down
Loading