target/xtensa: Describe RER and WER register operands
cover target/xtensa: Describe RER and WER register operands
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
Signature · 1 line
2.55.0
PATCH 1/2 target/xtensa: Describe RER and WER register operands
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.
--- 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(-)
target/xtensa/core-dc233c/xtensa-modules.c.inc +12 -2
@@ -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 },
target/xtensa/core-dsp3400/xtensa-modules.c.inc +12 -2
@@ -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 },
target/xtensa/core-lx106/xtensa-modules.c.inc +12 -2
@@ -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 } };
Signature · 1 line
2.55.0
PATCH 2/2 tests/qtest: Execute Xtensa external register instructions
In reply to 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
--- 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
tests/qtest/xtensa-extreg-test.c new file +81 -0
@@ -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 (); +}
tests/qtest/meson.build +2 -0
@@ -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']
Signature · 1 line
2.55.0