Skip to content

Commit

Permalink
Merge branch '19-add-spect_iss-library' into 'master'
Browse files Browse the repository at this point in the history
Resolve "Add SPECT_ISS library."

Closes #19

See merge request internal/sw-design/ts-spect-compiler!30
  • Loading branch information
Ondrej Ille committed Apr 18, 2024
2 parents d9967c0 + 8e1bd39 commit 6e5e1a3
Show file tree
Hide file tree
Showing 11 changed files with 657 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ deploy_compiler:

- cp build/src/apps/spect_* $DEST_FOLDER/$VERSION
- cp build/src/cosim/libspect_iss_dpi.so $DEST_FOLDER/$VERSION
- cp build/src/cosim/libspect_iss_lib.so $DEST_FOLDER/$VERSION

- cp src/cosim/spect_iss_dpi_pkg.sv $DEST_FOLDER/$VERSION
- cp src/cosim/spect_instr_gen_coverage.svh $DEST_FOLDER/$VERSION
Expand Down
14 changes: 14 additions & 0 deletions src/cosim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ add_library(spect_iss_dpi SHARED
spect_iss_dpi.cpp
)

add_library(spect_iss_lib SHARED
spect_iss_lib.cpp
)

target_link_libraries(spect_iss_dpi
SPECT
COMMON
XKCP
)

target_link_libraries(spect_iss_lib
SPECT
COMMON
XKCP
)

target_include_directories(spect_iss_dpi PUBLIC $ENV{VCS_HOME}/include)

target_compile_definitions(spect_iss_lib PUBLIC
TOOL_VERSION_TAG=${TAG_STR}
TOOL_VERSION_HASH=${HASH_STR})

set_source_files_properties(spect_iss_dpi.cpp PROPERTIES COMPILE_FLAGS -Wno-write-strings)
203 changes: 203 additions & 0 deletions src/cosim/spect_iss_lib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/**************************************************************************************************
** SPECT Instruction set simulator - Shared Library version
**
** TODO: License
**
** Author: Ondrej Ille
**************************************************************************************************/

#include "spect_iss_lib.h"


spect::CpuSimulator *simulator;

uint32_t first_addr_ = SPECT_INSTR_MEM_BASE;
spect::ParityType parity_type_ = spect::ParityType::NONE;


void spect_iss_init(int isa_version)
{
spect::InstructionFactory::SetActiveISAVersion(isa_version);
simulator = new spect::CpuSimulator();
simulator->model_->SetParityType(parity_type_);
}

void spect_iss_set_first_addr(int first_addr)
{
first_addr_ = first_addr;
}

void spect_iss_load_s_file(std::string s_file)
{
simulator->compiler_->CompileInit(first_addr_);
simulator->compiler_->Compile(s_file);
simulator->compiler_->CompileFinish();

uint32_t *p_start = simulator->model_->GetMemoryPtr();
p_start += (first_addr_ >> 2);
simulator->compiler_->program_->Assemble(p_start, parity_type_);

// Set address of first instruction to be fetched
uint32_t start_pc = simulator->compiler_->symbols_->GetSymbol(START_SYMBOL)->val_;
simulator->model_->SetStartPc(start_pc);
}

void spect_iss_set_parity_type(int parity_type)
{
if (parity_type == 1)
parity_type_ = spect::ParityType::ODD;
else if (parity_type == 2)
parity_type_ = spect::ParityType::EVEN;
}

void spect_iss_load_hex_file(std::string hex_file)
{
spect::HexHandler::LoadHexFile(hex_file,
simulator->model_->GetMemoryPtr(), SPECT_INSTR_MEM_BASE);
}

void spect_iss_set_const_rom_hex_file(std::string const_rom_hex_file)
{
spect::HexHandler::LoadHexFile(const_rom_hex_file,
simulator->model_->GetMemoryPtr(), SPECT_CONST_ROM_BASE);
}

void spect_iss_set_data_ram_in_hex_file(std::string data_ram_out_hex_file)
{
spect::HexHandler::LoadHexFile(data_ram_out_hex_file,
simulator->model_->GetMemoryPtr(), SPECT_DATA_RAM_IN_BASE);
}

void spect_iss_set_emem_in_hex_file(std::string emem_in_hex_file)
{
spect::HexHandler::LoadHexFile(emem_in_hex_file,
simulator->model_->GetMemoryPtr(), SPECT_EMEM_IN_BASE);
}

void spect_iss_set_timing_accurate(bool enable, int exec_time_step)
{
simulator->model_->timing_accurate_sim_ = enable;
simulator->model_->execution_time_step_ = exec_time_step;
}

void spect_iss_set_grv_hex_file(std::string grv_hex_file)
{
std::vector<uint32_t> mem;
spect::HexHandler::LoadHexFile(grv_hex_file, mem);

for (const auto &wrd : mem)
simulator->model_->GrvQueuePush(wrd);
}

void spect_iss_set_key_mem_hex_file(std::string key_mem_file)
{
simulator->key_memory_->Load(key_mem_file);
}

void spect_iss_set_start_pc(int start_pc)
{
simulator->model_->SetStartPc(start_pc);
}

void spect_iss_execute_cmd_file(std::string cmd_file)
{
cli::LoopScheduler scheduler;
cli::CliLocalTerminalSession session(*(simulator->cli_), scheduler, std::cout);

session.ExitAction(
[&scheduler](A_UNUSED auto& out)
{
scheduler.Stop();
}
);

simulator->cmd_file_ = cmd_file;
simulator->ExecCmdFile(session);

session.Feed("exit\n");
}

void spect_iss_cmd_start(std::ostream &out)
{
simulator->CmdStart(out);
}

void spect_iss_cmd_info(std::ostream &out, std::string arg1)
{
simulator->CmdInfo(out, arg1);
}

void spect_iss_cmd_run(std::ostream &out)
{
simulator->CmdRun(out);
}

void spect_iss_cmd_delete(std::ostream &out, std::string arg1, bool all)
{
simulator->CmdDelete(out, arg1, all);
}

void spect_iss_cmd_jump(std::ostream &out, std::string arg1)
{
simulator->CmdJump(out, arg1);
}

void spect_iss_cmd_get(std::ostream &out, std::string arg1)
{
simulator->CmdGet(out, arg1);
}

void spect_iss_cmd_load(std::ostream &out, std::string arg1, int offset)
{
simulator->CmdLoad(out, arg1, offset);
}

void spect_iss_cmd_step(std::ostream &out, int n)
{
simulator->CmdStep(out, n);
}

void spect_iss_cmd_dump(std::ostream &out, std::string arg1, uint32_t address, uint32_t size)
{
simulator->CmdDump(out, arg1, address, size);
}

void spect_iss_dump_data_ram_out_hex(std::string data_ram_out_hex_file)
{
spect::HexHandler::DumpHexFile(data_ram_out_hex_file,
spect::HexFileType::ISS_WORD, simulator->model_->GetMemoryPtr(),
SPECT_DATA_RAM_OUT_BASE, SPECT_DATA_RAM_OUT_SIZE);
}

void spect_iss_dump_emem_out_hex(std::string emem_out_hex_file)
{
spect::HexHandler::DumpHexFile(emem_out_hex_file,
spect::HexFileType::ISS_WORD, simulator->model_->GetMemoryPtr(), SPECT_EMEM_OUT_BASE,
SPECT_EMEM_OUT_SIZE);
}

void spect_iss_dump_key_mem_out_hex(std::string kmem_hex_file)
{
simulator->key_memory_->Dump(kmem_hex_file);
}

void spect_iss_exit(void)
{
delete simulator;
}

int spect_iss_get_git_hash(void)
{
std::stringstream ss;
ss << std::hex;
ss << std::string(TOOL_VERSION_HASH);
int ver;
ss >> ver;

return ver;
}

std::string spect_iss_get_version(void)
{
return std::string(TOOL_VERSION_TAG);
}
Loading

0 comments on commit 6e5e1a3

Please sign in to comment.