• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 #include "ecma_asm_defines.h"
16
17 /* JSFunctionEntry Callee Register Save Macro */
18.macro PUSH_CALLEE_SAVED_REGS
19    stp x27, x28, [sp, #-16]!
20    stp x25, x26, [sp, #-16]!
21    stp x23, x24, [sp, #-16]!
22    stp x21, x22, [sp, #-16]!
23    stp x19, x20, [sp, #-16]!
24    stp d14, d15, [sp, #-16]!
25    stp d12, d13, [sp, #-16]!
26    stp d10, d11, [sp, #-16]!
27    stp d8, d9, [sp, #-16]!
28.endm
29
30 /* JSFunctionEntry Callee Register restore Macro */
31.macro POP_CALLEE_SAVED_REGS
32    ldp d8, d9,   [sp], #16
33    ldp d10, d11, [sp], #16
34    ldp d12, d13, [sp], #16
35    ldp d14, d15, [sp], #16
36    ldp x19, x20, [sp], #16
37    ldp x21, x22, [sp], #16
38    ldp x23, x24, [sp], #16
39    ldp x25, x26, [sp], #16
40    ldp x27, x28, [sp], #16
41.endm
42
43// uint64_t JSFunctionEntry(uintptr_t glue, uintptr_t prevFp, uint32_t expectedNumArgs,
44//                                uint32_t actualNumArgs, const JSTaggedType argV[], uintptr_t codeAddr);
45// Input:
46// %x0 - glue
47// %x1 - prevFp
48// %x2 - expectedNumArgs
49// %x3 - actualNumArgs
50// %x4 - argV
51// %x5 - codeAddr
52// construct Entry Frame
53//   +--------------------------+
54//   |   returnaddress      |   ^
55//   |----------------------|   |
56//   |calleesave registers  | Fixed
57//   |----------------------| OptimizedEntryFrame
58//   |      prevFp          |   |
59//   |----------------------|   |
60//   |      frameType       |   |
61//   |----------------------|   |
62//   |  prevLeaveFrameFp    |   v
63//   +--------------------------+
64
65.global JSFunctionEntry
66.type JSFunctionEntry, %function
67JSFunctionEntry:
68    str     x30, [sp, #-8]!          // returnaddress
69    PUSH_CALLEE_SAVED_REGS
70    str     x29, [sp, #-8]!          // callee c-fp
71    mov     x29, sp
72    mov     x19, #JS_ENTRY_FRAME_TYPE
73    stp     x1, x19, [sp, #-16]!
74
75    mov     x20, x0
76    mov     w19, w2
77    mov     x2, x1
78    cmp     w19, w3
79    b.ls    .LCopyArguments
80    mov     w8, #10
81    mov     w9, w19
82
83.LCopyUndefined:
84    sub     x9, x9, #1
85    cmp     w9, w3
86    str     x8, [sp, #-8]!
87    b.hi    .LCopyUndefined
88.LCopyArguments:
89    cmp     w19, w3
90    csel    w8, w19, w3, lo
91    cbz     w8, .InvokeCompiledJSFunction
92    sub     w9, w8, #1              // =1
93    add     x9, x4, w9, uxtw #3
94.LCopyArgLoop:
95    ldr     x10, [x9], #-8
96    subs    w8, w8, #1              // =1
97    str     x10, [sp, #-8]!
98
99    b.ne    .LCopyArgLoop
100
101// Input:
102// %x0 - glue
103// argv push stack
104.InvokeCompiledJSFunction:
105    mov     x2, x5
106    blr     x2
107
108    // pop argv
109    lsl     w8, w19, #3
110    add     sp, sp, x8
111    // pop prevLeaveFrameFp to restore thread->currentFrame_
112    ldr    x19, [sp]
113    add    sp, sp, #0x8
114    str    x19, [x20, #ASM_GLUE_CURRENT_FRAME_OFFSET]
115    // pop entry frame type and c-fp
116    add    sp, sp, #0x8
117    ldr    x29, [sp]
118    add    sp, sp, #0x8
119
120    // restore callee save registers
121    POP_CALLEE_SAVED_REGS
122    // restore return address
123    ldr     x30, [sp]
124    add     sp, sp, #0x8
125    ret
126
127// uint64_t RuntimeCallTrampoline(uintptr_t glue, uint64_t runtime_id, uint64_t patch_id, uint64_t argc, ...);
128// webkit_jscc calling convention call runtime_id's runtion function(c-abi)
129// JSTaggedType (*)(uintptr_t argGlue, uint64_t argc, JSTaggedType argv[])
130// Input:
131// %x0 - glue
132// stack layout:
133// sp + N*8 argvN
134// ........
135// sp + 32: argv1
136// sp + 24: argv0
137// sp + 16: argc
138// sp + 8:  patch_id
139// sp:      runtime_id
140// construct Leave Frame:
141//   +--------------------------+
142//   |      argv[]              |
143//   +--------------------------+ ---
144//   |       argc               |   ^
145//   |--------------------------|   |
146//   |       patchID            | Fixed
147//   |--------------------------| OptimizedLeaveFrame
148//   |       RuntimeId          |   |
149//   |--------------------------|   |
150//   |       returnAddr         |   |
151//   |--------------------------|   |
152//   |       callsiteFp         |   |
153//   |--------------------------|   |
154//   |     frameType            |   v
155//   +--------------------------+ ---
156
157// Output:
158//  sp - 8 : x30
159//  sp - 16: x29 <---------current x29 & current sp
160//  current sp - 8:  type
161//  current sp - 16: callee save x19
162
163.global RuntimeCallTrampoline
164.type RuntimeCallTrampoline, %function
165RuntimeCallTrampoline:
166    stp     x29, x30, [sp, #-16]!  // save register for fp, rip
167    mov     x29, sp                // set frame pointer = callsiteFp
168    str     x29, [x0, #ASM_GLUE_CURRENT_FRAME_OFFSET]       // save to thread->currentFrame_
169    str     x19, [sp, #-16]        // callee save register
170
171    // construct leave frame
172    mov     x19, #LEAVE_FRAME_TYPE
173    str     x19, [sp, #-8]
174    add     sp, sp, #-16
175
176    // load runtime trampoline address
177    ldr     x19, [x29, #16]  // runtime_id
178    add     x19, x0, x19, lsl #3
179    ldr     x19, [x19, #ASM_GLUE_RUNTIME_FUNCTIONS_OFFSET]
180    ldr     x1, [x29, #32]  // argc
181    add     x2, x29,  #40   // argv[]
182    blr     x19
183
184    // descontruct leave frame and callee save register
185    ldr     x19, [sp]
186    add   sp, sp, #16
187    // restore register
188    ldp     x29, x30, [sp], #16
189    ret
190