Skip to content

Commit

Permalink
feat(difftest): support using difftest override ref flash (#758)
Browse files Browse the repository at this point in the history
Signed-off-by: jiaxiaoyu <[email protected]>
  • Loading branch information
xyyy1420 authored Jan 8, 2025
1 parent e3014dd commit 290da53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/cpu/difftest/dut.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
#include <memory/paddr.h>
#include <utils.h>
#include <difftest.h>
#include <device/flash.h>

void (*ref_difftest_memcpy)(paddr_t addr, void *buf, size_t n, bool direction) = NULL;
void (*ref_difftest_regcpy)(void *dut, bool direction) = NULL;
void (*ref_difftest_exec)(uint64_t n) = NULL;
void (*ref_difftest_raise_intr)(uint64_t NO) = NULL;
void (*ref_difftest_dirty_fsvs)(const uint64_t dirties) = NULL;
int (*ref_difftest_store_commit)(uint64_t *addr, uint64_t *data, uint8_t *mask) = NULL;
void (*ref_difftest_flash_cpy)(uint8_t* flash_bin, size_t size) = NULL;
#ifdef CONFIG_DIFFTEST

IFDEF(CONFIG_DIFFTEST_REF_QEMU_DL, __thread uint8_t resereve_for_qemu_tls[4096]);
Expand Down Expand Up @@ -71,7 +73,7 @@ void difftest_set_patch(void (*fn)(void *arg), void *arg) {
patch_arg = arg;
}

void init_difftest(char *ref_so_file, long img_size, int port) {
void init_difftest(char *ref_so_file, long img_size, long flash_size, int port) {
assert(ref_so_file != NULL);

void *handle;
Expand Down Expand Up @@ -103,13 +105,20 @@ void init_difftest(char *ref_so_file, long img_size, int port) {
assert(ref_difftest_store_commit);
#endif

#ifdef CONFIG_HAS_FLASH
ref_difftest_flash_cpy = dlsym(handle, "difftest_load_flash_v2");
assert(ref_difftest_flash_cpy);
#endif
Log("Differential testing: \33[1;32m%s\33[0m", "ON");
Log("The result of every instruction will be compared with %s. "
"This will help you a lot for debugging, but also significantly reduce the performance. "
"If it is not necessary, you can turn it off in include/common.h.", ref_so_file);

ref_difftest_init(port);
ref_difftest_memcpy(RESET_VECTOR, guest_to_host(RESET_VECTOR), img_size, DIFFTEST_TO_REF);
#ifdef CONFIG_HAS_FLASH
ref_difftest_flash_cpy(get_flash_base(), flash_size ? flash_size : CONFIG_FLASH_SIZE);
#endif
ref_difftest_regcpy(&cpu, DIFFTEST_TO_REF);
}

Expand Down
4 changes: 2 additions & 2 deletions src/monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void init_log(const char *log_file, const bool fast_log, const bool small_log);
void init_mem();
void init_regex();
void init_wp_pool();
void init_difftest(char *ref_so_file, long img_size, int port);
void init_difftest(char *ref_so_file, long img_size, long flash_size, int port);
void init_device();

static char *log_file = NULL;
Expand Down Expand Up @@ -346,7 +346,7 @@ void init_monitor(int argc, char *argv[]) {
fill_memory(img_file, flash_image, restorer, &img_size, &flash_size);

/* Initialize differential testing. */
init_difftest(diff_so_file, img_size, difftest_port);
init_difftest(diff_so_file, img_size, flash_size, difftest_port);

#endif

Expand Down

0 comments on commit 290da53

Please sign in to comment.