diff --git a/bsl.c b/bsl.c index 2768a9f..0b3ceaa 100644 --- a/bsl.c +++ b/bsl.c @@ -269,7 +269,7 @@ static int bsl_writemem(device_t dev_base, r = bsl_xfer(dev, CMD_RX_DATA, addr, mem, wlen); - if( r < 0 ) { + if (r < 0) { printc_err("bsl: failed to write to 0x%04x\n", addr); return -1; diff --git a/device.h b/device.h index fed2b2f..22fca3b 100644 --- a/device.h +++ b/device.h @@ -54,6 +54,12 @@ struct device_breakpoint { }; struct device { + /* Start of code memory. Required to distinguish between flash + * writes (which may require alignment) and RAM writes (which + * don't). + */ + address_t code_start; + /* Breakpoint table. This should not be modified directly. * Instead, you should use the device_setbrk() helper function. This * will set the appropriate flags and ensure that the breakpoint is diff --git a/fet.c b/fet.c index 48f8295..55ebb20 100644 --- a/fet.c +++ b/fet.c @@ -43,8 +43,6 @@ struct fet_device { int version; /* Device-specific information */ - uint16_t code_start; - uint8_t fet_buf[65538]; int fet_len; @@ -478,7 +476,7 @@ static int xfer(struct fet_device *dev, static void show_dev_info(const char *name, const struct fet_device *dev) { printc("Device: %s\n", name); - printc_dbg("Code memory starts at 0x%04x\n", dev->code_start); + printc_dbg("Code memory starts at 0x%04x\n", dev->base.code_start); printc_dbg("Number of breakpoints: %d\n", dev->base.max_breakpoints); } @@ -497,7 +495,7 @@ static int identify_old(struct fet_device *dev) memcpy(idtext, dev->fet_reply.data + 4, 32); idtext[32] = 0; - dev->code_start = LE_WORD(dev->fet_reply.data, 0x24); + dev->base.code_start = LE_WORD(dev->fet_reply.data, 0x24); dev->base.max_breakpoints = LE_WORD(dev->fet_reply.data, 0x2a); show_dev_info(idtext, dev); @@ -535,7 +533,7 @@ static int identify_new(struct fet_device *dev, const char *force_id) return -1; } - dev->code_start = LE_WORD(r->msg29_data, 0); + dev->base.code_start = LE_WORD(r->msg29_data, 0); dev->base.max_breakpoints = LE_WORD(r->msg29_data, 0x14); show_dev_info(r->name, dev); @@ -592,7 +590,7 @@ static int do_erase(struct fet_device *dev) } if (xfer(dev, C_ERASE, NULL, 0, 3, FET_ERASE_MAIN, - dev->code_start, 0) < 0) { + dev->base.code_start, 0) < 0) { printc_err("fet: erase command failed\n"); return -1; } diff --git a/sim.c b/sim.c index 5fd00b8..111b534 100644 --- a/sim.c +++ b/sim.c @@ -27,6 +27,7 @@ #include "sim.h" #define MEM_SIZE 65536 +#define MEM_CODE_START 0x8000 #define MEM_IO_END 0x200 struct sim_device { @@ -579,6 +580,7 @@ device_t sim_open(sim_fetch_func_t fetch_func, memset(dev, 0, sizeof(*dev)); + dev->base.code_start = MEM_CODE_START; dev->base.max_breakpoints = DEVICE_MAX_BREAKPOINTS; dev->base.destroy = sim_destroy; dev->base.readmem = sim_readmem;