1 /* -----------------------------------------------------------------------
2 sysv.S - Copyright (c) 2012 Alexandre K. I. de Mendonca <alexandre.keunecke@gmail.com>
4 Blackfin Foreign Function Interface
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:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
25 ----------------------------------------------------------------------- */
28 #include <fficonfig.h>
35 There is a "feature" in the bfin toolchain that it puts a _ before funcion names
36 that's why the function here it's called _ffi_call_SYSV and not ffi_call_SYSV
38 .global _ffi_call_SYSV;
39 .type _ffi_call_SYSV, STT_FUNC;
43 cif->bytes = R0 (fp+8)
45 ffi_prep_args = R2 (fp+16)
46 ret_type = stack (fp+20)
47 ecif.rvalue = stack (fp+24)
50 There is room for improvement here (we can use temporary registers
51 instead of saving the values in the memory)
53 P5 => Stack pointer (function arguments)
58 FP-16 = SP (parameters area)
60 FP-08 = function return part 1 [R0]
61 FP-04 = function return part 2 [R1]
73 //alocate cif->bytes into the stack
84 //get the addr of prep_args
85 P0 = [P3 + _ffi_prep_args@FUNCDESC_GOT17M4];
88 R0 = [FP-16];//SP (parameter area)
93 //ajust SP so as to allow the user function access the parameters on the stack
94 SP = [FP-16]; //point to function parameters
98 //load user function address
105 For functions returning aggregate values (struct) occupying more than 8 bytes,
106 the caller allocates the return value object on the stack and the address
107 of this object is passed to the callee as a hidden argument in register P0.
121 R0 = [P2+.rettable@GOT17M4];
127 R0 = [P2+.rettable@GOT17M4];
135 #define FFIBFIN_RET_VOID 0
136 #define FFIBFIN_RET_BYTE 1
137 #define FFIBFIN_RET_HALFWORD 2
138 #define FFIBFIN_RET_INT64 3
139 #define FFIBFIN_RET_INT32 4
144 .dd .epilogue - .rettable
145 .dd .rbyte - .rettable;
146 .dd .rhalfword - .rettable;
147 .dd .rint64 - .rettable;
148 .dd .rint32 - .rettable;
161 P0 = [FP+24];// &rvalue
176 .size _ffi_call_SYSV,.-_ffi_call_SYSV;