forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amd64.S
782 lines (697 loc) · 26.6 KB
/
amd64.S
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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/**************************************************************************/
/* */
/* OCaml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 2003 Institut National de Recherche en Informatique et */
/* en Automatique. */
/* */
/* All rights reserved. This file is distributed under the terms of */
/* the GNU Lesser General Public License version 2.1, with the */
/* special exception on linking described in the file LICENSE. */
/* */
/**************************************************************************/
/* Asm part of the runtime system, AMD64 processor */
/* Must be preprocessed by cpp */
/* PIC mode support based on contribution by Paul Stravers (see PR#4795) */
#include "caml/m.h"
#if defined(SYS_macosx)
#define LBL(x) L##x
#define G(r) _##r
#define GREL(r) _##r@GOTPCREL
#define GCALL(r) _##r
#define TEXT_SECTION(name) .text
#define FUNCTION_ALIGN 2
#define EIGHT_ALIGN 3
#define SIXTEEN_ALIGN 4
#define FUNCTION(name) \
.globl name; \
.align FUNCTION_ALIGN; \
name:
#elif defined(SYS_mingw64) || defined(SYS_cygwin)
#define LBL(x) .L##x
#define G(r) r
#undef GREL
#define GCALL(r) r
#define TEXT_SECTION(name)
#define FUNCTION_ALIGN 4
#define EIGHT_ALIGN 8
#define SIXTEEN_ALIGN 16
#define FUNCTION(name) \
TEXT_SECTION(name); \
.globl name; \
.align FUNCTION_ALIGN; \
name:
#else
#define LBL(x) .L##x
#define G(r) r
#define GREL(r) r@GOTPCREL
#define GCALL(r) r@PLT
#if defined(FUNCTION_SECTIONS)
#define TEXT_SECTION(name) .section .text.##name,"ax",%progbits
#else
#define TEXT_SECTION(name)
#endif
#define FUNCTION_ALIGN 4
#define EIGHT_ALIGN 8
#define SIXTEEN_ALIGN 16
#define FUNCTION(name) \
TEXT_SECTION(caml.##name); \
.globl name; \
.type name,@function; \
.align FUNCTION_ALIGN; \
name:
#endif
#if defined(SYS_linux) || defined(SYS_gnu)
#define ENDFUNCTION(name) \
.size name, . - name
#else
#define ENDFUNCTION(name)
#endif
#ifdef ASM_CFI_SUPPORTED
#define CFI_STARTPROC .cfi_startproc
#define CFI_ENDPROC .cfi_endproc
#define CFI_ADJUST(n) .cfi_adjust_cfa_offset n
#define CFI_OFFSET(r, n) .cfi_offset r, n
#define CFI_SAME_VALUE(r) .cfi_same_value r
#else
#define CFI_STARTPROC
#define CFI_ENDPROC
#define CFI_ADJUST(n)
#define CFI_OFFSET(r, n)
#define CFI_SAME_VALUE(r)
#endif
#ifdef WITH_FRAME_POINTERS
#define ENTER_FUNCTION \
pushq %rbp; CFI_ADJUST(8); \
movq %rsp, %rbp
#define LEAVE_FUNCTION \
popq %rbp; CFI_ADJUST(-8);
#else
#define ENTER_FUNCTION \
subq $8, %rsp; CFI_ADJUST (8);
#define LEAVE_FUNCTION \
addq $8, %rsp; CFI_ADJUST (-8);
#endif
.set domain_curr_field, 0
#define DOMAIN_STATE(c_type, name) \
.equ domain_field_caml_##name, domain_curr_field ; \
.set domain_curr_field, domain_curr_field + 1
#include "../runtime/caml/domain_state.tbl"
#undef DOMAIN_STATE
#define Caml_state(var) (8*domain_field_caml_##var)(%r14)
#if defined(__PIC__) && !defined(SYS_mingw64) && !defined(SYS_cygwin)
/* Position-independent operations on global variables. */
/* Store [srcreg] in global [dstlabel]. Clobbers %r11. */
#define STORE_VAR(srcreg,dstlabel) \
movq GREL(dstlabel)(%rip), %r11 ; \
movq srcreg, (%r11)
#define STORE_VAR32(srcreg,dstlabel) \
movq GREL(dstlabel)(%rip), %r11 ; \
movl srcreg, (%r11)
/* Load global [srclabel] in register [dstreg]. Clobbers %r11. */
#define LOAD_VAR(srclabel,dstreg) \
movq GREL(srclabel)(%rip), %r11 ; \
movq (%r11), dstreg
/* Compare global [label] with register [reg]. Clobbers %rax. */
#define CMP_VAR(label,reg) \
movq GREL(label)(%rip), %rax ; \
cmpq (%rax), reg
/* Test 32-bit global [label] against mask [imm]. Clobbers %r11. */
#define TESTL_VAR(imm,label) \
movq GREL(label)(%rip), %r11 ; \
testl imm, (%r11)
/* Push global [label] on stack. Clobbers %r11. */
#define PUSH_VAR(srclabel) \
movq GREL(srclabel)(%rip), %r11 ; \
pushq (%r11); CFI_ADJUST (8)
/* Pop global [label] off stack. Clobbers %r11. */
#define POP_VAR(dstlabel) \
movq GREL(dstlabel)(%rip), %r11 ; \
popq (%r11); CFI_ADJUST (-8)
/* Load address of global [label] in register [dst]. */
#define LEA_VAR(label,dst) \
movq GREL(label)(%rip), dst
#else
/* Non-PIC operations on global variables. Slightly faster. */
#define STORE_VAR(srcreg,dstlabel) \
movq srcreg, G(dstlabel)(%rip)
#define STORE_VAR32(srcreg,dstlabel) \
movl srcreg, G(dstlabel)(%rip)
#define LOAD_VAR(srclabel,dstreg) \
movq G(srclabel)(%rip), dstreg
#define CMP_VAR(label,reg) \
cmpq G(label)(%rip), %r15
#define TESTL_VAR(imm,label) \
testl imm, G(label)(%rip)
#define PUSH_VAR(srclabel) \
pushq G(srclabel)(%rip) ; CFI_ADJUST(8)
#define POP_VAR(dstlabel) \
popq G(dstlabel)(%rip); CFI_ADJUST(-8)
#define LEA_VAR(label,dst) \
leaq G(label)(%rip), dst
#endif
/* Save and restore all callee-save registers on stack.
Keep the stack 16-aligned. */
#if defined(SYS_mingw64) || defined(SYS_cygwin)
/* Win64 API: callee-save regs are rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15 */
#define PUSH_CALLEE_SAVE_REGS \
pushq %rbx; CFI_ADJUST (8); CFI_OFFSET(rbx, -16); \
pushq %rbp; CFI_ADJUST (8); CFI_OFFSET(rbp, -24); \
/* Allows debugger to walk the stack */ \
pushq %rsi; CFI_ADJUST (8); CFI_OFFSET(rsi, -32); \
pushq %rdi; CFI_ADJUST (8); CFI_OFFSET(rdi, -40); \
pushq %r12; CFI_ADJUST (8); CFI_OFFSET(r12, -48); \
pushq %r13; CFI_ADJUST (8); CFI_OFFSET(r13, -56); \
pushq %r14; CFI_ADJUST (8); CFI_OFFSET(r14, -64); \
pushq %r15; CFI_ADJUST (8); CFI_OFFSET(r15, -72); \
subq $(8+10*16), %rsp; CFI_ADJUST (8+10*16); \
movupd %xmm6, 0*16(%rsp); \
movupd %xmm7, 1*16(%rsp); \
movupd %xmm8, 2*16(%rsp); \
movupd %xmm9, 3*16(%rsp); \
movupd %xmm10, 4*16(%rsp); \
movupd %xmm11, 5*16(%rsp); \
movupd %xmm12, 6*16(%rsp); \
movupd %xmm13, 7*16(%rsp); \
movupd %xmm14, 8*16(%rsp); \
movupd %xmm15, 9*16(%rsp)
#define POP_CALLEE_SAVE_REGS \
movupd 0*16(%rsp), %xmm6; \
movupd 1*16(%rsp), %xmm7; \
movupd 2*16(%rsp), %xmm8; \
movupd 3*16(%rsp), %xmm9; \
movupd 4*16(%rsp), %xmm10; \
movupd 5*16(%rsp), %xmm11; \
movupd 6*16(%rsp), %xmm12; \
movupd 7*16(%rsp), %xmm13; \
movupd 8*16(%rsp), %xmm14; \
movupd 9*16(%rsp), %xmm15; \
addq $(8+10*16), %rsp; CFI_ADJUST (-8-10*16); \
popq %r15; CFI_ADJUST(-8); CFI_SAME_VALUE(r15); \
popq %r14; CFI_ADJUST(-8); CFI_SAME_VALUE(r14); \
popq %r13; CFI_ADJUST(-8); CFI_SAME_VALUE(r13); \
popq %r12; CFI_ADJUST(-8); CFI_SAME_VALUE(r12); \
popq %rdi; CFI_ADJUST(-8); CFI_SAME_VALUE(rdi); \
popq %rsi; CFI_ADJUST(-8); CFI_SAME_VALUE(rsi); \
popq %rbp; CFI_ADJUST(-8); CFI_SAME_VALUE(rbp); \
popq %rbx; CFI_ADJUST(-8); CFI_SAME_VALUE(rbx)
#else
/* Unix API: callee-save regs are rbx, rbp, r12-r15 */
#define PUSH_CALLEE_SAVE_REGS \
pushq %rbx; CFI_ADJUST(8); CFI_OFFSET(rbx, -16); \
pushq %rbp; CFI_ADJUST(8); CFI_OFFSET(rbp, -24); \
pushq %r12; CFI_ADJUST(8); CFI_OFFSET(r12, -32); \
pushq %r13; CFI_ADJUST(8); CFI_OFFSET(r13, -40); \
pushq %r14; CFI_ADJUST(8); CFI_OFFSET(r14, -48); \
pushq %r15; CFI_ADJUST(8); CFI_OFFSET(r15, -56); \
subq $8, %rsp; CFI_ADJUST(8)
#define POP_CALLEE_SAVE_REGS \
addq $8, %rsp; CFI_ADJUST(-8); \
popq %r15; CFI_ADJUST(-8); CFI_SAME_VALUE(r15); \
popq %r14; CFI_ADJUST(-8); CFI_SAME_VALUE(r14); \
popq %r13; CFI_ADJUST(-8); CFI_SAME_VALUE(r13); \
popq %r12; CFI_ADJUST(-8); CFI_SAME_VALUE(r12); \
popq %rbp; CFI_ADJUST(-8); CFI_SAME_VALUE(rbp); \
popq %rbx; CFI_ADJUST(-8); CFI_SAME_VALUE(rbx)
#endif
#if defined(SYS_mingw64) || defined (SYS_cygwin)
/* Calls from OCaml to C must reserve 32 bytes of extra stack space */
# define PREPARE_FOR_C_CALL subq $32, %rsp; CFI_ADJUST(32)
# define CLEANUP_AFTER_C_CALL addq $32, %rsp; CFI_ADJUST(-32)
/* Stack probing mustn't be larger than the page size */
# define STACK_PROBE_SIZE 4096
#else
# define PREPARE_FOR_C_CALL
# define CLEANUP_AFTER_C_CALL
# define STACK_PROBE_SIZE 4096
#endif
/* Registers holding arguments of C functions. */
#if defined(SYS_mingw64) || defined(SYS_cygwin)
#define C_ARG_1 %rcx
#define C_ARG_2 %rdx
#define C_ARG_3 %r8
#define C_ARG_4 %r9
#else
#define C_ARG_1 %rdi
#define C_ARG_2 %rsi
#define C_ARG_3 %rdx
#define C_ARG_4 %rcx
#endif
#if defined(FUNCTION_SECTIONS)
TEXT_SECTION(caml_hot__code_begin)
.globl G(caml_hot__code_begin)
G(caml_hot__code_begin):
TEXT_SECTION(caml_hot__code_end)
.globl G(caml_hot__code_end)
G(caml_hot__code_end):
#endif
.text
.globl G(caml_system__code_begin)
G(caml_system__code_begin):
ret /* just one instruction, so that debuggers don't display
caml_system__code_begin instead of caml_call_gc */
#define SAVE_REGS_AND_YOUNG_PTR_FOR_GC_OR_POLL \
pushq %r11; CFI_ADJUST (8); \
pushq %r10; CFI_ADJUST (8); \
pushq %r13; CFI_ADJUST (8); \
pushq %r12; CFI_ADJUST (8); \
pushq %r9; CFI_ADJUST (8); \
pushq %r8; CFI_ADJUST (8); \
pushq %rcx; CFI_ADJUST (8); \
pushq %rdx; CFI_ADJUST (8); \
pushq %rsi; CFI_ADJUST (8); \
pushq %rdi; CFI_ADJUST (8); \
pushq %rbx; CFI_ADJUST (8); \
pushq %rax; CFI_ADJUST (8); \
movq %rsp, Caml_state(gc_regs); \
/* Save young_ptr */ \
movq %r15, Caml_state(young_ptr); \
/* Save floating-point registers */ \
subq $(16*8), %rsp; CFI_ADJUST (16*8); \
movsd %xmm0, 0*8(%rsp); \
movsd %xmm1, 1*8(%rsp); \
movsd %xmm2, 2*8(%rsp); \
movsd %xmm3, 3*8(%rsp); \
movsd %xmm4, 4*8(%rsp); \
movsd %xmm5, 5*8(%rsp); \
movsd %xmm6, 6*8(%rsp); \
movsd %xmm7, 7*8(%rsp); \
movsd %xmm8, 8*8(%rsp); \
movsd %xmm9, 9*8(%rsp); \
movsd %xmm10, 10*8(%rsp); \
movsd %xmm11, 11*8(%rsp); \
movsd %xmm12, 12*8(%rsp); \
movsd %xmm13, 13*8(%rsp); \
movsd %xmm14, 14*8(%rsp); \
movsd %xmm15, 15*8(%rsp);
#define RESTORE_REGS_AND_YOUNG_PTR_FOR_GC_OR_POLL \
/* Restore young_ptr */ \
movq Caml_state(young_ptr), %r15; \
/* Restore all regs used by the code generator */ \
movsd 0*8(%rsp), %xmm0; \
movsd 1*8(%rsp), %xmm1; \
movsd 2*8(%rsp), %xmm2; \
movsd 3*8(%rsp), %xmm3; \
movsd 4*8(%rsp), %xmm4; \
movsd 5*8(%rsp), %xmm5; \
movsd 6*8(%rsp), %xmm6; \
movsd 7*8(%rsp), %xmm7; \
movsd 8*8(%rsp), %xmm8; \
movsd 9*8(%rsp), %xmm9; \
movsd 10*8(%rsp), %xmm10; \
movsd 11*8(%rsp), %xmm11; \
movsd 12*8(%rsp), %xmm12; \
movsd 13*8(%rsp), %xmm13; \
movsd 14*8(%rsp), %xmm14; \
movsd 15*8(%rsp), %xmm15; \
addq $(16*8), %rsp; CFI_ADJUST(-16*8); \
popq %rax; CFI_ADJUST(-8); \
popq %rbx; CFI_ADJUST(-8); \
popq %rdi; CFI_ADJUST(-8); \
popq %rsi; CFI_ADJUST(-8); \
popq %rdx; CFI_ADJUST(-8); \
popq %rcx; CFI_ADJUST(-8); \
popq %r8; CFI_ADJUST(-8); \
popq %r9; CFI_ADJUST(-8); \
popq %r12; CFI_ADJUST(-8); \
popq %r13; CFI_ADJUST(-8); \
popq %r10; CFI_ADJUST(-8); \
popq %r11; CFI_ADJUST(-8);
/* Allocation */
FUNCTION(G(caml_call_gc))
CFI_STARTPROC
LBL(caml_call_gc):
/* Record lowest stack address and return address. */
movq (%rsp), %r11
movq %r11, Caml_state(last_return_address)
leaq 8(%rsp), %r11
movq %r11, Caml_state(bottom_of_stack)
/* Touch the stack to trigger a recoverable segfault
if insufficient space remains */
subq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(STACK_PROBE_SIZE);
movq %r11, 0(%rsp)
addq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(-STACK_PROBE_SIZE);
/* Build array of registers, save it into Caml_state->gc_regs */
#ifdef WITH_FRAME_POINTERS
ENTER_FUNCTION ;
#else
pushq %rbp; CFI_ADJUST(8);
#endif
SAVE_REGS_AND_YOUNG_PTR_FOR_GC_OR_POLL
/* Call the garbage collector */
PREPARE_FOR_C_CALL
call GCALL(caml_garbage_collection)
CLEANUP_AFTER_C_CALL
RESTORE_REGS_AND_YOUNG_PTR_FOR_GC_OR_POLL
#ifdef WITH_FRAME_POINTERS
LEAVE_FUNCTION
#else
popq %rbp; CFI_ADJUST(-8);
#endif
/* Return to caller */
ret
CFI_ENDPROC
ENDFUNCTION(G(caml_call_gc))
FUNCTION(G(caml_alloc1))
CFI_STARTPROC
subq $16, %r15
cmpq Caml_state(young_limit), %r15
jb LBL(caml_call_gc)
ret
CFI_ENDPROC
ENDFUNCTION(G(caml_alloc1))
FUNCTION(G(caml_alloc2))
CFI_STARTPROC
subq $24, %r15
cmpq Caml_state(young_limit), %r15
jb LBL(caml_call_gc)
ret
CFI_ENDPROC
ENDFUNCTION(G(caml_alloc2))
FUNCTION(G(caml_alloc3))
CFI_STARTPROC
subq $32, %r15
cmpq Caml_state(young_limit), %r15
jb LBL(caml_call_gc)
ret
CFI_ENDPROC
ENDFUNCTION(G(caml_alloc3))
FUNCTION(G(caml_allocN))
CFI_STARTPROC
cmpq Caml_state(young_limit), %r15
jb LBL(caml_call_gc)
ret
CFI_ENDPROC
ENDFUNCTION(G(caml_allocN))
/* Polling */
FUNCTION(G(caml_call_poll))
CFI_STARTPROC
LBL(caml_call_poll):
/* Record lowest stack address and return address. */
movq (%rsp), %r11
movq %r11, Caml_state(last_return_address)
leaq 8(%rsp), %r11
movq %r11, Caml_state(bottom_of_stack)
/* Touch the stack to trigger a recoverable segfault
if insufficient space remains */
subq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(STACK_PROBE_SIZE);
movq %r11, 0(%rsp)
addq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(-STACK_PROBE_SIZE);
/* Build array of registers, save it into Caml_state->gc_regs */
#ifdef WITH_FRAME_POINTERS
ENTER_FUNCTION ;
#else
pushq %rbp; CFI_ADJUST(8);
#endif
SAVE_REGS_AND_YOUNG_PTR_FOR_GC_OR_POLL
/* Call the garbage collector */
PREPARE_FOR_C_CALL
call GCALL(caml_poll)
CLEANUP_AFTER_C_CALL
RESTORE_REGS_AND_YOUNG_PTR_FOR_GC_OR_POLL
#ifdef WITH_FRAME_POINTERS
LEAVE_FUNCTION
#else
popq %rbp; CFI_ADJUST(-8);
#endif
/* Return to caller */
ret
CFI_ENDPROC
ENDFUNCTION(G(caml_call_poll))
/* Call a C function from OCaml */
FUNCTION(G(caml_c_call))
CFI_STARTPROC
LBL(caml_c_call):
/* Record lowest stack address and return address */
popq Caml_state(last_return_address); CFI_ADJUST(-8)
movq %rsp, Caml_state(bottom_of_stack)
/* equivalent to pushing last return address */
subq $8, %rsp; CFI_ADJUST(8)
#ifdef WITH_SPACETIME
/* Record the trie node hole pointer that corresponds to
[Caml_state->last_return_address] */
STORE_VAR(%r13, caml_spacetime_trie_node_ptr)
#endif
/* Touch the stack to trigger a recoverable segfault
if insufficient space remains */
subq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(STACK_PROBE_SIZE);
movq %rax, 0(%rsp)
addq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(-STACK_PROBE_SIZE);
/* Make the alloc ptr available to the C code */
movq %r15, Caml_state(young_ptr)
/* Call the function (address in %rax) */
/* No need to PREPARE_FOR_C_CALL since the caller already
reserved the stack space if needed (cf. amd64/proc.ml) */
jmp *%rax
CFI_ENDPROC
ENDFUNCTION(G(caml_c_call))
/* Start the OCaml program */
FUNCTION(G(caml_start_program))
CFI_STARTPROC
/* Save callee-save registers */
PUSH_CALLEE_SAVE_REGS
/* Load Caml_state into r14 (was passed as an argument from C) */
movq C_ARG_1, %r14
/* Initial entry point is G(caml_program) */
LEA_VAR(caml_program, %r12)
/* Common code for caml_start_program and caml_callback* */
LBL(caml_start_program):
/* Build a callback link */
#ifdef WITH_SPACETIME
PUSH_VAR(caml_spacetime_trie_node_ptr)
#else
subq $8, %rsp; CFI_ADJUST (8) /* stack 16-aligned */
#endif
pushq Caml_state(gc_regs); CFI_ADJUST(8)
pushq Caml_state(last_return_address); CFI_ADJUST(8)
pushq Caml_state(bottom_of_stack); CFI_ADJUST(8)
#ifdef WITH_SPACETIME
/* Save arguments to caml_callback* */
pushq %rax; CFI_ADJUST (8)
pushq %rbx; CFI_ADJUST (8)
pushq %rdi; CFI_ADJUST (8)
pushq %rsi; CFI_ADJUST (8)
/* No need to push %r12: it's callee-save. */
movq %r12, C_ARG_1
LEA_VAR(caml_start_program, C_ARG_2)
call GCALL(caml_spacetime_c_to_ocaml)
popq %rsi; CFI_ADJUST (-8)
popq %rdi; CFI_ADJUST (-8)
popq %rbx; CFI_ADJUST (-8)
popq %rax; CFI_ADJUST (-8)
#endif
/* Setup alloc ptr */
movq Caml_state(young_ptr), %r15
/* Build an exception handler */
lea LBL(108)(%rip), %r13
pushq %r13; CFI_ADJUST(8)
pushq Caml_state(exception_pointer); CFI_ADJUST(8)
movq %rsp, Caml_state(exception_pointer)
#ifdef WITH_SPACETIME
LOAD_VAR(caml_spacetime_trie_node_ptr, %r13)
#endif
/* Call the OCaml code */
call *%r12
LBL(107):
/* Pop the exception handler */
popq Caml_state(exception_pointer); CFI_ADJUST(-8)
popq %r12; CFI_ADJUST(-8) /* dummy register */
LBL(109):
/* Update alloc ptr */
movq %r15, Caml_state(young_ptr)
/* Pop the callback link, restoring the global variables */
popq Caml_state(bottom_of_stack); CFI_ADJUST(-8)
popq Caml_state(last_return_address); CFI_ADJUST(-8)
popq Caml_state(gc_regs); CFI_ADJUST(-8)
#ifdef WITH_SPACETIME
POP_VAR(caml_spacetime_trie_node_ptr)
#else
addq $8, %rsp; CFI_ADJUST (-8);
#endif
/* Restore callee-save registers. */
POP_CALLEE_SAVE_REGS
/* Return to caller. */
ret
LBL(108):
/* Exception handler*/
/* Mark the bucket as an exception result and return it */
orq $2, %rax
jmp LBL(109)
CFI_ENDPROC
ENDFUNCTION(G(caml_start_program))
/* Raise an exception from OCaml */
FUNCTION(G(caml_raise_exn))
CFI_STARTPROC
testq $1, Caml_state(backtrace_active)
jne LBL(110)
movq Caml_state(exception_pointer), %rsp
popq Caml_state(exception_pointer); CFI_ADJUST(-8)
ret
LBL(110):
movq %rax, %r12 /* Save exception bucket */
movq %rax, C_ARG_1 /* arg 1: exception bucket */
#ifdef WITH_FRAME_POINTERS
ENTER_FUNCTION
movq 8(%rsp), C_ARG_2 /* arg 2: pc of raise */
leaq 16(%rsp), C_ARG_3 /* arg 3: sp at raise */
#else
popq C_ARG_2 /* arg 2: pc of raise */
movq %rsp, C_ARG_3 /* arg 3: sp at raise */
#endif
/* arg 4: sp of handler */
movq Caml_state(exception_pointer), C_ARG_4
/* PR#5700: thanks to popq above, stack is now 16-aligned */
/* Thanks to ENTER_FUNCTION, stack is now 16-aligned */
PREPARE_FOR_C_CALL /* no need to cleanup after */
call GCALL(caml_stash_backtrace)
movq %r12, %rax /* Recover exception bucket */
movq Caml_state(exception_pointer), %rsp
popq Caml_state(exception_pointer); CFI_ADJUST(-8)
ret
CFI_ENDPROC
ENDFUNCTION(G(caml_raise_exn))
/* Raise an exception from C */
FUNCTION(G(caml_raise_exception))
CFI_STARTPROC
movq C_ARG_1, %r14 /* Caml_state */
testq $1, Caml_state(backtrace_active)
jne LBL(112)
movq C_ARG_2, %rax
movq Caml_state(exception_pointer), %rsp /* Cut stack */
/* Recover previous exception handler */
popq Caml_state(exception_pointer); CFI_ADJUST(-8)
movq Caml_state(young_ptr), %r15 /* Reload alloc ptr */
ret
LBL(112):
#ifdef WITH_FRAME_POINTERS
ENTER_FUNCTION ;
#endif
/* Save exception bucket. Caml_state in r14 saved across C calls. */
movq C_ARG_2, %r12
/* arg 1: exception bucket */
movq C_ARG_2, C_ARG_1
/* arg 2: pc of raise */
movq Caml_state(last_return_address), C_ARG_2
/* arg 3: sp of raise */
movq Caml_state(bottom_of_stack), C_ARG_3
/* arg 4: sp of handler */
movq Caml_state(exception_pointer), C_ARG_4
#ifndef WITH_FRAME_POINTERS
subq $8, %rsp /* PR#5700: maintain stack alignment */
#endif
PREPARE_FOR_C_CALL /* no need to cleanup after */
call GCALL(caml_stash_backtrace)
movq %r12, %rax /* Recover exception bucket */
movq Caml_state(exception_pointer), %rsp
/* Recover previous exception handler */
popq Caml_state(exception_pointer); CFI_ADJUST(-8)
movq Caml_state(young_ptr), %r15 /* Reload alloc ptr */
ret
CFI_ENDPROC
ENDFUNCTION(G(caml_raise_exception))
/* Raise a Stack_overflow exception on return from segv_handler()
(in runtime/signals_nat.c). On entry, the stack is full, so we
cannot record a backtrace.
No CFI information here since this function disrupts the stack
backtrace anyway. */
FUNCTION(G(caml_stack_overflow))
movq C_ARG_1, %r14 /* Caml_state */
LEA_VAR(caml_exn_Stack_overflow, %rax)
movq Caml_state(exception_pointer), %rsp /* cut the stack */
/* Recover previous exn handler */
popq Caml_state(exception_pointer)
ret /* jump to handler's code */
ENDFUNCTION(G(caml_stack_overflow))
/* Callback from C to OCaml */
FUNCTION(G(caml_callback_asm))
CFI_STARTPROC
/* Save callee-save registers */
PUSH_CALLEE_SAVE_REGS
/* Initial loading of arguments */
movq C_ARG_1, %r14 /* Caml_state */
movq C_ARG_2, %rbx /* closure */
movq 0(C_ARG_3), %rax /* argument */
movq 0(%rbx), %r12 /* code pointer */
jmp LBL(caml_start_program)
CFI_ENDPROC
ENDFUNCTION(G(caml_callback_asm))
FUNCTION(G(caml_callback2_asm))
CFI_STARTPROC
/* Save callee-save registers */
PUSH_CALLEE_SAVE_REGS
/* Initial loading of arguments */
movq C_ARG_1, %r14 /* Caml_state */
movq C_ARG_2, %rdi /* closure */
movq 0(C_ARG_3), %rax /* first argument */
movq 8(C_ARG_3), %rbx /* second argument */
LEA_VAR(caml_apply2, %r12) /* code pointer */
jmp LBL(caml_start_program)
CFI_ENDPROC
ENDFUNCTION(G(caml_callback2_asm))
FUNCTION(G(caml_callback3_asm))
CFI_STARTPROC
/* Save callee-save registers */
PUSH_CALLEE_SAVE_REGS
/* Initial loading of arguments */
movq C_ARG_1, %r14 /* Caml_state */
movq 0(C_ARG_3), %rax /* first argument */
movq 8(C_ARG_3), %rbx /* second argument */
movq C_ARG_2, %rsi /* closure */
movq 16(C_ARG_3), %rdi /* third argument */
LEA_VAR(caml_apply3, %r12) /* code pointer */
jmp LBL(caml_start_program)
CFI_ENDPROC
ENDFUNCTION(G(caml_callback3_asm))
FUNCTION(G(caml_ml_array_bound_error))
CFI_STARTPROC
LEA_VAR(caml_array_bound_error, %rax)
jmp LBL(caml_c_call)
CFI_ENDPROC
ENDFUNCTION(G(caml_ml_array_bound_error))
.globl G(caml_system__code_end)
G(caml_system__code_end):
.data
.globl G(caml_system__frametable)
.align EIGHT_ALIGN
G(caml_system__frametable):
.quad 1 /* one descriptor */
.quad LBL(107) /* return address into callback */
.value -1 /* negative frame size => use callback link */
.value 0 /* no roots here */
.align EIGHT_ALIGN
.quad 16
.quad 0
.string "amd64.S"
#ifdef WITH_SPACETIME
.data
.globl G(caml_system__spacetime_shapes)
.align EIGHT_ALIGN
G(caml_system__spacetime_shapes):
.quad G(caml_start_program)
.quad 2 /* indirect call point to OCaml code */
.quad LBL(107) /* in caml_start_program / caml_callback* */
.quad 0 /* end of shapes for caml_start_program */
.quad 0 /* end of shape table */
.align EIGHT_ALIGN
#endif
#if defined(SYS_macosx)
.literal16
#elif defined(SYS_mingw64) || defined(SYS_cygwin)
.section .rdata,"dr"
#else
.section .rodata.cst8,"a",@progbits
#endif
.globl G(caml_negf_mask)
.align SIXTEEN_ALIGN
G(caml_negf_mask):
.quad 0x8000000000000000, 0
.globl G(caml_absf_mask)
.align SIXTEEN_ALIGN
G(caml_absf_mask):
.quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF
#if defined(SYS_linux)
/* Mark stack as non-executable, PR#4564 */
.section .note.GNU-stack,"",%progbits
#endif