rtos: Remove typedef'd struct
[openocd.git] / src / rtos / hwthread.c
index 2d9e42fa608b0a825729669952a6a4f892745696..ce24086353a2398a34250b25f1c0296bd1f00dfd 100644 (file)
 static bool hwthread_detect_rtos(struct target *target);
 static int hwthread_create(struct target *target);
 static int hwthread_update_threads(struct rtos *rtos);
+static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id,
+               uint32_t reg_num, struct rtos_reg *rtos_reg);
 static int hwthread_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
-                                       struct rtos_reg **reg_list, int *num_regs);
-static int hwthread_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]);
+               struct rtos_reg **reg_list, int *num_regs);
+static int hwthread_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]);
 static int hwthread_smp_init(struct target *target);
+static int hwthread_set_reg(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value);
 
 #define HW_THREAD_NAME_STR_SIZE (32)
 
@@ -51,8 +54,10 @@ const struct rtos_type hwthread_rtos = {
        .create = hwthread_create,
        .update_threads = hwthread_update_threads,
        .get_thread_reg_list = hwthread_get_thread_reg_list,
+       .get_thread_reg = hwthread_get_thread_reg,
        .get_symbol_list_to_lookup = hwthread_get_symbol_list_to_lookup,
        .smp_init = hwthread_smp_init,
+       .set_reg = hwthread_set_reg,
 };
 
 struct hwthread_params {
@@ -201,70 +206,132 @@ static int hwthread_smp_init(struct target *target)
        return hwthread_update_threads(target->rtos);
 }
 
-static int hwthread_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
-                                       struct rtos_reg **rtos_reg_list, int *num_regs)
+static struct target *hwthread_find_thread(struct target *target, int64_t thread_id)
 {
-       struct target_list *head;
-       struct target *target;
-       struct target *curr;
-       struct reg **reg_list;
-       int retval;
-
-       if (rtos == NULL)
-               return ERROR_FAIL;
-
-       target = rtos->target;
-
        /* Find the thread with that thread_id */
+       if (target == NULL)
+               return NULL;
        if (target->smp) {
-               curr = NULL;
-               for (head = target->head; head != NULL; head = head->next) {
-                       curr = head->target;
-
-                       if (thread_id == threadid_from_target(curr))
-                               break;
+               for (struct target_list *head = target->head; head != NULL; head = head->next) {
+                       if (thread_id == threadid_from_target(head->target))
+                               return head->target;
                }
+       } else if (thread_id == threadid_from_target(target)) {
+               return target;
+       }
+       return NULL;
+}
 
-               if (head == NULL)
-                       return ERROR_FAIL;
-       } else {
-               curr = target;
-               if (thread_id != threadid_from_target(curr))
-                       return ERROR_FAIL;
+static int hwthread_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
+               struct rtos_reg **rtos_reg_list, int *rtos_reg_list_size)
+{
+       if (rtos == NULL)
+               return ERROR_FAIL;
 
-       }
+       struct target *target = rtos->target;
+
+       struct target *curr = hwthread_find_thread(target, thread_id);
+       if (curr == NULL)
+               return ERROR_FAIL;
 
        if (!target_was_examined(curr))
                return ERROR_FAIL;
 
-       retval = target_get_gdb_reg_list(curr, &reg_list, num_regs,
+       int reg_list_size;
+       struct reg **reg_list;
+       int retval = target_get_gdb_reg_list(curr, &reg_list, &reg_list_size,
                        REG_CLASS_GENERAL);
        if (retval != ERROR_OK)
                return retval;
 
-       *rtos_reg_list = calloc(*num_regs, sizeof(struct rtos_reg));
+       int j = 0;
+       for (int i = 0; i < reg_list_size; i++) {
+               if (reg_list[i] == NULL || reg_list[i]->exist == false || reg_list[i]->hidden)
+                       continue;
+               j++;
+       }
+       *rtos_reg_list_size = j;
+       *rtos_reg_list = calloc(*rtos_reg_list_size, sizeof(struct rtos_reg));
        if (*rtos_reg_list == NULL) {
                free(reg_list);
                return ERROR_FAIL;
        }
 
-       for (int i = 0; i < *num_regs; i++) {
-               (*rtos_reg_list)[i].number = (*reg_list)[i].number;
-               (*rtos_reg_list)[i].size = (*reg_list)[i].size;
-               memcpy((*rtos_reg_list)[i].value, (*reg_list)[i].value,
-                      ((*reg_list)[i].size + 7) / 8);
+       j = 0;
+       for (int i = 0; i < reg_list_size; i++) {
+               if (reg_list[i] == NULL || reg_list[i]->exist == false || reg_list[i]->hidden)
+                       continue;
+               (*rtos_reg_list)[j].number = (*reg_list)[i].number;
+               (*rtos_reg_list)[j].size = (*reg_list)[i].size;
+               memcpy((*rtos_reg_list)[j].value, (*reg_list)[i].value,
+                               ((*reg_list)[i].size + 7) / 8);
+               j++;
        }
-
        free(reg_list);
 
        return ERROR_OK;
+}
+
+static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id,
+               uint32_t reg_num, struct rtos_reg *rtos_reg)
+{
+       if (rtos == NULL)
+               return ERROR_FAIL;
+
+       struct target *target = rtos->target;
+
+       struct target *curr = hwthread_find_thread(target, thread_id);
+       if (curr == NULL) {
+               LOG_ERROR("Couldn't find RTOS thread for id %" PRId64 ".", thread_id);
+               return ERROR_FAIL;
+       }
+
+       if (!target_was_examined(curr)) {
+               LOG_ERROR("Target %d hasn't been examined yet.", curr->coreid);
+               return ERROR_FAIL;
+       }
+
+       struct reg *reg = register_get_by_number(curr->reg_cache, reg_num, true);
+       if (!reg) {
+               LOG_ERROR("Couldn't find register %" PRIu32 " in thread %" PRId64 ".", reg_num,
+                               thread_id);
+               return ERROR_FAIL;
+       }
+
+       if (reg->type->get(reg) != ERROR_OK)
+               return ERROR_FAIL;
+
+       rtos_reg->number = reg->number;
+       rtos_reg->size = reg->size;
+       unsigned bytes = (reg->size + 7) / 8;
+       assert(bytes <= sizeof(rtos_reg->value));
+       memcpy(rtos_reg->value, reg->value, bytes);
+
+       return ERROR_OK;
+}
 
+static int hwthread_set_reg(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value)
+{
+       if (rtos == NULL)
+               return ERROR_FAIL;
+
+       struct target *target = rtos->target;
+
+       struct target *curr = hwthread_find_thread(target, rtos->current_thread);
+       if (curr == NULL)
+               return ERROR_FAIL;
+
+       struct reg *reg = register_get_by_number(curr->reg_cache, reg_num, true);
+       if (!reg)
+               return ERROR_FAIL;
+
+       return reg->type->set(reg, reg_value);
 }
 
-static int hwthread_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[])
+static int hwthread_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[])
 {
        /* return an empty list, we don't have any symbols to look up */
-       *symbol_list = calloc(1, sizeof(symbol_table_elem_t));
+       *symbol_list = calloc(1, sizeof(struct symbol_table_elem));
        (*symbol_list)[0].symbol_name = NULL;
        return 0;
 }
@@ -272,26 +339,10 @@ static int hwthread_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]
 static int hwthread_target_for_threadid(struct connection *connection, int64_t thread_id, struct target **p_target)
 {
        struct target *target = get_target_from_connection(connection);
-       struct target_list *head;
-       struct target *curr;
-
-       if (target->smp) {
-               /* Find the thread with that thread_id */
-               curr = NULL;
-               for (head = target->head; head != NULL; head = head->next) {
-                       curr = head->target;
-
-                       if (thread_id == threadid_from_target(curr))
-                               break;
-               }
 
-               if (head == NULL)
-                       return ERROR_FAIL;
-       } else {
-               curr = target;
-               if (thread_id != threadid_from_target(curr))
-                       return ERROR_FAIL;
-       }
+       struct target *curr = hwthread_find_thread(target, thread_id);
+       if (curr == NULL)
+               return ERROR_FAIL;
 
        *p_target = curr;
 

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)