1/* 2 * Copyright (c) 2025 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/trampoline/asm_defines.h" 17 18.extern GetGlueFromThreadLocalName 19.extern GetFixedReturnAddrName 20.extern GetDeoptHandlerAsmOffsetName 21 22.global LazyDeoptEntryName 23 24.macro PUSH_CALLEE_SAVE 25 pushq %r12 26 pushq %r13 27 pushq %r14 28 pushq %r15 29 pushq %rbx 30.endm 31 32.macro RESTORE_CALLEE_SAVE 33 popq %rbx 34 popq %r15 35 popq %r14 36 popq %r13 37 popq %r12 38.endm 39 40/* 41LazyDeoptEntry layout: 42+---------------+ 43| Placeholder | <- rsp + 56 44+---------------+ 45| rbp | <- rsp + 48 46+---------------+ 47| rax | <- rsp + 40 48+---------------+ 49| r12 | <- rsp + 32 50+---------------+ 51| r13 | <- rsp + 24 52+---------------+ 53| r14 | <- rsp + 16 54+---------------+ 55| r15 | <- rsp + 8 56+---------------+ 57| rbx | <- rsp (after PUSH_CALLEE_SAVE) 58+---------------+ 59*/ 60 61LazyDeoptEntryName : 62 pushq $0 // Place Holder (return address) 63 pushq %rbp // Save original frame pointer 64 pushq %rax // Save maybeAcc (original rax) 65 PUSH_CALLEE_SAVE // Callee-saved registers 66 67 // Get glue pointer from thread local storage 68 callq GetGlueFromThreadLocalName // rax = glue pointer 69 70 // Prepare arguments for GetFixedReturnAddr 71 movq %rax, %r12 // Save glue to r12 72 movq %rax, %rdi // arg0: glue 73 leaq PRE_SP_OFFSET_X64(%rsp), %rsi // arg1: prevCallSiteSp 74 callq GetFixedReturnAddrName // rax = return address offset 75 movq %rax, RETURN_ADDRESS_OFFSET_X64(%rsp) // Store origin return address 76 77 // Prepare deoptimization handler call 78 movq $0, %rdi // arg0: False 79 callq GetDeoptHandlerAsmOffsetName // rax = DeoptHandlerAsm offset 80 movq %r12, %rcx // rcx = glue 81 addq %rcx, %rax // rax = glue + offset(DeoptHandleAsm Address) 82 83 // Set up arguments and jump to DeoptHandlerASM 84 movq %rcx, %rdi // arg0: glue pointer 85 movq $LAZY_DEOPT_TYPE_OFFSET, %rsi // arg1: deopt type (LAZY_DEOPT) 86 RESTORE_CALLEE_SAVE // Restore callee-saved registers 87 popq %rdx // arg2: maybeAcc (original rax value) 88 popq %rbp // Restore original frame pointer 89 jmpq *(%rax) // Tail call to DeoptHandler