This is an automated email from Gerrit.

"Antonio Borneo <[email protected]>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9511

-- gerrit

commit 8db55af5faf480e0cbf16cfe9d4d8f438ab480b7
Author: Antonio Borneo <[email protected]>
Date:   Mon Mar 16 18:41:57 2026 +0100

    target: aarch64: deprecate command 'aarch64 disassemble'
    
    Deprecate the old command and fallback to the new one.
    Drop the old implementation of a64_disassemble().
    Add support for use of endianness and detection of target state.
    
    Change-Id: Ie4c45f65e574c3fe7506ee795210b1ae61602981
    Signed-off-by: Antonio Borneo <[email protected]>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index cae828543e..91f35f9027 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -11316,12 +11316,6 @@ target code relies on. In a configuration file, the 
command would typically be c
 However, normally it is not necessary to use the command at all.
 @end deffn
 
-@deffn {Command} {aarch64 disassemble} address [count]
-@cindex disassemble
-Disassembles @var{count} instructions starting at @var{address}.
-If @var{count} is not specified, a single instruction is disassembled.
-@end deffn
-
 @deffn {Command} {aarch64 smp} [on|off]
 Display, enable or disable SMP handling mode. The state of SMP handling 
influences the way targets in an SMP group
 are handled by the run control. With SMP handling enabled, issuing halt or 
resume to one core will trigger
diff --git a/src/target/Makefile.am b/src/target/Makefile.am
index 65331f58cf..3d855ab52f 100644
--- a/src/target/Makefile.am
+++ b/src/target/Makefile.am
@@ -89,7 +89,6 @@ ARMV8_SRC = \
        %D%/armv8_dpm.c \
        %D%/armv8_opcodes.c \
        %D%/aarch64.c \
-       %D%/a64_disassembler.c \
        %D%/armv8.c \
        %D%/armv8_cache.c
 
@@ -166,7 +165,6 @@ ARC_SRC = \
        %D%/armv7a_cache_l2x.h \
        %D%/armv7a_mmu.h \
        %D%/arm_disassembler.h \
-       %D%/a64_disassembler.h \
        %D%/arm_opcodes.h \
        %D%/arm_simulator.h \
        %D%/arm_semihosting.h \
diff --git a/src/target/a64_disassembler.c b/src/target/a64_disassembler.c
deleted file mode 100644
index ca3d3ea7a9..0000000000
--- a/src/target/a64_disassembler.c
+++ /dev/null
@@ -1,134 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-/***************************************************************************
- *   Copyright (C) 2019 by Mete Balci                                      *
- *   [email protected]                                                   *
- ***************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <helper/log.h>
-#include "target.h"
-#include "a64_disassembler.h"
-
-#if HAVE_CAPSTONE
-
-#include <capstone.h>
-
-static void print_opcode(struct command_invocation *cmd, const cs_insn *insn)
-{
-       uint32_t opcode = 0;
-
-       memcpy(&opcode, insn->bytes, insn->size);
-
-       if (insn->size == 4) {
-
-               uint16_t opcode_high = opcode >> 16;
-
-               opcode = opcode & 0xffff;
-
-               command_print(cmd,
-                               "0x%08" PRIx64"  %04x %04x\t%s\t%s",
-                               insn->address,
-                               opcode,
-                               opcode_high,
-                               insn->mnemonic,
-                               insn->op_str);
-
-       } else {
-
-               command_print(
-                               cmd,
-                               "0x%08" PRIx64"  %04x\t%s\t%s",
-                               insn->address,
-                               opcode,
-                               insn->mnemonic,
-                               insn->op_str);
-
-       }
-}
-
-int a64_disassemble(struct command_invocation *cmd, struct target *target, 
target_addr_t address, size_t count)
-{
-       int ret;
-       int csret;
-       csh handle;
-
-       csret = cs_open(CS_ARCH_ARM64, CS_MODE_LITTLE_ENDIAN, &handle);
-
-       if (csret != CS_ERR_OK) {
-
-               LOG_ERROR("cs_open() failed: %s", cs_strerror(csret));
-               return ERROR_FAIL;
-
-       }
-
-       csret = cs_option(handle, CS_OPT_SKIPDATA, CS_OPT_ON);
-
-       if (csret != CS_ERR_OK) {
-
-               LOG_ERROR("cs_option() failed: %s", cs_strerror(csret));
-               cs_close(&handle);
-               return ERROR_FAIL;
-
-       }
-
-       cs_insn *insn = cs_malloc(handle);
-
-       if (csret != CS_ERR_OK) {
-
-               LOG_ERROR("cs_malloc() failed: %s", cs_strerror(csret));
-               cs_close(&handle);
-               return ERROR_FAIL;
-
-       }
-
-       while (count > 0) {
-
-               uint8_t buffer[4];
-
-               ret = target_read_buffer(target, address, sizeof(buffer), 
buffer);
-
-               if (ret != ERROR_OK) {
-                       cs_free(insn, 1);
-                       cs_close(&handle);
-                       return ret;
-               }
-
-               size_t size = sizeof(buffer);
-               const uint8_t *tmp = buffer;
-
-               ret = cs_disasm_iter(handle, &tmp, &size, &address, insn);
-
-               if (!ret) {
-
-                       LOG_ERROR("cs_disasm_iter() failed: %s", 
cs_strerror(cs_errno(handle)));
-                       cs_free(insn, 1);
-                       cs_close(&handle);
-                       return ERROR_FAIL;
-
-               }
-
-               print_opcode(cmd, insn);
-               count--;
-
-       }
-
-       cs_free(insn, 1);
-       cs_close(&handle);
-
-       return ERROR_OK;
-}
-
-#else
-
-int a64_disassemble(struct command_invocation *cmd, struct target *target, 
target_addr_t address, size_t count)
-{
-       command_print(cmd, "capstone disassembly framework required");
-
-       return ERROR_FAIL;
-}
-
-#endif
diff --git a/src/target/a64_disassembler.h b/src/target/a64_disassembler.h
deleted file mode 100644
index 28fcf4b331..0000000000
--- a/src/target/a64_disassembler.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/***************************************************************************
- *   Copyright (C) 2019 by Mete Balci                                      *
- *   [email protected]                                                   *
- ***************************************************************************/
-
-#ifndef OPENOCD_TARGET_AARCH64_DISASSEMBLER_H
-#define OPENOCD_TARGET_AARCH64_DISASSEMBLER_H
-
-#include "target.h"
-
-int a64_disassemble(
-               struct command_invocation *cmd,
-               struct target *target,
-               target_addr_t address,
-               size_t count);
-
-#endif /* OPENOCD_TARGET_AARCH64_DISASSEMBLER_H */
diff --git a/src/target/aarch64.c b/src/target/aarch64.c
index 032a0da9a0..973a8c9bda 100644
--- a/src/target/aarch64.c
+++ b/src/target/aarch64.c
@@ -11,7 +11,6 @@
 
 #include "breakpoints.h"
 #include "aarch64.h"
-#include "a64_disassembler.h"
 #include "register.h"
 #include "target_request.h"
 #include "target_type.h"
@@ -2931,6 +2930,45 @@ static int aarch64_virt2phys(struct target *target, 
target_addr_t virt,
        return armv8_mmu_translate_va_pa(target, virt, phys, 1);
 }
 
+static int aarch64_insn_set(struct command_invocation *cmd,
+       struct target *target, const char **insn_set)
+{
+       if (target->state != TARGET_HALTED) {
+               command_print(cmd, "[%s] not halted", target_name(target));
+               return ERROR_TARGET_NOT_HALTED;
+       }
+
+       struct arm *arm = target_to_arm(target);
+
+       switch (arm->core_state) {
+       case ARM_STATE_AARCH64:
+               if (target->endianness == TARGET_BIG_ENDIAN)
+                       *insn_set = "arm64be";
+               else
+                       *insn_set = "arm64";
+               break;
+
+       case ARM_STATE_ARM:
+               if (target->endianness == TARGET_BIG_ENDIAN)
+                       *insn_set = "armbe";
+               else
+                       *insn_set = "arm";
+               break;
+
+       case ARM_STATE_THUMB:
+       case ARM_STATE_THUMB_EE:
+               *insn_set = "thumb";
+               break;
+
+       default:
+               command_print(cmd, "[%s] unknown core_state %d", 
target_name(target),
+                                         arm->core_state);
+               return ERROR_FAIL;
+       }
+
+       return ERROR_OK;
+}
+
 /*
  * private target configuration items
  */
@@ -3040,39 +3078,6 @@ COMMAND_HANDLER(aarch64_handle_dbginit_command)
        return aarch64_init_debug_access(target);
 }
 
-COMMAND_HANDLER(aarch64_handle_disassemble_command)
-{
-       struct target *target = get_current_target(CMD_CTX);
-
-       if (!target) {
-               LOG_ERROR("No target selected");
-               return ERROR_FAIL;
-       }
-
-       struct aarch64_common *aarch64 = target_to_aarch64(target);
-
-       if (aarch64->common_magic != AARCH64_COMMON_MAGIC) {
-               command_print(CMD, "current target isn't an AArch64");
-               return ERROR_FAIL;
-       }
-
-       int count = 1;
-       target_addr_t address;
-
-       switch (CMD_ARGC) {
-       case 2:
-               COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], count);
-       /* FALL THROUGH */
-       case 1:
-               COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address);
-               break;
-       default:
-               return ERROR_COMMAND_SYNTAX_ERROR;
-       }
-
-       return a64_disassemble(CMD, target, address, count);
-}
-
 COMMAND_HANDLER(aarch64_mask_interrupts_command)
 {
        struct target *target = get_current_target(CMD_CTX);
@@ -3219,13 +3224,6 @@ static const struct command_registration 
aarch64_exec_command_handlers[] = {
                .help = "Initialize core debug",
                .usage = "",
        },
-       {
-               .name = "disassemble",
-               .handler = aarch64_handle_disassemble_command,
-               .mode = COMMAND_EXEC,
-               .help = "Disassemble instructions",
-               .usage = "address [count]",
-       },
        {
                .name = "maskisr",
                .handler = aarch64_mask_interrupts_command,
@@ -3315,6 +3313,8 @@ struct target_type aarch64_target = {
        .write_phys_memory = aarch64_write_phys_memory,
        .mmu = aarch64_mmu,
        .virt2phys = aarch64_virt2phys,
+
+       .insn_set = aarch64_insn_set,
 };
 
 struct target_type armv8r_target = {
@@ -3351,4 +3351,6 @@ struct target_type armv8r_target = {
        .init_target = aarch64_init_target,
        .deinit_target = aarch64_deinit_target,
        .examine = aarch64_examine,
+
+       .insn_set = aarch64_insn_set,
 };
diff --git a/src/target/oocd_capstone.c b/src/target/oocd_capstone.c
index 1c15cce73f..6479605fc9 100644
--- a/src/target/oocd_capstone.c
+++ b/src/target/oocd_capstone.c
@@ -30,6 +30,7 @@ static struct {
        { "arm", CS_ARCH_ARM, CS_MODE_ARM },
        { "armbe", CS_ARCH_ARM, CS_MODE_ARM | CS_MODE_BIG_ENDIAN },
        { "arm64", CS_ARCH_ARM64, CS_MODE_LITTLE_ENDIAN },
+       { "arm64be", CS_ARCH_ARM64, CS_MODE_BIG_ENDIAN },
        { "cortexm", CS_ARCH_ARM, CS_MODE_ARM | CS_MODE_THUMB | CS_MODE_MCLASS 
},
        { "thumb", CS_ARCH_ARM, CS_MODE_ARM | CS_MODE_THUMB },
 };
diff --git a/src/target/startup.tcl b/src/target/startup.tcl
index 0b463dde08..8a05614c91 100644
--- a/src/target/startup.tcl
+++ b/src/target/startup.tcl
@@ -301,6 +301,12 @@ proc "arm disassemble" {args} {
        eval disassemble $args
 }
 
+lappend _telnet_autocomplete_skip "aarch64 disassemble"
+proc "aarch64 disassemble" {args} {
+       echo "DEPRECATED! use 'disassemble $args' not 'aarch64 disassemble 
$args'"
+       eval disassemble $args
+}
+
 lappend _telnet_autocomplete_skip _post_init_target_cortex_a_cache_auto
 proc _post_init_target_cortex_a_cache_auto {} {
        set cortex_a_found 0

-- 

Reply via email to