Re: [PATCH v3 11/13] target/hexagon: Add an errno mapping

Philippe Mathieu-Daudé <[email protected]>
Newsgroups gmane.comp.emulators.qemu
Message-ID <[email protected]>
On 20/7/26 19:41, Matheus Tavares Bernardino wrote:
> From: Brian Cain <[email protected]>
> 
> The Hexagon semihosting ABI defines its own errno values
> which may differ from the host's.  Translate host errno to
> the Hexagon-specific values before returning results to the
> guest so that baremetal programs see the expected error codes.
> 
> Signed-off-by: Brian Cain <[email protected]>
> Reviewed-by: Pierrick Bouvier <[email protected]>
> Signed-off-by: Matheus Tavares Bernardino <[email protected]>
> ---
>   target/hexagon/hexswi.c | 75 ++++++++++++++++++++++++++++++++++-------
>   1 file changed, 63 insertions(+), 12 deletions(-)
> 
> diff --git a/target/hexagon/hexswi.c b/target/hexagon/hexswi.c
> index 564a11e557a..d93789e39c7 100644
> --- a/target/hexagon/hexswi.c
> +++ b/target/hexagon/hexswi.c
> @@ -154,12 +154,63 @@ static void do_preload(CPUHexagonState *env, target_ulong swi_info, bool load)
>       hexagon_peek_memory_range(env, addr, count, retaddr);
>   }
>   
> +/* Hexagon semihosting errno values */
> +#define HEX_EINVAL          22
> +#define HEX_ERRNOS \
> +    HEX_ERRNO(EPERM,        1) \
> +    HEX_ERRNO(ENOENT,       2) \
> +    HEX_ERRNO(EINTR,        4) \
> +    HEX_ERRNO(EIO,          5) \
> +    HEX_ERRNO(ENXIO,        6) \
> +    HEX_ERRNO(EBADF,        9) \
> +    HEX_ERRNO(EAGAIN,       11) \
> +    HEX_ERRNO(ENOMEM,       12) \
> +    HEX_ERRNO(EACCES,       13) \
> +    HEX_ERRNO(EFAULT,       14) \
> +    HEX_ERRNO(EBUSY,        16) \
> +    HEX_ERRNO(EEXIST,       17) \
> +    HEX_ERRNO(EXDEV,        18) \
> +    HEX_ERRNO(ENODEV,       19) \
> +    HEX_ERRNO(ENOTDIR,      20) \
> +    HEX_ERRNO(EISDIR,       21) \
> +    HEX_ERRNO(EINVAL,       HEX_EINVAL) \
> +    HEX_ERRNO(ENFILE,       23) \
> +    HEX_ERRNO(EMFILE,       24) \
> +    HEX_ERRNO(ENOTTY,       25) \
> +    HEX_ERRNO(ETXTBSY,      26) \
> +    HEX_ERRNO(EFBIG,        27) \
> +    HEX_ERRNO(ENOSPC,       28) \
> +    HEX_ERRNO(ESPIPE,       29) \
> +    HEX_ERRNO(EROFS,        30) \
> +    HEX_ERRNO(EMLINK,       31) \
> +    HEX_ERRNO(EPIPE,        32) \
> +    HEX_ERRNO(ERANGE,       34) \
> +    HEX_ERRNO(ENAMETOOLONG, 36) \
> +    HEX_ERRNO(ENOSYS,       38) \
> +    HEX_ERRNO(ELOOP,        40) \
> +    HEX_ERRNO(EOVERFLOW,    75)
> +
> +/* Map host errno to hexagon semihosting errno */
> +static void semi_cb(CPUState *cs, uint64_t ret, int err)
> +{
> +#define HEX_ERRNO(NAME, CODE) case NAME: err = CODE; break;
> +    switch (err) {
> +    case 0:
> +        break;
> +    HEX_ERRNOS

IMHO defining the target-specific semihosting values as TARGET_foo
like done in target/xtensa/xtensa-semi.c is more readable long-term.

> +    default:
> +        err = HEX_EINVAL;
> +        break;
> +    }
> +    common_semi_cb(cs, ret, err);
> +}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.