Skip to content

Commit

Permalink
Merge branch 'main' into colby-nyce/ide-repl
Browse files Browse the repository at this point in the history
  • Loading branch information
colby-nyce authored Jan 22, 2025
2 parents edb93af + c8aac04 commit d420a6f
Show file tree
Hide file tree
Showing 11 changed files with 887 additions and 992 deletions.
7 changes: 5 additions & 2 deletions core/AtlasExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ namespace atlas
const Execute* execute_unit = state->getExecuteUnit();

const Execute::InstHandlersMap* inst_compute_address_handlers =
execute_unit->getInstComputeAddressHandlersMap();
(state->getXlen() == 64) ? execute_unit->getInstComputeAddressHandlersMap<RV64>()
: execute_unit->getInstComputeAddressHandlersMap<RV32>();
if (is_memory_inst_)
{
const Action & inst_compute_address_handler =
inst_compute_address_handlers->at(mnemonic_);
inst_action_group_.addAction(inst_compute_address_handler);
}

const Execute::InstHandlersMap* inst_handlers = execute_unit->getInstHandlersMap();
const Execute::InstHandlersMap* inst_handlers =
(state->getXlen() == 64) ? execute_unit->getInstHandlersMap<RV64>()
: execute_unit->getInstHandlersMap<RV32>();
try
{
const Action & inst_handler = inst_handlers->at(mnemonic_);
Expand Down
57 changes: 45 additions & 12 deletions core/AtlasState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,55 @@

namespace atlas
{
mavis::FileNameListType getUArchFiles(const std::string & uarch_file_path)
uint32_t getXlenFromIsaString_(const std::string & isa_string)
{
const std::string rv64_uarch_file_path = uarch_file_path + "/rv64";
if (isa_string.find("32") != std::string::npos)
{
return 32;
}
else if (isa_string.find("64") != std::string::npos)
{
return 64;
}
else
{
sparta_assert(false, "Failed to determine XLEN from ISA string: " << isa_string);
}
}

mavis::FileNameListType getUArchFiles(const std::string & uarch_file_path, const uint64_t xlen)
{
const std::string xlen_str = std::to_string(xlen);
const std::string xlen_uarch_file_path = uarch_file_path + "/rv" + xlen_str;
const mavis::FileNameListType uarch_files = {
rv64_uarch_file_path + "/atlas_uarch_rv64i.json",
rv64_uarch_file_path + "/atlas_uarch_rv64m.json",
rv64_uarch_file_path + "/atlas_uarch_rv64a.json",
rv64_uarch_file_path + "/atlas_uarch_rv64f.json",
rv64_uarch_file_path + "/atlas_uarch_rv64d.json",
rv64_uarch_file_path + "/atlas_uarch_rv64zicsr.json",
rv64_uarch_file_path + "/atlas_uarch_rv64zifencei.json"};
xlen_uarch_file_path + "/atlas_uarch_rv" + xlen_str + "i.json",
xlen_uarch_file_path + "/atlas_uarch_rv" + xlen_str + "m.json",
xlen_uarch_file_path + "/atlas_uarch_rv" + xlen_str + "a.json",
xlen_uarch_file_path + "/atlas_uarch_rv" + xlen_str + "f.json",
xlen_uarch_file_path + "/atlas_uarch_rv" + xlen_str + "d.json",
xlen_uarch_file_path + "/atlas_uarch_rv" + xlen_str + "zicsr.json",
xlen_uarch_file_path + "/atlas_uarch_rv" + xlen_str + "zifencei.json"};
return uarch_files;
}

AtlasState::AtlasState(sparta::TreeNode* core_tn, const AtlasStateParameters* p) :
sparta::Unit(core_tn),
hart_id_(p->hart_id),
isa_string_(p->isa_string),
xlen_(getXlenFromIsaString_(isa_string_)),
supported_isa_string_(std::string("rv" + std::to_string(xlen_) + "g_zicsr_zifencei")),
isa_file_path_(p->isa_file_path),
uarch_file_path_(p->uarch_file_path),
extension_manager_(mavis::extension_manager::riscv::RISCVExtensionManager::fromISA(
isa_string_, isa_file_path_ + std::string("/riscv_isa_spec.json"), isa_file_path_)),
supported_isa_string_, isa_file_path_ + std::string("/riscv_isa_spec.json"),
isa_file_path_)),
stop_sim_on_wfi_(p->stop_sim_on_wfi),
xlen_(extension_manager_.getXLEN()),
inst_logger_(core_tn, "inst", "Atlas Instruction Logger"),
finish_action_group_("finish_inst"),
stop_sim_action_group_("stop_sim")
{
sparta_assert(xlen_ == extension_manager_.getXLEN());

auto json_dir = (xlen_ == 32) ? REG32_JSON_DIR : REG64_JSON_DIR;
int_rset_ =
RegisterSet::create(core_tn, json_dir + std::string("/reg_int.json"), "int_regs");
Expand Down Expand Up @@ -85,13 +106,25 @@ namespace atlas
extension_manager_.constructMavis<
AtlasInst, AtlasExtractor, AtlasInstAllocatorWrapper<AtlasInstAllocator>,
AtlasExtractorAllocatorWrapper<AtlasExtractorAllocator>>(
getUArchFiles(uarch_file_path_),
getUArchFiles(uarch_file_path_, xlen_),
AtlasInstAllocatorWrapper<AtlasInstAllocator>(
sparta::notNull(AtlasAllocators::getAllocators(core_tn))->inst_allocator),
AtlasExtractorAllocatorWrapper<AtlasExtractorAllocator>(
sparta::notNull(AtlasAllocators::getAllocators(core_tn))->extractor_allocator,
this)));

extension_manager_.setISA(isa_string_);
std::vector<std::string> enabled_extensions;
for (auto & ext : extension_manager_.getEnabledExtensions())
{
enabled_extensions.emplace_back(ext.first);
}

const mavis::MatchSet<mavis::Pattern> inclusions{enabled_extensions};
mavis_->makeContext("boot", extension_manager_.getJSONs(),
getUArchFiles(uarch_file_path_, xlen_), {}, {}, inclusions, {});
mavis_->switchContext("boot");

// Connect finish ActionGroup to Fetch
finish_action_group_.setNextActionGroup(fetch_unit_->getActionGroup());

Expand Down
16 changes: 12 additions & 4 deletions core/AtlasState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ namespace atlas

struct SimState
{
uint64_t current_opcode = 0;
AtlasInstPtr current_inst = nullptr;
uint64_t inst_count = 0;
bool sim_stopped = false;
bool test_passed = true;
uint64_t workload_exit_code = 0;

void reset() { current_inst.reset(); }
void reset()
{
current_opcode = 0;
current_inst.reset();
}
};

const SimState* getSimState() const { return &sim_state_; }
Expand Down Expand Up @@ -237,6 +242,12 @@ namespace atlas
// ISA string
const std::string isa_string_;

// XLEN (either 32 or 64 bit)
uint64_t xlen_ = 64;

// Supported ISA string
const std::string supported_isa_string_;

// Path to Mavis
const std::string isa_file_path_;

Expand All @@ -252,9 +263,6 @@ namespace atlas
//! Stop simulatiion on WFI
const bool stop_sim_on_wfi_;

// XLEN (either 32 or 64 bit)
uint64_t xlen_ = 64;

//! Current pc
Addr pc_ = 0x0;

Expand Down
2 changes: 1 addition & 1 deletion core/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace atlas
const uint64_t cause = static_cast<uint64_t>(cause_.getValue());
WRITE_CSR_REG(MCAUSE, cause);

const uint64_t mtval = state->getCurrentInst()->getOpcode();
const uint64_t mtval = state->getSimState()->current_opcode;
WRITE_CSR_REG(MTVAL, mtval);

const uint64_t mtval2 = 0;
Expand Down
49 changes: 35 additions & 14 deletions core/Execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,44 @@ namespace atlas
execute_action.addTag(ActionTags::EXECUTE_TAG);
execute_action_group_.addAction(execute_action);

// TODO: Get RV32 inst handlers
// Get instruction handlers
RviInsts::getInstHandlers<RV64>(inst_handlers_);
RvmInsts::getInstHandlers<RV64>(inst_handlers_);
RvaInsts::getInstHandlers<RV64>(inst_handlers_);
RvfInsts::getInstHandlers<RV64>(inst_handlers_);
RvdInsts::getInstHandlers<RV64>(inst_handlers_);
RvzicsrInsts::getInstHandlers<RV64>(inst_handlers_);
RvzifenceiInsts::getInstHandlers<RV64>(inst_handlers_);
// Get RV64 instruction handlers
RviInsts::getInstHandlers<RV64>(rv64_inst_handlers_);
RvmInsts::getInstHandlers<RV64>(rv64_inst_handlers_);
RvaInsts::getInstHandlers<RV64>(rv64_inst_handlers_);
RvfInsts::getInstHandlers<RV64>(rv64_inst_handlers_);
RvdInsts::getInstHandlers<RV64>(rv64_inst_handlers_);
RvzicsrInsts::getInstHandlers<RV64>(rv64_inst_handlers_);
RvzifenceiInsts::getInstHandlers<RV64>(rv64_inst_handlers_);

// Get instruction compute address handlers
RviInsts::getInstComputeAddressHandlers<RV64>(inst_compute_address_handlers_);
RvaInsts::getInstComputeAddressHandlers<RV64>(inst_compute_address_handlers_);
RvfInsts::getInstComputeAddressHandlers<RV64>(inst_compute_address_handlers_);
RvdInsts::getInstComputeAddressHandlers<RV64>(inst_compute_address_handlers_);
// Get RV32 instruction handlers
RviInsts::getInstHandlers<RV64>(rv32_inst_handlers_);
// RvmInsts::getInstHandlers<RV32>(rv32_inst_handlers_);
// RvaInsts::getInstHandlers<RV32>(rv32_inst_handlers_);
// RvfInsts::getInstHandlers<RV32>(rv32_inst_handlers_);
// RvdInsts::getInstHandlers<RV32>(rv32_inst_handlers_);
// RvzicsrInsts::getInstHandlers<RV32>(rv32_inst_handlers_);
// RvzifenceiInsts::getInstHandlers<RV32>(rv32_inst_handlers_);

// Get RV64 instruction compute address handlers
RviInsts::getInstComputeAddressHandlers<RV64>(rv64_inst_compute_address_handlers_);
RvaInsts::getInstComputeAddressHandlers<RV64>(rv64_inst_compute_address_handlers_);
RvfInsts::getInstComputeAddressHandlers<RV64>(rv64_inst_compute_address_handlers_);
RvdInsts::getInstComputeAddressHandlers<RV64>(rv64_inst_compute_address_handlers_);

// Get RV32 instruction compute address handlers
RviInsts::getInstComputeAddressHandlers<RV32>(rv32_inst_compute_address_handlers_);
// RvaInsts::getInstComputeAddressHandlers<RV32>(rv32_inst_compute_address_handlers_);
// RvfInsts::getInstComputeAddressHandlers<RV32>(rv32_inst_compute_address_handlers_);
// RvdInsts::getInstComputeAddressHandlers<RV32>(rv32_inst_compute_address_handlers_);
}

template const Execute::InstHandlersMap* Execute::getInstHandlersMap<RV64>() const;
template const Execute::InstHandlersMap* Execute::getInstHandlersMap<RV32>() const;
template const Execute::InstHandlersMap*
Execute::getInstComputeAddressHandlersMap<RV64>() const;
template const Execute::InstHandlersMap*
Execute::getInstComputeAddressHandlersMap<RV32>() const;

ActionGroup* Execute::execute_(AtlasState* state)
{
// Connect instruction to Fetch
Expand Down
32 changes: 27 additions & 5 deletions core/Execute.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "core/ActionGroup.hpp"
#include "include/AtlasTypes.hpp"

#include "sparta/simulation/ParameterSet.hpp"
#include "sparta/simulation/TreeNode.hpp"
Expand Down Expand Up @@ -29,11 +30,30 @@ namespace atlas

using InstHandlersMap = std::map<std::string, Action>;

const InstHandlersMap* getInstHandlersMap() const { return &inst_handlers_; }
template <typename XLEN> const InstHandlersMap* getInstHandlersMap() const
{
static_assert(std::is_same_v<XLEN, RV64> || std::is_same_v<XLEN, RV32>);
if constexpr (std::is_same_v<XLEN, RV64>)
{
return &rv64_inst_handlers_;
}
else
{
return &rv32_inst_handlers_;
}
}

const InstHandlersMap* getInstComputeAddressHandlersMap() const
template <typename XLEN> const InstHandlersMap* getInstComputeAddressHandlersMap() const
{
return &inst_compute_address_handlers_;
static_assert(std::is_same_v<XLEN, RV64> || std::is_same_v<XLEN, RV32>);
if constexpr (std::is_same_v<XLEN, RV64>)
{
return &rv64_inst_compute_address_handlers_;
}
else
{
return &rv32_inst_compute_address_handlers_;
}
}

private:
Expand All @@ -42,9 +62,11 @@ namespace atlas
ActionGroup execute_action_group_{"Execute"};

// Instruction handlers
InstHandlersMap inst_handlers_;
InstHandlersMap rv64_inst_handlers_;
InstHandlersMap rv32_inst_handlers_;

// Instruction handlers for computing the address of load/store instructions
InstHandlersMap inst_compute_address_handlers_;
InstHandlersMap rv64_inst_compute_address_handlers_;
InstHandlersMap rv32_inst_compute_address_handlers_;
};
} // namespace atlas
7 changes: 3 additions & 4 deletions core/Fetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ namespace atlas
opcode_size = 2;
}

state->getSimState()->current_opcode = opcode;

// Decode instruction with Mavis
AtlasInstPtr inst = nullptr;
try
Expand All @@ -87,10 +89,7 @@ namespace atlas
}
catch (const mavis::UnknownOpcode & e)
{
// End simulation since exceptions are not handled yet
state->getSimState()->workload_exit_code = 1;
state->getSimState()->test_passed = false;
return state->getStopSimActionGroup();
THROW_ILLEGAL_INSTRUCTION;
}

return nullptr;
Expand Down
Loading

0 comments on commit d420a6f

Please sign in to comment.