summaryrefslogtreecommitdiffstats
path: root/src/emu/debug/debugcmd.cpp
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2017-07-31 23:47:16 -0400
committer AJR <ajrhacker@users.noreply.github.com>2017-08-01 00:21:19 -0400
commitbb0964f9a284b15851773f5428bd602ca01cc28b (patch)
treee2c7c0dc17e42a88046cf6de8b357daee868b9d9 /src/emu/debug/debugcmd.cpp
parentd050ba956ed79015389bc2cba7399db9cbd62684 (diff)
Changes to debugger memory address translation
- memory_translate now returns an address space number rather a boolean flag, permitting addresses in part of one space to map to an entirely different space. This is primarily intended to help MCUs which have blocks of internal memory that can be dynamically remapped, but may also allow for more accurate emulation of MMUs that drive multiple external address spaces, since the old limit of four address spaces per MAME device has been lifted. - memory_translate has also been made a const method, in spite of a couple of badly behaved CPU cores that can't honestly treat it as one. - The (read|write)_(byte|word|dword|qword|memory|opcode) accessors have been transferred from debugger_cpu to device_memory_interface, with somewhat modified arguments corresponding to the translate function it calls through to if requested.
Diffstat (limited to 'src/emu/debug/debugcmd.cpp')
-rw-r--r--src/emu/debug/debugcmd.cpp67
1 files changed, 33 insertions, 34 deletions
diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp
index f3650bdef92..a8d1b93ca15 100644
--- a/src/emu/debug/debugcmd.cpp
+++ b/src/emu/debug/debugcmd.cpp
@@ -41,7 +41,9 @@ const size_t debugger_commands::MAX_GLOBALS = 1000;
bool debugger_commands::cheat_address_is_valid(address_space &space, offs_t address)
{
- return space.device().memory().translate(space.spacenum(), TRANSLATE_READ, address) && (space.get_write_ptr(address) != nullptr);
+ device_memory_interface &memory = space.device().memory();
+ int tspacenum = memory.translate(space.spacenum(), TRANSLATE_READ, address);
+ return tspacenum != AS_INVALID && memory.space(tspacenum).get_write_ptr(address) != nullptr;
}
@@ -91,7 +93,7 @@ u64 debugger_commands::cheat_byte_swap(const cheat_system *cheatsys, u64 value)
u64 debugger_commands::cheat_read_extended(const cheat_system *cheatsys, address_space &space, offs_t address)
{
- return cheat_sign_extend(cheatsys, cheat_byte_swap(cheatsys, m_cpu.read_memory(space, address, cheatsys->width, true)));
+ return cheat_sign_extend(cheatsys, cheat_byte_swap(cheatsys, space.device().memory().read_memory(space.spacenum(), address, cheatsys->width, TRANSLATE_READ_DEBUG)));
}
debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu, debugger_console& console)
@@ -1667,9 +1669,10 @@ void debugger_commands::execute_save(int ref, const std::vector<std::string> &pa
}
/* now write the data out */
+ device_memory_interface &memory = space->device().memory();
for (i = offset; i <= endoffset; i++)
{
- u8 byte = m_cpu.read_byte(*space, i, true);
+ u8 byte = memory.read_byte(space->spacenum(), i, TRANSLATE_READ_DEBUG);
fwrite(&byte, 1, 1, f);
}
@@ -1719,12 +1722,13 @@ void debugger_commands::execute_load(int ref, const std::vector<std::string> &pa
offset = space->address_to_byte(offset) & space->bytemask();
// now read the data in, ignore endoffset and load entire file if length has been set to zero (offset-1)
+ device_memory_interface &memory = space->device().memory();
for (i = offset; f.good() && (i <= endoffset || endoffset == offset - 1); i++)
{
char byte;
f.read(&byte, 1);
if (f)
- m_cpu.write_byte(*space, i, byte, true);
+ memory.write_byte(space->spacenum(), i, byte, TRANSLATE_WRITE_DEBUG);
}
if (!f.good())
@@ -1783,6 +1787,7 @@ void debugger_commands::execute_dump(int ref, const std::vector<std::string> &pa
return;
}
+ device_memory_interface &memory = space->device().memory();
u64 endoffset = space->address_to_byte(offset + length - 1) & space->bytemask();
offset = space->address_to_byte(offset) & space->bytemask();
@@ -1811,9 +1816,9 @@ void debugger_commands::execute_dump(int ref, const std::vector<std::string> &pa
if (i + j <= endoffset)
{
offs_t curaddr = i + j;
- if (space->device().memory().translate(space->spacenum(), TRANSLATE_READ_DEBUG, curaddr))
+ if (memory.translate(space->spacenum(), TRANSLATE_READ_DEBUG, curaddr) != AS_INVALID)
{
- u64 value = m_cpu.read_memory(*space, i + j, width, true);
+ u64 value = memory.read_memory(space->spacenum(), i + j, width, TRANSLATE_READ_DEBUG);
util::stream_format(output, " %0*X", width * 2, value);
}
else
@@ -1832,9 +1837,9 @@ void debugger_commands::execute_dump(int ref, const std::vector<std::string> &pa
for (u64 j = 0; j < rowsize && (i + j) <= endoffset; j++)
{
offs_t curaddr = i + j;
- if (space->device().memory().translate(space->spacenum(), TRANSLATE_READ_DEBUG, curaddr))
+ if (memory.translate(space->spacenum(), TRANSLATE_READ_DEBUG, curaddr) != AS_INVALID)
{
- u8 byte = m_cpu.read_byte(*space, i + j, true);
+ u8 byte = memory.read_byte(space->spacenum(), i + j, TRANSLATE_READ_DEBUG);
util::stream_format(output, "%c", (byte >= 32 && byte < 127) ? byte : '.');
}
else
@@ -2363,6 +2368,8 @@ void debugger_commands::execute_find(int ref, const std::vector<std::string> &pa
}
/* now search */
+ device_memory_interface &memory = space->device().memory();
+ int spacenum = space->spacenum();
for (u64 i = offset; i <= endoffset; i += data_size[0])
{
int suboffset = 0;
@@ -2373,10 +2380,10 @@ void debugger_commands::execute_find(int ref, const std::vector<std::string> &pa
{
switch (data_size[j])
{
- case 1: match = (u8(m_cpu.read_byte(*space, i + suboffset, true)) == u8(data_to_find[j])); break;
- case 2: match = (u16(m_cpu.read_word(*space, i + suboffset, true)) == u16(data_to_find[j])); break;
- case 4: match = (u32(m_cpu.read_dword(*space, i + suboffset, true)) == u32(data_to_find[j])); break;
- case 8: match = (u64(m_cpu.read_qword(*space, i + suboffset, true)) == u64(data_to_find[j])); break;
+ case 1: match = (u8(memory.read_byte(spacenum, i + suboffset, TRANSLATE_READ_DEBUG)) == u8(data_to_find[j])); break;
+ case 2: match = (u16(memory.read_word(spacenum, i + suboffset, TRANSLATE_READ_DEBUG)) == u16(data_to_find[j])); break;
+ case 4: match = (u32(memory.read_dword(spacenum, i + suboffset, TRANSLATE_READ_DEBUG)) == u32(data_to_find[j])); break;
+ case 8: match = (u64(memory.read_qword(spacenum, i + suboffset, TRANSLATE_READ_DEBUG)) == u64(data_to_find[j])); break;
default: /* all other cases are wildcards */ break;
}
suboffset += data_size[j] & 0x0f;
@@ -2404,7 +2411,7 @@ void debugger_commands::execute_dasm(int ref, const std::vector<std::string> &pa
{
u64 offset, length, bytes = 1;
int minbytes, maxbytes, byteswidth;
- address_space *space, *decrypted_space;
+ address_space *space;
FILE *f;
int j;
@@ -2417,10 +2424,7 @@ void debugger_commands::execute_dasm(int ref, const std::vector<std::string> &pa
return;
if (!validate_cpu_space_parameter(params.size() > 4 ? params[4].c_str() : nullptr, AS_PROGRAM, space))
return;
- if (space->device().memory().has_space(AS_OPCODES))
- decrypted_space = &space->device().memory().space(AS_OPCODES);
- else
- decrypted_space = space;
+ int opcode_spacenum = space->device().memory().has_space(AS_OPCODES) ? AS_OPCODES : space->spacenum();
/* determine the width of the bytes */
device_disasm_interface *dasmintf;
@@ -2454,7 +2458,6 @@ void debugger_commands::execute_dasm(int ref, const std::vector<std::string> &pa
{
int pcbyte = space->address_to_byte(offset + i) & space->bytemask();
const char *comment;
- offs_t tempaddr;
int numbytes = 0;
output.clear();
output.rdbuf()->clear();
@@ -2465,8 +2468,8 @@ void debugger_commands::execute_dasm(int ref, const std::vector<std::string> &pa
stream_format(output, "%0*X: ", space->logaddrchars(), u32(space->byte_to_address(pcbyte)));
/* make sure we can translate the address */
- tempaddr = pcbyte;
- if (space->device().memory().translate(space->spacenum(), TRANSLATE_FETCH_DEBUG, tempaddr))
+ offs_t tempaddr = pcbyte;
+ if (space->device().memory().translate(space->spacenum(), TRANSLATE_FETCH_DEBUG, tempaddr) != AS_INVALID)
{
{
u8 opbuf[64], argbuf[64];
@@ -2474,8 +2477,8 @@ void debugger_commands::execute_dasm(int ref, const std::vector<std::string> &pa
/* fetch the bytes up to the maximum */
for (numbytes = 0; numbytes < maxbytes; numbytes++)
{
- opbuf[numbytes] = m_cpu.read_opcode(*decrypted_space, pcbyte + numbytes, 1);
- argbuf[numbytes] = m_cpu.read_opcode(*space, pcbyte + numbytes, 1);
+ opbuf[numbytes] = space->device().memory().read_opcode(opcode_spacenum, pcbyte + numbytes, 1);
+ argbuf[numbytes] = space->device().memory().read_opcode(space->spacenum(), pcbyte + numbytes, 1);
}
/* disassemble the result */
@@ -2488,7 +2491,7 @@ void debugger_commands::execute_dasm(int ref, const std::vector<std::string> &pa
auto const startdex = output.tellp();
numbytes = space->address_to_byte(numbytes);
for (j = 0; j < numbytes; j += minbytes)
- stream_format(output, "%0*X ", minbytes * 2, m_cpu.read_opcode(*decrypted_space, pcbyte + j, minbytes));
+ stream_format(output, "%0*X ", minbytes * 2, space->device().memory().read_opcode(opcode_spacenum, pcbyte + j, minbytes));
if ((output.tellp() - startdex) < byteswidth)
stream_format(output, "%*s", byteswidth - (output.tellp() - startdex), "");
stream_format(output, " ");
@@ -2640,13 +2643,10 @@ void debugger_commands::execute_traceflush(int ref, const std::vector<std::strin
void debugger_commands::execute_history(int ref, const std::vector<std::string> &params)
{
/* validate parameters */
- address_space *space, *decrypted_space;
+ address_space *space;
if (!validate_cpu_space_parameter(!params.empty() ? params[0].c_str() : nullptr, AS_PROGRAM, space))
return;
- if (space->device().memory().has_space(AS_OPCODES))
- decrypted_space = &space->device().memory().space(AS_OPCODES);
- else
- decrypted_space = space;
+ int opcode_spacenum = space->device().memory().has_space(AS_OPCODES) ? AS_OPCODES : space->spacenum();
u64 count = device_debug::HISTORY_SIZE;
if (params.size() > 1 && !validate_number_parameter(params[1], count))
@@ -2675,8 +2675,8 @@ void debugger_commands::execute_history(int ref, const std::vector<std::string>
u8 opbuf[64], argbuf[64];
for (int numbytes = 0; numbytes < maxbytes; numbytes++)
{
- opbuf[numbytes] = m_cpu.read_opcode(*decrypted_space, pcbyte + numbytes, 1);
- argbuf[numbytes] = m_cpu.read_opcode(*space, pcbyte + numbytes, 1);
+ opbuf[numbytes] = space->device().memory().read_opcode(opcode_spacenum, pcbyte + numbytes, 1);
+ argbuf[numbytes] = space->device().memory().read_opcode(space->spacenum(), pcbyte + numbytes, 1);
}
util::ovectorstream buffer;
@@ -2791,7 +2791,7 @@ void debugger_commands::execute_pcatmem(int ref, const std::vector<std::string>
// Get the value of memory at the address
const int native_data_width = space->data_width() / 8;
- const u64 data = m_cpu.read_memory(*space, space->address_to_byte(address), native_data_width, true);
+ const u64 data = space->device().memory().read_memory(space->spacenum(), space->address_to_byte(address), native_data_width, TRANSLATE_READ_DEBUG);
// Recover the pc & print
const int space_num = (int)ref;
@@ -2866,7 +2866,6 @@ void debugger_commands::execute_source(int ref, const std::vector<std::string> &
void debugger_commands::execute_map(int ref, const std::vector<std::string> &params)
{
address_space *space;
- offs_t taddress;
u64 address;
int intention;
@@ -2882,8 +2881,8 @@ void debugger_commands::execute_map(int ref, const std::vector<std::string> &par
for (intention = TRANSLATE_READ_DEBUG; intention <= TRANSLATE_FETCH_DEBUG; intention++)
{
static const char *const intnames[] = { "Read", "Write", "Fetch" };
- taddress = space->address_to_byte(address) & space->bytemask();
- if (space->device().memory().translate(space->spacenum(), intention, taddress))
+ offs_t taddress = space->address_to_byte(address) & space->bytemask();
+ if (space->device().memory().translate(space->spacenum(), intention, taddress) != AS_INVALID)
{
const char *mapname = space->get_handler_string((intention == TRANSLATE_WRITE_DEBUG) ? read_or_write::WRITE : read_or_write::READ, taddress);
m_console.printf(