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/x64/extended_assembler_x64.h"
17 #include "ecmascript/deoptimizer/calleeReg.h"
18 #include "ecmascript/frames.h"
19
20 namespace panda::ecmascript::x64 {
21 Register ExtendedAssembler::ghcJSCallDispacherArgs_[JS_CALL_DISPATCHER_ARGS_COUNT] =
22 { r13, rbp, r12, rbx, r14, rsi, rdi, r8, r9 };
23 Register ExtendedAssembler::cppJSCallDispacherArgs_[JS_CALL_DISPATCHER_ARGS_COUNT] =
24 { rdi, rbp, rsi, rdx, rcx, r8, r9, rInvalid, rInvalid };
25
PushAlignBytes()26 void ExtendedAssembler::PushAlignBytes()
27 {
28 Subq(8, rsp); // 8: 8 bytes
29 }
30
PopAlignBytes()31 void ExtendedAssembler::PopAlignBytes()
32 {
33 Addq(8, rsp); // 8: 8 bytes
34 }
35
36 // c++ calling convention
PushCppCalleeSaveRegisters()37 void ExtendedAssembler::PushCppCalleeSaveRegisters()
38 {
39 Pushq(r12);
40 Pushq(r13);
41 Pushq(r14);
42 Pushq(r15);
43 Pushq(rbx);
44 }
45
PopCppCalleeSaveRegisters()46 void ExtendedAssembler::PopCppCalleeSaveRegisters()
47 {
48 Popq(rbx);
49 Popq(r15);
50 Popq(r14);
51 Popq(r13);
52 Popq(r12);
53 }
54
UpdateCalleeSaveRegisters()55 void ExtendedAssembler::UpdateCalleeSaveRegisters()
56 {
57 Addq(8 * 5, rsp); // 8: 8 bytes, 5: number of CalleeSaveRegisters
58 }
59
PushGhcCalleeSaveRegisters()60 void ExtendedAssembler::PushGhcCalleeSaveRegisters()
61 {
62 Pushq(r10);
63 Pushq(r11);
64 Pushq(r12);
65 Pushq(r13);
66 Pushq(r15);
67 }
68
PopGhcCalleeSaveRegisters()69 void ExtendedAssembler::PopGhcCalleeSaveRegisters()
70 {
71 Popq(r15);
72 Popq(r13);
73 Popq(r12);
74 Popq(r11);
75 Popq(r10);
76 }
77
CallAssemblerStub(int id,bool isTail)78 void ExtendedAssembler::CallAssemblerStub(int id, bool isTail)
79 {
80 Label *target = module_->GetFunctionLabel(id);
81 isTail ? Jmp(target) : Callq(target);
82 }
83
BindAssemblerStub(int id)84 void ExtendedAssembler::BindAssemblerStub(int id)
85 {
86 Label *target = module_->GetFunctionLabel(id);
87 Bind(target);
88 auto callSigns = module_->GetCSigns();
89 auto cs = callSigns[id];
90 isGhcCallingConv_ = cs->GetCallConv() ==
91 CallSignature::CallConv::GHCCallConv;
92 }
93
PushArgc(int32_t argc,Register tempArgcRegister)94 void ExtendedAssembler::PushArgc(int32_t argc, Register tempArgcRegister)
95 {
96 Movabs(JSTaggedValue(argc).GetRawData(), tempArgcRegister);
97 Pushq(tempArgcRegister);
98 }
99
PushArgc(Register argcRegister,Register tempArgcRegister)100 void ExtendedAssembler::PushArgc(Register argcRegister, Register tempArgcRegister)
101 {
102 Movabs(JSTaggedValue::TAG_INT, tempArgcRegister);
103 Orq(argcRegister, tempArgcRegister);
104 Pushq(tempArgcRegister);
105 }
106 } // panda::ecmascript::x64