* [PATCH 0/2] target/xtensa: Describe RER and WER register operands
@ 2026-11-19 23:02 Philippe Mathieu-Daudé
2026-11-19 23:02 ` [PATCH 1/2] " Philippe Mathieu-Daudé
2026-11-19 23:02 ` [PATCH 2/2] tests/qtest: Execute Xtensa external register instructions Philippe Mathieu-Daudé
0 siblings, 2 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-19 23:02 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Laurent Vivier, Max Filippov, Fabiano Rosas,
Philippe Mathieu-Daudé
dc233c, lx106 and dsp3400 cores lack the external
register opcodes arguments. Fix and add a test.
Philippe Mathieu-Daudé (2):
target/xtensa: Describe RER and WER register operands
tests/qtest: Execute Xtensa external register instructions
tests/qtest/xtensa-extreg-test.c | 81 +++++++++++++++++++
.../xtensa/core-dc233c/xtensa-modules.c.inc | 14 +++-
.../xtensa/core-dsp3400/xtensa-modules.c.inc | 14 +++-
target/xtensa/core-lx106/xtensa-modules.c.inc | 14 +++-
tests/qtest/meson.build | 2 +
5 files changed, 119 insertions(+), 6 deletions(-)
create mode 100644 tests/qtest/xtensa-extreg-test.c
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] target/xtensa: Describe RER and WER register operands
2026-11-19 23:02 [PATCH 0/2] target/xtensa: Describe RER and WER register operands Philippe Mathieu-Daudé
@ 2026-11-19 23:02 ` Philippe Mathieu-Daudé
2026-11-19 23:02 ` [PATCH 2/2] tests/qtest: Execute Xtensa external register instructions Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-19 23:02 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Laurent Vivier, Max Filippov, Fabiano Rosas,
Philippe Mathieu-Daudé
Supply the two register operands missing from the dc233c, lx106
and dsp3400 ISA tables. RER writes its destination and reads its
address; WER reads both.
The translator expects these operands and otherwise consumes
uninitialized arguments when a guest accesses an external register.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/xtensa/core-dc233c/xtensa-modules.c.inc | 14 ++++++++++++--
target/xtensa/core-dsp3400/xtensa-modules.c.inc | 14 ++++++++++++--
target/xtensa/core-lx106/xtensa-modules.c.inc | 14 ++++++++++++--
3 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/target/xtensa/core-dc233c/xtensa-modules.c.inc b/target/xtensa/core-dc233c/xtensa-modules.c.inc
index 0f32f0804ab3..30a7970207cb 100644
--- a/target/xtensa/core-dc233c/xtensa-modules.c.inc
+++ b/target/xtensa/core-dc233c/xtensa-modules.c.inc
@@ -5814,6 +5814,16 @@ static xtensa_arg_internal Iclass_xt_iclass_div_args[] = {
{ { OPERAND_art }, 'i' }
};
+static xtensa_arg_internal Iclass_xt_iclass_rer_args[] = {
+ { { OPERAND_art }, 'o' },
+ { { OPERAND_ars }, 'i' }
+};
+
+static xtensa_arg_internal Iclass_xt_iclass_wer_args[] = {
+ { { OPERAND_art }, 'i' },
+ { { OPERAND_ars }, 'i' }
+};
+
static xtensa_arg_internal Iclass_xt_iclass_rer_stateArgs[] = {
{ { STATE_PSEXCM }, 'i' },
{ { STATE_PSRING }, 'i' }
@@ -6519,9 +6529,9 @@ static xtensa_iclass_internal iclasses[] = {
4, Iclass_xt_iclass_xsr_atomctl_stateArgs, 0, 0 },
{ 3, Iclass_xt_iclass_div_args,
0, 0, 0, 0 },
- { 0, 0 /* xt_iclass_rer */,
+ { 2, Iclass_xt_iclass_rer_args,
2, Iclass_xt_iclass_rer_stateArgs, 0, 0 },
- { 0, 0 /* xt_iclass_wer */,
+ { 2, Iclass_xt_iclass_wer_args,
2, Iclass_xt_iclass_wer_stateArgs, 0, 0 },
{ 1, Iclass_rur_expstate_args,
2, Iclass_rur_expstate_stateArgs, 0, 0 },
diff --git a/target/xtensa/core-dsp3400/xtensa-modules.c.inc b/target/xtensa/core-dsp3400/xtensa-modules.c.inc
index 28ea3d75fef0..5c358207ed69 100644
--- a/target/xtensa/core-dsp3400/xtensa-modules.c.inc
+++ b/target/xtensa/core-dsp3400/xtensa-modules.c.inc
@@ -54194,6 +54194,16 @@ static xtensa_arg_internal Iclass_wur_phasor_offset_stateArgs[] = {
{ { STATE_CPENABLE }, 'i' }
};
+static xtensa_arg_internal Iclass_xt_iclass_rer_args[] = {
+ { { OPERAND_art }, 'o' },
+ { { OPERAND_ars }, 'i' }
+};
+
+static xtensa_arg_internal Iclass_xt_iclass_wer_args[] = {
+ { { OPERAND_art }, 'i' },
+ { { OPERAND_ars }, 'i' }
+};
+
static xtensa_iclass_internal iclasses[] = {
{ 0, 0 /* xt_iclass_excw */,
0, 0, 0, 0 },
@@ -54719,9 +54729,9 @@ static xtensa_iclass_internal iclasses[] = {
2, Iclass_xt_iclass_wsr_atomctl_stateArgs, 0, 0 },
{ 1, Iclass_xt_iclass_xsr_atomctl_args,
2, Iclass_xt_iclass_xsr_atomctl_stateArgs, 0, 0 },
- { 0, 0 /* xt_iclass_rer */,
+ { 2, Iclass_xt_iclass_rer_args,
0, 0, 0, 0 },
- { 0, 0 /* xt_iclass_wer */,
+ { 2, Iclass_xt_iclass_wer_args,
0, 0, 0, 0 },
{ 1, Iclass_rur_fcr_args,
9, Iclass_rur_fcr_stateArgs, 0, 0 },
diff --git a/target/xtensa/core-lx106/xtensa-modules.c.inc b/target/xtensa/core-lx106/xtensa-modules.c.inc
index f2b5efc6ec88..d7889e707932 100644
--- a/target/xtensa/core-lx106/xtensa-modules.c.inc
+++ b/target/xtensa/core-lx106/xtensa-modules.c.inc
@@ -3291,6 +3291,16 @@ static xtensa_arg_internal Iclass_xt_iclass_nsa_args[] = {
{ { OPERAND_ars }, 'i' }
};
+static xtensa_arg_internal Iclass_xt_iclass_rer_args[] = {
+ { { OPERAND_art }, 'o' },
+ { { OPERAND_ars }, 'i' }
+};
+
+static xtensa_arg_internal Iclass_xt_iclass_wer_args[] = {
+ { { OPERAND_art }, 'i' },
+ { { OPERAND_ars }, 'i' }
+};
+
static xtensa_iclass_internal iclasses[] = {
{ 0, 0 /* xt_iclass_excw */,
0, 0, 0, 0 },
@@ -3606,9 +3616,9 @@ static xtensa_iclass_internal iclasses[] = {
0, 0, 0, 0 },
{ 2, Iclass_xt_iclass_nsa_args,
0, 0, 0, 0 },
- { 0, 0 /* xt_iclass_rer */,
+ { 2, Iclass_xt_iclass_rer_args,
0, 0, 0, 0 },
- { 0, 0 /* xt_iclass_wer */,
+ { 2, Iclass_xt_iclass_wer_args,
0, 0, 0, 0 }
};
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] tests/qtest: Execute Xtensa external register instructions
2026-11-19 23:02 [PATCH 0/2] target/xtensa: Describe RER and WER register operands Philippe Mathieu-Daudé
2026-11-19 23:02 ` [PATCH 1/2] " Philippe Mathieu-Daudé
@ 2026-11-19 23:02 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-19 23:02 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Laurent Vivier, Max Filippov, Fabiano Rosas,
Philippe Mathieu-Daudé
Run a minimal dc233c ELF that executes RER and WER on an unmapped
external register and then writes a RAM marker. Require the marker
while checking that QEMU stays alive.
The embedded guest covers the missing-operand translation crash
without requiring a cross assembler at test runtime.
AI-used-for: Regression tests
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
tests/qtest/xtensa-extreg-test.c | 81 ++++++++++++++++++++++++++++++++
tests/qtest/meson.build | 2 +
2 files changed, 83 insertions(+)
create mode 100644 tests/qtest/xtensa-extreg-test.c
diff --git a/tests/qtest/xtensa-extreg-test.c b/tests/qtest/xtensa-extreg-test.c
new file mode 100644
index 000000000000..10fde7461384
--- /dev/null
+++ b/tests/qtest/xtensa-extreg-test.c
@@ -0,0 +1,81 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * QTest for the RER/WER (external register) instructions of the dc233c core.
+ *
+ * The core's ISA tables used to describe RER and WER without operands, so
+ * translating them read uninitialised operands and crashed QEMU. The guest
+ * executes RER then WER on an unmapped external register address, then
+ * writes a marker to RAM, which the test polls.
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+
+#define MARKER_ADDR 0x100
+#define MARKER_VAL 0x123
+
+/*
+ * Guest ELF, assembled with xtensa-dc233c-elf-gcc (whose assembler has the
+ * same operand-less RER/WER, hence the raw bytes) at the reset vector
+ * 0xfe000000, then reduced to one PT_LOAD segment:
+ *
+ * _start:
+ * movi.n a2, 0x40
+ * .byte 0x30, 0x62, 0x40 # rer a3, a2
+ * .byte 0x30, 0x72, 0x40 # wer a3, a2
+ * movi a4, 0x100
+ * movi a5, 0x123
+ * s32i.n a5, a4, 0
+ * 1: j 1b
+ */
+static const uint8_t xtensa_guest[] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x5e, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xfe, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x14, 0x00, 0x00, 0x00,
+ 0x14, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
+ 0x4c, 0x02, 0x30, 0x62, 0x40, 0x30, 0x72, 0x40, 0x42, 0xa1, 0x00, 0x52,
+ 0xa1, 0x23, 0x59, 0x04, 0x06, 0xff, 0xff, 0x00,
+};
+
+static void test_extreg(void)
+{
+ g_autofree char *elf = NULL;
+ QTestState *qts;
+ int fd;
+
+ fd = g_file_open_tmp("qtest-xtensa-extreg-XXXXXX", &elf, NULL);
+ g_assert(fd != -1);
+ g_assert_cmpint(write(fd, xtensa_guest, sizeof(xtensa_guest)), ==,
+ sizeof(xtensa_guest));
+ close(fd);
+
+ qts = qtest_initf("-M sim -cpu dc233c -accel tcg -no-shutdown "
+ "-kernel %s", elf);
+ unlink(elf);
+
+ /* The harness enforces a timeout; stop if QEMU died */
+ while (qtest_readl(qts, MARKER_ADDR) != MARKER_VAL
+ && qtest_probe_child(qts)) {
+ g_usleep(10000);
+ }
+ g_assert_cmpint(qtest_readl(qts, MARKER_ADDR), ==, MARKER_VAL);
+
+ qtest_quit(qts);
+}
+
+int main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+
+ if (!qtest_has_accel("tcg")) {
+ g_test_skip("TCG not available");
+ return g_test_run();
+ }
+ qtest_add_func("xtensa/extreg", test_extreg);
+
+ return g_test_run();
+}
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 6e2938d913ef..c0de1df2530f 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -328,6 +328,8 @@ qtests_riscv64 = ['riscv-csr-test'] + \
['k230-ddr-test', 'k230-wdt-test', 'k230-gsdma-test', 'k230-decomp-gzip-test'] : []) + \
['milkv-duo-test']
+qtests_xtensa = ['xtensa-extreg-test']
+
qtests_hexagon = ['boot-serial-test', 'hexagon-config-test', 'l2vic-test',
'qcom-dsp-test',
'qct-qtimer-test']
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 23:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 23:02 [PATCH 0/2] target/xtensa: Describe RER and WER register operands Philippe Mathieu-Daudé
2026-11-19 23:02 ` [PATCH 1/2] " Philippe Mathieu-Daudé
2026-11-19 23:02 ` [PATCH 2/2] tests/qtest: Execute Xtensa external register instructions Philippe Mathieu-Daudé
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.