Use enum for target_register_timer_callback()
[openocd.git] / src / target / hla_target.c
index efc03130d74dfdf16cdeb64b577606828e757577..60ed7d64df1749014ff8d83b4466333d36181b6c 100644 (file)
@@ -18,9 +18,7 @@
  *   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, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -75,11 +73,6 @@ static int adapter_load_core_reg_u32(struct target *target,
                LOG_DEBUG("load from core reg %i  value 0x%" PRIx32 "", (int)num, *value);
                break;
 
-       case ARMV7M_FPSID:
-       case ARMV7M_FPEXC:
-               *value = 0;
-               break;
-
        case ARMV7M_FPSCR:
                /* Floating-point Status and Registers */
                retval = target_write_u32(target, ARMV7M_SCS_DCRSR, 33);
@@ -88,7 +81,7 @@ static int adapter_load_core_reg_u32(struct target *target,
                retval = target_read_u32(target, ARMV7M_SCS_DCRDR, value);
                if (retval != ERROR_OK)
                        return retval;
-               LOG_DEBUG("load from core reg %i  value 0x%" PRIx32 "", (int)num, *value);
+               LOG_DEBUG("load from FPSCR  value 0x%" PRIx32, *value);
                break;
 
        case ARMV7M_S0 ... ARMV7M_S31:
@@ -99,11 +92,8 @@ static int adapter_load_core_reg_u32(struct target *target,
                retval = target_read_u32(target, ARMV7M_SCS_DCRDR, value);
                if (retval != ERROR_OK)
                        return retval;
-               LOG_DEBUG("load from core reg %i  value 0x%" PRIx32 "", (int)num, *value);
-               break;
-
-       case ARMV7M_D0 ... ARMV7M_D15:
-               value = 0;
+               LOG_DEBUG("load from FPU reg S%d  value 0x%" PRIx32,
+                         (int)(num - ARMV7M_S0), *value);
                break;
 
        case ARMV7M_PRIMASK:
@@ -176,10 +166,6 @@ static int adapter_store_core_reg_u32(struct target *target,
                LOG_DEBUG("write core reg %i value 0x%" PRIx32 "", (int)num, value);
                break;
 
-       case ARMV7M_FPSID:
-       case ARMV7M_FPEXC:
-               break;
-
        case ARMV7M_FPSCR:
                /* Floating-point Status and Registers */
                retval = target_write_u32(target, ARMV7M_SCS_DCRDR, value);
@@ -188,7 +174,7 @@ static int adapter_store_core_reg_u32(struct target *target,
                retval = target_write_u32(target, ARMV7M_SCS_DCRSR, 33 | (1<<16));
                if (retval != ERROR_OK)
                        return retval;
-               LOG_DEBUG("write core reg %i value 0x%" PRIx32 "", (int)num, value);
+               LOG_DEBUG("write FPSCR value 0x%" PRIx32, value);
                break;
 
        case ARMV7M_S0 ... ARMV7M_S31:
@@ -199,10 +185,8 @@ static int adapter_store_core_reg_u32(struct target *target,
                retval = target_write_u32(target, ARMV7M_SCS_DCRSR, (num-ARMV7M_S0+64) | (1<<16));
                if (retval != ERROR_OK)
                        return retval;
-               LOG_DEBUG("write core reg %i value 0x%" PRIx32 "", (int)num, value);
-               break;
-
-       case ARMV7M_D0 ... ARMV7M_D15:
+               LOG_DEBUG("write FPU reg S%d  value 0x%" PRIx32,
+                         (int)(num - ARMV7M_S0), value);
                break;
 
        case ARMV7M_PRIMASK:
@@ -287,7 +271,10 @@ static int hl_target_request_data(struct target *target,
        uint32_t i;
 
        for (i = 0; i < (size * 4); i++) {
-               hl_dcc_read(hl_if, &data, &ctrl);
+               int err = hl_dcc_read(hl_if, &data, &ctrl);
+               if (err != ERROR_OK)
+                       return err;
+
                buffer[i] = data;
        }
 
@@ -297,6 +284,8 @@ static int hl_target_request_data(struct target *target,
 static int hl_handle_target_request(void *priv)
 {
        struct target *target = priv;
+       int err;
+
        if (!target_was_examined(target))
                return ERROR_OK;
        struct hl_interface_s *hl_if = target_to_adapter(target);
@@ -308,7 +297,9 @@ static int hl_handle_target_request(void *priv)
                uint8_t data;
                uint8_t ctrl;
 
-               hl_dcc_read(hl_if, &data, &ctrl);
+               err = hl_dcc_read(hl_if, &data, &ctrl);
+               if (err != ERROR_OK)
+                       return err;
 
                /* check if we have data */
                if (ctrl & (1 << 0)) {
@@ -316,11 +307,20 @@ static int hl_handle_target_request(void *priv)
 
                        /* we assume target is quick enough */
                        request = data;
-                       hl_dcc_read(hl_if, &data, &ctrl);
+                       err = hl_dcc_read(hl_if, &data, &ctrl);
+                       if (err != ERROR_OK)
+                               return err;
+
                        request |= (data << 8);
-                       hl_dcc_read(hl_if, &data, &ctrl);
+                       err = hl_dcc_read(hl_if, &data, &ctrl);
+                       if (err != ERROR_OK)
+                               return err;
+
                        request |= (data << 16);
-                       hl_dcc_read(hl_if, &data, &ctrl);
+                       err = hl_dcc_read(hl_if, &data, &ctrl);
+                       if (err != ERROR_OK)
+                               return err;
+
                        request |= (data << 24);
                        target_request(target, request);
                }
@@ -346,7 +346,8 @@ static int adapter_init_arch_info(struct target *target,
        armv7m->examine_debug_reason = adapter_examine_debug_reason;
        armv7m->stlink = true;
 
-       target_register_timer_callback(hl_handle_target_request, 1, 1, target);
+       target_register_timer_callback(hl_handle_target_request, 1,
+               TARGET_TIMER_TYPE_PERIODIC, target);
 
        return ERROR_OK;
 }
@@ -357,7 +358,7 @@ static int adapter_init_target(struct command_context *cmd_ctx,
        LOG_DEBUG("%s", __func__);
 
        armv7m_build_reg_cache(target);
-
+       arm_semihosting_init(target);
        return ERROR_OK;
 }
 
@@ -365,11 +366,17 @@ static int adapter_target_create(struct target *target,
                Jim_Interp *interp)
 {
        LOG_DEBUG("%s", __func__);
+       struct adiv5_private_config *pc = target->private_config;
+       if (pc != NULL && pc->ap_num > 0) {
+               LOG_ERROR("hla_target: invalid parameter -ap-num (> 0)");
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       }
 
        struct cortex_m_common *cortex_m = calloc(1, sizeof(struct cortex_m_common));
-
-       if (!cortex_m)
-               return ERROR_COMMAND_SYNTAX_ERROR;
+       if (cortex_m == NULL) {
+               LOG_ERROR("No memory creating target");
+               return ERROR_FAIL;
+       }
 
        adapter_init_arch_info(target, cortex_m, target->tap);
 
@@ -443,7 +450,7 @@ static int adapter_debug_entry(struct target *target)
 
        LOG_DEBUG("entered debug state in core mode: %s at PC 0x%08" PRIx32 ", target->state: %s",
                arm_mode_name(arm->core_mode),
-               *(uint32_t *)(arm->pc->value),
+               buf_get_u32(arm->pc->value, 0, 32),
                target_state_name(target));
 
        return retval;
@@ -466,6 +473,9 @@ static int adapter_poll(struct target *target)
        if (prev_target_state == state)
                return ERROR_OK;
 
+       if (prev_target_state == TARGET_DEBUG_RUNNING && state == TARGET_RUNNING)
+               return ERROR_OK;
+
        target->state = state;
 
        if (state == TARGET_HALTED) {
@@ -600,7 +610,7 @@ static int adapter_halt(struct target *target)
 }
 
 static int adapter_resume(struct target *target, int current,
-               uint32_t address, int handle_breakpoints,
+               target_addr_t address, int handle_breakpoints,
                int debug_execution)
 {
        int res;
@@ -610,8 +620,8 @@ static int adapter_resume(struct target *target, int current,
        struct breakpoint *breakpoint = NULL;
        struct reg *pc;
 
-       LOG_DEBUG("%s %d 0x%08" PRIx32 " %d %d", __func__, current, address,
-                       handle_breakpoints, debug_execution);
+       LOG_DEBUG("%s %d " TARGET_ADDR_FMT " %d %d", __func__, current,
+                       address, handle_breakpoints, debug_execution);
 
        if (target->state != TARGET_HALTED) {
                LOG_WARNING("target not halted");
@@ -658,7 +668,7 @@ static int adapter_resume(struct target *target, int current,
                /* Single step past breakpoint at current address */
                breakpoint = breakpoint_find(target, resume_pc);
                if (breakpoint) {
-                       LOG_DEBUG("unset breakpoint at 0x%8.8" PRIx32 " (ID: %" PRIu32 ")",
+                       LOG_DEBUG("unset breakpoint at " TARGET_ADDR_FMT " (ID: %" PRIu32 ")",
                                        breakpoint->address,
                                        breakpoint->unique_id);
                        cortex_m_unset_breakpoint(target, breakpoint);
@@ -691,7 +701,7 @@ static int adapter_resume(struct target *target, int current,
 }
 
 static int adapter_step(struct target *target, int current,
-               uint32_t address, int handle_breakpoints)
+               target_addr_t address, int handle_breakpoints)
 {
        int res;
        struct hl_interface_s *adapter = target_to_adapter(target);
@@ -754,7 +764,7 @@ static int adapter_step(struct target *target, int current,
        return ERROR_OK;
 }
 
-static int adapter_read_memory(struct target *target, uint32_t address,
+static int adapter_read_memory(struct target *target, target_addr_t address,
                uint32_t size, uint32_t count,
                uint8_t *buffer)
 {
@@ -763,12 +773,13 @@ static int adapter_read_memory(struct target *target, uint32_t address,
        if (!count || !buffer)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       LOG_DEBUG("%s 0x%08" PRIx32 " %" PRIu32 " %" PRIu32, __func__, address, size, count);
+       LOG_DEBUG("%s " TARGET_ADDR_FMT " %" PRIu32 " %" PRIu32,
+                         __func__, address, size, count);
 
        return adapter->layout->api->read_mem(adapter->handle, address, size, count, buffer);
 }
 
-static int adapter_write_memory(struct target *target, uint32_t address,
+static int adapter_write_memory(struct target *target, target_addr_t address,
                uint32_t size, uint32_t count,
                const uint8_t *buffer)
 {
@@ -777,7 +788,8 @@ static int adapter_write_memory(struct target *target, uint32_t address,
        if (!count || !buffer)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       LOG_DEBUG("%s 0x%08" PRIx32 " %" PRIu32 " %" PRIu32, __func__, address, size, count);
+       LOG_DEBUG("%s " TARGET_ADDR_FMT " %" PRIu32 " %" PRIu32,
+                         __func__, address, size, count);
 
        return adapter->layout->api->write_mem(adapter->handle, address, size, count, buffer);
 }
@@ -786,6 +798,9 @@ static const struct command_registration adapter_command_handlers[] = {
        {
                .chain = arm_command_handlers,
        },
+       {
+               .chain = armv7m_trace_command_handlers,
+       },
        COMMAND_REGISTRATION_DONE
 };
 
@@ -794,7 +809,9 @@ struct target_type hla_target = {
        .deprecated_name = "stm32_stlink",
 
        .init_target = adapter_init_target,
+       .deinit_target = cortex_m_deinit_target,
        .target_create = adapter_target_create,
+       .target_jim_configure = adiv5_jim_configure,
        .examine = cortex_m_examine,
        .commands = adapter_command_handlers,
 
@@ -809,6 +826,7 @@ struct target_type hla_target = {
        .resume = adapter_resume,
        .step = adapter_step,
 
+       .get_gdb_arch = arm_get_gdb_arch,
        .get_gdb_reg_list = armv7m_get_gdb_reg_list,
 
        .read_memory = adapter_read_memory,
@@ -824,4 +842,5 @@ struct target_type hla_target = {
        .remove_breakpoint = cortex_m_remove_breakpoint,
        .add_watchpoint = cortex_m_add_watchpoint,
        .remove_watchpoint = cortex_m_remove_watchpoint,
+       .profiling = cortex_m_profiling,
 };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)