gpcas_forwardcom 0.2.0

ForwardCom instruction set architecture (ISA) properties for use with the General Purpose Core Architecture Simulator (GPCAS).
Documentation
// Filename: common.rs
// Author:	 Kai Rese
// Version:	 0.1
// Date:	 21-06-2022 (DD-MM-YYYY)
// Library:  gpcas_forwardcom
//
// Copyright (c) 2022 Kai Rese
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see
// <https://www.gnu.org/licenses/>.

//! Jump instruction that are specific to one or a few formats.

use crate::emulator::instructions::functions::*;
use crate::emulator::instructions::*;
use crate::ForwardComEmulator;

/// Marks a system call that gets no shared memory.
pub const NO_MEMORY: usize = 0;
/// Marks a system call that shares some memory with the application.
pub const SOME_MEMORY: usize = 1;
/// Marks a system call that can access all memory of the application.
pub const ALL_MEMORY: usize = 2;

/// System call instructions with their different memory sharing modes.
pub const SYS_CALLS: [SimpleIsaInstruction; 3] = [
    SimpleIsaInstruction {
        function: ForwardComEmulator::handle_sys_call::<NO_MEMORY>,
        inputs: 1,
        instr_type: instruction_type::BRANCH,
        instruction_flags: 0,
        ..SimpleIsaInstruction::DEFAULT
    },
    SimpleIsaInstruction {
        function: ForwardComEmulator::handle_sys_call::<SOME_MEMORY>,
        inputs: 3,
        instr_type: instruction_type::BRANCH,
        instruction_flags: 0,
        ..SimpleIsaInstruction::DEFAULT
    },
    SimpleIsaInstruction {
        function: ForwardComEmulator::handle_sys_call::<ALL_MEMORY>,
        inputs: 3,
        instr_type: instruction_type::BRANCH,
        instruction_flags: 0,
        ..SimpleIsaInstruction::DEFAULT
    },
];

/// Jump instructions that are specific for the 1.6 format.
///
/// Selections of table entries need an offset of 42 applied from opcode 58 onwards.
/// This is because instructions up to opcode 57 are found in the general table.
pub const JUMP_INSTRUCTIONS_FORMAT_1_6: [SimpleIsaInstruction; 5] = [
    // 58
    SimpleIsaInstruction {
        function: indirect_jump,
        inputs: 1,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_JUMP | instruction_flags::BR_INDIRECT,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 59
    SimpleIsaInstruction {
        function: indirect_jump,
        inputs: 1,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_CALL | instruction_flags::BR_INDIRECT,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 60
    SimpleIsaInstruction {
        function: multiway_jump,
        inputs: 2,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_CONDITIONAL | instruction_flags::BR_INDIRECT,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 61
    SimpleIsaInstruction {
        function: multiway_jump,
        inputs: 2,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_CALL | instruction_flags::BR_INDIRECT,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 62
    SimpleIsaInstruction {
        function: |_, _, _| (),
        inputs: 0,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_CALL | instruction_flags::BR_RETURN,
        ..SimpleIsaInstruction::DEFAULT
    },
];

/// Jump instructions that are specific for the 1.7 format.
///
/// Selections of table entries need an offset of 42 applied from opcode 58 onwards.
/// This is because instructions up to opcode 57 are found in the general table.
pub const JUMP_INSTRUCTIONS_FORMAT_1_7: [SimpleIsaInstruction; 6] = [
    // 58
    UNSPECIFIED_INSTRUCTION,
    // 59
    UNSPECIFIED_INSTRUCTION,
    // 60
    SimpleIsaInstruction {
        function: indirect_jump,
        inputs: 1,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_JUMP | instruction_flags::BR_INDIRECT,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 61
    SimpleIsaInstruction {
        function: indirect_jump,
        inputs: 1,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_CALL | instruction_flags::BR_INDIRECT,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 62
    PRIVILEGED_INSTRUCTION,
    // 63
    NOT_YET_IMPLEMENTED_INSTRUCTION,
];

/// Jump instructions that are specific for the 2.5.2 format.
///
/// Selections of table entries need an offset of 42 applied from opcode 58 onwards.
/// This is because instructions up to opcode 57 are found in the general table.
pub const JUMP_INSTRUCTIONS_FORMAT_2_5_2: [SimpleIsaInstruction; 6] = [
    // 58
    SimpleIsaInstruction {
        function: indirect_jump,
        inputs: 1,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_JUMP | instruction_flags::BR_INDIRECT,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 59
    SimpleIsaInstruction {
        function: indirect_jump,
        inputs: 1,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_CALL | instruction_flags::BR_INDIRECT,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 60
    SimpleIsaInstruction {
        function: multiway_jump,
        inputs: 2,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_CONDITIONAL | instruction_flags::BR_INDIRECT,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 61
    UNSPECIFIED_INSTRUCTION,
    // 62
    UNSPECIFIED_INSTRUCTION,
    // 63
    UNSPECIFIED_INSTRUCTION,
];

/// Direct jump instructions, used by multiple formats.
///
/// Selections of table entries need an offset of 42 applied from opcode 58 onwards.
/// This is because instructions up to opcode 57 are found in the general table.
pub const DIRECT_JUMPS: [SimpleIsaInstruction; 2] = [
    // 58
    SimpleIsaInstruction {
        function: |_, _, _| (),
        inputs: 0,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_JUMP,
        ..SimpleIsaInstruction::DEFAULT
    },
    // 59
    SimpleIsaInstruction {
        function: |_, _, _| (),
        inputs: 0,
        instr_type: instruction_type::BRANCH,
        instruction_flags: instruction_flags::BR_TYPE_CALL,
        ..SimpleIsaInstruction::DEFAULT
    },
];