mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add virt_to_phys syscall
this will help speed up performance profiling as we can resolve the physical address of the performance buffer allocated in RAM and use a USB command to read it out, instead of streaming it over serial.
This commit is contained in:
parent
44afbd7697
commit
6d9848c239
2 changed files with 45 additions and 0 deletions
|
|
@ -936,6 +936,13 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
|
|||
}),
|
||||
_ => Err(xous_kernel::Error::InvalidLimit),
|
||||
},
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -457,6 +457,20 @@ 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
|
||||
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 +515,7 @@ pub enum SysCallNumber {
|
|||
JoinThread = 36,
|
||||
SetExceptionHandler = 37,
|
||||
AdjustProcessLimit = 38,
|
||||
VirtToPhys = 39,
|
||||
Invalid,
|
||||
}
|
||||
|
||||
|
|
@ -545,6 +560,7 @@ impl SysCallNumber {
|
|||
36 => JoinThread,
|
||||
37 => SetExceptionHandler,
|
||||
38 => AdjustProcessLimit,
|
||||
39 => VirtToPhys,
|
||||
_ => Invalid,
|
||||
}
|
||||
}
|
||||
|
|
@ -909,6 +925,16 @@ impl SysCall {
|
|||
0,
|
||||
0,
|
||||
],
|
||||
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 +1099,7 @@ impl SysCall {
|
|||
SysCallNumber::JoinThread => SysCall::JoinThread(a1 as _),
|
||||
SysCallNumber::SetExceptionHandler => SysCall::SetExceptionHandler(a1 as _, a2 as _),
|
||||
SysCallNumber::AdjustProcessLimit => SysCall::AdjustProcessLimit(a1, a2, a3),
|
||||
SysCallNumber::VirtToPhys => SysCall::VirtToPhys(a1 as _),
|
||||
SysCallNumber::Invalid => SysCall::Invalid(a1, a2, a3, a4, a5, a6, a7),
|
||||
})
|
||||
}
|
||||
|
|
@ -1839,6 +1866,17 @@ pub fn set_exception_handler(
|
|||
}
|
||||
*/
|
||||
|
||||
/// Translate a virtual address to a physical address
|
||||
pub fn virt_to_phys(va: usize) -> core::result::Result<usize, Error> {
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue