risc-v-tlm/inc/extension_base.h

84 lines
1.8 KiB
C
Raw Normal View History

/*!
\file extension_base.h
\brief Base class for ISA extensions
\author Màrius Montón
\date May 2020
*/
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef INC_EXTENSION_BASE_H_
#define INC_EXTENSION_BASE_H_
#include "systemc"
#include "Instruction.h"
#include "Registers.h"
#include "Log.h"
#include "MemoryInterface.h"
#define EXCEPTION_CAUSE_INSTRUCTION_MISALIGN 0
#define EXCEPTION_CAUSE_INSTRUCTION_ACCESS 1
#define EXCEPTION_CAUSE_ILLEGAL_INSTRUCTION 2
#define EXCEPTION_CAUSE_BREAKPOINT 3
2021-11-08 16:24:43 +08:00
#define EXCEPTION_CAUSE_BREAK 3
#define EXCEPTION_CAUSE_LOAD_ADDR_MISALIGN 4
#define EXCEPTION_CAUSE_LOAD_ACCESS_FAULT 5
class extension_base {
public:
2021-04-26 06:20:29 +08:00
extension_base(const sc_dt::sc_uint<32> & instr, Registers *register_bank,
MemoryInterface *mem_interface);
virtual ~extension_base() = 0;
void setInstr(std::uint32_t p_instr);
void RaiseException(std::uint32_t cause, std::uint32_t inst);
bool NOP();
/* pure virtual functions */
virtual std::int32_t opcode() const = 0;
2021-02-01 19:24:25 +08:00
virtual std::int32_t get_rd() const {
2021-02-01 18:49:38 +08:00
return m_instr.range(11, 7);
}
2021-02-01 19:24:25 +08:00
virtual void set_rd(std::int32_t value) {
2021-02-01 18:49:38 +08:00
m_instr.range(11, 7) = value;
}
2021-02-01 19:24:25 +08:00
virtual std::int32_t get_rs1() const {
2021-02-01 19:24:25 +08:00
return m_instr.range(19, 15);
}
virtual void set_rs1(std::int32_t value) {
2021-02-01 19:24:25 +08:00
m_instr.range(19, 15) = value;
}
virtual std::int32_t get_rs2() const {
2021-02-01 19:24:25 +08:00
return m_instr.range(24, 20);
}
virtual void set_rs2(std::int32_t value) {
2021-02-01 19:24:25 +08:00
m_instr.range(24, 20) = value;
}
virtual std::int32_t get_funct3() const {
2021-02-01 19:24:25 +08:00
return m_instr.range(14, 12);
}
virtual void set_funct3(std::int32_t value) {
2021-02-01 19:24:25 +08:00
m_instr.range(14, 12) = value;
}
2021-02-01 18:25:04 +08:00
virtual void dump() const;
protected:
sc_dt::sc_uint<32> m_instr;
Registers *regs;
Performance *perf;
Log *log;
MemoryInterface *mem_intf;
};
#endif /* INC_EXTENSION_BASE_H_ */