| 1 |
/* ----------------------------------------------------------------------- |
| 2 |
linux.S - (c) 2003-2004 Randolph Chung <[email protected]> |
| 3 |
(c) 2008 Red Hat, Inc. |
| 4 |
|
| 5 |
HPPA Foreign Function Interface |
| 6 |
|
| 7 |
Permission is hereby granted, free of charge, to any person obtaining |
| 8 |
a copy of this software and associated documentation files (the |
| 9 |
``Software''), to deal in the Software without restriction, including |
| 10 |
without limitation the rights to use, copy, modify, merge, publish, |
| 11 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 12 |
permit persons to whom the Software is furnished to do so, subject to |
| 13 |
the following conditions: |
| 14 |
|
| 15 |
The above copyright notice and this permission notice shall be included |
| 16 |
in all copies or substantial portions of the Software. |
| 17 |
|
| 18 |
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 |
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 21 |
IN NO EVENT SHALL RENESAS TECHNOLOGY BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 22 |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 23 |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 24 |
OTHER DEALINGS IN THE SOFTWARE. |
| 25 |
----------------------------------------------------------------------- */ |
| 26 |
|
| 27 |
#define LIBFFI_ASM |
| 28 |
#include <fficonfig.h> |
| 29 |
#include <ffi.h> |
| 30 |
|
| 31 |
.text |
| 32 |
.level 1.1 |
| 33 |
.align 4 |
| 34 |
|
| 35 |
/* void ffi_call_pa32(void (*)(char *, extended_cif *), |
| 36 |
extended_cif *ecif, |
| 37 |
unsigned bytes, |
| 38 |
unsigned flags, |
| 39 |
unsigned *rvalue, |
| 40 |
void (*fn)(void)); |
| 41 |
*/ |
| 42 |
|
| 43 |
.export ffi_call_pa32,code |
| 44 |
.import ffi_prep_args_pa32,code |
| 45 |
|
| 46 |
.type ffi_call_pa32, @function |
| 47 |
.LFB1: |
| 48 |
ffi_call_pa32: |
| 49 |
.proc |
| 50 |
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4 |
| 51 |
.entry |
| 52 |
stw %rp, -20(%sp) |
| 53 |
copy %r3, %r1 |
| 54 |
.LCFI11: |
| 55 |
|
| 56 |
copy %sp, %r3 |
| 57 |
.LCFI12: |
| 58 |
|
| 59 |
/* Setup the stack for calling prep_args... |
| 60 |
We want the stack to look like this: |
| 61 |
|
| 62 |
[ Previous stack ] <- %r3 |
| 63 |
|
| 64 |
[ 64-bytes register save area ] <- %r4 |
| 65 |
|
| 66 |
[ Stack space for actual call, passed as ] <- %arg0 |
| 67 |
[ arg0 to ffi_prep_args_pa32 ] |
| 68 |
|
| 69 |
[ Stack for calling prep_args ] <- %sp |
| 70 |
*/ |
| 71 |
|
| 72 |
stwm %r1, 64(%sp) |
| 73 |
stw %r4, 12(%r3) |
| 74 |
.LCFI13: |
| 75 |
copy %sp, %r4 |
| 76 |
|
| 77 |
addl %arg2, %r4, %arg0 /* arg stack */ |
| 78 |
stw %arg3, -48(%r3) /* save flags; we need it later */ |
| 79 |
|
| 80 |
/* Call prep_args: |
| 81 |
%arg0(stack) -- set up above |
| 82 |
%arg1(ecif) -- same as incoming param |
| 83 |
%arg2(bytes) -- same as incoming param */ |
| 84 |
bl ffi_prep_args_pa32,%r2 |
| 85 |
ldo 64(%arg0), %sp |
| 86 |
ldo -64(%sp), %sp |
| 87 |
|
| 88 |
/* now %sp should point where %arg0 was pointing. */ |
| 89 |
|
| 90 |
/* Load the arguments that should be passed in registers |
| 91 |
The fp args were loaded by the prep_args function. */ |
| 92 |
ldw -36(%sp), %arg0 |
| 93 |
ldw -40(%sp), %arg1 |
| 94 |
ldw -44(%sp), %arg2 |
| 95 |
ldw -48(%sp), %arg3 |
| 96 |
|
| 97 |
/* in case the function is going to return a structure |
| 98 |
we need to give it a place to put the result. */ |
| 99 |
ldw -52(%r3), %ret0 /* %ret0 <- rvalue */ |
| 100 |
ldw -56(%r3), %r22 /* %r22 <- function to call */ |
| 101 |
bl $$dyncall, %r31 /* Call the user function */ |
| 102 |
copy %r31, %rp |
| 103 |
|
| 104 |
/* Prepare to store the result; we need to recover flags and rvalue. */ |
| 105 |
ldw -48(%r3), %r21 /* r21 <- flags */ |
| 106 |
|
| 107 |
/* Adjust flags range from [-8, 15] to [0, 23]. */ |
| 108 |
addi 8, %r21, %r21 |
| 109 |
|
| 110 |
blr %r21, %r0 |
| 111 |
ldw -52(%r3), %r20 /* r20 <- rvalue */ |
| 112 |
|
| 113 |
/* Giant jump table */ |
| 114 |
/* 8-byte small struct */ |
| 115 |
b,n .Lsmst8 |
| 116 |
nop |
| 117 |
/* 7-byte small struct */ |
| 118 |
b,n .Lsmst7 |
| 119 |
nop |
| 120 |
/* 6-byte small struct */ |
| 121 |
b,n .Lsmst6 |
| 122 |
nop |
| 123 |
/* 5-byte small struct */ |
| 124 |
b,n .Lsmst5 |
| 125 |
nop |
| 126 |
/* 4-byte small struct */ |
| 127 |
b,n .Lsmst4 |
| 128 |
nop |
| 129 |
/* 3-byte small struct */ |
| 130 |
b,n .Lsmst3 |
| 131 |
nop |
| 132 |
/* 2-byte small struct */ |
| 133 |
b,n .Lsmst2 |
| 134 |
nop |
| 135 |
/* 1-byte small struct */ |
| 136 |
b .Ldone |
| 137 |
stb %ret0, 0(%r20) |
| 138 |
/* void */ |
| 139 |
b,n .Ldone |
| 140 |
nop |
| 141 |
/* int */ |
| 142 |
b .Ldone |
| 143 |
stw %ret0, 0(%r20) |
| 144 |
/* float */ |
| 145 |
b .Ldone |
| 146 |
fstw %fr4L,0(%r20) |
| 147 |
/* double */ |
| 148 |
b .Ldone |
| 149 |
fstd %fr4,0(%r20) |
| 150 |
/* long double */ |
| 151 |
b .Ldone |
| 152 |
fstd %fr4,0(%r20) |
| 153 |
/* unsigned int8 */ |
| 154 |
b .Ldone |
| 155 |
stw %ret0, 0(%r20) |
| 156 |
/* sint8 */ |
| 157 |
b .Ldone |
| 158 |
stw %ret0, 0(%r20) |
| 159 |
/* unsigned int16 */ |
| 160 |
b .Ldone |
| 161 |
stw %ret0, 0(%r20) |
| 162 |
/* sint16 */ |
| 163 |
b .Ldone |
| 164 |
stw %ret0, 0(%r20) |
| 165 |
/* unsigned int32 */ |
| 166 |
b .Ldone |
| 167 |
stw %ret0, 0(%r20) |
| 168 |
/* sint32 */ |
| 169 |
b .Ldone |
| 170 |
stw %ret0, 0(%r20) |
| 171 |
/* unsigned int64 */ |
| 172 |
b,n .Luint64 |
| 173 |
nop |
| 174 |
/* signed int64 */ |
| 175 |
b,n .Lsint64 |
| 176 |
nop |
| 177 |
/* large struct */ |
| 178 |
b,n .Ldone |
| 179 |
nop |
| 180 |
/* pointer */ |
| 181 |
b .Ldone |
| 182 |
stw %ret0, 0(%r20) |
| 183 |
/* complex */ |
| 184 |
b,n .Ldone |
| 185 |
nop |
| 186 |
|
| 187 |
/* Store the result according to the return type. */ |
| 188 |
|
| 189 |
.Luint64: |
| 190 |
.Lsint64: |
| 191 |
stw %ret0, 0(%r20) |
| 192 |
b .Ldone |
| 193 |
stw %ret1, 4(%r20) |
| 194 |
|
| 195 |
.Lsmst2: |
| 196 |
/* 2-byte structs are returned in ret0 as ????xxyy. */ |
| 197 |
extru %ret0, 23, 8, %r22 |
| 198 |
stbs,ma %r22, 1(%r20) |
| 199 |
b .Ldone |
| 200 |
stb %ret0, 0(%r20) |
| 201 |
|
| 202 |
.Lsmst3: |
| 203 |
/* 3-byte structs are returned in ret0 as ??xxyyzz. */ |
| 204 |
extru %ret0, 15, 8, %r22 |
| 205 |
stbs,ma %r22, 1(%r20) |
| 206 |
extru %ret0, 23, 8, %r22 |
| 207 |
stbs,ma %r22, 1(%r20) |
| 208 |
b .Ldone |
| 209 |
stb %ret0, 0(%r20) |
| 210 |
|
| 211 |
.Lsmst4: |
| 212 |
/* 4-byte structs are returned in ret0 as wwxxyyzz. */ |
| 213 |
extru %ret0, 7, 8, %r22 |
| 214 |
stbs,ma %r22, 1(%r20) |
| 215 |
extru %ret0, 15, 8, %r22 |
| 216 |
stbs,ma %r22, 1(%r20) |
| 217 |
extru %ret0, 23, 8, %r22 |
| 218 |
stbs,ma %r22, 1(%r20) |
| 219 |
b .Ldone |
| 220 |
stb %ret0, 0(%r20) |
| 221 |
|
| 222 |
.Lsmst5: |
| 223 |
/* 5 byte values are returned right justified: |
| 224 |
ret0 ret1 |
| 225 |
5: ??????aa bbccddee */ |
| 226 |
stbs,ma %ret0, 1(%r20) |
| 227 |
extru %ret1, 7, 8, %r22 |
| 228 |
stbs,ma %r22, 1(%r20) |
| 229 |
extru %ret1, 15, 8, %r22 |
| 230 |
stbs,ma %r22, 1(%r20) |
| 231 |
extru %ret1, 23, 8, %r22 |
| 232 |
stbs,ma %r22, 1(%r20) |
| 233 |
b .Ldone |
| 234 |
stb %ret1, 0(%r20) |
| 235 |
|
| 236 |
.Lsmst6: |
| 237 |
/* 6 byte values are returned right justified: |
| 238 |
ret0 ret1 |
| 239 |
6: ????aabb ccddeeff */ |
| 240 |
extru %ret0, 23, 8, %r22 |
| 241 |
stbs,ma %r22, 1(%r20) |
| 242 |
stbs,ma %ret0, 1(%r20) |
| 243 |
extru %ret1, 7, 8, %r22 |
| 244 |
stbs,ma %r22, 1(%r20) |
| 245 |
extru %ret1, 15, 8, %r22 |
| 246 |
stbs,ma %r22, 1(%r20) |
| 247 |
extru %ret1, 23, 8, %r22 |
| 248 |
stbs,ma %r22, 1(%r20) |
| 249 |
b .Ldone |
| 250 |
stb %ret1, 0(%r20) |
| 251 |
|
| 252 |
.Lsmst7: |
| 253 |
/* 7 byte values are returned right justified: |
| 254 |
ret0 ret1 |
| 255 |
7: ??aabbcc ddeeffgg */ |
| 256 |
extru %ret0, 15, 8, %r22 |
| 257 |
stbs,ma %r22, 1(%r20) |
| 258 |
extru %ret0, 23, 8, %r22 |
| 259 |
stbs,ma %r22, 1(%r20) |
| 260 |
stbs,ma %ret0, 1(%r20) |
| 261 |
extru %ret1, 7, 8, %r22 |
| 262 |
stbs,ma %r22, 1(%r20) |
| 263 |
extru %ret1, 15, 8, %r22 |
| 264 |
stbs,ma %r22, 1(%r20) |
| 265 |
extru %ret1, 23, 8, %r22 |
| 266 |
stbs,ma %r22, 1(%r20) |
| 267 |
b .Ldone |
| 268 |
stb %ret1, 0(%r20) |
| 269 |
|
| 270 |
.Lsmst8: |
| 271 |
/* 8 byte values are returned right justified: |
| 272 |
ret0 ret1 |
| 273 |
8: aabbccdd eeffgghh */ |
| 274 |
extru %ret0, 7, 8, %r22 |
| 275 |
stbs,ma %r22, 1(%r20) |
| 276 |
extru %ret0, 15, 8, %r22 |
| 277 |
stbs,ma %r22, 1(%r20) |
| 278 |
extru %ret0, 23, 8, %r22 |
| 279 |
stbs,ma %r22, 1(%r20) |
| 280 |
stbs,ma %ret0, 1(%r20) |
| 281 |
extru %ret1, 7, 8, %r22 |
| 282 |
stbs,ma %r22, 1(%r20) |
| 283 |
extru %ret1, 15, 8, %r22 |
| 284 |
stbs,ma %r22, 1(%r20) |
| 285 |
extru %ret1, 23, 8, %r22 |
| 286 |
stbs,ma %r22, 1(%r20) |
| 287 |
stb %ret1, 0(%r20) |
| 288 |
|
| 289 |
.Ldone: |
| 290 |
/* all done, return */ |
| 291 |
copy %r4, %sp /* pop arg stack */ |
| 292 |
ldw 12(%r3), %r4 |
| 293 |
ldwm -64(%sp), %r3 /* .. and pop stack */ |
| 294 |
ldw -20(%sp), %rp |
| 295 |
bv %r0(%rp) |
| 296 |
nop |
| 297 |
.exit |
| 298 |
.procend |
| 299 |
.LFE1: |
| 300 |
|
| 301 |
/* void ffi_closure_pa32(void); |
| 302 |
Called with closure argument in %r19 */ |
| 303 |
.export ffi_closure_pa32,code |
| 304 |
.import ffi_closure_inner_pa32,code |
| 305 |
|
| 306 |
.type ffi_closure_pa32, @function |
| 307 |
.LFB2: |
| 308 |
ffi_closure_pa32: |
| 309 |
.proc |
| 310 |
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3 |
| 311 |
.entry |
| 312 |
|
| 313 |
stw %rp, -20(%sp) |
| 314 |
.LCFI20: |
| 315 |
copy %r3, %r1 |
| 316 |
.LCFI21: |
| 317 |
copy %sp, %r3 |
| 318 |
.LCFI22: |
| 319 |
stwm %r1, 64(%sp) |
| 320 |
|
| 321 |
/* Put arguments onto the stack and call ffi_closure_inner. */ |
| 322 |
stw %arg0, -36(%r3) |
| 323 |
stw %arg1, -40(%r3) |
| 324 |
stw %arg2, -44(%r3) |
| 325 |
stw %arg3, -48(%r3) |
| 326 |
|
| 327 |
/* Retrieve closure pointer and real gp. */ |
| 328 |
copy %r19, %arg0 |
| 329 |
ldw 8(%r19), %r19 |
| 330 |
bl ffi_closure_inner_pa32, %r2 |
| 331 |
copy %r3, %arg1 |
| 332 |
|
| 333 |
ldwm -64(%sp), %r3 |
| 334 |
ldw -20(%sp), %rp |
| 335 |
ldw -36(%sp), %ret0 |
| 336 |
bv %r0(%r2) |
| 337 |
ldw -40(%sp), %ret1 |
| 338 |
|
| 339 |
.exit |
| 340 |
.procend |
| 341 |
.LFE2: |
| 342 |
|
| 343 |
.section ".eh_frame",EH_FRAME_FLAGS,@progbits |
| 344 |
.Lframe1: |
| 345 |
.word .LECIE1-.LSCIE1 ;# Length of Common Information Entry |
| 346 |
.LSCIE1: |
| 347 |
.word 0x0 ;# CIE Identifier Tag |
| 348 |
.byte 0x1 ;# CIE Version |
| 349 |
#ifdef __PIC__ |
| 350 |
.ascii "zR\0" ;# CIE Augmentation: 'z' - data, 'R' - DW_EH_PE_... data |
| 351 |
#else |
| 352 |
.ascii "\0" ;# CIE Augmentation |
| 353 |
#endif |
| 354 |
.uleb128 0x1 ;# CIE Code Alignment Factor |
| 355 |
.sleb128 4 ;# CIE Data Alignment Factor |
| 356 |
.byte 0x2 ;# CIE RA Column |
| 357 |
#ifdef __PIC__ |
| 358 |
.uleb128 0x1 ;# Augmentation size |
| 359 |
.byte 0x1b ;# FDE Encoding (DW_EH_PE_pcrel|DW_EH_PE_sdata4) |
| 360 |
#endif |
| 361 |
.byte 0xc ;# DW_CFA_def_cfa |
| 362 |
.uleb128 0x1e |
| 363 |
.uleb128 0x0 |
| 364 |
.align 4 |
| 365 |
.LECIE1: |
| 366 |
.LSFDE1: |
| 367 |
.word .LEFDE1-.LASFDE1 ;# FDE Length |
| 368 |
.LASFDE1: |
| 369 |
.word .LASFDE1-.Lframe1 ;# FDE CIE offset |
| 370 |
#ifdef __PIC__ |
| 371 |
.word .LFB1-. ;# FDE initial location |
| 372 |
#else |
| 373 |
.word .LFB1 ;# FDE initial location |
| 374 |
#endif |
| 375 |
.word .LFE1-.LFB1 ;# FDE address range |
| 376 |
#ifdef __PIC__ |
| 377 |
.uleb128 0x0 ;# Augmentation size: no data |
| 378 |
#endif |
| 379 |
.byte 0x4 ;# DW_CFA_advance_loc4 |
| 380 |
.word .LCFI11-.LFB1 |
| 381 |
.byte 0x83 ;# DW_CFA_offset, column 0x3 |
| 382 |
.uleb128 0x0 |
| 383 |
.byte 0x11 ;# DW_CFA_offset_extended_sf; save r2 at [r30-20] |
| 384 |
.uleb128 0x2 |
| 385 |
.sleb128 -5 |
| 386 |
|
| 387 |
.byte 0x4 ;# DW_CFA_advance_loc4 |
| 388 |
.word .LCFI12-.LCFI11 |
| 389 |
.byte 0xd ;# DW_CFA_def_cfa_register = r3 |
| 390 |
.uleb128 0x3 |
| 391 |
|
| 392 |
.byte 0x4 ;# DW_CFA_advance_loc4 |
| 393 |
.word .LCFI13-.LCFI12 |
| 394 |
.byte 0x84 ;# DW_CFA_offset, column 0x4 |
| 395 |
.uleb128 0x3 |
| 396 |
|
| 397 |
.align 4 |
| 398 |
.LEFDE1: |
| 399 |
|
| 400 |
.LSFDE2: |
| 401 |
.word .LEFDE2-.LASFDE2 ;# FDE Length |
| 402 |
.LASFDE2: |
| 403 |
.word .LASFDE2-.Lframe1 ;# FDE CIE offset |
| 404 |
#ifdef __PIC__ |
| 405 |
.word .LFB2-. ;# FDE initial location |
| 406 |
#else |
| 407 |
.word .LFB2 ;# FDE initial location |
| 408 |
#endif |
| 409 |
.word .LFE2-.LFB2 ;# FDE address range |
| 410 |
#ifdef __PIC__ |
| 411 |
.uleb128 0x0 ;# Augmentation size: no data |
| 412 |
#endif |
| 413 |
.byte 0x4 ;# DW_CFA_advance_loc4 |
| 414 |
.word .LCFI21-.LFB2 |
| 415 |
.byte 0x83 ;# DW_CFA_offset, column 0x3 |
| 416 |
.uleb128 0x0 |
| 417 |
.byte 0x11 ;# DW_CFA_offset_extended_sf |
| 418 |
.uleb128 0x2 |
| 419 |
.sleb128 -5 |
| 420 |
|
| 421 |
.byte 0x4 ;# DW_CFA_advance_loc4 |
| 422 |
.word .LCFI22-.LCFI21 |
| 423 |
.byte 0xd ;# DW_CFA_def_cfa_register = r3 |
| 424 |
.uleb128 0x3 |
| 425 |
|
| 426 |
.align 4 |
| 427 |
.LEFDE2: |
| 428 |
|
| 429 |
#if defined(__ELF__) && defined(__linux__) |
| 430 |
.section .note.GNU-stack,"",%progbits |
| 431 |
#endif |