[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 37/44] Hexagon (decode): look for pkts with multiple insns at t
|
From: |
Taylor Simpson |
|
Subject: |
[PULL v2 37/44] Hexagon (decode): look for pkts with multiple insns at the same slot |
|
Date: |
Thu, 18 May 2023 13:04:04 -0700 |
From: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Each slot in a packet can be assigned to at most one instruction.
Although the assembler generally ought to enforce this rule, we better
be safe than sorry and also do some check to properly throw an "invalid
packet" exception on wrong slot assignments.
This should also make it easier to debug possible future errors caused
by missing updates to `find_iclass_slots()` rules in
target/hexagon/iclass.c.
Co-authored-by: Taylor Simpson <tsimpson@quicinc.com>
Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Reviewed-by: Taylor Simpson <tsimpson@quicinc.com>
Tested-by: Taylor Simpson <tsimpson@quicinc.com>
Message-Id:
<f8b829443523568823d062adf8bf6659bc6d4a3f.1683552984.git.quic_mathbern@quicinc.com>
---
target/hexagon/decode.c | 30 +++++++++++++++++++++++++++---
tests/tcg/hexagon/invalid-slots.c | 29 +++++++++++++++++++++++++++++
tests/tcg/hexagon/Makefile.target | 7 +++++++
3 files changed, 63 insertions(+), 3 deletions(-)
create mode 100644 tests/tcg/hexagon/invalid-slots.c
diff --git a/target/hexagon/decode.c b/target/hexagon/decode.c
index 041c8de751..946c55cc71 100644
--- a/target/hexagon/decode.c
+++ b/target/hexagon/decode.c
@@ -1,5 +1,5 @@
/*
- * Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights
Reserved.
+ * Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights
Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -797,7 +797,26 @@ static bool decode_parsebits_is_loopend(uint32_t
encoding32)
return bits == 0x2;
}
-static void
+static bool has_valid_slot_assignment(Packet *pkt)
+{
+ int used_slots = 0;
+ for (int i = 0; i < pkt->num_insns; i++) {
+ int slot_mask;
+ Insn *insn = &pkt->insn[i];
+ if (decode_opcode_ends_loop(insn->opcode)) {
+ /* We overload slot 0 for endloop. */
+ continue;
+ }
+ slot_mask = 1 << insn->slot;
+ if (used_slots & slot_mask) {
+ return false;
+ }
+ used_slots |= slot_mask;
+ }
+ return true;
+}
+
+static bool
decode_set_slot_number(Packet *pkt)
{
int slot;
@@ -886,6 +905,8 @@ decode_set_slot_number(Packet *pkt)
/* Then push it to slot0 */
pkt->insn[slot1_iidx].slot = 0;
}
+
+ return has_valid_slot_assignment(pkt);
}
/*
@@ -961,8 +982,11 @@ int decode_packet(int max_words, const uint32_t *words,
Packet *pkt,
decode_apply_extenders(pkt);
if (!disas_only) {
decode_remove_extenders(pkt);
+ if (!decode_set_slot_number(pkt)) {
+ /* Invalid packet */
+ return 0;
+ }
}
- decode_set_slot_number(pkt);
decode_fill_newvalue_regno(pkt);
if (pkt->pkt_has_hvx) {
diff --git a/tests/tcg/hexagon/invalid-slots.c
b/tests/tcg/hexagon/invalid-slots.c
new file mode 100644
index 0000000000..366ce4f42f
--- /dev/null
+++ b/tests/tcg/hexagon/invalid-slots.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+char mem[8] __attribute__((aligned(8)));
+
+int main()
+{
+ asm volatile(
+ "r0 = #mem\n"
+ /* Invalid packet (2 instructions at slot 0): */
+ ".word 0xa1804100\n" /* { memw(r0) = r1; */
+ ".word 0x28032804\n" /* r3 = #0; r4 = #0 } */
+ : : : "r0", "r3", "r4", "memory");
+ return 0;
+}
diff --git a/tests/tcg/hexagon/Makefile.target
b/tests/tcg/hexagon/Makefile.target
index 6109a7ed10..890cceed5d 100644
--- a/tests/tcg/hexagon/Makefile.target
+++ b/tests/tcg/hexagon/Makefile.target
@@ -50,6 +50,13 @@ HEX_TESTS += vector_add_int
HEX_TESTS += scatter_gather
HEX_TESTS += hvx_misc
HEX_TESTS += hvx_histogram
+HEX_TESTS += invalid-slots
+
+run-and-check-exception = $(call run-test,$2,$3 2>$2.stderr; \
+ test $$? -eq 1 && grep -q "exception $(strip $1)" $2.stderr)
+
+run-invalid-slots: invalid-slots
+ $(call run-and-check-exception, 0x15, $@, $(QEMU) $(QEMU_OPTS) $<)
HEX_TESTS += test_abs
HEX_TESTS += test_bitcnt
--
2.25.1
- [PULL v2 17/44] Hexagon (target/hexagon) Clean up pred_written usage, (continued)
- [PULL v2 17/44] Hexagon (target/hexagon) Clean up pred_written usage, Taylor Simpson, 2023/05/18
- [PULL v2 15/44] Hexagon (target/hexagon) Remove log_reg_write from op_helper.[ch], Taylor Simpson, 2023/05/18
- [PULL v2 39/44] gdbstub: only send stop-reply packets when allowed to, Taylor Simpson, 2023/05/18
- [PULL v2 06/44] Hexagon (target/hexagon) Add v69 HVX instructions, Taylor Simpson, 2023/05/18
- [PULL v2 12/44] Hexagon (target/hexagon) Add overrides for loop setup instructions, Taylor Simpson, 2023/05/18
- [PULL v2 22/44] Hexagon (target/hexagon) Short-circuit packet HVX writes, Taylor Simpson, 2023/05/18
- [PULL v2 26/44] Hexagon (target/hexagon) Move new_value to DisasContext, Taylor Simpson, 2023/05/18
- [PULL v2 34/44] Hexagon: list available CPUs with `-cpu help`, Taylor Simpson, 2023/05/18
- [PULL v2 14/44] Hexagon (target/hexagon) Add overrides for clr[tf]new, Taylor Simpson, 2023/05/18
- [PULL v2 03/44] Hexagon (tests/tcg/hexagon) Add v68 scalar tests, Taylor Simpson, 2023/05/18
- [PULL v2 37/44] Hexagon (decode): look for pkts with multiple insns at the same slot,
Taylor Simpson <=
- [PULL v2 09/44] Hexagon (tests/tcg/hexagon) Add v73 scalar tests, Taylor Simpson, 2023/05/18
- [PULL v2 02/44] Hexagon (target/hexagon) Add v68 scalar instructions, Taylor Simpson, 2023/05/18
- [PULL v2 07/44] Hexagon (tests/tcg/hexagon) Add v69 HVX tests, Taylor Simpson, 2023/05/18
- [PULL v2 11/44] Hexagon (target/hexagon) Add DisasContext arg to gen_log_reg_write, Taylor Simpson, 2023/05/18
- [PULL v2 24/44] Hexagon (target/hexagon) Add overrides for disabled idef-parser insns, Taylor Simpson, 2023/05/18
- [PULL v2 20/44] Hexagon (target/hexagon) Short-circuit packet register writes, Taylor Simpson, 2023/05/18
- [PULL v2 23/44] Hexagon (target/hexagon) Short-circuit more HVX single instruction packets, Taylor Simpson, 2023/05/18
- [PULL v2 21/44] Hexagon (target/hexagon) Short-circuit packet predicate writes, Taylor Simpson, 2023/05/18
- [PULL v2 18/44] Hexagon (target/hexagon) Don't overlap dest writes with source reads, Taylor Simpson, 2023/05/18
- [PULL v2 25/44] Hexagon (target/hexagon) Make special new_value for USR, Taylor Simpson, 2023/05/18