openocd: src/target: replace the GPL-2.0-or-later license tag
[fw/openocd] / src / target / nds32_cmd.c
index 89da845d3f8ba82c21b7156e2d9ffe86ba11ae86..0e24009dba48b30b690840facd6b4d5377cfe0ea 100644 (file)
@@ -1,19 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
 /***************************************************************************
  *   Copyright (C) 2013 Andes Technology                                   *
  *   Hsiangkai Wang <hkwang@andestech.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     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   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, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
 extern struct nds32_edm_operation nds32_edm_ops[NDS32_EDM_OPERATION_MAX_NUM];
 extern uint32_t nds32_edm_ops_num;
 
-static const char *const NDS_MEMORY_ACCESS_NAME[] = {
+static const char *const nds_memory_access_name[] = {
        "BUS",
        "CPU",
 };
 
-static const char *const NDS_MEMORY_SELECT_NAME[] = {
+static const char *const nds_memory_select_name[] = {
        "AUTO",
        "MEM",
        "ILM",
@@ -84,13 +73,13 @@ COMMAND_HANDLER(handle_nds32_memory_access_command)
                        memory->access_channel = NDS_MEMORY_ACC_CPU;
 
                LOG_DEBUG("memory access channel is changed to %s",
-                               NDS_MEMORY_ACCESS_NAME[memory->access_channel]);
+                               nds_memory_access_name[memory->access_channel]);
 
                aice_memory_access(aice, memory->access_channel);
        } else {
                command_print(CMD, "%s: memory access channel: %s",
                                target_name(target),
-                               NDS_MEMORY_ACCESS_NAME[memory->access_channel]);
+                               nds_memory_access_name[memory->access_channel]);
        }
 
        return ERROR_OK;
@@ -147,7 +136,7 @@ COMMAND_HANDLER(handle_nds32_memory_mode_command)
 
        command_print(CMD, "%s: memory mode: %s",
                        target_name(target),
-                       NDS_MEMORY_SELECT_NAME[nds32->memory.mode]);
+                       nds_memory_select_name[nds32->memory.mode]);
 
        return ERROR_OK;
 }
@@ -575,10 +564,9 @@ COMMAND_HANDLER(handle_nds32_decode_command)
                read_addr = addr;
                i = 0;
                while (i < insn_count) {
-                       if (ERROR_OK != nds32_read_opcode(nds32, read_addr, &opcode))
+                       if (nds32_read_opcode(nds32, read_addr, &opcode) != ERROR_OK)
                                return ERROR_FAIL;
-                       if (ERROR_OK != nds32_evaluate_opcode(nds32, opcode,
-                                               read_addr, &instruction))
+                       if (nds32_evaluate_opcode(nds32, opcode, read_addr, &instruction) != ERROR_OK)
                                return ERROR_FAIL;
 
                        command_print(CMD, "%s", instruction.text);
@@ -594,9 +582,9 @@ COMMAND_HANDLER(handle_nds32_decode_command)
 
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr);
 
-               if (ERROR_OK != nds32_read_opcode(nds32, addr, &opcode))
+               if (nds32_read_opcode(nds32, addr, &opcode) != ERROR_OK)
                        return ERROR_FAIL;
-               if (ERROR_OK != nds32_evaluate_opcode(nds32, opcode, addr, &instruction))
+               if (nds32_evaluate_opcode(nds32, opcode, addr, &instruction) != ERROR_OK)
                        return ERROR_FAIL;
 
                command_print(CMD, "%s", instruction.text);
@@ -681,8 +669,8 @@ static int jim_nds32_bulk_write(Jim_Interp *interp, int argc, Jim_Obj * const *a
 {
        const char *cmd_name = Jim_GetString(argv[0], NULL);
 
-       Jim_GetOptInfo goi;
-       Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
+       struct jim_getopt_info goi;
+       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
 
        if (goi.argc < 3) {
                Jim_SetResultFormatted(goi.interp,
@@ -692,23 +680,23 @@ static int jim_nds32_bulk_write(Jim_Interp *interp, int argc, Jim_Obj * const *a
 
        int e;
        jim_wide address;
-       e = Jim_GetOpt_Wide(&goi, &address);
+       e = jim_getopt_wide(&goi, &address);
        if (e != JIM_OK)
                return e;
 
        jim_wide count;
-       e = Jim_GetOpt_Wide(&goi, &count);
+       e = jim_getopt_wide(&goi, &count);
        if (e != JIM_OK)
                return e;
 
        uint32_t *data = malloc(count * sizeof(uint32_t));
-       if (data == NULL)
+       if (!data)
                return JIM_ERR;
 
        jim_wide i;
        for (i = 0; i < count; i++) {
                jim_wide tmp;
-               e = Jim_GetOpt_Wide(&goi, &tmp);
+               e = jim_getopt_wide(&goi, &tmp);
                if (e != JIM_OK) {
                        free(data);
                        return e;
@@ -722,8 +710,9 @@ static int jim_nds32_bulk_write(Jim_Interp *interp, int argc, Jim_Obj * const *a
                return JIM_ERR;
        }
 
-       struct command *c = jim_to_command(goi.interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        int result;
 
        result = target_write_buffer(target, address, count * 4, (const uint8_t *)data);
@@ -737,8 +726,8 @@ static int jim_nds32_multi_write(Jim_Interp *interp, int argc, Jim_Obj * const *
 {
        const char *cmd_name = Jim_GetString(argv[0], NULL);
 
-       Jim_GetOptInfo goi;
-       Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
+       struct jim_getopt_info goi;
+       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
 
        if (goi.argc < 3) {
                Jim_SetResultFormatted(goi.interp,
@@ -748,12 +737,13 @@ static int jim_nds32_multi_write(Jim_Interp *interp, int argc, Jim_Obj * const *
 
        int e;
        jim_wide num_of_pairs;
-       e = Jim_GetOpt_Wide(&goi, &num_of_pairs);
+       e = jim_getopt_wide(&goi, &num_of_pairs);
        if (e != JIM_OK)
                return e;
 
-       struct command *c = jim_to_command(goi.interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        struct aice_port_s *aice = target_to_aice(target);
        int result;
        uint32_t address;
@@ -763,12 +753,12 @@ static int jim_nds32_multi_write(Jim_Interp *interp, int argc, Jim_Obj * const *
        aice_set_command_mode(aice, AICE_COMMAND_MODE_PACK);
        for (i = 0; i < num_of_pairs; i++) {
                jim_wide tmp;
-               e = Jim_GetOpt_Wide(&goi, &tmp);
+               e = jim_getopt_wide(&goi, &tmp);
                if (e != JIM_OK)
                        break;
                address = (uint32_t)tmp;
 
-               e = Jim_GetOpt_Wide(&goi, &tmp);
+               e = jim_getopt_wide(&goi, &tmp);
                if (e != JIM_OK)
                        break;
                data = (uint32_t)tmp;
@@ -790,8 +780,8 @@ static int jim_nds32_bulk_read(Jim_Interp *interp, int argc, Jim_Obj * const *ar
 {
        const char *cmd_name = Jim_GetString(argv[0], NULL);
 
-       Jim_GetOptInfo goi;
-       Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
+       struct jim_getopt_info goi;
+       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
 
        if (goi.argc < 2) {
                Jim_SetResultFormatted(goi.interp,
@@ -801,12 +791,12 @@ static int jim_nds32_bulk_read(Jim_Interp *interp, int argc, Jim_Obj * const *ar
 
        int e;
        jim_wide address;
-       e = Jim_GetOpt_Wide(&goi, &address);
+       e = jim_getopt_wide(&goi, &address);
        if (e != JIM_OK)
                return e;
 
        jim_wide count;
-       e = Jim_GetOpt_Wide(&goi, &count);
+       e = jim_getopt_wide(&goi, &count);
        if (e != JIM_OK)
                return e;
 
@@ -814,8 +804,9 @@ static int jim_nds32_bulk_read(Jim_Interp *interp, int argc, Jim_Obj * const *ar
        if (goi.argc != 0)
                return JIM_ERR;
 
-       struct command *c = jim_to_command(goi.interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        uint32_t *data = malloc(count * sizeof(uint32_t));
        int result;
        result = target_read_buffer(target, address, count * 4, (uint8_t *)data);
@@ -837,8 +828,8 @@ static int jim_nds32_read_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const *
 {
        const char *cmd_name = Jim_GetString(argv[0], NULL);
 
-       Jim_GetOptInfo goi;
-       Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
+       struct jim_getopt_info goi;
+       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
 
        if (goi.argc < 1) {
                Jim_SetResultFormatted(goi.interp,
@@ -849,7 +840,7 @@ static int jim_nds32_read_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const *
        int e;
        const char *edm_sr_name;
        int edm_sr_name_len;
-       e = Jim_GetOpt_String(&goi, &edm_sr_name, &edm_sr_name_len);
+       e = jim_getopt_string(&goi, &edm_sr_name, &edm_sr_name_len);
        if (e != JIM_OK)
                return e;
 
@@ -866,8 +857,9 @@ static int jim_nds32_read_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const *
        else
                return ERROR_FAIL;
 
-       struct command *c = jim_to_command(goi.interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        struct aice_port_s *aice = target_to_aice(target);
        char data_str[11];
 
@@ -884,8 +876,8 @@ static int jim_nds32_write_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const
 {
        const char *cmd_name = Jim_GetString(argv[0], NULL);
 
-       Jim_GetOptInfo goi;
-       Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
+       struct jim_getopt_info goi;
+       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
 
        if (goi.argc < 2) {
                Jim_SetResultFormatted(goi.interp,
@@ -896,12 +888,12 @@ static int jim_nds32_write_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const
        int e;
        const char *edm_sr_name;
        int edm_sr_name_len;
-       e = Jim_GetOpt_String(&goi, &edm_sr_name, &edm_sr_name_len);
+       e = jim_getopt_string(&goi, &edm_sr_name, &edm_sr_name_len);
        if (e != JIM_OK)
                return e;
 
        jim_wide value;
-       e = Jim_GetOpt_Wide(&goi, &value);
+       e = jim_getopt_wide(&goi, &value);
        if (e != JIM_OK)
                return e;
 
@@ -915,8 +907,9 @@ static int jim_nds32_write_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const
        else
                return ERROR_FAIL;
 
-       struct command *c = jim_to_command(goi.interp);
-       struct target *target = c->jim_handler_data;
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        struct aice_port_s *aice = target_to_aice(target);
 
        aice_write_debug_reg(aice, edm_sr_number, value);