From 2cdb10de7e841a1aaf445eb2d617b35a68881485 Mon Sep 17 00:00:00 2001 From: Daniel Selifonov Date: Sun, 28 Oct 2018 16:45:03 -0700 Subject: [PATCH] Added "translate" debugger command for virtual->physical address lookup --- src/core_interface.c | 3 +++ src/core_interface.h | 1 + src/debugger.c | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/src/core_interface.c b/src/core_interface.c index a353741..f978d1b 100644 --- a/src/core_interface.c +++ b/src/core_interface.c @@ -112,6 +112,7 @@ ptr_DebugBreakpointLookup DebugBreakpointLookup = NULL; ptr_DebugBreakpointCommand DebugBreakpointCommand = NULL; ptr_DebugBreakpointTriggeredBy DebugBreakpointTriggeredBy = NULL; +ptr_DebugVirtualToPhysical DebugVirtualToPhysical = NULL; /* global variables */ m64p_dynlib_handle CoreHandle = NULL; @@ -302,6 +303,7 @@ m64p_error AttachCoreLib(const char *CoreLibFilepath) DebugBreakpointCommand = (ptr_DebugBreakpointCommand) osal_dynlib_getproc(CoreHandle, "DebugBreakpointCommand"); DebugBreakpointTriggeredBy = (ptr_DebugBreakpointTriggeredBy) osal_dynlib_getproc(CoreHandle, "DebugBreakpointTriggeredBy"); + DebugVirtualToPhysical = (ptr_DebugVirtualToPhysical) osal_dynlib_getproc(CoreHandle, "DebugVirtualToPhysical"); return M64ERR_SUCCESS; } @@ -371,6 +373,7 @@ m64p_error DetachCoreLib(void) DebugBreakpointCommand = NULL; DebugBreakpointTriggeredBy = NULL; + DebugVirtualToPhysical = NULL; /* detach the shared library */ osal_dynlib_close(CoreHandle); diff --git a/src/core_interface.h b/src/core_interface.h index cbd9119..a0c9883 100644 --- a/src/core_interface.h +++ b/src/core_interface.h @@ -105,6 +105,7 @@ extern ptr_DebugBreakpointLookup DebugBreakpointLookup; extern ptr_DebugBreakpointCommand DebugBreakpointCommand; extern ptr_DebugBreakpointTriggeredBy DebugBreakpointTriggeredBy; +extern ptr_DebugVirtualToPhysical DebugVirtualToPhysical; #endif /* #define CORE_INTERFACE_H */ diff --git a/src/debugger.c b/src/debugger.c index e40dd01..99718b6 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -347,6 +347,16 @@ int debugger_loop(void *arg) { printf("\n"); } } + else if (strncmp(input, "translate", 9) == 0) { + uint32_t virt_addr, phys_addr; + if (sscanf(input, "translate %i", &virt_addr) == 1) { + } else { + printf("Improperly formatted translate command: '%s'\n", input); + continue; + } + phys_addr = (*DebugVirtualToPhysical)(virt_addr); + printf("virtual 0x%08x -> physical 0x%08x\n", virt_addr, phys_addr); + } else if (strncmp(input, "write", 5) == 0) { uint32_t writeAddr, size=1; uint64_t writeVal;