| 1 |
/* ----------------------------------------------------------------------- |
| 2 |
sysv.S - Copyright (c) 2004 Renesas Technology |
| 3 |
|
| 4 |
M32R 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 |
/* XXX these lose for some platforms, I'm sure. */ |
| 33 |
#define CNAME(x) x |
| 34 |
#define ENTRY(x) .globl CNAME(x)! .type CNAME(x),%function! CNAME(x): |
| 35 |
#endif |
| 36 |
|
| 37 |
.text |
| 38 |
|
| 39 |
/* R0: ffi_prep_args */ |
| 40 |
/* R1: &ecif */ |
| 41 |
/* R2: cif->bytes */ |
| 42 |
/* R3: fig->flags */ |
| 43 |
/* sp+0: ecif.rvalue */ |
| 44 |
/* sp+4: fn */ |
| 45 |
|
| 46 |
/* This assumes we are using gas. */ |
| 47 |
ENTRY(ffi_call_SYSV) |
| 48 |
/* Save registers. */ |
| 49 |
push fp |
| 50 |
push lr |
| 51 |
push r3 |
| 52 |
push r2 |
| 53 |
push r1 |
| 54 |
push r0 |
| 55 |
mv fp, sp |
| 56 |
|
| 57 |
/* Make room for all of the new args. */ |
| 58 |
sub sp, r2 |
| 59 |
|
| 60 |
/* Place all of the ffi_prep_args in position. */ |
| 61 |
mv lr, r0 |
| 62 |
mv r0, sp |
| 63 |
/* R1 already set. */ |
| 64 |
|
| 65 |
/* And call. */ |
| 66 |
jl lr |
| 67 |
|
| 68 |
/* Move first 4 parameters in registers... */ |
| 69 |
ld r0, @(0,sp) |
| 70 |
ld r1, @(4,sp) |
| 71 |
ld r2, @(8,sp) |
| 72 |
ld r3, @(12,sp) |
| 73 |
|
| 74 |
/* ...and adjust the stack. */ |
| 75 |
ld lr, @(8,fp) |
| 76 |
cmpi lr, #16 |
| 77 |
bc adjust_stack |
| 78 |
ldi lr, #16 |
| 79 |
adjust_stack: |
| 80 |
add sp, lr |
| 81 |
|
| 82 |
/* Call the function. */ |
| 83 |
ld lr, @(28,fp) |
| 84 |
jl lr |
| 85 |
|
| 86 |
/* Remove the space we pushed for the args. */ |
| 87 |
mv sp, fp |
| 88 |
|
| 89 |
/* Load R2 with the pointer to storage for the return value. */ |
| 90 |
ld r2, @(24,sp) |
| 91 |
|
| 92 |
/* Load R3 with the return type code. */ |
| 93 |
ld r3, @(12,sp) |
| 94 |
|
| 95 |
/* If the return value pointer is NULL, assume no return value. */ |
| 96 |
beqz r2, epilogue |
| 97 |
|
| 98 |
/* Return INT. */ |
| 99 |
ldi r4, #FFI_TYPE_INT |
| 100 |
bne r3, r4, return_double |
| 101 |
st r0, @r2 |
| 102 |
bra epilogue |
| 103 |
|
| 104 |
return_double: |
| 105 |
/* Return DOUBLE or LONGDOUBLE. */ |
| 106 |
ldi r4, #FFI_TYPE_DOUBLE |
| 107 |
bne r3, r4, epilogue |
| 108 |
st r0, @r2 |
| 109 |
st r1, @(4,r2) |
| 110 |
|
| 111 |
epilogue: |
| 112 |
pop r0 |
| 113 |
pop r1 |
| 114 |
pop r2 |
| 115 |
pop r3 |
| 116 |
pop lr |
| 117 |
pop fp |
| 118 |
jmp lr |
| 119 |
|
| 120 |
.ffi_call_SYSV_end: |
| 121 |
.size CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV) |