target/arm: correct return values for WRITE/READ in arm-semi

The documentation says the write should return the number of bytes not
written on an error (0 means everything was written). Read provides a
buffer length and the return value should be the buffer length - bytes
actually read. Remove the incorrect FIXME's and return the correct
values.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
This commit is contained in:
Alex Bennée 2019-05-14 12:21:45 +01:00
parent a131795f4c
commit 629a0b065a

View File

@ -331,13 +331,15 @@ target_ulong do_arm_semihosting(CPUARMState *env)
} else { } else {
s = lock_user(VERIFY_READ, arg1, len, 1); s = lock_user(VERIFY_READ, arg1, len, 1);
if (!s) { if (!s) {
/* FIXME - should this error code be -TARGET_EFAULT ? */ /* Return bytes not written on error */
return (uint32_t)-1; return len;
} }
ret = set_swi_errno(ts, write(arg0, s, len)); ret = set_swi_errno(ts, write(arg0, s, len));
unlock_user(s, arg1, 0); unlock_user(s, arg1, 0);
if (ret == (uint32_t)-1) if (ret == (uint32_t)-1) {
return -1; ret = 0;
}
/* Return bytes not written */
return len - ret; return len - ret;
} }
case TARGET_SYS_READ: case TARGET_SYS_READ:
@ -352,15 +354,17 @@ target_ulong do_arm_semihosting(CPUARMState *env)
} else { } else {
s = lock_user(VERIFY_WRITE, arg1, len, 0); s = lock_user(VERIFY_WRITE, arg1, len, 0);
if (!s) { if (!s) {
/* FIXME - should this error code be -TARGET_EFAULT ? */ /* return bytes not read */
return (uint32_t)-1; return len;
} }
do { do {
ret = set_swi_errno(ts, read(arg0, s, len)); ret = set_swi_errno(ts, read(arg0, s, len));
} while (ret == -1 && errno == EINTR); } while (ret == -1 && errno == EINTR);
unlock_user(s, arg1, len); unlock_user(s, arg1, len);
if (ret == (uint32_t)-1) if (ret == (uint32_t)-1) {
return -1; ret = 0;
}
/* Return bytes not read */
return len - ret; return len - ret;
} }
case TARGET_SYS_READC: case TARGET_SYS_READC: