diff mbox series

[08/13] target/arm/arm-semi: Factor out implementation of SYS_ISTTY

Message ID 20190910144428.32597-9-peter.maydell@linaro.org
State Superseded
Headers show
Series target/arm: Implement semihosting v2.0 | expand

Commit Message

Peter Maydell Sept. 10, 2019, 2:44 p.m. UTC
Factor out the implementation of SYS_ISTTY via the new function
tables.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

---
 target/arm/arm-semi.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

-- 
2.20.1

Comments

Alex Bennée Sept. 12, 2019, 11:20 a.m. UTC | #1
Peter Maydell <peter.maydell@linaro.org> writes:

> Factor out the implementation of SYS_ISTTY via the new function

> tables.

>

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>


Reviewed-by: Alex Bennée <alex.bennee@linaro.org>


> ---

>  target/arm/arm-semi.c | 20 +++++++++++++++-----

>  1 file changed, 15 insertions(+), 5 deletions(-)

>

> diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c

> index 48a10dd3c3a..64ed39fc075 100644

> --- a/target/arm/arm-semi.c

> +++ b/target/arm/arm-semi.c

> @@ -349,6 +349,7 @@ typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,

>                               target_ulong buf, uint32_t len);

>  typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,

>                              target_ulong buf, uint32_t len);

> +typedef uint32_t sys_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf);

>

>  static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)

>  {

> @@ -399,6 +400,11 @@ static uint32_t host_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,

>      return len - ret;

>  }

>

> +static uint32_t host_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)

> +{

> +    return isatty(gf->hostfd);

> +}

> +

>  static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)

>  {

>      return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);

> @@ -420,10 +426,16 @@ static uint32_t gdb_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,

>                             gf->hostfd, buf, len);

>  }

>

> +static uint32_t gdb_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)

> +{

> +    return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);

> +}

> +

>  typedef struct GuestFDFunctions {

>      sys_closefn *closefn;

>      sys_writefn *writefn;

>      sys_readfn *readfn;

> +    sys_isattyfn *isattyfn;

>  } GuestFDFunctions;

>

>  static const GuestFDFunctions guestfd_fns[] = {

> @@ -431,11 +443,13 @@ static const GuestFDFunctions guestfd_fns[] = {

>          .closefn = host_closefn,

>          .writefn = host_writefn,

>          .readfn = host_readfn,

> +        .isattyfn = host_isattyfn,

>      },

>      [GuestFDGDB] = {

>          .closefn = gdb_closefn,

>          .writefn = gdb_writefn,

>          .readfn = gdb_readfn,

> +        .isattyfn = gdb_isattyfn,

>      },

>  };

>

> @@ -600,11 +614,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)

>              return set_swi_errno(ts, -1);

>          }

>

> -        if (use_gdb_syscalls()) {

> -            return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);

> -        } else {

> -            return isatty(gf->hostfd);

> -        }

> +        return guestfd_fns[gf->type].isattyfn(ts, cpu, gf);

>      case TARGET_SYS_SEEK:

>          GET_ARG(0);

>          GET_ARG(1);



--
Alex Bennée
diff mbox series

Patch

diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
index 48a10dd3c3a..64ed39fc075 100644
--- a/target/arm/arm-semi.c
+++ b/target/arm/arm-semi.c
@@ -349,6 +349,7 @@  typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,
                              target_ulong buf, uint32_t len);
 typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,
                             target_ulong buf, uint32_t len);
+typedef uint32_t sys_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf);
 
 static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)
 {
@@ -399,6 +400,11 @@  static uint32_t host_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,
     return len - ret;
 }
 
+static uint32_t host_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)
+{
+    return isatty(gf->hostfd);
+}
+
 static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)
 {
     return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
@@ -420,10 +426,16 @@  static uint32_t gdb_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,
                            gf->hostfd, buf, len);
 }
 
+static uint32_t gdb_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)
+{
+    return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
+}
+
 typedef struct GuestFDFunctions {
     sys_closefn *closefn;
     sys_writefn *writefn;
     sys_readfn *readfn;
+    sys_isattyfn *isattyfn;
 } GuestFDFunctions;
 
 static const GuestFDFunctions guestfd_fns[] = {
@@ -431,11 +443,13 @@  static const GuestFDFunctions guestfd_fns[] = {
         .closefn = host_closefn,
         .writefn = host_writefn,
         .readfn = host_readfn,
+        .isattyfn = host_isattyfn,
     },
     [GuestFDGDB] = {
         .closefn = gdb_closefn,
         .writefn = gdb_writefn,
         .readfn = gdb_readfn,
+        .isattyfn = gdb_isattyfn,
     },
 };
 
@@ -600,11 +614,7 @@  target_ulong do_arm_semihosting(CPUARMState *env)
             return set_swi_errno(ts, -1);
         }
 
-        if (use_gdb_syscalls()) {
-            return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
-        } else {
-            return isatty(gf->hostfd);
-        }
+        return guestfd_fns[gf->type].isattyfn(ts, cpu, gf);
     case TARGET_SYS_SEEK:
         GET_ARG(0);
         GET_ARG(1);