1
#ifndef _avcall_hppa_c /*-*- C -*-*/
4
Copyright 1993 Bill Triggs, <Bill.Triggs@inrialpes.fr>
5
Copyright 1995-1999 Bruno Haible, <bruno@clisp.org>
7
This is free software distributed under the GNU General Public
8
Licence described in the file COPYING. Contact the author if
9
you don't have this or can't live with it. There is ABSOLUTELY
10
NO WARRANTY, explicit or implied, on this software.
12
/*----------------------------------------------------------------------
13
!!! THIS ROUTINE MUST BE COMPILED gcc -O !!!
15
Foreign function interface for a HP Precision Architecture 1.0 with gcc
17
This calls a C function with an argument list built up using macros
20
HPPA Argument Passing Conventions:
22
All arguments, except the first 4 words, are passed on the stack
23
- growing down! - with word alignment. Doubles take two words and force
24
double alignment. Small structures args are passed as true structures
25
embedded in the argument stack. They force double alignment and - if they
26
don't fit entirely in the 4 register words - are passed in memory.
27
The first 2 words are passed like this:
28
%r26 = first integer arg, %r25 = second integer arg, or
29
%r26 = high word of double arg, %r25 = low word of double arg.
30
Similarly for the next 2 words, passed in %r24 and %r23.
31
Note that other calling conventions would be in effect if we would call
32
an explicitly named function!
34
To return a structure, the called function copies the return value to
35
the address supplied in register "%r28".
37
It is forbidden to modify the stack pointer.
39
Compile this routine with gcc -O2 -fomit-frame-pointer to get the right
40
register variables, then replace the -120 in the second save statement
41
"stw %r3,-120(0,%r30)" by -1060, or use the assembler version.
42
----------------------------------------------------------------------*/
43
#include "avcall.h.in"
45
#define RETURN(TYPE,VAL) (*(TYPE*)l->raddr = (TYPE)(VAL))
47
/* This declaration tells gcc not to modify %r28. */
48
register __avword* sret __asm__("%r28"); /* structure return pointer */
51
__builtin_avcall(av_alist* l)
53
register __avword* sp __asm__("%r30"); /* C names for registers */
54
register float fret __asm__("%fr4");
55
register double dret __asm__("%fr4");
56
/*register __avword iret1 __asm__("%r28"); */
57
register __avword iret2 __asm__("%r29");
59
__avword space[__AV_ALIST_WORDS]; /* space for callee's stack frame */
60
__avword* argframe = sp - 8; /* stack offset for argument list */
61
int arglen = &l->args[__AV_ALIST_WORDS] - l->aptr;
66
for (i = -arglen; i < -4; i++) /* push function args onto stack */
67
argframe[i] = l->args[__AV_ALIST_WORDS+i];
70
if (l->rtype == __AVstruct) /* push struct return address */
73
/* call function, pass 4 args in registers */
74
i = (*l->func)(l->args[__AV_ALIST_WORDS-1], l->args[__AV_ALIST_WORDS-2],
75
l->args[__AV_ALIST_WORDS-3], l->args[__AV_ALIST_WORDS-4]);
77
/* save return value */
78
if (l->rtype == __AVvoid) {
80
if (l->rtype == __AVword) {
83
if (l->rtype == __AVchar) {
86
if (l->rtype == __AVschar) {
87
RETURN(signed char, i);
89
if (l->rtype == __AVuchar) {
90
RETURN(unsigned char, i);
92
if (l->rtype == __AVshort) {
95
if (l->rtype == __AVushort) {
96
RETURN(unsigned short, i);
98
if (l->rtype == __AVint) {
101
if (l->rtype == __AVuint) {
102
RETURN(unsigned int, i);
104
if (l->rtype == __AVlong) {
107
if (l->rtype == __AVulong) {
108
RETURN(unsigned long, i);
110
if (l->rtype == __AVlonglong || l->rtype == __AVulonglong) {
111
((__avword*)l->raddr)[0] = i;
112
((__avword*)l->raddr)[1] = iret2;
114
if (l->rtype == __AVfloat) {
117
if (l->rtype == __AVdouble) {
118
RETURN(double, dret);
120
if (l->rtype == __AVvoidp) {
123
if (l->rtype == __AVstruct) {
124
if (l->flags & __AV_PCC_STRUCT_RETURN) {
125
/* pcc struct return convention: need a *(TYPE*)l->raddr = *(TYPE*)i; */
126
if (l->rsize == sizeof(char)) {
127
RETURN(char, *(char*)i);
129
if (l->rsize == sizeof(short)) {
130
RETURN(short, *(short*)i);
132
if (l->rsize == sizeof(int)) {
133
RETURN(int, *(int*)i);
135
if (l->rsize == sizeof(double)) {
136
((int*)l->raddr)[0] = ((int*)i)[0];
137
((int*)l->raddr)[1] = ((int*)i)[1];
139
int n = (l->rsize + sizeof(__avword)-1)/sizeof(__avword);
141
((__avword*)l->raddr)[n] = ((__avword*)i)[n];
144
/* normal struct return convention */
145
if (l->flags & __AV_SMALL_STRUCT_RETURN) {
146
if (l->flags & __AV_OLDGCC_STRUCT_RETURN) {
147
/* gcc <= 2.6.3 returns structs of size 1,2,4 in registers. */
148
if (l->rsize == sizeof(char)) {
151
if (l->rsize == sizeof(short)) {
154
if (l->rsize == sizeof(int)) {
158
/* cc, c89 and gcc >= 2.7 return structs of size <= 8 in registers. */
160
((unsigned char *)l->raddr)[0] = (unsigned char)(i);
163
((unsigned char *)l->raddr)[0] = (unsigned char)(i>>8);
164
((unsigned char *)l->raddr)[1] = (unsigned char)(i);
167
((unsigned char *)l->raddr)[0] = (unsigned char)(i>>16);
168
((unsigned char *)l->raddr)[1] = (unsigned char)(i>>8);
169
((unsigned char *)l->raddr)[2] = (unsigned char)(i);
172
((unsigned char *)l->raddr)[0] = (unsigned char)(i>>24);
173
((unsigned char *)l->raddr)[1] = (unsigned char)(i>>16);
174
((unsigned char *)l->raddr)[2] = (unsigned char)(i>>8);
175
((unsigned char *)l->raddr)[3] = (unsigned char)(i);
178
((unsigned char *)l->raddr)[0] = (unsigned char)(i>>24);
179
((unsigned char *)l->raddr)[1] = (unsigned char)(i>>16);
180
((unsigned char *)l->raddr)[2] = (unsigned char)(i>>8);
181
((unsigned char *)l->raddr)[3] = (unsigned char)(i);
182
((unsigned char *)l->raddr)[4] = (unsigned char)(iret2);
185
((unsigned char *)l->raddr)[0] = (unsigned char)(i>>24);
186
((unsigned char *)l->raddr)[1] = (unsigned char)(i>>16);
187
((unsigned char *)l->raddr)[2] = (unsigned char)(i>>8);
188
((unsigned char *)l->raddr)[3] = (unsigned char)(i);
189
((unsigned char *)l->raddr)[4] = (unsigned char)(iret2>>8);
190
((unsigned char *)l->raddr)[5] = (unsigned char)(iret2);
193
((unsigned char *)l->raddr)[0] = (unsigned char)(i>>24);
194
((unsigned char *)l->raddr)[1] = (unsigned char)(i>>16);
195
((unsigned char *)l->raddr)[2] = (unsigned char)(i>>8);
196
((unsigned char *)l->raddr)[3] = (unsigned char)(i);
197
((unsigned char *)l->raddr)[4] = (unsigned char)(iret2>>16);
198
((unsigned char *)l->raddr)[5] = (unsigned char)(iret2>>8);
199
((unsigned char *)l->raddr)[6] = (unsigned char)(iret2);
202
((unsigned char *)l->raddr)[0] = (unsigned char)(i>>24);
203
((unsigned char *)l->raddr)[1] = (unsigned char)(i>>16);
204
((unsigned char *)l->raddr)[2] = (unsigned char)(i>>8);
205
((unsigned char *)l->raddr)[3] = (unsigned char)(i);
206
((unsigned char *)l->raddr)[4] = (unsigned char)(iret2>>24);
207
((unsigned char *)l->raddr)[5] = (unsigned char)(iret2>>16);
208
((unsigned char *)l->raddr)[6] = (unsigned char)(iret2>>8);
209
((unsigned char *)l->raddr)[7] = (unsigned char)(iret2);
218
#endif /*_avcall_hppa_c */