include fesvr as a library; improve harnesses
This commit is contained in:
@ -1,61 +1,53 @@
|
||||
#include "htif_phy.h"
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <map>
|
||||
#include "htif_emulator.h"
|
||||
#include "common.h"
|
||||
#include "emulator.h"
|
||||
#include "mm.h"
|
||||
#include "mm_dramsim2.h"
|
||||
#include "Top.h" // chisel-generated code...
|
||||
#include "disasm.h"
|
||||
#include "Top.h" // chisel-generated code...
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static bool exit_now = false;
|
||||
void handle_sigterm(int signum)
|
||||
htif_emulator_t* htif;
|
||||
void handle_sigterm(int sig)
|
||||
{
|
||||
exit_now = true;
|
||||
htif->stop();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int fromhost_fd = -1, tohost_fd = -1;
|
||||
unsigned random_seed = (unsigned)time(NULL) ^ (unsigned)getpid();
|
||||
uint64_t max_cycles = 0;
|
||||
uint64_t trace_count = 0;
|
||||
int start = 0;
|
||||
bool log = false;
|
||||
bool quiet = false;
|
||||
const char* vcd = NULL;
|
||||
const char* loadmem = NULL;
|
||||
FILE *vcdfile = NULL, *logfile = stderr;
|
||||
const char* failure = NULL;
|
||||
disassembler disasm;
|
||||
bool dramsim2 = false;
|
||||
|
||||
signal(SIGTERM, handle_sigterm);
|
||||
std::vector<std::string> target_args;
|
||||
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
std::string arg = argv[i];
|
||||
if (arg == "-l")
|
||||
log = true;
|
||||
else if (arg == "-q")
|
||||
quiet = true;
|
||||
else if (arg == "+dramsim")
|
||||
dramsim2 = true;
|
||||
else if (arg.substr(0, 2) == "-v")
|
||||
if (arg.substr(0, 2) == "-v")
|
||||
vcd = argv[i]+2;
|
||||
else if (arg.substr(0, 2) == "-m")
|
||||
max_cycles = atoll(argv[i]+2);
|
||||
else if (arg.substr(0, 2) == "-s")
|
||||
random_seed = atoi(argv[i]+2);
|
||||
else if (arg.substr(0, 10) == "+fromhost=")
|
||||
fromhost_fd = atoi(argv[i]+10);
|
||||
else if (arg.substr(0, 8) == "+tohost=")
|
||||
tohost_fd = atoi(argv[i]+8);
|
||||
else if (arg == "+dramsim")
|
||||
dramsim2 = true;
|
||||
else if (arg == "+verbose")
|
||||
log = true;
|
||||
else if (arg.substr(0, 12) == "+max-cycles=")
|
||||
max_cycles = atoll(argv[i]+12);
|
||||
else if (arg.substr(0, 9) == "+loadmem=")
|
||||
loadmem = argv[i]+9;
|
||||
else if (arg.substr(0, 1) != "-" || arg.substr(0, 1) != "+")
|
||||
target_args = std::vector<std::string>(argv + i, argv + argc);
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "unknown option: %s\n", argv[i]);
|
||||
@ -63,8 +55,11 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
demand(fcntl(fromhost_fd,F_GETFD) >= 0, "fromhost file not open");
|
||||
demand(fcntl(tohost_fd,F_GETFD) >= 0, "tohost file not open");
|
||||
if (target_args.empty())
|
||||
{
|
||||
fprintf(stderr, "usage: %s [host options] <target program> [target args]\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const int disasm_len = 24;
|
||||
if (vcd)
|
||||
@ -89,6 +84,13 @@ int main(int argc, char** argv)
|
||||
srand(random_seed);
|
||||
tile.init(random_seed != 0);
|
||||
|
||||
// Instantiate HTIF
|
||||
htif = new htif_emulator_t(target_args);
|
||||
int htif_bits = tile.Top__io_host_in_bits.width();
|
||||
assert(htif_bits % 8 == 0 && htif_bits <= val_n_bits());
|
||||
|
||||
signal(SIGTERM, handle_sigterm);
|
||||
|
||||
// reset for a few cycles to support pipelined reset
|
||||
tile.Top__io_host_in_valid = LIT<1>(0);
|
||||
tile.Top__io_host_out_ready = LIT<1>(0);
|
||||
@ -99,9 +101,7 @@ int main(int argc, char** argv)
|
||||
tile.clock_hi(LIT<1>(1));
|
||||
}
|
||||
|
||||
htif_phy_t htif_phy(tile.Top__io_host_in_bits.width(), fromhost_fd, tohost_fd);
|
||||
|
||||
while (!exit_now)
|
||||
while (!htif->done())
|
||||
{
|
||||
tile.Top__io_mem_req_cmd_ready = LIT<1>(mm->req_cmd_ready());
|
||||
tile.Top__io_mem_req_data_ready = LIT<1>(mm->req_data_ready());
|
||||
@ -109,10 +109,6 @@ int main(int argc, char** argv)
|
||||
tile.Top__io_mem_resp_bits_tag = LIT<64>(mm->resp_tag());
|
||||
memcpy(&tile.Top__io_mem_resp_bits_data, mm->resp_data(), tile.Top__io_mem_resp_bits_data.width()/8);
|
||||
|
||||
tile.Top__io_host_in_valid = LIT<1>(htif_phy.in_valid());
|
||||
tile.Top__io_host_in_bits = LIT<64>(htif_phy.in_bits());
|
||||
tile.Top__io_host_out_ready = LIT<1>(htif_phy.out_ready());
|
||||
|
||||
tile.clock_lo(LIT<1>(0));
|
||||
|
||||
mm->tick(
|
||||
@ -127,9 +123,13 @@ int main(int argc, char** argv)
|
||||
|
||||
if (tile.Top__io_host_clk_edge.to_bool())
|
||||
{
|
||||
htif_phy.tick(tile.Top__io_host_in_ready.lo_word(),
|
||||
tile.Top__io_host_out_valid.lo_word(),
|
||||
tile.Top__io_host_out_bits.lo_word());
|
||||
bool in_valid = tile.Top__io_host_in_ready.to_bool() &&
|
||||
htif->recv_nonblocking(&tile.Top__io_host_in_bits.values[0], htif_bits/8);
|
||||
tile.Top__io_host_in_valid = LIT<1>(in_valid);
|
||||
tile.Top__io_host_out_ready = LIT<1>(1);
|
||||
|
||||
if (tile.Top__io_host_out_valid.to_bool())
|
||||
htif->send(&tile.Top__io_host_out_bits.values[0], htif_bits/8);
|
||||
}
|
||||
|
||||
|
||||
@ -152,7 +152,7 @@ int main(int argc, char** argv)
|
||||
wb_insn.bits = wb_reg_inst;
|
||||
std::string wb_disasm = disasm.disassemble(wb_insn);
|
||||
|
||||
if (log || (quiet && trace_count % 10000 == 0))
|
||||
if (log)
|
||||
{
|
||||
fprintf(logfile, "C: %10lld [%ld] pc=[%011lx] W[r%2ld=%016lx][%ld] R[r%2ld=%016lx] R[r%2ld=%016lx] inst=[%08lx] %-32s\n", \
|
||||
(long long)trace_count, tile.Top_Tile_core_ctrl__wb_reg_valid.lo_word(), tile.Top_Tile_core_dpath__wb_reg_pc.lo_word(), \
|
||||
@ -192,8 +192,5 @@ int main(int argc, char** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(tohost_fd);
|
||||
close(fromhost_fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user