Device interface and drivers are now 32-bit clean.

This commit is contained in:
Daniel Beer 2010-08-05 14:43:07 +12:00
parent 137329cc13
commit 5b2c75563d
9 changed files with 65 additions and 43 deletions

15
bsl.c
View File

@ -222,32 +222,37 @@ static device_status_t bsl_poll(device_t dev_base)
return DEVICE_STATUS_HALTED; return DEVICE_STATUS_HALTED;
} }
static int bsl_getregs(device_t dev_base, uint16_t *regs) static int bsl_getregs(device_t dev_base, address_t *regs)
{ {
fprintf(stderr, "bsl: register fetch is not implemented\n"); fprintf(stderr, "bsl: register fetch is not implemented\n");
return -1; return -1;
} }
static int bsl_setregs(device_t dev_base, const uint16_t *regs) static int bsl_setregs(device_t dev_base, const address_t *regs)
{ {
fprintf(stderr, "bsl: register store is not implemented\n"); fprintf(stderr, "bsl: register store is not implemented\n");
return -1; return -1;
} }
static int bsl_writemem(device_t dev_base, static int bsl_writemem(device_t dev_base,
uint16_t addr, const uint8_t *mem, int len) address_t addr, const uint8_t *mem, address_t len)
{ {
fprintf(stderr, "bsl: memory write is not implemented\n"); fprintf(stderr, "bsl: memory write is not implemented\n");
return -1; return -1;
} }
static int bsl_readmem(device_t dev_base, static int bsl_readmem(device_t dev_base,
uint16_t addr, uint8_t *mem, int len) address_t addr, uint8_t *mem, address_t len)
{ {
struct bsl_device *dev = (struct bsl_device *)dev_base; struct bsl_device *dev = (struct bsl_device *)dev_base;
if ((addr | len | (addr + len)) & 0xffff0000) {
fprintf(stderr, "bsl: memory read out of range\n");
return -1;
}
while (len) { while (len) {
int count = len; address_t count = len;
if (count > 128) if (count > 128)
count = 128; count = 128;

View File

@ -280,7 +280,7 @@ void cproc_hexdump(cproc_t cp, uint16_t addr, const uint8_t *data, int data_len)
} }
} }
void cproc_regs(cproc_t cp, const uint16_t *regs) void cproc_regs(cproc_t cp, const address_t *regs)
{ {
int i; int i;

View File

@ -31,6 +31,6 @@ void cproc_hexdump(cproc_t cp, uint16_t addr,
const uint8_t *buf, int len); const uint8_t *buf, int len);
/* Colorized register dump */ /* Colorized register dump */
void cproc_regs(cproc_t cp, const uint16_t *regs); void cproc_regs(cproc_t cp, const address_t *regs);
#endif #endif

View File

@ -34,7 +34,7 @@
static int cmd_regs(cproc_t cp, char **arg) static int cmd_regs(cproc_t cp, char **arg)
{ {
device_t dev = cproc_device(cp); device_t dev = cproc_device(cp);
uint16_t regs[DEVICE_NUM_REGS]; address_t regs[DEVICE_NUM_REGS];
uint8_t code[16]; uint8_t code[16];
int len = sizeof(code); int len = sizeof(code);
@ -184,7 +184,7 @@ static int cmd_run(cproc_t cp, char **arg)
{ {
device_t dev = cproc_device(cp); device_t dev = cproc_device(cp);
device_status_t status; device_status_t status;
uint16_t regs[DEVICE_NUM_REGS]; address_t regs[DEVICE_NUM_REGS];
if (dev->getregs(dev, regs) < 0) { if (dev->getregs(dev, regs) < 0) {
fprintf(stderr, "warning: device: can't fetch registers\n"); fprintf(stderr, "warning: device: can't fetch registers\n");
@ -237,7 +237,7 @@ static int cmd_set(cproc_t cp, char **arg)
char *val_text = get_arg(arg); char *val_text = get_arg(arg);
int reg; int reg;
address_t value = 0; address_t value = 0;
uint16_t regs[DEVICE_NUM_REGS]; address_t regs[DEVICE_NUM_REGS];
if (!(reg_text && val_text)) { if (!(reg_text && val_text)) {
fprintf(stderr, "set: must specify a register and a value\n"); fprintf(stderr, "set: must specify a register and a value\n");

View File

@ -60,7 +60,7 @@ static void delbrk(device_t dev, uint16_t addr)
} }
} }
int device_setbrk(device_t dev, int which, int enabled, uint16_t addr) int device_setbrk(device_t dev, int which, int enabled, address_t addr)
{ {
if (which < 0) { if (which < 0) {
if (enabled) if (enabled)

View File

@ -20,6 +20,7 @@
#define DEVICE_H_ #define DEVICE_H_
#include <stdint.h> #include <stdint.h>
#include "util.h"
struct device; struct device;
typedef struct device *device_t; typedef struct device *device_t;
@ -46,8 +47,8 @@ typedef enum {
#define DEVICE_BP_DIRTY 0x02 #define DEVICE_BP_DIRTY 0x02
struct device_breakpoint { struct device_breakpoint {
uint16_t addr; address_t addr;
int flags; int flags;
}; };
struct device { struct device {
@ -63,14 +64,14 @@ struct device {
void (*destroy)(device_t dev); void (*destroy)(device_t dev);
/* Read/write memory */ /* Read/write memory */
int (*readmem)(device_t dev, uint16_t addr, int (*readmem)(device_t dev, address_t addr,
uint8_t *mem, int len); uint8_t *mem, address_t len);
int (*writemem)(device_t dev, uint16_t addr, int (*writemem)(device_t dev, address_t addr,
const uint8_t *mem, int len); const uint8_t *mem, address_t len);
/* Read/write registers */ /* Read/write registers */
int (*getregs)(device_t dev, uint16_t *regs); int (*getregs)(device_t dev, address_t *regs);
int (*setregs)(device_t dev, const uint16_t *regs); int (*setregs)(device_t dev, const address_t *regs);
/* CPU control */ /* CPU control */
int (*ctl)(device_t dev, device_ctl_t op); int (*ctl)(device_t dev, device_ctl_t op);
@ -87,6 +88,6 @@ struct device {
* modified. Otherwise, if which < 0, breakpoint slots are selected * modified. Otherwise, if which < 0, breakpoint slots are selected
* automatically. * automatically.
*/ */
int device_setbrk(device_t dev, int which, int enabled, uint16_t address); int device_setbrk(device_t dev, int which, int enabled, address_t address);
#endif #endif

21
fet.c
View File

@ -42,7 +42,7 @@ struct fet_device {
int version; int version;
/* Device-specific information */ /* Device-specific information */
u_int16_t code_start; uint16_t code_start;
uint8_t fet_buf[65538]; uint8_t fet_buf[65538];
int fet_len; int fet_len;
@ -443,7 +443,7 @@ static int xfer(struct fet_device *dev,
va_start(ap, nparams); va_start(ap, nparams);
for (i = 0; i < nparams; i++) for (i = 0; i < nparams; i++)
params[i] = va_arg(ap, unsigned int); params[i] = va_arg(ap, uint32_t);
va_end(ap); va_end(ap);
if (data && (dev->proto_flags & FET_PROTO_RF2500)) { if (data && (dev->proto_flags & FET_PROTO_RF2500)) {
@ -707,7 +707,8 @@ static void fet_destroy(device_t dev_base)
free(dev); free(dev);
} }
int fet_readmem(device_t dev_base, uint16_t addr, uint8_t *buffer, int count) int fet_readmem(device_t dev_base, address_t addr, uint8_t *buffer,
address_t count)
{ {
struct fet_device *dev = (struct fet_device *)dev_base; struct fet_device *dev = (struct fet_device *)dev_base;
@ -735,8 +736,8 @@ int fet_readmem(device_t dev_base, uint16_t addr, uint8_t *buffer, int count)
return 0; return 0;
} }
int fet_writemem(device_t dev_base, uint16_t addr, int fet_writemem(device_t dev_base, address_t addr,
const uint8_t *buffer, int count) const uint8_t *buffer, address_t count)
{ {
struct fet_device *dev = (struct fet_device *)dev_base; struct fet_device *dev = (struct fet_device *)dev_base;
@ -760,7 +761,7 @@ int fet_writemem(device_t dev_base, uint16_t addr,
return 0; return 0;
} }
static int fet_getregs(device_t dev_base, uint16_t *regs) static int fet_getregs(device_t dev_base, address_t *regs)
{ {
struct fet_device *dev = (struct fet_device *)dev_base; struct fet_device *dev = (struct fet_device *)dev_base;
int i; int i;
@ -775,12 +776,12 @@ static int fet_getregs(device_t dev_base, uint16_t *regs)
} }
for (i = 0; i < DEVICE_NUM_REGS; i++) for (i = 0; i < DEVICE_NUM_REGS; i++)
regs[i] = LE_WORD(dev->fet_reply.data, i * 4); regs[i] = LE_LONG(dev->fet_reply.data, i * 4);
return 0; return 0;
} }
static int fet_setregs(device_t dev_base, const uint16_t *regs) static int fet_setregs(device_t dev_base, const address_t *regs)
{ {
struct fet_device *dev = (struct fet_device *)dev_base; struct fet_device *dev = (struct fet_device *)dev_base;
uint8_t buf[DEVICE_NUM_REGS * 4];; uint8_t buf[DEVICE_NUM_REGS * 4];;
@ -791,7 +792,9 @@ static int fet_setregs(device_t dev_base, const uint16_t *regs)
for (i = 0; i < DEVICE_NUM_REGS; i++) { for (i = 0; i < DEVICE_NUM_REGS; i++) {
buf[i * 4] = regs[i] & 0xff; buf[i * 4] = regs[i] & 0xff;
buf[i * 4 + 1] = regs[i] >> 8; buf[i * 4 + 1] = (regs[i] >> 8) & 0xff;
buf[i * 4 + 2] = (regs[i] >> 16) & 0xff;
buf[i * 4 + 3] = regs[i] >> 24;
} }
ret = xfer(dev, C_WRITEREGISTERS, buf, sizeof(buf), 1, 0xffff); ret = xfer(dev, C_WRITEREGISTERS, buf, sizeof(buf), 1, 0xffff);

8
gdb.c
View File

@ -213,7 +213,7 @@ static int gdb_send(struct gdb_data *data, const char *msg)
static int read_registers(struct gdb_data *data) static int read_registers(struct gdb_data *data)
{ {
uint16_t regs[DEVICE_NUM_REGS]; address_t regs[DEVICE_NUM_REGS];
int i; int i;
printf("Reading registers\n"); printf("Reading registers\n");
@ -258,7 +258,7 @@ static int monitor_command(struct gdb_data *data, char *buf)
static int write_registers(struct gdb_data *data, char *buf) static int write_registers(struct gdb_data *data, char *buf)
{ {
uint16_t regs[DEVICE_NUM_REGS]; address_t regs[DEVICE_NUM_REGS];
int i; int i;
if (strlen(buf) < DEVICE_NUM_REGS * 4) if (strlen(buf) < DEVICE_NUM_REGS * 4)
@ -352,7 +352,7 @@ static int write_memory(struct gdb_data *data, char *text)
static int run_set_pc(struct gdb_data *data, char *buf) static int run_set_pc(struct gdb_data *data, char *buf)
{ {
uint16_t regs[DEVICE_NUM_REGS]; address_t regs[DEVICE_NUM_REGS];
if (!*buf) if (!*buf)
return 0; return 0;
@ -366,7 +366,7 @@ static int run_set_pc(struct gdb_data *data, char *buf)
static int run_final_status(struct gdb_data *data) static int run_final_status(struct gdb_data *data)
{ {
uint16_t regs[DEVICE_NUM_REGS]; address_t regs[DEVICE_NUM_REGS];
int i; int i;
if (data->device->getregs(data->device, regs) < 0) if (data->device->getregs(data->device, regs) < 0)

33
sim.c
View File

@ -440,11 +440,17 @@ static void sim_destroy(device_t dev_base)
free(dev_base); free(dev_base);
} }
static int sim_readmem(device_t dev_base, uint16_t addr, static int sim_readmem(device_t dev_base, address_t addr,
uint8_t *mem, int len) uint8_t *mem, address_t len)
{ {
struct sim_device *dev = (struct sim_device *)dev_base; struct sim_device *dev = (struct sim_device *)dev_base;
if (addr > MEM_SIZE || (addr + len) < addr ||
(addr + len) > MEM_SIZE) {
fprintf(stderr, "sim: memory read out of range\n");
return -1;
}
if (addr + len > MEM_SIZE) if (addr + len > MEM_SIZE)
len = MEM_SIZE - addr; len = MEM_SIZE - addr;
@ -452,31 +458,38 @@ static int sim_readmem(device_t dev_base, uint16_t addr,
return 0; return 0;
} }
static int sim_writemem(device_t dev_base, uint16_t addr, static int sim_writemem(device_t dev_base, address_t addr,
const uint8_t *mem, int len) const uint8_t *mem, address_t len)
{ {
struct sim_device *dev = (struct sim_device *)dev_base; struct sim_device *dev = (struct sim_device *)dev_base;
if (addr + len > MEM_SIZE) if (addr > MEM_SIZE || (addr + len) < addr ||
len = MEM_SIZE - addr; (addr + len) > MEM_SIZE) {
fprintf(stderr, "sim: memory write out of range\n");
return -1;
}
memcpy(dev->memory + addr, mem, len); memcpy(dev->memory + addr, mem, len);
return 0; return 0;
} }
static int sim_getregs(device_t dev_base, uint16_t *regs) static int sim_getregs(device_t dev_base, address_t *regs)
{ {
struct sim_device *dev = (struct sim_device *)dev_base; struct sim_device *dev = (struct sim_device *)dev_base;
int i;
memcpy(regs, dev->regs, sizeof(dev->regs)); for (i = 0; i < DEVICE_NUM_REGS; i++)
regs[i] = dev->regs[i];
return 0; return 0;
} }
static int sim_setregs(device_t dev_base, const uint16_t *regs) static int sim_setregs(device_t dev_base, const address_t *regs)
{ {
struct sim_device *dev = (struct sim_device *)dev_base; struct sim_device *dev = (struct sim_device *)dev_base;
int i;
memcpy(dev->regs, regs, sizeof(dev->regs)); for (i = 0; i < DEVICE_NUM_REGS; i++)
dev->regs[i] = regs[i];
return 0; return 0;
} }