about summary refs log tree commit diff
path: root/sysdeps/ia64/dl-trampoline.S
blob: 11e86932c75d5b6b57d6158fa93e75a751a64e69 (plain) (blame)
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/* PLT trampolines.  ia64 version.
   Copyright (C) 2005-2021 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <https://www.gnu.org/licenses/>.  */

#include <sysdep.h>
#undef ret

/*
   This code is used in dl-runtime.c to call the `_dl_fixup' function
   and then redirect to the address it returns. `_dl_fixup()' takes two
   arguments, however _dl_profile_fixup() takes five.

   The ABI specifies that we will never see more than 8 input
   registers to a function call, thus it is safe to simply allocate
   those, and simpler than playing stack games.  */

/* Used to save and restore 8 incoming fp registers */
#define RESOLVE_FRAME_SIZE (16*8)

ENTRY(_dl_runtime_resolve)
	{ .mmi
	  .prologue
	  .save ar.pfs, r40
	  alloc loc0 = ar.pfs, 8, 6, 2, 0
	  /* Use the 16 byte scratch area. r2 will start at f8 and
	     r3 will start at f9.  */
	  adds r2 = -(RESOLVE_FRAME_SIZE - 16), r12
	  adds r3 = -(RESOLVE_FRAME_SIZE - 32), r12
	}
	{ .mii
	  .fframe RESOLVE_FRAME_SIZE
	  adds r12 = -RESOLVE_FRAME_SIZE, r12
	  .save rp, loc1
	  mov loc1 = b0
	  .body
	  mov loc2 = r8		/* preserve struct value register */
	  ;;
	}
	{ .mii
	  mov loc3 = r9		/* preserve language specific register */
	  mov loc4 = r10	/* preserve language specific register */
	  mov loc5 = r11	/* preserve language specific register */
	}
	{ .mmi
	  stf.spill [r2] = f8, 32
	  stf.spill [r3] = f9, 32
	  mov out0 = r16
	  ;;
	}
	{ .mmi
	  stf.spill [r2] = f10, 32
	  stf.spill [r3] = f11, 32
	  shl out1 = r15, 4
	  ;;
	}
	{ .mmi
	  stf.spill [r2] = f12, 32
	  stf.spill [r3] = f13, 32
	  /* Relocation record is 24 byte. */
	  shladd out1 = r15, 3, out1
	  ;;
	}
	{ .mmb
	  stf.spill [r2] = f14
	  stf.spill [r3] = f15
	  br.call.sptk.many b0 = _dl_fixup
	}
	{ .mii
	  /* Skip the 16byte scratch area.  */
	  adds r2 = 16, r12
	  adds r3 = 32, r12
	  mov b6 = ret0
	  ;;
	}
	{ .mmi
	  ldf.fill f8 = [r2], 32
	  ldf.fill f9 = [r3], 32
	  mov b0 = loc1
	  ;;
	}
	{ .mmi
	  ldf.fill f10 = [r2], 32
	  ldf.fill f11 = [r3], 32
	  mov gp = ret1
	  ;;
	}
	{ .mmi
	  ldf.fill f12 = [r2], 32
	  ldf.fill f13 = [r3], 32
	  mov ar.pfs = loc0
	  ;;
	}
	{ .mmi
	  ldf.fill f14 = [r2], 32
	  ldf.fill f15 = [r3], 32
	  .restore sp		/* pop the unwind frame state */
	  adds r12 = RESOLVE_FRAME_SIZE, r12
	  ;;
	}
	{ .mii
	  mov r9 = loc3		/* restore language specific register */
	  mov r10 = loc4	/* restore language specific register */
	  mov r11 = loc5	/* restore language specific register */
	}
	{ .mii
	  mov r8 = loc2		/* restore struct value register */
	  ;;
	}
	/* An alloc is needed for the break system call to work.
	   We don't care about the old value of the pfs register.  */
	{ .mmb
	  .prologue
	  .body
	  alloc r2 = ar.pfs, 0, 0, 8, 0
	  br.sptk.many b6
	  ;;
	}
END(_dl_runtime_resolve)


/* The fourth argument to _dl_profile_fixup and the third one to
   _dl_audit_pltexit are a pointer to La_ia64_regs:

   8byte r8
   8byte r9
   8byte r10
   8byte r11
   8byte in0
   8byte in1
   8byte in2
   8byte in3
   8byte in4
   8byte in5
   8byte in6
   8byte in7
   16byte f8
   16byte f9
   16byte f10
   16byte f11
   16byte f12
   16byte f13
   16byte f14
   16byte f15
   8byte ar.unat
   8byte sp

   The fifth argument to _dl_profile_fixup is a pointer to long int.
   The fourth argument to _dl_audit_pltexit is a pointer to
   La_ia64_retval:

   8byte r8
   8byte r9
   8byte r10
   8byte r11
   16byte f8
   16byte f9
   16byte f10
   16byte f11
   16byte f12
   16byte f13
   16byte f14
   16byte f15

  Since stack has to be 16 byte aligned, the stack allocation is in
  16byte increment. Before calling _dl_profile_fixup, the stack will
  look like

  psp	new frame_size
  +16	La_ia64_regs
  sp	scratch

 */

#define PLTENTER_FRAME_SIZE (4*8 + 8*8 + 8*16 + 2*8 + 16)
#define PLTEXIT_FRAME_SIZE (PLTENTER_FRAME_SIZE + 4*8 + 8*16)

#ifndef PROF
ENTRY(_dl_runtime_profile)
	{ .mii
	  .prologue
	  .save ar.pfs, r40
	  alloc loc0 = ar.pfs, 8, 12, 8, 0
	  .vframe loc10
	  mov loc10 = r12
	  .save rp, loc1
	  mov loc1 = b0
	}
	{ .mii
	  .save ar.unat, r17
	  mov r17 = ar.unat
	  .save ar.lc, loc6
	  mov loc6 = ar.lc
	  mov loc11 = gp
	}
	{ .mii
	  .body
	  /* There is a 16 byte scratch area. r2 will start at r8 and
	     r3 will start at r9 for La_ia64_regs.  */
	  adds r2 = -(PLTENTER_FRAME_SIZE - 16), r12
	  adds r3 = -(PLTENTER_FRAME_SIZE - 24), r12
	  adds r12 = -PLTENTER_FRAME_SIZE, r12
	  ;;
	}
	{ .mmi
	  st8 [r2] = r8, 16;
	  st8 [r3] = r9, 16;
	  mov out2 = b0		/* needed by _dl_fixup_profile */
	  ;;
	}
	{ .mmi
	  st8 [r2] = r10, 16;
	  st8 [r3] = r11, 16;
	  adds out3 = 16, r12	/* pointer to La_ia64_regs */
	  ;;
	}
	{ .mmi
	  .mem.offset 0, 0
	  st8.spill [r2] = in0, 16
	  .mem.offset 8, 0
	  st8.spill [r3] = in1, 16
	  mov out4 = loc10	/* pointer to new frame size  */
	  ;;
	}
	{ .mmi
	  .mem.offset 0, 0
	  st8.spill [r2] = in2, 16
	  .mem.offset 8, 0
	  st8.spill [r3] = in3, 16
	  mov loc2 = r8		/* preserve struct value register */
	  ;;
	}
	{ .mmi
	  .mem.offset 0, 0
	  st8.spill [r2] = in4, 16
	  .mem.offset 8, 0
	  st8.spill [r3] = in5, 16
	  mov loc3 = r9		/* preserve language specific register */
	  ;;
	}
	{ .mmi
	  .mem.offset 0, 0
	  st8 [r2] = in6, 16
	  .mem.offset 8, 0
	  st8 [r3] = in7, 24	/* adjust for f9 */
	  mov loc4 = r10	/* preserve language specific register */
	  ;;
	}
	{ .mii
	  mov r18 = ar.unat	/* save it in La_ia64_regs */
	  mov loc7 = out3	/* save it for _dl_audit_pltexit */
	  mov loc5 = r11	/* preserve language specific register */
	}
	{ .mmi
	  stf.spill [r2] = f8, 32
	  stf.spill [r3] = f9, 32
	  mov out0 = r16	/* needed by _dl_fixup_profile */
	  ;;
	}
	{ .mii
	  mov ar.unat = r17	/* restore it for function call */
	  mov loc8 = r16	/* save it for _dl_audit_pltexit */
	  nop.i 0x0
	}
	{ .mmi
	  stf.spill [r2] = f10, 32
	  stf.spill [r3] = f11, 32
	  shl out1 = r15, 4
	  ;;
	}
	{ .mmi
	  stf.spill [r2] = f12, 32
	  stf.spill [r3] = f13, 32
	  /* Relocation record is 24 byte. */
	  shladd out1 = r15, 3, out1
	  ;;
	}
	{ .mmi
	  stf.spill [r2] = f14, 32
	  stf.spill [r3] = f15, 24
	  mov loc9 = out1	/* save it for _dl_audit_pltexit */
	  ;;
	}
	{ .mmb
	  st8 [r2] = r18	/* store ar.unat */
	  st8 [r3] = loc10	/* store sp */
	  br.call.sptk.many b0 = _dl_profile_fixup
	}
	{ .mii
	  /* Skip the 16byte scratch area, 4 language specific GRs and
	     8 incoming GRs to restore incoming fp registers.  */
	  adds r2 = (4*8 + 8*8 + 16), r12
	  adds r3 = (4*8 + 8*8 + 32), r12
	  mov b6 = ret0
	  ;;
	}
	{ .mmi
	  ldf.fill f8 = [r2], 32
	  ldf.fill f9 = [r3], 32
	  mov gp = ret1
	  ;;
	}
	{ .mmi
	  ldf.fill f10 = [r2], 32
	  ldf.fill f11 = [r3], 32
	  mov r8 = loc2		/* restore struct value register */
	  ;;
	}
	{ .mmi
	  ldf.fill f12 = [r2], 32
	  ldf.fill f13 = [r3], 32
	  mov r9 = loc3		/* restore language specific register */
	  ;;
	}
	{ .mmi
	  ldf.fill f14 = [r2], 32
	  ldf.fill f15 = [r3], 32
	  mov r10 = loc4	/* restore language specific register */
	  ;;
	}
	{ .mii
	  ld8 r15 = [loc10]	/* load the new frame size */
	  mov r11 = loc5	/* restore language specific register */
	  ;;
	  cmp.eq p6, p7 = -1, r15
	  ;;
	}
	{ .mii
(p7)	  cmp.eq p8, p9 = 0, r15
(p6)	  mov b0 = loc1
(p6)	  mov ar.lc = loc6
	}
	{ .mib
	  nop.m 0x0
(p6)	  mov ar.pfs = loc0
(p6)	  br.cond.dptk.many .Lresolved
	  ;;
	}

	/* At this point, the stack looks like

	  +psp	free
	  +16	La_ia64_regs
	  sp	scratch

	  We need to keep the current stack and call the resolved
	  function by copying the r15 byte from sp + PLTENTER_FRAME_SIZE
	  + 16 (scratch area) to sp + 16 (scratch area). Since stack
	  has to be 16byte aligned, we around r15 up to 16byte.  */

	{ .mbb
(p9)	  adds r15 = 15, r15
(p8)	  br.cond.dptk.many .Lno_new_frame
	  nop.b 0x0
	  ;;
	}
	{ .mmi
	  and r15 = -16, r15
	  ;;
	  /* We don't copy the 16byte scatch area. Prepare r16/r17 as
	     destination.  */
	  sub r16 = r12, r15
	  sub r17 = r12, r15
	  ;;
	}
	{ .mii
	  adds r16 = 16, r16
	  adds r17 = 24, r17
	  sub r12 = r12, r15		/* Adjust stack  */
	  ;;
	}
	{ .mii
	  nop.m 0x0
	  shr r15 = r15, 4
	  ;;
	  adds r15 = -1, r15
	  ;;
	}
	{ .mii
	  /* Skip the 16byte scatch area. Prepare r2/r3 as source.  */
	  adds r2 = 16, loc10
	  adds r3 = 24, loc10
	  mov ar.lc = r15
	  ;;
	}
.Lcopy:
	{ .mmi
	  ld8 r18 = [r2], 16
	  ld8 r19 = [r3], 16
	  nop.i 0x0
	  ;;
	}
	{ .mmb
	  st8 [r16] = r18, 16
	  st8 [r17] = r19, 16
	  br.cloop.sptk.few .Lcopy
	}
.Lno_new_frame:
	{ .mii
	  mov out0 = in0
	  mov out1 = in1
	  mov out2 = in2
	}
	{ .mii
	  mov out3 = in3
	  mov out4 = in4
	  mov out5 = in5
	}
	{ .mib
	  mov out6 = in6
	  mov out7 = in7
	  /* Call the resolved function  */
	  br.call.sptk.many b0 = b6
	}
	{ .mii
	  /* Prepare stack for _dl_audit_pltexit. Loc10 has the original
	     stack pointer.  */
	  adds r12 = -PLTEXIT_FRAME_SIZE, loc10
	  adds r2 = -(PLTEXIT_FRAME_SIZE - 16), loc10
	  adds r3 = -(PLTEXIT_FRAME_SIZE - 24), loc10
	  ;;
	}
	{ .mmi
	  /* Load all possible return values into buffer.  */
	  st8 [r2] = r8, 16
	  st8 [r3] = r9, 16
	  mov out0 = loc8
	  ;;
	}
	{ .mmi
	  st8 [r2] = r10, 16
	  st8 [r3] = r11, 24
	  mov out1 = loc9
	  ;;
	}
	{ .mmi
	  stf.spill [r2] = f8, 32
	  stf.spill [r3] = f9, 32
	  mov out2 = loc7		/* Pointer to La_ia64_regs */
	  ;;
	}
	{ .mmi
	  stf.spill [r2] = f10, 32
	  stf.spill [r3] = f11, 32
	  adds out3 = 16, r12		/* Pointer to La_ia64_retval */
	  ;;
	}
	{ .mmi
	  stf.spill [r2] = f12, 32
	  stf.spill [r3] = f13, 32
	  /* We need to restore gp for _dl_audit_pltexit. */
	  mov gp = loc11
	  ;;
	}
	{ .mmb
	  stf.spill [r2] = f14
	  stf.spill [r3] = f15
	  br.call.sptk.many b0 = _dl_audit_pltexit
	}
	{ .mmi
	  /* Load all the non-floating and floating return values. Skip
	     the 16byte scratch area.  */
	  adds r2 = 16, r12
	  adds r3 = 24, r12
	  nop.i 0x0
	  ;;
	}
	{ .mmi
	  ld8 r8 = [r2], 16
	  ld8 r9 = [r3], 16
	  nop.i 0x0
	  ;;
	}
	{ .mmi
	  ld8 r10 = [r2], 16
	  ld8 r11 = [r3], 24
	  nop.i 0x0
	  ;;
	}
	{ .mmi
	  ldf.fill f8 = [r2], 32
	  ldf.fill f9 = [r3], 32
	  mov ar.lc = loc6
	  ;;
	}
	{ .mmi
	  ldf.fill f10 = [r2], 32
	  ldf.fill f11 = [r3], 32
	  mov ar.pfs = loc0
	  ;;
	}
	{ .mmi
	  ldf.fill f12 = [r2], 32
	  ldf.fill f13 = [r3], 32
	  mov b0 = loc1
	  ;;
	}
	{ .mmi
	  ldf.fill f14 = [r2]
	  ldf.fill f15 = [r3]
	  /* We know that the previous stack pointer, loc10, isn't 0.
	     We use it to reload p7.  */
	  cmp.ne p7, p0 = 0, loc10
	  ;;
	}
.Lresolved:
	{ .mmb
	  .restore sp
	  mov r12 = loc10
(p7)	  br.ret.sptk.many b0
	  ;;
	}
	/* An alloc is needed for the break system call to work. We
	   don't care about the old value of the pfs register. After
	   this alloc, we can't use any rotating registers. Otherwise
	   assembler won't be happy. This has to be at the end.  */
	{ .mmb
	  .prologue
	  .body
	  alloc r2 = ar.pfs, 0, 0, 8, 0
	  br.sptk.many b6
	  ;;
	}
END(_dl_runtime_profile)
#endif