提交 c4401c32 编写于 作者: Y Yinan Xu

emu: add xs_assert to replace finish to support exception handling

上级 020e2057
......@@ -56,7 +56,7 @@ $(SIM_TOP_V): $(SCALA_FILE) $(TEST_FILE)
date -R
mill XiangShan.test.runMain $(SIMTOP) -X verilog -td $(@D) --full-stacktrace --output-file $(@F) $(SIM_ARGS)
sed -i '/module XSSimTop/,/endmodule/d' $(SIM_TOP_V)
sed -i -e 's/$$fatal/$$finish/g' $(SIM_TOP_V)
sed -i -e 's/$$fatal/xs_assert(`__LINE__)/g' $(SIM_TOP_V)
date -R
EMU_TOP = XSSimSoC
......@@ -80,7 +80,7 @@ endif
# Verilator multi-thread support
EMU_THREADS ?= 1
ifneq ($(EMU_THREADS),1)
VEXTRA_FLAGS += --threads $(EMU_THREADS) --threads-dpi none
VEXTRA_FLAGS += --threads $(EMU_THREADS) --threads-dpi all
endif
# Verilator savable
......
#include "common.h"
#include "emu.h"
int assert_count = 0;
static pthread_mutex_t assert_mutex;
void assert_init() {
pthread_mutex_init(&assert_mutex, 0);
}
void assert_finish() {
pthread_mutex_destroy(&assert_mutex);
}
extern "C" void xs_assert(long long line) {
pthread_mutex_lock(&assert_mutex);
printf("Assertion failed at line %lld\n.", line);
assert_count++;
pthread_mutex_unlock(&assert_mutex);
}
......@@ -6,6 +6,7 @@
#include <cstdlib>
#include <stdint.h>
#include <assert.h>
#include <pthread.h>
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
......@@ -21,4 +22,8 @@
#include "cosimulation.h"
#endif
extern int assert_count;
void assert_init();
void assert_finish();
#endif // __COMMON_H
......@@ -96,4 +96,7 @@ int difftest_step(DiffState *s);
int difftest_store_step(uint64_t *saddr, uint64_t *sdata, uint8_t *smask);
void difftest_display(uint8_t mode);
uint64_t get_nemu_this_pc();
void set_nemu_this_pc(uint64_t pc);
#endif
......@@ -8,12 +8,6 @@
#include "zlib.h"
#include "compress.h"
void* get_ram_start();
long get_ram_size();
uint64_t get_nemu_this_pc();
void set_nemu_this_pc(uint64_t pc);
static inline void print_help(const char *file) {
printf("Usage: %s [OPTION...]\n", file);
printf("\n");
......@@ -90,6 +84,7 @@ Emulator::Emulator(int argc, const char *argv[]):
srand(args.seed);
srand48(args.seed);
Verilated::randReset(2);
assert_init();
// init core
reset_ncycles(10);
......@@ -132,6 +127,7 @@ Emulator::Emulator(int argc, const char *argv[]):
Emulator::~Emulator() {
ram_finish();
assert_finish();
#ifdef VM_SAVABLE
if (args.enable_snapshot && trapCode != STATE_GOODTRAP && trapCode != STATE_LIMIT_EXCEEDED) {
......@@ -382,7 +378,7 @@ uint64_t Emulator::execute(uint64_t max_cycle, uint64_t max_instr) {
#endif
}
if (Verilated::gotFinish()) {
if (assert_count > 0) {
difftest_display(dut_ptr->io_difftest_priviledgeMode);
eprintf("The simulation stopped. There might be some assertion failed.\n");
trapCode = STATE_ABORT;
......
......@@ -12,6 +12,8 @@ CoDRAMsim3 *dram = NULL;
static uint64_t *ram;
static long img_size = 0;
static pthread_mutex_t ram_mutex;
void* get_img_start() { return &ram[0]; }
long get_img_size() { return img_size; }
void* get_ram_start() { return &ram[0]; }
......@@ -155,6 +157,8 @@ void init_ram(const char *img) {
dram = new CoDRAMsim3(DRAMSIM3_CONFIG, DRAMSIM3_OUTDIR);
#endif
pthread_mutex_init(&ram_mutex, 0);
}
void ram_finish() {
......@@ -162,13 +166,18 @@ void ram_finish() {
#ifdef WITH_DRAMSIM3
dramsim3_finish();
#endif
pthread_mutex_destroy(&ram_mutex);
}
extern "C" uint64_t ram_read_helper(uint8_t en, uint64_t rIdx) {
if (en && rIdx >= EMU_RAM_SIZE / sizeof(uint64_t)) {
rIdx %= EMU_RAM_SIZE / sizeof(uint64_t);
}
return (en) ? ram[rIdx] : 0;
pthread_mutex_lock(&ram_mutex);
uint64_t rdata = (en) ? ram[rIdx] : 0;
pthread_mutex_unlock(&ram_mutex);
return rdata;
}
extern "C" void ram_write_helper(uint64_t wIdx, uint64_t wdata, uint64_t wmask, uint8_t wen) {
......@@ -177,7 +186,9 @@ extern "C" void ram_write_helper(uint64_t wIdx, uint64_t wdata, uint64_t wmask,
printf("ERROR: ram wIdx = 0x%lx out of bound!\n", wIdx);
assert(wIdx < EMU_RAM_SIZE / sizeof(uint64_t));
}
pthread_mutex_lock(&ram_mutex);
ram[wIdx] = (ram[wIdx] & ~wmask) | (wdata & wmask);
pthread_mutex_unlock(&ram_mutex);
}
}
......
......@@ -8,6 +8,8 @@
void init_ram(const char *img);
void ram_finish();
void* get_ram_start();
long get_ram_size();
#ifdef WITH_DRAMSIM3
// 4*64 bits
......
import "DPI-C" function void xs_assert
(
input longint line
);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册