[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/31] tcg/loongarch64: Implement necessary relocation operations
From: |
Richard Henderson |
Subject: |
[PULL 07/31] tcg/loongarch64: Implement necessary relocation operations |
Date: |
Tue, 21 Dec 2021 08:47:13 -0800 |
From: WANG Xuerui <git@xen0n.name>
Signed-off-by: WANG Xuerui <git@xen0n.name>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20211221054105.178795-8-git@xen0n.name>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/loongarch64/tcg-target.c.inc | 66 ++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc
index 1c1b798c06..a88ba9a253 100644
--- a/tcg/loongarch64/tcg-target.c.inc
+++ b/tcg/loongarch64/tcg-target.c.inc
@@ -168,3 +168,69 @@ static bool tcg_target_const_match(int64_t val, TCGType
type, int ct)
}
return false;
}
+
+/*
+ * Relocations
+ */
+
+/*
+ * Relocation records defined in LoongArch ELF psABI v1.00 is way too
+ * complicated; a whopping stack machine is needed to stuff the fields, at
+ * the very least one SOP_PUSH and one SOP_POP (of the correct format) are
+ * needed.
+ *
+ * Hence, define our own simpler relocation types. Numbers are chosen as to
+ * not collide with potential future additions to the true ELF relocation
+ * type enum.
+ */
+
+/* Field Sk16, shifted right by 2; suitable for conditional jumps */
+#define R_LOONGARCH_BR_SK16 256
+/* Field Sd10k16, shifted right by 2; suitable for B and BL */
+#define R_LOONGARCH_BR_SD10K16 257
+
+static bool reloc_br_sk16(tcg_insn_unit *src_rw, const tcg_insn_unit *target)
+{
+ const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
+ intptr_t offset = (intptr_t)target - (intptr_t)src_rx;
+
+ tcg_debug_assert((offset & 3) == 0);
+ offset >>= 2;
+ if (offset == sextreg(offset, 0, 16)) {
+ *src_rw = deposit64(*src_rw, 10, 16, offset);
+ return true;
+ }
+
+ return false;
+}
+
+static bool reloc_br_sd10k16(tcg_insn_unit *src_rw,
+ const tcg_insn_unit *target)
+{
+ const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw);
+ intptr_t offset = (intptr_t)target - (intptr_t)src_rx;
+
+ tcg_debug_assert((offset & 3) == 0);
+ offset >>= 2;
+ if (offset == sextreg(offset, 0, 26)) {
+ *src_rw = deposit64(*src_rw, 0, 10, offset >> 16); /* slot d10 */
+ *src_rw = deposit64(*src_rw, 10, 16, offset); /* slot k16 */
+ return true;
+ }
+
+ return false;
+}
+
+static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
+ intptr_t value, intptr_t addend)
+{
+ tcg_debug_assert(addend == 0);
+ switch (type) {
+ case R_LOONGARCH_BR_SK16:
+ return reloc_br_sk16(code_ptr, (tcg_insn_unit *)value);
+ case R_LOONGARCH_BR_SD10K16:
+ return reloc_br_sd10k16(code_ptr, (tcg_insn_unit *)value);
+ default:
+ g_assert_not_reached();
+ }
+}
--
2.25.1
- [PULL 00/31] tcg/loongarch64: New tcg backend, Richard Henderson, 2021/12/21
- [PULL 01/31] elf: Add machine type value for LoongArch, Richard Henderson, 2021/12/21
- [PULL 02/31] MAINTAINERS: Add tcg/loongarch64 entry with myself as maintainer, Richard Henderson, 2021/12/21
- [PULL 03/31] tcg/loongarch64: Add the tcg-target.h file, Richard Henderson, 2021/12/21
- [PULL 05/31] tcg/loongarch64: Add register names, allocation order and input/output sets, Richard Henderson, 2021/12/21
- [PULL 09/31] tcg/loongarch64: Implement tcg_out_mov and tcg_out_movi, Richard Henderson, 2021/12/21
- [PULL 04/31] tcg/loongarch64: Add generated instruction opcodes and encoding helpers, Richard Henderson, 2021/12/21
- [PULL 07/31] tcg/loongarch64: Implement necessary relocation operations,
Richard Henderson <=
- [PULL 06/31] tcg/loongarch64: Define the operand constraints, Richard Henderson, 2021/12/21
- [PULL 14/31] tcg/loongarch64: Implement bswap{16,32,64} ops, Richard Henderson, 2021/12/21
- [PULL 13/31] tcg/loongarch64: Implement deposit/extract ops, Richard Henderson, 2021/12/21
- [PULL 12/31] tcg/loongarch64: Implement not/and/or/xor/nor/andc/orc ops, Richard Henderson, 2021/12/21
- [PULL 15/31] tcg/loongarch64: Implement clz/ctz ops, Richard Henderson, 2021/12/21
- [PULL 16/31] tcg/loongarch64: Implement shl/shr/sar/rotl/rotr ops, Richard Henderson, 2021/12/21
- [PULL 17/31] tcg/loongarch64: Implement add/sub ops, Richard Henderson, 2021/12/21
- [PULL 18/31] tcg/loongarch64: Implement mul/mulsh/muluh/div/divu/rem/remu ops, Richard Henderson, 2021/12/21
- [PULL 19/31] tcg/loongarch64: Implement br/brcond ops, Richard Henderson, 2021/12/21
- [PULL 11/31] tcg/loongarch64: Implement sign-/zero-extension ops, Richard Henderson, 2021/12/21