Browse Source

target/hexagon: Return decode failure for invalid non-duplex encodings

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.

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com>
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
master
Brian Cain 2 months ago
parent
commit
b0129a14a4
  1. 3
      target/hexagon/decode.c
  2. 25
      tests/tcg/hexagon/invalid-encoding.c

3
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);

25
tests/tcg/hexagon/invalid-encoding.c

@ -65,6 +65,30 @@ static int test_invalid_duplex(void)
return sig;
}
/*
* Invalid non-duplex encoding:
* 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.
*/
static int test_invalid_nonduplex(void)
{
int sig;
asm volatile(
"r0 = #0\n"
"r1 = ##1f\n"
"memw(%1) = r1\n"
".word 0xffffc000\n"
"1:\n"
"%0 = r0\n"
: "=r"(sig)
: "r"(&resume_pc)
: "r0", "r1", "memory");
return sig;
}
int main()
{
struct sigaction act;
@ -75,6 +99,7 @@ int main()
assert(sigaction(SIGILL, &act, NULL) == 0);
assert(test_invalid_duplex() == SIGILL);
assert(test_invalid_nonduplex() == SIGILL);
puts("PASS");
return EXIT_SUCCESS;

Loading…
Cancel
Save