All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Cain <brian.cain@oss.qualcomm.com>
To: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com>,
	qemu-devel@nongnu.org
Cc: pierrick.bouvier@oss.qualcomm.com, marco.liebel@oss.qualcomm.com,
	philmd@oss.qualcomm.com, ale@rev.ng, anjo@rev.ng
Subject: Re: [PATCH v3 04/13] hexagon: cpu_helper: add reg reading/writing helpers
Date: Sun, 9 Aug 2026 22:48:22 -0500	[thread overview]
Message-ID: <17d59ae1-82f4-4af9-b0be-38d032840358@oss.qualcomm.com> (raw)
In-Reply-To: <b02e7a60814d97b1a259718daa3199f01dcac45b.1784568922.git.matheus.bernardino@oss.qualcomm.com>


On 7/20/2026 12:41 PM, Matheus Tavares Bernardino wrote:
> And adjust op_helper to use those. They will also be used on upcoming
> semihosting commits.
>
> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> Signed-off-by: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com>
> ---


I got rid of arch_{s,g}et_system_reg() from a previous series under 
advice from Taylor.  I think it's probably for the best. In our 
downstream fork we had a nest of functions and macros for accessing 
system registers and if we can avoid those we'll probably be better off.


https://lore.kernel.org/qemu-devel/017c01db9772$3f31b610$bd952230$@gmail.com/


>   target/hexagon/cpu_helper.h | 18 +++++++++++++++++
>   target/hexagon/cpu_helper.c | 40 +++++++++++++++++++++++++++++++++++++
>   target/hexagon/op_helper.c  | 18 ++---------------
>   3 files changed, 60 insertions(+), 16 deletions(-)
>
> diff --git a/target/hexagon/cpu_helper.h b/target/hexagon/cpu_helper.h
> index ca2e13ab1d1..757a49fc4d4 100644
> --- a/target/hexagon/cpu_helper.h
> +++ b/target/hexagon/cpu_helper.h
> @@ -7,6 +7,24 @@
>   #ifndef HEXAGON_CPU_HELPER_H
>   #define HEXAGON_CPU_HELPER_H
>   
> +static inline void arch_set_thread_reg(CPUHexagonState *env, uint32_t reg,
> +                                       uint32_t val)
> +{
> +    g_assert(reg < TOTAL_PER_THREAD_REGS);
> +    env->gpr[reg] = val;
> +}
> +
> +static inline uint32_t arch_get_thread_reg(CPUHexagonState *env, uint32_t reg)
> +{
> +    g_assert(reg < TOTAL_PER_THREAD_REGS);
> +    return env->gpr[reg];
> +}
> +
> +void arch_set_system_reg(CPUHexagonState *env, uint32_t reg, uint32_t val);
> +void arch_set_system_reg_masked(CPUHexagonState *env, uint32_t reg,
> +                                uint32_t val);
> +uint32_t arch_get_system_reg(CPUHexagonState *env, uint32_t reg);
> +
>   void hexagon_read_memory(CPUHexagonState *env, target_ulong vaddr, int size,
>                            void *retptr, uintptr_t retaddr);
>   void hexagon_write_memory(CPUHexagonState *env, target_ulong vaddr,
> diff --git a/target/hexagon/cpu_helper.c b/target/hexagon/cpu_helper.c
> index e981e11a35d..98ce599571e 100644
> --- a/target/hexagon/cpu_helper.c
> +++ b/target/hexagon/cpu_helper.c
> @@ -27,6 +27,46 @@
>   
>   #ifndef CONFIG_USER_ONLY
>   
> +uint32_t arch_get_system_reg(CPUHexagonState *env, uint32_t reg)
> +{
> +    if (reg == HEX_SREG_PCYCLELO) {
> +        return hexagon_get_sys_pcycle_count_low(env);
> +    } else if (reg == HEX_SREG_PCYCLEHI) {
> +        return hexagon_get_sys_pcycle_count_high(env);
> +    }
> +
> +    g_assert(reg < NUM_SREGS);
> +    if (reg < HEX_SREG_GLB_START) {
> +        return env->t_sreg[reg];
> +    } else {
> +        HexagonCPU *cpu = env_archcpu(env);
> +        return hexagon_globalreg_read(cpu->globalregs, reg, env->threadId);
> +    }
> +}
> +
> +void arch_set_system_reg(CPUHexagonState *env, uint32_t reg, uint32_t val)
> +{
> +    g_assert(reg < NUM_SREGS);
> +    if (reg < HEX_SREG_GLB_START) {
> +        env->t_sreg[reg] = val;
> +    } else {
> +        HexagonCPU *cpu = env_archcpu(env);
> +        hexagon_globalreg_write(cpu->globalregs, reg, val, env->threadId);
> +    }
> +}
> +
> +void arch_set_system_reg_masked(CPUHexagonState *env, uint32_t reg,
> +                                uint32_t val)
> +{
> +    g_assert(reg < NUM_SREGS);
> +    if (reg < HEX_SREG_GLB_START) {
> +        env->t_sreg[reg] = val;
> +    } else {
> +        HexagonCPU *cpu = env_archcpu(env);
> +        hexagon_globalreg_write_masked(cpu->globalregs, reg, val);
> +    }
> +}
> +
>   static bool hexagon_read_memory_small(CPUHexagonState *env, target_ulong addr,
>                                         int byte_count, unsigned char *dstbuf,
>                                         int mmu_idx, uintptr_t retaddr)
> diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c
> index 3ce223caba3..324a9632dd4 100644
> --- a/target/hexagon/op_helper.c
> +++ b/target/hexagon/op_helper.c
> @@ -1846,28 +1846,14 @@ void HELPER(setimask)(CPUHexagonState *env, uint32_t tid, uint32_t imask)
>   void HELPER(sreg_write_masked)(CPUHexagonState *env, uint32_t reg, uint32_t val)
>   {
>       BQL_LOCK_GUARD();
> -    if (reg < HEX_SREG_GLB_START) {
> -        env->t_sreg[reg] = val;
> -    } else {
> -        HexagonCPU *cpu = env_archcpu(env);
> -        if (cpu->globalregs) {
> -            hexagon_globalreg_write_masked(cpu->globalregs, reg, val);
> -        }
> -    }
> +    arch_set_system_reg_masked(env, reg, val);
>   }
>   
>   static inline QEMU_ALWAYS_INLINE uint32_t sreg_read(CPUHexagonState *env,
>                                                       uint32_t reg)
>   {
> -    HexagonCPU *cpu;
> -
>       g_assert(bql_locked());
> -    if (reg < HEX_SREG_GLB_START) {
> -        return env->t_sreg[reg];
> -    }
> -    cpu = env_archcpu(env);
> -    return cpu->globalregs ?
> -        hexagon_globalreg_read(cpu->globalregs, reg, env->threadId) : 0;
> +    return arch_get_system_reg(env, reg);
>   }
>   
>   uint32_t HELPER(sreg_read)(CPUHexagonState *env, uint32_t reg)


  reply	other threads:[~2026-08-10  3:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 17:40 [PATCH v3 00/13] hexagon: add semihosting support Matheus Tavares Bernardino
2026-07-20 17:40 ` [PATCH v3 01/13] target/hexagon: fix improper assign of cause code to exception index Matheus Tavares Bernardino
2026-07-20 17:40 ` [PATCH v3 02/13] target/hexagon: fix PC advancement for non-COF TB terminators Matheus Tavares Bernardino
2026-07-20 17:40 ` [PATCH v3 03/13] target/hexagon: add aux functions for guest mem load/store Matheus Tavares Bernardino
2026-07-20 17:41 ` [PATCH v3 04/13] hexagon: cpu_helper: add reg reading/writing helpers Matheus Tavares Bernardino
2026-08-10  3:48   ` Brian Cain [this message]
2026-07-20 17:41 ` [PATCH v3 05/13] semihosting: add APIs for chardev-aware guest fd routing Matheus Tavares Bernardino
2026-07-20 17:41 ` [PATCH v3 06/13] semihosting: add callback to set error Matheus Tavares Bernardino
2026-07-20 17:41 ` [PATCH v3 07/13] target/hexagon: add semihosting support Matheus Tavares Bernardino
2026-08-17  4:11   ` Brian Cain
2026-08-17  4:23   ` Philippe Mathieu-Daudé
2026-08-17 18:50     ` Matheus Tavares Bernardino
2026-07-20 17:41 ` [PATCH v3 08/13] semihosting: add ftruncate helper (to be used for hexagon) Matheus Tavares Bernardino
2026-07-20 17:41 ` [PATCH v3 09/13] target/hexagon: add main arch-specific semihosting operations Matheus Tavares Bernardino
2026-08-17  4:10   ` Brian Cain
2026-08-17  4:29   ` Philippe Mathieu-Daudé
2026-08-18 14:06     ` Matheus Tavares Bernardino
2026-07-20 17:41 ` [PATCH v3 10/13] target/hexagon: add COREDUMP semihosting operation Matheus Tavares Bernardino
2026-08-17  4:34   ` Philippe Mathieu-Daudé
2026-08-17 19:55     ` Matheus Tavares Bernardino
2026-07-20 17:41 ` [PATCH v3 11/13] target/hexagon: Add an errno mapping Matheus Tavares Bernardino
2026-08-17  4:41   ` Philippe Mathieu-Daudé
2026-08-17 20:09     ` Matheus Tavares Bernardino
2026-07-20 17:41 ` [PATCH v3 12/13] python/machine: support routing semihosting output to the test console Matheus Tavares Bernardino
2026-07-20 17:41 ` [PATCH v3 13/13] tests/functional: Add hexagon semihosting systests Matheus Tavares Bernardino
2026-08-17  4:47   ` Philippe Mathieu-Daudé
2026-08-19 20:25     ` Matheus Tavares Bernardino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17d59ae1-82f4-4af9-b0be-38d032840358@oss.qualcomm.com \
    --to=brian.cain@oss.qualcomm.com \
    --cc=ale@rev.ng \
    --cc=anjo@rev.ng \
    --cc=marco.liebel@oss.qualcomm.com \
    --cc=matheus.bernardino@oss.qualcomm.com \
    --cc=philmd@oss.qualcomm.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.