NJU-ProjectN/nemu ics2023 initialized
NJU-ProjectN/nemu eb63cf3568dbf4e0c3c6ef462e6ec685550fabbc Merge pull request #76 from rijuyuezhu/master
This commit is contained in:
parent
1efe03efb9
commit
2824efad33
141 changed files with 19573 additions and 0 deletions
2
nemu/tools/spike-diff/.gitignore
vendored
Normal file
2
nemu/tools/spike-diff/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
repo/
|
||||
!difftest.cc
|
54
nemu/tools/spike-diff/Makefile
Normal file
54
nemu/tools/spike-diff/Makefile
Normal file
|
@ -0,0 +1,54 @@
|
|||
#***************************************************************************************
|
||||
# Copyright (c) 2014-2022 Zihao Yu, Nanjing University
|
||||
#
|
||||
# NEMU is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
# See the Mulan PSL v2 for more details.
|
||||
#**************************************************************************************/
|
||||
|
||||
REPO_PATH = repo
|
||||
ifeq ($(wildcard repo/spike_main),)
|
||||
$(shell git clone --depth=1 git@github.com:NJU-ProjectN/riscv-isa-sim $(REPO_PATH))
|
||||
endif
|
||||
|
||||
REPO_BUILD_PATH = $(REPO_PATH)/build
|
||||
REPO_MAKEFILE = $(REPO_BUILD_PATH)/Makefile
|
||||
$(REPO_MAKEFILE):
|
||||
@mkdir -p $(@D)
|
||||
cd $(@D) && $(abspath $(REPO_PATH))/configure
|
||||
sed -i -e 's/-g -O2/-O2/' $@
|
||||
|
||||
SPIKE = $(REPO_BUILD_PATH)/spike
|
||||
$(SPIKE): $(REPO_MAKEFILE)
|
||||
CFLAGS="-fvisibility=hidden" CXXFLAGS="-fvisibility=hidden" $(MAKE) -C $(^D)
|
||||
|
||||
BUILD_DIR = ./build
|
||||
$(shell mkdir -p $(BUILD_DIR))
|
||||
|
||||
inc_dependencies = fesvr riscv disasm customext fdt softfloat spike_main spike_dasm build
|
||||
INC_PATH = -I$(REPO_PATH) $(addprefix -I$(REPO_PATH)/, $(inc_dependencies))
|
||||
INC_PATH += -I$(NEMU_HOME)/include
|
||||
lib_dependencies = libspike_main.a libriscv.a libdisasm.a libsoftfloat.a libfesvr.a libfdt.a
|
||||
INC_LIBS = $(addprefix $(REPO_PATH)/build/, $(lib_dependencies))
|
||||
|
||||
NAME = $(GUEST_ISA)-spike-so
|
||||
BINARY = $(BUILD_DIR)/$(NAME)
|
||||
SRCS = difftest.cc
|
||||
|
||||
$(BINARY): $(SPIKE) $(SRCS)
|
||||
g++ -std=c++17 -O2 -shared -fPIC -fvisibility=hidden $(INC_PATH) $(SRCS) $(INC_LIBS) -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
all: $(BINARY)
|
||||
.DEFAULT_GOAL = all
|
||||
|
||||
.PHONY: all clean $(SPIKE)
|
131
nemu/tools/spike-diff/difftest.cc
Normal file
131
nemu/tools/spike-diff/difftest.cc
Normal file
|
@ -0,0 +1,131 @@
|
|||
/***************************************************************************************
|
||||
* Copyright (c) 2014-2022 Zihao Yu, Nanjing University
|
||||
*
|
||||
* NEMU is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the Mulan PSL v2 for more details.
|
||||
***************************************************************************************/
|
||||
|
||||
#include "mmu.h"
|
||||
#include "sim.h"
|
||||
#include "../../include/common.h"
|
||||
#include <difftest-def.h>
|
||||
|
||||
#define NR_GPR MUXDEF(CONFIG_RVE, 16, 32)
|
||||
|
||||
static std::vector<std::pair<reg_t, abstract_device_t*>> difftest_plugin_devices;
|
||||
static std::vector<std::string> difftest_htif_args;
|
||||
static std::vector<std::pair<reg_t, mem_t*>> difftest_mem(
|
||||
1, std::make_pair(reg_t(DRAM_BASE), new mem_t(CONFIG_MSIZE)));
|
||||
static debug_module_config_t difftest_dm_config = {
|
||||
.progbufsize = 2,
|
||||
.max_sba_data_width = 0,
|
||||
.require_authentication = false,
|
||||
.abstract_rti = 0,
|
||||
.support_hasel = true,
|
||||
.support_abstract_csr_access = true,
|
||||
.support_abstract_fpr_access = true,
|
||||
.support_haltgroups = true,
|
||||
.support_impebreak = true
|
||||
};
|
||||
|
||||
struct diff_context_t {
|
||||
word_t gpr[MUXDEF(CONFIG_RVE, 16, 32)];
|
||||
word_t pc;
|
||||
};
|
||||
|
||||
static sim_t* s = NULL;
|
||||
static processor_t *p = NULL;
|
||||
static state_t *state = NULL;
|
||||
|
||||
void sim_t::diff_init(int port) {
|
||||
p = get_core("0");
|
||||
state = p->get_state();
|
||||
}
|
||||
|
||||
void sim_t::diff_step(uint64_t n) {
|
||||
step(n);
|
||||
}
|
||||
|
||||
void sim_t::diff_get_regs(void* diff_context) {
|
||||
struct diff_context_t* ctx = (struct diff_context_t*)diff_context;
|
||||
for (int i = 0; i < NR_GPR; i++) {
|
||||
ctx->gpr[i] = state->XPR[i];
|
||||
}
|
||||
ctx->pc = state->pc;
|
||||
}
|
||||
|
||||
void sim_t::diff_set_regs(void* diff_context) {
|
||||
struct diff_context_t* ctx = (struct diff_context_t*)diff_context;
|
||||
for (int i = 0; i < NR_GPR; i++) {
|
||||
state->XPR.write(i, (sword_t)ctx->gpr[i]);
|
||||
}
|
||||
state->pc = ctx->pc;
|
||||
}
|
||||
|
||||
void sim_t::diff_memcpy(reg_t dest, void* src, size_t n) {
|
||||
mmu_t* mmu = p->get_mmu();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
mmu->store<uint8_t>(dest+i, *((uint8_t*)src+i));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
__EXPORT void difftest_memcpy(paddr_t addr, void *buf, size_t n, bool direction) {
|
||||
if (direction == DIFFTEST_TO_REF) {
|
||||
s->diff_memcpy(addr, buf, n);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
__EXPORT void difftest_regcpy(void* dut, bool direction) {
|
||||
if (direction == DIFFTEST_TO_REF) {
|
||||
s->diff_set_regs(dut);
|
||||
} else {
|
||||
s->diff_get_regs(dut);
|
||||
}
|
||||
}
|
||||
|
||||
__EXPORT void difftest_exec(uint64_t n) {
|
||||
s->diff_step(n);
|
||||
}
|
||||
|
||||
__EXPORT void difftest_init(int port) {
|
||||
difftest_htif_args.push_back("");
|
||||
const char *isa = "RV" MUXDEF(CONFIG_RV64, "64", "32") MUXDEF(CONFIG_RVE, "E", "I") "MAFDC";
|
||||
cfg_t cfg(/*default_initrd_bounds=*/std::make_pair((reg_t)0, (reg_t)0),
|
||||
/*default_bootargs=*/nullptr,
|
||||
/*default_isa=*/isa,
|
||||
/*default_priv=*/DEFAULT_PRIV,
|
||||
/*default_varch=*/DEFAULT_VARCH,
|
||||
/*default_misaligned=*/false,
|
||||
/*default_endianness*/endianness_little,
|
||||
/*default_pmpregions=*/16,
|
||||
/*default_mem_layout=*/std::vector<mem_cfg_t>(),
|
||||
/*default_hartids=*/std::vector<size_t>(1),
|
||||
/*default_real_time_clint=*/false,
|
||||
/*default_trigger_count=*/4);
|
||||
s = new sim_t(&cfg, false,
|
||||
difftest_mem, difftest_plugin_devices, difftest_htif_args,
|
||||
difftest_dm_config, nullptr, false, NULL,
|
||||
false,
|
||||
NULL,
|
||||
true);
|
||||
s->diff_init(port);
|
||||
}
|
||||
|
||||
__EXPORT void difftest_raise_intr(uint64_t NO) {
|
||||
trap_t t(NO);
|
||||
p->take_trap_public(t, state->pc);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue