summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/ppc64-abi-1.c
blob: 8fcb7fd7fae3f10418bb3c85416e6b51edad71ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/* { dg-do run { target { powerpc*-*-* && lp64 } } } */
/* { dg-skip-if "" { *-*-darwin* } { "*" } { "" } } */
/* { dg-options "-O2" } */
#include <stdarg.h>
#include <signal.h>
#include <stdio.h>

/* Testcase to check for ABI compliance of parameter passing
   for the PowerPC64 ABI.  
   Parameter passing of integral and floating point is tested.  */

extern void abort (void);

typedef struct
{
  unsigned long gprs[8];
  double fprs[13];
} reg_parms_t;

reg_parms_t gparms;


/* Testcase could break on future gcc's, if parameter regs
   are changed before this asm.  */

#ifndef __MACH__
#define save_parms(lparms)				\
    asm volatile ("ld 11,gparms@got(2)\n\t"                \
                  "std 3,0(11)\n\t"		        \
	          "std 4,8(11)\n\t"			\
	          "std 5,16(11)\n\t"			\
	          "std 6,24(11)\n\t"			\
	          "std 7,32(11)\n\t"			\
	          "std 8,40(11)\n\t"			\
	          "std 9,48(11)\n\t"			\
	          "std 10,56(11)\n\t"                 \
                  "stfd 1,64(11)\n\t"		        \
	          "stfd 2,72(11)\n\t"			\
	          "stfd 3,80(11)\n\t"			\
	          "stfd 4,88(11)\n\t"			\
	          "stfd 5,96(11)\n\t"			\
	          "stfd 6,104(11)\n\t"			\
	          "stfd 7,112(11)\n\t"			\
	          "stfd 8,120(11)\n\t"			\
	          "stfd 9,128(11)\n\t"			\
	          "stfd 10,136(11)\n\t"			\
	          "stfd 11,144(11)\n\t"			\
	          "stfd 12,152(11)\n\t"                 \
	          "stfd 13,160(11)\n\t":::"11", "memory");  \
                  lparms = gparms;
#else
#define save_parms(lparms)				\
    asm volatile ("ld r11,gparms@got(r2)\n\t"           \
                  "std r3,0(r11)\n\t"		        \
	          "std r4,8(r11)\n\t"			\
	          "std r5,16(r11)\n\t"			\
	          "std r6,24(r11)\n\t"			\
	          "std r7,32(r11)\n\t"			\
	          "std r8,40(r11)\n\t"			\
	          "std r9,48(r11)\n\t"			\
	          "std r10,56(r11)\n\t"                 \
                  "stfd f1,64(r11)\n\t"		        \
	          "stfd f2,72(r11)\n\t"			\
	          "stfd f3,80(r11)\n\t"			\
	          "stfd f4,88(r11)\n\t"			\
	          "stfd f5,96(r11)\n\t"			\
	          "stfd f6,104(r11)\n\t"		\
	          "stfd f7,112(r11)\n\t"		\
	          "stfd f8,120(r11)\n\t"		\
	          "stfd f9,128(r11)\n\t"		\
	          "stfd f10,136(r11)\n\t"		\
	          "stfd f11,144(r11)\n\t"		\
	          "stfd f12,152(r11)\n\t"               \
	          "stfd f13,160(r11)\n\t":::"r11", "memory");  \
                  lparms = gparms;
#endif

/* Stackframe structure relevant for parameter passing.  */
typedef union
{
  double d;
  unsigned long l;
  unsigned int i[2];
} parm_t;

typedef struct sf
{
  struct sf *backchain;
  long a1;
  long a2;
  long a3;
  long a4;
  long a5;
  parm_t slot[100];
} stack_frame_t;


/* Paramter passing.
   s : gpr 3
   l : gpr 4
   d : fpr 1
*/
void __attribute__ ((noinline)) fcld (char *s, long l, double d)
{
  reg_parms_t lparms;
  save_parms (lparms);

  if (s != (char *) lparms.gprs[0])
    abort ();

  if (l != lparms.gprs[1])
    abort ();

  if (d != lparms.fprs[0])
    abort ();
}

/* Paramter passing.
   s : gpr 3
   l : gpr 4
   d : fpr 2
   i : gpr 5
*/
void __attribute__ ((noinline))
fcldi (char *s, long l, double d, signed int i)
{
  reg_parms_t lparms;
  save_parms (lparms);

  if (s != (char *) lparms.gprs[0])
    abort ();

  if (l != lparms.gprs[1])
    abort ();

  if (d != lparms.fprs[0])
    abort ();

  if ((signed long) i != lparms.gprs[3])
    abort ();
}

/* Paramter passing.
   s : gpr 3
   l : gpr 4
   d : fpr 2
   i : gpr 5
*/
void __attribute__ ((noinline))
fcldu (char *s, long l, float d, unsigned int i)
{
  reg_parms_t lparms;
  save_parms (lparms);

  if (s != (char *) lparms.gprs[0])
    abort ();

  if (l != lparms.gprs[1])
    abort ();

  if ((double) d != lparms.fprs[0])
    abort ();

  if ((unsigned long) i != lparms.gprs[3])
    abort ();
}

/* Paramter passing.
   s : gpr 3
   l : slot 1
   d : slot 2
*/

void __attribute__ ((noinline)) fceld (char *s, ...)
{
  stack_frame_t *sp;
  reg_parms_t lparms;
  va_list arg;
  double d;
  long l;
  save_parms (lparms);

  va_start (arg, s);

  if (s != (char *) lparms.gprs[0])
    abort ();

  l = va_arg (arg, long);
  d = va_arg (arg, double);

  /* Go back one frame.  */
  sp = __builtin_frame_address (0);
  sp = sp->backchain;

  if (sp->slot[1].l != l)
    abort ();

  if (sp->slot[2].d != d)
    abort ();
}

/* Paramter passing.
   s : gpr 3
   i : gpr 4
   j : gpr 5
   d : slot 3
   l : slot 4
*/
void __attribute__ ((noinline)) fciiedl (char *s, int i, int j, ...)
{
  stack_frame_t *sp;
  reg_parms_t lparms;
  va_list arg;
  double d;
  long l;
  save_parms (lparms);

  va_start (arg, j);

  if (s != (char *) lparms.gprs[0])
    abort ();

  if ((long) i != lparms.gprs[1])
    abort ();

  if ((long) j != lparms.gprs[2])
    abort ();

  d = va_arg (arg, double);
  l = va_arg (arg, long);

  sp = __builtin_frame_address (0);
  sp = sp->backchain;

  if (sp->slot[3].d != d)
    abort ();

  if (sp->slot[4].l != l)
    abort ();
}

/* 
Parameter     Register     Offset in parameter save area
c             r3           0-7    (not stored in parameter save area)
ff            f1           8-15   (not stored)
d             r5           16-23  (not stored)
ld            f2           24-31  (not stored)
f             r7           32-39  (not stored)
s             r8,r9        40-55  (not stored)
gg            f3           56-63  (not stored)
t             (none)       64-79  (stored in parameter save area)
e             (none)       80-87  (stored)
hh            f4           88-95  (stored)  

*/

typedef struct
{
  int a;
  double dd;
} sparm;

typedef union
{
  int i[2];
  long l;
  double d;
} double_t;

/* Example from ABI documentation with slight changes.
   Paramter passing. 
   c  : gpr 3
   ff : fpr 1
   d  : gpr 5
   ld : fpr 2
   f  : gpr 7
   s  : gpr 8 - 9
   gg : fpr 3
   t  : save area offset 64 - 79 
   e  : save area offset 80 - 88
   hh : fpr 4   
*/

void __attribute__ ((noinline))
fididisdsid (int c, double ff, int d, double ld, int f,
	     sparm s, double gg, sparm t, int e, double hh)
{
  stack_frame_t *sp;
  reg_parms_t lparms;
  double_t dx, dy;

  save_parms (lparms);

  /* Parm 0: int.  */
  if ((long) c != lparms.gprs[0])
    abort ();

  /* Parm 1: double.  */
  if (ff != lparms.fprs[0])
    abort ();

  /* Parm 2: int.  */
  if ((long) d != lparms.gprs[2])
    abort ();

  /* Parm 3: double.  */
  if (ld != lparms.fprs[1])
    abort ();

  /* Parm 4: int.  */
  if ((long) f != lparms.gprs[4])
    abort ();

  /* Parm 5: struct sparm.  */
  dx.l = lparms.gprs[5];
  dy.l = lparms.gprs[6];

  if (s.a != dx.i[0])
    abort ();
  if (s.dd != dy.d)
    abort ();

  /* Parm 6: double.  */
  if (gg != lparms.fprs[2])
    abort ();

  sp = __builtin_frame_address (0);
  sp = sp->backchain;

  /* Parm 7: struct sparm.  */
  dx.l = sp->slot[8].l;
  dy.l = sp->slot[9].l;
  if (t.a != dx.i[0])
    abort ();
  if (t.dd != dy.d)
    abort ();

  /* Parm 8: int.  */
  if (e != sp->slot[10].l)
    abort ();

  /* Parm 9: double.  */

  if (hh != lparms.fprs[3])
    abort ();
}

int
main ()
{
  char *s = "ii";

  fcld (s, 1, 1.0);
  fcldi (s, 1, 1.0, -2);
  fcldu (s, 1, 1.0, 2);
  fceld (s, 1, 1.0);
  fciiedl (s, 1, 2, 1.0, 3);
  fididisdsid (1, 1.0, 2, 2.0, -1, (sparm)
	       {
	       3, 3.0}, 4.0, (sparm)
	       {
	       5, 5.0}, 6, 7.0);
  return 0;
}