2018-11-19 10:45:50 +01:00
|
|
|
/*******************************************************************************
|
2020-12-30 08:29:52 +01:00
|
|
|
* Copyright (C) 2017 - 2020 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-02-06 15:47:06 +01:00
|
|
|
<%
|
|
|
|
def getRegisterSizes(){
|
|
|
|
def regs = registers.collect{it.size}
|
|
|
|
regs[-1]=pc.size // correct for NEXT_PC
|
|
|
|
regs+=[32, 32, 32, 32, 64] // append TRAP_STATE, PENDING_TRAP, MACHINE_STATE, LAST_BRANCH, ICOUNT
|
|
|
|
return regs
|
|
|
|
}
|
|
|
|
def getRegisterOffsets(){
|
|
|
|
def regs = registers.collect{it.offset}
|
|
|
|
def offs= regs[-1]
|
|
|
|
// append TRAP_STATE, PENDING_TRAP, MACHINE_STATE, LAST_BRANCH, ICOUNT offsets starting with NEXT_PC size
|
|
|
|
[pc.size/8, 4, 4, 4, 4].each{ sz ->
|
|
|
|
regs+=offs+sz
|
|
|
|
offs+=sz
|
|
|
|
}
|
|
|
|
return regs
|
|
|
|
}
|
|
|
|
%>
|
2018-02-09 19:34:26 +01:00
|
|
|
#ifndef _${coreDef.name.toUpperCase()}_H_
|
|
|
|
#define _${coreDef.name.toUpperCase()}_H_
|
|
|
|
|
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
|
|
|
|
2018-02-11 22:23:26 +01:00
|
|
|
constexpr static char const* const core_type = "${coreDef.name}";
|
|
|
|
|
2020-12-29 09:48:22 +01:00
|
|
|
static constexpr std::array<const char*, ${registers.size}> reg_names{
|
|
|
|
{"${registers.collect{it.name}.join('", "')}"}};
|
2018-11-24 20:29:24 +01:00
|
|
|
|
2020-12-29 09:48:22 +01:00
|
|
|
static constexpr std::array<const char*, ${registers.size}> reg_aliases{
|
|
|
|
{"${registers.collect{it.alias}.join('", "')}"}};
|
2018-11-24 20:29:24 +01:00
|
|
|
|
2020-12-29 09:48:22 +01:00
|
|
|
enum constants {${constants.collect{c -> c.name+"="+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
|
|
|
|
2018-02-09 19:34:26 +01:00
|
|
|
enum reg_e {<%
|
2020-12-29 09:48:22 +01:00
|
|
|
registers.each { reg -> %>
|
2018-11-24 20:29:24 +01:00
|
|
|
${reg.name},<%
|
2018-02-09 19:34:26 +01:00
|
|
|
}%>
|
|
|
|
NEXT_${pc.name}=NUM_REGS,
|
|
|
|
TRAP_STATE,
|
|
|
|
PENDING_TRAP,
|
|
|
|
MACHINE_STATE,
|
2018-05-15 18:49:29 +02:00
|
|
|
LAST_BRANCH,
|
2020-12-29 09:48:22 +01:00
|
|
|
ICOUNT
|
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>;
|
|
|
|
|
2021-02-06 15:47:06 +01:00
|
|
|
static constexpr std::array<const uint32_t, ${getRegisterSizes().size}> reg_bit_widths{
|
|
|
|
{${getRegisterSizes().join(',')}}};
|
2018-02-09 19:34:26 +01:00
|
|
|
|
2021-02-06 15:47:06 +01:00
|
|
|
static constexpr std::array<const uint32_t, ${getRegisterOffsets().size}> reg_byte_offsets{
|
|
|
|
{${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
|
|
|
|
2020-12-29 09:48:22 +01:00
|
|
|
enum mem_type_e { ${spaces.collect{it.name}.join(', ')} };
|
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;
|
|
|
|
/// deprecated
|
|
|
|
void get_reg(short idx, std::vector<uint8_t>& value) override {}
|
|
|
|
void set_reg(short idx, const std::vector<uint8_t>& value) override {}
|
|
|
|
/// deprecated
|
|
|
|
bool get_flag(int flag) override {return false;}
|
|
|
|
void set_flag(int, bool value) override {};
|
|
|
|
/// deprecated
|
|
|
|
void update_flags(operations op, uint64_t opr1, uint64_t opr2) override {};
|
|
|
|
|
2018-11-19 10:45:50 +01:00
|
|
|
inline uint64_t get_icount() { return reg.icount; }
|
|
|
|
|
|
|
|
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
|
|
|
inline phys_addr_t v2p(const iss::addr_t& addr){
|
2018-11-19 10:45:50 +01:00
|
|
|
if (addr.space != traits<${coreDef.name.toLowerCase()}>::MEM || addr.type == iss::address_type::PHYSICAL ||
|
|
|
|
addr_mode[static_cast<uint16_t>(addr.access)&0x3]==address_type::PHYSICAL) {
|
2018-02-09 19:34:26 +01:00
|
|
|
return phys_addr_t(addr.access, addr.space, addr.val&traits<${coreDef.name.toLowerCase()}>::addr_mask);
|
|
|
|
} else
|
|
|
|
return virt2phys(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual phys_addr_t virt2phys(const iss::addr_t& addr);
|
|
|
|
|
|
|
|
virtual iss::sync_type needed_sync() const { return iss::NO_SYNC; }
|
|
|
|
|
2018-11-19 10:45:50 +01:00
|
|
|
inline uint32_t get_last_branch() { return reg.last_branch; }
|
2018-05-15 18:49:29 +02:00
|
|
|
|
2018-02-09 19:34:26 +01:00
|
|
|
protected:
|
|
|
|
struct ${coreDef.name}_regs {<%
|
2021-02-06 15:47:06 +01:00
|
|
|
registers.each { reg -> if(reg.size>0) {%>
|
2020-12-29 09:48:22 +01:00
|
|
|
uint${reg.size}_t ${reg.name} = 0;<%
|
2021-02-06 15:47:06 +01:00
|
|
|
}}%>
|
2020-12-29 09:48:22 +01:00
|
|
|
uint${pc.size}_t NEXT_${pc.name} = 0;
|
2018-05-15 18:49:29 +02:00
|
|
|
uint32_t trap_state = 0, pending_trap = 0, machine_state = 0, last_branch = 0;
|
2018-02-09 19:34:26 +01:00
|
|
|
uint64_t icount = 0;
|
|
|
|
} reg;
|
|
|
|
|
|
|
|
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) {%>
|
2020-12-29 09:48:22 +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 { %>
|
|
|
|
uint32_t get_fcsr(){return 0;}
|
|
|
|
void set_fcsr(uint32_t val){}
|
|
|
|
<%}%>
|
2018-02-09 19:34:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* _${coreDef.name.toUpperCase()}_H_ */
|