[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 32/68] target/arm/arm-semi: Factor out implementation of SYS_WRITE
From: |
Peter Maydell |
Subject: |
[PULL 32/68] target/arm/arm-semi: Factor out implementation of SYS_WRITE |
Date: |
Mon, 14 Oct 2019 17:03:28 +0100 |
Factor out the implementation of SYS_WRITE via the
new function tables.
Signed-off-by: Peter Maydell <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Message-id: address@hidden
---
target/arm/arm-semi.c | 51 ++++++++++++++++++++++++++++---------------
1 file changed, 33 insertions(+), 18 deletions(-)
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
index e5f1e2aaaf2..c21cbb97bc1 100644
--- a/target/arm/arm-semi.c
+++ b/target/arm/arm-semi.c
@@ -384,6 +384,8 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu,
gdb_syscall_complete_cb cb,
* setting the guest errno if appropriate.
*/
typedef uint32_t sys_closefn(ARMCPU *cpu, GuestFD *gf);
+typedef uint32_t sys_writefn(ARMCPU *cpu, GuestFD *gf,
+ target_ulong buf, uint32_t len);
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
{
@@ -392,21 +394,51 @@ static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
return set_swi_errno(env, close(gf->hostfd));
}
+static uint32_t host_writefn(ARMCPU *cpu, GuestFD *gf,
+ target_ulong buf, uint32_t len)
+{
+ uint32_t ret;
+ CPUARMState *env = &cpu->env;
+ char *s = lock_user(VERIFY_READ, buf, len, 1);
+ if (!s) {
+ /* Return bytes not written on error */
+ return len;
+ }
+ ret = set_swi_errno(env, write(gf->hostfd, s, len));
+ unlock_user(s, buf, 0);
+ if (ret == (uint32_t)-1) {
+ ret = 0;
+ }
+ /* Return bytes not written */
+ return len - ret;
+}
+
static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf)
{
return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
}
+static uint32_t gdb_writefn(ARMCPU *cpu, GuestFD *gf,
+ target_ulong buf, uint32_t len)
+{
+ arm_semi_syscall_len = len;
+ return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x",
+ gf->hostfd, buf, len);
+}
+
typedef struct GuestFDFunctions {
sys_closefn *closefn;
+ sys_writefn *writefn;
} GuestFDFunctions;
static const GuestFDFunctions guestfd_fns[] = {
[GuestFDHost] = {
.closefn = host_closefn,
+ .writefn = host_writefn,
},
[GuestFDGDB] = {
.closefn = gdb_closefn,
+ .writefn = gdb_writefn,
},
};
@@ -539,24 +571,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)
return set_swi_errno(env, -1);
}
- if (use_gdb_syscalls()) {
- arm_semi_syscall_len = len;
- return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x",
- gf->hostfd, arg1, len);
- } else {
- s = lock_user(VERIFY_READ, arg1, len, 1);
- if (!s) {
- /* Return bytes not written on error */
- return len;
- }
- ret = set_swi_errno(env, write(gf->hostfd, s, len));
- unlock_user(s, arg1, 0);
- if (ret == (uint32_t)-1) {
- ret = 0;
- }
- /* Return bytes not written */
- return len - ret;
- }
+ return guestfd_fns[gf->type].writefn(cpu, gf, arg1, len);
case TARGET_SYS_READ:
GET_ARG(0);
GET_ARG(1);
--
2.20.1
- [PULL 22/68] hw/timer/mss-timerc: Switch to transaction-based ptimer API, (continued)
- [PULL 22/68] hw/timer/mss-timerc: Switch to transaction-based ptimer API, Peter Maydell, 2019/10/14
- [PULL 23/68] hw/watchdog/cmsdk-apb-watchdog.c: Switch to transaction-based ptimer API, Peter Maydell, 2019/10/14
- [PULL 24/68] hw/net/lan9118.c: Switch to transaction-based ptimer API, Peter Maydell, 2019/10/14
- [PULL 25/68] target/arm/arm-semi: Capture errno in softmmu version of set_swi_errno(), Peter Maydell, 2019/10/14
- [PULL 26/68] target/arm/arm-semi: Always set some kind of errno for failed calls, Peter Maydell, 2019/10/14
- [PULL 27/68] target/arm/arm-semi: Correct comment about gdb syscall races, Peter Maydell, 2019/10/14
- [PULL 30/68] target/arm/arm-semi: Use set_swi_errno() in gdbstub callback functions, Peter Maydell, 2019/10/14
- [PULL 28/68] target/arm/arm-semi: Make semihosting code hand out its own file descriptors, Peter Maydell, 2019/10/14
- [PULL 29/68] target/arm/arm-semi: Restrict use of TaskState*, Peter Maydell, 2019/10/14
- [PULL 31/68] target/arm/arm-semi: Factor out implementation of SYS_CLOSE, Peter Maydell, 2019/10/14
- [PULL 32/68] target/arm/arm-semi: Factor out implementation of SYS_WRITE,
Peter Maydell <=
- [PULL 33/68] target/arm/arm-semi: Factor out implementation of SYS_READ, Peter Maydell, 2019/10/14
- [PULL 34/68] target/arm/arm-semi: Factor out implementation of SYS_ISTTY, Peter Maydell, 2019/10/14
- [PULL 35/68] target/arm/arm-semi: Factor out implementation of SYS_SEEK, Peter Maydell, 2019/10/14
- [PULL 36/68] target/arm/arm-semi: Factor out implementation of SYS_FLEN, Peter Maydell, 2019/10/14
- [PULL 37/68] target/arm/arm-semi: Implement support for semihosting feature detection, Peter Maydell, 2019/10/14
- [PULL 38/68] target/arm/arm-semi: Implement SH_EXT_EXIT_EXTENDED extension, Peter Maydell, 2019/10/14
- [PULL 39/68] target/arm/arm-semi: Implement SH_EXT_STDOUT_STDERR extension, Peter Maydell, 2019/10/14
- [PULL 40/68] aspeed/wdt: Check correct register for clock source, Peter Maydell, 2019/10/14
- [PULL 41/68] hw/sd/aspeed_sdhci: New device, Peter Maydell, 2019/10/14
- [PULL 44/68] aspeed/timer: Add support for control register 3, Peter Maydell, 2019/10/14