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