1 /* -----------------------------------------------------------------------
2 sysv.S - Copyright (c) 2004 Simon Posnjak
3 Copyright (c) 2005 Axis Communications AB
5 CRIS 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, 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 SIMON POSNJAK 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 ----------------------------------------------------------------------- */
29 #define CONCAT(x,y) x ## y
30 #define XCONCAT(x,y) CONCAT (x, y)
31 #define L(x) XCONCAT (__USER_LABEL_PREFIX__, x)
35 ;; OK, when we get called we should have this (according to
36 ;; AXIS ETRAX 100LX Programmer's Manual chapter 6.3).
38 ;; R10: ffi_prep_args (func. pointer)
43 ;; sp+4: fn (function pointer to the function that we need to call)
45 .globl L(ffi_call_SYSV)
46 .type L(ffi_call_SYSV),@function
47 .hidden L(ffi_call_SYSV)
50 ;; Save the regs to the stack.
52 ;; Used for stack pointer saving.
54 ;; Used for function address pointer.
56 ;; Used for stack pointer saving.
58 ;; We save fig->flags to stack we will need them after we
62 ;; Saving current stack pointer.
66 ;; Move address of ffi_prep_args to r13.
69 ;; Make room on the stack for the args of fn.
72 ;; Function void ffi_prep_args(char *stack, extended_cif *ecif) parameters are:
73 ;; r10 <-- stack pointer
74 ;; r11 <-- &ecif (already there)
80 ;; Save the size of the structures which are passed on stack.
83 ;; Move first four args in to r10..r13.
89 ;; Adjust the stack and check if any parameters are given on stack.
97 go_on_no_params_on_stack:
101 ;; Discover if we need to put rval address in to r9.
103 cmpq FFI_TYPE_STRUCT,$r7
107 ;; Move rval address to $r9.
111 ;; Move address of The Function in to r7.
114 ;; Call The Function.
120 ;; Load rval type (fig->flags) in to r13.
124 cmpq FFI_TYPE_VOID,$r13
127 cmpq FFI_TYPE_STRUCT,$r13
130 cmpq FFI_TYPE_DOUBLE,$r13
131 beq return_double_or_longlong
133 cmpq FFI_TYPE_UINT64,$r13
134 beq return_double_or_longlong
136 cmpq FFI_TYPE_SINT64,$r13
137 beq return_double_or_longlong
140 ;; Just return the 32 bit value.
144 return_double_or_longlong:
145 ;; Load half of the rval to r10 and the other half to r11.
154 ;; Load the rval to r10.
164 .size ffi_call_SYSV,.-ffi_call_SYSV
166 /* Save R10..R13 into an array, somewhat like varargs. Copy the next
167 argument too, to simplify handling of any straddling parameter.
168 Save R9 and SP after those. Jump to function handling the rest.
169 Since this is a template, copied and the main function filled in by
172 .globl L(ffi_cris_trampoline_template)
173 .type L(ffi_cris_trampoline_template),@function
174 .hidden L(ffi_cris_trampoline_template)
176 L(ffi_cris_trampoline_template):
178 /* The value we get for "PC" is right after the prefix instruction,
179 two bytes from the beginning, i.e. 0b+2. */
180 move.d $r10,[$pc+2f-(0b+2)]
191 subq FFI_CRIS_TRAMPOLINE_DATA_PART_SIZE,$r10
196 .size ffi_cris_trampoline_template,.-0b
198 /* This macro create a constant usable as "extern const int \name" in
199 C from within libffi, when \name has no prefix decoration. */
201 .macro const name,value
210 /* Constants for offsets within the trampoline. We could do this with
211 just symbols, avoiding memory contents and memory accesses, but the
212 C usage code would look a bit stranger. */
214 const L(ffi_cris_trampoline_fn_offset),2b-4-0b
215 const L(ffi_cris_trampoline_closure_offset),3b-4-0b