This is an automated email from Gerrit.

"Name of user not set <[email protected]>" just uploaded a new 
patch set to Gerrit, which you can find at 
https://review.openocd.org/c/openocd/+/9788

-- gerrit

commit 96fc87b5a663271213fae36026e18d15abbb8901
Author: OpinionatedDeer <[email protected]>
Date:   Wed Jul 22 09:29:49 2026 +0530

    target/smp: split target->smp into bool enable flag and unsigned int smp_id
    
    - Running smp off; smp on changes the SMP group identifier of all targets
    in the group to 1, disregarding the original group number assigned by
    the target smp command. RISC-V targets use this identifier as the DM
    halt group ID, so the halt group becomes misconfigured without the DM
    being updated.
    - Fix by introducing target->smp_id to store the persistent group
    identifier, separate from target->smp which is now a bool flag for
    SMP enable/disable. Since smp_off no longer overwrites the group ID,
    smp_on preserves the original group.
    - Replace curr->smp 1/0 Values with Boolean
    Link: https://github.com/riscv-collab/riscv-openocd/issues/1294
    
    Change-Id: I494dbcc4c8bec240d20339b340f111f0cd892c3c
    Signed-off-by: OpinionatedDeer <[email protected]>

diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c
index d5dd1fc709..3974f6e219 100644
--- a/src/target/cortex_a.c
+++ b/src/target/cortex_a.c
@@ -711,9 +711,9 @@ static int update_halt_gdb(struct target *target)
                        continue;
 
                /* avoid recursion in cortex_a_poll() */
-               curr->smp = 0;
+               curr->smp = false;
                cortex_a_poll(curr);
-               curr->smp = 1;
+               curr->smp = true;
        }
 
        /* after all targets were updated, poll the gdb serving target */
diff --git a/src/target/espressif/esp_xtensa_smp.c 
b/src/target/espressif/esp_xtensa_smp.c
index b9e2156440..15c8337730 100644
--- a/src/target/espressif/esp_xtensa_smp.c
+++ b/src/target/espressif/esp_xtensa_smp.c
@@ -290,12 +290,12 @@ static int esp_xtensa_smp_update_halt_gdb(struct target 
*target, bool *need_resu
                /* avoid auto-resume after syscall, it will be done later */
                esp_xtensa_smp->other_core_does_resume = true;
                /* avoid recursion in esp_xtensa_smp_poll() */
-               curr->smp = 0;
+               curr->smp = false;
                if (esp_xtensa_smp->chip_ops->poll)
                        ret = esp_xtensa_smp->chip_ops->poll(curr);
                else
                        ret = esp_xtensa_smp_poll(curr);
-               curr->smp = 1;
+               curr->smp = true;
                if (ret != ERROR_OK)
                        return ret;
                esp_xtensa_smp->other_core_does_resume = false;
@@ -346,9 +346,9 @@ static int esp_xtensa_smp_resume_cores(struct target 
*target,
                /* in single-core mode disabled core cannot be examined, but 
need to be resumed too*/
                if ((curr != target) && (curr->state != TARGET_RUNNING) && 
target_was_examined(curr)) {
                        /*  resume current address, not in SMP mode */
-                       curr->smp = 0;
+                       curr->smp = false;
                        int res = esp_xtensa_smp_resume(curr, true, 0, 
handle_breakpoints, debug_execution);
-                       curr->smp = 1;
+                       curr->smp = true;
                        if (res != ERROR_OK)
                                return res;
                }
@@ -466,10 +466,10 @@ int esp_xtensa_smp_watchpoint_add(struct target *target, 
struct watchpoint *watc
                /* Need to use high level API here because every target for 
core contains list of watchpoints.
                 * GDB works with active core only, so we need to duplicate 
every watchpoint on other cores,
                 * otherwise watchpoint_free() on active core can fail if WP 
has been initially added on another core. */
-               curr->smp = 0;
+               curr->smp = false;
                res = watchpoint_add(curr, watchpoint->address, 
watchpoint->length,
                        watchpoint->rw, watchpoint->value, watchpoint->mask);
-               curr->smp = 1;
+               curr->smp = true;
                if (res != ERROR_OK)
                        return res;
        }
@@ -491,9 +491,9 @@ int esp_xtensa_smp_watchpoint_remove(struct target *target, 
struct watchpoint *w
                if (curr == target)
                        continue;
                /* see big comment in esp_xtensa_smp_watchpoint_add() */
-               curr->smp = 0;
+               curr->smp = false;
                watchpoint_remove(curr, watchpoint->address);
-               curr->smp = 1;
+               curr->smp = true;
        }
        return ERROR_OK;
 }
diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index c7e068b394..f1be9c0a9d 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -2167,14 +2167,14 @@ static int examine(struct target *target)
        }
 
        if (target->smp) {
-               if (set_group(target, &info->haltgroup_supported, target->smp, 
HALT_GROUP) != ERROR_OK)
+               if (set_group(target, &info->haltgroup_supported, 
target->smp_id, HALT_GROUP) != ERROR_OK)
                        return ERROR_FAIL;
                if (info->haltgroup_supported)
                        LOG_TARGET_INFO(target, "Core %d made part of halt 
group %d.", info->index,
-                                       target->smp);
+                                       target->smp_id);
                else
                        LOG_TARGET_INFO(target, "Core %d could not be made part 
of halt group %d.",
-                                       info->index, target->smp);
+                                       info->index, target->smp_id);
        }
 
        /* Some regression suites rely on seeing 'Examined RISC-V core' to know
diff --git a/src/target/smp.c b/src/target/smp.c
index 8a9dd2d9d7..fbad6d9398 100644
--- a/src/target/smp.c
+++ b/src/target/smp.c
@@ -106,14 +106,14 @@ COMMAND_HANDLER(default_handle_smp_command)
 
        if (!strcmp(CMD_ARGV[0], "on")) {
                foreach_smp_target(head, target->smp_targets)
-                       head->target->smp = 1;
+                       head->target->smp = true;
 
                return ERROR_OK;
        }
 
        if (!strcmp(CMD_ARGV[0], "off")) {
                foreach_smp_target(head, target->smp_targets)
-                       head->target->smp = 0;
+                       head->target->smp = false;
 
                /* fixes the target display to the debugger */
                if (!list_empty(target->smp_targets) && target->gdb_service)
diff --git a/src/target/target.c b/src/target/target.c
index 1b2bc8191b..a8c964e5c9 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -2240,7 +2240,8 @@ static void free_smp_target_list(struct list_head 
*smp_targets)
        struct target_list *head, *tmp;
        list_for_each_entry_safe(head, tmp, smp_targets, lh) {
                list_del(&head->lh);
-               head->target->smp = 0;
+               head->target->smp = false;
+               head->target->smp_id = 0;
                head->target->smp_targets = &empty_smp_targets;
                free(head);
        }
@@ -6120,7 +6121,8 @@ COMMAND_HANDLER(handle_target_smp)
        }
        foreach_smp_target(curr, lh) {
                struct target *target = curr->target;
-               target->smp = smp_group;
+               target->smp = true;
+               target->smp_id = smp_group;
                target->smp_targets = lh;
        }
        smp_group++;
diff --git a/src/target/target.h b/src/target/target.h
index ce1fc728be..44069bf5d7 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -197,7 +197,8 @@ struct target {
         * poll too quickly because we'll just overwhelm the user with error
         * messages. */
        struct backoff_timer backoff;
-       unsigned int smp;                                       /* Unique 
non-zero number for each SMP group */
+       bool smp;                                                       /* set 
to true if smp is enabled */
+       unsigned int smp_id;                            /* Unique non-zero 
number for each SMP group */
        struct list_head *smp_targets;          /* list all targets in this smp 
group/cluster
                                                                                
 * The head of the list is shared between the
                                                                                
 * cluster, thus here there is a pointer */

-- 

Reply via email to