1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ecmascript/compiler/assembler/aarch64/extend_assembler.h"
17
18 #include "ecmascript/frames.h"
19
20 namespace panda::ecmascript::aarch64 {
21 Register ExtendedAssembler::ghcJSCallDispacherArgs_[JS_CALL_DISPATCHER_ARGS_COUNT] =
22 { X19, FP, X20, X21, X22, X23, X24, X25, X26 };
23 Register ExtendedAssembler::cppJSCallDispacherArgs_[JS_CALL_DISPATCHER_ARGS_COUNT] =
24 { X0, FP, X1, X2, X3, X4, X5, X6, X7 };
25
CalleeSave()26 void ExtendedAssembler::CalleeSave()
27 {
28 Register sp(SP);
29 Stp(Register(X27), Register(X28), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
30 Stp(Register(X25), Register(X26), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
31 Stp(Register(X23), Register(X24), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
32 Stp(Register(X21), Register(X22), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
33 Stp(Register(X19), Register(X20), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
34
35 Stp(VectorRegister(v14), VectorRegister(v15), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
36 Stp(VectorRegister(v12), VectorRegister(v13), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
37 Stp(VectorRegister(v10), VectorRegister(v11), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
38 Stp(VectorRegister(v8), VectorRegister(v9), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
39 }
40
CalleeRestore()41 void ExtendedAssembler::CalleeRestore()
42 {
43 Register sp(SP);
44 Ldp(VectorRegister(v8), VectorRegister(v9), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
45 Ldp(VectorRegister(v10), VectorRegister(v11), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
46 Ldp(VectorRegister(v12), VectorRegister(v13), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
47 Ldp(VectorRegister(v14), VectorRegister(v15), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
48 Ldp(Register(X19), Register(X20), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
49 Ldp(Register(X21), Register(X22), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
50 Ldp(Register(X23), Register(X24), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
51 Ldp(Register(X25), Register(X26), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
52 Ldp(Register(X27), Register(X28), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
53 }
54
CallAssemblerStub(int id,bool isTail)55 void ExtendedAssembler::CallAssemblerStub(int id, bool isTail)
56 {
57 Label *target = module_->GetFunctionLabel(id);
58 isTail ? B(target) : Bl(target);
59 }
60
BindAssemblerStub(int id)61 void ExtendedAssembler::BindAssemblerStub(int id)
62 {
63 Label *target = module_->GetFunctionLabel(id);
64 Bind(target);
65 auto callSigns = module_->GetCSigns();
66 auto cs = callSigns[id];
67 isGhcCallingConv_ = cs->GetCallConv() == CallSignature::CallConv::GHCCallConv;
68 }
69
PushFpAndLr()70 void ExtendedAssembler::PushFpAndLr()
71 {
72 Register sp(SP);
73 Stp(Register(X29), Register(X30), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
74 }
75
SaveFpAndLr()76 void ExtendedAssembler::SaveFpAndLr()
77 {
78 Register sp(SP);
79 Stp(Register(X29), Register(X30), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
80 Mov(Register(X29), Register(SP));
81 }
82
RestoreFpAndLr()83 void ExtendedAssembler::RestoreFpAndLr()
84 {
85 Register sp(SP);
86 Ldp(Register(X29), Register(X30), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
87 }
88
PushLrAndFp()89 void ExtendedAssembler::PushLrAndFp()
90 {
91 Register sp(SP);
92 Stp(Register(X30), Register(X29), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
93 }
94
SaveLrAndFp()95 void ExtendedAssembler::SaveLrAndFp()
96 {
97 Register sp(SP);
98 Stp(Register(X30), Register(X29), MemoryOperand(sp, -PAIR_SLOT_SIZE, PREINDEX));
99 Mov(Register(X29), Register(SP));
100 }
101
RestoreLrAndFp()102 void ExtendedAssembler::RestoreLrAndFp()
103 {
104 Register sp(SP);
105 Ldp(Register(X30), Register(X29), MemoryOperand(sp, PAIR_SLOT_SIZE, POSTINDEX));
106 }
107
PushArgc(int32_t argc,Register op,Register fp)108 void ExtendedAssembler::PushArgc(int32_t argc, Register op, Register fp)
109 {
110 Mov(op, Immediate(JSTaggedValue(argc).GetRawData()));
111 Str(op, MemoryOperand(fp, -8, PREINDEX)); // -8: 8 bytes
112 }
113
PushArgc(Register argc,Register op,Register fp)114 void ExtendedAssembler::PushArgc(Register argc, Register op, Register fp)
115 {
116 Orr(op, argc, LogicalImmediate::Create(JSTaggedValue::TAG_INT, RegXSize));
117 Str(op, MemoryOperand(fp, -8, PREINDEX)); // -8: 8 bytes
118 }
119
Align16(Register fp)120 void ExtendedAssembler::Align16(Register fp)
121 {
122 Label aligned;
123 Tst(fp, LogicalImmediate::Create(0xf, RegXSize)); // 0xf: 0x1111
124 B(Condition::EQ, &aligned);
125 // 8: frame slot size
126 Sub(fp, fp, Immediate(8));
127 Bind(&aligned);
128 }
129 } // namespace panda::ecmascript::aarch64