@samitouri / QOSamiQemu / commits / 8c87f82cf9

target/hexagon: Add guest reg reading functionality

Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com> Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>

Matheus Tavares Bernardino committed Jun 22, 2026 at 15:28 UTC 8c87f82cf90d59ddbcdb5ac7ce556e29f1148db0
3 files changed +34 -2
target/hexagon/cpu.c
+19
@@ -770,6 +770,25 @@ static void hexagon_cpu_class_init(ObjectClass *c, const void *data)
770 #endif
771 }
772
773 +#ifndef CONFIG_USER_ONLY
774 +uint32_t hexagon_greg_read(CPUHexagonState *env, uint32_t reg)
775 +{
776 + if (reg <= HEX_GREG_G3) {
777 + return env->greg[reg];
778 + }
779 + switch (reg) {
780 + case HEX_GREG_GPCYCLELO:
781 + return hexagon_get_sys_pcycle_count_low(env);
782 + case HEX_GREG_GPCYCLEHI:
783 + return hexagon_get_sys_pcycle_count_high(env);
784 + default:
785 + qemu_log_mask(LOG_UNIMP, "reading greg %" PRId32
786 + " not yet supported.\n", reg);
787 + return 0;
788 + }
789 +}
790 +#endif
791 +
792 static void hexagon_cpu_class_base_init(ObjectClass *c, const void *data)
793 {
794 HexagonCPUClass *mcc = HEXAGON_CPU_CLASS(c);
target/hexagon/cpu.h
+1
@@ -220,6 +220,7 @@ G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,
220 * not stopped.
221 */
222 bool hexagon_thread_is_enabled(CPUHexagonState *thread_env);
223 +uint32_t hexagon_greg_read(CPUHexagonState *env, uint32_t reg);
224 void hexagon_cpu_soft_reset(CPUHexagonState *env);
225 #endif
226
target/hexagon/op_helper.c
+14 -2
@@ -1878,13 +1878,25 @@ uint64_t HELPER(sreg_read_pair)(CPUHexagonState *env, uint32_t reg)
1878 }
1879
1880 uint32_t HELPER(greg_read)(CPUHexagonState *env, uint32_t reg)
1881 +
1882 {
1882 - g_assert_not_reached();
1883 + return hexagon_greg_read(env, reg);
1884 }
1885
1886 uint64_t HELPER(greg_read_pair)(CPUHexagonState *env, uint32_t reg)
1887 +
1888 {
1887 - g_assert_not_reached();
1889 + if (reg == HEX_GREG_G0 || reg == HEX_GREG_G2) {
1890 + return (uint64_t)(env->greg[reg]) |
1891 + (((uint64_t)(env->greg[reg + 1])) << 32);
1892 + }
1893 + switch (reg) {
1894 + case HEX_GREG_GPCYCLELO:
1895 + return hexagon_get_sys_pcycle_count(env);
1896 + default:
1897 + return (uint64_t)hexagon_greg_read(env, reg) |
1898 + ((uint64_t)(hexagon_greg_read(env, reg + 1)) << 32);
1899 + }
1900 }
1901
1902 /*