2018-09-11 00:44:54 +08:00
|
|
|
/*!
|
2020-06-02 19:08:38 +08:00
|
|
|
\file Memory.h
|
|
|
|
\brief Basic TLM-2 memory model
|
|
|
|
\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 __MEMORY_H__
|
|
|
|
#define __MEMORY_H__
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#define SC_INCLUDE_DYNAMIC_PROCESSES
|
|
|
|
|
|
|
|
#include "systemc"
|
|
|
|
|
|
|
|
#include "tlm.h"
|
|
|
|
#include "tlm_utils/simple_target_socket.h"
|
|
|
|
|
2021-11-25 19:11:18 +08:00
|
|
|
#include "spdlog/spdlog.h"
|
|
|
|
#include "spdlog/sinks/basic_file_sink.h"
|
2018-09-11 00:44:54 +08:00
|
|
|
/**
|
2020-05-28 23:18:50 +08:00
|
|
|
* @brief Basic TLM-2 memory
|
2018-09-11 00:44:54 +08:00
|
|
|
*/
|
2020-06-02 19:08:38 +08:00
|
|
|
class Memory: sc_core::sc_module {
|
2018-09-11 00:44:54 +08:00
|
|
|
public:
|
2020-06-02 19:08:38 +08:00
|
|
|
// TLM-2 socket, defaults to 32-bits wide, base protocol
|
|
|
|
tlm_utils::simple_target_socket<Memory> socket;
|
|
|
|
|
2021-11-16 17:20:59 +08:00
|
|
|
/* 16 MBytes */
|
2020-06-02 19:08:38 +08:00
|
|
|
enum {
|
2021-11-16 17:20:59 +08:00
|
|
|
SIZE = 0x1000000
|
2020-06-02 19:08:38 +08:00
|
|
|
};
|
|
|
|
const sc_core::sc_time LATENCY;
|
|
|
|
|
2021-01-23 18:44:10 +08:00
|
|
|
Memory(sc_core::sc_module_name const &name, std::string const &filename);
|
2021-04-26 01:52:12 +08:00
|
|
|
explicit Memory(const sc_core::sc_module_name& name);
|
2020-06-02 19:08:38 +08:00
|
|
|
|
2021-04-26 01:52:12 +08:00
|
|
|
~Memory() override;
|
2020-06-02 19:08:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns Program Counter read from hexfile
|
|
|
|
* @return Initial PC
|
|
|
|
*/
|
2021-11-12 00:10:23 +08:00
|
|
|
virtual std::uint32_t getPCfromHEX();
|
2020-06-02 19:08:38 +08:00
|
|
|
|
|
|
|
// TLM-2 blocking transport method
|
|
|
|
virtual void b_transport(tlm::tlm_generic_payload &trans,
|
|
|
|
sc_core::sc_time &delay);
|
|
|
|
|
|
|
|
// *********************************************
|
|
|
|
// TLM-2 forward DMI method
|
|
|
|
// *********************************************
|
|
|
|
virtual bool get_direct_mem_ptr(tlm::tlm_generic_payload &trans,
|
|
|
|
tlm::tlm_dmi &dmi_data);
|
|
|
|
|
|
|
|
// *********************************************
|
|
|
|
// TLM-2 debug transport method
|
|
|
|
// *********************************************
|
|
|
|
virtual unsigned int transport_dbg(tlm::tlm_generic_payload &trans);
|
2018-09-11 00:44:54 +08:00
|
|
|
|
2018-09-20 05:44:38 +08:00
|
|
|
private:
|
2018-09-21 15:24:49 +08:00
|
|
|
|
2020-06-02 19:08:38 +08:00
|
|
|
/**
|
|
|
|
* @brief Memory array in bytes
|
|
|
|
*/
|
2021-11-09 18:15:36 +08:00
|
|
|
std::array<uint8_t, Memory::SIZE> mem{};
|
2020-06-02 19:08:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Log class
|
|
|
|
*/
|
2021-11-25 19:11:18 +08:00
|
|
|
std::shared_ptr<spdlog::logger> logger;
|
2020-06-02 19:08:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Program counter (PC) read from hex file
|
|
|
|
*/
|
2021-11-12 00:10:23 +08:00
|
|
|
std::uint32_t program_counter;
|
2020-06-02 19:08:38 +08:00
|
|
|
|
2021-11-16 17:20:59 +08:00
|
|
|
/**
|
|
|
|
* @brief DMI can be used?
|
|
|
|
*/
|
|
|
|
bool dmi_allowed;
|
|
|
|
|
2020-06-02 19:08:38 +08:00
|
|
|
/**
|
|
|
|
* @brief Read Intel hex file
|
|
|
|
* @param filename file name to read
|
|
|
|
*/
|
2021-01-23 18:44:10 +08:00
|
|
|
void readHexFile(const std::string& filename);
|
2018-09-11 00:44:54 +08:00
|
|
|
};
|
2020-06-02 19:08:38 +08:00
|
|
|
#endif /* __MEMORY_H__ */
|