> compile NEMU
ysyx_22040000 李心杨 Linux calcite 6.6.19 #1-NixOS SMP PREEMPT_DYNAMIC Fri Mar 1 12:35:11 UTC 2024 x86_64 GNU/Linux 17:50:21 up 7:26, 2 users, load average: 0.39, 0.50, 0.54
This commit is contained in:
parent
e391bdd5df
commit
12b18e77fd
2 changed files with 46 additions and 3 deletions
15
nemu/Kconfig
15
nemu/Kconfig
|
@ -159,7 +159,20 @@ config ITRACE_BUFFER
|
||||||
config MTRACE
|
config MTRACE
|
||||||
depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
|
depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
|
||||||
bool "Enable memory tracer"
|
bool "Enable memory tracer"
|
||||||
default n
|
|
||||||
|
|
||||||
|
config MTRACE_RANGE
|
||||||
|
depends on MTRACE
|
||||||
|
string "Memory trace active range"
|
||||||
|
default "0-fffffff"
|
||||||
|
help
|
||||||
|
Memory tracer will only print memory access in these ranges.
|
||||||
|
Use comma to seperate between ranges.
|
||||||
|
|
||||||
|
config MTRACE_RANGE_MAX
|
||||||
|
depends on MTRACE
|
||||||
|
int "Max range count in MTRACE_RANGE"
|
||||||
|
default 10
|
||||||
|
|
||||||
config DIFFTEST
|
config DIFFTEST
|
||||||
depends on TARGET_NATIVE_ELF
|
depends on TARGET_NATIVE_ELF
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* See the Mulan PSL v2 for more details.
|
* See the Mulan PSL v2 for more details.
|
||||||
***************************************************************************************/
|
***************************************************************************************/
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include <memory/host.h>
|
#include <memory/host.h>
|
||||||
#include <memory/paddr.h>
|
#include <memory/paddr.h>
|
||||||
#include <device/mmio.h>
|
#include <device/mmio.h>
|
||||||
|
@ -23,6 +24,11 @@ static uint8_t *pmem = NULL;
|
||||||
#else // CONFIG_PMEM_GARRAY
|
#else // CONFIG_PMEM_GARRAY
|
||||||
static uint8_t pmem[CONFIG_MSIZE] PG_ALIGN = {};
|
static uint8_t pmem[CONFIG_MSIZE] PG_ALIGN = {};
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef CONFIG_MTRACE
|
||||||
|
static word_t mtrace_start[CONFIG_MTRACE_RANGE_MAX] = {0};
|
||||||
|
static word_t mtrace_end[CONFIG_MTRACE_RANGE_MAX] = {0};
|
||||||
|
static int range_count = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t* guest_to_host(paddr_t paddr) { return pmem + paddr - CONFIG_MBASE; }
|
uint8_t* guest_to_host(paddr_t paddr) { return pmem + paddr - CONFIG_MBASE; }
|
||||||
paddr_t host_to_guest(uint8_t *haddr) { return haddr - pmem + CONFIG_MBASE; }
|
paddr_t host_to_guest(uint8_t *haddr) { return haddr - pmem + CONFIG_MBASE; }
|
||||||
|
@ -41,10 +47,34 @@ static void out_of_bound(paddr_t addr) {
|
||||||
addr, PMEM_LEFT, PMEM_RIGHT, cpu.pc);
|
addr, PMEM_LEFT, PMEM_RIGHT, cpu.pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_MTRACE
|
||||||
|
static void mtrace_print(char type, word_t addr, int len, word_t data) {
|
||||||
|
for (int i = 0; i < range_count; i++)
|
||||||
|
if (addr <= mtrace_end[i] && addr >= mtrace_start[i] ) {
|
||||||
|
printf("[TRACE] Mem %c " FMT_WORD "%d D " FMT_WORD "\n", type, addr, len, data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void init_mem() {
|
void init_mem() {
|
||||||
#if defined(CONFIG_PMEM_MALLOC)
|
#if defined(CONFIG_PMEM_MALLOC)
|
||||||
pmem = malloc(CONFIG_MSIZE);
|
pmem = malloc(CONFIG_MSIZE);
|
||||||
assert(pmem);
|
assert(pmem);
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_MTRACE
|
||||||
|
char range[sizeof(CONFIG_MTRACE_RANGE)] = CONFIG_MTRACE_RANGE;
|
||||||
|
char *saveptr, *ptr;
|
||||||
|
ptr = strtok_r(range, ",", &saveptr);
|
||||||
|
for (range_count = 0; range_count < CONFIG_MTRACE_RANGE_MAX; range_count++) {
|
||||||
|
word_t start, end;
|
||||||
|
Assert(sscanf(ptr, "%x-%x", &start, &end) == 2, "Config option MTRACE_RANGE has wrong format");
|
||||||
|
mtrace_start[range_count] = start;
|
||||||
|
mtrace_end[range_count] = end;
|
||||||
|
|
||||||
|
ptr = strtok_r(NULL, ",", &saveptr);
|
||||||
|
if (!ptr) break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
IFDEF(CONFIG_MEM_RANDOM, memset(pmem, rand(), CONFIG_MSIZE));
|
IFDEF(CONFIG_MEM_RANDOM, memset(pmem, rand(), CONFIG_MSIZE));
|
||||||
Log("physical memory area [" FMT_PADDR ", " FMT_PADDR "]", PMEM_LEFT, PMEM_RIGHT);
|
Log("physical memory area [" FMT_PADDR ", " FMT_PADDR "]", PMEM_LEFT, PMEM_RIGHT);
|
||||||
|
@ -57,13 +87,13 @@ word_t paddr_read(paddr_t addr, int len) {
|
||||||
out_of_bound(addr);
|
out_of_bound(addr);
|
||||||
|
|
||||||
mtrace:
|
mtrace:
|
||||||
IFDEF(CONFIG_MTRACE, printf("R " FMT_WORD "%d D " FMT_WORD "\n", addr, len, result));
|
IFDEF(CONFIG_MTRACE, mtrace_print('R', addr, len, result));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void paddr_write(paddr_t addr, int len, word_t data) {
|
void paddr_write(paddr_t addr, int len, word_t data) {
|
||||||
IFDEF(CONFIG_MTRACE, printf("W " FMT_WORD "%d D " FMT_WORD "\n", addr, len, data));
|
IFDEF(CONFIG_MTRACE, mtrace_print('W', addr, len, data));
|
||||||
if (likely(in_pmem(addr))) { pmem_write(addr, len, data); return; }
|
if (likely(in_pmem(addr))) { pmem_write(addr, len, data); return; }
|
||||||
IFDEF(CONFIG_DEVICE, mmio_write(addr, len, data); return);
|
IFDEF(CONFIG_DEVICE, mmio_write(addr, len, data); return);
|
||||||
out_of_bound(addr);
|
out_of_bound(addr);
|
||||||
|
|
Loading…
Reference in a new issue