osiris_process/
lib.rs

1//! This crate provides structs and implementation to help create virtual machines :
2//! * addressed on 64-bits,
3//! * with 64-bits length operations,
4//! * operating on 64-bits words.
5//!
6//! **It is not ready for production, it may evolve a lot !**
7//!
8//! An example (WIP) [implementation](https://asgard.trehinos.eu/osiris/virtual-process).
9//!
10//! It makes some opinionated choices like :
11//! * Having 65536 general-registers ([register::integral::Bank]) per [processor::Cpu],
12//! * Having 65536 floating-point registers ([register::floating_point::Vector]),
13//! * [operation::Operation]s are meant to operate on a range of registers,
14//! * Neither the ordering or the invocation of processors nor the operation sets are implemented in this crate.
15//!
16
17pub mod register;
18
19pub mod compare;
20
21#[cfg(feature = "processor")]
22pub mod operation;
23
24#[cfg(feature = "communication")]
25pub mod communication;
26
27#[cfg(feature = "processor")]
28pub mod processor;
29
30#[cfg(test)]
31#[cfg(feature = "processor")]
32mod tests {
33    use std::cell::RefCell;
34    use std::rc::Rc;
35    use osiris_data::data::atomic::Word;
36    use osiris_data::memory::Memory;
37    
38    use crate::operation::{Instruction, Operation, OperationSet};
39    use crate::operation::scheme::{ArgumentType, OperationId};
40    
41    use crate::processor::Cpu;
42
43    #[test]
44    fn test_creation() {
45        let instr = Instruction::new(0);
46        assert_eq!(instr.to_u64(), 0);
47    }
48
49    #[test]
50    fn test_operation() {
51        const OPID: OperationId = OperationId::new(0x7357);
52
53        let operation = Operation::new(
54            OPID, "SET R:$1 = 1".to_string(),
55            true, ArgumentType::NoArgument,
56            |cpu, scheme| {
57                cpu.bank_set(scheme.target, Word::new(1));
58                Ok(())
59            },
60        );
61
62        let mut cpu = Cpu::new(RefCell::new(Memory::new()), Rc::new(OperationSet::new()));
63
64        let instr = Instruction::new(0x7357_0000_0000_0000);
65        let scheme = instr.scheme(ArgumentType::NoArgument);
66        operation.call(&mut cpu, scheme).unwrap();
67        assert_eq!(cpu.bank_get(scheme.target), Word::new(1));
68    }
69}