Skip to content

Commit

Permalink
[RISCV64] Add MacroAssemblerRISCV64 operations with patchable elements
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=234635

Patch by Zan Dobersek <zdobersek@igalia.com> on 2021-12-28
Reviewed by Yusuke Suzuki.

Add MacroAssemblerRISCV64 implementations for operations that generate
patchable code sections. This covers moves, stores and branches.

For moves and stores of pointer values, the patchable section is
achieved by generating a immediate loader instruction sequence with all
the placeholder instructions (nops) included.

Some methods that had their noop implementations provided until now have
been removed since they are not necessary anymore.

* assembler/MacroAssemblerRISCV64.h:
(JSC::MacroAssemblerRISCV64::moveWithPatch):
(JSC::MacroAssemblerRISCV64::storePtrWithPatch):
(JSC::MacroAssemblerRISCV64::branch32WithPatch):
(JSC::MacroAssemblerRISCV64::branchPtrWithPatch):
(JSC::MacroAssemblerRISCV64::patchableBranch64):


Canonical link: https://commits.webkit.org/245601@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287466 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
commit-queue@webkit.org committed Dec 28, 2021
1 parent 79bf357 commit a42b9ab
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 12 deletions.
24 changes: 24 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,27 @@
2021-12-28 Zan Dobersek <zdobersek@igalia.com>

[RISCV64] Add MacroAssemblerRISCV64 operations with patchable elements
https://bugs.webkit.org/show_bug.cgi?id=234635

Reviewed by Yusuke Suzuki.

Add MacroAssemblerRISCV64 implementations for operations that generate
patchable code sections. This covers moves, stores and branches.

For moves and stores of pointer values, the patchable section is
achieved by generating a immediate loader instruction sequence with all
the placeholder instructions (nops) included.

Some methods that had their noop implementations provided until now have
been removed since they are not necessary anymore.

* assembler/MacroAssemblerRISCV64.h:
(JSC::MacroAssemblerRISCV64::moveWithPatch):
(JSC::MacroAssemblerRISCV64::storePtrWithPatch):
(JSC::MacroAssemblerRISCV64::branch32WithPatch):
(JSC::MacroAssemblerRISCV64::branchPtrWithPatch):
(JSC::MacroAssemblerRISCV64::patchableBranch64):

2021-12-28 Zan Dobersek <zdobersek@igalia.com>

[RISCV64] Enable signal-based VM traps for CPU(RISCV64)
Expand Down
76 changes: 64 additions & 12 deletions Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.h
Expand Up @@ -1033,11 +1033,6 @@ class MacroAssemblerRISCV64 : public AbstractMacroAssembler<Assembler> {
store32(src2, Address(dest, offset.m_value + 4));
}

MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(load64WithAddressOffsetPatch, DataLabel32);
MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(load64WithCompactAddressOffsetPatch, DataLabelCompact);
MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(store64WithAddressOffsetPatch, DataLabel32);
MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(storePtrWithPatch, DataLabelPtr);

void zeroExtend8To32(RegisterID src, RegisterID dest)
{
m_assembler.slliInsn<56>(dest, src);
Expand Down Expand Up @@ -1933,15 +1928,72 @@ class MacroAssemblerRISCV64 : public AbstractMacroAssembler<Assembler> {

MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchPtr, Jump);

MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(moveWithPatch, DataLabel32);
MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(moveWithPatch, DataLabelPtr);
DataLabel32 moveWithPatch(TrustedImm32 imm, RegisterID dest)
{
RISCV64Assembler::ImmediateLoader imml(RISCV64Assembler::ImmediateLoader::Placeholder, imm.m_value);

DataLabel32 label(this);
imml.moveInto(m_assembler, dest);
return label;
}

DataLabelPtr moveWithPatch(TrustedImmPtr imm, RegisterID dest)
{
RISCV64Assembler::ImmediateLoader imml(RISCV64Assembler::ImmediateLoader::Placeholder, int64_t(imm.asIntptr()));

DataLabelPtr label(this);
imml.moveInto(m_assembler, dest);
return label;
}

DataLabelPtr storePtrWithPatch(TrustedImmPtr initialValue, Address address)
{
auto temp = temps<Data, Memory>();
RISCV64Assembler::ImmediateLoader imml(RISCV64Assembler::ImmediateLoader::Placeholder, int64_t(initialValue.asIntptr()));
DataLabelPtr label(this);
imml.moveInto(m_assembler, temp.data());

auto resolution = resolveAddress(address, temp.memory());
m_assembler.sdInsn(resolution.base, temp.data(), Imm::S(resolution.offset));
return label;
}

DataLabelPtr storePtrWithPatch(Address address)
{
return storePtrWithPatch(TrustedImmPtr(nullptr), address);
}

Jump branch32WithPatch(RelationalCondition cond, Address address, DataLabel32& dataLabel, TrustedImm32 initialRightValue = TrustedImm32(0))
{
auto temp = temps<Data, Memory>();
auto resolution = resolveAddress(address, temp.memory());
m_assembler.lwInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));

dataLabel = moveWithPatch(initialRightValue, temp.data());
return makeBranch(cond, temp.memory(), temp.data());
}

Jump branchPtrWithPatch(RelationalCondition cond, Address address, DataLabelPtr& dataLabel, TrustedImmPtr initialRightValue = TrustedImmPtr(nullptr))
{
auto temp = temps<Data, Memory>();
auto resolution = resolveAddress(address, temp.memory());
m_assembler.ldInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));

dataLabel = moveWithPatch(initialRightValue, temp.data());
return makeBranch(cond, temp.memory(), temp.data());
}

MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branch32WithPatch, Jump);
MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchPtrWithPatch, Jump);
Jump branchPtrWithPatch(RelationalCondition cond, RegisterID lhs, DataLabelPtr& dataLabel, TrustedImmPtr initialRightValue = TrustedImmPtr(nullptr))
{
auto temp = temps<Data>();
dataLabel = moveWithPatch(initialRightValue, temp.data());
return makeBranch(cond, lhs, temp.data());
}

MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(patchableBranch8, PatchableJump);
MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(patchableBranch32, PatchableJump);
MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(patchableBranch64, PatchableJump);
PatchableJump patchableBranch64(RelationalCondition cond, RegisterID left, RegisterID right)
{
return PatchableJump(branch64(cond, left, right));
}

MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchFloat, Jump);
MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchDouble, Jump);
Expand Down

0 comments on commit a42b9ab

Please sign in to comment.