diff options
author | 2023-06-16 17:47:01 +0000 | |
---|---|---|
committer | 2023-06-17 00:19:50 +0000 | |
commit | 112c70b6700a042d7152b0c2bf5094464a158931 (patch) | |
tree | 259d58012408e1350595b98262f03e17d08a39d9 | |
parent | a6b1208db4c19f6cb6bf4367ec5a678f1db69efd (diff) |
Revert "riscv64: rewrite `CreateTrampoline` using assembler to generate code."
This reverts commit d0918409aad47edaf912e1c3d0e8e8258836ab8b.
Reason for revert: Observing a SIGILL in zygote64 after this patch.
Change-Id: I145becde7eb0da3bc44ea0d3df9ffea48139311d
-rw-r--r-- | compiler/trampolines/trampoline_compiler.cc | 69 | ||||
-rw-r--r-- | compiler/utils/riscv64/assembler_riscv64.h | 2 |
2 files changed, 41 insertions, 30 deletions
diff --git a/compiler/trampolines/trampoline_compiler.cc b/compiler/trampolines/trampoline_compiler.cc index 3821399e61..e542763f82 100644 --- a/compiler/trampolines/trampoline_compiler.cc +++ b/compiler/trampolines/trampoline_compiler.cc @@ -28,10 +28,6 @@ #include "utils/arm64/assembler_arm64.h" #endif -#ifdef ART_ENABLE_CODEGEN_riscv64 -#include "utils/riscv64/assembler_riscv64.h" -#endif - #ifdef ART_ENABLE_CODEGEN_x86 #include "utils/x86/assembler_x86.h" #endif @@ -133,33 +129,48 @@ static std::unique_ptr<const std::vector<uint8_t>> CreateTrampoline( #ifdef ART_ENABLE_CODEGEN_riscv64 namespace riscv64 { -static std::unique_ptr<const std::vector<uint8_t>> CreateTrampoline(ArenaAllocator* allocator, - EntryPointCallingConvention abi, - ThreadOffset64 offset) { - Riscv64Assembler assembler(allocator); - - switch (abi) { - case kInterpreterAbi: // Thread* is first argument (A0) in interpreter ABI. - __ Loadd(TMP, A0, offset.Int32Value()); - __ Jr(TMP); - break; - case kJniAbi: // Load via Thread* held in JNIEnv* in first argument (A0). - // TODO(riscv64): implement this. - __ Unimp(); - break; - case kQuickAbi: // TR holds Thread*. - __ Loadd(TMP, TR, offset.Int32Value()); - __ Jr(TMP); - break; - } +static std::unique_ptr<const std::vector<uint8_t>> CreateTrampoline( + ArenaAllocator* /*allocator*/, EntryPointCallingConvention abi, ThreadOffset64 offset) { + if (abi == kJniAbi) { + // TODO(riscv64): implement this properly once we have macro-assembler for RISC-V. + std::unique_ptr<std::vector<uint8_t>> entry_stub(new std::vector<uint8_t>(2)); + uint8_t* bytes = entry_stub->data(); + + // 0000 unimp + bytes[0] = 0x00; + bytes[1] = 0x00; + + return std::move(entry_stub); + } else { + CHECK_LE(offset.Int32Value(), 0x7ff); + uint8_t offset_hi = (offset.Int32Value() & 0x7ff) >> 4; + uint8_t offset_lo = (offset.Int32Value() & 0xf) << 4; + + std::unique_ptr<std::vector<uint8_t>> entry_stub(new std::vector<uint8_t>(6)); + uint8_t* bytes = entry_stub->data(); + + if (abi == kInterpreterAbi) { + // Thread* is first argument (A0) in interpreter ABI. + // xxx53283 ld t0, xxx(a0) + bytes[0] = 0x83; + bytes[1] = 0x32; + bytes[2] = offset_lo | 0x05; + bytes[3] = offset_hi; + } else { + // abi == kQuickAbi: TR holds Thread*. + // xxx4b283 ld t0, xxx(s1) + bytes[0] = 0x83; + bytes[1] = 0xb2; + bytes[2] = offset_lo | 0x04; + bytes[3] = offset_hi; + } - __ FinalizeCode(); - size_t cs = __ CodeSize(); - std::unique_ptr<std::vector<uint8_t>> entry_stub(new std::vector<uint8_t>(cs)); - MemoryRegion code(entry_stub->data(), entry_stub->size()); - __ FinalizeInstructions(code); + // 8282 jr t0 + bytes[4] = 0x82; + bytes[5] = 0x82; - return std::move(entry_stub); + return std::move(entry_stub); + } } } // namespace riscv64 #endif // ART_ENABLE_CODEGEN_riscv64 diff --git a/compiler/utils/riscv64/assembler_riscv64.h b/compiler/utils/riscv64/assembler_riscv64.h index 9cb6519601..d94433f184 100644 --- a/compiler/utils/riscv64/assembler_riscv64.h +++ b/compiler/utils/riscv64/assembler_riscv64.h @@ -66,7 +66,7 @@ class Riscv64Label : public Label { public: Riscv64Label() : prev_branch_id_(kNoPrevBranchId) {} - Riscv64Label(Riscv64Label&& src) noexcept + Riscv64Label(Riscv64Label&& src) : Label(std::move(src)), prev_branch_id_(src.prev_branch_id_) {} private: |