Basic simulation implementation (memory IO only).

This commit is contained in:
Daniel Beer 2010-01-09 16:14:30 +13:00
parent 22c0bbd28b
commit 5a84cbf7f5
4 changed files with 151 additions and 19 deletions

View File

@ -26,7 +26,7 @@ clean:
.SUFFIXES: .c .o .SUFFIXES: .c .o
mspdebug: main.o fet.o rf2500.o dis.o uif.o ihex.o elf32.o stab.o util.o \ mspdebug: main.o fet.o rf2500.o dis.o uif.o ihex.o elf32.o stab.o util.o \
bsl.o bsl.o sim.o
$(CC) $(CFLAGS) -o $@ $^ -lusb $(CC) $(CFLAGS) -o $@ $^ -lusb
.c.o: .c.o:

View File

@ -54,4 +54,7 @@ const struct device *fet_open(const struct fet_transport *transport,
/* MSP430 FET Bootloader implementation. */ /* MSP430 FET Bootloader implementation. */
const struct device *fet_open_bl(const struct fet_transport *transport); const struct device *fet_open_bl(const struct fet_transport *transport);
/* Dummy/simulation implementation. */
const struct device *sim_open(void);
#endif #endif

50
main.c
View File

@ -616,7 +616,7 @@ static void reader_loop(void)
static void usage(const char *progname) static void usage(const char *progname)
{ {
fprintf(stderr, fprintf(stderr,
"Usage: %s [-u device] [-j] [-B] [-v voltage] [command ...]\n" "Usage: %s [-u device] [-j] [-B] [-s] [-v voltage] [command ...]\n"
"\n" "\n"
" -u device\n" " -u device\n"
" Open the given tty device (MSP430 UIF compatible devices).\n" " Open the given tty device (MSP430 UIF compatible devices).\n"
@ -626,6 +626,8 @@ static void usage(const char *progname)
" Set the supply voltage, in millivolts.\n" " Set the supply voltage, in millivolts.\n"
" -B\n" " -B\n"
" Debug the FET itself through the bootloader.\n" " Debug the FET itself through the bootloader.\n"
" -s\n"
" Start in simulation mode (only memory IO is allowed).\n"
"\n" "\n"
"By default, the first RF2500 device on the USB bus is opened.\n" "By default, the first RF2500 device on the USB bus is opened.\n"
"\n" "\n"
@ -642,6 +644,7 @@ int main(int argc, char **argv)
int flags = 0; int flags = 0;
int want_jtag = 0; int want_jtag = 0;
int want_bootloader = 0; int want_bootloader = 0;
int want_sim = 0;
int vcc_mv = 3000; int vcc_mv = 3000;
puts( puts(
@ -650,7 +653,8 @@ int main(int argc, char **argv)
"This is free software; see the source for copying conditions. There is NO\n" "This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
while ((opt = getopt(argc, argv, "u:jv:B")) >= 0) /* Parse arguments */
while ((opt = getopt(argc, argv, "u:jv:Bs")) >= 0)
switch (opt) { switch (opt) {
case 'u': case 'u':
uif_device = optarg; uif_device = optarg;
@ -668,28 +672,38 @@ int main(int argc, char **argv)
want_bootloader = 1; want_bootloader = 1;
break; break;
case 's':
want_sim = 1;
break;
default: default:
usage(argv[0]); usage(argv[0]);
return -1; return -1;
} }
/* Open the appropriate transport */ /* Open a device */
if (uif_device) if (want_sim) {
trans = uif_open(uif_device); msp430_dev = sim_open();
else { } else {
trans = rf2500_open(); /* Open the appropriate transport */
flags |= FET_PROTO_RF2500; if (uif_device)
} trans = uif_open(uif_device);
if (!trans) else {
return -1; trans = rf2500_open();
flags |= FET_PROTO_RF2500;
}
if (!trans)
return -1;
/* Then initialize the device */
if (!want_jtag)
flags |= FET_PROTO_SPYBIWIRE;
if (want_bootloader)
msp430_dev = fet_open_bl(trans);
else
msp430_dev = fet_open(trans, flags, vcc_mv);
}
/* Then initialize the device */
if (!want_jtag)
flags |= FET_PROTO_SPYBIWIRE;
if (want_bootloader)
msp430_dev = fet_open_bl(trans);
else
msp430_dev = fet_open(trans, flags, vcc_mv);
if (!msp430_dev) if (!msp430_dev)
return -1; return -1;

115
sim.c Normal file
View File

@ -0,0 +1,115 @@
/* MSPDebug - debugging tool for the eZ430
* Copyright (C) 2009, 2010 Daniel Beer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "device.h"
#define MEM_SIZE 65536
static u_int8_t *memory;
static void sim_close(void)
{
if (memory) {
free(memory);
memory = NULL;
}
}
static int sim_control(device_ctl_t action)
{
switch (action) {
case DEVICE_CTL_ERASE:
memset(memory, 0xff, MEM_SIZE);
return 0;
case DEVICE_CTL_HALT:
return 0;
default:
fprintf(stderr, "sim: CPU control is not implemented\n");
break;
}
return -1;
}
static int sim_wait(void)
{
return 0;
}
static int sim_breakpoint(u_int16_t addr)
{
return 0;
}
static int sim_getregs(u_int16_t *regs)
{
fprintf(stderr, "sim: register fetch is not implemented\n");
return -1;
}
static int sim_setregs(const u_int16_t *regs)
{
fprintf(stderr, "sim: register store is not implemented\n");
return -1;
}
static int sim_readmem(u_int16_t addr, u_int8_t *mem, int len)
{
if (addr + len > MEM_SIZE)
len = MEM_SIZE - addr;
memcpy(mem, memory + addr, len);
return 0;
}
static int sim_writemem(u_int16_t addr, const u_int8_t *mem, int len)
{
if (addr + len > MEM_SIZE)
len = MEM_SIZE - addr;
memcpy(memory + addr, mem, len);
return 0;
}
static const struct device sim_device = {
.close = sim_close,
.control = sim_control,
.wait = sim_wait,
.breakpoint = sim_breakpoint,
.getregs = sim_getregs,
.setregs = sim_setregs,
.readmem = sim_readmem,
.writemem = sim_writemem
};
const struct device *sim_open(void)
{
memory = malloc(MEM_SIZE);
if (!memory) {
perror("sim: can't allocate memory");
return NULL;
}
printf("Simulation started, 0x%x bytes of RAM\n", MEM_SIZE);
return &sim_device;
}