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// ARM64 callee-saved registers: X19-X28, D8-D15 25.macro PUSH_CALLEE_SAVE 26 stp x27, x28, [sp, #-REG_PAIR_SIZE_ARM64]! 27 stp x25, x26, [sp, #-REG_PAIR_SIZE_ARM64]! 28 stp x23, x24, [sp, #-REG_PAIR_SIZE_ARM64]! 29 stp x21, x22, [sp, #-REG_PAIR_SIZE_ARM64]! 30 stp x19, x20, [sp, #-REG_PAIR_SIZE_ARM64]! 31 stp d14, d15, [sp, #-REG_PAIR_SIZE_ARM64]! 32 stp d12, d13, [sp, #-REG_PAIR_SIZE_ARM64]! 33 stp d10, d11, [sp, #-REG_PAIR_SIZE_ARM64]! 34 stp d8, d9, [sp, #-REG_PAIR_SIZE_ARM64]! 35.endm 36 37.macro RESTORE_CALLEE_SAVE 38 ldp d8, d9, [sp], #REG_PAIR_SIZE_ARM64 39 ldp d10, d11, [sp], #REG_PAIR_SIZE_ARM64 40 ldp d12, d13, [sp], #REG_PAIR_SIZE_ARM64 41 ldp d14, d15, [sp], #REG_PAIR_SIZE_ARM64 42 ldp x19, x20, [sp], #REG_PAIR_SIZE_ARM64 43 ldp x21, x22, [sp], #REG_PAIR_SIZE_ARM64 44 ldp x23, x24, [sp], #REG_PAIR_SIZE_ARM64 45 ldp x25, x26, [sp], #REG_PAIR_SIZE_ARM64 46 ldp x27, x28, [sp], #REG_PAIR_SIZE_ARM64 47.endm 48 49/* 50+---------------+ 51| | 52| Caller Stack | 53| | 54+---------------+ <--------- // SP + 176 (SP before LazyDeoptEntry) 55| x30 | (8 bytes) // SP + 168 56| x29 | (8 bytes) // SP + 160 57+---------------+ 58| x1 | (8 bytes) // SP + 152 59| x0 | (8 bytes) // SP + 144 60+---------------+ 61| x27/x28 | (16 bytes) // SP + 128 62| x25/x26 | (16 bytes) // SP + 112 63| x23/x24 | (16 bytes) // SP + 96 64| x21/x22 | (16 bytes) // SP + 80 65| x19/x20 | (16 bytes) // SP + 64 66| d14/d15 | (16 bytes) // SP + 48 67| d12/d13 | (16 bytes) // SP + 32 68| d10/d11 | (16 bytes) // SP + 16 69| d8/d9 | (16 bytes) // SP 70+---------------+ 71*/ 72 73LazyDeoptEntryName : 74 stp x29, x30, [sp, #-REG_PAIR_SIZE_ARM64]! // Frame pointer and return address 75 stp x0, x3, [sp, #-REG_PAIR_SIZE_ARM64]! // Save maybeAcc, x3 use to align up 76 PUSH_CALLEE_SAVE // Callee-saved registers 77 78 // Get glue pointer from thread local storage 79 bl GetGlueFromThreadLocalName // x0 = glue pointer 80 81 // Prepare arguments for GetFixedReturnAddr 82 mov x19, x0 // Save glue to x19, arg0: glue 83 add x1, sp, #PRE_SP_OFFSET_ARM64 // arg1: prevCallSiteSp 84 bl GetFixedReturnAddrName // x0 = return address offset 85 str x0, [sp, #RETURN_ADDRESS_OFFSET_ARM64] // Store origin return address 86 87 // Prepare deoptimization handler call 88 mov x0, #0 // arg0: False 89 bl GetDeoptHandlerAsmOffsetName // x0 = DeoptHandlerAsm offset 90 ldr x4, [x19, x0] // x4 = *(glue + offset) (DeoptHandleAsm Address) 91 92 // Set up arguments and jump to DeoptHandlerASM 93 mov x0, x19 // arg0: glue 94 mov x1, #LAZY_DEOPT_TYPE_OFFSET // arg1: LAZY_DEOPT 95 RESTORE_CALLEE_SAVE // Restore callee-saved registers 96 ldp x2, x3, [sp], #REG_PAIR_SIZE_ARM64 // arg2: maybeAcc 97 ldp x29, x30, [sp], #REG_PAIR_SIZE_ARM64 // Restore frame pointer and return address 98 br x4 // Tail call to DeoptHandler