target/hexagon: Add sysemu TCG overrides
Define TCG overrides for setprio(), crswap(,sgp{0,1,1:0}). Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
Brian Cain committed
Jun 22, 2026 at 15:28 UTC
8626bd93097b014fc80b48ab974d972cd5e3ca69
7 files changed
+95
-7
target/hexagon/cpu_helper.h
new
+18
@@ -0,0 +1,18 @@
1
+/*
2
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3
+ *
4
+ * SPDX-License-Identifier: GPL-2.0-or-later
5
+ */
6
+
7
+#ifndef HEXAGON_CPU_HELPER_H
8
+#define HEXAGON_CPU_HELPER_H
9
+
10
+uint32_t hexagon_get_pmu_counter(CPUHexagonState *cur_env, int index);
11
+uint64_t hexagon_get_sys_pcycle_count(CPUHexagonState *env);
12
+uint32_t hexagon_get_sys_pcycle_count_high(CPUHexagonState *env);
13
+uint32_t hexagon_get_sys_pcycle_count_low(CPUHexagonState *env);
14
+void hexagon_set_sys_pcycle_count_high(CPUHexagonState *env, uint32_t val);
15
+void hexagon_set_sys_pcycle_count_low(CPUHexagonState *env, uint32_t val);
16
+void hexagon_set_sys_pcycle_count(CPUHexagonState *env, uint64_t val);
17
+
18
+#endif
target/hexagon/gen_tcg_sys.h
new
+55
@@ -0,0 +1,55 @@
1
+/*
2
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3
+ *
4
+ * SPDX-License-Identifier: GPL-2.0-or-later
5
+ */
6
+
7
+#ifndef HEXAGON_GEN_TCG_SYS_H
8
+#define HEXAGON_GEN_TCG_SYS_H
9
+
10
+#define fGEN_TCG_Y2_setprio(SHORTCODE) \
11
+ gen_helper_setprio(tcg_env, PtV, RsV)
12
+
13
+#define fGEN_TCG_Y2_crswap0(SHORTCODE) \
14
+ do { \
15
+ TCGv_i32 tmp = tcg_temp_new_i32(); \
16
+ tcg_gen_mov_tl(tmp, RxV); \
17
+ tcg_gen_mov_tl(RxV, hex_t_sreg[HEX_SREG_SGP0]); \
18
+ if (ctx->need_commit) { \
19
+ tcg_gen_mov_tl(ctx->t_sreg_new_value[HEX_SREG_SGP0], tmp); \
20
+ } else { \
21
+ tcg_gen_mov_tl(hex_t_sreg[HEX_SREG_SGP0], tmp); \
22
+ } \
23
+ } while (0)
24
+
25
+#define fGEN_TCG_Y4_crswap1(SHORTCODE) \
26
+ do { \
27
+ TCGv_i32 tmp = tcg_temp_new_i32(); \
28
+ tcg_gen_mov_tl(tmp, RxV); \
29
+ tcg_gen_mov_tl(RxV, hex_t_sreg[HEX_SREG_SGP1]); \
30
+ if (ctx->need_commit) { \
31
+ tcg_gen_mov_tl(ctx->t_sreg_new_value[HEX_SREG_SGP1], tmp); \
32
+ } else { \
33
+ tcg_gen_mov_tl(hex_t_sreg[HEX_SREG_SGP1], tmp); \
34
+ } \
35
+ } while (0)
36
+
37
+#define fGEN_TCG_Y4_crswap10(SHORTCODE) \
38
+ do { \
39
+ TCGv_i64 tmp = tcg_temp_new_i64(); \
40
+ tcg_gen_mov_i64(tmp, RxxV); \
41
+ tcg_gen_concat_i32_i64(RxxV, \
42
+ hex_t_sreg[HEX_SREG_SGP0], \
43
+ hex_t_sreg[HEX_SREG_SGP1]); \
44
+ if (ctx->need_commit) { \
45
+ tcg_gen_extrl_i64_i32( \
46
+ ctx->t_sreg_new_value[HEX_SREG_SGP0], tmp); \
47
+ tcg_gen_extrh_i64_i32( \
48
+ ctx->t_sreg_new_value[HEX_SREG_SGP1], tmp); \
49
+ } else { \
50
+ tcg_gen_extrl_i64_i32(hex_t_sreg[HEX_SREG_SGP0], tmp); \
51
+ tcg_gen_extrh_i64_i32(hex_t_sreg[HEX_SREG_SGP1], tmp); \
52
+ } \
53
+ } while (0)
54
+
55
+#endif
target/hexagon/genptr.c
+4
@@ -31,6 +31,10 @@
31
#undef QEMU_GENERATE
32
#include "gen_tcg.h"
33
#include "gen_tcg_hvx.h"
34
+#ifndef CONFIG_USER_ONLY
35
+#include "gen_tcg_sys.h"
36
+#endif
37
+
38
#include "genptr.h"
39
40
TCGv gen_read_reg(TCGv result, int num)
target/hexagon/helper.h
+1
@@ -114,4 +114,5 @@ DEF_HELPER_2(sreg_read_pair, i64, env, i32)
114
DEF_HELPER_2(greg_read, i32, env, i32)
115
DEF_HELPER_2(greg_read_pair, i64, env, i32)
116
DEF_HELPER_3(sreg_write_masked, void, env, i32, i32)
117
+DEF_HELPER_3(setprio, void, env, i32, i32)
118
#endif
target/hexagon/hex_common.py
+2
@@ -1369,6 +1369,7 @@ def parse_common_args(desc):
1369
parser.add_argument("semantics", help="semantics file")
1370
parser.add_argument("overrides", help="overrides file")
1371
parser.add_argument("overrides_vec", help="vector overrides file")
1372
+ parser.add_argument("overrides_sys", help="system overrides file")
1373
parser.add_argument("out", help="output file")
1374
parser.add_argument("--idef-parser",
1375
help="file of instructions translated by idef-parser")
@@ -1376,6 +1377,7 @@ def parse_common_args(desc):
1377
read_semantics_file(args.semantics)
1378
read_overrides_file(args.overrides)
1379
read_overrides_file(args.overrides_vec)
1380
+ read_overrides_file(args.overrides_sys)
1381
if args.idef_parser:
1382
read_idef_parser_enabled_file(args.idef_parser)
1383
calculate_attribs()
target/hexagon/meson.build
+7
-6
@@ -20,6 +20,7 @@ hexagon_ss = ss.source_set()
20
hex_common_py = 'hex_common.py'
21
gen_tcg_h = meson.current_source_dir() / 'gen_tcg.h'
22
gen_tcg_hvx_h = meson.current_source_dir() / 'gen_tcg_hvx.h'
23
+gen_tcg_sys_h = meson.current_source_dir() / 'gen_tcg_sys.h'
24
idef_parser_dir = meson.current_source_dir() / 'idef-parser'
25
26
#
@@ -337,12 +338,12 @@ if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
338
# Setup input and dependencies for the next step, this depends on whether or
339
# not idef-parser is enabled
340
helper_dep = [semantics_generated, idef_generated_tcg_c, idef_generated_tcg]
340
- helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h, '--idef-parser', idef_generated_list]
341
+ helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h, '--idef-parser', idef_generated_list]
342
else
343
# Setup input and dependencies for the next step, this depends on whether or
344
# not idef-parser is enabled
345
helper_dep = [semantics_generated]
345
- helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h]
346
+ helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h]
347
endif
348
349
#
@@ -356,7 +357,7 @@ helper_protos_generated = custom_target(
357
'helper_protos_generated.h.inc',
358
output: 'helper_protos_generated.h.inc',
359
depends: helper_dep,
359
- depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h],
360
+ depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h],
361
command: [python, files('gen_helper_protos.py'), helper_in, '@OUTPUT@'],
362
)
363
hexagon_ss.add(helper_protos_generated)
@@ -365,7 +366,7 @@ helper_funcs_generated = custom_target(
366
'helper_funcs_generated.c.inc',
367
output: 'helper_funcs_generated.c.inc',
368
depends: helper_dep,
368
- depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h],
369
+ depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h],
370
command: [python, files('gen_helper_funcs.py'), helper_in, '@OUTPUT@'],
371
)
372
hexagon_ss.add(helper_funcs_generated)
@@ -374,7 +375,7 @@ tcg_funcs_generated = custom_target(
375
'tcg_funcs_generated.c.inc',
376
output: 'tcg_funcs_generated.c.inc',
377
depends: helper_dep,
377
- depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h],
378
+ depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h],
379
command: [python, files('gen_tcg_funcs.py'), helper_in, '@OUTPUT@'],
380
)
381
hexagon_ss.add(tcg_funcs_generated)
@@ -383,7 +384,7 @@ analyze_funcs_generated = custom_target(
384
'analyze_funcs_generated.c.inc',
385
output: 'analyze_funcs_generated.c.inc',
386
depends: helper_dep,
386
- depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h],
387
+ depend_files: [hex_common_py, gen_tcg_h, gen_tcg_hvx_h, gen_tcg_sys_h],
388
command: [python, files('gen_analyze_funcs.py'), helper_in, '@OUTPUT@'],
389
)
390
hexagon_ss.add(analyze_funcs_generated)
target/hexagon/op_helper.c
+8
-1
@@ -20,9 +20,9 @@
20
#include "accel/tcg/cpu-ldst.h"
21
#include "accel/tcg/cpu-loop.h"
22
#include "accel/tcg/probe.h"
23
+#include "cpu.h"
24
#include "exec/helper-proto.h"
25
#include "fpu/softfloat.h"
25
-#include "cpu.h"
26
#include "internal.h"
27
#include "macros.h"
28
#include "sys_macros.h"
@@ -32,6 +32,7 @@
32
#include "mmvec/mmvec.h"
33
#include "mmvec/macros.h"
34
#include "op_helper.h"
35
+#include "cpu_helper.h"
36
#include "translate.h"
37
#ifndef CONFIG_USER_ONLY
38
#include "hexswi.h"
@@ -1413,6 +1414,12 @@ uint64_t HELPER(greg_read_pair)(CPUHexagonState *env, uint32_t reg)
1414
{
1415
g_assert_not_reached();
1416
}
1417
+
1418
+void HELPER(setprio)(CPUHexagonState *env, uint32_t thread, uint32_t prio)
1419
+{
1420
+ g_assert_not_reached();
1421
+}
1422
+
1423
#endif
1424
1425