mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
remove engine-25519 as it is now deprecated
also remove "bencharks" as default set in shellchat
This commit is contained in:
parent
0106861eb4
commit
712fd4569b
7 changed files with 1 additions and 1376 deletions
|
|
@ -1,36 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "engine-25519"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
description = "Curve25519 Engine"
|
|
||||||
|
|
||||||
# Dependency versions enforced by Cargo.lock.
|
|
||||||
[dependencies]
|
|
||||||
xous = "0.9.58"
|
|
||||||
log-server = { package = "xous-api-log", version = "0.1.54" }
|
|
||||||
ticktimer-server = { package = "xous-api-ticktimer", version = "0.9.54" }
|
|
||||||
xous-names = { package = "xous-api-names", version = "0.9.56" }
|
|
||||||
log = "0.4.14"
|
|
||||||
susres = { package = "xous-api-susres", version = "0.9.54" }
|
|
||||||
llio = { path = "../llio" } # temporary for testing some power stuff
|
|
||||||
utralib = { version = "0.1.24", optional = true, default-features = false }
|
|
||||||
|
|
||||||
xous-ipc = "0.9.58"
|
|
||||||
num-derive = { version = "0.3.3", default-features = false }
|
|
||||||
num-traits = { version = "0.2.14", default-features = false }
|
|
||||||
rkyv = { version = "0.4.3", default-features = false, features = [
|
|
||||||
"const_generics",
|
|
||||||
] }
|
|
||||||
|
|
||||||
[dependencies.engine25519-as]
|
|
||||||
git = "https://github.com/betrusted-io/engine25519-as.git"
|
|
||||||
rev = "775e8406eb4aad08f05ae10619fcb4ca891ba0a6"
|
|
||||||
default-features = false
|
|
||||||
features = []
|
|
||||||
|
|
||||||
[features]
|
|
||||||
precursor = ["utralib/precursor"]
|
|
||||||
hosted = ["utralib/hosted"]
|
|
||||||
renode = ["utralib/renode"]
|
|
||||||
default = []
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
# Curve 25519 engine
|
|
||||||
|
|
||||||
Please refer to the [datasheet](https://ci.betrusted.io/betrusted-soc/doc/engine.html) for comprehensive documentation
|
|
||||||
on how the hardware engine itself works.
|
|
||||||
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
pub(crate) const SERVER_NAME_ENGINE25519: &str = "_Curve-25519 Accelerator Engine_";
|
|
||||||
|
|
||||||
// I don't understand why clippy says these are unused. But clippy is wrong. Shut up, clippy.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) const UCODE_U8_BASE: usize = 0x0;
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) const UCODE_U32_BASE: usize = 0x0;
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) const UCODE_U32_SIZE: usize = 0x1000 / 4;
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) const UCODE_U8_SIZE: usize = 0x1000;
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) const RF_U8_BASE: usize = 0x1_0000;
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) const RF_U32_BASE: usize = 0x1_0000 / 4;
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) const RF_TOTAL_U32_SIZE: usize = 0x4000 / 4;
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) const RF_TOTAL_U8_SIZE: usize = 0x4000;
|
|
||||||
|
|
||||||
pub(crate) const NUM_REGS: usize = 32;
|
|
||||||
pub(crate) const BITWIDTH: usize = 256;
|
|
||||||
#[allow(dead_code)] // not used in hosted
|
|
||||||
pub(crate) const NUM_WINDOWS: usize = 16;
|
|
||||||
pub const RF_SIZE_IN_U32: usize = NUM_REGS * (BITWIDTH / 32); // 32 registers, 256 bits/register/32 bits per u32
|
|
||||||
#[allow(dead_code)] // not used in hosted
|
|
||||||
pub const TOTAL_RF_SIZE_IN_U32: usize = NUM_REGS * (BITWIDTH / 32) * NUM_WINDOWS; // 32 registers, 256 bits/register/32 bits per u32, times 16 windows
|
|
||||||
|
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone, Copy)]
|
|
||||||
pub struct Job {
|
|
||||||
/// If present the SID of the server to which we should return results asynchronously.
|
|
||||||
/// If None, then the job will run synchronously.
|
|
||||||
pub id: Option<[u32; 4]>,
|
|
||||||
/// start location for microcode load
|
|
||||||
pub uc_start: u32,
|
|
||||||
/// length of the microcode to run
|
|
||||||
pub uc_len: u32,
|
|
||||||
/// microcode program
|
|
||||||
pub ucode: [u32; 1024],
|
|
||||||
/// initial register file contents (also contains any arguments to the program)
|
|
||||||
pub rf: [u32; RF_SIZE_IN_U32],
|
|
||||||
/// which register window, if any, to use for the job
|
|
||||||
pub window: Option<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone, Copy)]
|
|
||||||
pub struct MontgomeryJob {
|
|
||||||
pub x0_u: [u8; 32],
|
|
||||||
pub x0_w: [u8; 32],
|
|
||||||
pub x1_u: [u8; 32],
|
|
||||||
pub x1_w: [u8; 32],
|
|
||||||
pub affine_u: [u8; 32],
|
|
||||||
pub scalar: [u8; 32],
|
|
||||||
}
|
|
||||||
|
|
||||||
mod rkyv_enum;
|
|
||||||
pub use rkyv_enum::*;
|
|
||||||
|
|
||||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
|
||||||
pub(crate) enum Opcode {
|
|
||||||
/// Runs a job, if the server is not already occupied
|
|
||||||
RunJob,
|
|
||||||
|
|
||||||
/// MontgomeryJob
|
|
||||||
MontgomeryJob,
|
|
||||||
|
|
||||||
/// a function that can be polled to determine if the block has been currently acquired
|
|
||||||
IsFree,
|
|
||||||
|
|
||||||
/// IRQ handler feedback
|
|
||||||
EngineDone,
|
|
||||||
IllegalOpcode,
|
|
||||||
|
|
||||||
// note: suspend/resume handled by a separate thread and server
|
|
||||||
/// exit the server
|
|
||||||
Quit,
|
|
||||||
// note that suspend/resume is handled by a secondary thread that can concurrently
|
|
||||||
// interrupt the main thread and store the state
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
|
||||||
pub(crate) enum Return {
|
|
||||||
Result,
|
|
||||||
Quit,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
|
||||||
pub(crate) enum SusResOps {
|
|
||||||
/// Suspend/resume callback
|
|
||||||
SuspendResume,
|
|
||||||
/// exit the thread
|
|
||||||
Quit,
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// As of Rust 1.64.0:
|
|
||||||
//
|
|
||||||
// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used
|
|
||||||
// and I can't figure out how to make them go away. Since they spam the build log,
|
|
||||||
// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code`
|
|
||||||
// allow on top.
|
|
||||||
//
|
|
||||||
// This might be a temporary compiler regression, or it could just
|
|
||||||
// be yet another indicator that it's time to upgrade rkyv. However, we are waiting
|
|
||||||
// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough
|
|
||||||
// for 1.0") release until we rework the entire system to chase the latest rkyv.
|
|
||||||
// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8.
|
|
||||||
|
|
||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
|
||||||
pub enum JobResult {
|
|
||||||
/// returns a copy of the entire register file as a result
|
|
||||||
Result([u32; crate::RF_SIZE_IN_U32]),
|
|
||||||
SingleResult([u8; 32]),
|
|
||||||
Started,
|
|
||||||
EngineUnavailable,
|
|
||||||
NotAsyncObject, // attempt to run an async job on an object that was setup for sync jobs
|
|
||||||
IllegalOpcodeException,
|
|
||||||
SuspendError,
|
|
||||||
}
|
|
||||||
|
|
@ -1,202 +0,0 @@
|
||||||
#![cfg_attr(target_os = "none", no_std)]
|
|
||||||
|
|
||||||
//! Detailed docs are parked under Structs/Engine25519 down below
|
|
||||||
|
|
||||||
/*
|
|
||||||
#[cfg(any(feature="precursor", feature="renode"))]
|
|
||||||
pub use curve25519_dalek_hw::*;
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "xous"))]
|
|
||||||
pub use curve25519_dalek::*;
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub mod api;
|
|
||||||
pub use api::*;
|
|
||||||
use num_traits::*;
|
|
||||||
use xous::{Message, CID};
|
|
||||||
use xous_ipc::Buffer;
|
|
||||||
|
|
||||||
static mut ENGINE_CB: Option<fn(JobResult)> = None;
|
|
||||||
|
|
||||||
#[doc = include_str!("../README.md")]
|
|
||||||
pub struct Engine25519 {
|
|
||||||
conn: CID,
|
|
||||||
cb_sid: Option<[u32; 4]>,
|
|
||||||
}
|
|
||||||
impl Engine25519 {
|
|
||||||
// this is used to set up a system with async callbacks
|
|
||||||
pub fn new_async(xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
|
|
||||||
REFCOUNT.fetch_add(1, Ordering::Relaxed);
|
|
||||||
let conn = xns
|
|
||||||
.request_connection_blocking(api::SERVER_NAME_ENGINE25519)
|
|
||||||
.expect("Can't connect to Engine25519 server");
|
|
||||||
|
|
||||||
let sid = xous::create_server().unwrap();
|
|
||||||
let sid_tuple = sid.to_u32();
|
|
||||||
xous::create_thread_4(
|
|
||||||
engine_cb_server,
|
|
||||||
sid_tuple.0 as usize,
|
|
||||||
sid_tuple.1 as usize,
|
|
||||||
sid_tuple.2 as usize,
|
|
||||||
sid_tuple.3 as usize,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Ok(Engine25519 { conn, cb_sid: Some(sid.to_array()) })
|
|
||||||
}
|
|
||||||
|
|
||||||
// typically, we just want synchronous callbacks. This integrates more nicely into single-threaded code.
|
|
||||||
pub fn new() -> Self {
|
|
||||||
REFCOUNT.fetch_add(1, Ordering::Relaxed);
|
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
|
||||||
let conn = xns
|
|
||||||
.request_connection_blocking(api::SERVER_NAME_ENGINE25519)
|
|
||||||
.expect("Can't connect to Engine25519 server");
|
|
||||||
|
|
||||||
Engine25519 { conn, cb_sid: None }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// this is unsafe because the caller must make sure that within their process space, multiple threads
|
|
||||||
/// are not spawing concurrent jobs; or, if they do, they all share a common result_callback method:
|
|
||||||
/// we always blindly replace result_callback!
|
|
||||||
pub unsafe fn spawn_async_job(
|
|
||||||
&mut self,
|
|
||||||
job: &mut Job,
|
|
||||||
result_callback: fn(JobResult),
|
|
||||||
) -> Result<bool, xous::Error> {
|
|
||||||
if let Some(cb_sid) = self.cb_sid {
|
|
||||||
ENGINE_CB = Some(result_callback); // this is the unsafe bit!
|
|
||||||
job.id = Some(cb_sid);
|
|
||||||
let mut buf = Buffer::into_buf(*job).or(Err(xous::Error::InternalError))?;
|
|
||||||
buf.lend_mut(self.conn, Opcode::RunJob.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
|
||||||
|
|
||||||
match buf.to_original().unwrap() {
|
|
||||||
JobResult::Started => Ok(true),
|
|
||||||
_ => Ok(false),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Err(xous::Error::InvalidSyscall)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn montgomery_job(&mut self, job: MontgomeryJob) -> Result<[u8; 32], xous::Error> {
|
|
||||||
let mut buf = Buffer::into_buf(job).or(Err(xous::Error::OutOfMemory))?;
|
|
||||||
match buf.lend_mut(self.conn, Opcode::MontgomeryJob.to_u32().unwrap()) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(e) => {
|
|
||||||
if e == xous::Error::ServerNotFound {
|
|
||||||
log::error!(
|
|
||||||
"Looks like another thread called disconnect() on us while we weren't looking: {:?}",
|
|
||||||
e
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
log::error!("couldn't lend buffer: {:?}", e);
|
|
||||||
}
|
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match buf.to_original().unwrap() {
|
|
||||||
JobResult::SingleResult(r) => Ok(r),
|
|
||||||
JobResult::EngineUnavailable => {
|
|
||||||
log::debug!("spawn job: engine unavailable");
|
|
||||||
Err(xous::Error::ServerQueueFull)
|
|
||||||
}
|
|
||||||
JobResult::IllegalOpcodeException => {
|
|
||||||
log::error!("spawn job: illegal opcode");
|
|
||||||
Err(xous::Error::InvalidString)
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
log::error!("spawn job: other error");
|
|
||||||
Err(xous::Error::UnknownError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// this is a blocking version of spawn_async_job.
|
|
||||||
/// if the engine is free, it will block until a result is returned
|
|
||||||
/// if the engine is busy, it will return an EngineUnavailable result.
|
|
||||||
pub fn spawn_job(&mut self, job: Job) -> Result<[u32; RF_SIZE_IN_U32], xous::Error> {
|
|
||||||
if job.id.is_some() {
|
|
||||||
log::error!("spawn sync job: don't set a job id if you want a synchronous job!");
|
|
||||||
return Err(xous::Error::InvalidSyscall); // the job.id should be None for a sync job. Do not set it to Some, even as a joke.
|
|
||||||
}
|
|
||||||
let mut buf = Buffer::into_buf(job).or(Err(xous::Error::OutOfMemory))?;
|
|
||||||
match buf.lend_mut(self.conn, Opcode::RunJob.to_u32().unwrap()) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(e) => {
|
|
||||||
if e == xous::Error::ServerNotFound {
|
|
||||||
log::error!(
|
|
||||||
"Looks like another thread called disconnect() on us while we weren't looking: {:?}",
|
|
||||||
e
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
log::error!("couldn't lend buffer: {:?}", e);
|
|
||||||
}
|
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match buf.to_original().unwrap() {
|
|
||||||
JobResult::Result(rf) => Ok(rf),
|
|
||||||
JobResult::EngineUnavailable => {
|
|
||||||
log::debug!("spawn job: engine unavailable");
|
|
||||||
Err(xous::Error::ServerQueueFull)
|
|
||||||
}
|
|
||||||
JobResult::IllegalOpcodeException => {
|
|
||||||
log::error!("spawn job: illegal opcode");
|
|
||||||
Err(xous::Error::InvalidString)
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
log::error!("spawn job: other error");
|
|
||||||
Err(xous::Error::UnknownError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
|
||||||
static REFCOUNT: AtomicU32 = AtomicU32::new(0);
|
|
||||||
impl Drop for Engine25519 {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
// disconnect from the main server, only if there are no more instances active
|
|
||||||
if REFCOUNT.fetch_sub(1, Ordering::Relaxed) == 1 {
|
|
||||||
unsafe {
|
|
||||||
xous::disconnect(self.conn).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// disconnect and destroy the callback server that is specific to this instance
|
|
||||||
if let Some(cb_sid) = self.cb_sid {
|
|
||||||
let cid = xous::connect(xous::SID::from_array(cb_sid)).unwrap();
|
|
||||||
xous::send_message(cid, Message::new_scalar(Return::Quit.to_usize().unwrap(), 0, 0, 0, 0))
|
|
||||||
.unwrap();
|
|
||||||
unsafe {
|
|
||||||
xous::disconnect(cid).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// handles callback messages from the engine server, in the library user's process space.
|
|
||||||
fn engine_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
|
||||||
let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32);
|
|
||||||
loop {
|
|
||||||
let msg = xous::receive_message(sid).unwrap();
|
|
||||||
match FromPrimitive::from_usize(msg.body.id()) {
|
|
||||||
Some(Return::Result) => {
|
|
||||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
|
||||||
let job_result = buffer.to_original::<JobResult, _>().unwrap();
|
|
||||||
unsafe {
|
|
||||||
if let Some(cb) = ENGINE_CB {
|
|
||||||
cb(job_result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(Return::Quit) => {
|
|
||||||
break; // this exits the loop and kills the thread
|
|
||||||
}
|
|
||||||
None => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xous::destroy_server(sid).unwrap();
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -153,4 +153,4 @@ rand-api = []
|
||||||
locktests = [
|
locktests = [
|
||||||
] # for debugging some specific `std` tests cherry-picked out of the test suite
|
] # for debugging some specific `std` tests cherry-picked out of the test suite
|
||||||
simple-tls = ["rustls", "webpki-roots"]
|
simple-tls = ["rustls", "webpki-roots"]
|
||||||
default = ["benchmarks"] # "debugprint"
|
default = [] # "debugprint"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue