refactor: drop internal difftest support
This commit is contained in:
parent
f852ee8689
commit
422ff9e006
21 changed files with 192 additions and 433 deletions
9
nemu/include/config.h
Normal file
9
nemu/include/config.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef __NEMU_CONFIG_H__
|
||||
#define __NEMU_CONFIG_H__
|
||||
|
||||
extern char *log_file = NULL;
|
||||
extern char *elf_file = NULL;
|
||||
extern char *img_file = NULL;
|
||||
extern bool enable_gdbstub = false;
|
||||
|
||||
#endif // __NEMU_CONFIG_H__
|
|
@ -1,53 +0,0 @@
|
|||
/***************************************************************************************
|
||||
* 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.
|
||||
***************************************************************************************/
|
||||
|
||||
#ifndef __CPU_DIFFTEST_H__
|
||||
#define __CPU_DIFFTEST_H__
|
||||
|
||||
#include <common.h>
|
||||
#include <difftest-def.h>
|
||||
|
||||
#ifdef CONFIG_DIFFTEST
|
||||
void difftest_skip_ref();
|
||||
void difftest_skip_dut(int nr_ref, int nr_dut);
|
||||
void difftest_set_patch(void (*fn)(void *arg), void *arg);
|
||||
void difftest_step(vaddr_t pc, vaddr_t npc);
|
||||
void difftest_detach();
|
||||
void difftest_attach();
|
||||
#else
|
||||
static inline void difftest_skip_ref() {}
|
||||
static inline void difftest_skip_dut(int nr_ref, int nr_dut) {}
|
||||
static inline void difftest_set_patch(void (*fn)(void *arg), void *arg) {}
|
||||
static inline void difftest_step(vaddr_t pc, vaddr_t npc) {}
|
||||
static inline void difftest_detach() {}
|
||||
static inline void difftest_attach() {}
|
||||
#endif
|
||||
|
||||
extern void (*ref_difftest_memcpy)(paddr_t addr, void *buf, size_t n, bool direction);
|
||||
extern void (*ref_difftest_regcpy)(void *dut, bool direction);
|
||||
extern void (*ref_difftest_exec)(uint64_t n);
|
||||
extern void (*ref_difftest_raise_intr)(uint64_t NO);
|
||||
|
||||
static inline bool difftest_check_reg(const char *name, vaddr_t pc, word_t ref, word_t dut) {
|
||||
if (ref != dut) {
|
||||
Log("%s is different after executing instruction at pc = " FMT_WORD
|
||||
", right = " FMT_WORD ", wrong = " FMT_WORD ", diff = " FMT_WORD,
|
||||
name, pc, ref, dut, ref ^ dut);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -16,10 +16,12 @@
|
|||
#ifndef __DEVICE_MAP_H__
|
||||
#define __DEVICE_MAP_H__
|
||||
|
||||
#include <cpu/difftest.h>
|
||||
#include <difftest.h>
|
||||
#include <stdbool.h>
|
||||
#include <types.h>
|
||||
|
||||
typedef void(*io_callback_t)(uint32_t, int, bool);
|
||||
uint8_t* new_space(int size);
|
||||
typedef void (*io_callback_t)(uint32_t, int, bool);
|
||||
uint8_t *new_space(int size);
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
|
@ -36,19 +38,19 @@ static inline bool map_inside(IOMap *map, paddr_t addr) {
|
|||
|
||||
static inline int find_mapid_by_addr(IOMap *maps, int size, paddr_t addr) {
|
||||
int i;
|
||||
for (i = 0; i < size; i ++) {
|
||||
for (i = 0; i < size; i++) {
|
||||
if (map_inside(maps + i, addr)) {
|
||||
difftest_skip_ref();
|
||||
nemu_do_difftest = false;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void add_pio_map(const char *name, ioaddr_t addr,
|
||||
void *space, uint32_t len, io_callback_t callback);
|
||||
void add_mmio_map(const char *name, paddr_t addr,
|
||||
void *space, uint32_t len, io_callback_t callback);
|
||||
void add_pio_map(const char *name, ioaddr_t addr, void *space, uint32_t len,
|
||||
io_callback_t callback);
|
||||
void add_mmio_map(const char *name, paddr_t addr, void *space, uint32_t len,
|
||||
io_callback_t callback);
|
||||
|
||||
word_t map_read(paddr_t addr, int len, IOMap *map);
|
||||
void map_write(paddr_t addr, int len, word_t data, IOMap *map);
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
/***************************************************************************************
|
||||
* 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.
|
||||
***************************************************************************************/
|
||||
|
||||
#ifndef __DIFFTEST_DEF_H__
|
||||
#define __DIFFTEST_DEF_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <macro.h>
|
||||
#include <generated/autoconf.h>
|
||||
|
||||
#define __EXPORT __attribute__((visibility("default")))
|
||||
enum { DIFFTEST_TO_DUT, DIFFTEST_TO_REF };
|
||||
|
||||
#if defined(CONFIG_ISA_x86)
|
||||
# define DIFFTEST_REG_SIZE (sizeof(uint32_t) * 9) // GPRs + pc
|
||||
#elif defined(CONFIG_ISA_mips32)
|
||||
# define DIFFTEST_REG_SIZE (sizeof(uint32_t) * 38) // GPRs + status + lo + hi + badvaddr + cause + pc
|
||||
#elif defined(CONFIG_ISA_riscv)
|
||||
#define RISCV_GPR_TYPE MUXDEF(CONFIG_RV64, uint64_t, uint32_t)
|
||||
#define RISCV_GPR_NUM MUXDEF(CONFIG_RVE , 16, 32)
|
||||
#define DIFFTEST_REG_SIZE (sizeof(RISCV_GPR_TYPE) * (RISCV_GPR_NUM + 1)) // GPRs + pc
|
||||
#elif defined(CONFIG_ISA_loongarch32r)
|
||||
# define DIFFTEST_REG_SIZE (sizeof(uint32_t) * 33) // GPRs + pc
|
||||
#else
|
||||
# error Unsupport ISA
|
||||
#endif
|
||||
|
||||
#endif
|
8
nemu/include/difftest.h
Normal file
8
nemu/include/difftest.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef __NEMU_DIFFTEST_H__
|
||||
#define __NEMU_DIFFTEST_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
extern bool nemu_do_difftest;
|
||||
|
||||
#endif // __NEMU_DIFFTEST_H__
|
|
@ -29,7 +29,7 @@
|
|||
#define ARRLEN(arr) (int)(sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
// macro concatenation
|
||||
#define concat_temp(x, y) x ## y
|
||||
#define concat_temp(x, y) x##y
|
||||
#define concat(x, y) concat_temp(x, y)
|
||||
#define concat3(x, y, z) concat(concat(x, y), z)
|
||||
#define concat4(x, y, z, w) concat3(concat(x, y), z, w)
|
||||
|
@ -39,17 +39,18 @@
|
|||
// See https://stackoverflow.com/questions/26099745/test-if-preprocessor-symbol-is-defined-inside-macro
|
||||
#define CHOOSE2nd(a, b, ...) b
|
||||
#define MUX_WITH_COMMA(contain_comma, a, b) CHOOSE2nd(contain_comma a, b)
|
||||
#define MUX_MACRO_PROPERTY(p, macro, a, b) MUX_WITH_COMMA(concat(p, macro), a, b)
|
||||
#define MUX_MACRO_PROPERTY(p, macro, a, b) \
|
||||
MUX_WITH_COMMA(concat(p, macro), a, b)
|
||||
// define placeholders for some property
|
||||
#define __P_DEF_0 X,
|
||||
#define __P_DEF_1 X,
|
||||
#define __P_ONE_1 X,
|
||||
#define __P_DEF_0 X,
|
||||
#define __P_DEF_1 X,
|
||||
#define __P_ONE_1 X,
|
||||
#define __P_ZERO_0 X,
|
||||
// define some selection functions based on the properties of BOOLEAN macro
|
||||
#define MUXDEF(macro, X, Y) MUX_MACRO_PROPERTY(__P_DEF_, macro, X, Y)
|
||||
#define MUXDEF(macro, X, Y) MUX_MACRO_PROPERTY(__P_DEF_, macro, X, Y)
|
||||
#define MUXNDEF(macro, X, Y) MUX_MACRO_PROPERTY(__P_DEF_, macro, Y, X)
|
||||
#define MUXONE(macro, X, Y) MUX_MACRO_PROPERTY(__P_ONE_, macro, X, Y)
|
||||
#define MUXZERO(macro, X, Y) MUX_MACRO_PROPERTY(__P_ZERO_,macro, X, Y)
|
||||
#define MUXONE(macro, X, Y) MUX_MACRO_PROPERTY(__P_ONE_, macro, X, Y)
|
||||
#define MUXZERO(macro, X, Y) MUX_MACRO_PROPERTY(__P_ZERO_, macro, X, Y)
|
||||
|
||||
// test if a boolean macro is defined
|
||||
#define ISDEF(macro) MUXDEF(macro, 1, 0)
|
||||
|
@ -84,29 +85,46 @@
|
|||
#define MAP(c, f) c(f)
|
||||
|
||||
#define BITMASK(bits) ((1ull << (bits)) - 1)
|
||||
#define BITS(x, hi, lo) (((x) >> (lo)) & BITMASK((hi) - (lo) + 1)) // similar to x[hi:lo] in verilog
|
||||
#define SEXT(x, len) ({ struct { int64_t n : len; } __x = { .n = x }; (uint64_t)__x.n; })
|
||||
#define BITS(x, hi, lo) \
|
||||
(((x) >> (lo)) & BITMASK((hi) - (lo) + 1)) // similar to x[hi:lo] in verilog
|
||||
#define SEXT(x, len) \
|
||||
({ \
|
||||
struct { \
|
||||
int64_t n : len; \
|
||||
} __x = {.n = x}; \
|
||||
(uint64_t) __x.n; \
|
||||
})
|
||||
|
||||
#define ROUNDUP(a, sz) ((((uintptr_t)a) + (sz) - 1) & ~((sz) - 1))
|
||||
#define ROUNDDOWN(a, sz) ((((uintptr_t)a)) & ~((sz) - 1))
|
||||
#define ROUNDUP(a, sz) ((((uintptr_t)a) + (sz)-1) & ~((sz)-1))
|
||||
#define ROUNDDOWN(a, sz) ((((uintptr_t)a)) & ~((sz)-1))
|
||||
|
||||
#define PG_ALIGN __attribute((aligned(4096)))
|
||||
|
||||
#define FAILED_GOTO(tag, exp) do {if((exp)) goto tag;} while(0)
|
||||
#define FAILED_GOTO(tag, exp) \
|
||||
do { \
|
||||
if ((exp)) \
|
||||
goto tag; \
|
||||
} while (0)
|
||||
|
||||
#if !defined(likely)
|
||||
#define likely(cond) __builtin_expect(cond, 1)
|
||||
#define likely(cond) __builtin_expect(cond, 1)
|
||||
#define unlikely(cond) __builtin_expect(cond, 0)
|
||||
#endif
|
||||
|
||||
// for AM IOE
|
||||
#define io_read(reg) \
|
||||
({ reg##_T __io_param; \
|
||||
ioe_read(reg, &__io_param); \
|
||||
__io_param; })
|
||||
#define __EXPORT __attribute__((visibility("default")))
|
||||
|
||||
#define io_write(reg, ...) \
|
||||
({ reg##_T __io_param = (reg##_T) { __VA_ARGS__ }; \
|
||||
ioe_write(reg, &__io_param); })
|
||||
// for AM IOE
|
||||
#define io_read(reg) \
|
||||
({ \
|
||||
reg##_T __io_param; \
|
||||
ioe_read(reg, &__io_param); \
|
||||
__io_param; \
|
||||
})
|
||||
|
||||
#define io_write(reg, ...) \
|
||||
({ \
|
||||
reg##_T __io_param = (reg##_T){__VA_ARGS__}; \
|
||||
ioe_write(reg, &__io_param); \
|
||||
})
|
||||
|
||||
#endif
|
||||
|
|
28
nemu/include/nemu.h
Normal file
28
nemu/include/nemu.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef __NEMU_HEADER__
|
||||
#define __NEMU_HEADER__
|
||||
|
||||
#include <stddef.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <gdbstub.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
int nemu_read_mem(void *args, size_t addr, size_t len, void *val);
|
||||
int nemu_write_mem(void *args, size_t addr, size_t len, void *val);
|
||||
void nemu_cont(void *args, gdb_action_t *res);
|
||||
void nemu_stepi(void *args, gdb_action_t *res);
|
||||
bool nemu_set_bp(void *args, size_t addr, bp_type_t type);
|
||||
bool nemu_del_bp(void *args, size_t addr, bp_type_t type);
|
||||
void nemu_on_interrupt(void *args);
|
||||
int nemu_read_reg(void *args, int regno, size_t *data);
|
||||
int nemu_write_reg(void *args, int regno, size_t data);
|
||||
void nemu_init(void *args);
|
||||
|
||||
extern arch_info_t nemu_isa_arch_info;
|
||||
extern bool nemu_do_difftest;
|
||||
extern bool nemu_dbg_state_size;
|
||||
|
||||
#endif // __NEMU_HEADER__
|
Loading…
Add table
Add a link
Reference in a new issue