From 406617a2a470021d9412e9280feda0d28bdb653b Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Fri, 4 Feb 2011 20:23:52 +1300 Subject: Import of working source tree. --- src/include/adiv5.h | 119 ++++++++++++++++++++++++++++++++ src/include/command.h | 37 ++++++++++ src/include/cortexm3.h | 29 ++++++++ src/include/gdb_if.h | 30 ++++++++ src/include/gdb_main.h | 27 ++++++++ src/include/gdb_packet.h | 36 ++++++++++ src/include/general.h | 34 ++++++++++ src/include/hex_utils.h | 29 ++++++++ src/include/jtag_scan.h | 56 +++++++++++++++ src/include/jtagtap.h | 69 +++++++++++++++++++ src/include/lmi.h | 29 ++++++++ src/include/stm32_tgt.h | 29 ++++++++ src/include/swdptap.h | 39 +++++++++++ src/include/target.h | 173 +++++++++++++++++++++++++++++++++++++++++++++++ 14 files changed, 736 insertions(+) create mode 100644 src/include/adiv5.h create mode 100644 src/include/command.h create mode 100644 src/include/cortexm3.h create mode 100644 src/include/gdb_if.h create mode 100644 src/include/gdb_main.h create mode 100644 src/include/gdb_packet.h create mode 100644 src/include/general.h create mode 100644 src/include/hex_utils.h create mode 100644 src/include/jtag_scan.h create mode 100644 src/include/jtagtap.h create mode 100644 src/include/lmi.h create mode 100644 src/include/stm32_tgt.h create mode 100644 src/include/swdptap.h create mode 100644 src/include/target.h (limited to 'src/include') diff --git a/src/include/adiv5.h b/src/include/adiv5.h new file mode 100644 index 0000000..a9cacf1 --- /dev/null +++ b/src/include/adiv5.h @@ -0,0 +1,119 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __ADIV5_H +#define __ADIV5_H + +#include "general.h" +#include "jtag_scan.h" +#include "target.h" + +#define DP_ABORT 0x0 +#define DP_CTRLSTAT 0x4 +#define DP_SELECT 0x8 +#define DP_RDBUFF 0xC + + +/* Try to keep this somewhat absract for later adding SW-DP */ +typedef struct ADIv5_DP_s { + struct ADIv5_DP_s *next; + uint32_t idcode; + + void (*dp_write)(struct ADIv5_DP_s *dp, uint8_t addr, uint32_t value); + uint32_t (*dp_read)(struct ADIv5_DP_s *dp, uint8_t addr); + + void (*ap_write)(struct ADIv5_DP_s *dp, uint8_t addr, uint32_t value); + uint32_t (*ap_read)(struct ADIv5_DP_s *dp, uint8_t addr); + + uint32_t (*error)(struct ADIv5_DP_s *dp); + + uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t APnDP, uint8_t RnW, + uint8_t addr, uint32_t value); + + union { + jtag_dev_t *dev; + uint8_t fault; + }; +} ADIv5_DP_t; + +static inline void adiv5_dp_write(ADIv5_DP_t *dp, uint8_t addr, uint32_t value) +{ + dp->dp_write(dp, addr, value); +} + +static inline uint32_t adiv5_dp_read(ADIv5_DP_t *dp, uint8_t addr) +{ + return dp->dp_read(dp, addr); +} + +static inline void adiv5_dp_write_ap(ADIv5_DP_t *dp, uint8_t addr, uint32_t value) +{ + dp->ap_write(dp, addr, value); +} + +static inline uint32_t adiv5_dp_read_ap(ADIv5_DP_t *dp, uint8_t addr) +{ + return dp->ap_read(dp, addr); +} + +static inline uint32_t adiv5_dp_error(ADIv5_DP_t *dp) +{ + return dp->error(dp); +} + +static inline uint32_t adiv5_dp_low_access(struct ADIv5_DP_s *dp, uint8_t APnDP, + uint8_t RnW, uint8_t addr, uint32_t value) +{ + return dp->low_access(dp, APnDP, RnW, addr, value); +} + +extern ADIv5_DP_t *adiv5_dp_list; + +typedef struct ADIv5_AP_s { + ADIv5_DP_t *dp; + uint8_t apsel; + + uint32_t idr; + uint32_t cfg; + uint32_t base; +} ADIv5_AP_t; + +struct target_ap_s { + target t; + ADIv5_AP_t *ap; +}; + +extern ADIv5_AP_t adiv5_aps[5]; +extern int adiv5_ap_count; + +void adiv5_free_all(void); +void adiv5_dp_init(ADIv5_DP_t *dp); + +uint32_t adiv5_ap_mem_read(ADIv5_AP_t *ap, uint32_t addr); +void adiv5_ap_mem_write(ADIv5_AP_t *ap, uint32_t addr, uint32_t value); + +void adiv5_ap_write(ADIv5_AP_t *ap, uint8_t addr, uint32_t value); +uint32_t adiv5_ap_read(ADIv5_AP_t *ap, uint8_t addr); + +void adiv5_jtag_dp_handler(jtag_dev_t *dev); +int adiv5_swdp_scan(void); + +#endif + diff --git a/src/include/command.h b/src/include/command.h new file mode 100644 index 0000000..34db13d --- /dev/null +++ b/src/include/command.h @@ -0,0 +1,37 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __COMMAND_H +#define __COMMAND_H + +#include "general.h" + +int command_process(char *cmd); +typedef void (*cmd_handler)(int argc, const char **argv); + +struct command_s { + const char *cmd; + cmd_handler handler; + + const char *help; +}; + +#endif + diff --git a/src/include/cortexm3.h b/src/include/cortexm3.h new file mode 100644 index 0000000..7a3d449 --- /dev/null +++ b/src/include/cortexm3.h @@ -0,0 +1,29 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __CORTEXM3_H +#define __CORTEXM3_H + +#include "target.h" + +int cm3_probe(struct target_s *target); + +#endif + diff --git a/src/include/gdb_if.h b/src/include/gdb_if.h new file mode 100644 index 0000000..930a3d6 --- /dev/null +++ b/src/include/gdb_if.h @@ -0,0 +1,30 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __GDB_IF_H +#define __GDB_IF_H + +int gdb_if_init(void); +unsigned char gdb_if_getchar(void); +unsigned char gdb_if_getchar_to(int timeout); +void gdb_if_putchar(unsigned char c, int flush); + +#endif + diff --git a/src/include/gdb_main.h b/src/include/gdb_main.h new file mode 100644 index 0000000..f57e5e3 --- /dev/null +++ b/src/include/gdb_main.h @@ -0,0 +1,27 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __GDB_MAIN_H +#define __GDB_MAIN_H + +void gdb_main(void); + +#endif + diff --git a/src/include/gdb_packet.h b/src/include/gdb_packet.h new file mode 100644 index 0000000..9f5430f --- /dev/null +++ b/src/include/gdb_packet.h @@ -0,0 +1,36 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __GDB_PACKET_H +#define __GDB_PACKET_H + +#include + +int gdb_getpacket(unsigned char *packet, int size); +void gdb_putpacket(unsigned char *packet, int size); +#define gdb_putpacketz(packet) gdb_putpacket((packet), strlen(packet)) +void gdb_putpacket_f(const unsigned char *packet, ...); + +void gdb_out(const char *buf); +void gdb_outf(const char *fmt, ...); + +#endif + + diff --git a/src/include/general.h b/src/include/general.h new file mode 100644 index 0000000..65ec2af --- /dev/null +++ b/src/include/general.h @@ -0,0 +1,34 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __GENERAL_H +#define __GENERAL_H + +#include "platform.h" + +#ifndef DEBUG +#include +#define DEBUG printf +#endif + +#include + +#endif + diff --git a/src/include/hex_utils.h b/src/include/hex_utils.h new file mode 100644 index 0000000..3aa210b --- /dev/null +++ b/src/include/hex_utils.h @@ -0,0 +1,29 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __HEX_UTILS_H +#define __HEX_UTILS_H + +char * hexify(char *hex, const unsigned char *buf, int size); + +char * unhexify(unsigned char *buf, const char *hex, int size); + +#endif + diff --git a/src/include/jtag_scan.h b/src/include/jtag_scan.h new file mode 100644 index 0000000..083aea0 --- /dev/null +++ b/src/include/jtag_scan.h @@ -0,0 +1,56 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __JTAG_SCAN_H +#define __JTAG_SCAN_H + +#include "general.h" + +#define JTAG_MAX_DEVS 5 +#define JTAG_MAX_IR_LEN 16 + +typedef struct jtag_dev_s { + union { + uint8_t dev; + uint8_t dr_prescan; + }; + uint8_t dr_postscan; + + uint8_t ir_len; + uint8_t ir_prescan; + uint8_t ir_postscan; + + uint32_t idcode; + char *descr; + + uint32_t current_ir; + +} jtag_dev_t; + +extern struct jtag_dev_s jtag_devs[JTAG_MAX_DEVS+1]; +extern int jtag_dev_count; + +int jtag_scan(void); + +void jtag_dev_write_ir(jtag_dev_t *dev, uint32_t ir); +void jtag_dev_shift_dr(jtag_dev_t *dev, uint8_t *dout, const uint8_t *din, int ticks); + +#endif + diff --git a/src/include/jtagtap.h b/src/include/jtagtap.h new file mode 100644 index 0000000..9fe3e0d --- /dev/null +++ b/src/include/jtagtap.h @@ -0,0 +1,69 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __JTAGTAP_H +#define __JTAGTAP_H + +#include "general.h" + +/* Note: Signal names are as for the device under test. */ + +int jtagtap_init(void); + +void jtagtap_reset(void); + +void jtagtap_srst(void); + +uint8_t jtagtap_next(const uint8_t TMS, const uint8_t TDI); +/* tap_next executes one state transision in the JTAG TAP state machine: + * - Ensure TCK is low + * - Assert the values of TMS and TDI + * - Assert TCK (TMS and TDO are latched on rising edge + * - Caputure the value on TDO + * - Release TCK. + */ + +void jtagtap_tms_seq(uint32_t MS, int ticks); +void jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks); +void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks); +/* Shift out a sequence on MS and DI, capture data to DO. + * - This is not endian safe: First byte will always be first shifted out. + * - DO may be NULL to ignore captured data. + * - DO may be point to the same address as DI. + */ + +/* generic soft reset: 1, 1, 1, 1, 1, 0 */ +#define jtagtap_soft_reset() \ + jtagtap_tms_seq(0x1F, 6) + +/* Goto Shift-IR: 1, 1, 0, 0 */ +#define jtagtap_shift_ir() \ + jtagtap_tms_seq(0x03, 4) + +/* Goto Shift-DR: 1, 0, 0 */ +#define jtagtap_shift_dr() \ + jtagtap_tms_seq(0x01, 3) + +/* Goto Run-test/Idle: 1, 1, 0 */ +#define jtagtap_return_idle() \ + jtagtap_tms_seq(0x01, 2) + +#endif + diff --git a/src/include/lmi.h b/src/include/lmi.h new file mode 100644 index 0000000..ac21a33 --- /dev/null +++ b/src/include/lmi.h @@ -0,0 +1,29 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __LMI_H +#define __LMI_H + +#include "target.h" + +int lmi_probe(struct target_s *target); + +#endif + diff --git a/src/include/stm32_tgt.h b/src/include/stm32_tgt.h new file mode 100644 index 0000000..e63310f --- /dev/null +++ b/src/include/stm32_tgt.h @@ -0,0 +1,29 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __STM32_TGT_H +#define __STM32_TGT_H + +#include "target.h" + +int stm32_probe(struct target_s *target); + +#endif + diff --git a/src/include/swdptap.h b/src/include/swdptap.h new file mode 100644 index 0000000..a6252dc --- /dev/null +++ b/src/include/swdptap.h @@ -0,0 +1,39 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +#ifndef __SWDPTAP_H +#define __SWDPTAP_H + +#include "general.h" + +int swdptap_init(void); +void swdptap_reset(void); + +void swdptap_turnaround(uint8_t dir); +uint8_t swdptap_bit_in(void); +void swdptap_bit_out(uint8_t val); + +uint32_t swdptap_seq_in(int ticks); +uint8_t swdptap_seq_in_parity(uint32_t *data, int ticks); +void swdptap_seq_out(uint32_t MS, int ticks); +void swdptap_seq_out_parity(uint32_t MS, int ticks); + +#endif + diff --git a/src/include/target.h b/src/include/target.h new file mode 100644 index 0000000..bd32c0f --- /dev/null +++ b/src/include/target.h @@ -0,0 +1,173 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 3 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, see . + */ + +/* Provides an abstract 'target object', the 'methods' of which must be + * implemented by a target driver when a supported device is detected. + */ + +#ifndef __TARGET_H +#define __TARGET_H + +/* Halt/resume functions */ +#define target_attach(target) \ + (target)->attach(target) + +#define target_detach(target) \ + (target)->detach(target) + +#define target_check_error(target) \ + (target)->check_error(target) + + +/* Memory access functions */ +#define target_mem_read_words(target, dest, src, len) \ + (target)->mem_read_words((target), (dest), (src), (len)) + +#define target_mem_write_words(target, dest, src, len) \ + (target)->mem_write_words((target), (dest), (src), (len)) + +#define target_mem_read_bytes(target, dest, src, len) \ + (target)->mem_read_bytes((target), (dest), (src), (len)) + +#define target_mem_write_bytes(target, dest, src, len) \ + (target)->mem_write_bytes((target), (dest), (src), (len)) + + +/* Register access functions */ +#define target_regs_read(target, data) \ + (target)->regs_read((target), (data)) + +#define target_regs_write(target, data) \ + (target)->regs_write((target), (data)) + +#define target_pc_read(target) \ + (target)->pc_read((target)) + +#define target_pc_write(target, val) \ + (target)->pc_write((target), (val)) + + +/* Halt/resume functions */ +#define target_reset(target) \ + (target)->reset(target) + +#define target_halt_request(target) \ + (target)->halt_request(target) + +#define target_halt_wait(target) \ + (target)->halt_wait(target) + +#define target_halt_resume(target, step) \ + (target)->halt_resume((target), (step)) + + +/* Break-/watchpoint functions */ +#define target_set_hw_bp(target, addr) \ + (target)->set_hw_bp((target), (addr)) + +#define target_clear_hw_bp(target, addr) \ + (target)->clear_hw_bp((target), (addr)) + + +#define target_set_hw_wp(target, type, addr, len) \ + (target)->set_hw_wp((target), (type), (addr), (len)) + +#define target_clear_hw_wp(target, type, addr, len) \ + (target)->clear_hw_wp((target), (type), (addr), (len)) + + +#define target_check_hw_wp(target, addr) \ + (target)->check_hw_wp((target), (addr)) + + +/* Flash memory access functions */ +#define target_flash_erase(target, addr, len) \ + (target)->flash_erase((target), (addr), (len)) + +#define target_flash_write_words(target, dest, src, len) \ + (target)->flash_write_words((target), (dest), (src), (len)) + + +#define TARGET_LIST_FREE() { \ + while(target_list) { \ + target *t = target_list->next; \ + free(target_list); \ + target_list = t; \ + } \ + last_target = cur_target = NULL; \ +} + + +typedef struct target_s { + /* Attach/Detach funcitons */ + void (*attach)(struct target_s *target); + void (*detach)(struct target_s *target); + int (*check_error)(struct target_s *target); + + /* Memory access functions */ + int (*mem_read_words)(struct target_s *target, uint32_t *dest, uint32_t src, + int len); + int (*mem_write_words)(struct target_s *target, uint32_t dest, + const uint32_t *src, int len); + + int (*mem_read_bytes)(struct target_s *target, uint8_t *dest, uint32_t src, + int len); + int (*mem_write_bytes)(struct target_s *target, uint32_t dest, + const uint8_t *src, int len); + + /* Register access functions */ + int regs_size; + int (*regs_read)(struct target_s *target, void *data); + int (*regs_write)(struct target_s *target, const void *data); + + uint32_t (*pc_read)(struct target_s *target); + int (*pc_write)(struct target_s *target, const uint32_t val); + + /* Halt/resume functions */ + void (*reset)(struct target_s *target); + void (*halt_request)(struct target_s *target); + int (*halt_wait)(struct target_s *target); + void (*halt_resume)(struct target_s *target, uint8_t step); + + /* Break-/watchpoint functions */ + int (*set_hw_bp)(struct target_s *target, uint32_t addr); + int (*clear_hw_bp)(struct target_s *target, uint32_t addr); + + int (*set_hw_wp)(struct target_s *target, uint8_t type, uint32_t addr, uint8_t len); + int (*clear_hw_wp)(struct target_s *target, uint8_t type, uint32_t addr, uint8_t len); + + int (*check_hw_wp)(struct target_s *target, uint32_t *addr); + + /* Flash memory access functions */ + const char *xml_mem_map; + int (*flash_erase)(struct target_s *target, uint32_t addr, int len); + int (*flash_write_words)(struct target_s *target, uint32_t dest, + const uint32_t *src, int len); + + const char *driver; + + int size; + struct target_s *next; +} target; + +extern target *target_list, *cur_target, *last_target; + +#endif + -- cgit v1.2.3