2020-01-10 07:24:00 +01:00
|
|
|
/*******************************************************************************
|
2021-03-01 07:26:33 +01:00
|
|
|
* Copyright (C) 2021 MINRES Technologies GmbH
|
2020-01-10 07:24:00 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2021-10-17 12:25:13 +02:00
|
|
|
#include "../fp_functions.h"
|
|
|
|
#include <iss/arch/tgc_c.h>
|
|
|
|
#include <iss/arch/riscv_hart_m_p.h>
|
2020-01-10 07:24:00 +01:00
|
|
|
#include <iss/debugger/gdb_session.h>
|
|
|
|
#include <iss/debugger/server.h>
|
|
|
|
#include <iss/iss.h>
|
|
|
|
#include <iss/interp/vm_base.h>
|
|
|
|
#include <util/logging.h>
|
|
|
|
#include <sstream>
|
2021-10-17 12:25:13 +02:00
|
|
|
|
|
|
|
#ifndef FMT_HEADER_ONLY
|
|
|
|
#define FMT_HEADER_ONLY
|
|
|
|
#endif
|
2020-01-10 07:24:00 +01:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <iss/debugger/riscv_target_adapter.h>
|
|
|
|
|
|
|
|
namespace iss {
|
|
|
|
namespace interp {
|
2021-05-13 15:38:33 +02:00
|
|
|
namespace tgc_c {
|
2020-01-10 07:24:00 +01:00
|
|
|
using namespace iss::arch;
|
|
|
|
using namespace iss::debugger;
|
|
|
|
|
2020-01-10 09:37:48 +01:00
|
|
|
template <typename ARCH> class vm_impl : public iss::interp::vm_base<ARCH> {
|
2020-01-10 07:24:00 +01:00
|
|
|
public:
|
2020-12-29 09:48:22 +01:00
|
|
|
using traits = arch::traits<ARCH>;
|
|
|
|
using super = typename iss::interp::vm_base<ARCH>;
|
2020-01-10 07:24:00 +01:00
|
|
|
using virt_addr_t = typename super::virt_addr_t;
|
|
|
|
using phys_addr_t = typename super::phys_addr_t;
|
|
|
|
using code_word_t = typename super::code_word_t;
|
2020-12-29 09:48:22 +01:00
|
|
|
using addr_t = typename super::addr_t;
|
|
|
|
using reg_t = typename traits::reg_t;
|
|
|
|
using mem_type_e = typename traits::mem_type_e;
|
2021-09-23 21:09:36 +02:00
|
|
|
|
2020-01-10 07:24:00 +01:00
|
|
|
vm_impl();
|
|
|
|
|
|
|
|
vm_impl(ARCH &core, unsigned core_id = 0, unsigned cluster_id = 0);
|
|
|
|
|
|
|
|
void enableDebug(bool enable) { super::sync_exec = super::ALL_SYNC; }
|
|
|
|
|
|
|
|
target_adapter_if *accquire_target_adapter(server_if *srv) override {
|
|
|
|
debugger_if::dbg_enabled = true;
|
2020-01-10 09:37:48 +01:00
|
|
|
if (super::tgt_adapter == nullptr)
|
|
|
|
super::tgt_adapter = new riscv_target_adapter<ARCH>(srv, this->get_arch());
|
|
|
|
return super::tgt_adapter;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
using this_class = vm_impl<ARCH>;
|
|
|
|
using compile_ret_t = virt_addr_t;
|
|
|
|
using compile_func = compile_ret_t (this_class::*)(virt_addr_t &pc, code_word_t instr);
|
|
|
|
|
2020-12-29 09:48:22 +01:00
|
|
|
inline const char *name(size_t index){return traits::reg_aliases.at(index);}
|
2020-01-10 07:24:00 +01:00
|
|
|
|
2021-07-09 07:37:12 +02:00
|
|
|
compile_func decode_inst(code_word_t instr) ;
|
2021-03-17 20:32:57 +01:00
|
|
|
virt_addr_t execute_inst(finish_cond_e cond, virt_addr_t start, uint64_t icount_limit) override;
|
2020-01-10 07:24:00 +01:00
|
|
|
|
|
|
|
// some compile time constants
|
|
|
|
// enum { MASK16 = 0b1111110001100011, MASK32 = 0b11111111111100000111000001111111 };
|
|
|
|
enum { MASK16 = 0b1111111111111111, MASK32 = 0b11111111111100000111000001111111 };
|
|
|
|
enum { EXTR_MASK16 = MASK16 >> 2, EXTR_MASK32 = MASK32 >> 2 };
|
2021-10-17 12:25:13 +02:00
|
|
|
enum {
|
|
|
|
LUT_SIZE = 1 << util::bit_count(static_cast<uint32_t>(EXTR_MASK32)),
|
|
|
|
LUT_SIZE_C = 1 << util::bit_count(static_cast<uint32_t>(EXTR_MASK16))
|
|
|
|
};
|
2020-01-10 07:24:00 +01:00
|
|
|
|
|
|
|
std::array<compile_func, LUT_SIZE> lut;
|
|
|
|
|
|
|
|
std::array<compile_func, LUT_SIZE_C> lut_00, lut_01, lut_10;
|
|
|
|
std::array<compile_func, LUT_SIZE> lut_11;
|
|
|
|
|
2021-07-09 07:37:12 +02:00
|
|
|
struct instruction_pattern {
|
|
|
|
uint32_t value;
|
|
|
|
uint32_t mask;
|
|
|
|
compile_func opc;
|
|
|
|
};
|
2020-01-10 07:24:00 +01:00
|
|
|
|
2021-07-09 07:37:12 +02:00
|
|
|
std::array<std::vector<instruction_pattern>, 4> qlut;
|
2020-01-10 07:24:00 +01:00
|
|
|
|
2021-03-07 11:51:00 +01:00
|
|
|
inline void raise(uint16_t trap_id, uint16_t cause){
|
2020-01-12 18:19:48 +01:00
|
|
|
auto trap_val = 0x80ULL << 24 | (cause << 16) | trap_id;
|
2020-12-29 09:48:22 +01:00
|
|
|
this->template get_reg<uint32_t>(traits::TRAP_STATE) = trap_val;
|
|
|
|
this->template get_reg<uint32_t>(traits::NEXT_PC) = std::numeric_limits<uint32_t>::max();
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2021-03-07 11:51:00 +01:00
|
|
|
inline void leave(unsigned lvl){
|
2020-01-12 18:19:48 +01:00
|
|
|
this->core.leave_trap(lvl);
|
|
|
|
}
|
|
|
|
|
2021-03-07 11:51:00 +01:00
|
|
|
inline void wait(unsigned type){
|
2020-01-12 18:19:48 +01:00
|
|
|
this->core.wait_until(type);
|
|
|
|
}
|
|
|
|
|
2021-03-01 07:26:33 +01:00
|
|
|
template<typename T>
|
|
|
|
T& pc_assign(T& val){super::ex_info.branch_taken=true; return val;}
|
2021-06-07 22:22:36 +02:00
|
|
|
inline uint8_t readSpace1(typename super::mem_type_e space, uint64_t addr){
|
|
|
|
auto ret = super::template read_mem<uint8_t>(space, addr);
|
|
|
|
if(this->template get_reg<uint32_t>(traits::TRAP_STATE)) throw 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
inline uint16_t readSpace2(typename super::mem_type_e space, uint64_t addr){
|
|
|
|
auto ret = super::template read_mem<uint16_t>(space, addr);
|
|
|
|
if(this->template get_reg<uint32_t>(traits::TRAP_STATE)) throw 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
inline uint32_t readSpace4(typename super::mem_type_e space, uint64_t addr){
|
|
|
|
auto ret = super::template read_mem<uint32_t>(space, addr);
|
|
|
|
if(this->template get_reg<uint32_t>(traits::TRAP_STATE)) throw 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
inline uint64_t readSpace8(typename super::mem_type_e space, uint64_t addr){
|
|
|
|
auto ret = super::template read_mem<uint64_t>(space, addr);
|
|
|
|
if(this->template get_reg<uint32_t>(traits::TRAP_STATE)) throw 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
inline void writeSpace1(typename super::mem_type_e space, uint64_t addr, uint8_t data){
|
|
|
|
super::write_mem(space, addr, data);
|
|
|
|
if(this->template get_reg<uint32_t>(traits::TRAP_STATE)) throw 0;
|
|
|
|
}
|
|
|
|
inline void writeSpace2(typename super::mem_type_e space, uint64_t addr, uint16_t data){
|
|
|
|
super::write_mem(space, addr, data);
|
|
|
|
if(this->template get_reg<uint32_t>(traits::TRAP_STATE)) throw 0;
|
|
|
|
}
|
|
|
|
inline void writeSpace4(typename super::mem_type_e space, uint64_t addr, uint32_t data){
|
|
|
|
super::write_mem(space, addr, data);
|
|
|
|
if(this->template get_reg<uint32_t>(traits::TRAP_STATE)) throw 0;
|
|
|
|
}
|
|
|
|
inline void writeSpace8(typename super::mem_type_e space, uint64_t addr, uint64_t data){
|
|
|
|
super::write_mem(space, addr, data);
|
|
|
|
if(this->template get_reg<uint32_t>(traits::TRAP_STATE)) throw 0;
|
|
|
|
}
|
2021-03-13 11:19:30 +01:00
|
|
|
template<unsigned W, typename U, typename S = typename std::make_signed<U>::type>
|
|
|
|
inline S sext(U from) {
|
2021-03-09 11:21:36 +01:00
|
|
|
auto mask = (1ULL<<W) - 1;
|
|
|
|
auto sign_mask = 1ULL<<(W-1);
|
|
|
|
return (from & mask) | ((from & sign_mask) ? ~mask : 0);
|
|
|
|
}
|
2020-01-12 18:19:48 +01:00
|
|
|
|
2020-01-10 07:24:00 +01:00
|
|
|
private:
|
|
|
|
/****************************************************************************
|
|
|
|
* start opcode definitions
|
|
|
|
****************************************************************************/
|
|
|
|
struct InstructionDesriptor {
|
|
|
|
size_t length;
|
|
|
|
uint32_t value;
|
|
|
|
uint32_t mask;
|
|
|
|
compile_func op;
|
|
|
|
};
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
const std::array<InstructionDesriptor, 88> instr_descr = {{
|
2020-01-10 07:24:00 +01:00
|
|
|
/* entries are: size, valid value, valid mask, function ptr */
|
|
|
|
/* instruction LUI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000000000000110111, 0b00000000000000000000000001111111, &this_class::__lui},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction AUIPC */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000000000000010111, 0b00000000000000000000000001111111, &this_class::__auipc},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction JAL */
|
|
|
|
{32, 0b00000000000000000000000001101111, 0b00000000000000000000000001111111, &this_class::__jal},
|
|
|
|
/* instruction JALR */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000000000001100111, 0b00000000000000000111000001111111, &this_class::__jalr},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction BEQ */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000000000001100011, 0b00000000000000000111000001111111, &this_class::__beq},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction BNE */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000001000001100011, 0b00000000000000000111000001111111, &this_class::__bne},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction BLT */
|
|
|
|
{32, 0b00000000000000000100000001100011, 0b00000000000000000111000001111111, &this_class::__blt},
|
|
|
|
/* instruction BGE */
|
|
|
|
{32, 0b00000000000000000101000001100011, 0b00000000000000000111000001111111, &this_class::__bge},
|
|
|
|
/* instruction BLTU */
|
|
|
|
{32, 0b00000000000000000110000001100011, 0b00000000000000000111000001111111, &this_class::__bltu},
|
|
|
|
/* instruction BGEU */
|
|
|
|
{32, 0b00000000000000000111000001100011, 0b00000000000000000111000001111111, &this_class::__bgeu},
|
|
|
|
/* instruction LB */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000000000000000011, 0b00000000000000000111000001111111, &this_class::__lb},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction LH */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000001000000000011, 0b00000000000000000111000001111111, &this_class::__lh},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction LW */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000010000000000011, 0b00000000000000000111000001111111, &this_class::__lw},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction LBU */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000100000000000011, 0b00000000000000000111000001111111, &this_class::__lbu},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction LHU */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000101000000000011, 0b00000000000000000111000001111111, &this_class::__lhu},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SB */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000000000000100011, 0b00000000000000000111000001111111, &this_class::__sb},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SH */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000001000000100011, 0b00000000000000000111000001111111, &this_class::__sh},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SW */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000010000000100011, 0b00000000000000000111000001111111, &this_class::__sw},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction ADDI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000000000000010011, 0b00000000000000000111000001111111, &this_class::__addi},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SLTI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000010000000010011, 0b00000000000000000111000001111111, &this_class::__slti},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SLTIU */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000011000000010011, 0b00000000000000000111000001111111, &this_class::__sltiu},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction XORI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000100000000010011, 0b00000000000000000111000001111111, &this_class::__xori},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction ORI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000110000000010011, 0b00000000000000000111000001111111, &this_class::__ori},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction ANDI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000111000000010011, 0b00000000000000000111000001111111, &this_class::__andi},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SLLI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000001000000010011, 0b11111110000000000111000001111111, &this_class::__slli},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SRLI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000101000000010011, 0b11111110000000000111000001111111, &this_class::__srli},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SRAI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b01000000000000000101000000010011, 0b11111110000000000111000001111111, &this_class::__srai},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction ADD */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000000000000110011, 0b11111110000000000111000001111111, &this_class::__add},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SUB */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b01000000000000000000000000110011, 0b11111110000000000111000001111111, &this_class::__sub},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SLL */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000001000000110011, 0b11111110000000000111000001111111, &this_class::__sll},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SLT */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000010000000110011, 0b11111110000000000111000001111111, &this_class::__slt},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SLTU */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000011000000110011, 0b11111110000000000111000001111111, &this_class::__sltu},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction XOR */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000100000000110011, 0b11111110000000000111000001111111, &this_class::__xor},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SRL */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000101000000110011, 0b11111110000000000111000001111111, &this_class::__srl},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SRA */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b01000000000000000101000000110011, 0b11111110000000000111000001111111, &this_class::__sra},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction OR */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000110000000110011, 0b11111110000000000111000001111111, &this_class::__or},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction AND */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000111000000110011, 0b11111110000000000111000001111111, &this_class::__and},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction FENCE */
|
2021-06-07 22:22:36 +02:00
|
|
|
{32, 0b00000000000000000000000000001111, 0b00000000000000000111000001111111, &this_class::__fence},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction ECALL */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000000000001110011, 0b11111111111111111111111111111111, &this_class::__ecall},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction EBREAK */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000100000000000001110011, 0b11111111111111111111111111111111, &this_class::__ebreak},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction URET */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000001000000000000001110011, 0b11111111111111111111111111111111, &this_class::__uret},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction SRET */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00010000001000000000000001110011, 0b11111111111111111111111111111111, &this_class::__sret},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction MRET */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00110000001000000000000001110011, 0b11111111111111111111111111111111, &this_class::__mret},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction WFI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00010000010100000000000001110011, 0b11111111111111111111111111111111, &this_class::__wfi},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction CSRRW */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000001000001110011, 0b00000000000000000111000001111111, &this_class::__csrrw},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction CSRRS */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000010000001110011, 0b00000000000000000111000001111111, &this_class::__csrrs},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction CSRRC */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000000000000000011000001110011, 0b00000000000000000111000001111111, &this_class::__csrrc},
|
2020-01-10 07:24:00 +01:00
|
|
|
/* instruction CSRRWI */
|
|
|
|
{32, 0b00000000000000000101000001110011, 0b00000000000000000111000001111111, &this_class::__csrrwi},
|
|
|
|
/* instruction CSRRSI */
|
|
|
|
{32, 0b00000000000000000110000001110011, 0b00000000000000000111000001111111, &this_class::__csrrsi},
|
|
|
|
/* instruction CSRRCI */
|
|
|
|
{32, 0b00000000000000000111000001110011, 0b00000000000000000111000001111111, &this_class::__csrrci},
|
2020-08-24 15:01:54 +02:00
|
|
|
/* instruction MUL */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000010000000000000000000110011, 0b11111110000000000111000001111111, &this_class::__mul},
|
2020-08-24 15:01:54 +02:00
|
|
|
/* instruction MULH */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000010000000000001000000110011, 0b11111110000000000111000001111111, &this_class::__mulh},
|
2020-08-24 15:01:54 +02:00
|
|
|
/* instruction MULHSU */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000010000000000010000000110011, 0b11111110000000000111000001111111, &this_class::__mulhsu},
|
2020-08-24 15:01:54 +02:00
|
|
|
/* instruction MULHU */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000010000000000011000000110011, 0b11111110000000000111000001111111, &this_class::__mulhu},
|
2020-08-24 15:01:54 +02:00
|
|
|
/* instruction DIV */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000010000000000100000000110011, 0b11111110000000000111000001111111, &this_class::__div},
|
2020-08-24 15:01:54 +02:00
|
|
|
/* instruction DIVU */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000010000000000101000000110011, 0b11111110000000000111000001111111, &this_class::__divu},
|
2020-08-24 15:01:54 +02:00
|
|
|
/* instruction REM */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000010000000000110000000110011, 0b11111110000000000111000001111111, &this_class::__rem},
|
2020-08-24 15:01:54 +02:00
|
|
|
/* instruction REMU */
|
2021-03-07 11:51:00 +01:00
|
|
|
{32, 0b00000010000000000111000000110011, 0b11111110000000000111000001111111, &this_class::__remu},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CADDI4SPN */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0000000000000000, 0b1110000000000011, &this_class::__caddi4spn},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CLW */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0100000000000000, 0b1110000000000011, &this_class::__clw},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CSW */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1100000000000000, 0b1110000000000011, &this_class::__csw},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CADDI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0000000000000001, 0b1110000000000011, &this_class::__caddi},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CNOP */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0000000000000001, 0b1110111110000011, &this_class::__cnop},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CJAL */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0010000000000001, 0b1110000000000011, &this_class::__cjal},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CLI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0100000000000001, 0b1110000000000011, &this_class::__cli},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CLUI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0110000000000001, 0b1110000000000011, &this_class::__clui},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CADDI16SP */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0110000100000001, 0b1110111110000011, &this_class::__caddi16sp},
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction __reserved_clui */
|
|
|
|
{16, 0b0110000000000001, 0b1111000001111111, &this_class::____reserved_clui},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CSRLI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1000000000000001, 0b1111110000000011, &this_class::__csrli},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CSRAI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1000010000000001, 0b1111110000000011, &this_class::__csrai},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CANDI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1000100000000001, 0b1110110000000011, &this_class::__candi},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CSUB */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1000110000000001, 0b1111110001100011, &this_class::__csub},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CXOR */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1000110000100001, 0b1111110001100011, &this_class::__cxor},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction COR */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1000110001000001, 0b1111110001100011, &this_class::__cor},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CAND */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1000110001100001, 0b1111110001100011, &this_class::__cand},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CJ */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1010000000000001, 0b1110000000000011, &this_class::__cj},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CBEQZ */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1100000000000001, 0b1110000000000011, &this_class::__cbeqz},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CBNEZ */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1110000000000001, 0b1110000000000011, &this_class::__cbnez},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CSLLI */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0000000000000010, 0b1111000000000011, &this_class::__cslli},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CLWSP */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0100000000000010, 0b1110000000000011, &this_class::__clwsp},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CMV */
|
|
|
|
{16, 0b1000000000000010, 0b1111000000000011, &this_class::__cmv},
|
|
|
|
/* instruction CJR */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1000000000000010, 0b1111000001111111, &this_class::__cjr},
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction __reserved_cmv */
|
|
|
|
{16, 0b1000000000000010, 0b1111111111111111, &this_class::____reserved_cmv},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CADD */
|
|
|
|
{16, 0b1001000000000010, 0b1111000000000011, &this_class::__cadd},
|
|
|
|
/* instruction CJALR */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1001000000000010, 0b1111000001111111, &this_class::__cjalr},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CEBREAK */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b1001000000000010, 0b1111111111111111, &this_class::__cebreak},
|
2020-12-29 09:48:22 +01:00
|
|
|
/* instruction CSWSP */
|
|
|
|
{16, 0b1100000000000010, 0b1110000000000011, &this_class::__cswsp},
|
2020-01-12 18:19:48 +01:00
|
|
|
/* instruction DII */
|
2021-03-07 11:51:00 +01:00
|
|
|
{16, 0b0000000000000000, 0b1111111111111111, &this_class::__dii},
|
2020-01-10 07:24:00 +01:00
|
|
|
}};
|
|
|
|
|
|
|
|
/* instruction definitions */
|
|
|
|
/* instruction 0: LUI */
|
|
|
|
compile_ret_t __lui(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 0);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint32_t imm = ((bit_sub<12,20>(instr) << 12));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "lui"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-01 22:07:20 +01:00
|
|
|
if(rd != 0) *(X+rd) = (int32_t)imm;
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 0);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 1: AUIPC */
|
|
|
|
compile_ret_t __auipc(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 1);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint32_t imm = ((bit_sub<12,20>(instr) << 12));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm:#08x}", fmt::arg("mnemonic", "auipc"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-01 22:07:20 +01:00
|
|
|
if(rd != 0) *(X+rd) = *PC + (int32_t)imm;
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 1);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 2: JAL */
|
|
|
|
compile_ret_t __jal(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 2);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint32_t imm = ((bit_sub<12,8>(instr) << 12) | (bit_sub<20,1>(instr) << 11) | (bit_sub<21,10>(instr) << 1) | (bit_sub<31,1>(instr) << 20));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm:#0x}", fmt::arg("mnemonic", "jal"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-09-29 00:03:11 +02:00
|
|
|
if(imm % traits::INSTR_ALIGNMENT) {
|
|
|
|
raise(0, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(rd != 0) *(X+rd) = *PC + 4;
|
|
|
|
pc_assign(*NEXT_PC) = *PC + (int32_t)sext<21>(imm);
|
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 2);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 3: JALR */
|
|
|
|
compile_ret_t __jalr(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 3);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {imm:#0x}", fmt::arg("mnemonic", "jalr"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-09-29 00:44:17 +02:00
|
|
|
int32_t new_pc = (*(X+rs1) + (int16_t)sext<12>(imm)) & ~ 1;
|
2021-09-29 00:03:11 +02:00
|
|
|
if(new_pc % traits::INSTR_ALIGNMENT) {
|
|
|
|
raise(0, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(rd != 0) *(X+rd) = *PC + 4;
|
|
|
|
pc_assign(*NEXT_PC) = new_pc & ~ 0x1;
|
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 3);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 4: BEQ */
|
|
|
|
compile_ret_t __beq(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 4);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "beq"),
|
|
|
|
fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-09-29 00:03:11 +02:00
|
|
|
{
|
|
|
|
if(*(X+rs1) == *(X+rs2)) if(imm % traits::INSTR_ALIGNMENT) {
|
|
|
|
raise(0, 0);
|
|
|
|
}
|
|
|
|
else pc_assign(*NEXT_PC) = *PC + (int16_t)sext<13>(imm);
|
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 4);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 5: BNE */
|
|
|
|
compile_ret_t __bne(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 5);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "bne"),
|
|
|
|
fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-09-29 00:03:11 +02:00
|
|
|
{
|
|
|
|
if(*(X+rs1) != *(X+rs2)) if(imm % traits::INSTR_ALIGNMENT) {
|
|
|
|
raise(0, 0);
|
|
|
|
}
|
|
|
|
else pc_assign(*NEXT_PC) = *PC + (int16_t)sext<13>(imm);
|
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 5);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 6: BLT */
|
|
|
|
compile_ret_t __blt(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 6);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "blt"),
|
|
|
|
fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-09-29 00:03:11 +02:00
|
|
|
{
|
|
|
|
if((int32_t)*(X+rs1) < (int32_t)*(X+rs2)) if(imm % traits::INSTR_ALIGNMENT) {
|
|
|
|
raise(0, 0);
|
|
|
|
}
|
|
|
|
else pc_assign(*NEXT_PC) = *PC + (int16_t)sext<13>(imm);
|
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 6);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 7: BGE */
|
|
|
|
compile_ret_t __bge(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 7);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "bge"),
|
|
|
|
fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-09-29 00:03:11 +02:00
|
|
|
{
|
|
|
|
if((int32_t)*(X+rs1) >= (int32_t)*(X+rs2)) if(imm % traits::INSTR_ALIGNMENT) {
|
|
|
|
raise(0, 0);
|
|
|
|
}
|
|
|
|
else pc_assign(*NEXT_PC) = *PC + (int16_t)sext<13>(imm);
|
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 7);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 8: BLTU */
|
|
|
|
compile_ret_t __bltu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 8);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "bltu"),
|
|
|
|
fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-09-29 00:03:11 +02:00
|
|
|
{
|
|
|
|
if(*(X+rs1) < *(X+rs2)) if(imm % traits::INSTR_ALIGNMENT) {
|
|
|
|
raise(0, 0);
|
|
|
|
}
|
|
|
|
else pc_assign(*NEXT_PC) = *PC + (int16_t)sext<13>(imm);
|
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 8);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 9: BGEU */
|
|
|
|
compile_ret_t __bgeu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 9);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "bgeu"),
|
|
|
|
fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-09-29 00:03:11 +02:00
|
|
|
{
|
|
|
|
if(*(X+rs1) >= *(X+rs2)) if(imm % traits::INSTR_ALIGNMENT) {
|
|
|
|
raise(0, 0);
|
|
|
|
}
|
|
|
|
else pc_assign(*NEXT_PC) = *PC + (int16_t)sext<13>(imm);
|
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 9);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 10: LB */
|
|
|
|
compile_ret_t __lb(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 10);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lb"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
int8_t res = (int8_t)readSpace1(traits::MEM, *(X+rs1) + (int16_t)sext<12>(imm));
|
|
|
|
if(rd != 0) *(X+rd) = res;
|
2021-03-07 11:51:00 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 10);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 11: LH */
|
|
|
|
compile_ret_t __lh(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 11);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lh"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t load_address = *(X+rs1) + (int16_t)sext<12>(imm);
|
2021-08-14 10:57:36 +02:00
|
|
|
int16_t res = (int16_t)readSpace2(traits::MEM, load_address);
|
2021-07-06 21:19:36 +02:00
|
|
|
if(rd != 0) *(X+rd) = res;
|
2021-03-07 11:51:00 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 11);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 12: LW */
|
|
|
|
compile_ret_t __lw(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 12);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lw"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t load_address = *(X+rs1) + (int16_t)sext<12>(imm);
|
2021-08-14 10:57:36 +02:00
|
|
|
int32_t res = (int32_t)readSpace4(traits::MEM, load_address);
|
2021-07-06 21:19:36 +02:00
|
|
|
if(rd != 0) *(X+rd) = (uint32_t)res;
|
2021-03-07 11:51:00 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 12);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 13: LBU */
|
|
|
|
compile_ret_t __lbu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 13);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lbu"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint8_t res = (uint8_t)readSpace1(traits::MEM, *(X+rs1) + (int16_t)sext<12>(imm));
|
|
|
|
if(rd != 0) *(X+rd) = res;
|
2021-03-07 11:51:00 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 13);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 14: LHU */
|
|
|
|
compile_ret_t __lhu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 14);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lhu"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t load_address = *(X+rs1) + (int16_t)sext<12>(imm);
|
2021-08-14 10:57:36 +02:00
|
|
|
uint16_t res = (uint16_t)readSpace2(traits::MEM, load_address);
|
2021-07-06 21:19:36 +02:00
|
|
|
if(rd != 0) *(X+rd) = res;
|
2021-03-07 11:51:00 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 14);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 15: SB */
|
|
|
|
compile_ret_t __sb(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 15);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs2}, {imm}({rs1})", fmt::arg("mnemonic", "sb"),
|
|
|
|
fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
writeSpace1(traits::MEM, *(X+rs1) + (int16_t)sext<12>(imm), (int8_t)*(X+rs2));
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 15);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 16: SH */
|
|
|
|
compile_ret_t __sh(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 16);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs2}, {imm}({rs1})", fmt::arg("mnemonic", "sh"),
|
|
|
|
fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t store_address = *(X+rs1) + (int16_t)sext<12>(imm);
|
2021-07-06 21:19:36 +02:00
|
|
|
writeSpace2(traits::MEM, store_address, (int16_t)*(X+rs2));
|
2021-03-07 11:51:00 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 16);
|
|
|
|
// trap check
|
2021-03-06 08:17:42 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-06 08:17:42 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 17: SW */
|
|
|
|
compile_ret_t __sw(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 17);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs2}, {imm}({rs1})", fmt::arg("mnemonic", "sw"),
|
|
|
|
fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t store_address = *(X+rs1) + (int16_t)sext<12>(imm);
|
2021-07-06 21:19:36 +02:00
|
|
|
writeSpace4(traits::MEM, store_address, *(X+rs2));
|
2021-03-07 11:51:00 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 17);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 18: ADDI */
|
|
|
|
compile_ret_t __addi(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 18);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "addi"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) + (int16_t)sext<12>(imm);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 18);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 19: SLTI */
|
|
|
|
compile_ret_t __slti(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 19);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "slti"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
if(rd != 0) *(X+rd) = (int32_t)*(X+rs1) < (int16_t)sext<12>(imm)? 1 : 0;
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 19);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 20: SLTIU */
|
|
|
|
compile_ret_t __sltiu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 20);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "sltiu"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-06-29 11:51:19 +02:00
|
|
|
if(rd != 0) *(X+rd) = (*(X+rs1) < (uint32_t)((int16_t)sext<12>(imm)))? 1 : 0;
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 20);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 21: XORI */
|
|
|
|
compile_ret_t __xori(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 21);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "xori"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) ^ (int16_t)sext<12>(imm);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 21);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 22: ORI */
|
|
|
|
compile_ret_t __ori(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 22);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "ori"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) | (int16_t)sext<12>(imm);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 22);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 23: ANDI */
|
|
|
|
compile_ret_t __andi(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 23);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<20,12>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "andi"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) & (int16_t)sext<12>(imm);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 23);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 24: SLLI */
|
|
|
|
compile_ret_t __slli(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 24);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t shamt = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {shamt}", fmt::arg("mnemonic", "slli"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("shamt", shamt));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(shamt > 31) {
|
2021-03-13 11:19:30 +01:00
|
|
|
raise(0, 0);
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) << shamt;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 24);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 25: SRLI */
|
|
|
|
compile_ret_t __srli(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 25);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t shamt = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {shamt}", fmt::arg("mnemonic", "srli"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("shamt", shamt));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(shamt > 31) {
|
2021-03-13 11:19:30 +01:00
|
|
|
raise(0, 0);
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) >> shamt;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 25);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 26: SRAI */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __srai(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 26);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t shamt = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {shamt}", fmt::arg("mnemonic", "srai"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("shamt", shamt));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(shamt > 31) {
|
2021-03-13 11:19:30 +01:00
|
|
|
raise(0, 0);
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) *(X+rd) = (int32_t)*(X+rs1) >> shamt;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 26);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 27: ADD */
|
|
|
|
compile_ret_t __add(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 27);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "add"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) + *(X+rs2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 27);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 28: SUB */
|
|
|
|
compile_ret_t __sub(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 28);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "sub"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) - *(X+rs2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 28);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 29: SLL */
|
|
|
|
compile_ret_t __sll(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 29);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "sll"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) << (*(X+rs2) & (traits::XLEN - 1));
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 29);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 30: SLT */
|
|
|
|
compile_ret_t __slt(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 30);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "slt"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-11 17:12:28 +01:00
|
|
|
if(rd != 0) *(X+rd) = (int32_t)*(X+rs1) < (int32_t)*(X+rs2)? 1 : 0;
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 30);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 31: SLTU */
|
|
|
|
compile_ret_t __sltu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 31);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "sltu"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(rd != 0) *(X+rd) = (uint32_t)*(X+rs1) < (uint32_t)*(X+rs2)? 1 : 0;
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 31);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 32: XOR */
|
|
|
|
compile_ret_t __xor(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 32);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "xor"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) ^ *(X+rs2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 32);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 33: SRL */
|
|
|
|
compile_ret_t __srl(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 33);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "srl"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-11 17:12:28 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) >> (*(X+rs2) & (traits::XLEN - 1));
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 33);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 34: SRA */
|
|
|
|
compile_ret_t __sra(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 34);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "sra"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-11 17:12:28 +01:00
|
|
|
if(rd != 0) *(X+rd) = (int32_t)*(X+rs1) >> (*(X+rs2) & (traits::XLEN - 1));
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 34);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 35: OR */
|
|
|
|
compile_ret_t __or(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 35);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "or"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) | *(X+rs2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 35);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 36: AND */
|
|
|
|
compile_ret_t __and(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 36);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "and"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs1) & *(X+rs2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 36);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 37: FENCE */
|
|
|
|
compile_ret_t __fence(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 37);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t succ = ((bit_sub<20,4>(instr)));
|
|
|
|
uint8_t pred = ((bit_sub<24,4>(instr)));
|
2021-06-07 22:22:36 +02:00
|
|
|
uint8_t fm = ((bit_sub<28,4>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
2021-02-15 19:01:33 +01:00
|
|
|
auto mnemonic = fmt::format(
|
2021-06-07 22:22:36 +02:00
|
|
|
"{mnemonic:10} {pred}, {succ} ({fm} , {rs1}, {rd})", fmt::arg("mnemonic", "fence"),
|
|
|
|
fmt::arg("pred", pred), fmt::arg("succ", succ), fmt::arg("fm", fm), fmt::arg("rs1", name(rs1)), fmt::arg("rd", name(rd)));
|
2021-02-15 19:01:33 +01:00
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
2021-02-06 15:47:06 +01:00
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
writeSpace1(traits::FENCE, traits::fence, pred << 4 | succ);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 37);
|
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 38: ECALL */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __ecall(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 38);
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "ecall");
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
raise(0, 11);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 38);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 39: EBREAK */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __ebreak(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 39);
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "ebreak");
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
raise(0, 3);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 39);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 40: URET */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __uret(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 40);
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "uret");
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
leave(0);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 40);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 41: SRET */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __sret(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 41);
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "sret");
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
leave(1);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 41);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 42: MRET */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __mret(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 42);
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "mret");
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
leave(3);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 42);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 43: WFI */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __wfi(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 43);
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "wfi");
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
wait(1);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 43);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 44: CSRRW */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __csrrw(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 44);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint16_t csr = ((bit_sub<20,12>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {csr}, {rs1}", fmt::arg("mnemonic", "csrrw"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-06-29 11:51:19 +02:00
|
|
|
uint32_t xrs1 = *(X+rs1);
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) {
|
2021-06-29 11:51:19 +02:00
|
|
|
uint32_t xrd = readSpace4(traits::CSR, csr);
|
|
|
|
writeSpace4(traits::CSR, csr, xrs1);
|
|
|
|
*(X+rd) = xrd;
|
2021-03-13 11:19:30 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-06-29 11:51:19 +02:00
|
|
|
writeSpace4(traits::CSR, csr, xrs1);
|
2021-03-13 11:19:30 +01:00
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 44);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 45: CSRRS */
|
2020-01-12 18:19:48 +01:00
|
|
|
compile_ret_t __csrrs(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 45);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint16_t csr = ((bit_sub<20,12>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {csr}, {rs1}", fmt::arg("mnemonic", "csrrs"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t xrd = readSpace4(traits::CSR, csr);
|
|
|
|
uint32_t xrs1 = *(X+rs1);
|
|
|
|
if(rs1 != 0) writeSpace4(traits::CSR, csr, xrd | xrs1);
|
2021-06-07 22:22:36 +02:00
|
|
|
if(rd != 0) *(X+rd) = xrd;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 45);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 46: CSRRC */
|
2020-01-12 18:19:48 +01:00
|
|
|
compile_ret_t __csrrc(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 46);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint16_t csr = ((bit_sub<20,12>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {csr}, {rs1}", fmt::arg("mnemonic", "csrrc"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t xrd = readSpace4(traits::CSR, csr);
|
|
|
|
uint32_t xrs1 = *(X+rs1);
|
|
|
|
if(rs1 != 0) writeSpace4(traits::CSR, csr, xrd & ~ xrs1);
|
2021-06-07 22:22:36 +02:00
|
|
|
if(rd != 0) *(X+rd) = xrd;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 46);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
2020-01-10 07:24:00 +01:00
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 47: CSRRWI */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __csrrwi(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 47);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t zimm = ((bit_sub<15,5>(instr)));
|
|
|
|
uint16_t csr = ((bit_sub<20,12>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {csr}, {zimm:#0x}", fmt::arg("mnemonic", "csrrwi"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("zimm", zimm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-06-29 11:51:19 +02:00
|
|
|
uint32_t xrd = readSpace4(traits::CSR, csr);
|
2021-03-13 11:19:30 +01:00
|
|
|
writeSpace4(traits::CSR, csr, (uint32_t)zimm);
|
2021-06-29 11:51:19 +02:00
|
|
|
if(rd != 0) *(X+rd) = xrd;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 47);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 48: CSRRSI */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __csrrsi(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 48);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t zimm = ((bit_sub<15,5>(instr)));
|
|
|
|
uint16_t csr = ((bit_sub<20,12>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {csr}, {zimm:#0x}", fmt::arg("mnemonic", "csrrsi"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("zimm", zimm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-06-29 11:51:19 +02:00
|
|
|
uint32_t xrd = readSpace4(traits::CSR, csr);
|
|
|
|
if(zimm != 0) writeSpace4(traits::CSR, csr, xrd | (uint32_t)zimm);
|
|
|
|
if(rd != 0) *(X+rd) = xrd;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 48);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 49: CSRRCI */
|
2020-01-10 07:24:00 +01:00
|
|
|
compile_ret_t __csrrci(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 49);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t zimm = ((bit_sub<15,5>(instr)));
|
|
|
|
uint16_t csr = ((bit_sub<20,12>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {csr}, {zimm:#0x}", fmt::arg("mnemonic", "csrrci"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("zimm", zimm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-06-29 11:51:19 +02:00
|
|
|
uint32_t xrd = readSpace4(traits::CSR, csr);
|
|
|
|
if(zimm != 0) writeSpace4(traits::CSR, csr, xrd & ~ ((uint32_t)zimm));
|
|
|
|
if(rd != 0) *(X+rd) = xrd;
|
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 49);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 50: MUL */
|
2020-08-24 15:01:54 +02:00
|
|
|
compile_ret_t __mul(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 50);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "mul"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) {
|
2021-03-13 11:46:30 +01:00
|
|
|
int64_t res = (int64_t)(int32_t)*(X+rs1) * (int64_t)(int32_t)*(X+rs2);
|
2021-03-13 11:19:30 +01:00
|
|
|
*(X+rd) = (uint32_t)res;
|
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 50);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-08-24 15:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 51: MULH */
|
2020-08-24 15:01:54 +02:00
|
|
|
compile_ret_t __mulh(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 51);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "mulh"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) {
|
2021-03-13 11:46:30 +01:00
|
|
|
int64_t res = (int64_t)(int32_t)*(X+rs1) * (int64_t)(int32_t)*(X+rs2);
|
2021-03-13 11:19:30 +01:00
|
|
|
*(X+rd) = (uint32_t)(res >> traits::XLEN);
|
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 51);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-08-24 15:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 52: MULHSU */
|
2020-08-24 15:01:54 +02:00
|
|
|
compile_ret_t __mulhsu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 52);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "mulhsu"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) {
|
2021-03-13 11:46:30 +01:00
|
|
|
int64_t res = (int64_t)(int32_t)*(X+rs1) * (uint64_t)*(X+rs2);
|
|
|
|
*(X+rd) = (uint32_t)(res >> traits::XLEN);
|
2021-03-13 11:19:30 +01:00
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 52);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-08-24 15:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 53: MULHU */
|
2020-08-24 15:01:54 +02:00
|
|
|
compile_ret_t __mulhu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 53);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "mulhu"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) {
|
2021-03-13 11:46:30 +01:00
|
|
|
uint64_t res = (uint64_t)*(X+rs1) * (uint64_t)*(X+rs2);
|
|
|
|
*(X+rd) = (uint32_t)(res >> traits::XLEN);
|
2021-03-13 11:19:30 +01:00
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 53);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-08-24 15:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 54: DIV */
|
2020-08-24 15:01:54 +02:00
|
|
|
compile_ret_t __div(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 54);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "div"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) {
|
|
|
|
if(*(X+rs2) != 0) {
|
|
|
|
uint32_t MMIN = 1 << (traits::XLEN - 1);
|
|
|
|
if(*(X+rs1) == MMIN && (int32_t)*(X+rs2) == - 1) *(X+rd) = MMIN;
|
|
|
|
else *(X+rd) = (int32_t)*(X+rs1) / (int32_t)*(X+rs2);
|
|
|
|
}
|
|
|
|
else *(X+rd) = - 1;
|
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 54);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-08-24 15:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 55: DIVU */
|
2020-08-24 15:01:54 +02:00
|
|
|
compile_ret_t __divu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 55);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "divu"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) {
|
|
|
|
if(*(X+rs2) != 0) *(X+rd) = *(X+rs1) / *(X+rs2);
|
|
|
|
else *(X+rd) = - 1;
|
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 55);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-08-24 15:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 56: REM */
|
2020-08-24 15:01:54 +02:00
|
|
|
compile_ret_t __rem(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 56);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "rem"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) {
|
|
|
|
if(*(X+rs2) != 0) {
|
|
|
|
uint32_t MMIN = 1 << (traits::XLEN - 1);
|
|
|
|
if(*(X+rs1) == MMIN && (int32_t)*(X+rs2) == - 1) *(X+rd) = 0;
|
|
|
|
else *(X+rd) = (int32_t)*(X+rs1) % (int32_t)*(X+rs2);
|
|
|
|
}
|
|
|
|
else *(X+rd) = *(X+rs1);
|
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 56);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-08-24 15:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 57: REMU */
|
2020-08-24 15:01:54 +02:00
|
|
|
compile_ret_t __remu(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 57);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<15,5>(instr)));
|
|
|
|
uint8_t rs2 = ((bit_sub<20,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "remu"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 4;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) {
|
|
|
|
if(*(X+rs2) != 0) *(X+rd) = *(X+rs1) % *(X+rs2);
|
|
|
|
else *(X+rd) = *(X+rs1);
|
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 57);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 58: CADDI4SPN */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __caddi4spn(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 58);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<2,3>(instr)));
|
|
|
|
uint16_t imm = ((bit_sub<5,1>(instr) << 3) | (bit_sub<6,1>(instr) << 2) | (bit_sub<7,4>(instr) << 6) | (bit_sub<11,2>(instr) << 4));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "caddi4spn"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-06-29 11:51:19 +02:00
|
|
|
if(imm) *(X+(rd + 8)) = *(X+2) + imm;
|
|
|
|
else raise(0, 2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 58);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 59: CLW */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __clw(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 59);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<2,3>(instr)));
|
|
|
|
uint8_t uimm = ((bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 2) | (bit_sub<10,3>(instr) << 3));
|
|
|
|
uint8_t rs1 = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "clw"),
|
|
|
|
fmt::arg("rd", name(8+rd)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t load_address = *(X+(rs1 + 8)) + uimm;
|
2021-07-06 21:19:36 +02:00
|
|
|
*(X+(rd + 8)) = (int32_t)readSpace4(traits::MEM, load_address);
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 59);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 60: CSW */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __csw(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 60);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs2 = ((bit_sub<2,3>(instr)));
|
|
|
|
uint8_t uimm = ((bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 2) | (bit_sub<10,3>(instr) << 3));
|
|
|
|
uint8_t rs1 = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs2}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "csw"),
|
|
|
|
fmt::arg("rs2", name(8+rs2)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t load_address = *(X+(rs1 + 8)) + uimm;
|
2021-07-06 21:19:36 +02:00
|
|
|
writeSpace4(traits::MEM, load_address, *(X+(rs2 + 8)));
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 60);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 61: CADDI */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __caddi(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 61);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint8_t imm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "caddi"),
|
|
|
|
fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
*(X+rs1) = *(X+rs1) + (int8_t)sext<6>(imm);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 61);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 62: CNOP */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cnop(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 62);
|
2021-03-07 11:51:00 +01:00
|
|
|
uint8_t nzimm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "cnop");
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 62);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 63: CJAL */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cjal(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 63);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,3>(instr) << 1) | (bit_sub<6,1>(instr) << 7) | (bit_sub<7,1>(instr) << 6) | (bit_sub<8,1>(instr) << 10) | (bit_sub<9,2>(instr) << 8) | (bit_sub<11,1>(instr) << 4) | (bit_sub<12,1>(instr) << 11));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "cjal"),
|
|
|
|
fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
*(X+1) = *PC + 2;
|
|
|
|
pc_assign(*NEXT_PC) = *PC + (int16_t)sext<12>(imm);
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 63);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 64: CLI */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cli(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 64);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint8_t imm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "cli"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(rd != 0) *(X+rd) = (uint32_t)(int32_t)sext<6>(imm);
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 64);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 65: CLUI */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __clui(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 65);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint32_t imm = ((bit_sub<2,5>(instr) << 12) | (bit_sub<12,1>(instr) << 17));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "clui"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
if(imm == 0) raise(0, 2);
|
2021-06-29 11:51:19 +02:00
|
|
|
if(rd != 0) *(X+rd) = (int32_t)sext<18>(imm);
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 65);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 22:22:36 +02:00
|
|
|
/* instruction 66: CADDI16SP */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __caddi16sp(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 66);
|
2021-03-13 11:19:30 +01:00
|
|
|
uint16_t nzimm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,2>(instr) << 7) | (bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 4) | (bit_sub<12,1>(instr) << 9));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
2021-03-13 11:19:30 +01:00
|
|
|
"{mnemonic:10} {nzimm:#05x}", fmt::arg("mnemonic", "caddi16sp"),
|
|
|
|
fmt::arg("nzimm", nzimm));
|
2021-02-06 15:47:06 +01:00
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
if(nzimm) *(X+2) = *(X+2) + (int16_t)sext<10>(nzimm);
|
2021-03-07 11:51:00 +01:00
|
|
|
else raise(0, 2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-07 22:22:36 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 66);
|
2021-06-29 11:51:19 +02:00
|
|
|
// trap check
|
|
|
|
if(*trap_state!=0){
|
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
|
|
|
}
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
|
|
|
pc.val=*NEXT_PC;
|
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 67: __reserved_clui */
|
|
|
|
compile_ret_t ____reserved_clui(virt_addr_t& pc, code_word_t instr){
|
|
|
|
// pre execution stuff
|
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
2021-03-07 11:51:00 +01:00
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
2021-06-29 11:51:19 +02:00
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 67);
|
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "__reserved_clui");
|
|
|
|
|
|
|
|
}
|
|
|
|
// used registers// calculate next pc value
|
|
|
|
*NEXT_PC = *PC + 2;
|
|
|
|
// execute instruction
|
|
|
|
try {
|
|
|
|
raise(0, 2);
|
|
|
|
} catch(...){}
|
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 67);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 68: CSRLI */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __csrli(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 68);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t shamt = ((bit_sub<2,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "csrli"),
|
|
|
|
fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t rs1_idx = rs1 + 8;
|
|
|
|
*(X+rs1_idx) = *(X+rs1_idx) >> shamt;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 68);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 69: CSRAI */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __csrai(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 69);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t shamt = ((bit_sub<2,5>(instr)));
|
|
|
|
uint8_t rs1 = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "csrai"),
|
|
|
|
fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
if(shamt) {
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t rs1_idx = rs1 + 8;
|
|
|
|
*(X+rs1_idx) = ((int32_t)*(X+rs1_idx)) >> shamt;
|
2021-03-07 11:51:00 +01:00
|
|
|
}
|
|
|
|
else if(traits::XLEN == 128) {
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t rs1_idx = rs1 + 8;
|
|
|
|
*(X+rs1_idx) = ((int32_t)*(X+rs1_idx)) >> 64;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 69);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 70: CANDI */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __candi(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 70);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint8_t imm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "candi"),
|
|
|
|
fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t rs1_idx = rs1 + 8;
|
|
|
|
*(X+rs1_idx) = *(X+rs1_idx) & (int8_t)sext<6>(imm);
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 70);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 71: CSUB */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __csub(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 71);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs2 = ((bit_sub<2,3>(instr)));
|
|
|
|
uint8_t rd = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "csub"),
|
|
|
|
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t rd_idx = rd + 8;
|
|
|
|
*(X+rd_idx) = *(X+rd_idx) - *(X+(rs2 + 8));
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 71);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 72: CXOR */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cxor(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 72);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs2 = ((bit_sub<2,3>(instr)));
|
|
|
|
uint8_t rd = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "cxor"),
|
|
|
|
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t rd_idx = rd + 8;
|
|
|
|
*(X+rd_idx) = *(X+rd_idx) ^ *(X+(rs2 + 8));
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 72);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 73: COR */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cor(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 73);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs2 = ((bit_sub<2,3>(instr)));
|
|
|
|
uint8_t rd = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "cor"),
|
|
|
|
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t rd_idx = rd + 8;
|
|
|
|
*(X+rd_idx) = *(X+rd_idx) | *(X+(rs2 + 8));
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 73);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 74: CAND */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cand(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 74);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs2 = ((bit_sub<2,3>(instr)));
|
|
|
|
uint8_t rd = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "cand"),
|
|
|
|
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t rd_idx = rd + 8;
|
|
|
|
*(X+rd_idx) = *(X+rd_idx) & *(X+(rs2 + 8));
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 74);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 75: CJ */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cj(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 75);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,3>(instr) << 1) | (bit_sub<6,1>(instr) << 7) | (bit_sub<7,1>(instr) << 6) | (bit_sub<8,1>(instr) << 10) | (bit_sub<9,2>(instr) << 8) | (bit_sub<11,1>(instr) << 4) | (bit_sub<12,1>(instr) << 11));
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "cj"),
|
|
|
|
fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
pc_assign(*NEXT_PC) = *PC + (int16_t)sext<12>(imm);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 75);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 76: CBEQZ */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cbeqz(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 76);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,2>(instr) << 1) | (bit_sub<5,2>(instr) << 6) | (bit_sub<10,2>(instr) << 3) | (bit_sub<12,1>(instr) << 8));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "cbeqz"),
|
|
|
|
fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
if(*(X+(rs1 + 8)) == 0) pc_assign(*NEXT_PC) = *PC + (int16_t)sext<9>(imm);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 76);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 77: CBNEZ */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cbnez(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 77);
|
2021-03-01 22:07:20 +01:00
|
|
|
uint16_t imm = ((bit_sub<2,1>(instr) << 5) | (bit_sub<3,2>(instr) << 1) | (bit_sub<5,2>(instr) << 6) | (bit_sub<10,2>(instr) << 3) | (bit_sub<12,1>(instr) << 8));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<7,3>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "cbnez"),
|
|
|
|
fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-09 11:21:36 +01:00
|
|
|
if(*(X+(rs1 + 8)) != 0) pc_assign(*NEXT_PC) = *PC + (int16_t)sext<9>(imm);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 77);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 78: CSLLI */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cslli(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 78);
|
2021-03-07 11:51:00 +01:00
|
|
|
uint8_t nzuimm = ((bit_sub<2,5>(instr)));
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
2021-03-07 11:51:00 +01:00
|
|
|
"{mnemonic:10} {rs1}, {nzuimm}", fmt::arg("mnemonic", "cslli"),
|
|
|
|
fmt::arg("rs1", name(rs1)), fmt::arg("nzuimm", nzuimm));
|
2021-02-06 15:47:06 +01:00
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
if(nzuimm) *(X+rs1) = *(X+rs1) << nzuimm;
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 78);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 79: CLWSP */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __clwsp(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 79);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t uimm = ((bit_sub<2,2>(instr) << 6) | (bit_sub<4,3>(instr) << 2) | (bit_sub<12,1>(instr) << 5));
|
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, sp, {uimm:#05x}", fmt::arg("mnemonic", "clwsp"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("uimm", uimm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
if(rd) {
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t offs = *(X+2) + uimm;
|
2021-07-06 21:19:36 +02:00
|
|
|
*(X+rd) = (int32_t)readSpace4(traits::MEM, offs);
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-03-07 11:51:00 +01:00
|
|
|
else raise(0, 2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 79);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 80: CMV */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cmv(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 80);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs2 = ((bit_sub<2,5>(instr)));
|
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "cmv"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-06-29 11:51:19 +02:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rs2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 80);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 81: CJR */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cjr(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 81);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}", fmt::arg("mnemonic", "cjr"),
|
|
|
|
fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-06-29 11:51:19 +02:00
|
|
|
if(rs1) pc_assign(*NEXT_PC) = *(X+rs1) & ~ 0x1;
|
2021-03-07 11:51:00 +01:00
|
|
|
else raise(0, 2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 81);
|
|
|
|
// trap check
|
|
|
|
if(*trap_state!=0){
|
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
|
|
|
}
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
|
|
|
pc.val=*NEXT_PC;
|
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* instruction 82: __reserved_cmv */
|
|
|
|
compile_ret_t ____reserved_cmv(virt_addr_t& pc, code_word_t instr){
|
|
|
|
// pre execution stuff
|
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
2021-03-07 11:51:00 +01:00
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
2021-06-29 11:51:19 +02:00
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 82);
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "__reserved_cmv");
|
|
|
|
|
|
|
|
}
|
|
|
|
// used registers// calculate next pc value
|
|
|
|
*NEXT_PC = *PC + 2;
|
|
|
|
// execute instruction
|
|
|
|
try {
|
|
|
|
raise(0, 2);
|
|
|
|
} catch(...){}
|
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 82);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 83: CADD */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cadd(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 83);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs2 = ((bit_sub<2,5>(instr)));
|
|
|
|
uint8_t rd = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "cadd"),
|
|
|
|
fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-06-29 11:51:19 +02:00
|
|
|
if(rd != 0) *(X+rd) = *(X+rd) + *(X+rs2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 83);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 84: CJALR */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cjalr(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 84);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs1 = ((bit_sub<7,5>(instr)));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs1}", fmt::arg("mnemonic", "cjalr"),
|
|
|
|
fmt::arg("rs1", name(rs1)));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-06-29 11:51:19 +02:00
|
|
|
int32_t new_pc = *(X+rs1);
|
2021-03-13 11:19:30 +01:00
|
|
|
*(X+1) = *PC + 2;
|
2021-06-29 11:51:19 +02:00
|
|
|
pc_assign(*NEXT_PC) = new_pc & ~ 0x1;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 84);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 85: CEBREAK */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cebreak(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 85);
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "cebreak");
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
raise(0, 3);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 85);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-12-29 09:48:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 86: CSWSP */
|
2020-12-29 09:48:22 +01:00
|
|
|
compile_ret_t __cswsp(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 86);
|
2021-02-06 15:47:06 +01:00
|
|
|
uint8_t rs2 = ((bit_sub<2,5>(instr)));
|
|
|
|
uint8_t uimm = ((bit_sub<7,2>(instr) << 6) | (bit_sub<9,4>(instr) << 2));
|
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
auto mnemonic = fmt::format(
|
|
|
|
"{mnemonic:10} {rs2}, {uimm:#05x}(sp)", fmt::arg("mnemonic", "cswsp"),
|
|
|
|
fmt::arg("rs2", name(rs2)), fmt::arg("uimm", uimm));
|
|
|
|
this->core.disass_output(pc.val, mnemonic);
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* X = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::X0]);// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-02-06 15:47:06 +01:00
|
|
|
{
|
2021-03-13 11:19:30 +01:00
|
|
|
uint32_t offs = *(X+2) + uimm;
|
2021-07-06 21:19:36 +02:00
|
|
|
writeSpace4(traits::MEM, offs, (uint32_t)*(X+rs2));
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 86);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2021-06-29 11:51:19 +02:00
|
|
|
/* instruction 87: DII */
|
2020-01-12 18:19:48 +01:00
|
|
|
compile_ret_t __dii(virt_addr_t& pc, code_word_t instr){
|
2021-02-06 15:47:06 +01:00
|
|
|
// pre execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
auto NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*PC=*NEXT_PC;
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
*trap_state = *reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PENDING_TRAP]);
|
|
|
|
if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, 87);
|
2021-02-06 15:47:06 +01:00
|
|
|
if(this->disass_enabled){
|
|
|
|
/* generate console output when executing the command */
|
|
|
|
this->core.disass_output(pc.val, "dii");
|
|
|
|
|
|
|
|
}
|
2021-03-26 09:23:47 +01:00
|
|
|
// used registers// calculate next pc value
|
2021-03-01 07:26:33 +01:00
|
|
|
*NEXT_PC = *PC + 2;
|
2021-02-06 15:47:06 +01:00
|
|
|
// execute instruction
|
2021-06-07 22:22:36 +02:00
|
|
|
try {
|
2021-03-07 11:51:00 +01:00
|
|
|
raise(0, 2);
|
2021-06-07 22:22:36 +02:00
|
|
|
} catch(...){}
|
2021-02-06 15:47:06 +01:00
|
|
|
// post execution stuff
|
2021-06-29 11:51:19 +02:00
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, 87);
|
2021-02-06 15:47:06 +01:00
|
|
|
// trap check
|
2021-03-07 11:51:00 +01:00
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
|
|
|
} else {
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++;
|
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++;
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-06-29 11:51:19 +02:00
|
|
|
(*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++;
|
2021-03-07 11:51:00 +01:00
|
|
|
pc.val=*NEXT_PC;
|
2021-02-06 15:47:06 +01:00
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* end opcode definitions
|
|
|
|
****************************************************************************/
|
|
|
|
compile_ret_t illegal_intruction(virt_addr_t &pc, code_word_t instr) {
|
2021-03-07 11:51:00 +01:00
|
|
|
this->do_sync(PRE_SYNC, static_cast<unsigned>(arch::traits<ARCH>::opcode_e::MAX_OPCODE));
|
|
|
|
uint32_t* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]);
|
|
|
|
uint32_t* NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]);
|
|
|
|
*NEXT_PC = *PC + ((instr & 3) == 3 ? 4 : 2);
|
2021-06-07 22:22:36 +02:00
|
|
|
raise(0, 2);
|
2021-03-07 11:51:00 +01:00
|
|
|
// post execution stuff
|
|
|
|
if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, static_cast<unsigned>(arch::traits<ARCH>::opcode_e::MAX_OPCODE));
|
|
|
|
auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]);
|
|
|
|
// trap check
|
|
|
|
if(*trap_state!=0){
|
2021-06-29 11:51:19 +02:00
|
|
|
super::core.enter_trap(*trap_state, pc.val, instr);
|
2021-03-07 11:51:00 +01:00
|
|
|
}
|
|
|
|
pc.val=*NEXT_PC;
|
2020-01-10 07:24:00 +01:00
|
|
|
return pc;
|
|
|
|
}
|
2021-03-06 08:17:42 +01:00
|
|
|
|
2021-10-17 12:25:13 +02:00
|
|
|
//static constexpr typename traits::addr_t upper_bits = ~traits::PGMASK;
|
2021-03-06 08:17:42 +01:00
|
|
|
iss::status fetch_ins(virt_addr_t pc, uint8_t * data){
|
|
|
|
auto phys_pc = this->core.v2p(pc);
|
2021-03-13 11:19:30 +01:00
|
|
|
//if ((pc.val & upper_bits) != ((pc.val + 2) & upper_bits)) { // we may cross a page boundary
|
|
|
|
// if (this->core.read(phys_pc, 2, data) != iss::Ok) return iss::Err;
|
|
|
|
// if ((data[0] & 0x3) == 0x3) // this is a 32bit instruction
|
|
|
|
// if (this->core.read(this->core.v2p(pc + 2), 2, data + 2) != iss::Ok) return iss::Err;
|
|
|
|
//} else {
|
2021-03-06 08:17:42 +01:00
|
|
|
if (this->core.read(phys_pc, 4, data) != iss::Ok) return iss::Err;
|
2021-03-13 11:19:30 +01:00
|
|
|
//}
|
2021-03-06 08:17:42 +01:00
|
|
|
return iss::Ok;
|
|
|
|
}
|
2020-01-10 07:24:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename CODE_WORD> void debug_fn(CODE_WORD insn) {
|
|
|
|
volatile CODE_WORD x = insn;
|
|
|
|
insn = 2 * x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ARCH> vm_impl<ARCH>::vm_impl() { this(new ARCH()); }
|
|
|
|
|
2021-07-09 07:37:12 +02:00
|
|
|
// according to
|
|
|
|
// https://stackoverflow.com/questions/8871204/count-number-of-1s-in-binary-representation
|
|
|
|
#ifdef __GCC__
|
|
|
|
constexpr size_t bit_count(uint32_t u) { return __builtin_popcount(u); }
|
|
|
|
#elif __cplusplus < 201402L
|
|
|
|
constexpr size_t uCount(uint32_t u) { return u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111); }
|
|
|
|
constexpr size_t bit_count(uint32_t u) { return ((uCount(u) + (uCount(u) >> 3)) & 030707070707) % 63; }
|
|
|
|
#else
|
|
|
|
constexpr size_t bit_count(uint32_t u) {
|
|
|
|
size_t uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111);
|
|
|
|
return ((uCount + (uCount >> 3)) & 030707070707) % 63;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-01-10 07:24:00 +01:00
|
|
|
template <typename ARCH>
|
|
|
|
vm_impl<ARCH>::vm_impl(ARCH &core, unsigned core_id, unsigned cluster_id)
|
2020-01-10 09:37:48 +01:00
|
|
|
: vm_base<ARCH>(core, core_id, cluster_id) {
|
2020-01-10 07:24:00 +01:00
|
|
|
for (auto instr : instr_descr) {
|
2021-07-09 07:37:12 +02:00
|
|
|
auto quadrant = instr.value & 0x3;
|
|
|
|
qlut[quadrant].push_back(instruction_pattern{instr.value, instr.mask, instr.op});
|
|
|
|
}
|
|
|
|
for(auto& lut: qlut){
|
|
|
|
std::sort(std::begin(lut), std::end(lut), [](instruction_pattern const& a, instruction_pattern const& b){
|
|
|
|
return bit_count(a.mask) > bit_count(b.mask);
|
|
|
|
});
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-22 23:47:30 +01:00
|
|
|
inline bool is_count_limit_enabled(finish_cond_e cond){
|
|
|
|
return (cond & finish_cond_e::COUNT_LIMIT) == finish_cond_e::COUNT_LIMIT;
|
|
|
|
}
|
2021-07-09 07:37:12 +02:00
|
|
|
|
2021-08-14 10:57:36 +02:00
|
|
|
inline bool is_jump_to_self_enabled(finish_cond_e cond){
|
|
|
|
return (cond & finish_cond_e::JUMP_TO_SELF) == finish_cond_e::JUMP_TO_SELF;
|
|
|
|
}
|
|
|
|
|
2021-07-09 07:37:12 +02:00
|
|
|
template <typename ARCH>
|
|
|
|
typename vm_impl<ARCH>::compile_func vm_impl<ARCH>::decode_inst(code_word_t instr){
|
|
|
|
for(auto& e: qlut[instr&0x3]){
|
|
|
|
if(!((instr&e.mask) ^ e.value )) return e.opc;
|
|
|
|
}
|
|
|
|
return &this_class::illegal_intruction;
|
|
|
|
}
|
|
|
|
|
2020-01-10 07:24:00 +01:00
|
|
|
template <typename ARCH>
|
2021-03-17 20:32:57 +01:00
|
|
|
typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e cond, virt_addr_t start, uint64_t icount_limit){
|
2020-01-10 07:24:00 +01:00
|
|
|
// we fetch at max 4 byte, alignment is 2
|
2020-01-12 18:19:48 +01:00
|
|
|
code_word_t insn = 0;
|
2020-01-10 07:24:00 +01:00
|
|
|
auto *const data = (uint8_t *)&insn;
|
2020-01-12 18:19:48 +01:00
|
|
|
auto pc=start;
|
2021-03-17 20:32:57 +01:00
|
|
|
while(!this->core.should_stop() &&
|
2021-03-22 23:47:30 +01:00
|
|
|
!(is_count_limit_enabled(cond) && this->core.get_icount() >= icount_limit)){
|
2021-03-06 08:17:42 +01:00
|
|
|
auto res = fetch_ins(pc, data);
|
|
|
|
if(res!=iss::Ok){
|
2021-08-14 10:57:36 +02:00
|
|
|
this->do_sync(POST_SYNC, std::numeric_limits<unsigned>::max());
|
|
|
|
pc.val = super::core.enter_trap(std::numeric_limits<uint64_t>::max(), pc.val, 0);
|
|
|
|
} else {
|
2021-09-18 11:40:00 +02:00
|
|
|
if (is_jump_to_self_enabled(cond) &&
|
|
|
|
(insn == 0x0000006f || (insn&0xffff)==0xa001)) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
|
2021-08-14 10:57:36 +02:00
|
|
|
auto f = decode_inst(insn);
|
2021-09-23 21:09:36 +02:00
|
|
|
auto old_pc = pc.val;
|
2021-08-14 10:57:36 +02:00
|
|
|
pc = (this->*f)(pc, insn);
|
|
|
|
}
|
2020-01-12 18:19:48 +01:00
|
|
|
}
|
|
|
|
return pc;
|
2020-01-10 07:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mnrv32
|
|
|
|
|
|
|
|
template <>
|
2021-05-13 15:38:33 +02:00
|
|
|
std::unique_ptr<vm_if> create<arch::tgc_c>(arch::tgc_c *core, unsigned short port, bool dump) {
|
|
|
|
auto ret = new tgc_c::vm_impl<arch::tgc_c>(*core, dump);
|
2020-01-10 07:24:00 +01:00
|
|
|
if (port != 0) debugger::server<debugger::gdb_session>::run_server(ret, port);
|
|
|
|
return std::unique_ptr<vm_if>(ret);
|
|
|
|
}
|
2020-01-10 09:37:48 +01:00
|
|
|
} // namespace interp
|
2020-01-10 07:24:00 +01:00
|
|
|
} // namespace iss
|