]> git.sur5r.net Git - openocd/blobdiff - src/target/arm_adi_v5.c
MIPS: make fixed code arrays static const
[openocd] / src / target / arm_adi_v5.c
index c5e0dd38a097b3500ad0f2f55f55e47906ed78af..61cf98921880f14faef3d6a3c334c7f35d102ff0 100644 (file)
@@ -69,6 +69,7 @@
 #include "config.h"
 #endif
 
+#include "arm.h"
 #include "arm_adi_v5.h"
 #include <helper/time_support.h>
 
@@ -108,7 +109,7 @@ static uint32_t max_tar_block_size(uint32_t tar_autoincr_block, uint32_t address
  * @param invalue NULL, or points to a 32-bit (little-endian) integer
  * @param ack points to where the three bit JTAG_ACK_* code will be stored
  */
-static int adi_jtag_dp_scan(struct swjdp_common *swjdp,
+static int adi_jtag_dp_scan(struct adiv5_dap *swjdp,
                uint8_t instr, uint8_t reg_addr, uint8_t RnW,
                uint8_t *outvalue, uint8_t *invalue, uint8_t *ack)
 {
@@ -122,7 +123,6 @@ static int adi_jtag_dp_scan(struct swjdp_common *swjdp,
        /* Scan out a read or write operation using some DP or AP register.
         * For APACC access with any sticky error flag set, this is discarded.
         */
-       fields[0].tap = jtag_info->tap;
        fields[0].num_bits = 3;
        buf_set_u32(&out_addr_buf, 0, 3, ((reg_addr >> 1) & 0x6) | (RnW & 0x1));
        fields[0].out_value = &out_addr_buf;
@@ -133,12 +133,11 @@ static int adi_jtag_dp_scan(struct swjdp_common *swjdp,
         * When overrun detect is active, STICKYORUN is set.
         */
 
-       fields[1].tap = jtag_info->tap;
        fields[1].num_bits = 32;
        fields[1].out_value = outvalue;
        fields[1].in_value = invalue;
 
-       jtag_add_dr_scan(2, fields, jtag_get_end_state());
+       jtag_add_dr_scan(jtag_info->tap, 2, fields, jtag_get_end_state());
 
        /* Add specified number of tck clocks after starting memory bus
         * access, giving the hardware time to complete the access.
@@ -161,7 +160,7 @@ static int adi_jtag_dp_scan(struct swjdp_common *swjdp,
  * conversions are performed (so the types of invalue and outvalue
  * must be different).
  */
-static int adi_jtag_dp_scan_u32(struct swjdp_common *swjdp,
+static int adi_jtag_dp_scan_u32(struct adiv5_dap *swjdp,
                uint8_t instr, uint8_t reg_addr, uint8_t RnW,
                uint32_t outvalue, uint32_t *invalue, uint8_t *ack)
 {
@@ -185,14 +184,14 @@ static int adi_jtag_dp_scan_u32(struct swjdp_common *swjdp,
 /**
  * Utility to write AP registers.
  */
-static inline int adi_jtag_ap_write_check(struct swjdp_common *dap,
+static inline int adi_jtag_ap_write_check(struct adiv5_dap *dap,
                uint8_t reg_addr, uint8_t *outvalue)
 {
        return adi_jtag_dp_scan(dap, JTAG_DP_APACC, reg_addr, DPAP_WRITE,
                        outvalue, NULL, NULL);
 }
 
-static int adi_jtag_scan_inout_check_u32(struct swjdp_common *swjdp,
+static int adi_jtag_scan_inout_check_u32(struct adiv5_dap *swjdp,
                uint8_t instr, uint8_t reg_addr, uint8_t RnW,
                uint32_t outvalue, uint32_t *invalue)
 {
@@ -213,7 +212,7 @@ static int adi_jtag_scan_inout_check_u32(struct swjdp_common *swjdp,
        return retval;
 }
 
-static int jtagdp_transaction_endcheck(struct swjdp_common *swjdp)
+static int jtagdp_transaction_endcheck(struct adiv5_dap *swjdp)
 {
        int retval;
        uint32_t ctrlstat;
@@ -367,7 +366,7 @@ static int jtagdp_transaction_endcheck(struct swjdp_common *swjdp)
  * @param apsel Number of the AP to (implicitly) use with further
  *     transactions.  This normally identifies a MEM-AP.
  */
-void dap_ap_select(struct swjdp_common *swjdp,uint8_t apsel)
+void dap_ap_select(struct adiv5_dap *swjdp,uint8_t apsel)
 {
        uint32_t select = (apsel << 24) & 0xFF000000;
 
@@ -402,7 +401,7 @@ void dap_ap_select(struct swjdp_common *swjdp,uint8_t apsel)
  *
  * @return ERROR_OK if the transaction was properly queued, else a fault code.
  */
-int dap_setup_accessport(struct swjdp_common *swjdp, uint32_t csw, uint32_t tar)
+int dap_setup_accessport(struct adiv5_dap *swjdp, uint32_t csw, uint32_t tar)
 {
        int retval;
 
@@ -440,7 +439,7 @@ int dap_setup_accessport(struct swjdp_common *swjdp, uint32_t csw, uint32_t tar)
  *
  * @return ERROR_OK for success.  Otherwise a fault code.
  */
-int mem_ap_read_u32(struct swjdp_common *swjdp, uint32_t address,
+int mem_ap_read_u32(struct adiv5_dap *swjdp, uint32_t address,
                uint32_t *value)
 {
        int retval;
@@ -468,7 +467,7 @@ int mem_ap_read_u32(struct swjdp_common *swjdp, uint32_t address,
  * @return ERROR_OK for success; *value holds the result.
  * Otherwise a fault code.
  */
-int mem_ap_read_atomic_u32(struct swjdp_common *swjdp, uint32_t address,
+int mem_ap_read_atomic_u32(struct adiv5_dap *swjdp, uint32_t address,
                uint32_t *value)
 {
        int retval;
@@ -491,7 +490,7 @@ int mem_ap_read_atomic_u32(struct swjdp_common *swjdp, uint32_t address,
  *
  * @return ERROR_OK for success.  Otherwise a fault code.
  */
-int mem_ap_write_u32(struct swjdp_common *swjdp, uint32_t address,
+int mem_ap_write_u32(struct adiv5_dap *swjdp, uint32_t address,
                uint32_t value)
 {
        int retval;
@@ -519,7 +518,7 @@ int mem_ap_write_u32(struct swjdp_common *swjdp, uint32_t address,
  *
  * @return ERROR_OK for success; the data was written.  Otherwise a fault code.
  */
-int mem_ap_write_atomic_u32(struct swjdp_common *swjdp, uint32_t address,
+int mem_ap_write_atomic_u32(struct adiv5_dap *swjdp, uint32_t address,
                uint32_t value)
 {
        int retval = mem_ap_write_u32(swjdp, address, value);
@@ -532,12 +531,12 @@ int mem_ap_write_atomic_u32(struct swjdp_common *swjdp, uint32_t address,
 
 /*****************************************************************************
 *                                                                            *
-* mem_ap_write_buf(struct swjdp_common *swjdp, uint8_t *buffer, int count, uint32_t address) *
+* mem_ap_write_buf(struct adiv5_dap *swjdp, uint8_t *buffer, int count, uint32_t address) *
 *                                                                            *
 * Write a buffer in target order (little endian)                             *
 *                                                                            *
 *****************************************************************************/
-int mem_ap_write_buf_u32(struct swjdp_common *swjdp, uint8_t *buffer, int count, uint32_t address)
+int mem_ap_write_buf_u32(struct adiv5_dap *swjdp, uint8_t *buffer, int count, uint32_t address)
 {
        int wcount, blocksize, writecount, errorcount = 0, retval = ERROR_OK;
        uint32_t adr = address;
@@ -608,7 +607,7 @@ int mem_ap_write_buf_u32(struct swjdp_common *swjdp, uint8_t *buffer, int count,
        return retval;
 }
 
-static int mem_ap_write_buf_packed_u16(struct swjdp_common *swjdp,
+static int mem_ap_write_buf_packed_u16(struct adiv5_dap *swjdp,
                uint8_t *buffer, int count, uint32_t address)
 {
        int retval = ERROR_OK;
@@ -688,7 +687,7 @@ static int mem_ap_write_buf_packed_u16(struct swjdp_common *swjdp,
        return retval;
 }
 
-int mem_ap_write_buf_u16(struct swjdp_common *swjdp, uint8_t *buffer, int count, uint32_t address)
+int mem_ap_write_buf_u16(struct adiv5_dap *swjdp, uint8_t *buffer, int count, uint32_t address)
 {
        int retval = ERROR_OK;
 
@@ -717,7 +716,7 @@ int mem_ap_write_buf_u16(struct swjdp_common *swjdp, uint8_t *buffer, int count,
        return retval;
 }
 
-static int mem_ap_write_buf_packed_u8(struct swjdp_common *swjdp,
+static int mem_ap_write_buf_packed_u8(struct adiv5_dap *swjdp,
                uint8_t *buffer, int count, uint32_t address)
 {
        int retval = ERROR_OK;
@@ -792,7 +791,7 @@ static int mem_ap_write_buf_packed_u8(struct swjdp_common *swjdp,
        return retval;
 }
 
-int mem_ap_write_buf_u8(struct swjdp_common *swjdp, uint8_t *buffer, int count, uint32_t address)
+int mem_ap_write_buf_u8(struct adiv5_dap *swjdp, uint8_t *buffer, int count, uint32_t address)
 {
        int retval = ERROR_OK;
 
@@ -827,7 +826,7 @@ int mem_ap_write_buf_u8(struct swjdp_common *swjdp, uint8_t *buffer, int count,
  * @param address Memory address from which to read words; all the
  *     words must be readable by the currently selected MEM-AP.
  */
-int mem_ap_read_buf_u32(struct swjdp_common *swjdp, uint8_t *buffer,
+int mem_ap_read_buf_u32(struct adiv5_dap *swjdp, uint8_t *buffer,
                int count, uint32_t address)
 {
        int wcount, blocksize, readcount, errorcount = 0, retval = ERROR_OK;
@@ -924,7 +923,7 @@ int mem_ap_read_buf_u32(struct swjdp_common *swjdp, uint8_t *buffer,
        return retval;
 }
 
-static int mem_ap_read_buf_packed_u16(struct swjdp_common *swjdp,
+static int mem_ap_read_buf_packed_u16(struct adiv5_dap *swjdp,
                uint8_t *buffer, int count, uint32_t address)
 {
        uint32_t invalue;
@@ -984,7 +983,7 @@ static int mem_ap_read_buf_packed_u16(struct swjdp_common *swjdp,
  * @param address Memory address from which to read words; all the
  *     words must be readable by the currently selected MEM-AP.
  */
-int mem_ap_read_buf_u16(struct swjdp_common *swjdp, uint8_t *buffer,
+int mem_ap_read_buf_u16(struct adiv5_dap *swjdp, uint8_t *buffer,
                int count, uint32_t address)
 {
        uint32_t invalue, i;
@@ -1032,7 +1031,7 @@ int mem_ap_read_buf_u16(struct swjdp_common *swjdp, uint8_t *buffer,
  * The solution is to arrange for a large out/in scan in this loop and
  * and convert data afterwards.
  */
-static int mem_ap_read_buf_packed_u8(struct swjdp_common *swjdp,
+static int mem_ap_read_buf_packed_u8(struct adiv5_dap *swjdp,
                uint8_t *buffer, int count, uint32_t address)
 {
        uint32_t invalue;
@@ -1089,7 +1088,7 @@ static int mem_ap_read_buf_packed_u8(struct swjdp_common *swjdp,
  * @param address Memory address from which to read data; all the
  *     data must be readable by the currently selected MEM-AP.
  */
-int mem_ap_read_buf_u8(struct swjdp_common *swjdp, uint8_t *buffer,
+int mem_ap_read_buf_u8(struct adiv5_dap *swjdp, uint8_t *buffer,
                int count, uint32_t address)
 {
        uint32_t invalue;
@@ -1117,7 +1116,7 @@ int mem_ap_read_buf_u8(struct swjdp_common *swjdp, uint8_t *buffer,
 
 /*--------------------------------------------------------------------------*/
 
-static int jtag_idcode_q_read(struct swjdp_common *dap,
+static int jtag_idcode_q_read(struct adiv5_dap *dap,
                uint8_t *ack, uint32_t *data)
 {
        struct arm_jtag *jtag_info = dap->jtag_info;
@@ -1131,12 +1130,11 @@ static int jtag_idcode_q_read(struct swjdp_common *dap,
        if (retval != ERROR_OK)
                return retval;
 
-       fields[0].tap = jtag_info->tap;
        fields[0].num_bits = 32;
        fields[0].out_value = NULL;
        fields[0].in_value = (void *) data;
 
-       jtag_add_dr_scan(1, fields, jtag_get_end_state());
+       jtag_add_dr_scan(jtag_info->tap, 1, fields, jtag_get_end_state());
        retval = jtag_get_error();
        if (retval != ERROR_OK)
                return retval;
@@ -1147,14 +1145,14 @@ static int jtag_idcode_q_read(struct swjdp_common *dap,
        return retval;
 }
 
-static int jtag_dp_q_read(struct swjdp_common *dap, unsigned reg,
+static int jtag_dp_q_read(struct adiv5_dap *dap, unsigned reg,
                uint32_t *data)
 {
        return adi_jtag_scan_inout_check_u32(dap, JTAG_DP_DPACC,
                        reg, DPAP_READ, 0, data);
 }
 
-static int jtag_dp_q_write(struct swjdp_common *dap, unsigned reg,
+static int jtag_dp_q_write(struct adiv5_dap *dap, unsigned reg,
                uint32_t data)
 {
        return adi_jtag_scan_inout_check_u32(dap, JTAG_DP_DPACC,
@@ -1162,7 +1160,7 @@ static int jtag_dp_q_write(struct swjdp_common *dap, unsigned reg,
 }
 
 /** Select the AP register bank matching bits 7:4 of reg. */
-static int jtag_ap_q_bankselect(struct swjdp_common *dap, unsigned reg)
+static int jtag_ap_q_bankselect(struct adiv5_dap *dap, unsigned reg)
 {
        uint32_t select = reg & 0x000000F0;
 
@@ -1175,7 +1173,7 @@ static int jtag_ap_q_bankselect(struct swjdp_common *dap, unsigned reg)
        return jtag_dp_q_write(dap, DP_SELECT, select);
 }
 
-static int jtag_ap_q_read(struct swjdp_common *dap, unsigned reg,
+static int jtag_ap_q_read(struct adiv5_dap *dap, unsigned reg,
                uint32_t *data)
 {
        int retval = jtag_ap_q_bankselect(dap, reg);
@@ -1187,7 +1185,7 @@ static int jtag_ap_q_read(struct swjdp_common *dap, unsigned reg,
                        DPAP_READ, 0, data);
 }
 
-static int jtag_ap_q_write(struct swjdp_common *dap, unsigned reg,
+static int jtag_ap_q_write(struct adiv5_dap *dap, unsigned reg,
                uint32_t data)
 {
        uint8_t out_value_buf[4];
@@ -1201,14 +1199,14 @@ static int jtag_ap_q_write(struct swjdp_common *dap, unsigned reg,
        return adi_jtag_ap_write_check(dap, reg, out_value_buf);
 }
 
-static int jtag_ap_q_abort(struct swjdp_common *dap, uint8_t *ack)
+static int jtag_ap_q_abort(struct adiv5_dap *dap, uint8_t *ack)
 {
        /* for JTAG, this is the only valid ABORT register operation */
        return adi_jtag_dp_scan_u32(dap, JTAG_DP_ABORT,
                        0, DPAP_WRITE, 1, NULL, ack);
 }
 
-static int jtag_dp_run(struct swjdp_common *dap)
+static int jtag_dp_run(struct adiv5_dap *dap)
 {
        return jtagdp_transaction_endcheck(dap);
 }
@@ -1237,7 +1235,7 @@ static const struct dap_ops jtag_dp_ops = {
  * in layering.  (JTAG is useful without any debug target; but not SWD.)
  * And this may not even use an AHB-AP ... e.g. DAP-Lite uses an APB-AP.
  */
-int ahbap_debugport_init(struct swjdp_common *swjdp)
+int ahbap_debugport_init(struct adiv5_dap *swjdp)
 {
        uint32_t idreg, romaddr, dummy;
        uint32_t ctrlstat;
@@ -1352,8 +1350,8 @@ is_dap_cid_ok(uint32_t cid3, uint32_t cid2, uint32_t cid1, uint32_t cid0)
                        && ((cid1 & 0x0f) == 0) && cid0 == 0x0d;
 }
 
-int dap_info_command(struct command_context *cmd_ctx,
-               struct swjdp_common *swjdp, int apsel)
+static int dap_info_command(struct command_context *cmd_ctx,
+               struct adiv5_dap *swjdp, int apsel)
 {
        int retval;
        uint32_t dbgbase, apid;
@@ -1711,15 +1709,40 @@ int dap_info_command(struct command_context *cmd_ctx,
        return ERROR_OK;
 }
 
-DAP_COMMAND_HANDLER(dap_baseaddr_command)
+COMMAND_HANDLER(handle_dap_info_command)
 {
+       struct target *target = get_current_target(CMD_CTX);
+       struct arm *arm = target_to_arm(target);
+       struct adiv5_dap *dap = arm->dap;
+       uint32_t apsel;
+
+       switch (CMD_ARGC) {
+       case 0:
+               apsel = dap->apsel;
+               break;
+       case 1:
+               COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
+               break;
+       default:
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       }
+
+       return dap_info_command(CMD_CTX, dap, apsel);
+}
+
+COMMAND_HANDLER(dap_baseaddr_command)
+{
+       struct target *target = get_current_target(CMD_CTX);
+       struct arm *arm = target_to_arm(target);
+       struct adiv5_dap *dap = arm->dap;
+
        uint32_t apsel, apselsave, baseaddr;
        int retval;
 
-       apselsave = swjdp->apsel;
+       apselsave = dap->apsel;
        switch (CMD_ARGC) {
        case 0:
-               apsel = swjdp->apsel;
+               apsel = dap->apsel;
                break;
        case 1:
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
@@ -1732,33 +1755,37 @@ DAP_COMMAND_HANDLER(dap_baseaddr_command)
        }
 
        if (apselsave != apsel)
-               dap_ap_select(swjdp, apsel);
+               dap_ap_select(dap, apsel);
 
        /* NOTE:  assumes we're talking to a MEM-AP, which
         * has a base address.  There are other kinds of AP,
         * though they're not common for now.  This should
         * use the ID register to verify it's a MEM-AP.
         */
-       retval = dap_queue_ap_read(swjdp, AP_REG_BASE, &baseaddr);
-       retval = dap_run(swjdp);
+       retval = dap_queue_ap_read(dap, AP_REG_BASE, &baseaddr);
+       retval = dap_run(dap);
        if (retval != ERROR_OK)
                return retval;
 
        command_print(CMD_CTX, "0x%8.8" PRIx32, baseaddr);
 
        if (apselsave != apsel)
-               dap_ap_select(swjdp, apselsave);
+               dap_ap_select(dap, apselsave);
 
        return retval;
 }
 
-DAP_COMMAND_HANDLER(dap_memaccess_command)
+COMMAND_HANDLER(dap_memaccess_command)
 {
+       struct target *target = get_current_target(CMD_CTX);
+       struct arm *arm = target_to_arm(target);
+       struct adiv5_dap *dap = arm->dap;
+
        uint32_t memaccess_tck;
 
        switch (CMD_ARGC) {
        case 0:
-               memaccess_tck = swjdp->memaccess_tck;
+               memaccess_tck = dap->memaccess_tck;
                break;
        case 1:
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], memaccess_tck);
@@ -1766,16 +1793,20 @@ DAP_COMMAND_HANDLER(dap_memaccess_command)
        default:
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       swjdp->memaccess_tck = memaccess_tck;
+       dap->memaccess_tck = memaccess_tck;
 
        command_print(CMD_CTX, "memory bus access delay set to %" PRIi32 " tck",
-                       swjdp->memaccess_tck);
+                       dap->memaccess_tck);
 
        return ERROR_OK;
 }
 
-DAP_COMMAND_HANDLER(dap_apsel_command)
+COMMAND_HANDLER(dap_apsel_command)
 {
+       struct target *target = get_current_target(CMD_CTX);
+       struct arm *arm = target_to_arm(target);
+       struct adiv5_dap *dap = arm->dap;
+
        uint32_t apsel, apid;
        int retval;
 
@@ -1793,9 +1824,9 @@ DAP_COMMAND_HANDLER(dap_apsel_command)
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       dap_ap_select(swjdp, apsel);
-       retval = dap_queue_ap_read(swjdp, AP_REG_IDR, &apid);
-       retval = dap_run(swjdp);
+       dap_ap_select(dap, apsel);
+       retval = dap_queue_ap_read(dap, AP_REG_IDR, &apid);
+       retval = dap_run(dap);
        if (retval != ERROR_OK)
                return retval;
 
@@ -1805,15 +1836,19 @@ DAP_COMMAND_HANDLER(dap_apsel_command)
        return retval;
 }
 
-DAP_COMMAND_HANDLER(dap_apid_command)
+COMMAND_HANDLER(dap_apid_command)
 {
+       struct target *target = get_current_target(CMD_CTX);
+       struct arm *arm = target_to_arm(target);
+       struct adiv5_dap *dap = arm->dap;
+
        uint32_t apsel, apselsave, apid;
        int retval;
 
-       apselsave = swjdp->apsel;
+       apselsave = dap->apsel;
        switch (CMD_ARGC) {
        case 0:
-               apsel = swjdp->apsel;
+               apsel = dap->apsel;
                break;
        case 1:
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
@@ -1826,20 +1861,75 @@ DAP_COMMAND_HANDLER(dap_apid_command)
        }
 
        if (apselsave != apsel)
-               dap_ap_select(swjdp, apsel);
+               dap_ap_select(dap, apsel);
 
-       retval = dap_queue_ap_read(swjdp, AP_REG_IDR, &apid);
-       retval = dap_run(swjdp);
+       retval = dap_queue_ap_read(dap, AP_REG_IDR, &apid);
+       retval = dap_run(dap);
        if (retval != ERROR_OK)
                return retval;
 
        command_print(CMD_CTX, "0x%8.8" PRIx32, apid);
        if (apselsave != apsel)
-               dap_ap_select(swjdp, apselsave);
+               dap_ap_select(dap, apselsave);
 
        return retval;
 }
 
+static const struct command_registration dap_commands[] = {
+       {
+               .name = "info",
+               .handler = handle_dap_info_command,
+               .mode = COMMAND_EXEC,
+               .help = "display ROM table for MEM-AP "
+                       "(default currently selected AP)",
+               .usage = "[ap_num]",
+       },
+       {
+               .name = "apsel",
+               .handler = dap_apsel_command,
+               .mode = COMMAND_EXEC,
+               .help = "Set the currently selected AP (default 0) "
+                       "and display the result",
+               .usage = "[ap_num]",
+       },
+       {
+               .name = "apid",
+               .handler = dap_apid_command,
+               .mode = COMMAND_EXEC,
+               .help = "return ID register from AP "
+                       "(default currently selected AP)",
+               .usage = "[ap_num]",
+       },
+       {
+               .name = "baseaddr",
+               .handler = dap_baseaddr_command,
+               .mode = COMMAND_EXEC,
+               .help = "return debug base address from MEM-AP "
+                       "(default currently selected AP)",
+               .usage = "[ap_num]",
+       },
+       {
+               .name = "memaccess",
+               .handler = dap_memaccess_command,
+               .mode = COMMAND_EXEC,
+               .help = "set/get number of extra tck for MEM-AP memory "
+                       "bus access [0-255]",
+               .usage = "[cycles]",
+       },
+       COMMAND_REGISTRATION_DONE
+};
+
+const struct command_registration dap_command_handlers[] = {
+       {
+               .name = "dap",
+               .mode = COMMAND_EXEC,
+               .help = "DAP command group",
+               .chain = dap_commands,
+       },
+       COMMAND_REGISTRATION_DONE
+};
+
+
 /*
  * This represents the bits which must be sent out on TMS/SWDIO to
  * switch a DAP implemented using an SWJ-DP module into SWD mode.