source: trunk/gcc/libffi/src/arm/ffi.c

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.3 KB
Line 
1/* -----------------------------------------------------------------------
2 ffi.c - Copyright (c) 1998 Cygnus Solutions
3
4 ARM 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 CYGNUS SOLUTIONS 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#include <ffi.h>
27#include <ffi_common.h>
28
29#include <stdlib.h>
30
31/* ffi_prep_args is called by the assembly routine once stack space
32 has been allocated for the function's arguments */
33
34/*@-exportheader@*/
35void ffi_prep_args(char *stack, extended_cif *ecif)
36/*@=exportheader@*/
37{
38 register unsigned int i;
39 register void **p_argv;
40 register char *argp;
41 register ffi_type **p_arg;
42
43 argp = stack;
44
45 if ( ecif->cif->rtype->type == FFI_TYPE_STRUCT ) {
46 *(void **) argp = ecif->rvalue;
47 argp += 4;
48 }
49
50 p_argv = ecif->avalue;
51
52 for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
53 (i != 0);
54 i--, p_arg++)
55 {
56 size_t z;
57
58 /* Align if necessary */
59 if (((*p_arg)->alignment - 1) & (unsigned) argp) {
60 argp = (char *) ALIGN(argp, (*p_arg)->alignment);
61 }
62
63 z = (*p_arg)->size;
64 if (z < sizeof(int))
65 {
66 z = sizeof(int);
67 switch ((*p_arg)->type)
68 {
69 case FFI_TYPE_SINT8:
70 *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv);
71 break;
72
73 case FFI_TYPE_UINT8:
74 *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv);
75 break;
76
77 case FFI_TYPE_SINT16:
78 *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv);
79 break;
80
81 case FFI_TYPE_UINT16:
82 *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv);
83 break;
84
85 case FFI_TYPE_STRUCT:
86 *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
87 break;
88
89 default:
90 FFI_ASSERT(0);
91 }
92 }
93 else if (z == sizeof(int))
94 {
95 *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
96 }
97 else
98 {
99 memcpy(argp, *p_argv, z);
100 }
101 p_argv++;
102 argp += z;
103 }
104
105 return;
106}
107
108/* Perform machine dependent cif processing */
109ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
110{
111 /* Set the return type flag */
112 switch (cif->rtype->type)
113 {
114 case FFI_TYPE_VOID:
115 case FFI_TYPE_STRUCT:
116 case FFI_TYPE_FLOAT:
117 case FFI_TYPE_DOUBLE:
118 cif->flags = (unsigned) cif->rtype->type;
119 break;
120
121 default:
122 cif->flags = FFI_TYPE_INT;
123 break;
124 }
125
126 return FFI_OK;
127}
128
129/*@-declundef@*/
130/*@-exportheader@*/
131extern void ffi_call_SYSV(void (*)(char *, extended_cif *),
132 /*@out@*/ extended_cif *,
133 unsigned, unsigned,
134 /*@out@*/ unsigned *,
135 void (*fn)());
136/*@=declundef@*/
137/*@=exportheader@*/
138
139void ffi_call(/*@dependent@*/ ffi_cif *cif,
140 void (*fn)(),
141 /*@out@*/ void *rvalue,
142 /*@dependent@*/ void **avalue)
143{
144 extended_cif ecif;
145
146 ecif.cif = cif;
147 ecif.avalue = avalue;
148
149 /* If the return value is a struct and we don't have a return */
150 /* value address then we need to make one */
151
152 if ((rvalue == NULL) &&
153 (cif->rtype->type == FFI_TYPE_STRUCT))
154 {
155 /*@-sysunrecog@*/
156 ecif.rvalue = alloca(cif->rtype->size);
157 /*@=sysunrecog@*/
158 }
159 else
160 ecif.rvalue = rvalue;
161
162
163 switch (cif->abi)
164 {
165 case FFI_SYSV:
166 /*@-usedef@*/
167 ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes,
168 cif->flags, ecif.rvalue, fn);
169 /*@=usedef@*/
170 break;
171 default:
172 FFI_ASSERT(0);
173 break;
174 }
175}
Note: See TracBrowser for help on using the repository browser.