risc-v-tlm/inc/CPU.h

125 lines
2.5 KiB
C
Raw Normal View History

2018-09-11 00:44:54 +08:00
/*!
\file CPU.h
\brief Main CPU class
\author Màrius Montón
\date August 2018
*/
// SPDX-License-Identifier: GPL-3.0-or-later
2018-09-11 00:44:54 +08:00
#ifndef CPU_BASE_H
#define CPU_BASE_H
#define SC_INCLUDE_DYNAMIC_PROCESSES
#include "systemc"
#include "tlm.h"
#include "tlm_utils/simple_initiator_socket.h"
#include "tlm_utils/tlm_quantumkeeper.h"
2018-09-11 00:44:54 +08:00
#include "memory.h"
#include "MemoryInterface.h"
#include "BASE_ISA.h"
2018-09-11 00:44:54 +08:00
#include "Registers.h"
2018-10-15 19:51:41 +08:00
#include "Instruction.h"
#include "C_extension.h"
#include "M_extension.h"
#include "A_extension.h"
2018-09-11 00:44:54 +08:00
/**
* @brief ISC_V CPU model
* @param name name of the module
*/
class CPU: sc_core::sc_module {
2018-09-11 00:44:54 +08:00
public:
/**
* @brief Instruction Memory bus socket
* @param trans transction to perfoem
* @param delay time to annotate
*/
tlm_utils::simple_initiator_socket<CPU> instr_bus;
/**
* @brief IRQ line socket
* @param trans transction to perform (empty)
* @param delay time to annotate
*/
tlm_utils::simple_target_socket<CPU> irq_line_socket;
/**
* @brief Constructor
* @param name Module name
* @param PC Program Counter initialize value
2021-02-21 20:48:41 +08:00
* @param debug To start debugging
*/
CPU(sc_core::sc_module_name const &name, std::uint32_t PC, bool debug);
/**
* @brief Destructor
*/
2021-04-26 01:52:12 +08:00
~CPU() override;
MemoryInterface *mem_intf;
2021-04-26 01:52:12 +08:00
bool CPU_step();
2021-02-21 20:48:41 +08:00
Registers *getRegisterBank() {return register_bank;}
2018-09-11 00:44:54 +08:00
private:
Registers *register_bank;
Performance *perf;
2021-11-25 19:11:18 +08:00
std::shared_ptr<spdlog::logger> logger;
C_extension *c_inst;
M_extension *m_inst;
A_extension *a_inst;
BASE_ISA *exec;
tlm_utils::tlm_quantumkeeper *m_qk;
2021-11-16 17:26:42 +08:00
Instruction inst;
bool interrupt;
std::uint32_t int_cause;
bool irq_already_down;
sc_core::sc_time default_time;
bool dmi_ptr_valid;
2021-02-21 20:48:41 +08:00
tlm::tlm_generic_payload trans;
std::uint32_t INSTR;
2021-02-21 20:48:41 +08:00
unsigned char *dmi_ptr = nullptr;
/**
*
* @brief Process and triggers IRQ if all conditions met
* @return true if IRQ is triggered, false otherwise
*/
bool cpu_process_IRQ();
/**
* main thread for CPU simulation
* @brief CPU mai thread
*/
2021-04-26 01:52:12 +08:00
[[noreturn]] void CPU_thread();
/**
* @brief callback for IRQ simple socket
* @param trans transaction to perform (empty)
* @param delay time to annotate
*
* it triggers an IRQ when called
*/
void call_interrupt(tlm::tlm_generic_payload &trans,
sc_core::sc_time &delay);
/**
* DMI pointer is not longer valid
* @param start memory address region start
* @param end memory address region end
*/
void invalidate_direct_mem_ptr(sc_dt::uint64 start, sc_dt::uint64 end);
2018-09-11 00:44:54 +08:00
};
#endif