diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 564b4b2b3..b7d99def1 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -35,6 +35,7 @@ gdbserver = ["gdbstub", "gdbstub_arch"] print-panics = [] report-memory = ["stats_alloc"] wrap-print = [] +v2p = ["xous-kernel/v2p"] # default = ["print-panics", "debug-print", "wrap-print"] default = ["print-panics", "gdbserver"] diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 675001e2d..2288da465 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -936,6 +936,14 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR }), _ => Err(xous_kernel::Error::InvalidLimit), }, + #[cfg(feature="v2p")] + SysCall::VirtToPhys(vaddr) => { + let phys_addr = crate::arch::mem::virt_to_phys(vaddr as usize); + match phys_addr { + Ok(pa) => Ok(xous_kernel::Result::Scalar1(pa)), + Err(_) => Err(xous_kernel::Error::BadAddress), + } + } /* https://github.com/betrusted-io/xous-core/issues/90 SysCall::SetExceptionHandler(pc, sp) => SystemServices::with_mut(|ss| { ss.set_exception_handler(pid, pc, sp) diff --git a/xous-rs/Cargo.toml b/xous-rs/Cargo.toml index 679cfe0e7..856b513f8 100644 --- a/xous-rs/Cargo.toml +++ b/xous-rs/Cargo.toml @@ -13,6 +13,8 @@ core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core compiler_builtins = { version = '0.1.0', optional = true } [features] +v2p = [] +default = [] # If this is set, then the "Drop" feature of MemoryMessage structs # will not be implemented. This should only be set by the kernel. diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index 364d3ce00..492211913 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -457,6 +457,21 @@ pub enum SysCall { usize, /* proposed new limit */ ), + /// Returns the physical address corresponding to a virtual address, if such a mapping exists. + /// + /// ## Arguments + /// * **vaddr**: The virtual address to inspect + /// + /// ## Returns + /// Returns a Scalar1 containing the physical address + /// + /// ## Errors + /// * **BadAddress**: The mapping does not exist + #[cfg(feature="v2p")] + VirtToPhys( + usize, /* virtual address */ + ), + /// This syscall does not exist. It captures all possible /// arguments so detailed analysis can be performed. Invalid(usize, usize, usize, usize, usize, usize, usize), @@ -501,6 +516,8 @@ pub enum SysCallNumber { JoinThread = 36, SetExceptionHandler = 37, AdjustProcessLimit = 38, + #[cfg(feature="v2p")] + VirtToPhys = 39, Invalid, } @@ -545,6 +562,8 @@ impl SysCallNumber { 36 => JoinThread, 37 => SetExceptionHandler, 38 => AdjustProcessLimit, + #[cfg(feature="v2p")] + 39 => VirtToPhys, _ => Invalid, } } @@ -909,6 +928,17 @@ impl SysCall { 0, 0, ], + #[cfg(feature="v2p")] + SysCall::VirtToPhys(vaddr) => [ + SysCallNumber::VirtToPhys as usize, + *vaddr, + 0, + 0, + 0, + 0, + 0, + 0, + ], SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7) => [ SysCallNumber::Invalid as usize, *a1, @@ -1073,6 +1103,8 @@ impl SysCall { SysCallNumber::JoinThread => SysCall::JoinThread(a1 as _), SysCallNumber::SetExceptionHandler => SysCall::SetExceptionHandler(a1 as _, a2 as _), SysCallNumber::AdjustProcessLimit => SysCall::AdjustProcessLimit(a1, a2, a3), + #[cfg(feature="v2p")] + SysCallNumber::VirtToPhys => SysCall::VirtToPhys(a1 as _), SysCallNumber::Invalid => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7), }) } @@ -1839,6 +1871,18 @@ pub fn set_exception_handler( } */ +/// Translate a virtual address to a physical address +#[cfg(feature="v2p")] +pub fn virt_to_phys(va: usize) -> core::result::Result { + rsyscall(SysCall::VirtToPhys(va)).and_then(|result| { + if let Result::Scalar1(pa) = result { + Ok(pa) + } else { + Err(Error::BadAddress) + } + }) +} + /// Perform a raw syscall and return the result. This will transform /// `xous::Result::Error(e)` into an `Err(e)`. pub fn rsyscall(call: SysCall) -> SysCallResult { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 1af13c329..20b6cd5f5 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -311,7 +311,7 @@ fn main() -> Result<(), Box> { None, Some(&["--features", "tts", "--features", "braille"]), &[&tts_exec_string], - None, + None, None, )?; let mut locale_revert = OpenOptions::new() .read(true) @@ -345,7 +345,7 @@ fn main() -> Result<(), Box> { None, None, None, - extra_packages.as_slice(), None)?; + extra_packages.as_slice(), None, None)?; } } Some("libstd-test") => { @@ -385,6 +385,7 @@ fn main() -> Result<(), Box> { None, &[], Some(&["--features", "renode-bypass"]), + None, )? //renode_image(false, &pkgs, extra_packages.as_slice(), //None, Some(&["--features", "renode-bypass"]))?; @@ -535,7 +536,7 @@ fn main() -> Result<(), Box> { kkey, None, &[], - None, + None, None, )? } Some("perf-image") => { @@ -554,10 +555,10 @@ fn main() -> Result<(), Box> { lkey, kkey, Some(&[ - "--features", "perfcounter" + "--features", "perfcounter", ]), &[], - None, + None, None, )? } Some("utra") => { @@ -584,6 +585,9 @@ fn main() -> Result<(), Box> { std::env::set_var("XOUS_SVD_FILE", path.canonicalize().unwrap()); println!("XOUS_SVD_FILE: {}", path.canonicalize().unwrap().display()); } + let generated_path = std::path::Path::new("utralib/src/generated.rs"); + // blank the contents so that the build command runs + std::fs::write(generated_path, "")?; let status = Command::new(cargo()) .current_dir(project_root()) .args(&[ @@ -615,7 +619,7 @@ fn main() -> Result<(), Box> { "--features", "ditherpunk", ]), &[], - None, + None, None, )? } Some("hw-image") => { @@ -639,7 +643,7 @@ fn main() -> Result<(), Box> { kkey, None, &[], - None, + None, None, )? } Some("gfx-dev") => run( @@ -656,7 +660,7 @@ fn main() -> Result<(), Box> { kkey, None, &[], - None, + None, None, )?, Some("pddb-hosted") => run(false, &pddb_dev_pkgs, None, false)?, Some("benchmark") => build_hw_image( @@ -667,7 +671,7 @@ fn main() -> Result<(), Box> { kkey, None, &[], - None, + None, None, )?, Some("minimal") => build_hw_image( false, @@ -677,7 +681,7 @@ fn main() -> Result<(), Box> { kkey, None, &[], - None, + None, None, )?, Some("cbtest") => build_hw_image( false, @@ -687,7 +691,7 @@ fn main() -> Result<(), Box> { kkey, None, &[], - None, + None, None, )?, Some("trng-test") => { generate_app_menus(&Vec::::new()); @@ -699,7 +703,7 @@ fn main() -> Result<(), Box> { kkey, Some(&["--features", "urandomtest"]), &[], - None, + None, None, )? } Some("ro-test") => { @@ -712,7 +716,7 @@ fn main() -> Result<(), Box> { kkey, Some(&["--features", "ringosctest"]), &[], - None, + None, None, )? } Some("av-test") => { @@ -725,7 +729,7 @@ fn main() -> Result<(), Box> { kkey, Some(&["--features", "avalanchetest"]), &[], - None, + None, None, )? } Some("sr-test") => build_hw_image( @@ -736,7 +740,7 @@ fn main() -> Result<(), Box> { kkey, None, &[], - None, + None, None, )?, Some("burn-kernel") => update_usb(true, false, false, false)?, Some("burn-loader") => update_usb(false, true, false, false)?, @@ -952,6 +956,7 @@ fn build_hw_image( extra_args: Option<&[&str]>, extra_packages: &[&str], loader_features: Option<&[&str]>, + kernel_features: Option<&[&str]>, ) -> Result<(), DynError> { let svd_file = match svd { Some(s) => s, @@ -972,7 +977,7 @@ fn build_hw_image( let loaderkey_file = lkey.unwrap_or_else(|| "devkey/dev.key".into()); let kernelkey_file = kkey.unwrap_or_else(|| "devkey/dev.key".into()); - let kernel = build_kernel(debug)?; + let kernel = build_kernel(debug, kernel_features)?; let mut init = vec![]; let base_path = build( packages, @@ -1170,6 +1175,7 @@ fn renode_image( xous_features, extra_packages, loader_features, + None, ) } @@ -1234,8 +1240,8 @@ fn run( Ok(()) } -fn build_kernel(debug: bool) -> Result { - let mut path = build(&["kernel"], debug, Some(KERNEL_TARGET), None, None, None)?; +fn build_kernel(debug: bool, features: Option<&[&str]>) -> Result { + let mut path = build(&["kernel"], debug, Some(KERNEL_TARGET), None, None, features)?; path.push("kernel"); Ok(path) }