Debian Codegraph @

src/arc/arcompact.S

raw
1 /* -----------------------------------------------------------------------
2 arcompact.S - Copyright (c) 2013 Synposys, Inc. (www.synopsys.com)
3
4 ARCompact Foreign Function Interface
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 ``Software''), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL RENESAS TECHNOLOGY BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24 ----------------------------------------------------------------------- */
25
26 #define LIBFFI_ASM
27 #include <fficonfig.h>
28 #include <ffi.h>
29 #ifdef HAVE_MACHINE_ASM_H
30 #include <machine/asm.h>
31 #else
32 #define CNAME(x) x
33 #define ENTRY(x) .globl CNAME(x)` .type CNAME(x),%function` CNAME(x):
34 #endif
35
36 #if __SIZEOF_POINTER__ == 8
37 #define PTRS 8
38 #define FLTS 8
39 #define LARG ldl
40 #define SARG stl
41 #define ADDPTR addl
42 #define MOVPTR movl
43 #else
44 #define PTRS 4
45 #define FLTS 4
46 #define LARG ld
47 #define SARG st
48 #define ADDPTR add
49 #define MOVPTR mov
50 #endif
51
52 #define FRAME_LEN (8 * PTRS + 16)
53
54 .text
55
56 ENTRY(ffi_call_asm)
57 .cfi_startproc
58
59 /* Save registers. */
60 .cfi_def_cfa r1, FRAME_LEN
61 SARG fp, [r1, FRAME_LEN - 2*PTRS]
62 .cfi_offset fp, -2*PTRS
63 SARG blink, [r1, FRAME_LEN - 1*PTRS]
64 .cfi_offset blink, -1*PTRS
65 ADDPTR fp, r1, FRAME_LEN
66 MOVPTR sp, r0
67 .cfi_def_cfa fp, 0
68
69 /* Load arguments. */
70 MOVPTR r11, r2 /* fn */
71 MOVPTR r12, r3 /* closure */
72
73 /* Save arguments. */
74 LARG r0, [fp, -FRAME_LEN+0*PTRS]
75 LARG r1, [fp, -FRAME_LEN+1*PTRS]
76 LARG r2, [fp, -FRAME_LEN+2*PTRS]
77 LARG r3, [fp, -FRAME_LEN+3*PTRS]
78 LARG r4, [fp, -FRAME_LEN+4*PTRS]
79 LARG r5, [fp, -FRAME_LEN+5*PTRS]
80 LARG r6, [fp, -FRAME_LEN+6*PTRS]
81 LARG r7, [fp, -FRAME_LEN+7*PTRS]
82
83 /* Call the function. */
84 jl [r11]
85
86 /* Save return value (r0/r1) */
87 SARG r0, [fp, -FRAME_LEN+0*PTRS]
88 SARG r1, [fp, -FRAME_LEN+1*PTRS]
89
90 /* Restore and return. */
91 add sp, fp, -FRAME_LEN
92 .cfi_def_cfa sp, FRAME_LEN
93 LARG blink, [fp, -1*PTRS]
94 .cfi_restore blink
95 LARG fp, [fp, -2*PTRS]
96 .cfi_restore fp
97 j_s [blink]
98 .cfi_endproc
99 .size ffi_call_asm, .-ffi_call_asm
100
101 /*
102 ffi_closure_asm. Expects address of the passed-in ffi_closure in r8.
103 void ffi_closure_inner (ffi_cif *cif,
104 void (*fun) (ffi_cif *, void *, void **, void *),
105 void *user_data,
106 size_t *stackargs, struct call_context *regargs)
107 */
108
109 ENTRY(ffi_closure_asm)
110 .cfi_startproc
111
112 ADDPTR sp, sp, -FRAME_LEN
113 .cfi_def_cfa_offset FRAME_LEN
114
115 /* Make a frame. */
116 SARG fp, [sp, FRAME_LEN-2*PTRS]
117 .cfi_offset fp, -2*PTRS
118 SARG blink, [sp, FRAME_LEN-1*PTRS]
119 .cfi_offset blink, -1*PTRS
120 ADDPTR fp, sp, FRAME_LEN
121
122 /* Save arguments. */
123 SARG r0, [sp, 0*PTRS]
124 SARG r1, [sp, 1*PTRS]
125 SARG r2, [sp, 2*PTRS]
126 SARG r3, [sp, 3*PTRS]
127 SARG r4, [sp, 4*PTRS]
128 SARG r5, [sp, 5*PTRS]
129 SARG r6, [sp, 6*PTRS]
130 SARG r7, [sp, 7*PTRS]
131
132 /* Enter C. */
133 LARG r0, [r8, FFI_TRAMPOLINE_SIZE+0*PTRS]
134 LARG r1, [r8, FFI_TRAMPOLINE_SIZE+1*PTRS]
135 LARG r2, [r8, FFI_TRAMPOLINE_SIZE+2*PTRS]
136 ADDPTR r3, sp, FRAME_LEN
137 MOVPTR r4, sp
138
139 /* Call the C code. */
140 bl ffi_closure_inner
141
142 /* Return values. */
143 LARG r0, [sp, 0*PTRS]
144 LARG r1, [sp, 1*PTRS]
145
146 /* Restore and return. */
147 LARG blink, [sp, FRAME_LEN-1*PTRS]
148 .cfi_restore blink
149 LARG fp, [sp, FRAME_LEN-2*PTRS]
150 .cfi_restore fp
151 ADDPTR sp, sp, FRAME_LEN
152 .cfi_def_cfa_offset 0
153 j_s [blink]
154 .cfi_endproc
155 .size ffi_closure_asm, .-ffi_closure_asm
156
157 /*
158 ffi_go_closure_asm. Expects address of the passed-in ffi_go_closure in r12.
159 void ffi_closure_inner (ffi_cif *cif,
160 void (*fun) (ffi_cif *, void *, void **, void *),
161 void *user_data,
162 size_t *stackargs, struct call_context *regargs)
163 */
164
165 ENTRY(ffi_go_closure_asm)
166 .cfi_startproc
167
168 ADDPTR sp, sp, -FRAME_LEN
169 .cfi_def_cfa_offset FRAME_LEN
170
171 /* make a frame */
172 SARG fp, [sp, FRAME_LEN-2*PTRS]
173 .cfi_offset fp, -2*PTRS
174 SARG blink, [sp, FRAME_LEN-1*PTRS]
175 .cfi_offset blink, -1*PTRS
176 ADDPTR fp, sp, FRAME_LEN
177
178 /* save arguments */
179 SARG r0, [sp, 0*PTRS]
180 SARG r1, [sp, 1*PTRS]
181 SARG r2, [sp, 2*PTRS]
182 SARG r3, [sp, 3*PTRS]
183 SARG r4, [sp, 4*PTRS]
184 SARG r5, [sp, 5*PTRS]
185 SARG r6, [sp, 6*PTRS]
186 SARG r7, [sp, 7*PTRS]
187
188 /* enter C */
189 LARG r0, [r12, 1*PTRS]
190 LARG r1, [r12, 2*PTRS]
191 MOVPTR r2, r12
192 ADDPTR r3, sp, FRAME_LEN
193 MOVPTR r4, sp
194
195 bl ffi_closure_inner
196
197 /* Return values. */
198 LARG r0, [sp, 0*PTRS]
199 LARG r1, [sp, 1*PTRS]
200
201
202 LARG blink, [sp, FRAME_LEN-1*PTRS]
203 .cfi_restore blink
204 LARG fp, [sp, FRAME_LEN-2*PTRS]
205 .cfi_restore fp
206 ADDPTR sp, sp, FRAME_LEN
207 .cfi_def_cfa_offset 0
208 j_s [blink]
209 .cfi_endproc
210 .size ffi_go_closure_asm, .-ffi_go_closure_asm