[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [Qemu-arm] [PATCH 07/13] target/arm/arm-semi: Factor ou
From: |
Alex Bennée |
Subject: |
Re: [Qemu-devel] [Qemu-arm] [PATCH 07/13] target/arm/arm-semi: Factor out implementation of SYS_READ |
Date: |
Thu, 12 Sep 2019 12:19:39 +0100 |
User-agent: |
mu4e 1.3.4; emacs 27.0.50 |
Peter Maydell <address@hidden> writes:
> Factor out the implementation of SYS_READ via the
> new function tables.
"As for SYS_WRITE we need env for lock_user in system emulation."?
>
> Signed-off-by: Peter Maydell <address@hidden>
Either way:
Reviewed-by: Alex Bennée <address@hidden>
> ---
> target/arm/arm-semi.c | 57 ++++++++++++++++++++++++++++---------------
> 1 file changed, 37 insertions(+), 20 deletions(-)
>
> diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
> index 0dec4c04e2f..48a10dd3c3a 100644
> --- a/target/arm/arm-semi.c
> +++ b/target/arm/arm-semi.c
> @@ -347,6 +347,8 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu,
> gdb_syscall_complete_cb cb,
> typedef uint32_t sys_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf);
> 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);
>
> static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)
> {
> @@ -374,6 +376,29 @@ static uint32_t host_writefn(TaskState *ts, ARMCPU *cpu,
> GuestFD *gf,
> return len - ret;
> }
>
> +static uint32_t host_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,
> + target_ulong buf, uint32_t len)
> +{
> + uint32_t ret;
> +#ifndef CONFIG_USER_ONLY
> + CPUARMState *env = &cpu->env;
> +#endif
> + char *s = lock_user(VERIFY_WRITE, buf, len, 0);
> + if (!s) {
> + /* return bytes not read */
> + return len;
> + }
> + do {
> + ret = set_swi_errno(ts, read(gf->hostfd, s, len));
> + } while (ret == -1 && errno == EINTR);
> + unlock_user(s, buf, len);
> + if (ret == (uint32_t)-1) {
> + ret = 0;
> + }
> + /* Return bytes not read */
> + return len - ret;
> +}
> +
> static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf)
> {
> return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
> @@ -387,19 +412,30 @@ static uint32_t gdb_writefn(TaskState *ts, ARMCPU *cpu,
> GuestFD *gf,
> gf->hostfd, buf, len);
> }
>
> +static uint32_t gdb_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf,
> + target_ulong buf, uint32_t len)
> +{
> + arm_semi_syscall_len = len;
> + return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x",
> + gf->hostfd, buf, len);
> +}
> +
> typedef struct GuestFDFunctions {
> sys_closefn *closefn;
> sys_writefn *writefn;
> + sys_readfn *readfn;
> } GuestFDFunctions;
>
> static const GuestFDFunctions guestfd_fns[] = {
> [GuestFDHost] = {
> .closefn = host_closefn,
> .writefn = host_writefn,
> + .readfn = host_readfn,
> },
> [GuestFDGDB] = {
> .closefn = gdb_closefn,
> .writefn = gdb_writefn,
> + .readfn = gdb_readfn,
> },
> };
>
> @@ -551,26 +587,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)
> return set_swi_errno(ts, -1);
> }
>
> - if (use_gdb_syscalls()) {
> - arm_semi_syscall_len = len;
> - return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x",
> - gf->hostfd, arg1, len);
> - } else {
> - s = lock_user(VERIFY_WRITE, arg1, len, 0);
> - if (!s) {
> - /* return bytes not read */
> - return len;
> - }
> - do {
> - ret = set_swi_errno(ts, read(gf->hostfd, s, len));
> - } while (ret == -1 && errno == EINTR);
> - unlock_user(s, arg1, len);
> - if (ret == (uint32_t)-1) {
> - ret = 0;
> - }
> - /* Return bytes not read */
> - return len - ret;
> - }
> + return guestfd_fns[gf->type].readfn(ts, cpu, gf, arg1, len);
> case TARGET_SYS_READC:
> qemu_log_mask(LOG_UNIMP, "%s: SYS_READC not implemented", __func__);
> return 0;
--
Alex Bennée
- [Qemu-devel] [PATCH 04/13] target/arm/arm-semi: clean up TaskState* usage in non-user-only code, (continued)
- [Qemu-devel] [PATCH 04/13] target/arm/arm-semi: clean up TaskState* usage in non-user-only code, Peter Maydell, 2019/09/10
- [Qemu-devel] [PATCH 05/13] target/arm/arm-semi: Factor out implementation of SYS_CLOSE, Peter Maydell, 2019/09/10
- [Qemu-devel] [PATCH 06/13] target/arm/arm-semi: Factor out implementation of SYS_WRITE, Peter Maydell, 2019/09/10
- [Qemu-devel] [PATCH 08/13] target/arm/arm-semi: Factor out implementation of SYS_ISTTY, Peter Maydell, 2019/09/10
- [Qemu-devel] [PATCH 07/13] target/arm/arm-semi: Factor out implementation of SYS_READ, Peter Maydell, 2019/09/10
- Re: [Qemu-devel] [Qemu-arm] [PATCH 07/13] target/arm/arm-semi: Factor out implementation of SYS_READ,
Alex Bennée <=
- [Qemu-devel] [PATCH 09/13] target/arm/arm-semi: Factor out implementation of SYS_SEEK, Peter Maydell, 2019/09/10
- [Qemu-devel] [PATCH 03/13] target/arm/arm-semi: Make semihosting code hand out its own file descriptors, Peter Maydell, 2019/09/10
- [Qemu-devel] [PATCH 12/13] target/arm/arm-semi: Implement SH_EXT_STDOUT_STDERR extension, Peter Maydell, 2019/09/10
- [Qemu-devel] [PATCH 13/13] target/arm/arm-semi: Implement SH_EXT_EXIT_EXTENDED extension, Peter Maydell, 2019/09/10
- [Qemu-devel] [PATCH 10/13] target/arm/arm-semi: Factor out implementation of SYS_FLEN, Peter Maydell, 2019/09/10