Skip to content

Commit 1b9bd3c

Browse files
committed
fix: hal 内部不再输出文档
Signed-off-by: YdrMaster <ydrml@hotmail.com>
1 parent 4557d68 commit 1b9bd3c

File tree

6 files changed

+70
-36
lines changed

6 files changed

+70
-36
lines changed

fast-trap/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,3 @@ categories = ["embedded", "hardware-support", "no-std"]
1616
[features]
1717
riscv-s = []
1818
riscv-m = []
19-
20-
[package.metadata.docs.rs]
21-
targets = ["riscv32imac-unknown-none-elf", "riscv64imac-unknown-none-elf"]
22-
features = ["riscv-s", "riscv-m"]

fast-trap/src/hal/mod.rs

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
1-
mod riscv;
2-
#[cfg(feature = "riscv-m")]
3-
#[macro_use]
4-
mod riscv_m;
5-
#[cfg(feature = "riscv-s")]
6-
#[macro_use]
7-
mod riscv_s;
1+
#[cfg(not(doc))]
2+
mod riscv;
83

4+
#[cfg(not(doc))]
95
pub use riscv::*;
10-
#[cfg(feature = "riscv-m")]
11-
pub use riscv_m::*;
12-
#[cfg(feature = "riscv-s")]
13-
pub use riscv_s::*;
6+
7+
mod doc {
8+
#![allow(unused)]
9+
10+
/// 设置全局陷入入口。
11+
///
12+
/// # Safety
13+
///
14+
/// 这个函数操作硬件寄存器,寄存器里原本的值将丢弃。
15+
pub unsafe fn load_direct_trap_entry() {}
16+
17+
/// 把当前栈复用为陷入栈,预留 Handler 空间。
18+
///
19+
/// # Safety
20+
///
21+
/// 裸指针,直接移动 sp,只能在纯汇编环境调用。
22+
pub unsafe extern "C" fn reuse_stack_for_trap() {}
23+
24+
/// 模拟一个 `cause` 类的陷入。
25+
///
26+
/// # Safety
27+
///
28+
/// 如同发生一个陷入。
29+
pub fn soft_trap(cause: usize) {}
30+
31+
/// 陷入处理例程。
32+
///
33+
/// # Safety
34+
///
35+
/// 不要直接调用这个函数。暴露它仅仅是为了提供其入口的符号链接。
36+
pub unsafe extern "C" fn trap_entry() {}
37+
38+
/// 陷入上下文。
39+
///
40+
/// 保存了陷入时的寄存器状态。包括所有通用寄存器和 `pc`。
41+
pub struct FlowContext {}
42+
43+
impl FlowContext {
44+
/// 零初始化。
45+
pub const ZERO: Self = Self {};
46+
}
47+
}
48+
49+
#[cfg(doc)]
50+
pub use doc::*;

fast-trap/src/hal/riscv.rs renamed to fast-trap/src/hal/riscv/mod.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
use crate::TrapHandler;
2-
use core::alloc::Layout;
1+
#![allow(missing_docs)]
2+
3+
#[cfg(feature = "riscv-m")]
4+
#[macro_use]
5+
mod riscv_m;
6+
#[cfg(feature = "riscv-s")]
7+
#[macro_use]
8+
mod riscv_s;
39

410
#[cfg(target_pointer_width = "32")]
511
#[macro_use]
@@ -64,11 +70,14 @@ mod arch {
6470
}
6571
}
6672

67-
use super::{exchange, r#return};
73+
use crate::TrapHandler;
74+
use core::alloc::Layout;
75+
76+
#[cfg(feature = "riscv-m")]
77+
pub use riscv_m::*;
78+
#[cfg(feature = "riscv-s")]
79+
pub use riscv_s::*;
6880

69-
/// 陷入上下文。
70-
///
71-
/// 保存了陷入时的寄存器状态。包括所有通用寄存器和 `pc`。
7281
#[repr(C)]
7382
#[allow(missing_docs)]
7483
pub struct FlowContext {
@@ -96,11 +105,9 @@ impl FlowContext {
96105
};
97106
}
98107

99-
/// 把当前栈复用为陷入栈,预留 Handler 空间。
100-
///
101108
/// # Safety
102109
///
103-
/// 裸指针,直接移动 sp,只能在纯汇编环境调用。
110+
/// See [proto](crate::hal::doc::reuse_stack_for_trap).
104111
#[naked]
105112
pub unsafe extern "C" fn reuse_stack_for_trap() {
106113
const LAYOUT: Layout = Layout::new::<TrapHandler>();
@@ -115,11 +122,9 @@ pub unsafe extern "C" fn reuse_stack_for_trap() {
115122
)
116123
}
117124

118-
/// 陷入处理例程。
119-
///
120125
/// # Safety
121126
///
122-
/// 不要直接调用这个函数。暴露它仅仅是为了提供其入口的符号链接。
127+
/// See [proto](crate::hal::doc::trap_entry).
123128
#[naked]
124129
pub unsafe extern "C" fn trap_entry() {
125130
core::arch::asm!(

fast-trap/src/hal/riscv_m.rs renamed to fast-trap/src/hal/riscv/riscv_m.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ pub(crate) fn exchange_scratch(mut val: usize) -> usize {
4444
val
4545
}
4646

47-
/// 模拟一个 `cause` 类的陷入。
48-
///
4947
/// # Safety
5048
///
51-
/// 如同发生一个陷入。
49+
/// See [proto](crate::hal::doc::soft_trap).
5250
#[inline]
5351
pub unsafe fn soft_trap(cause: usize) {
5452
asm!(
@@ -64,11 +62,9 @@ pub unsafe fn soft_trap(cause: usize) {
6462
);
6563
}
6664

67-
/// 设置全局陷入入口。
68-
///
6965
/// # Safety
7066
///
71-
/// 这个函数操作硬件寄存器,寄存器里原本的值将丢弃。
67+
/// See [proto](crate::hal::doc::load_direct_trap_entry).
7268
#[inline]
7369
pub unsafe fn load_direct_trap_entry() {
7470
asm!("csrw mtvec, {0}", in(reg) trap_entry, options(nomem))
File renamed without changes.

fast-trap/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod hal;
1010

1111
pub use entire::*;
1212
pub use fast::*;
13-
pub use hal::*;
13+
pub use hal::{load_direct_trap_entry, reuse_stack_for_trap, soft_trap, trap_entry, FlowContext};
1414

1515
use core::{
1616
alloc::Layout,
@@ -58,7 +58,7 @@ impl FreeTrapStack {
5858
/// 将这个陷入栈加载为预备陷入栈。
5959
#[inline]
6060
pub fn load(self) -> LoadedTrapStack {
61-
let scratch = exchange_scratch(self.0.as_ptr() as _);
61+
let scratch = hal::exchange_scratch(self.0.as_ptr() as _);
6262
forget(self);
6363
LoadedTrapStack(scratch)
6464
}
@@ -96,7 +96,7 @@ impl LoadedTrapStack {
9696
/// 间接复制了所有权。用于 `Drop`。
9797
#[inline]
9898
unsafe fn unload_unchecked(&self) -> FreeTrapStack {
99-
let ptr = exchange_scratch(self.0) as *mut TrapHandler;
99+
let ptr = hal::exchange_scratch(self.0) as *mut TrapHandler;
100100
let handler = unsafe { NonNull::new_unchecked(ptr) };
101101
FreeTrapStack(handler)
102102
}

0 commit comments

Comments
 (0)