kernel/environment/riscv64.rs
1// RISC-V environment constants
2
3use super::common::PAGE_SIZE;
4
5pub const RISCV_STIMER_FREQ: u64 = 10000000; // 10MHz
6
7// Virtual memory maximum address (inclusive)
8// RISC-V SV48: upper canonical end.
9pub const VMMAX: usize = 0xffff_ffff_ffff_ffff;
10
11// Trampoline-managed high-VA infrastructure anchor.
12//
13// We treat the upper-most high-VA region as "trampoline-managed" infrastructure space:
14// - the trampoline mapping itself
15// - the kernel VM stack
16// - per-task kernel stack windows (kstack slots) mapped into the shared kernel PT
17pub const TRAMPOLINE_VA_END: usize = VMMAX;
18
19// Keep the existing RISC-V layout: user stack ends at the page right before the
20// last (top-most) page used by the trampoline.
21pub const TRAMPOLINE_VA_RESERVE: usize = PAGE_SIZE;
22
23// User stack end address (exclusive)
24// NOTE: avoid `TRAMPOLINE_VA_END + 1` because TRAMPOLINE_VA_END may be `usize::MAX`.
25pub const USER_STACK_END: usize =
26 (TRAMPOLINE_VA_END - TRAMPOLINE_VA_RESERVE + 1) & !(PAGE_SIZE - 1);
27
28// Kernel VM stack end address (inclusive)
29pub const KERNEL_VM_STACK_END: usize = USER_STACK_END - 1;