Allow any device memory (not just CPU's) to be accessed via debug expressions.

Change eeprom accessors to require the eeprom device name.
This commit is contained in:
Aaron Giles 2009-12-27 23:10:25 +00:00
parent 0e058f3762
commit 96f9302a8c

View File

@ -25,7 +25,7 @@
#include "debugvw.h" #include "debugvw.h"
#include "debugger.h" #include "debugger.h"
#include "uiinput.h" #include "uiinput.h"
#include "machine/eeprom.h" #include "machine/eepromdev.h"
#include <ctype.h> #include <ctype.h>
@ -101,11 +101,11 @@ static UINT32 dasm_wrapped(const device_config *device, char *buffer, offs_t pc)
static UINT64 expression_read_memory(void *param, const char *name, int space, UINT32 address, int size); static UINT64 expression_read_memory(void *param, const char *name, int space, UINT32 address, int size);
static UINT64 expression_read_program_direct(const address_space *space, int opcode, offs_t address, int size); static UINT64 expression_read_program_direct(const address_space *space, int opcode, offs_t address, int size);
static UINT64 expression_read_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size); static UINT64 expression_read_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size);
static UINT64 expression_read_eeprom(running_machine *machine, offs_t address, int size); static UINT64 expression_read_eeprom(const device_config *device, offs_t address, int size);
static void expression_write_memory(void *param, const char *name, int space, UINT32 address, int size, UINT64 data); static void expression_write_memory(void *param, const char *name, int space, UINT32 address, int size, UINT64 data);
static void expression_write_program_direct(const address_space *space, int opcode, offs_t address, int size, UINT64 data); static void expression_write_program_direct(const address_space *space, int opcode, offs_t address, int size, UINT64 data);
static void expression_write_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size, UINT64 data); static void expression_write_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size, UINT64 data);
static void expression_write_eeprom(running_machine *machine, offs_t address, int size, UINT64 data); static void expression_write_eeprom(const device_config *device, offs_t address, int size, UINT64 data);
static EXPRERR expression_validate(void *param, const char *name, int space); static EXPRERR expression_validate(void *param, const char *name, int space);
/* variable getters/setters */ /* variable getters/setters */
@ -2437,17 +2437,17 @@ static UINT32 dasm_wrapped(const device_config *device, char *buffer, offs_t pc)
***************************************************************************/ ***************************************************************************/
/*------------------------------------------------- /*-------------------------------------------------
expression_cpu_index - return the CPU index expression_get_device - return a device
based on a case insensitive tag search based on a case insensitive tag search
-------------------------------------------------*/ -------------------------------------------------*/
static const device_config *expression_cpu_index(running_machine *machine, const char *tag) static const device_config *expression_get_device(running_machine *machine, const char *tag)
{ {
const device_config *cpu; const device_config *device;
for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu)) for (device = machine->config->devicelist.head; device != NULL; device = device->next)
if (mame_stricmp(cpu->tag, tag) == 0) if (mame_stricmp(device->tag, tag) == 0)
return cpu; return device;
return NULL; return NULL;
} }
@ -2463,7 +2463,7 @@ static UINT64 expression_read_memory(void *param, const char *name, int spacenum
{ {
running_machine *machine = (running_machine *)param; running_machine *machine = (running_machine *)param;
UINT64 result = ~(UINT64)0 >> (64 - 8*size); UINT64 result = ~(UINT64)0 >> (64 - 8*size);
const device_config *cpu = NULL; const device_config *device = NULL;
const address_space *space; const address_space *space;
switch (spacenum) switch (spacenum)
@ -2473,10 +2473,10 @@ static UINT64 expression_read_memory(void *param, const char *name, int spacenum
case EXPSPACE_IO_LOGICAL: case EXPSPACE_IO_LOGICAL:
case EXPSPACE_SPACE3_LOGICAL: case EXPSPACE_SPACE3_LOGICAL:
if (name != NULL) if (name != NULL)
cpu = expression_cpu_index(machine, name); device = expression_get_device(machine, name);
if (cpu == NULL) if (device == NULL)
cpu = debug_cpu_get_visible_cpu(machine); device = debug_cpu_get_visible_cpu(machine);
space = cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_LOGICAL)); space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_LOGICAL));
if (space != NULL) if (space != NULL)
result = debug_read_memory(space, memory_address_to_byte(space, address), size, TRUE); result = debug_read_memory(space, memory_address_to_byte(space, address), size, TRUE);
break; break;
@ -2486,10 +2486,10 @@ static UINT64 expression_read_memory(void *param, const char *name, int spacenum
case EXPSPACE_IO_PHYSICAL: case EXPSPACE_IO_PHYSICAL:
case EXPSPACE_SPACE3_PHYSICAL: case EXPSPACE_SPACE3_PHYSICAL:
if (name != NULL) if (name != NULL)
cpu = expression_cpu_index(machine, name); device = expression_get_device(machine, name);
if (cpu == NULL) if (device == NULL)
cpu = debug_cpu_get_visible_cpu(machine); device = debug_cpu_get_visible_cpu(machine);
space = cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_PHYSICAL)); space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_PHYSICAL));
if (space != NULL) if (space != NULL)
result = debug_read_memory(space, memory_address_to_byte(space, address), size, FALSE); result = debug_read_memory(space, memory_address_to_byte(space, address), size, FALSE);
break; break;
@ -2497,14 +2497,17 @@ static UINT64 expression_read_memory(void *param, const char *name, int spacenum
case EXPSPACE_OPCODE: case EXPSPACE_OPCODE:
case EXPSPACE_RAMWRITE: case EXPSPACE_RAMWRITE:
if (name != NULL) if (name != NULL)
cpu = expression_cpu_index(machine, name); device = expression_get_device(machine, name);
if (cpu == NULL) if (device == NULL)
cpu = debug_cpu_get_visible_cpu(machine); device = debug_cpu_get_visible_cpu(machine);
result = expression_read_program_direct(cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size); result = expression_read_program_direct(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size);
break; break;
case EXPSPACE_EEPROM: case EXPSPACE_EEPROM:
result = expression_read_eeprom(machine, address, size); if (name != NULL)
device = expression_get_device(machine, name);
if (device != NULL)
result = expression_read_eeprom(device, address, size);
break; break;
case EXPSPACE_REGION: case EXPSPACE_REGION:
@ -2632,14 +2635,14 @@ static UINT64 expression_read_memory_region(running_machine *machine, const char
expression_read_eeprom - read EEPROM data expression_read_eeprom - read EEPROM data
-------------------------------------------------*/ -------------------------------------------------*/
static UINT64 expression_read_eeprom(running_machine *machine, offs_t address, int size) static UINT64 expression_read_eeprom(const device_config *device, offs_t address, int size)
{ {
UINT64 result = ~(UINT64)0 >> (64 - 8*size); UINT64 result = ~(UINT64)0 >> (64 - 8*size);
UINT32 eelength, eesize; UINT32 eelength, eesize;
void *base; void *base;
/* make sure we get a valid base before proceeding */ /* make sure we get a valid base before proceeding */
base = eeprom_get_data_pointer(&eelength, &eesize); base = eepromdev_get_data_pointer(device, &eelength, &eesize);
if (base != NULL && address < eelength) if (base != NULL && address < eelength)
{ {
/* switch off the size */ /* switch off the size */
@ -2662,7 +2665,7 @@ static UINT64 expression_read_eeprom(running_machine *machine, offs_t address, i
static void expression_write_memory(void *param, const char *name, int spacenum, UINT32 address, int size, UINT64 data) static void expression_write_memory(void *param, const char *name, int spacenum, UINT32 address, int size, UINT64 data)
{ {
running_machine *machine = (running_machine *)param; running_machine *machine = (running_machine *)param;
const device_config *cpu = NULL; const device_config *device = NULL;
const address_space *space; const address_space *space;
switch (spacenum) switch (spacenum)
@ -2672,10 +2675,10 @@ static void expression_write_memory(void *param, const char *name, int spacenum,
case EXPSPACE_IO_LOGICAL: case EXPSPACE_IO_LOGICAL:
case EXPSPACE_SPACE3_LOGICAL: case EXPSPACE_SPACE3_LOGICAL:
if (name != NULL) if (name != NULL)
cpu = expression_cpu_index(machine, name); device = expression_get_device(machine, name);
if (cpu == NULL) if (device == NULL)
cpu = debug_cpu_get_visible_cpu(machine); device = debug_cpu_get_visible_cpu(machine);
space = cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_LOGICAL)); space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_LOGICAL));
if (space != NULL) if (space != NULL)
debug_write_memory(space, memory_address_to_byte(space, address), data, size, TRUE); debug_write_memory(space, memory_address_to_byte(space, address), data, size, TRUE);
break; break;
@ -2685,10 +2688,10 @@ static void expression_write_memory(void *param, const char *name, int spacenum,
case EXPSPACE_IO_PHYSICAL: case EXPSPACE_IO_PHYSICAL:
case EXPSPACE_SPACE3_PHYSICAL: case EXPSPACE_SPACE3_PHYSICAL:
if (name != NULL) if (name != NULL)
cpu = expression_cpu_index(machine, name); device = expression_get_device(machine, name);
if (cpu == NULL) if (device == NULL)
cpu = debug_cpu_get_visible_cpu(machine); device = debug_cpu_get_visible_cpu(machine);
space = cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_PHYSICAL)); space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_PHYSICAL));
if (space != NULL) if (space != NULL)
debug_write_memory(space, memory_address_to_byte(space, address), data, size, FALSE); debug_write_memory(space, memory_address_to_byte(space, address), data, size, FALSE);
break; break;
@ -2696,14 +2699,17 @@ static void expression_write_memory(void *param, const char *name, int spacenum,
case EXPSPACE_OPCODE: case EXPSPACE_OPCODE:
case EXPSPACE_RAMWRITE: case EXPSPACE_RAMWRITE:
if (name != NULL) if (name != NULL)
cpu = expression_cpu_index(machine, name); device = expression_get_device(machine, name);
if (cpu == NULL) if (device == NULL)
cpu = debug_cpu_get_visible_cpu(machine); device = debug_cpu_get_visible_cpu(machine);
expression_write_program_direct(cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size, data); expression_write_program_direct(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size, data);
break; break;
case EXPSPACE_EEPROM: case EXPSPACE_EEPROM:
expression_write_eeprom(machine, address, size, data); if (name != NULL)
device = expression_get_device(machine, name);
if (device != NULL)
expression_write_eeprom(device, address, size, data);
break; break;
case EXPSPACE_REGION: case EXPSPACE_REGION:
@ -2843,11 +2849,11 @@ static void expression_write_memory_region(running_machine *machine, const char
expression_write_eeprom - write EEPROM data expression_write_eeprom - write EEPROM data
-------------------------------------------------*/ -------------------------------------------------*/
static void expression_write_eeprom(running_machine *machine, offs_t address, int size, UINT64 data) static void expression_write_eeprom(const device_config *device, offs_t address, int size, UINT64 data)
{ {
debugcpu_private *global = machine->debugcpu_data; debugcpu_private *global = device->machine->debugcpu_data;
UINT32 eelength, eesize; UINT32 eelength, eesize;
void *vbase = eeprom_get_data_pointer(&eelength, &eesize); void *vbase = eepromdev_get_data_pointer(device, &eelength, &eesize);
/* make sure we get a valid base before proceeding */ /* make sure we get a valid base before proceeding */
if (vbase != NULL && address < eelength) if (vbase != NULL && address < eelength)
@ -2887,7 +2893,7 @@ static void expression_write_eeprom(running_machine *machine, offs_t address, in
static EXPRERR expression_validate(void *param, const char *name, int space) static EXPRERR expression_validate(void *param, const char *name, int space)
{ {
running_machine *machine = (running_machine *)param; running_machine *machine = (running_machine *)param;
const device_config *cpu = NULL; const device_config *device = NULL;
switch (space) switch (space)
{ {
@ -2897,13 +2903,13 @@ static EXPRERR expression_validate(void *param, const char *name, int space)
case EXPSPACE_SPACE3_LOGICAL: case EXPSPACE_SPACE3_LOGICAL:
if (name != NULL) if (name != NULL)
{ {
cpu = expression_cpu_index(machine, name); device = expression_get_device(machine, name);
if (cpu == NULL) if (device == NULL)
return EXPRERR_INVALID_MEMORY_NAME; return EXPRERR_INVALID_MEMORY_NAME;
} }
if (cpu == NULL) if (device == NULL)
cpu = debug_cpu_get_visible_cpu(machine); device = debug_cpu_get_visible_cpu(machine);
if (cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (space - EXPSPACE_PROGRAM_LOGICAL)) == NULL) if (cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (space - EXPSPACE_PROGRAM_LOGICAL)) == NULL)
return EXPRERR_NO_SUCH_MEMORY_SPACE; return EXPRERR_NO_SUCH_MEMORY_SPACE;
break; break;
@ -2913,13 +2919,13 @@ static EXPRERR expression_validate(void *param, const char *name, int space)
case EXPSPACE_SPACE3_PHYSICAL: case EXPSPACE_SPACE3_PHYSICAL:
if (name != NULL) if (name != NULL)
{ {
cpu = expression_cpu_index(machine, name); device = expression_get_device(machine, name);
if (cpu == NULL) if (device == NULL)
return EXPRERR_INVALID_MEMORY_NAME; return EXPRERR_INVALID_MEMORY_NAME;
} }
if (cpu == NULL) if (device == NULL)
cpu = debug_cpu_get_visible_cpu(machine); device = debug_cpu_get_visible_cpu(machine);
if (cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (space - EXPSPACE_PROGRAM_PHYSICAL)) == NULL) if (cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (space - EXPSPACE_PROGRAM_PHYSICAL)) == NULL)
return EXPRERR_NO_SUCH_MEMORY_SPACE; return EXPRERR_NO_SUCH_MEMORY_SPACE;
break; break;
@ -2927,20 +2933,24 @@ static EXPRERR expression_validate(void *param, const char *name, int space)
case EXPSPACE_RAMWRITE: case EXPSPACE_RAMWRITE:
if (name != NULL) if (name != NULL)
{ {
cpu = expression_cpu_index(machine, name); device = expression_get_device(machine, name);
if (cpu == NULL) if (device == NULL)
return EXPRERR_INVALID_MEMORY_NAME; return EXPRERR_INVALID_MEMORY_NAME;
} }
if (cpu == NULL) if (device == NULL)
cpu = debug_cpu_get_visible_cpu(machine); device = debug_cpu_get_visible_cpu(machine);
if (cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM) == NULL) if (cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM) == NULL)
return EXPRERR_NO_SUCH_MEMORY_SPACE; return EXPRERR_NO_SUCH_MEMORY_SPACE;
break; break;
case EXPSPACE_EEPROM: case EXPSPACE_EEPROM:
if (name != NULL) if (name != NULL)
return EXPRERR_INVALID_MEMORY_NAME; {
break; device = expression_get_device(machine, name);
if (device != NULL)
break;
}
return EXPRERR_INVALID_MEMORY_NAME;
case EXPSPACE_REGION: case EXPSPACE_REGION:
if (name == NULL) if (name == NULL)