RTOS Thread awareness support wip
[openocd.git] / src / target / target.c
index 66aa6bf7bf3d7987b3e31ece61835cd35940f895..abe1b43ae03e01f5d79a464f5281d2cf93b23545 100644 (file)
@@ -14,6 +14,9 @@
  *   Copyright (C) 2008 by Rick Altherr                                    *
  *   kc8apf@kc8apf.net>                                                    *
  *                                                                         *
+ *   Copyright (C) 2011 by Broadcom Corporation                            *
+ *   Evan Hunter - ehunter@broadcom.com                                    *
+ *                                                                         *
  *   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 2 of the License, or     *
 #include "register.h"
 #include "trace.h"
 #include "image.h"
+#include "rtos/rtos.h"
 
 
+static int target_read_buffer_default(struct target *target, uint32_t address,
+               uint32_t size, uint8_t *buffer);
+static int target_write_buffer_default(struct target *target, uint32_t address,
+               uint32_t size, const uint8_t *buffer);
 static int target_array2mem(Jim_Interp *interp, struct target *target,
                int argc, Jim_Obj *const *argv);
 static int target_mem2array(Jim_Interp *interp, struct target *target,
@@ -66,7 +74,6 @@ extern struct target_type dragonite_target;
 extern struct target_type xscale_target;
 extern struct target_type cortexm3_target;
 extern struct target_type cortexa8_target;
-extern struct target_type cortexa9_target;
 extern struct target_type arm11_target;
 extern struct target_type mips_m4k_target;
 extern struct target_type avr_target;
@@ -89,7 +96,6 @@ static struct target_type *target_types[] =
        &xscale_target,
        &cortexm3_target,
        &cortexa8_target,
-       &cortexa9_target,
        &arm11_target,
        &mips_m4k_target,
        &avr_target,
@@ -280,6 +286,15 @@ uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
                return be_to_h_u32(buffer);
 }
 
+/* read a uint24_t from a buffer in target memory endianness */
+uint32_t target_buffer_get_u24(struct target *target, const uint8_t *buffer)
+{
+       if (target->endianness == TARGET_LITTLE_ENDIAN)
+               return le_to_h_u24(buffer);
+       else
+               return be_to_h_u24(buffer);
+}
+
 /* read a uint16_t from a buffer in target memory endianness */
 uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer)
 {
@@ -304,6 +319,15 @@ void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t valu
                h_u32_to_be(buffer, value);
 }
 
+/* write a uint24_t to a buffer in target memory endianness */
+void target_buffer_set_u24(struct target *target, uint8_t *buffer, uint32_t value)
+{
+       if (target->endianness == TARGET_LITTLE_ENDIAN)
+               h_u24_to_le(buffer, value);
+       else
+               h_u24_to_be(buffer, value);
+}
+
 /* write a uint16_t to a buffer in target memory endianness */
 void target_buffer_set_u16(struct target *target, uint8_t *buffer, uint16_t value)
 {
@@ -595,7 +619,7 @@ const char *target_type_name(struct target *target)
        return target->type->name;
 }
 
-static int target_write_memory_imp(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
+static int target_write_memory_imp(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
 {
        if (!target_was_examined(target))
        {
@@ -685,19 +709,19 @@ static int target_read_phys_memory(struct target *target,
 }
 
 int target_write_memory(struct target *target,
-               uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
+               uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
 {
        return target->type->write_memory(target, address, size, count, buffer);
 }
 
 static int target_write_phys_memory(struct target *target,
-               uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
+               uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
 {
        return target->type->write_phys_memory(target, address, size, count, buffer);
 }
 
 int target_bulk_write_memory(struct target *target,
-               uint32_t address, uint32_t count, uint8_t *buffer)
+               uint32_t address, uint32_t count, const uint8_t *buffer)
 {
        return target->type->bulk_write_memory(target, address, count, buffer);
 }
@@ -763,7 +787,7 @@ err_read_phys_memory(struct target *target, uint32_t address,
 
 static int
 err_write_phys_memory(struct target *target, uint32_t address,
-               uint32_t size, uint32_t count, uint8_t *buffer)
+               uint32_t size, uint32_t count, const uint8_t *buffer)
 {
        LOG_ERROR("Not implemented: %s", __func__);
        return ERROR_FAIL;
@@ -847,6 +871,13 @@ static int target_init_one(struct command_context *cmd_ctx,
                type->read_phys_memory = type->read_memory;
                type->virt2phys = identity_virt2phys;
        }
+
+       if (target->type->read_buffer == NULL)
+               target->type->read_buffer = target_read_buffer_default;
+
+       if (target->type->write_buffer == NULL)
+               target->type->write_buffer = target_write_buffer_default;
+
        return ERROR_OK;
 }
 
@@ -1313,9 +1344,8 @@ int target_arch_state(struct target *target)
  * mode respectively, otherwise data is handled as quickly as
  * possible
  */
-int target_write_buffer(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
+int target_write_buffer(struct target *target, uint32_t address, uint32_t size, const uint8_t *buffer)
 {
-       int retval;
        LOG_DEBUG("writing buffer of %i byte at 0x%8.8x",
                  (int)size, (unsigned)address);
 
@@ -1338,6 +1368,13 @@ int target_write_buffer(struct target *target, uint32_t address, uint32_t size,
                return ERROR_FAIL;
        }
 
+       return target->type->write_buffer(target, address, size, buffer);
+}
+
+static int target_write_buffer_default(struct target *target, uint32_t address, uint32_t size, const uint8_t *buffer)
+{
+       int retval = ERROR_OK;
+
        if (((address % 2) == 0) && (size == 2))
        {
                return target_write_memory(target, address, 2, 1, buffer);
@@ -1388,7 +1425,7 @@ int target_write_buffer(struct target *target, uint32_t address, uint32_t size,
                        return retval;
        }
 
-       return ERROR_OK;
+       return retval;
 }
 
 /* Single aligned words are guaranteed to use 16 or 32 bit access
@@ -1397,7 +1434,6 @@ int target_write_buffer(struct target *target, uint32_t address, uint32_t size,
  */
 int target_read_buffer(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
 {
-       int retval;
        LOG_DEBUG("reading buffer of %i byte at 0x%8.8x",
                          (int)size, (unsigned)address);
 
@@ -1420,6 +1456,13 @@ int target_read_buffer(struct target *target, uint32_t address, uint32_t size, u
                return ERROR_FAIL;
        }
 
+       return target->type->read_buffer(target, address, size, buffer);
+}
+
+static int target_read_buffer_default(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
+{
+       int retval = ERROR_OK;
+
        if (((address % 2) == 0) && (size == 2))
        {
                return target_read_memory(target, address, 2, 1, buffer);
@@ -1504,7 +1547,7 @@ int target_checksum_memory(struct target *target, uint32_t address, uint32_t siz
                        return retval;
                }
 
-               /* convert to target endianess */
+               /* convert to target endianness */
                for (i = 0; i < (size/sizeof(uint32_t)); i++)
                {
                        uint32_t target_data;
@@ -2351,10 +2394,10 @@ COMMAND_HANDLER(handle_md_command)
 }
 
 typedef int (*target_write_fn)(struct target *target,
-               uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
+               uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer);
 
 static int target_write_memory_fast(struct target *target,
-               uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
+               uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
 {
        return target_write_buffer(target, address, size * count, buffer);
 }
@@ -3664,6 +3707,8 @@ enum target_cfg_param {
        TCFG_VARIANT,
        TCFG_COREID,
        TCFG_CHAIN_POSITION,
+       TCFG_DBGBASE,
+       TCFG_RTOS,
 };
 
 static Jim_Nvp nvp_config_opts[] = {
@@ -3677,7 +3722,8 @@ static Jim_Nvp nvp_config_opts[] = {
        { .name = "-variant",          .value = TCFG_VARIANT },
        { .name = "-coreid",           .value = TCFG_COREID },
        { .name = "-chain-position",   .value = TCFG_CHAIN_POSITION },
-
+       { .name = "-dbgbase",          .value = TCFG_DBGBASE },
+       { .name = "-rtos",             .value = TCFG_RTOS },
        { .name = NULL, .value = -1 }
 };
 
@@ -3968,6 +4014,34 @@ static int target_configure(Jim_GetOptInfo *goi, struct target *target)
                        Jim_SetResultString(goi->interp, target->tap->dotted_name, -1);
                        /* loop for more e*/
                        break;
+               case TCFG_DBGBASE:
+                       if (goi->isconfigure) {
+                               e = Jim_GetOpt_Wide(goi, &w);
+                               if (e != JIM_OK) {
+                                       return e;
+                               }
+                               target->dbgbase = (uint32_t)w;
+                               target->dbgbase_set = true;
+                       } else {
+                               if (goi->argc != 0) {
+                                       goto no_params;
+                               }
+                       }
+                       Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, target->dbgbase));
+                       /* loop for more */
+                       break;
+
+               case TCFG_RTOS:
+                       /* RTOS */
+                       {
+                               int result = rtos_create( goi, target );
+                               if ( result != JIM_OK )
+                               {
+                                       return result;
+                               }
+                       }
+                       /* loop for more */
+                       break;
                }
        } /* while (goi->argc) */
 
@@ -4690,6 +4764,9 @@ static int target_create(Jim_GetOptInfo *goi)
 
        target->endianness = TARGET_ENDIAN_UNKNOWN;
 
+       target->rtos = NULL;
+       target->rtos_auto_detect = false;
+
        /* Do the rest as "configure" options */
        goi->isconfigure = 1;
        e = target_configure(goi, target);

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)