2018-11-19 10:45:50 +01:00
|
|
|
/*******************************************************************************
|
2021-03-01 07:26:33 +01:00
|
|
|
* Copyright (C) 2017 - 2021 MINRES Technologies GmbH
|
2018-11-19 10:45:50 +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-03-01 07:26:33 +01:00
|
|
|
<%
|
|
|
|
def nativeTypeSize(int size){
|
|
|
|
if(size<=8) return 8; else if(size<=16) return 16; else if(size<=32) return 32; else return 64;
|
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
def getRegisterSizes(){
|
2021-03-01 07:26:33 +01:00
|
|
|
def regs = registers.collect{nativeTypeSize(it.size)}
|
2023-05-14 17:16:42 +02:00
|
|
|
regs+=[32,32, 64, 64, 64, 32, 32] // append TRAP_STATE, PENDING_TRAP, ICOUNT, CYCLE, INSTRET, INSTRUCTION, LAST_BRANCH
|
2021-02-06 15:47:06 +01:00
|
|
|
return regs
|
|
|
|
}
|
|
|
|
def getRegisterOffsets(){
|
2021-03-01 07:26:33 +01:00
|
|
|
def offset = 0
|
|
|
|
def offsets = []
|
|
|
|
getRegisterSizes().each { size ->
|
|
|
|
offsets<<offset
|
|
|
|
offset+=size/8
|
2021-02-23 09:29:12 +01:00
|
|
|
}
|
2021-03-01 07:26:33 +01:00
|
|
|
return offsets
|
2021-02-06 15:47:06 +01:00
|
|
|
}
|
2021-02-23 09:29:12 +01:00
|
|
|
def byteSize(int size){
|
|
|
|
if(size<=8) return 8;
|
|
|
|
if(size<=16) return 16;
|
|
|
|
if(size<=32) return 32;
|
|
|
|
if(size<=64) return 64;
|
|
|
|
return 128;
|
|
|
|
}
|
2021-03-01 22:07:20 +01:00
|
|
|
def getCString(def val){
|
2023-07-10 20:39:02 +02:00
|
|
|
return val.toString()+'ULL'
|
2021-03-01 22:07:20 +01:00
|
|
|
}
|
2021-02-06 15:47:06 +01:00
|
|
|
%>
|
2018-02-09 19:34:26 +01:00
|
|
|
#ifndef _${coreDef.name.toUpperCase()}_H_
|
|
|
|
#define _${coreDef.name.toUpperCase()}_H_
|
2023-11-05 17:19:43 +01:00
|
|
|
// clang-format off
|
2018-11-19 10:45:50 +01:00
|
|
|
#include <array>
|
|
|
|
#include <iss/arch/traits.h>
|
2018-02-09 19:34:26 +01:00
|
|
|
#include <iss/arch_if.h>
|
|
|
|
#include <iss/vm_if.h>
|
|
|
|
|
|
|
|
namespace iss {
|
|
|
|
namespace arch {
|
|
|
|
|
|
|
|
struct ${coreDef.name.toLowerCase()};
|
|
|
|
|
2018-11-19 10:45:50 +01:00
|
|
|
template <> struct traits<${coreDef.name.toLowerCase()}> {
|
2018-02-09 19:34:26 +01:00
|
|
|
|
2021-02-23 09:29:12 +01:00
|
|
|
constexpr static char const* const core_type = "${coreDef.name}";
|
2018-02-11 22:23:26 +01:00
|
|
|
|
2024-06-21 10:46:11 +02:00
|
|
|
static constexpr std::array<const char*, ${registers.size()}> reg_names{
|
2023-09-20 15:17:43 +02:00
|
|
|
{"${registers.collect{it.name.toLowerCase()}.join('", "')}"}};
|
2018-11-24 20:29:24 +01:00
|
|
|
|
2024-06-21 10:46:11 +02:00
|
|
|
static constexpr std::array<const char*, ${registers.size()}> reg_aliases{
|
2023-09-20 15:17:43 +02:00
|
|
|
{"${registers.collect{it.alias.toLowerCase()}.join('", "')}"}};
|
2018-11-24 20:29:24 +01:00
|
|
|
|
2021-03-01 22:07:20 +01:00
|
|
|
enum constants {${constants.collect{c -> c.name+"="+getCString(c.value)}.join(', ')}};
|
2018-02-09 19:34:26 +01:00
|
|
|
|
2020-12-29 09:48:22 +01:00
|
|
|
constexpr static unsigned FP_REGS_SIZE = ${constants.find {it.name=='FLEN'}?.value?:0};
|
2018-04-24 15:33:21 +02:00
|
|
|
|
2021-03-01 07:26:33 +01:00
|
|
|
enum reg_e {
|
2023-05-14 17:16:42 +02:00
|
|
|
${registers.collect{it.name}.join(', ')}, NUM_REGS, TRAP_STATE=NUM_REGS, PENDING_TRAP, ICOUNT, CYCLE, INSTRET, INSTRUCTION, LAST_BRANCH
|
2018-02-09 19:34:26 +01:00
|
|
|
};
|
|
|
|
|
2020-12-29 09:48:22 +01:00
|
|
|
using reg_t = uint${addrDataWidth}_t;
|
2018-02-09 19:34:26 +01:00
|
|
|
|
|
|
|
using addr_t = uint${addrDataWidth}_t;
|
|
|
|
|
2018-04-30 19:22:00 +02:00
|
|
|
using code_word_t = uint${addrDataWidth}_t; //TODO: check removal
|
|
|
|
|
2018-02-09 19:34:26 +01:00
|
|
|
using virt_addr_t = iss::typed_addr_t<iss::address_type::VIRTUAL>;
|
|
|
|
|
|
|
|
using phys_addr_t = iss::typed_addr_t<iss::address_type::PHYSICAL>;
|
|
|
|
|
2024-06-21 10:46:11 +02:00
|
|
|
static constexpr std::array<const uint32_t, ${getRegisterSizes().size()}> reg_bit_widths{
|
2021-02-23 09:29:12 +01:00
|
|
|
{${getRegisterSizes().join(',')}}};
|
2018-02-09 19:34:26 +01:00
|
|
|
|
2024-06-21 10:46:11 +02:00
|
|
|
static constexpr std::array<const uint32_t, ${getRegisterOffsets().size()}> reg_byte_offsets{
|
2021-02-23 09:29:12 +01:00
|
|
|
{${getRegisterOffsets().join(',')}}};
|
2018-11-19 10:45:50 +01:00
|
|
|
|
2018-02-09 19:34:26 +01:00
|
|
|
static const uint64_t addr_mask = (reg_t(1) << (XLEN - 1)) | ((reg_t(1) << (XLEN - 1)) - 1);
|
|
|
|
|
2018-11-19 10:45:50 +01:00
|
|
|
enum sreg_flag_e { FLAGS };
|
2018-02-09 19:34:26 +01:00
|
|
|
|
2024-02-21 07:08:24 +01:00
|
|
|
enum mem_type_e { ${spaces.collect{it.name}.join(', ')}, IMEM = MEM };
|
2021-02-23 09:29:12 +01:00
|
|
|
|
2023-07-06 08:02:48 +02:00
|
|
|
enum class opcode_e {<%instructions.eachWithIndex{instr, index -> %>
|
2021-02-23 09:29:12 +01:00
|
|
|
${instr.instruction.name} = ${index},<%}%>
|
|
|
|
MAX_OPCODE
|
|
|
|
};
|
2018-02-09 19:34:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ${coreDef.name.toLowerCase()}: public arch_if {
|
|
|
|
|
|
|
|
using virt_addr_t = typename traits<${coreDef.name.toLowerCase()}>::virt_addr_t;
|
|
|
|
using phys_addr_t = typename traits<${coreDef.name.toLowerCase()}>::phys_addr_t;
|
|
|
|
using reg_t = typename traits<${coreDef.name.toLowerCase()}>::reg_t;
|
|
|
|
using addr_t = typename traits<${coreDef.name.toLowerCase()}>::addr_t;
|
|
|
|
|
|
|
|
${coreDef.name.toLowerCase()}();
|
|
|
|
~${coreDef.name.toLowerCase()}();
|
|
|
|
|
|
|
|
void reset(uint64_t address=0) override;
|
|
|
|
|
|
|
|
uint8_t* get_regs_base_ptr() override;
|
|
|
|
|
2023-05-27 10:20:49 +02:00
|
|
|
inline uint64_t get_icount() { return reg.icount; }
|
2018-11-19 10:45:50 +01:00
|
|
|
|
|
|
|
inline bool should_stop() { return interrupt_sim; }
|
2018-02-09 19:34:26 +01:00
|
|
|
|
2020-05-30 11:27:44 +02:00
|
|
|
inline uint64_t stop_code() { return interrupt_sim; }
|
|
|
|
|
2018-02-09 19:34:26 +01:00
|
|
|
virtual phys_addr_t virt2phys(const iss::addr_t& addr);
|
|
|
|
|
|
|
|
virtual iss::sync_type needed_sync() const { return iss::NO_SYNC; }
|
|
|
|
|
2023-05-27 10:20:49 +02:00
|
|
|
inline uint32_t get_last_branch() { return reg.last_branch; }
|
2018-05-15 18:49:29 +02:00
|
|
|
|
2022-01-12 07:21:16 +01:00
|
|
|
|
2021-03-07 11:51:00 +01:00
|
|
|
#pragma pack(push, 1)
|
2018-02-09 19:34:26 +01:00
|
|
|
struct ${coreDef.name}_regs {<%
|
2021-02-23 09:29:12 +01:00
|
|
|
registers.each { reg -> if(reg.size>0) {%>
|
|
|
|
uint${byteSize(reg.size)}_t ${reg.name} = 0;<%
|
2021-02-06 15:47:06 +01:00
|
|
|
}}%>
|
2023-05-14 17:16:42 +02:00
|
|
|
uint32_t trap_state = 0, pending_trap = 0;
|
|
|
|
uint64_t icount = 0;
|
|
|
|
uint64_t cycle = 0;
|
|
|
|
uint64_t instret = 0;
|
|
|
|
uint32_t instruction = 0;
|
2023-05-14 17:00:37 +02:00
|
|
|
uint32_t last_branch = 0;
|
2018-02-09 19:34:26 +01:00
|
|
|
} reg;
|
2022-05-07 17:22:06 +02:00
|
|
|
#pragma pack(pop)
|
2018-02-09 19:34:26 +01:00
|
|
|
std::array<address_type, 4> addr_mode;
|
2018-04-24 11:05:11 +02:00
|
|
|
|
2020-05-30 11:27:44 +02:00
|
|
|
uint64_t interrupt_sim=0;
|
2018-04-24 11:05:11 +02:00
|
|
|
<%
|
2020-12-29 09:48:22 +01:00
|
|
|
def fcsr = registers.find {it.name=='FCSR'}
|
2018-04-24 11:05:11 +02:00
|
|
|
if(fcsr != null) {%>
|
2021-02-23 09:29:12 +01:00
|
|
|
uint${fcsr.size}_t get_fcsr(){return reg.FCSR;}
|
|
|
|
void set_fcsr(uint${fcsr.size}_t val){reg.FCSR = val;}
|
2018-04-24 11:05:11 +02:00
|
|
|
<%} else { %>
|
2021-02-23 09:29:12 +01:00
|
|
|
uint32_t get_fcsr(){return 0;}
|
|
|
|
void set_fcsr(uint32_t val){}
|
2018-04-24 11:05:11 +02:00
|
|
|
<%}%>
|
2018-02-09 19:34:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* _${coreDef.name.toUpperCase()}_H_ */
|
2023-11-05 17:19:43 +01:00
|
|
|
// clang-format on
|