target/hexagon: fix allocframe FRAMEKEY scrambling
PATCH v2 1/1 target/hexagon: fix allocframe FRAMEKEY scrambling
The architecture scrambles only the LR word of the {FP, LR} frame that allocframe stores. With the idef parser enabled, fFRAME_SCRAMBLE built the XOR key with FRAMEKEY in both halves of the 64-bit value, so the stored FP was scrambled as well.
deallocframe is also parser-generated and applies the same incorrect transform a second time, which masks the error. dealloc_return uses the hand-written TCG implementation that correctly descrambles only LR, so it leaves FP corrupt when returning from a frame allocated by the parser.
Add a regression test that sets a nonzero FRAMEKEY, allocates a frame, and returns through dealloc_return to validate the restored FP.
Uncovered by testing some boot images using QuRT.
--- target/hexagon/idef-parser/parser-helpers.c | 2 +- tests/tcg/hexagon/framekey.c | 54 +++++++++++++++++++++ tests/tcg/hexagon/meson.build | 1 + 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/framekey.c
target/hexagon/idef-parser/parser-helpers.c +1 -1
@@ -1989,7 +1989,7 @@ HexValue gen_rvalue_fscr(Context *c, YYLTYPE *locp, HexValue *value) *value =gen_rvalue_extend (c, locp, value);OUT (c, locp,"gen_read_reg(" , &frame_key,", HEX_REG_FRAMEKEY);\n" );OUT (c, locp,"tcg_gen_concat_i32_i64(" , - &key,", " , &frame_key,", " , &frame_key,");\n" ); + &key,", tcg_constant_tl(0), " , &frame_key,");\n" );OUT (c, locp,"tcg_gen_xor_i64(" , &res,", " , value,", " , &key,");\n" );return res; }
tests/tcg/hexagon/framekey.c new file +54 -0
54 lines not on this page · raw message
tests/tcg/hexagon/meson.build +1 -0
@@ -68,6 +68,7 @@ tests += { 'overflow.c': {'cflags': cflags, 'exe_name': 'hex-overflow'}, 'preg_alias.c': {'cflags': cflags}, 'dual_stores.c': {'cflags': cflags}, + 'framekey.c': {'cflags': cflags}, 'multi_result.c': {'cflags': cflags}, 'mem_noshuf.c': {'cflags': cflags}, 'mem_noshuf_exception.c': {'cflags': cflags},
Signature · 1 line
2.34.1
Quoted 16 lines · Brian Cain
The architecture scrambles only the LR word of the {FP, LR} frame that allocframe stores. With the idef parser enabled,
fFRAME_SCRAMBLEbuilt the XOR key with FRAMEKEY in both halves of the 64-bit value, so the stored FP was scrambled as well.deallocframe is also parser-generated and applies the same incorrect transform a second time, which masks the error.
dealloc_returnuses the hand-written TCG implementation that correctly descrambles only LR, so it leaves FP corrupt when returning from a frame allocated by the parser.Add a regression test that sets a nonzero FRAMEKEY, allocates a frame, and returns through
dealloc_returnto validate the restored FP.Uncovered by testing some boot images using QuRT.
Quoted 8 lines
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/idef-parser/parser-helpers.c | 2 +- tests/tcg/hexagon/framekey.c | 54 +++++++++++++++++++++ tests/tcg/hexagon/meson.build | 1 + 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/framekey.c