mod functions;
mod jumps;
mod multi_format;
mod single_word;
mod three_words;
mod two_words;
use crate::emulator::core::{DecodedComplexInstruction, DecodedInstruction, Operand, OperandType};
use crate::emulator::{EmulatorInstruction, ForwardComEmulator, RegisterFile};
use gpcas_base::instruction_type;
use gpcas_isa::instruction_flags;
use std::collections::VecDeque;
pub use jumps::*;
pub use multi_format::*;
pub use single_word::*;
pub use three_words::*;
pub use two_words::*;
#[derive(Clone, Copy)]
pub enum VectorMode {
Element,
Full,
}
pub type SimpleInstructionFunction =
fn(emulator: &mut ForwardComEmulator, instruction: &mut EmulatorInstruction, offset: usize);
pub type ComplexInstructionFunction = fn(
instruction: DecodedComplexInstruction,
register_file: &RegisterFile,
memory: &[u8],
output: &mut VecDeque<DecodedInstruction>,
);
pub struct SimpleIsaInstruction {
pub function: SimpleInstructionFunction,
pub vector_mode: VectorMode,
pub inputs: u8,
pub instr_type: u16,
pub instruction_flags: u16,
pub has_option_bits: bool,
pub operand_type_override: Option<OperandType>,
pub register_type_override: Option<(u8, Operand)>,
}
pub enum IsaInstruction {
Simple(SimpleIsaInstruction),
Complex(ComplexInstructionFunction),
}
pub const NOP: SimpleIsaInstruction = SimpleIsaInstruction {
function: |_, _, _| (),
instruction_flags: 0,
..SimpleIsaInstruction::DEFAULT
};
pub const NOT_YET_IMPLEMENTED_INSTRUCTION: SimpleIsaInstruction = SimpleIsaInstruction {
function: |_, instruction, _| {
log::debug!("Unimplemented instruction!");
instruction.valid = false;
},
..NOP
};
pub const UNSPECIFIED_INSTRUCTION: SimpleIsaInstruction = SimpleIsaInstruction {
function: |_, instruction, _| {
log::debug!("Tried to use unspecified instruction!");
instruction.valid = false;
},
..NOP
};
pub const LIMIT_VIOLATED: SimpleIsaInstruction = SimpleIsaInstruction {
function: |_, instruction, _| {
log::debug!("The index of the format went beyond the defined limit!");
instruction.valid = false;
},
..NOP
};
pub const PRIVILEGED_INSTRUCTION: SimpleIsaInstruction = SimpleIsaInstruction {
function: |_, instruction, _| {
log::debug!("Tried to use privileged instruction in user mode!");
instruction.valid = false;
},
..NOP
};
impl SimpleIsaInstruction {
const DEFAULT: Self = Self {
function: |_, _, _| (),
vector_mode: VectorMode::Element,
inputs: 0,
instr_type: instruction_type::REGISTER_MOVE,
instruction_flags: instruction_flags::REG_OUT,
has_option_bits: false,
operand_type_override: None,
register_type_override: None,
};
}