[PATCH 18/22] bsd-user: Define target_arg64

Warner Losh posted 22 patches 4 years ago
Maintainers: Kyle Evans <kevans@freebsd.org>, Warner Losh <imp@bsdimp.com>, Brad Smith <brad@comstyle.com>
There is a newer version of this series
[PATCH 18/22] bsd-user: Define target_arg64
Posted by Warner Losh 4 years ago
target_arg64 is a generic way to extract 64-bits from a pair of
arguments. On 32-bit platforms, it returns them joined together as
appropriate. On 64-bit platforms, it returns the first arg because it's
already 64-bits.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index a9efa807b78..af272c2a802 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -462,6 +462,19 @@ static inline void *lock_user_string(abi_ulong guest_addr)
 #define unlock_user_struct(host_ptr, guest_addr, copy)          \
     unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0)
 
+static inline uint64_t target_arg64(uint32_t word0, uint32_t word1)
+{
+#if TARGET_ABI_BITS == 32
+#ifdef TARGET_WORDS_BIGENDIAN
+    return ((uint64_t)word0 << 32) | word1;
+#else
+    return ((uint64_t)word1 << 32) | word0;
+#endif
+#else /* TARGET_ABI_BITS != 32 */
+    return word0;
+#endif /* TARGET_ABI_BITS != 32 */
+}
+
 #include <pthread.h>
 
 #include "user/safe-syscall.h"
-- 
2.33.1


Re: [PATCH 18/22] bsd-user: Define target_arg64
Posted by Kyle Evans 4 years ago
On Tue, Feb 1, 2022 at 5:15 AM Warner Losh <imp@bsdimp.com> wrote:
>
> target_arg64 is a generic way to extract 64-bits from a pair of
> arguments. On 32-bit platforms, it returns them joined together as
> appropriate. On 64-bit platforms, it returns the first arg because it's
> already 64-bits.
>
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>  bsd-user/qemu.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>

Reviewed-by: Kyle Evans <kevans@FreeBSD.org>

> diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
> index a9efa807b78..af272c2a802 100644
> --- a/bsd-user/qemu.h
> +++ b/bsd-user/qemu.h
> @@ -462,6 +462,19 @@ static inline void *lock_user_string(abi_ulong guest_addr)
>  #define unlock_user_struct(host_ptr, guest_addr, copy)          \
>      unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0)
>
> +static inline uint64_t target_arg64(uint32_t word0, uint32_t word1)
> +{
> +#if TARGET_ABI_BITS == 32
> +#ifdef TARGET_WORDS_BIGENDIAN
> +    return ((uint64_t)word0 << 32) | word1;
> +#else
> +    return ((uint64_t)word1 << 32) | word0;
> +#endif
> +#else /* TARGET_ABI_BITS != 32 */
> +    return word0;
> +#endif /* TARGET_ABI_BITS != 32 */
> +}
> +
>  #include <pthread.h>
>
>  #include "user/safe-syscall.h"
> --
> 2.33.1
>

Re: [PATCH 18/22] bsd-user: Define target_arg64
Posted by Richard Henderson 4 years ago
On 2/1/22 22:14, Warner Losh wrote:
> target_arg64 is a generic way to extract 64-bits from a pair of
> arguments. On 32-bit platforms, it returns them joined together as
> appropriate. On 64-bit platforms, it returns the first arg because it's
> already 64-bits.
> 
> Signed-off-by: Stacey Son<sson@FreeBSD.org>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/qemu.h | 13 +++++++++++++
>   1 file changed, 13 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~