Skip to content

Commit

Permalink
Rollup merge of #92574 - luojia65:riscv-kernel-dev-rust, r=Amanieu
Browse files Browse the repository at this point in the history
Add RISC-V detection macro and more architecture instructions

This pull request includes:

- Update `stdarch` dependency to include ratified RISC-V supervisor and hypervisor instruction intrinsics which is useful in Rust kernel development
- Add macro `is_riscv_feature_detected!`
- Modify impl of `core::hint::spin_loop` to comply with latest version of `core::arch`

After this update, users may now develop RISC-V kernels and user applications more freely.

r? `@Amanieu`
  • Loading branch information
matthiaskrgr authored Jan 5, 2022
2 parents 051d591 + 06f4453 commit c570fcb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
20 changes: 15 additions & 5 deletions library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ pub fn spin_loop() {
}
}

// RISC-V platform spin loop hint implementation
{
// RISC-V RV32 and RV64 share the same PAUSE instruction, but they are located in different
// modules in `core::arch`.
// In this case, here we call `pause` function in each core arch module.
#[cfg(target_arch = "riscv32")]
{
crate::arch::riscv32::pause();
}
#[cfg(target_arch = "riscv64")]
{
crate::arch::riscv64::pause();
}
}

#[cfg(any(target_arch = "aarch64", all(target_arch = "arm", target_feature = "v6")))]
{
#[cfg(target_arch = "aarch64")]
Expand All @@ -137,11 +152,6 @@ pub fn spin_loop() {
unsafe { crate::arch::arm::__yield() };
}
}

#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
{
crate::arch::riscv::pause();
}
}

/// An identity function that *__hints__* to the compiler to be maximally pessimistic about what
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ pub use std_detect::*;
pub use std_detect::{
is_aarch64_feature_detected, is_arm_feature_detected, is_mips64_feature_detected,
is_mips_feature_detected, is_powerpc64_feature_detected, is_powerpc_feature_detected,
is_riscv_feature_detected,
};

// Re-export macros defined in libcore.
Expand Down

0 comments on commit c570fcb

Please sign in to comment.