From 290da53f4316e4e94fc194e5cdcb940582336134 Mon Sep 17 00:00:00 2001 From: xyyy1420 Date: Wed, 8 Jan 2025 11:13:35 +0800 Subject: [PATCH] feat(difftest): support using difftest override ref flash (#758) Signed-off-by: jiaxiaoyu --- src/cpu/difftest/dut.c | 11 ++++++++++- src/monitor/monitor.c | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cpu/difftest/dut.c b/src/cpu/difftest/dut.c index b250abc71..f410a2c20 100644 --- a/src/cpu/difftest/dut.c +++ b/src/cpu/difftest/dut.c @@ -20,6 +20,7 @@ #include #include #include +#include void (*ref_difftest_memcpy)(paddr_t addr, void *buf, size_t n, bool direction) = NULL; void (*ref_difftest_regcpy)(void *dut, bool direction) = NULL; @@ -27,6 +28,7 @@ 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]); @@ -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; @@ -103,6 +105,10 @@ 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. " @@ -110,6 +116,9 @@ void init_difftest(char *ref_so_file, long img_size, int port) { 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); } diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index 72d45f7b2..7325c4f37 100644 --- a/src/monitor/monitor.c +++ b/src/monitor/monitor.c @@ -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; @@ -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