This is an automated email from Gerrit.

Muhammad Omair Javaid (omair.jav...@linaro.org) just uploaded a new patch set 
to Gerrit, which you can find at http://openocd.zylin.com/4489

-- gerrit

commit 01e2c930256f05cda516ebf50453eec0ccf252d9
Author: Omair Javaid <omair.jav...@linaro.org>
Date:   Tue Apr 10 15:13:00 2018 +0500

    AArch64 semihosting and GDB fileIO support
    
    This patch implements semihosting support for AArch64. It also fixes gdb 
fileio
    for Arm targets and allows OpenOCD to use gdb console for stdout. Moreover 
this
    patch adds support for arm/aarch64 SYS_FLEN semihosting call using lseek 
operations.
    
    Now we can do something like
    gdb <inferior file>
    
    (gdb) tar ext :3333
    (gdb) load
    (gdb) monitor arm semihosting enable
    (gdb) monitor arm semihosting_fileio enable
    (gdb) continue
    
    Here: Output from inferior using puts, printf etc will be routed to gdb 
console.
    
    Change-Id: I7f3db8e8a94aa555cf7692cb59e1d0184a06f9e5
    Signed-off-by: Omair Javaid <omair.jav...@linaro.org>

diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 428547b..c427e93 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -790,64 +790,64 @@ static void gdb_fileio_reply(struct target *target, 
struct connection *connectio
        bool program_exited = false;
 
        if (strcmp(target->fileio_info->identifier, "open") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 "/%" PRIx32 ",%" PRIx32 
",%" PRIx32, target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 "/%" PRIx64 ",%" PRIx64 
",%" PRIx64, target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2,
                                target->fileio_info->param_3,
                                target->fileio_info->param_4);
        else if (strcmp(target->fileio_info->identifier, "close") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1);
        else if (strcmp(target->fileio_info->identifier, "read") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 ",%" PRIx32 ",%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 ",%" PRIx64 ",%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2,
                                target->fileio_info->param_3);
        else if (strcmp(target->fileio_info->identifier, "write") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 ",%" PRIx32 ",%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 ",%" PRIx64 ",%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2,
                                target->fileio_info->param_3);
        else if (strcmp(target->fileio_info->identifier, "lseek") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 ",%" PRIx32 ",%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 ",%" PRIx64 ",%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2,
                                target->fileio_info->param_3);
        else if (strcmp(target->fileio_info->identifier, "rename") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 "/%" PRIx32 ",%" PRIx32 
"/%" PRIx32, target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 "/%" PRIx64 ",%" PRIx64 
"/%" PRIx64, target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2,
                                target->fileio_info->param_3,
                                target->fileio_info->param_4);
        else if (strcmp(target->fileio_info->identifier, "unlink") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 "/%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 "/%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2);
        else if (strcmp(target->fileio_info->identifier, "stat") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 "/%" PRIx32 ",%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 "/%" PRIx64 ",%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2,
                                target->fileio_info->param_3);
        else if (strcmp(target->fileio_info->identifier, "fstat") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 ",%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 ",%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2);
        else if (strcmp(target->fileio_info->identifier, "gettimeofday") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 ",%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 ",%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2);
        else if (strcmp(target->fileio_info->identifier, "isatty") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1);
        else if (strcmp(target->fileio_info->identifier, "system") == 0)
-               sprintf(fileio_command, "F%s,%" PRIx32 "/%" PRIx32, 
target->fileio_info->identifier,
+               sprintf(fileio_command, "F%s,%" PRIx64 "/%" PRIx64, 
target->fileio_info->identifier,
                                target->fileio_info->param_1,
                                target->fileio_info->param_2);
        else if (strcmp(target->fileio_info->identifier, "exit") == 0) {
                /* If target hits exit syscall, report to GDB the program is 
terminated.
                 * In addition, let target run its own exit syscall handler. */
                program_exited = true;
-               sprintf(fileio_command, "W%02" PRIx32, 
target->fileio_info->param_1);
+               sprintf(fileio_command, "W%02" PRIx64, 
target->fileio_info->param_1);
        } else {
                LOG_DEBUG("Unknown syscall: %s", 
target->fileio_info->identifier);
 
diff --git a/src/target/aarch64.c b/src/target/aarch64.c
index 4641a3f..51d257f 100644
--- a/src/target/aarch64.c
+++ b/src/target/aarch64.c
@@ -28,6 +28,7 @@
 #include "target_type.h"
 #include "armv8_opcodes.h"
 #include "armv8_cache.h"
+#include "arm_semihosting.h"
 #include <helper/time_support.h>
 
 enum restart_mode {
@@ -522,6 +523,9 @@ static int aarch64_poll(struct target *target)
                        if (target->smp)
                                update_halt_gdb(target, debug_reason);
 
+                       if (arm_semihosting(target, &retval) != 0)
+                               return retval;
+
                        switch (prev_target_state) {
                        case TARGET_RUNNING:
                        case TARGET_UNKNOWN:
@@ -543,6 +547,9 @@ static int aarch64_poll(struct target *target)
 
 static int aarch64_halt(struct target *target)
 {
+       struct armv8_common *armv8 = target_to_armv8(target);
+       armv8->last_run_control_op = ARMV8_RUNCONTROL_HALT;
+
        if (target->smp)
                return aarch64_halt_smp(target, false);
 
@@ -831,6 +838,9 @@ static int aarch64_resume(struct target *target, int 
current,
        int retval = 0;
        uint64_t addr = address;
 
+       struct armv8_common *armv8 = target_to_armv8(target);
+       armv8->last_run_control_op = ARMV8_RUNCONTROL_RESUME;
+
        if (target->state != TARGET_HALTED)
                return ERROR_TARGET_NOT_HALTED;
 
@@ -1069,6 +1079,8 @@ static int aarch64_step(struct target *target, int 
current, target_addr_t addres
        int retval;
        uint32_t edecr;
 
+       armv8->last_run_control_op = ARMV8_RUNCONTROL_STEP;
+
        if (target->state != TARGET_HALTED) {
                LOG_WARNING("target not halted");
                return ERROR_TARGET_NOT_HALTED;
@@ -2060,8 +2072,8 @@ static int aarch64_read_cpu_memory(struct target *target,
        if (retval != ERROR_OK)
                return retval;
 
-       if (size == 4 && (address % 4) == 0)
-               retval = aarch64_read_cpu_memory_fast(target, count, buffer, 
&dscr);
+       if (((size % 4) == 0) && ((address % 4) == 0))
+               retval = aarch64_read_cpu_memory_fast(target, count * size / 4, 
buffer, &dscr);
        else
                retval = aarch64_read_cpu_memory_slow(target, size, count, 
buffer, &dscr);
 
@@ -2351,6 +2363,7 @@ static int aarch64_init_target(struct command_context 
*cmd_ctx,
        struct target *target)
 {
        /* examine_first() does a bunch of this */
+       arm_semihosting_init(target);
        return ERROR_OK;
 }
 
diff --git a/src/target/arm.h b/src/target/arm.h
index 62fbb73..431226f 100644
--- a/src/target/arm.h
+++ b/src/target/arm.h
@@ -194,10 +194,10 @@ struct arm {
        int arm_vfp_version;
 
        /** Current semihosting operation. */
-       int semihosting_op;
+       uint64_t semihosting_op;
 
        /** Current semihosting result. */
-       int semihosting_result;
+       uint64_t semihosting_result;
 
        /** Value to be returned by semihosting SYS_ERRNO request. */
        int semihosting_errno;
diff --git a/src/target/arm_semihosting.c b/src/target/arm_semihosting.c
index f31f901..47d7921 100644
--- a/src/target/arm_semihosting.c
+++ b/src/target/arm_semihosting.c
@@ -43,6 +43,7 @@
 #include "arm7_9_common.h"
 #include "armv7m.h"
 #include "armv7a.h"
+#include "armv8.h"
 #include "cortex_m.h"
 #include "register.h"
 #include "arm_opcodes.h"
@@ -67,6 +68,9 @@ static const int open_modeflags[12] = {
        O_RDWR | O_CREAT | O_APPEND | O_BINARY
 };
 
+static int flen_seek_steps = -1;
+static int flen_last_fd = -1;
+
 static int post_result(struct target *target)
 {
        struct arm *arm = target_to_arm(target);
@@ -100,6 +104,16 @@ static int post_result(struct target *target)
                if (spsr & 0x20)
                        arm->core_state = ARM_STATE_THUMB;
 
+       } else if (is_armv8(target_to_armv8(target))) {
+               if (arm->core_state == ARM_STATE_AARCH64) {
+                       /* return value in R0 */
+                       buf_set_u64(arm->core_cache->reg_list[0].value, 0, 64, 
arm->semihosting_result);
+                       arm->core_cache->reg_list[0].dirty = 1;
+
+                       uint64_t pc = 
buf_get_u64(arm->core_cache->reg_list[32].value, 0, 64);
+                       buf_set_u64(arm->pc->value, 0, 64, pc + 4);
+                       arm->pc->dirty = 1;
+               }
        } else {
                /* resume execution, this will be pc+2 to skip over the
                 * bkpt instruction */
@@ -107,11 +121,48 @@ static int post_result(struct target *target)
                /* return result in R0 */
                buf_set_u32(arm->core_cache->reg_list[0].value, 0, 32, 
arm->semihosting_result);
                arm->core_cache->reg_list[0].dirty = 1;
+
+               /* LR --> PC */
+               buf_set_u32(arm->core_cache->reg_list[15].value, 0, 32,
+                       buf_get_u32(arm_reg_current(arm, 14)->value, 0, 32));
+               arm->core_cache->reg_list[15].dirty = 1;
+
        }
 
        return ERROR_OK;
 }
 
+static int arm_semihosting_complete(struct target *target, int *retval)
+{
+       *retval = post_result(target);
+       if (*retval != ERROR_OK) {
+               LOG_ERROR("Failed to post semihosting result");
+               return 0;
+       }
+
+       if (target->debug_reason == DBG_REASON_DBGRQ)
+               return 0;
+
+       if (is_armv8(target_to_armv8(target))) {
+               struct armv8_common *armv8 = target_to_armv8(target);
+               if (armv8->last_run_control_op == ARMV8_RUNCONTROL_RESUME) {
+                       *retval = target_resume(target, 1, 0, 0, 0);
+                       if (*retval != ERROR_OK) {
+                               LOG_ERROR("Failed to resume target");
+                               return 0;
+                       }
+               } else if (armv8->last_run_control_op == ARMV8_RUNCONTROL_STEP)
+                       target->debug_reason = DBG_REASON_SINGLESTEP;
+       } else {
+               *retval = target_resume(target, 1, 0, 0, 0);
+               if (*retval != ERROR_OK) {
+                       LOG_ERROR("Failed to resume target");
+                       return 0;
+               }
+       }
+       return 1;
+}
+
 static int do_semihosting(struct target *target)
 {
        struct arm *arm = target_to_arm(target);
@@ -146,7 +197,14 @@ static int do_semihosting(struct target *target)
                        fn[l] = 0;
                        if (arm->is_semihosting_fileio) {
                                if (strcmp((char *)fn, ":tt") == 0)
-                                       arm->semihosting_result = 0;
+                                       if (m == 0)
+                                               arm->semihosting_result = 0;
+                                       else if (m == 4)
+                                               arm->semihosting_result = 1;
+                                       else if (m == 8)
+                                               arm->semihosting_result = 2;
+                                       else
+                                               arm->semihosting_result = -1;
                                else {
                                        arm->semihosting_hit_fileio = true;
                                        fileio_info->identifier = "open";
@@ -184,6 +242,10 @@ static int do_semihosting(struct target *target)
                else {
                        int fd = target_buffer_get_u32(target, params+0);
                        if (arm->is_semihosting_fileio) {
+                               if (fd == 0 || fd == 1 || fd == 2) {
+                                       arm->semihosting_result = 0;
+                                       break;
+                               }
                                arm->semihosting_hit_fileio = true;
                                fileio_info->identifier = "close";
                                fileio_info->param_1 = fd;
@@ -259,7 +321,7 @@ static int do_semihosting(struct target *target)
                        } else {
                                uint8_t *buf = malloc(l);
                                if (!buf) {
-                                       arm->semihosting_result = -1;
+                                       arm->semihosting_result = ULLONG_MAX;
                                        arm->semihosting_errno = ENOMEM;
                                } else {
                                        retval = target_read_buffer(target, a, 
l, buf);
@@ -269,7 +331,7 @@ static int do_semihosting(struct target *target)
                                        }
                                        arm->semihosting_result = write(fd, 
buf, l);
                                        arm->semihosting_errno = errno;
-                                       if (arm->semihosting_result >= 0)
+                                       if (arm->semihosting_result != 
ULLONG_MAX)
                                                arm->semihosting_result = l - 
arm->semihosting_result;
                                        free(buf);
                                }
@@ -294,12 +356,12 @@ static int do_semihosting(struct target *target)
                        } else {
                                uint8_t *buf = malloc(l);
                                if (!buf) {
-                                       arm->semihosting_result = -1;
+                                       arm->semihosting_result = ULLONG_MAX;
                                        arm->semihosting_errno = ENOMEM;
                                } else {
                                        arm->semihosting_result = read(fd, buf, 
l);
                                        arm->semihosting_errno = errno;
-                                       if (arm->semihosting_result >= 0) {
+                                       if (arm->semihosting_result != 
ULLONG_MAX) {
                                                retval = 
target_write_buffer(target, a, arm->semihosting_result, buf);
                                                if (retval != ERROR_OK) {
                                                        free(buf);
@@ -357,30 +419,36 @@ static int do_semihosting(struct target *target)
                        } else {
                                arm->semihosting_result = lseek(fd, pos, 
SEEK_SET);
                                arm->semihosting_errno = errno;
-                               if (arm->semihosting_result == pos)
+                               if (arm->semihosting_result == (uint64_t)pos)
                                        arm->semihosting_result = 0;
                        }
                }
                break;
 
        case 0x0c:      /* SYS_FLEN */
-               if (arm->is_semihosting_fileio) {
-                       LOG_ERROR("SYS_FLEN not supported by semihosting 
fileio");
-                       return ERROR_FAIL;
-               }
                retval = target_read_memory(target, r1, 4, 1, params);
                if (retval != ERROR_OK)
                        return retval;
                else {
                        int fd = target_buffer_get_u32(target, params+0);
-                       struct stat buf;
-                       arm->semihosting_result = fstat(fd, &buf);
-                       if (arm->semihosting_result == -1) {
-                               arm->semihosting_errno = errno;
-                               arm->semihosting_result = -1;
-                               break;
+                       if (arm->is_semihosting_fileio) {
+                               arm->semihosting_hit_fileio = true;
+                               flen_last_fd = fd;
+                               flen_seek_steps = SEEK_CUR;
+                               fileio_info->identifier = "lseek";
+                               fileio_info->param_1 = fd;
+                               fileio_info->param_2 = 0;
+                               fileio_info->param_3 = SEEK_CUR;
+                       } else {
+                               struct stat buf;
+                               arm->semihosting_result = fstat(fd, &buf);
+                               if (arm->semihosting_result == ULLONG_MAX) {
+                                       arm->semihosting_errno = errno;
+                                       arm->semihosting_result = -1;
+                                       break;
+                               }
+                               arm->semihosting_result = buf.st_size;
                        }
-                       arm->semihosting_result = buf.st_size;
                }
                break;
 
@@ -560,6 +628,7 @@ static int do_semihosting(struct target *target)
        case 0x30:      /* SYS_ELAPSED */
        case 0x31:      /* SYS_TICKFREQ */
        default:
+               return ERROR_OK;
                fprintf(stderr, "semihosting: unsupported call %#x\n",
                                (unsigned) r0);
                arm->semihosting_result = -1;
@@ -569,6 +638,485 @@ static int do_semihosting(struct target *target)
        return ERROR_OK;
 }
 
+static int do_semihosting64(struct target *target)
+{
+       struct arm *arm = target_to_arm(target);
+       struct gdb_fileio_info *fileio_info = target->fileio_info;
+       uint64_t x0 = buf_get_u64(arm->core_cache->reg_list[0].value, 0, 64);
+       uint64_t x1 = buf_get_u64(arm->core_cache->reg_list[1].value, 0, 64);
+       uint8_t params[32];
+       int retval;
+
+       /*
+        * TODO: lots of security issues are not considered yet, such as:
+        * - no validation on target provided file descriptors
+        * - no safety checks on opened/deleted/renamed file paths
+        * Beware the target app you use this support with.
+        *
+        * TODO: unsupported semihosting fileio operations could be
+        * implemented if we had a small working area at our disposal.
+        */
+       memset(params, 0, 4*8);
+       switch ((arm->semihosting_op = x0)) {
+       case 0x01:      /* SYS_OPEN */
+               retval = target_read_memory(target, x1, 8, 3, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t name = target_buffer_get_u64(target, params+0);
+                       uint64_t mode = target_buffer_get_u64(target, params+8);
+                       uint64_t len = target_buffer_get_u64(target, params+16);
+                       uint8_t fn[256];
+                       retval = target_read_memory(target, name, 1, len, fn);
+                       if (retval != ERROR_OK)
+                               return retval;
+                       fn[len] = 0;
+                       if (arm->is_semihosting_fileio) {
+                               if (strcmp((char *)fn, ":tt") == 0) {
+                                       if (mode == 0)
+                                               arm->semihosting_result = 0;
+                                       else if (mode == 4)
+                                               arm->semihosting_result = 1;
+                                       else if (mode == 8)
+                                               arm->semihosting_result = 2;
+                                       else
+                                               arm->semihosting_result = -1;
+                               } else {
+                                       arm->semihosting_hit_fileio = true;
+                                       fileio_info->identifier = "open";
+                                       fileio_info->param_1 = name;
+                                       fileio_info->param_2 = len;
+                                       fileio_info->param_3 = 
open_modeflags[mode];
+                                       fileio_info->param_4 = 0644;
+                               }
+                       } else {
+                               if (len <= 255 && mode <= 11) {
+                                       if (strcmp((char *)fn, ":tt") == 0) {
+                                               if (mode < 4)
+                                                       arm->semihosting_result 
= dup(STDIN_FILENO);
+                                               else
+                                                       arm->semihosting_result 
= dup(STDOUT_FILENO);
+                                       } else {
+                                               /* cygwin requires the 
permission setting
+                                                * otherwise it will fail to 
reopen a previously
+                                                * written file */
+                                               arm->semihosting_result = 
open((char *)fn, open_modeflags[mode], 0644);
+                                       }
+                                       arm->semihosting_errno =  errno;
+                               } else {
+                                       arm->semihosting_result = -1;
+                                       arm->semihosting_errno = EINVAL;
+                               }
+                       }
+               }
+               break;
+
+       case 0x02:      /* SYS_CLOSE */
+               retval = target_read_memory(target, x1, 8, 1, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t fhandle = target_buffer_get_u64(target, 
params+0);
+                       if (arm->is_semihosting_fileio) {
+                               if (fhandle == 0 || fhandle == 1 || fhandle == 
2) {
+                                       arm->semihosting_result = 0;
+                                       break;
+                               }
+                               arm->semihosting_hit_fileio = true;
+                               fileio_info->identifier = "close";
+                               fileio_info->param_1 = fhandle;
+                       } else {
+                               arm->semihosting_result = close(fhandle);
+                               arm->semihosting_errno = errno;
+                       }
+               }
+               break;
+
+       case 0x03:      /* SYS_WRITEC */
+               if (arm->is_semihosting_fileio) {
+                       arm->semihosting_hit_fileio = true;
+                       fileio_info->identifier = "write";
+                       fileio_info->param_1 = 1;
+                       fileio_info->param_2 = x1;
+                       fileio_info->param_3 = 1;
+               } else {
+                       unsigned char ch;
+                       retval = target_read_memory(target, x1, 1, 1, &ch);
+                       if (retval != ERROR_OK)
+                               return retval;
+                       putchar(ch);
+                       arm->semihosting_result = 0;
+               }
+               break;
+
+       case 0x04:      /* SYS_WRITE0 */
+               if (arm->is_semihosting_fileio) {
+                       size_t count = 0;
+                       for (uint64_t a = x1;; a++) {
+                               unsigned char ch;
+                               retval = target_read_memory(target, a, 1, 1, 
&ch);
+                               if (retval != ERROR_OK)
+                                       return retval;
+                               if (ch == '\0')
+                                       break;
+                               count++;
+                       }
+                       arm->semihosting_hit_fileio = true;
+                       fileio_info->identifier = "write";
+                       fileio_info->param_1 = 1;
+                       fileio_info->param_2 = x1;
+                       fileio_info->param_3 = count;
+               } else {
+                       do {
+                               unsigned char ch;
+                               retval = target_read_memory(target, x1++, 1, 1, 
&ch);
+                               if (retval != ERROR_OK)
+                                       return retval;
+                               if (ch == '\0')
+                                       break;
+                               putchar(ch);
+                       } while (1);
+                       arm->semihosting_result = 0;
+               }
+               break;
+
+       case 0x05:      /* SYS_WRITE */
+               retval = target_read_memory(target, x1, 8, 3, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t fhandle = target_buffer_get_u64(target, 
params+0);
+                       uint64_t dataptr = target_buffer_get_u64(target, 
params+8);
+                       uint64_t length = target_buffer_get_u64(target, 
params+16);
+                       if (arm->is_semihosting_fileio) {
+                               arm->semihosting_hit_fileio = true;
+                               fileio_info->identifier = "write";
+                               fileio_info->param_1 = fhandle;
+                               fileio_info->param_2 = dataptr;
+                               fileio_info->param_3 = length;
+                       } else {
+                               uint8_t *buf = malloc(length);
+                               if (!buf) {
+                                       arm->semihosting_result = -1;
+                                       arm->semihosting_errno = ENOMEM;
+                               } else {
+                                       retval = target_read_buffer(target, 
dataptr, length, buf);
+                                       if (retval != ERROR_OK) {
+                                               free(buf);
+                                               return retval;
+                                       }
+                                       arm->semihosting_result = 
write(fhandle, buf, length);
+                                       arm->semihosting_errno = errno;
+                                       if (arm->semihosting_result != 
ULLONG_MAX)
+                                               arm->semihosting_result = 
length - arm->semihosting_result;
+                                       free(buf);
+                               }
+                       }
+               }
+               break;
+
+       case 0x06:      /* SYS_READ */
+               retval = target_read_memory(target, x1, 8, 3, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t fhandle = target_buffer_get_u64(target, 
params+0);
+                       uint64_t bufptr = target_buffer_get_u64(target, 
params+8);
+                       uint64_t length = target_buffer_get_u64(target, 
params+16);
+                       if (arm->is_semihosting_fileio) {
+                               arm->semihosting_hit_fileio = true;
+                               fileio_info->identifier = "read";
+                               fileio_info->param_1 = fhandle;
+                               fileio_info->param_2 = bufptr;
+                               fileio_info->param_3 = length;
+                       } else {
+                               uint8_t *buf = malloc(length);
+                               if (!buf) {
+                                       arm->semihosting_result = -1;
+                                       arm->semihosting_errno = ENOMEM;
+                               } else {
+                                       arm->semihosting_result = read(fhandle, 
buf, length);
+                                       arm->semihosting_errno = errno;
+                                       if (arm->semihosting_result != 
ULLONG_MAX) {
+                                               retval = 
target_write_buffer(target, bufptr, arm->semihosting_result, buf);
+                                               if (retval != ERROR_OK) {
+                                                       free(buf);
+                                                       return retval;
+                                               }
+                                               arm->semihosting_result = 
length - arm->semihosting_result;
+                                       }
+                                       free(buf);
+                               }
+                       }
+               }
+               break;
+
+       case 0x07:      /* SYS_READC */
+               if (arm->is_semihosting_fileio) {
+                       LOG_ERROR("SYS_READC not supported by semihosting 
fileio");
+                       return ERROR_FAIL;
+               }
+               arm->semihosting_result = getchar();
+               break;
+
+       case 0x08:      /* SYS_ISERROR */
+               retval = target_read_memory(target, x1, 8, 1, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               arm->semihosting_result = (target_buffer_get_u64(target, 
params+0) != 0);
+               break;
+
+       case 0x09:      /* SYS_ISTTY */
+               if (arm->is_semihosting_fileio) {
+                       arm->semihosting_hit_fileio = true;
+                       fileio_info->identifier = "isatty";
+                       fileio_info->param_1 = x1;
+               } else {
+                       retval = target_read_memory(target, x1, 8, 1, params);
+                       if (retval != ERROR_OK)
+                               return retval;
+                       arm->semihosting_result = 
isatty(target_buffer_get_u64(target, params+0));
+               }
+               break;
+
+       case 0x0a:      /* SYS_SEEK */
+               retval = target_read_memory(target, x1, 8, 2, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t fd = target_buffer_get_u64(target, params+0);
+                       uint64_t pos = target_buffer_get_u64(target, params+8);
+                       if (arm->is_semihosting_fileio) {
+                               arm->semihosting_hit_fileio = true;
+                               fileio_info->identifier = "lseek";
+                               fileio_info->param_1 = fd;
+                               fileio_info->param_2 = pos;
+                               fileio_info->param_3 = SEEK_SET;
+                       } else {
+                               arm->semihosting_result = lseek(fd, pos, 
SEEK_SET);
+                               arm->semihosting_errno = errno;
+                               if (arm->semihosting_result == pos)
+                                       arm->semihosting_result = 0;
+                       }
+               }
+               break;
+
+       case 0x0c:      /* SYS_FLEN */
+               retval = target_read_memory(target, x1, 8, 1, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t fd = target_buffer_get_u64(target, params+0);
+                       if (arm->is_semihosting_fileio) {
+                               arm->semihosting_hit_fileio = true;
+                               flen_last_fd = fd;
+                               flen_seek_steps = SEEK_CUR;
+                               fileio_info->identifier = "lseek";
+                               fileio_info->param_1 = fd;
+                               fileio_info->param_2 = 0;
+                               fileio_info->param_3 = SEEK_CUR;
+                       } else {
+                               struct stat buf;
+                               arm->semihosting_result = fstat(fd, &buf);
+                               if (arm->semihosting_result == ULLONG_MAX) {
+                                       arm->semihosting_errno = errno;
+                                       arm->semihosting_result = -1;
+                                       break;
+                               }
+                               arm->semihosting_result = buf.st_size;
+                       }
+               }
+               break;
+
+       case 0x0e:      /* SYS_REMOVE */
+               retval = target_read_memory(target, x1, 8, 2, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t a = target_buffer_get_u64(target, params+0);
+                       uint64_t l = target_buffer_get_u64(target, params+8);
+                       if (arm->is_semihosting_fileio) {
+                               arm->semihosting_hit_fileio = true;
+                               fileio_info->identifier = "unlink";
+                               fileio_info->param_1 = a;
+                               fileio_info->param_2 = l;
+                       } else {
+                               if (l <= 255) {
+                                       uint8_t fn[256];
+                                       retval = target_read_memory(target, a, 
1, l, fn);
+                                       if (retval != ERROR_OK)
+                                               return retval;
+                                       fn[l] = 0;
+                                       arm->semihosting_result = remove((char 
*)fn);
+                                       arm->semihosting_errno =  errno;
+                               } else {
+                                       arm->semihosting_result = -1;
+                                       arm->semihosting_errno = EINVAL;
+                               }
+                       }
+               }
+               break;
+
+       case 0x0f:      /* SYS_RENAME */
+               retval = target_read_memory(target, x1, 8, 4, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t a1 = target_buffer_get_u64(target, params+0);
+                       uint64_t l1 = target_buffer_get_u64(target, params+8);
+                       uint64_t a2 = target_buffer_get_u64(target, params+16);
+                       uint64_t l2 = target_buffer_get_u64(target, params+24);
+                       if (arm->is_semihosting_fileio) {
+                               arm->semihosting_hit_fileio = true;
+                               fileio_info->identifier = "rename";
+                               fileio_info->param_1 = a1;
+                               fileio_info->param_2 = l1;
+                               fileio_info->param_3 = a2;
+                               fileio_info->param_4 = l2;
+                       } else {
+                               if (l1 <= 255 && l2 <= 255) {
+                                       uint8_t fn1[256], fn2[256];
+                                       retval = target_read_memory(target, a1, 
1, l1, fn1);
+                                       if (retval != ERROR_OK)
+                                               return retval;
+                                       retval = target_read_memory(target, a2, 
1, l2, fn2);
+                                       if (retval != ERROR_OK)
+                                               return retval;
+                                       fn1[l1] = 0;
+                                       fn2[l2] = 0;
+                                       arm->semihosting_result = rename((char 
*)fn1, (char *)fn2);
+                                       arm->semihosting_errno =  errno;
+                               } else {
+                                       arm->semihosting_result = -1;
+                                       arm->semihosting_errno = EINVAL;
+                               }
+                       }
+               }
+               break;
+
+       case 0x11:      /* SYS_TIME */
+               arm->semihosting_result = time(NULL);
+               break;
+
+       case 0x13:      /* SYS_ERRNO */
+               arm->semihosting_result = arm->semihosting_errno;
+               break;
+
+       case 0x15:      /* SYS_GET_CMDLINE */
+               retval = target_read_memory(target, x1, 8, 2, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t a = target_buffer_get_u64(target, params+0);
+                       uint64_t l = target_buffer_get_u64(target, params+8);
+                       char *arg = arm->semihosting_cmdline != NULL ? 
arm->semihosting_cmdline : "";
+                       uint64_t s = strlen(arg) + 1;
+                       if (l < s)
+                               arm->semihosting_result = -1;
+                       else {
+                               retval = target_write_buffer(target, a, s, 
(uint8_t *)arg);
+                               if (retval != ERROR_OK)
+                                       return retval;
+                               arm->semihosting_result = 0;
+                       }
+               }
+               break;
+
+       case 0x16:      /* SYS_HEAPINFO */
+               retval = target_read_memory(target, x1, 8, 1, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t block_addr = target_buffer_get_u64(target, 
params+0);
+                       /* tell the remote we have no idea */
+                       memset(params, 0, 4*8);
+                       retval = target_write_memory(target, block_addr, 8, 4, 
params);
+                       if (retval != ERROR_OK)
+                               return retval;
+                       arm->semihosting_result = 0;
+               }
+               break;
+
+       case 0x18:      /* angel_SWIreason_ReportException */
+               retval = target_read_memory(target, x1, 8, 2, params);
+               uint64_t type = target_buffer_get_u64(target, params+0);
+               switch (type) {
+               case 0x20026:   /* ADP_Stopped_ApplicationExit */
+                       fprintf(stderr, "semihosting: *** application exited 
***\n");
+                       target->debug_reason = DBG_REASON_DBGRQ;
+                       break;
+               case 0x20000:   /* ADP_Stopped_BranchThroughZero */
+               case 0x20001:   /* ADP_Stopped_UndefinedInstr */
+               case 0x20002:   /* ADP_Stopped_SoftwareInterrupt */
+               case 0x20003:   /* ADP_Stopped_PrefetchAbort */
+               case 0x20004:   /* ADP_Stopped_DataAbort */
+               case 0x20005:   /* ADP_Stopped_AddressException */
+               case 0x20006:   /* ADP_Stopped_IRQ */
+               case 0x20007:   /* ADP_Stopped_FIQ */
+               case 0x20020:   /* ADP_Stopped_BreakPoint */
+               case 0x20021:   /* ADP_Stopped_WatchPoint */
+               case 0x20022:   /* ADP_Stopped_StepComplete */
+               case 0x20023:   /* ADP_Stopped_RunTimeErrorUnknown */
+               case 0x20024:   /* ADP_Stopped_InternalError */
+               case 0x20025:   /* ADP_Stopped_UserInterruption */
+               case 0x20027:   /* ADP_Stopped_StackOverflow */
+               case 0x20028:   /* ADP_Stopped_DivisionByZero */
+               case 0x20029:   /* ADP_Stopped_OSSpecific */
+               default:
+                       fprintf(stderr, "semihosting: exception %#x\n",
+                                       (unsigned) x1);
+               }
+               return target_call_event_callbacks(target, TARGET_EVENT_HALTED);
+
+       case 0x12:      /* SYS_SYSTEM */
+               /* Provide SYS_SYSTEM functionality.  Uses the
+                * libc system command, there may be a reason *NOT*
+                * to use this, but as I can't think of one, I
+                * implemented it this way.
+                */
+               retval = target_read_memory(target, x1, 8, 2, params);
+               if (retval != ERROR_OK)
+                       return retval;
+               else {
+                       uint64_t len = target_buffer_get_u64(target, params+8);
+                       uint64_t c_ptr = target_buffer_get_u64(target, params);
+                       if (arm->is_semihosting_fileio) {
+                               arm->semihosting_hit_fileio = true;
+                               fileio_info->identifier = "system";
+                               fileio_info->param_1 = c_ptr;
+                               fileio_info->param_2 = len;
+                       } else {
+                               uint8_t cmd[256];
+                               if (len > 255) {
+                                       arm->semihosting_result = -1;
+                                       arm->semihosting_errno = EINVAL;
+                               } else {
+                                       memset(cmd, 0x0, 256);
+                                       retval = target_read_memory(target, 
c_ptr, 1, len, cmd);
+                                       if (retval != ERROR_OK)
+                                               return retval;
+                                       else
+                                               arm->semihosting_result = 
system((const char *)cmd);
+                               }
+                       }
+               }
+               break;
+       case 0x0d:      /* SYS_TMPNAM */
+       case 0x10:      /* SYS_CLOCK */
+       case 0x17:      /* angel_SWIreason_EnterSVC */
+       case 0x30:      /* SYS_ELAPSED */
+       case 0x31:      /* SYS_TICKFREQ */
+       default:
+               return ERROR_OK;
+               fprintf(stderr, "semihosting: unsupported call %#x\n",
+                               (unsigned) x0);
+               arm->semihosting_result = -1;
+               arm->semihosting_errno = ENOTSUP;
+       }
+
+       return ERROR_OK;
+}
+
 static int get_gdb_fileio_info(struct target *target, struct gdb_fileio_info 
*fileio_info)
 {
        struct arm *arm = target_to_arm(target);
@@ -587,6 +1135,7 @@ static int gdb_fileio_end(struct target *target, int 
result, int fileio_errno, b
 {
        struct arm *arm = target_to_arm(target);
        struct gdb_fileio_info *fileio_info = target->fileio_info;
+       static int flen_pos_curr, flen_pos_end;
 
        /* clear pending status */
        arm->semihosting_hit_fileio = false;
@@ -617,9 +1166,44 @@ static int gdb_fileio_end(struct target *target, int 
result, int fileio_errno, b
                if (result > 0)
                        arm->semihosting_result = 0;
                break;
+
+       case 0x0c:      /* SYS_FLEN */
+               if (result < 0)
+                       break;
+               if (flen_seek_steps == SEEK_CUR) {
+                       flen_pos_curr = result;
+                       flen_seek_steps = SEEK_END;
+                       arm->semihosting_hit_fileio = true;
+                       fileio_info->identifier = "lseek";
+                       fileio_info->param_1 = flen_last_fd;
+                       fileio_info->param_2 = 0;
+                       fileio_info->param_3 = SEEK_END;
+                       return target_call_event_callbacks(target, 
TARGET_EVENT_HALTED);
+               } else if (flen_seek_steps == SEEK_END) {
+                       flen_pos_end = result;
+                       flen_seek_steps = SEEK_SET;
+                       arm->semihosting_hit_fileio = true;
+                       fileio_info->identifier = "lseek";
+                       fileio_info->param_1 = flen_last_fd;
+                       fileio_info->param_2 = flen_pos_curr;
+                       fileio_info->param_3 = SEEK_SET;
+                       return target_call_event_callbacks(target, 
TARGET_EVENT_HALTED);
+               } else if (flen_seek_steps == SEEK_SET) {
+                       flen_seek_steps = -1;
+                       arm->semihosting_result = flen_pos_end;
+                       break;
+               }
        }
 
-       return post_result(target);
+       /* Post result to target if we are not waiting on a fileio
+        * operation to complete:
+        */
+       if (!arm->semihosting_hit_fileio) {
+               int retval = ERROR_OK;
+               arm_semihosting_complete(target, &retval);
+               return retval;
+       }
+       return ERROR_OK;
 }
 
 /**
@@ -758,6 +1342,24 @@ int arm_semihosting(struct target *target, int *retval)
                /* bkpt 0xAB */
                if (insn != 0xBEAB)
                        return 0;
+       } else if (is_armv8(target_to_armv8(target))) {
+               if (target->debug_reason != DBG_REASON_BREAKPOINT)
+                       return 0;
+
+               if (arm->core_state == ARM_STATE_AARCH64) {
+                       uint32_t insn = 0;
+                       r = arm->pc;
+                       uint64_t pc64 = buf_get_u64(r->value, 0, 64);
+                       *retval = target_read_u32(target, pc64, &insn);
+
+                       if (*retval != ERROR_OK)
+                               return 1;
+
+                       /* bkpt 0xAB */
+                       if (insn != 0xD45E0000)
+                               return 0;
+               } else
+                       return 1;
        } else {
                LOG_ERROR("Unsupported semi-hosting Target");
                return 0;
@@ -767,7 +1369,10 @@ int arm_semihosting(struct target *target, int *retval)
         * operation to complete.
         */
        if (!arm->semihosting_hit_fileio) {
-               *retval = do_semihosting(target);
+               if (arm->core_state == ARM_STATE_AARCH64)
+                       *retval = do_semihosting64(target);
+               else
+                       *retval = do_semihosting(target);
                if (*retval != ERROR_OK) {
                        LOG_ERROR("Failed semihosting operation");
                        return 0;
@@ -777,21 +1382,8 @@ int arm_semihosting(struct target *target, int *retval)
        /* Post result to target if we are not waiting on a fileio
         * operation to complete:
         */
-       if (!arm->semihosting_hit_fileio) {
-               *retval = post_result(target);
-               if (*retval != ERROR_OK) {
-                       LOG_ERROR("Failed to post semihosting result");
-                       return 0;
-               }
-
-               *retval = target_resume(target, 1, 0, 0, 0);
-               if (*retval != ERROR_OK) {
-                       LOG_ERROR("Failed to resume target");
-                       return 0;
-               }
-
-               return 1;
-       }
+       if (!arm->semihosting_hit_fileio)
+               return arm_semihosting_complete(target, retval);
 
        return 0;
 }
diff --git a/src/target/armv8.c b/src/target/armv8.c
index 3321dd6..153cc4f 100644
--- a/src/target/armv8.c
+++ b/src/target/armv8.c
@@ -1013,11 +1013,24 @@ int armv8_handle_cache_info_command(struct 
command_context *cmd_ctx,
        return ERROR_OK;
 }
 
+static int armv8_setup_semihosting(struct target *target, int enable)
+{
+       struct arm *arm = target_to_arm(target);
+
+       if (arm->core_state != ARM_STATE_AARCH64) {
+               LOG_ERROR("semihosting only supported in AArch64 state\n");
+               return ERROR_FAIL;
+       }
+
+       return ERROR_OK;
+}
+
 int armv8_init_arch_info(struct target *target, struct armv8_common *armv8)
 {
        struct arm *arm = &armv8->arm;
        arm->arch_info = armv8;
        target->arch_info = &armv8->arm;
+       arm->setup_semihosting = armv8_setup_semihosting;
        /*  target is useful in all function arm v4 5 compatible */
        armv8->arm.target = target;
        armv8->arm.common_magic = ARM_COMMON_MAGIC;
diff --git a/src/target/armv8.h b/src/target/armv8.h
index 6525d26..6065e5a 100644
--- a/src/target/armv8.h
+++ b/src/target/armv8.h
@@ -113,6 +113,12 @@ enum {
        ARMV8_LAST_REG,
 };
 
+enum run_control_op {
+       ARMV8_RUNCONTROL_UNKNOWN = 0,
+       ARMV8_RUNCONTROL_RESUME = 1,
+       ARMV8_RUNCONTROL_HALT = 2,
+       ARMV8_RUNCONTROL_STEP = 3,
+};
 
 #define ARMV8_COMMON_MAGIC 0x0A450AAA
 
@@ -210,6 +216,9 @@ struct armv8_common {
 
        struct arm_cti *cti;
 
+       /* last run-control command issued to this target (resume, halt, step) 
*/
+       enum run_control_op last_run_control_op;
+
        /* Direct processor core register read and writes */
        int (*read_reg_u64)(struct armv8_common *armv8, int num, uint64_t 
*value);
        int (*write_reg_u64)(struct armv8_common *armv8, int num, uint64_t 
value);
@@ -232,6 +241,11 @@ target_to_armv8(struct target *target)
        return container_of(target->arch_info, struct armv8_common, arm);
 }
 
+static inline bool is_armv8(struct armv8_common *armv8)
+{
+       return armv8->common_magic == ARMV8_COMMON_MAGIC;
+}
+
 /* register offsets from armv8.debug_base */
 #define CPUV8_DBG_MAINID0              0xD00
 #define CPUV8_DBG_CPUFEATURE0  0xD20
diff --git a/src/target/nds32.c b/src/target/nds32.c
index e4bb17f..4115ea4 100644
--- a/src/target/nds32.c
+++ b/src/target/nds32.c
@@ -2339,63 +2339,66 @@ int nds32_get_gdb_fileio_info(struct target *target, 
struct gdb_fileio_info *fil
                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 = 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 = 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);
+                               target->type->read_buffer(target, reg_r0, 256, 
filename);
                                fileio_info->param_2 = strlen((char *)filename) 
+ 1;
                        }
                        break;
                case NDS32_SYSCALL_CLOSE:
                        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 = 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 = 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 = 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 = 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);
+                               target->type->read_buffer(target, reg_r0, 256, 
filename);
                                fileio_info->param_2 = strlen((char *)filename) 
+ 1;
                        }
                        break;
@@ -2404,61 +2407,57 @@ int nds32_get_gdb_fileio_info(struct target *target, 
struct gdb_fileio_info *fil
                                uint8_t filename[256];
                                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);
+                               target->type->read_buffer(target, reg_r0, 256, 
filename);
                                fileio_info->param_2 = strlen((char *)filename) 
+ 1;
 
-                               target->type->read_buffer(target, 
fileio_info->param_3,
-                                               256, filename);
+                               target->type->read_buffer(target, reg_r1, 256, 
filename);
                                fileio_info->param_4 = strlen((char *)filename) 
+ 1;
                        }
                        break;
                case NDS32_SYSCALL_FSTAT:
                        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 = 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 = 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 = 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 = 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);
+                               target->type->read_buffer(target, reg_r0, 256, 
command);
                                fileio_info->param_2 = strlen((char *)command) 
+ 1;
                        }
                        break;
diff --git a/src/target/target.h b/src/target/target.h
index 7a8a80f..b6d579b 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -214,10 +214,10 @@ struct target_list {
 
 struct gdb_fileio_info {
        char *identifier;
-       uint32_t param_1;
-       uint32_t param_2;
-       uint32_t param_3;
-       uint32_t param_4;
+       uint64_t param_1;
+       uint64_t param_2;
+       uint64_t param_3;
+       uint64_t param_4;
 };
 
 /** Returns the instance-specific name of the specified target. */

-- 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to