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