1/** 2 * Copyright (c) 2021-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 "arch/asm_support.h" 17 18// T InvokeHelper(const uint8_t* gprs, const uint8_t* fprs, const uint8_t* stack, size_t stack_size, ManagedThread* thread); 19.global InvokeHelper 20.type InvokeHelper, %function 21InvokeHelper: 22 CFI_STARTPROC 23 CFI_DEF_CFA(rsp, 8) 24 25 // regs: 26 // rdi - gprs, rsi - fprs, rdx - stack, rcx - stack_size, r8 - thread 27 28 // setup stack frame 29 pushq %rbp 30 CFI_ADJUST_CFA_OFFSET(8) 31 CFI_REL_OFFSET(rbp, 0) 32 33 movq %rsp, %rbp 34 CFI_DEF_CFA_REGISTER(rbp) 35 36 pushq %THREAD_REG 37 CFI_REL_OFFSET(THREAD_REG, -(1 * 8)) 38 pushq %r14 39 CFI_REL_OFFSET(r14, -(2 * 8)) 40 41 movq %r8, %THREAD_REG 42 43 // load fp regs 44 movsd (%rsi), %xmm0 45 movsd 8(%rsi), %xmm1 46 movsd 16(%rsi), %xmm2 47 movsd 24(%rsi), %xmm3 48 movsd 32(%rsi), %xmm4 49 movsd 40(%rsi), %xmm5 50 movsd 48(%rsi), %xmm6 51 movsd 56(%rsi), %xmm7 52 53 // check stack arguments 54 test %rcx, %rcx 55 je 2f 56 // reserve stack space 57 movq %rcx, %r8 58 shlq $3, %r8 59 sub %r8, %rsp 60 movq %rsp, %r8 61 // push stack args 621: test %rcx, %rcx 63 je 2f 64 movq (%rdx), %r14 65 movq %r14, (%r8) 66 addq $8, %rdx 67 addq $8, %r8 68 sub $1, %rcx 69 jmp 1b 70 712: // load gprs 72 movq %rdi, %r14 73 movq (%r14), %rdi 74 movq 8(%r14), %rsi 75 movq 16(%r14), %rdx 76 movq 24(%r14), %rcx 77 movq 32(%r14), %r8 78 movq 40(%r14), %r9 79 80 // invoke 81 movq METHOD_COMPILED_ENTRY_POINT_OFFSET(%rdi), %rax 82 callq *%rax 83 84 // rax, rdx contain the result 85 // restore regs and pop frame 86 leaq -16(%rbp), %rsp 87 popq %r14 88 CFI_RESTORE(r14) 89 popq %THREAD_REG 90 CFI_RESTORE(THREAD_REG) 91 popq %rbp 92 CFI_RESTORE(rbp) 93 CFI_DEF_CFA(rsp, (1 * 8)) 94 retq 95 CFI_ENDPROC 96