• 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
16#define CALLEE_SAVED_GP_REGS_COUNT 10
17
18.extern printf
19
20.macro PUSH_CALLER_REGS
21    stp x0, x1, [sp, #-16]!
22    stp x2, x3, [sp, #-16]!
23    stp x4, x5, [sp, #-16]!
24    stp x6, x7, [sp, #-16]!
25    stp x8, x9, [sp, #-16]!
26    stp x10, x11, [sp, #-16]!
27    stp x12, x13, [sp, #-16]!
28    stp x14, x15, [sp, #-16]!
29.endm
30
31.macro POP_CALLER_REGS
32    ldp x14, x15, [sp], #16
33    ldp x12, x13, [sp], #16
34    ldp x10, x11, [sp], #16
35    ldp x8, x9, [sp], #16
36    ldp x6, x7, [sp], #16
37    ldp x4, x5, [sp], #16
38    ldp x2, x3, [sp], #16
39    ldp x0, x1, [sp], #16
40.endm
41
42.macro PUSH_CALLER_VREGS
43    stp d0, d1, [sp, #-16]!
44    stp d2, d3, [sp, #-16]!
45    stp d4, d5, [sp, #-16]!
46    stp d6, d7, [sp, #-16]!
47    stp d16, d17, [sp, #-16]!
48    stp d18, d19, [sp, #-16]!
49    stp d20, d21, [sp, #-16]!
50    stp d22, d23, [sp, #-16]!
51    stp d24, d25, [sp, #-16]!
52    stp d26, d27, [sp, #-16]!
53    stp d28, d29, [sp, #-16]!
54    stp d30, d31, [sp, #-16]!
55.endm
56
57.macro POP_CALLER_VREGS
58    ldp d30, d31, [sp], #16
59    ldp d28, d29, [sp], #16
60    ldp d26, d27, [sp], #16
61    ldp d24, d25, [sp], #16
62    ldp d22, d23, [sp], #16
63    ldp d20, d21, [sp], #16
64    ldp d18, d19, [sp], #16
65    ldp d16, d17, [sp], #16
66    ldp d6, d7, [sp], #16
67    ldp d4, d5, [sp], #16
68    ldp d2, d3, [sp], #16
69    ldp d0, d1, [sp], #16
70.endm
71
72.macro PUSH_ARGS_REGS
73    stp x6, x7, [sp, #-16]!
74    stp x4, x5, [sp, #-16]!
75    stp x2, x3, [sp, #-16]!
76    stp x0, x1, [sp, #-16]!
77.endm
78
79.macro POP_ARGS_REGS
80    ldp x0, x1, [sp], #16
81    ldp x2, x3, [sp], #16
82    ldp x4, x5, [sp], #16
83    ldp x6, x7, [sp], #16
84.endm
85
86.macro PUSH_ARGS_VREGS
87    stp d0, d1, [sp, #-16]!
88    stp d2, d3, [sp, #-16]!
89    stp d4, d5, [sp, #-16]!
90    stp d6, d7, [sp, #-16]!
91.endm
92
93.macro POP_ARGS_VREGS
94    ldp d6, d7, [sp], #16
95    ldp d4, d5, [sp], #16
96    ldp d2, d3, [sp], #16
97    ldp d0, d1, [sp], #16
98.endm
99
100.macro PUSH_CALLEE_REGS base_reg
101    stp x27, x28, [\base_reg, #-16]!
102    stp x25, x26, [\base_reg, #-16]!
103    stp x23, x24, [\base_reg, #-16]!
104    stp x21, x22, [\base_reg, #-16]!
105    stp x19, x20, [\base_reg, #-16]!
106    stp d14, d15, [\base_reg, #-16]!
107    stp d12, d13, [\base_reg, #-16]!
108    stp d10, d11, [\base_reg, #-16]!
109    stp d8, d9, [\base_reg, #-16]!
110.endm
111
112.macro BEGIN_CALL
113    PUSH_CALLER_REGS
114.endm
115
116.macro LARG0 v
117    ldr x0, =\v
118.endm
119
120.macro ARG0 v
121    mov x0, \v
122.endm
123
124.macro ARG1 v
125    mov x1, \v
126.endm
127
128.macro ARG2 v
129    mov x2, \v
130.endm
131
132.macro END_CALL func
133    bl \func
134    POP_CALLER_REGS
135.endm
136
137.macro LOG3 fmt, arg1, arg2
138    BEGIN_CALL
139        LARG0 \fmt
140        ARG1 \arg1
141        ARG2 \arg2
142    END_CALL LogEntrypoint
143.endm
144
145.macro ABORT
146    brk 0
147.endm
148
149.macro ASSERT_REGS_CMP reg1, reg2, pred
150#ifndef NDEBUG
151    cmp \reg1, \reg2
152    b\pred 1f
153    ABORT
1541:
155#endif
156.endm
157