diff --git a/nemu/src/cpu/Kconfig b/nemu/src/cpu/Kconfig index 57e94ab..cac6ceb 100644 --- a/nemu/src/cpu/Kconfig +++ b/nemu/src/cpu/Kconfig @@ -90,6 +90,17 @@ menuconfig DTRACE if DTRACE +config DTRACE_COND + string "Only trace device when the condition is true (you can use 'offset' variable)" + default "offset >= 0" + +config DTRACE_WRITE + bool "Enable device trace on write" + default y + +config DTRACE_READ + bool "Enable device trace on read" + default y endif # DTRACE diff --git a/nemu/src/device/io/map.c b/nemu/src/device/io/map.c index c3ab777..8a53450 100644 --- a/nemu/src/device/io/map.c +++ b/nemu/src/device/io/map.c @@ -58,6 +58,10 @@ word_t map_read(paddr_t addr, int len, IOMap *map) { paddr_t offset = addr - map->low; invoke_callback(map->callback, offset, len, false); // prepare data to read word_t ret = host_read(map->space + offset, len); +#ifdef CONFIG_DTRACE_READ + if (CONFIG_DTRACE_COND) log_write("device_read " FMT_WORD " from offset " FMT_PADDR " (%s)\n", + ret, offset, map->name); +#endif //word_t ret = *(word_t*)(map->space + offset); //printf("map_read: %p, %d\n", map->space + offset, ret); return ret; @@ -68,5 +72,9 @@ void map_write(paddr_t addr, int len, word_t data, IOMap *map) { check_bound(map, addr); paddr_t offset = addr - map->low; host_write(map->space + offset, len, data); +#ifdef CONFIG_DTRACE_WRITE + if (CONFIG_DTRACE_COND) log_write("device_write " FMT_WORD " from offset " FMT_PADDR " (%s)\n", + data, offset, map->name); +#endif invoke_callback(map->callback, offset, len, true); }