| 1 |
/* ----------------------------------------------------------------------- |
| 2 |
eabi.S - Copyright (c) 2012, 2013 Anthony Green |
| 3 |
|
| 4 |
Moxie Assembly glue. |
| 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 THE AUTHOR 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 |
|
| 30 |
.globl ffi_prep_args_EABI |
| 31 |
|
| 32 |
.text |
| 33 |
.p2align 4 |
| 34 |
.globl ffi_call_EABI |
| 35 |
.type ffi_call_EABI, @function |
| 36 |
|
| 37 |
# $r0 : ffi_prep_args |
| 38 |
# $r1 : &ecif |
| 39 |
# $r2 : cif->bytes |
| 40 |
# $r3 : fig->flags |
| 41 |
# $r4 : ecif.rvalue |
| 42 |
# $r5 : fn |
| 43 |
|
| 44 |
ffi_call_EABI: |
| 45 |
push $sp, $r6 |
| 46 |
push $sp, $r7 |
| 47 |
push $sp, $r8 |
| 48 |
dec $sp, 24 |
| 49 |
|
| 50 |
/* Store incoming args on stack. */ |
| 51 |
sto.l 0($sp), $r0 /* ffi_prep_args */ |
| 52 |
sto.l 4($sp), $r1 /* ecif */ |
| 53 |
sto.l 8($sp), $r2 /* bytes */ |
| 54 |
sto.l 12($sp), $r3 /* flags */ |
| 55 |
sto.l 16($sp), $r4 /* &rvalue */ |
| 56 |
sto.l 20($sp), $r5 /* fn */ |
| 57 |
|
| 58 |
/* Call ffi_prep_args. */ |
| 59 |
mov $r6, $r4 /* Save result buffer */ |
| 60 |
mov $r7, $r5 /* Save the target fn */ |
| 61 |
mov $r8, $r3 /* Save the flags */ |
| 62 |
sub $sp, $r2 /* Allocate stack space */ |
| 63 |
mov $r0, $sp /* We can stomp over $r0 */ |
| 64 |
/* $r1 is already set up */ |
| 65 |
jsra ffi_prep_args |
| 66 |
|
| 67 |
/* Load register arguments. */ |
| 68 |
ldo.l $r0, 0($sp) |
| 69 |
ldo.l $r1, 4($sp) |
| 70 |
ldo.l $r2, 8($sp) |
| 71 |
ldo.l $r3, 12($sp) |
| 72 |
ldo.l $r4, 16($sp) |
| 73 |
ldo.l $r5, 20($sp) |
| 74 |
|
| 75 |
/* Call the target function. */ |
| 76 |
jsr $r7 |
| 77 |
|
| 78 |
ldi.l $r7, 0xffffffff |
| 79 |
cmp $r8, $r7 |
| 80 |
beq retstruct |
| 81 |
|
| 82 |
ldi.l $r7, 4 |
| 83 |
cmp $r8, $r7 |
| 84 |
bgt ret2reg |
| 85 |
|
| 86 |
st.l ($r6), $r0 |
| 87 |
jmpa retdone |
| 88 |
|
| 89 |
ret2reg: |
| 90 |
st.l ($r6), $r0 |
| 91 |
sto.l 4($r6), $r1 |
| 92 |
|
| 93 |
retstruct: |
| 94 |
retdone: |
| 95 |
/* Return. */ |
| 96 |
ldo.l $r6, -4($fp) |
| 97 |
ldo.l $r7, -8($fp) |
| 98 |
ldo.l $r8, -12($fp) |
| 99 |
ret |
| 100 |
.size ffi_call_EABI, .-ffi_call_EABI |
| 101 |
|