When a non-duplex encoding (parse_bits != 0) fails both decode_normal() and decode_hvx(), the decoder hit an unreachable. Instead, handle the decode failure and raise an exception.
Signed-off-by: Brian Cain <[email protected]> --- target/hexagon/decode.c | 3 ++- tests/tcg/hexagon/invalid-encoding.c | 20 ++++++++++++++++++++ tests/tcg/hexagon/Makefile.target | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/invalid-encoding.c diff --git a/target/hexagon/decode.c b/target/hexagon/decode.c index 90499fc320..ebb4e02a17 100644 --- a/target/hexagon/decode.c +++ b/target/hexagon/decode.c @@ -489,7 +489,8 @@ decode_insns(DisasContext *ctx, Insn *insn, uint32_t encoding) insn->iclass = iclass_bits(encoding); return 1; } - g_assert_not_reached(); + /* Invalid non-duplex encoding */ + return 0; } else { uint32_t iclass = get_duplex_iclass(encoding); unsigned int slot0_subinsn = get_slot0_subinsn(encoding); diff --git a/tests/tcg/hexagon/invalid-encoding.c b/tests/tcg/hexagon/invalid-encoding.c new file mode 100644 index 0000000000..efe914b4e4 --- /dev/null +++ b/tests/tcg/hexagon/invalid-encoding.c @@ -0,0 +1,20 @@ +/* + * Test that invalid non-duplex encodings are properly rejected. + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +/* + * The encoding 0xffffc000 has parse bits [15:14] = 0b11, making it a + * non-duplex instruction and packet end. The remaining bits do not match + * any valid normal or HVX instruction encoding, so this should raise SIGILL. + */ + +int main() +{ + asm volatile( + ".word 0xffffc000\n" + : : : "memory"); + return 0; +} diff --git a/tests/tcg/hexagon/Makefile.target b/tests/tcg/hexagon/Makefile.target index 7199e29a30..79ebfd56ce 100644 --- a/tests/tcg/hexagon/Makefile.target +++ b/tests/tcg/hexagon/Makefile.target @@ -53,6 +53,7 @@ HEX_TESTS += hvx_histogram HEX_TESTS += invalid-slots HEX_TESTS += invalid-duplex HEX_TESTS += invalid-dups +HEX_TESTS += invalid-encoding HEX_TESTS += unaligned_pc run-and-check-exception = $(call run-test,$2,$3 2>$2.stderr; \ @@ -74,6 +75,11 @@ run-invalid-dups: invalid-dups $(QEMU) $(QEMU_OPTS) $< ; test $$? -eq 132, \ TEST, invalid-dups on $(TARGET_NAME)) +run-invalid-encoding: invalid-encoding + $(call quiet-command, \ + $(QEMU) $(QEMU_OPTS) $< ; test $$? -eq 132, \ + TEST, invalid-encoding on $(TARGET_NAME)) + HEX_TESTS += test_abs HEX_TESTS += test_bitcnt HEX_TESTS += test_bitsplit -- 2.34.1
