osiris_process/register/
state.rs

1//! Exposes some structs to help track state in a processor.
2
3use osiris_data::data::atomic::Word;
4use osiris_data::data::composite::WordStack;
5use osiris_data::data::identification::Address;
6
7use crate::register::floating_point::Vector;
8use crate::register::integral::Bank;
9
10/// The state of an operation.
11#[derive(Copy, Clone, Debug, Default)]
12pub struct OperationState {
13    /// Shall be used to store the result of an arithmetic operation.
14    pub result: Word,
15    /// Shall be used to implement a for-next logic.
16    pub counter: Word,
17    /// Shall be used to implement A <=> B comparison logic,
18    pub compare: i64,
19    /// Shall be used to signal an operation resulting with 0 or an empty set,
20    pub flag_zero: bool,
21    /// Shall be used to signal an operation resulting with a numeric overflow,
22    pub flag_overflow: bool,
23}
24
25impl OperationState {
26    /// Reset the whole operation state
27    pub fn reset(&mut self) {
28        self.reset_arithmetic();
29        self.counter = Word::default();
30        self.compare = 0;
31    }
32    /// Reset the arithmetic operation state.
33    /// 
34    /// Fields set :
35    /// * result
36    /// * flag_zero
37    /// * flag_overflow
38    pub fn reset_arithmetic(&mut self) {
39        self.result = Word::default();
40        self.flag_zero = false;
41        self.flag_overflow = false;
42    }
43}
44
45/// A proposed implementation of a processor state.
46#[derive(Clone, Debug, Default)]
47pub struct CpuState {
48    /// The current operation pointer,
49    pub current: Address,
50    /// Last operation result,
51    pub operation: OperationState,
52    /// The stack (for procedure-calling and operations),
53    pub stack: WordStack,
54    /// The integral register bank,
55    pub bank: Bank,
56    /// The floating-point register bank,
57    pub vector: Vector,
58    /// On if a trace shall be printed out,
59    pub flag_debug: bool,
60    /// On if the processor must skip the next instruction,
61    pub flag_skip: bool,
62    /// On if the processor must halt,
63    pub flag_halt: bool,
64}
65
66impl CpuState {
67    /// Creates a default state.
68    pub fn new() -> Self {
69        Self {
70            current: Address::default(),
71            operation: OperationState::default(),
72            stack: WordStack::default(),
73            bank: Bank::default(),
74            vector: Vector::default(),
75            flag_debug: false,
76            flag_skip: false,
77            flag_halt: false,
78        }
79    }
80}
81
82/// The result of a processor tick.
83#[derive(Copy, Clone, Eq, PartialEq)]
84pub enum TickState {
85    /// Operation normally executed,
86    Executed,
87    /// The last operation was a jump in memory,
88    Jumped,
89    /// The last operation was skip accordingly to the [CpuState],
90    Skipped,
91    /// The last operation resulted in an error.
92    Error,
93}