target/arm_adi_v5,arm_dap: introduce multidrop_targetsel and its configuration
[openocd.git] / src / target / nds32.c
index 4c9f29134b32b9cdd4d15e7eb3176dd17cfe5bbb..12340ac2c0b0e9a0dfdb012ed0b5a7382e7ce17c 100644 (file)
@@ -13,9 +13,7 @@
  *   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, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -29,9 +27,6 @@
 #include "nds32_tlb.h"
 #include "nds32_disassembler.h"
 
-const int NDS32_BREAK_16 = 0x00EA;      /* 0xEA00 */
-const int NDS32_BREAK_32 = 0x0A000064;  /* 0x6400000A */
-
 struct nds32_edm_operation nds32_edm_ops[NDS32_EDM_OPERATION_MAX_NUM];
 uint32_t nds32_edm_ops_num;
 
@@ -49,7 +44,7 @@ const char *nds32_debug_type_name[11] = {
        "LOAD STORE GLOBAL STOP",
 };
 
-static const int NDS32_LM_SIZE_TABLE[16] = {
+static const int nds32_lm_size_table[16] = {
        4 * 1024,
        8 * 1024,
        16 * 1024,
@@ -63,7 +58,7 @@ static const int NDS32_LM_SIZE_TABLE[16] = {
        2 * 1024,
 };
 
-static const int NDS32_LINE_SIZE_TABLE[6] = {
+static const int nds32_line_size_table[6] = {
        0,
        8,
        16,
@@ -86,32 +81,32 @@ static int nds32_get_core_reg(struct reg *reg)
        }
 
        if (reg->valid) {
-               LOG_DEBUG("reading register(cached) %i(%s), value: 0x%8.8" PRIx32,
-                               reg_arch_info->num, reg->name, reg_arch_info->value);
+               uint32_t val = buf_get_u32(reg_arch_info->value, 0, 32);
+               LOG_DEBUG("reading register(cached) %" PRIi32 "(%s), value: 0x%8.8" PRIx32,
+                               reg_arch_info->num, reg->name, val);
                return ERROR_OK;
        }
 
        int mapped_regnum = nds32->register_map(nds32, reg_arch_info->num);
 
        if (reg_arch_info->enable == false) {
-               reg_arch_info->value = NDS32_REGISTER_DISABLE;
+               buf_set_u32(reg_arch_info->value, 0, 32, NDS32_REGISTER_DISABLE);
                retval = ERROR_FAIL;
        } else {
-               if ((nds32->fpu_enable == false) &&
-                       (NDS32_REG_TYPE_FPU == nds32_reg_type(mapped_regnum))) {
-                       reg_arch_info->value = 0;
+               uint32_t val = 0;
+               if ((nds32->fpu_enable == false)
+                               && (nds32_reg_type(mapped_regnum) == NDS32_REG_TYPE_FPU)) {
                        retval = ERROR_OK;
-               } else if ((nds32->audio_enable == false) &&
-                       (NDS32_REG_TYPE_AUMR == nds32_reg_type(mapped_regnum))) {
-                       reg_arch_info->value = 0;
+               } else if ((nds32->audio_enable == false)
+                               && (nds32_reg_type(mapped_regnum) == NDS32_REG_TYPE_AUMR)) {
                        retval = ERROR_OK;
                } else {
-                       retval = aice_read_register(aice,
-                                       mapped_regnum, &(reg_arch_info->value));
+                       retval = aice_read_register(aice, mapped_regnum, &val);
                }
+               buf_set_u32(reg_arch_info->value, 0, 32, val);
 
-               LOG_DEBUG("reading register %i(%s), value: 0x%8.8" PRIx32,
-                               reg_arch_info->num, reg->name, reg_arch_info->value);
+               LOG_DEBUG("reading register %" PRIi32 "(%s), value: 0x%8.8" PRIx32,
+                               reg_arch_info->num, reg->name, val);
        }
 
        if (retval == ERROR_OK) {
@@ -139,17 +134,17 @@ static int nds32_get_core_reg_64(struct reg *reg)
                return ERROR_OK;
 
        if (reg_arch_info->enable == false) {
-               reg_arch_info->value_64 = NDS32_REGISTER_DISABLE;
+               buf_set_u64(reg_arch_info->value, 0, 64, NDS32_REGISTER_DISABLE);
                retval = ERROR_FAIL;
        } else {
-               if ((nds32->fpu_enable == false) &&
-                       ((FD0 <= reg_arch_info->num) && (reg_arch_info->num <= FD31))) {
-                       reg_arch_info->value_64 = 0;
+               uint64_t val = 0;
+               if ((nds32->fpu_enable == false)
+                               && ((reg_arch_info->num >= FD0) && (reg_arch_info->num <= FD31))) {
                        retval = ERROR_OK;
                } else {
-                       retval = aice_read_reg_64(aice, reg_arch_info->num,
-                                       &(reg_arch_info->value_64));
+                       retval = aice_read_reg_64(aice, reg_arch_info->num, &val);
                }
+               buf_set_u64(reg_arch_info->value, 0, 64, val);
        }
 
        if (retval == ERROR_OK) {
@@ -198,7 +193,7 @@ static int nds32_update_cache_info(struct nds32 *nds32)
 {
        uint32_t value;
 
-       if (ERROR_OK == nds32_get_mapped_reg(nds32, MR8, &value)) {
+       if (nds32_get_mapped_reg(nds32, MR8, &value) == ERROR_OK) {
                if (value & 0x1)
                        nds32->memory.icache.enable = true;
                else
@@ -309,40 +304,42 @@ static int nds32_set_core_reg(struct reg *reg, uint8_t *buf)
        if (nds32_reg_exception(mapped_regnum, value))
                return ERROR_OK;
 
-       LOG_DEBUG("writing register %i(%s) with value 0x%8.8" PRIx32,
+       LOG_DEBUG("writing register %" PRIi32 "(%s) with value 0x%8.8" PRIx32,
                        reg_arch_info->num, reg->name, value);
 
        if ((nds32->fpu_enable == false) &&
-               (NDS32_REG_TYPE_FPU == nds32_reg_type(mapped_regnum))) {
+               (nds32_reg_type(mapped_regnum) == NDS32_REG_TYPE_FPU)) {
 
                buf_set_u32(reg->value, 0, 32, 0);
        } else if ((nds32->audio_enable == false) &&
-               (NDS32_REG_TYPE_AUMR == nds32_reg_type(mapped_regnum))) {
+               (nds32_reg_type(mapped_regnum) == NDS32_REG_TYPE_AUMR)) {
 
                buf_set_u32(reg->value, 0, 32, 0);
        } else {
                buf_set_u32(reg->value, 0, 32, value);
-               aice_write_register(aice, mapped_regnum, reg_arch_info->value);
+               uint32_t val = buf_get_u32(reg_arch_info->value, 0, 32);
+               aice_write_register(aice, mapped_regnum, val);
 
                /* After set value to registers, read the value from target
                 * to avoid W1C inconsistency. */
-               aice_read_register(aice, mapped_regnum, &(reg_arch_info->value));
+               aice_read_register(aice, mapped_regnum, &val);
+               buf_set_u32(reg_arch_info->value, 0, 32, val);
        }
 
        reg->valid = true;
        reg->dirty = false;
 
        /* update registers to take effect right now */
-       if (IR0 == mapped_regnum) {
+       if (mapped_regnum == IR0) {
                nds32_update_psw(nds32);
-       } else if (MR0 == mapped_regnum) {
+       } else if (mapped_regnum == MR0) {
                nds32_update_mmu_info(nds32);
-       } else if ((MR6 == mapped_regnum) || (MR7 == mapped_regnum)) {
+       } else if ((mapped_regnum == MR6) || (mapped_regnum == MR7)) {
                /* update lm information */
                nds32_update_lm_info(nds32);
-       } else if (MR8 == mapped_regnum) {
+       } else if (mapped_regnum == MR8) {
                nds32_update_cache_info(nds32);
-       } else if (FUCPR == mapped_regnum) {
+       } else if (mapped_regnum == FUCPR) {
                /* update audio/fpu setting */
                nds32_check_extension(nds32);
        }
@@ -364,7 +361,7 @@ static int nds32_set_core_reg_64(struct reg *reg, uint8_t *buf)
        }
 
        if ((nds32->fpu_enable == false) &&
-               ((FD0 <= reg_arch_info->num) && (reg_arch_info->num <= FD31))) {
+               ((reg_arch_info->num >= FD0) && (reg_arch_info->num <= FD31))) {
 
                buf_set_u32(reg->value, 0, 32, 0);
                buf_set_u32(reg->value, 32, 32, 0);
@@ -395,7 +392,7 @@ static const struct reg_arch_type nds32_reg_access_type_64 = {
 static struct reg_cache *nds32_build_reg_cache(struct target *target,
                struct nds32 *nds32)
 {
-       struct reg_cache *cache = malloc(sizeof(struct reg_cache));
+       struct reg_cache *cache = calloc(sizeof(struct reg_cache), 1);
        struct reg *reg_list = calloc(TOTAL_REG_NUM, sizeof(struct reg));
        struct nds32_reg *reg_arch_info = calloc(TOTAL_REG_NUM, sizeof(struct nds32_reg));
        int i;
@@ -423,21 +420,21 @@ static struct reg_cache *nds32_build_reg_cache(struct target *target,
                reg_list[i].size = nds32_reg_size(i);
                reg_list[i].arch_info = &reg_arch_info[i];
 
-               reg_list[i].reg_data_type = malloc(sizeof(struct reg_data_type));
+               reg_list[i].reg_data_type = calloc(sizeof(struct reg_data_type), 1);
 
-               if (FD0 <= reg_arch_info[i].num && reg_arch_info[i].num <= FD31) {
-                       reg_list[i].value = &(reg_arch_info[i].value_64);
+               if (reg_arch_info[i].num >= FD0 && reg_arch_info[i].num <= FD31) {
+                       reg_list[i].value = reg_arch_info[i].value;
                        reg_list[i].type = &nds32_reg_access_type_64;
 
                        reg_list[i].reg_data_type->type = REG_TYPE_IEEE_DOUBLE;
                        reg_list[i].reg_data_type->id = "ieee_double";
                        reg_list[i].group = "float";
                } else {
-                       reg_list[i].value = &(reg_arch_info[i].value);
+                       reg_list[i].value = reg_arch_info[i].value;
                        reg_list[i].type = &nds32_reg_access_type;
                        reg_list[i].group = "general";
 
-                       if ((FS0 <= reg_arch_info[i].num) && (reg_arch_info[i].num <= FS31)) {
+                       if ((reg_arch_info[i].num >= FS0) && (reg_arch_info[i].num <= FS31)) {
                                reg_list[i].reg_data_type->type = REG_TYPE_IEEE_SINGLE;
                                reg_list[i].reg_data_type->id = "ieee_single";
                                reg_list[i].group = "float";
@@ -459,20 +456,20 @@ static struct reg_cache *nds32_build_reg_cache(struct target *target,
                        }
                }
 
-               if (R16 <= reg_arch_info[i].num && reg_arch_info[i].num <= R25)
+               if (reg_arch_info[i].num >= R16 && reg_arch_info[i].num <= R25)
                        reg_list[i].caller_save = true;
                else
                        reg_list[i].caller_save = false;
 
                reg_list[i].feature = malloc(sizeof(struct reg_feature));
 
-               if (R0 <= reg_arch_info[i].num && reg_arch_info[i].num <= IFC_LP)
+               if (reg_arch_info[i].num >= R0 && reg_arch_info[i].num <= IFC_LP)
                        reg_list[i].feature->name = "org.gnu.gdb.nds32.core";
-               else if (CR0 <= reg_arch_info[i].num && reg_arch_info[i].num <= SECUR0)
+               else if (reg_arch_info[i].num >= CR0 && reg_arch_info[i].num <= SECUR0)
                        reg_list[i].feature->name = "org.gnu.gdb.nds32.system";
-               else if (D0L24 <= reg_arch_info[i].num && reg_arch_info[i].num <= CBE3)
+               else if (reg_arch_info[i].num >= D0L24 && reg_arch_info[i].num <= CBE3)
                        reg_list[i].feature->name = "org.gnu.gdb.nds32.audio";
-               else if (FPCSR <= reg_arch_info[i].num && reg_arch_info[i].num <= FD31)
+               else if (reg_arch_info[i].num >= FPCSR && reg_arch_info[i].num <= FD31)
                        reg_list[i].feature->name = "org.gnu.gdb.nds32.fpu";
 
                cache->num_regs++;
@@ -534,7 +531,7 @@ int nds32_get_mapped_reg(struct nds32 *nds32, unsigned regnum, uint32_t *value)
 
        r = nds32_reg_current(nds32, regnum);
 
-       if (ERROR_OK != r->type->get(r))
+       if (r->type->get(r) != ERROR_OK)
                return ERROR_FAIL;
 
        *value = buf_get_u32(r->value, 0, 32);
@@ -639,7 +636,7 @@ static int nds32_select_memory_mode(struct target *target, uint32_t address,
        /* init end_address */
        *end_address = address_end;
 
-       if (NDS_MEMORY_ACC_CPU == memory->access_channel)
+       if (memory->access_channel == NDS_MEMORY_ACC_CPU)
                return ERROR_OK;
 
        if (edm->access_control == false) {
@@ -653,7 +650,7 @@ static int nds32_select_memory_mode(struct target *target, uint32_t address,
                return ERROR_OK;
        }
 
-       if (NDS_MEMORY_SELECT_AUTO != memory->mode) {
+       if (memory->mode != NDS_MEMORY_SELECT_AUTO) {
                LOG_DEBUG("Memory mode is not AUTO");
                return ERROR_OK;
        }
@@ -730,7 +727,7 @@ int nds32_read_buffer(struct target *target, uint32_t address,
        struct nds32 *nds32 = target_to_nds32(target);
        struct nds32_memory *memory = &(nds32->memory);
 
-       if ((NDS_MEMORY_ACC_CPU == memory->access_channel) &&
+       if ((memory->access_channel == NDS_MEMORY_ACC_CPU) &&
                        (target->state != TARGET_HALTED)) {
                LOG_WARNING("target was not halted");
                return ERROR_TARGET_NOT_HALTED;
@@ -823,7 +820,7 @@ int nds32_read_memory(struct target *target, uint32_t address,
        return aice_read_mem_unit(aice, address, size, count, buffer);
 }
 
-int nds32_read_phys_memory(struct target *target, uint32_t address,
+int nds32_read_phys_memory(struct target *target, target_addr_t address,
                uint32_t size, uint32_t count, uint8_t *buffer)
 {
        struct aice_port_s *aice = target_to_aice(target);
@@ -853,7 +850,7 @@ int nds32_write_buffer(struct target *target, uint32_t address,
        struct nds32 *nds32 = target_to_nds32(target);
        struct nds32_memory *memory = &(nds32->memory);
 
-       if ((NDS_MEMORY_ACC_CPU == memory->access_channel) &&
+       if ((memory->access_channel == NDS_MEMORY_ACC_CPU) &&
                        (target->state != TARGET_HALTED)) {
                LOG_WARNING("target was not halted");
                return ERROR_TARGET_NOT_HALTED;
@@ -932,7 +929,7 @@ int nds32_write_memory(struct target *target, uint32_t address,
        return aice_write_mem_unit(aice, address, size, count, buffer);
 }
 
-int nds32_write_phys_memory(struct target *target, uint32_t address,
+int nds32_write_phys_memory(struct target *target, target_addr_t address,
                uint32_t size, uint32_t count, const uint8_t *buffer)
 {
        struct aice_port_s *aice = target_to_aice(target);
@@ -997,7 +994,7 @@ int nds32_arch_state(struct target *target)
                        nds32->virtual_hosting ? ", virtual hosting" : "");
 
        /* save pc value to pseudo register pc */
-       struct reg *reg = register_get_by_name(target->reg_cache, "pc", 1);
+       struct reg *reg = register_get_by_name(target->reg_cache, "pc", true);
        buf_set_u32(reg->value, 0, 32, value_pc);
 
        return ERROR_OK;
@@ -1134,7 +1131,7 @@ static void nds32_init_config(struct nds32 *nds32)
        misc_config->div_instruction = (value_cr4 >> 5) & 0x1;
        misc_config->mac_instruction = (value_cr4 >> 6) & 0x1;
        misc_config->audio_isa = (value_cr4 >> 7) & 0x3;
-       misc_config->L2_cache = (value_cr4 >> 9) & 0x1;
+       misc_config->l2_cache = (value_cr4 >> 9) & 0x1;
        misc_config->reduce_register = (value_cr4 >> 10) & 0x1;
        misc_config->addr_24 = (value_cr4 >> 11) & 0x1;
        misc_config->interruption_level = (value_cr4 >> 12) & 0x1;
@@ -1462,8 +1459,7 @@ int nds32_add_software_breakpoint(struct target *target,
                break_insn = NDS32_BREAK_32;
        }
 
-       if (breakpoint->orig_instr != NULL)
-               free(breakpoint->orig_instr);
+       free(breakpoint->orig_instr);
 
        breakpoint->orig_instr = malloc(breakpoint->length);
        memcpy(breakpoint->orig_instr, &data, breakpoint->length);
@@ -1545,14 +1541,18 @@ int nds32_restore_context(struct target *target)
                        if (reg->valid == true) {
 
                                LOG_DEBUG("examining dirty reg: %s", reg->name);
-                               LOG_DEBUG("writing register %i "
-                                               "with value 0x%8.8" PRIx32, i, buf_get_u32(reg->value, 0, 32));
+                               LOG_DEBUG("writing register %d with value 0x%8.8" PRIx32,
+                                               i, buf_get_u32(reg->value, 0, 32));
 
                                reg_arch_info = reg->arch_info;
-                               if (FD0 <= reg_arch_info->num && reg_arch_info->num <= FD31)
-                                       aice_write_reg_64(aice, reg_arch_info->num, reg_arch_info->value_64);
-                               else
-                                       aice_write_register(aice, reg_arch_info->num, reg_arch_info->value);
+                               if (reg_arch_info->num >= FD0 && reg_arch_info->num <= FD31) {
+                                       uint64_t val = buf_get_u64(reg_arch_info->value, 0, 64);
+                                       aice_write_reg_64(aice, reg_arch_info->num, val);
+                               } else {
+                                       uint32_t val = buf_get_u32(reg_arch_info->value, 0, 32);
+                                       aice_write_register(aice, reg_arch_info->num, val);
+                               }
+
                                reg->valid = true;
                                reg->dirty = false;
                        }
@@ -1572,11 +1572,11 @@ int nds32_edm_config(struct nds32 *nds32)
        aice_read_debug_reg(aice, NDS_EDM_SR_EDM_CFG, &edm_cfg);
 
        nds32->edm.version = (edm_cfg >> 16) & 0xFFFF;
-       LOG_INFO("EDM version 0x%04" PRIx32, nds32->edm.version);
+       LOG_INFO("EDM version 0x%04x", nds32->edm.version);
 
        nds32->edm.breakpoint_num = (edm_cfg & 0x7) + 1;
 
-       if ((nds32->edm.version & 0x1000) || (0x60 <= nds32->edm.version))
+       if ((nds32->edm.version & 0x1000) || (nds32->edm.version >= 0x60))
                nds32->edm.access_control = true;
        else
                nds32->edm.access_control = false;
@@ -1619,11 +1619,11 @@ int nds32_config(struct nds32 *nds32)
        uint32_t size_index;
        nds32_get_mapped_reg(nds32, MR6, &value_mr6);
        size_index = (value_mr6 >> 1) & 0xF;
-       nds32->memory.ilm_size = NDS32_LM_SIZE_TABLE[size_index];
+       nds32->memory.ilm_size = nds32_lm_size_table[size_index];
 
        nds32_get_mapped_reg(nds32, MR7, &value_mr7);
        size_index = (value_mr7 >> 1) & 0xF;
-       nds32->memory.dlm_size = NDS32_LM_SIZE_TABLE[size_index];
+       nds32->memory.dlm_size = nds32_lm_size_table[size_index];
 
        return ERROR_OK;
 }
@@ -1644,24 +1644,33 @@ int nds32_init_arch_info(struct target *target, struct nds32 *nds32)
        nds32->reset_halt_as_examine = false;
        nds32->keep_target_edm_ctl = false;
        nds32->word_access_mem = false;
-       nds32->virtual_hosting = false;
+       nds32->virtual_hosting = true;
        nds32->hit_syscall = false;
        nds32->active_syscall_id = NDS32_SYSCALL_UNDEFINED;
        nds32->virtual_hosting_errno = 0;
        nds32->virtual_hosting_ctrl_c = false;
+       nds32->attached = false;
+
+       nds32->syscall_break.asid = 0;
+       nds32->syscall_break.length = 4;
+       nds32->syscall_break.set = 0;
+       nds32->syscall_break.orig_instr = NULL;
+       nds32->syscall_break.next = NULL;
+       nds32->syscall_break.unique_id = 0x515CAll + target->target_number;
+       nds32->syscall_break.linked_brp = 0;
 
        nds32_reg_init();
 
-       if (ERROR_FAIL == nds32_reg_cache_init(target, nds32))
+       if (nds32_reg_cache_init(target, nds32) == ERROR_FAIL)
                return ERROR_FAIL;
 
-       if (ERROR_OK != nds32_init_register_table(nds32))
+       if (nds32_init_register_table(nds32) != ERROR_OK)
                return ERROR_FAIL;
 
        return ERROR_OK;
 }
 
-int nds32_virtual_to_physical(struct target *target, uint32_t address, uint32_t *physical)
+int nds32_virtual_to_physical(struct target *target, target_addr_t address, target_addr_t *physical)
 {
        struct nds32 *nds32 = target_to_nds32(target);
 
@@ -1670,23 +1679,23 @@ int nds32_virtual_to_physical(struct target *target, uint32_t address, uint32_t
                return ERROR_OK;
        }
 
-       if (ERROR_OK == nds32_probe_tlb(nds32, address, physical))
+       if (nds32_probe_tlb(nds32, address, physical) == ERROR_OK)
                return ERROR_OK;
 
-       if (ERROR_OK == nds32_walk_page_table(nds32, address, physical))
+       if (nds32_walk_page_table(nds32, address, physical) == ERROR_OK)
                return ERROR_OK;
 
        return ERROR_FAIL;
 }
 
-int nds32_cache_sync(struct target *target, uint32_t address, uint32_t length)
+int nds32_cache_sync(struct target *target, target_addr_t address, uint32_t length)
 {
        struct aice_port_s *aice = target_to_aice(target);
        struct nds32 *nds32 = target_to_nds32(target);
        struct nds32_cache *dcache = &(nds32->memory.dcache);
        struct nds32_cache *icache = &(nds32->memory.icache);
-       uint32_t dcache_line_size = NDS32_LINE_SIZE_TABLE[dcache->line_size];
-       uint32_t icache_line_size = NDS32_LINE_SIZE_TABLE[icache->line_size];
+       uint32_t dcache_line_size = nds32_line_size_table[dcache->line_size];
+       uint32_t icache_line_size = nds32_line_size_table[icache->line_size];
        uint32_t cur_address;
        int result;
        uint32_t start_line, end_line;
@@ -1698,8 +1707,8 @@ int nds32_cache_sync(struct target *target, uint32_t address, uint32_t length)
                /* (address + length - 1) / dcache_line_size */
                end_line = (address + length - 1) >> (dcache->line_size + 2);
 
-               for (cur_address = address, cur_line = start_line ;
-                               cur_line <= end_line ;
+               for (cur_address = address, cur_line = start_line;
+                               cur_line <= end_line;
                                cur_address += dcache_line_size, cur_line++) {
                        /* D$ write back */
                        result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_VA_WB, cur_address);
@@ -1719,15 +1728,14 @@ int nds32_cache_sync(struct target *target, uint32_t address, uint32_t length)
                /* (address + length - 1) / icache_line_size */
                end_line = (address + length - 1) >> (icache->line_size + 2);
 
-               for (cur_address = address, cur_line = start_line ;
-                               cur_line <= end_line ;
+               for (cur_address = address, cur_line = start_line;
+                               cur_line <= end_line;
                                cur_address += icache_line_size, cur_line++) {
                        /* Because PSW.IT is turned off under debug exception, address MUST
                         * be physical address.  L1I_VA_INVALIDATE uses PSW.IT to decide
                         * address translation or not. */
-                       uint32_t physical_addr;
-                       if (ERROR_FAIL == target->type->virt2phys(target, cur_address,
-                                               &physical_addr))
+                       target_addr_t physical_addr;
+                       if (target->type->virt2phys(target, cur_address, &physical_addr) == ERROR_FAIL)
                                return ERROR_FAIL;
 
                        /* I$ invalidate */
@@ -1751,7 +1759,7 @@ uint32_t nds32_nextpc(struct nds32 *nds32, int current, uint32_t address)
 }
 
 int nds32_step(struct target *target, int current,
-               uint32_t address, int handle_breakpoints)
+               target_addr_t address, int handle_breakpoints)
 {
        LOG_DEBUG("target->state: %s",
                        target_state_name(target));
@@ -1765,7 +1773,7 @@ int nds32_step(struct target *target, int current,
 
        address = nds32_nextpc(nds32, current, address);
 
-       LOG_DEBUG("STEP PC %08" PRIx32 "%s", address, !current ? "!" : "");
+       LOG_DEBUG("STEP PC %08" TARGET_PRIxADDR "%s", address, !current ? "!" : "");
 
        /** set DSSIM */
        uint32_t ir14_value;
@@ -1791,7 +1799,7 @@ int nds32_step(struct target *target, int current,
 
        if (no_step == false) {
                struct aice_port_s *aice = target_to_aice(target);
-               if (ERROR_OK != aice_step(aice))
+               if (aice_step(aice) != ERROR_OK)
                        return ERROR_FAIL;
        }
 
@@ -1834,7 +1842,7 @@ static int nds32_step_without_watchpoint(struct nds32 *nds32)
 
        struct aice_port_s *aice = target_to_aice(target);
 
-       if (ERROR_OK != aice_step(aice))
+       if (aice_step(aice) != ERROR_OK)
                return ERROR_FAIL;
 
        /* save state */
@@ -1915,10 +1923,9 @@ int nds32_examine_debug_reason(struct nds32 *nds32)
 
                                nds32_get_mapped_reg(nds32, PC, &value_pc);
 
-                               if (ERROR_OK != nds32_read_opcode(nds32, value_pc, &opcode))
+                               if (nds32_read_opcode(nds32, value_pc, &opcode) != ERROR_OK)
                                        return ERROR_FAIL;
-                               if (ERROR_OK != nds32_evaluate_opcode(nds32, opcode, value_pc,
-                                                       &instruction))
+                               if (nds32_evaluate_opcode(nds32, opcode, value_pc, &instruction) != ERROR_OK)
                                        return ERROR_FAIL;
 
                                /* hit 'break 0x7FFF' */
@@ -1942,7 +1949,7 @@ int nds32_examine_debug_reason(struct nds32 *nds32)
                                nds32_step_without_watchpoint(nds32);
 
                                /* before single_step, save exception address */
-                               if (ERROR_OK != result)
+                               if (result != ERROR_OK)
                                        return ERROR_FAIL;
 
                                target->debug_reason = DBG_REASON_WATCHPOINT;
@@ -1957,8 +1964,7 @@ int nds32_examine_debug_reason(struct nds32 *nds32)
                case NDS32_DEBUG_DATA_VALUE_WATCHPOINT_IMPRECISE:
                case NDS32_DEBUG_DATA_ADDR_WATCHPOINT_NEXT_PRECISE:
                case NDS32_DEBUG_DATA_VALUE_WATCHPOINT_NEXT_PRECISE:
-                       if (ERROR_OK != nds32->get_watched_address(nds32,
-                                               &(nds32->watched_address), reason))
+                       if (nds32->get_watched_address(nds32, &(nds32->watched_address), reason) != ERROR_OK)
                                return ERROR_FAIL;
 
                        target->debug_reason = DBG_REASON_WATCHPOINT;
@@ -1985,7 +1991,7 @@ int nds32_login(struct nds32 *nds32)
 
        LOG_DEBUG("nds32_login");
 
-       if (nds32->edm_passcode != NULL) {
+       if (nds32->edm_passcode) {
                /* convert EDM passcode to command sequences */
                passcode_length = strlen(nds32->edm_passcode);
                command_sequence[0] = '\0';
@@ -1999,11 +2005,11 @@ int nds32_login(struct nds32 *nds32)
                        code_str[copy_length] = '\0';
                        code = strtoul(code_str, NULL, 16);
 
-                       sprintf(command_str, "write_misc gen_port0 0x%x;", code);
+                       sprintf(command_str, "write_misc gen_port0 0x%" PRIx32 ";", code);
                        strcat(command_sequence, command_str);
                }
 
-               if (ERROR_OK != aice_program_edm(aice, command_sequence))
+               if (aice_program_edm(aice, command_sequence) != ERROR_OK)
                        return ERROR_FAIL;
 
                /* get current privilege level */
@@ -2024,8 +2030,8 @@ int nds32_login(struct nds32 *nds32)
                        else
                                return ERROR_FAIL;
 
-                       sprintf(command_str, "write_misc %s 0x%x;", reg_name, code);
-                       if (ERROR_OK != aice_program_edm(aice, command_str))
+                       sprintf(command_str, "write_misc %s 0x%" PRIx32 ";", reg_name, code);
+                       if (aice_program_edm(aice, command_str) != ERROR_OK)
                                return ERROR_FAIL;
                }
        }
@@ -2050,9 +2056,9 @@ int nds32_halt(struct target *target)
        if (nds32_target_state(nds32, &state) != ERROR_OK)
                return ERROR_FAIL;
 
-       if (TARGET_HALTED != state)
+       if (state != TARGET_HALTED)
                /* TODO: if state == TARGET_HALTED, check ETYPE is DBGI or not */
-               if (ERROR_OK != aice_halt(aice))
+               if (aice_halt(aice) != ERROR_OK)
                        return ERROR_FAIL;
 
        CHECK_RETVAL(nds32->enter_debug_state(nds32, true));
@@ -2074,7 +2080,7 @@ int nds32_poll(struct target *target)
        if (state == TARGET_HALTED) {
                if (target->state != TARGET_HALTED) {
                        /* if false_hit, continue free_run */
-                       if (ERROR_OK != nds32->enter_debug_state(nds32, true)) {
+                       if (nds32->enter_debug_state(nds32, true) != ERROR_OK) {
                                struct aice_port_s *aice = target_to_aice(target);
                                aice_run(aice);
                                return ERROR_OK;
@@ -2107,9 +2113,11 @@ int nds32_poll(struct target *target)
 }
 
 int nds32_resume(struct target *target, int current,
-               uint32_t address, int handle_breakpoints, int debug_execution)
+               target_addr_t address, int handle_breakpoints, int debug_execution)
 {
-       LOG_DEBUG("current %d  address %08x  handle_breakpoints %d  debug_execution %d",
+       LOG_DEBUG("current %d address %08" TARGET_PRIxADDR
+                       " handle_breakpoints %d"
+                       " debug_execution %d",
                        current, address, handle_breakpoints, debug_execution);
 
        struct nds32 *nds32 = target_to_nds32(target);
@@ -2121,7 +2129,7 @@ int nds32_resume(struct target *target, int current,
 
        address = nds32_nextpc(nds32, current, address);
 
-       LOG_DEBUG("RESUME PC %08" PRIx32 "%s", address, !current ? "!" : "");
+       LOG_DEBUG("RESUME PC %08" TARGET_PRIxADDR "%s", address, !current ? "!" : "");
 
        if (!debug_execution)
                target_free_all_working_areas(target);
@@ -2155,12 +2163,40 @@ int nds32_resume(struct target *target, int current,
        return ERROR_OK;
 }
 
+static int nds32_soft_reset_halt(struct target *target)
+{
+       /* TODO: test it */
+       struct nds32 *nds32 = target_to_nds32(target);
+       struct aice_port_s *aice = target_to_aice(target);
+
+       aice_assert_srst(aice, AICE_SRST);
+
+       /* halt core and set pc to 0x0 */
+       int retval = target_halt(target);
+       if (retval != ERROR_OK)
+               return retval;
+
+       /* start fetching from IVB */
+       uint32_t value_ir3;
+       nds32_get_mapped_reg(nds32, IR3, &value_ir3);
+       nds32_set_mapped_reg(nds32, PC, value_ir3 & 0xFFFF0000);
+
+       return ERROR_OK;
+}
+
 int nds32_assert_reset(struct target *target)
 {
        struct nds32 *nds32 = target_to_nds32(target);
        struct aice_port_s *aice = target_to_aice(target);
        struct nds32_cpu_version *cpu_version = &(nds32->cpu_version);
 
+       /* TODO: apply hw reset signal in not examined state */
+       if (!(target_was_examined(target))) {
+               LOG_WARNING("Reset is not asserted because the target is not examined.");
+               LOG_WARNING("Use a reset button or power cycle the target.");
+               return ERROR_TARGET_NOT_EXAMINED;
+       }
+
        if (target->reset_halt) {
                if ((nds32->soft_reset_halt)
                        || (nds32->edm.version < 0x51)
@@ -2168,7 +2204,7 @@ int nds32_assert_reset(struct target *target)
                                && (cpu_version->revision == 0x1C)
                                && (cpu_version->cpu_id_family == 0xC)
                                && (cpu_version->cpu_id_version == 0x0)))
-                       target->type->soft_reset_halt(target);
+                       nds32_soft_reset_halt(target);
                else
                        aice_assert_srst(aice, AICE_RESET_HOLD);
        } else {
@@ -2187,27 +2223,21 @@ int nds32_assert_reset(struct target *target)
        return ERROR_OK;
 }
 
-static uint32_t nds32_backup_edm_ctl;
-static bool gdb_attached;
-
 static int nds32_gdb_attach(struct nds32 *nds32)
 {
-       LOG_DEBUG("nds32_gdb_attach");
+       LOG_DEBUG("nds32_gdb_attach, target coreid: %" PRId32, nds32->target->coreid);
 
-       if (gdb_attached == false) {
+       if (nds32->attached == false) {
 
                if (nds32->keep_target_edm_ctl) {
                        /* backup target EDM_CTL */
                        struct aice_port_s *aice = target_to_aice(nds32->target);
-                       aice_read_debug_reg(aice, NDS_EDM_SR_EDM_CTL, &nds32_backup_edm_ctl);
+                       aice_read_debug_reg(aice, NDS_EDM_SR_EDM_CTL, &nds32->backup_edm_ctl);
                }
 
                target_halt(nds32->target);
 
-               /* turn on polling */
-               jtag_poll_set_enabled(true);
-
-               gdb_attached = true;
+               nds32->attached = true;
        }
 
        return ERROR_OK;
@@ -2218,7 +2248,7 @@ static int nds32_gdb_detach(struct nds32 *nds32)
        LOG_DEBUG("nds32_gdb_detach");
        bool backup_virtual_hosting_setting;
 
-       if (gdb_attached) {
+       if (nds32->attached) {
 
                backup_virtual_hosting_setting = nds32->virtual_hosting;
                /* turn off virtual hosting before resume as gdb-detach */
@@ -2229,13 +2259,10 @@ static int nds32_gdb_detach(struct nds32 *nds32)
                if (nds32->keep_target_edm_ctl) {
                        /* restore target EDM_CTL */
                        struct aice_port_s *aice = target_to_aice(nds32->target);
-                       aice_write_debug_reg(aice, NDS_EDM_SR_EDM_CTL, nds32_backup_edm_ctl);
+                       aice_write_debug_reg(aice, NDS_EDM_SR_EDM_CTL, nds32->backup_edm_ctl);
                }
 
-               /* turn off polling */
-               jtag_poll_set_enabled(false);
-
-               gdb_attached = false;
+               nds32->attached = false;
        }
 
        return ERROR_OK;
@@ -2245,7 +2272,12 @@ static int nds32_callback_event_handler(struct target *target,
                enum target_event event, void *priv)
 {
        int retval = ERROR_OK;
-       struct nds32 *nds32 = priv;
+       int target_number = *(int *)priv;
+
+       if (target_number != target->target_number)
+               return ERROR_OK;
+
+       struct nds32 *nds32 = target_to_nds32(target);
 
        switch (event) {
                case TARGET_EVENT_GDB_ATTACH:
@@ -2266,11 +2298,9 @@ int nds32_init(struct nds32 *nds32)
        /* Initialize anything we can set up without talking to the target */
        nds32->memory.access_channel = NDS_MEMORY_ACC_CPU;
 
-       /* turn off polling by default */
-       jtag_poll_set_enabled(false);
-
        /* register event callback */
-       target_register_event_callback(nds32_callback_event_handler, nds32);
+       target_register_event_callback(nds32_callback_event_handler,
+                       &(nds32->target->target_number));
 
        return ERROR_OK;
 }
@@ -2278,7 +2308,7 @@ int nds32_init(struct nds32 *nds32)
 int nds32_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
 {
        /* fill syscall parameters to file-I/O info */
-       if (NULL == fileio_info) {
+       if (!fileio_info) {
                LOG_ERROR("Target has not initial file-I/O data structure");
                return ERROR_FAIL;
        }
@@ -2294,144 +2324,141 @@ int nds32_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fil
        syscall_id = (value_ir6 >> 16) & 0x7FFF;
        nds32->active_syscall_id = syscall_id;
 
-       LOG_DEBUG("hit syscall ID: 0x%x", syscall_id);
+       LOG_DEBUG("hit syscall ID: 0x%" PRIx32, syscall_id);
 
        /* free previous identifier storage */
-       if (NULL != fileio_info->identifier) {
-               free(fileio_info->identifier);
-               fileio_info->identifier = NULL;
-       }
+       free(fileio_info->identifier);
+       fileio_info->identifier = NULL;
+
+       uint32_t reg_r0, reg_r1, reg_r2;
+       nds32_get_mapped_reg(nds32, R0, &reg_r0);
+       nds32_get_mapped_reg(nds32, R1, &reg_r1);
+       nds32_get_mapped_reg(nds32, R2, &reg_r2);
 
        switch (syscall_id) {
                case NDS32_SYSCALL_EXIT:
-                       fileio_info->identifier = (char *)malloc(5);
+                       fileio_info->identifier = malloc(5);
                        sprintf(fileio_info->identifier, "exit");
-                       nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
+                       fileio_info->param_1 = reg_r0;
                        break;
                case NDS32_SYSCALL_OPEN:
                        {
                                uint8_t filename[256];
-                               fileio_info->identifier = (char *)malloc(5);
+                               fileio_info->identifier = malloc(5);
                                sprintf(fileio_info->identifier, "open");
-                               nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
+                               fileio_info->param_1 = reg_r0;
                                /* reserve fileio_info->param_2 for length of path */
-                               nds32_get_mapped_reg(nds32, R1, &(fileio_info->param_3));
-                               nds32_get_mapped_reg(nds32, R2, &(fileio_info->param_4));
+                               fileio_info->param_3 = reg_r1;
+                               fileio_info->param_4 = reg_r2;
 
-                               target->type->read_buffer(target, fileio_info->param_1,
-                                               256, filename);
-                               fileio_info->param_2 = strlen((char *)filename) + 1;
+                               target->type->read_buffer(target, reg_r0, 256, filename);
+                               fileio_info->param_2 = strlen((char *)filename);
                        }
                        break;
                case NDS32_SYSCALL_CLOSE:
-                       fileio_info->identifier = (char *)malloc(6);
+                       fileio_info->identifier = malloc(6);
                        sprintf(fileio_info->identifier, "close");
-                       nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
+                       fileio_info->param_1 = reg_r0;
                        break;
                case NDS32_SYSCALL_READ:
-                       fileio_info->identifier = (char *)malloc(5);
+                       fileio_info->identifier = malloc(5);
                        sprintf(fileio_info->identifier, "read");
-                       nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
-                       nds32_get_mapped_reg(nds32, R1, &(fileio_info->param_2));
-                       nds32_get_mapped_reg(nds32, R2, &(fileio_info->param_3));
+                       fileio_info->param_1 = reg_r0;
+                       fileio_info->param_2 = reg_r1;
+                       fileio_info->param_3 = reg_r2;
                        break;
                case NDS32_SYSCALL_WRITE:
-                       fileio_info->identifier = (char *)malloc(6);
+                       fileio_info->identifier = malloc(6);
                        sprintf(fileio_info->identifier, "write");
-                       nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
-                       nds32_get_mapped_reg(nds32, R1, &(fileio_info->param_2));
-                       nds32_get_mapped_reg(nds32, R2, &(fileio_info->param_3));
+                       fileio_info->param_1 = reg_r0;
+                       fileio_info->param_2 = reg_r1;
+                       fileio_info->param_3 = reg_r2;
                        break;
                case NDS32_SYSCALL_LSEEK:
-                       fileio_info->identifier = (char *)malloc(6);
+                       fileio_info->identifier = malloc(6);
                        sprintf(fileio_info->identifier, "lseek");
-                       nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
-                       nds32_get_mapped_reg(nds32, R1, &(fileio_info->param_2));
-                       nds32_get_mapped_reg(nds32, R2, &(fileio_info->param_3));
+                       fileio_info->param_1 = reg_r0;
+                       fileio_info->param_2 = reg_r1;
+                       fileio_info->param_3 = reg_r2;
                        break;
                case NDS32_SYSCALL_UNLINK:
                        {
                                uint8_t filename[256];
-                               fileio_info->identifier = (char *)malloc(7);
+                               fileio_info->identifier = malloc(7);
                                sprintf(fileio_info->identifier, "unlink");
-                               nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
+                               fileio_info->param_1 = reg_r0;
                                /* reserve fileio_info->param_2 for length of path */
 
-                               target->type->read_buffer(target, fileio_info->param_1,
-                                               256, filename);
-                               fileio_info->param_2 = strlen((char *)filename) + 1;
+                               target->type->read_buffer(target, reg_r0, 256, filename);
+                               fileio_info->param_2 = strlen((char *)filename);
                        }
                        break;
                case NDS32_SYSCALL_RENAME:
                        {
                                uint8_t filename[256];
-                               fileio_info->identifier = (char *)malloc(7);
+                               fileio_info->identifier = malloc(7);
                                sprintf(fileio_info->identifier, "rename");
-                               nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
+                               fileio_info->param_1 = reg_r0;
                                /* reserve fileio_info->param_2 for length of old path */
-                               nds32_get_mapped_reg(nds32, R1, &(fileio_info->param_3));
+                               fileio_info->param_3 = reg_r1;
                                /* reserve fileio_info->param_4 for length of new path */
 
-                               target->type->read_buffer(target, fileio_info->param_1,
-                                               256, filename);
-                               fileio_info->param_2 = strlen((char *)filename) + 1;
+                               target->type->read_buffer(target, reg_r0, 256, filename);
+                               fileio_info->param_2 = strlen((char *)filename);
 
-                               target->type->read_buffer(target, fileio_info->param_3,
-                                               256, filename);
-                               fileio_info->param_4 = strlen((char *)filename) + 1;
+                               target->type->read_buffer(target, reg_r1, 256, filename);
+                               fileio_info->param_4 = strlen((char *)filename);
                        }
                        break;
                case NDS32_SYSCALL_FSTAT:
-                       fileio_info->identifier = (char *)malloc(6);
+                       fileio_info->identifier = malloc(6);
                        sprintf(fileio_info->identifier, "fstat");
-                       nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
-                       nds32_get_mapped_reg(nds32, R1, &(fileio_info->param_2));
+                       fileio_info->param_1 = reg_r0;
+                       fileio_info->param_2 = reg_r1;
                        break;
                case NDS32_SYSCALL_STAT:
                        {
                                uint8_t filename[256];
-                               fileio_info->identifier = (char *)malloc(5);
+                               fileio_info->identifier = malloc(5);
                                sprintf(fileio_info->identifier, "stat");
-                               nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
+                               fileio_info->param_1 = reg_r0;
                                /* reserve fileio_info->param_2 for length of old path */
-                               nds32_get_mapped_reg(nds32, R1, &(fileio_info->param_3));
+                               fileio_info->param_3 = reg_r1;
 
-                               target->type->read_buffer(target, fileio_info->param_1,
-                                               256, filename);
+                               target->type->read_buffer(target, reg_r0, 256, filename);
                                fileio_info->param_2 = strlen((char *)filename) + 1;
                        }
                        break;
                case NDS32_SYSCALL_GETTIMEOFDAY:
-                       fileio_info->identifier = (char *)malloc(13);
+                       fileio_info->identifier = malloc(13);
                        sprintf(fileio_info->identifier, "gettimeofday");
-                       nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
-                       nds32_get_mapped_reg(nds32, R1, &(fileio_info->param_2));
+                       fileio_info->param_1 = reg_r0;
+                       fileio_info->param_2 = reg_r1;
                        break;
                case NDS32_SYSCALL_ISATTY:
-                       fileio_info->identifier = (char *)malloc(7);
+                       fileio_info->identifier = malloc(7);
                        sprintf(fileio_info->identifier, "isatty");
-                       nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
+                       fileio_info->param_1 = reg_r0;
                        break;
                case NDS32_SYSCALL_SYSTEM:
                        {
                                uint8_t command[256];
-                               fileio_info->identifier = (char *)malloc(7);
+                               fileio_info->identifier = malloc(7);
                                sprintf(fileio_info->identifier, "system");
-                               nds32_get_mapped_reg(nds32, R0, &(fileio_info->param_1));
+                               fileio_info->param_1 = reg_r0;
                                /* reserve fileio_info->param_2 for length of old path */
 
-                               target->type->read_buffer(target, fileio_info->param_1,
-                                               256, command);
-                               fileio_info->param_2 = strlen((char *)command) + 1;
+                               target->type->read_buffer(target, reg_r0, 256, command);
+                               fileio_info->param_2 = strlen((char *)command);
                        }
                        break;
                case NDS32_SYSCALL_ERRNO:
-                       fileio_info->identifier = (char *)malloc(6);
+                       fileio_info->identifier = malloc(6);
                        sprintf(fileio_info->identifier, "errno");
                        nds32_set_mapped_reg(nds32, R0, nds32->virtual_hosting_errno);
                        break;
                default:
-                       fileio_info->identifier = (char *)malloc(8);
+                       fileio_info->identifier = malloc(8);
                        sprintf(fileio_info->identifier, "unknown");
                        break;
        }
@@ -2441,7 +2468,7 @@ int nds32_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fil
 
 int nds32_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
 {
-       LOG_DEBUG("syscall return code: 0x%x, errno: 0x%x, ctrl_c: %s",
+       LOG_DEBUG("syscall return code: 0x%x, errno: 0x%x , ctrl_c: %s",
                        retcode, fileio_errno, ctrl_c ? "true" : "false");
 
        struct nds32 *nds32 = target_to_nds32(target);
@@ -2463,11 +2490,17 @@ int nds32_profiling(struct target *target, uint32_t *samples,
        struct aice_port_s *aice = target_to_aice(target);
        struct nds32 *nds32 = target_to_nds32(target);
 
+       /* REVISIT: can nds32 profile without halting? */
+       if (target->state != TARGET_HALTED) {
+               LOG_WARNING("target %s is not halted (profiling)", target->cmd_name);
+               return ERROR_TARGET_NOT_HALTED;
+       }
+
        if (max_num_samples < iteration)
                iteration = max_num_samples;
 
        int pc_regnum = nds32->register_map(nds32, PC);
-       aice->port->api->profiling(10, iteration, pc_regnum, samples, num_samples);
+       aice_profiling(aice, 10, iteration, pc_regnum, samples, num_samples);
 
        register_cache_invalidate(nds32->core_cache);
 
@@ -2477,8 +2510,8 @@ int nds32_profiling(struct target *target, uint32_t *samples,
 int nds32_gdb_fileio_write_memory(struct nds32 *nds32, uint32_t address,
                uint32_t size, const uint8_t *buffer)
 {
-       if ((NDS32_SYSCALL_FSTAT == nds32->active_syscall_id) ||
-                       (NDS32_SYSCALL_STAT == nds32->active_syscall_id)) {
+       if ((nds32->active_syscall_id == NDS32_SYSCALL_FSTAT) ||
+                       (nds32->active_syscall_id == NDS32_SYSCALL_STAT)) {
                /* If doing GDB file-I/O, target should convert 'struct stat'
                 * from gdb-format to target-format */
                uint8_t stat_buffer[NDS32_STRUCT_STAT_SIZE];
@@ -2561,7 +2594,7 @@ int nds32_gdb_fileio_write_memory(struct nds32 *nds32, uint32_t address,
                stat_buffer[59] = 0;
 
                return nds32_write_buffer(nds32->target, address, NDS32_STRUCT_STAT_SIZE, stat_buffer);
-       } else if (NDS32_SYSCALL_GETTIMEOFDAY == nds32->active_syscall_id) {
+       } else if (nds32->active_syscall_id == NDS32_SYSCALL_GETTIMEOFDAY) {
                /* If doing GDB file-I/O, target should convert 'struct timeval'
                 * from gdb-format to target-format */
                uint8_t timeval_buffer[NDS32_STRUCT_TIMEVAL_SIZE];

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)