52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
// Copyright (c) 2025 taitep
|
|
// SPDX-License-Identifier: MIT
|
|
//
|
|
// This file is part of TRVE (https://gitea.taitep.se/taitep/trve)
|
|
// See LICENSE file in the project root for full license text.
|
|
|
|
mod rvi;
|
|
|
|
use crate::{
|
|
core::{Core, InstructionResult},
|
|
decode::Instruction,
|
|
};
|
|
|
|
pub(crate) fn find_and_exec(instr: Instruction, core: &mut Core) -> Option<InstructionResult> {
|
|
match instr.opcode_noncompressed() {
|
|
0b00100 => match instr.funct3() {
|
|
// OP_IMM
|
|
0b000 => Some(rvi::addi(core, instr)),
|
|
0b001 => (instr.funct6() == 0).then(|| rvi::slli(core, instr)),
|
|
0b111 => Some(rvi::andi(core, instr)),
|
|
_ => None,
|
|
},
|
|
0b00110 => match instr.funct3() {
|
|
// OP_IMM_32
|
|
0b000 => Some(rvi::addiw(core, instr)),
|
|
_ => None,
|
|
},
|
|
0b01000 => match instr.funct3() {
|
|
// STORE
|
|
0b000 => Some(rvi::sb(core, instr)),
|
|
0b011 => Some(rvi::sd(core, instr)),
|
|
_ => None,
|
|
},
|
|
0b00000 => match instr.funct3() {
|
|
// LOAD
|
|
0b000 => Some(rvi::lb(core, instr)),
|
|
0b100 => Some(rvi::lbu(core, instr)),
|
|
_ => None,
|
|
},
|
|
0b11000 => match instr.funct3() {
|
|
// BRANCH
|
|
0b000 => Some(rvi::beq(core, instr)),
|
|
_ => None,
|
|
},
|
|
0b01101 => Some(rvi::lui(core, instr)),
|
|
0b00101 => Some(rvi::auipc(core, instr)),
|
|
0b11011 => Some(rvi::jal(core, instr)),
|
|
0b11001 => (instr.funct3() == 0).then(|| rvi::jalr(core, instr)),
|
|
_ => None,
|
|
}
|
|
}
|