sEMU
载入中...
搜索中...
未找到
difftest.hpp
浏览该文件的文档.
1#ifndef SEMU_DIFFTEST_HPP
2#define SEMU_DIFFTEST_HPP
3
4#include <string>
5#include <cstdint>
6#include <cstddef>
7#include "sEMU/core.hpp"
8#include "sEMU/mem.hpp"
9
10// 差分测试的数据流方向
12
17struct CPU_state {
18 uint32_t gpr[32];
19 uint32_t pc;
20};
21
29class DiffTest {
30public:
31 DiffTest();
32 ~DiffTest();
33
40 bool init(const std::string& ref_so_file, int port);
41
49 void sync_memory(size_t addr, void* buf, size_t n, bool to_ref);
50
56 void sync_registers(const Core* core, bool to_ref);
57
62 void step(uint64_t n);
63
69 bool check_registers(const CPU_state& dut_state);
70
75 void skip_ref();
76
81 bool is_active() const { return active; }
82
83private:
84 void* handle = nullptr;
85 bool active = false;
86
87 // API function pointers
88 void (*ref_difftest_memcpy)(uint32_t addr, void* buf, size_t n, bool direction) = nullptr;
89 void (*ref_difftest_regcpy)(void* dut, bool direction) = nullptr;
90 void (*ref_difftest_exec)(uint64_t n) = nullptr;
91 void (*ref_difftest_raise_intr)(uint32_t NO) = nullptr;
92 void (*ref_difftest_init)(int port) = nullptr;
93 void (*ref_difftest_skip_ref)() = nullptr;
94};
95
96// Global instance, defined in main.cpp
97extern DiffTest difftest;
98
99#endif // SEMU_DIFFTEST_HPP
处理器核心仿真封装类
定义 core.hpp:28
差分测试 (Differential Testing) 引擎
定义 difftest.hpp:29
bool is_active() const
检查差分测试是否已启用且库已成功加载
定义 difftest.hpp:81
bool init(const std::string &ref_so_file, int port)
初始化差分测试引擎,尝试加载参考模拟器
定义 difftest.cpp:18
void(* ref_difftest_memcpy)(uint32_t addr, void *buf, size_t n, bool direction)
定义 difftest.hpp:88
void(* ref_difftest_exec)(uint64_t n)
定义 difftest.hpp:90
bool active
定义 difftest.hpp:85
void * handle
定义 difftest.hpp:84
void sync_memory(size_t addr, void *buf, size_t n, bool to_ref)
物理内存状态同步
定义 difftest.cpp:63
void skip_ref()
跳过参考模拟器的内部比对环节 适用于一些由于设备 MMIO 等异步行为导致无法产生一致读写结果的特定指令跳过。
定义 difftest.cpp:137
DiffTest()
定义 difftest.cpp:10
bool check_registers(const CPU_state &dut_state)
运行差分比对:检查当前 DUT 的状态与 REF 的状态是否严格一致
定义 difftest.cpp:93
void(* ref_difftest_skip_ref)()
定义 difftest.hpp:93
~DiffTest()
定义 difftest.cpp:12
void sync_registers(const Core *core, bool to_ref)
通用寄存器状态同步
定义 difftest.cpp:68
void(* ref_difftest_raise_intr)(uint32_t NO)
定义 difftest.hpp:91
void step(uint64_t n)
推进参考模拟器执行 N 条指令
定义 difftest.cpp:88
void(* ref_difftest_regcpy)(void *dut, bool direction)
定义 difftest.hpp:89
void(* ref_difftest_init)(int port)
定义 difftest.hpp:92
@ DIFFTEST_TO_REF
定义 difftest.hpp:11
@ DIFFTEST_TO_DUT
定义 difftest.hpp:11
DiffTest difftest
定义 difftest.cpp:8
NEMU 参考模拟器的 CPU 状态布局 必须与参考模拟器中定义的 difftest 寄存器拷贝结构保持绝对一致。
定义 difftest.hpp:17
uint32_t pc
程序计数器
定义 difftest.hpp:19
uint32_t gpr[32]
32个通用寄存器
定义 difftest.hpp:18