#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+
+#include <stlink-common.h>
+
#include "gdb-remote.h"
-#include "stlink-hw.h"
#define FLASH_BASE 0x08000000
#define FLASH_PAGE (sl->flash_pgsz)
{ 0 }
};
-int serve(struct stlink* sl, int port);
+int serve(stlink_t *sl, int port);
char* make_memory_map(const struct chip_params *params, uint32_t flash_size);
int main(int argc, char** argv) {
return 1;
}
- struct stlink *sl = stlink_quirk_open(argv[2], 0);
+ // FIXME - hardcoded to usb....
+ stlink_t *sl =stlink_open_usb(argv[2], 10);
if (sl == NULL)
return 1;
struct code_hw_watchpoint data_watches[DATA_WATCH_NUM];
-static void init_data_watchpoints(struct stlink *sl) {
- int i;
-
+static void init_data_watchpoints(stlink_t *sl) {
#ifdef DEBUG
printf("init watchpoints\n");
#endif
}
}
-static int add_data_watchpoint(struct stlink* sl, enum watchfun wf, stm32_addr_t addr, unsigned int len)
+static int add_data_watchpoint(stlink_t *sl, enum watchfun wf, stm32_addr_t addr, unsigned int len)
{
int i = 0;
- uint32_t mask, temp;
+ uint32_t mask;
// computer mask
// find a free watchpoint
return -1;
}
-static int delete_data_watchpoint(struct stlink* sl, stm32_addr_t addr)
+static int delete_data_watchpoint(stlink_t *sl, stm32_addr_t addr)
{
int i;
struct code_hw_breakpoint code_breaks[CODE_BREAK_NUM];
-static void init_code_breakpoints(struct stlink* sl) {
+static void init_code_breakpoints(stlink_t *sl) {
memset(sl->q_buf, 0, 4);
sl->q_buf[0] = 0x03; // KEY | ENABLE
stlink_write_mem32(sl, 0xe0002000, 4);
}
}
-static int update_code_breakpoint(struct stlink* sl, stm32_addr_t addr, int set) {
+static int update_code_breakpoint(stlink_t *sl, stm32_addr_t addr, int set) {
stm32_addr_t fpb_addr = addr & ~0x3;
int type = addr & 0x2 ? CODE_BREAK_HIGH : CODE_BREAK_LOW;
static struct flash_block* flash_root;
static int flash_add_block(stm32_addr_t addr, unsigned length,
- struct stlink* sl) {
+ stlink_t *sl) {
if(addr < FLASH_BASE || addr + length > FLASH_BASE + FLASH_SIZE) {
fprintf(stderr, "flash_add_block: incorrect bounds\n");
return -1;
return 0;
}
-static int flash_go(struct stlink* sl) {
+static int flash_go(stlink_t *sl) {
int error = -1;
// Some kinds of clock settings do not allow writing to flash.
return error;
}
-int serve(struct stlink* sl, int port) {
+int serve(stlink_t *sl, int port) {
int sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock < 0) {
perror("socket");
#endif
char* reply = NULL;
+ reg regp;
switch(packet[0]) {
case 'q': {
break;
case 'g':
- stlink_read_all_regs(sl);
+ stlink_read_all_regs(sl, ®p);
reply = calloc(8 * 16 + 1, 1);
for(int i = 0; i < 16; i++)
- sprintf(&reply[i * 8], "%08x", htonl(sl->reg.r[i]));
+ sprintf(&reply[i * 8], "%08x", htonl(regp.r[i]));
break;
case 'p': {
- unsigned id = strtoul(&packet[1], NULL, 16), reg = 0xDEADDEAD;
+ unsigned id = strtoul(&packet[1], NULL, 16);
+ unsigned myreg = 0xDEADDEAD;
if(id < 16) {
- stlink_read_reg(sl, id);
- reg = htonl(sl->reg.r[id]);
+ stlink_read_reg(sl, id, ®p);
+ myreg = htonl(regp.r[id]);
} else if(id == 0x19) {
- stlink_read_reg(sl, 16);
- reg = htonl(sl->reg.xpsr);
+ stlink_read_reg(sl, 16, ®p);
+ myreg = htonl(regp.xpsr);
} else {
reply = strdup("E00");
}
reply = calloc(8 + 1, 1);
- sprintf(reply, "%08x", reg);
+ sprintf(reply, "%08x", myreg);
break;
}
case 'z': {
char *endptr;
stm32_addr_t addr = strtoul(&packet[3], &endptr, 16);
- stm32_addr_t len = strtoul(&endptr[1], NULL, 16);
+ //stm32_addr_t len = strtoul(&endptr[1], NULL, 16);
switch (packet[1]) {
case '1': // remove breakpoint
void (*read_mem32) (stlink_t *sl, uint32_t addr, uint16_t len);
void (*write_mem32) (stlink_t *sl, uint32_t addr, uint16_t len);
void (*write_mem8) (stlink_t *sl, uint32_t addr, uint16_t len);
- void (*read_all_reg) (stlink_t * stl);
+ void (*read_all_regs) (stlink_t *sl, reg* regp);
void (*read_reg) (stlink_t *sl, int r_idx, reg* regp);
void (*write_reg) (stlink_t *sl, uint32_t reg, int idx);
void (*step) (stlink_t * stl);
void stlink_read_mem32(stlink_t *sl, uint32_t addr, uint16_t len);
void stlink_write_mem32(stlink_t *sl, uint32_t addr, uint16_t len);
void stlink_write_mem8(stlink_t *sl, uint32_t addr, uint16_t len);
- void stlink_read_all_regs(stlink_t *sl);
+ void stlink_read_all_regs(stlink_t *sl, reg *regp);
void stlink_read_reg(stlink_t *sl, int r_idx, reg *regp);
void stlink_write_reg(stlink_t *sl, uint32_t reg, int idx);
void stlink_step(stlink_t *sl);