1
1
;*********************************************************************
5
; Xavier Leroy, projet Gallium, INRIA Rocquencourt
7
; Copyright 2006 Institut National de Recherche en Informatique et
8
; en Automatique. All rights reserved. This file is distributed
9
; under the terms of the GNU Library General Public License, with
10
; the special exception on linking described in file ../LICENSE.
5
; Xavier Leroy, projet Gallium, INRIA Rocquencourt
7
; Copyright 2006 Institut National de Recherche en Informatique et
8
; en Automatique. All rights reserved. This file is distributed
9
; under the terms of the GNU Library General Public License, with
10
; the special exception on linking described in file ../LICENSE.
12
12
;*********************************************************************
14
; $Id: amd64nt.asm 7942 2007-03-01 10:26:51Z xleroy $
14
; $Id: amd64nt.asm 10215 2010-03-28 08:04:39Z xleroy $
16
16
; Asm part of the runtime system, AMD64 processor, Intel syntax
46
46
mov caml_last_return_address, rax
48
48
mov caml_bottom_of_stack, rax
50
50
; Save caml_young_ptr, caml_exception_pointer
51
51
mov caml_young_ptr, r15
52
52
mov caml_exception_pointer, r14
53
; Build array of registers, save it into caml_gc_regs
53
; Build array of registers, save it into caml_gc_regs
67
67
mov caml_gc_regs, rsp
68
; Save floating-point registers
68
; Save floating-point registers
70
70
movlpd QWORD PTR [rsp + 0*8], xmm0
71
71
movlpd QWORD PTR [rsp + 1*8], xmm1
83
83
movlpd QWORD PTR [rsp + 13*8], xmm13
84
84
movlpd QWORD PTR [rsp + 14*8], xmm14
85
85
movlpd QWORD PTR [rsp + 15*8], xmm15
86
; Call the garbage collector
87
call caml_garbage_collection
88
; Restore all regs used by the code generator
86
; Call the garbage collector
87
sub rsp, 32 ; PR#5008: bottom 32 bytes are reserved for callee
88
call caml_garbage_collection
90
; Restore all regs used by the code generator
89
91
movlpd xmm0, QWORD PTR [rsp + 0*8]
90
92
movlpd xmm1, QWORD PTR [rsp + 1*8]
91
93
movlpd xmm2, QWORD PTR [rsp + 2*8]
119
; Restore caml_young_ptr, caml_exception_pointer
121
; Restore caml_young_ptr, caml_exception_pointer
120
122
mov r15, caml_young_ptr
121
123
mov r14, caml_exception_pointer
125
127
PUBLIC caml_alloc1
184
push rax ; save desired size
186
push rax ; save desired size
185
187
mov rax, [rsp + 8]
186
188
mov caml_last_return_address, rax
187
189
lea rax, [rsp + 16]
188
190
mov caml_bottom_of_stack, rax
190
pop rax ; recover desired size
192
pop rax ; recover desired size
193
; Call a C function from Caml
195
; Call a C function from Caml
195
197
PUBLIC caml_c_call
198
; Record lowest stack address and return address
200
; Record lowest stack address and return address
200
202
mov caml_last_return_address, r12
201
203
mov caml_bottom_of_stack, rsp
202
; Make the exception handler and alloc ptr available to the C code
204
; Make the exception handler and alloc ptr available to the C code
203
205
mov caml_young_ptr, r15
204
206
mov caml_exception_pointer, r14
205
; Call the function (address in rax)
207
; Call the function (address in rax)
208
210
mov r15, caml_young_ptr
213
; Start the Caml program
215
; Start the Caml program
215
217
PUBLIC caml_start_program
217
219
caml_start_program:
218
; Save callee-save registers
220
; Save callee-save registers
235
237
movapd OWORD PTR [rsp + 7*16], xmm13
236
238
movapd OWORD PTR [rsp + 8*16], xmm14
237
239
movapd OWORD PTR [rsp + 9*16], xmm15
238
; Initial entry point is caml_program
240
; Initial entry point is caml_program
239
241
lea r12, caml_program
240
; Common code for caml_start_program and caml_callback*
242
; Common code for caml_start_program and caml_callback*
242
; Build a callback link
243
sub rsp, 8 ; stack 16-aligned
244
; Build a callback link
245
sub rsp, 8 ; stack 16-aligned
244
246
push caml_gc_regs
245
247
push caml_last_return_address
246
248
push caml_bottom_of_stack
247
; Setup alloc ptr and exception ptr
249
; Setup alloc ptr and exception ptr
248
250
mov r15, caml_young_ptr
249
251
mov r14, caml_exception_pointer
250
; Build an exception handler
252
; Build an exception handler
258
; Pop the exception handler
260
; Pop the exception handler
260
pop r12 ; dummy register
262
pop r12 ; dummy register
262
; Update alloc ptr and exception ptr
264
; Update alloc ptr and exception ptr
263
265
mov caml_young_ptr, r15
264
266
mov caml_exception_pointer, r14
265
; Pop the callback restoring, link the global variables
267
; Pop the callback restoring, link the global variables
266
268
pop caml_bottom_of_stack
267
269
pop caml_last_return_address
270
; Restore callee-save registers.
272
; Restore callee-save registers.
271
273
movapd xmm6, OWORD PTR [rsp + 0*16]
272
274
movapd xmm7, OWORD PTR [rsp + 1*16]
273
275
movapd xmm8, OWORD PTR [rsp + 2*16]
328
330
mov rax, rcx ; First argument is exn bucket
329
331
mov rsp, caml_exception_pointer
330
pop r14 ; Recover previous exception handler
331
mov r15, caml_young_ptr ; Reload alloc ptr
332
pop r14 ; Recover previous exception handler
333
mov r15, caml_young_ptr ; Reload alloc ptr
334
336
mov r12, rcx ; Save exception bucket in r12
340
342
call caml_stash_backtrace
341
343
mov rax, r12 ; Recover exception bucket
342
344
mov rsp, caml_exception_pointer
343
pop r14 ; Recover previous exception handler
344
mov r15, caml_young_ptr ; Reload alloc ptr
345
pop r14 ; Recover previous exception handler
346
mov r15, caml_young_ptr ; Reload alloc ptr
347
; Callback from C to Caml
349
; Callback from C to Caml
349
351
PUBLIC caml_callback_exn
351
353
caml_callback_exn:
352
; Save callee-save registers
354
; Save callee-save registers
369
371
movapd OWORD PTR [rsp + 7*16], xmm13
370
372
movapd OWORD PTR [rsp + 8*16], xmm14
371
373
movapd OWORD PTR [rsp + 9*16], xmm15
372
; Initial loading of arguments
373
mov rbx, rcx ; closure
374
mov rax, rdx ; argument
375
mov r12, [rbx] ; code pointer
374
; Initial loading of arguments
375
mov rbx, rcx ; closure
376
mov rax, rdx ; argument
377
mov r12, [rbx] ; code pointer
378
380
PUBLIC caml_callback2_exn
380
382
caml_callback2_exn:
381
; Save callee-save registers
383
; Save callee-save registers
398
400
movapd OWORD PTR [rsp + 7*16], xmm13
399
401
movapd OWORD PTR [rsp + 8*16], xmm14
400
402
movapd OWORD PTR [rsp + 9*16], xmm15
401
; Initial loading of arguments
403
; Initial loading of arguments
402
404
mov rdi, rcx ; closure
403
mov rax, rdx ; first argument
404
mov rbx, r8 ; second argument
405
lea r12, caml_apply2 ; code pointer
405
mov rax, rdx ; first argument
406
mov rbx, r8 ; second argument
407
lea r12, caml_apply2 ; code pointer
408
410
PUBLIC caml_callback3_exn
410
412
caml_callback3_exn:
411
; Save callee-save registers
413
; Save callee-save registers
428
430
movapd OWORD PTR [rsp + 7*16], xmm13
429
431
movapd OWORD PTR [rsp + 8*16], xmm14
430
432
movapd OWORD PTR [rsp + 9*16], xmm15
431
; Initial loading of arguments
433
; Initial loading of arguments
432
434
mov rsi, rcx ; closure
433
mov rax, rdx ; first argument
434
mov rbx, r8 ; second argument
435
mov rdi, r9 ; third argument
436
lea r12, caml_apply3 ; code pointer
435
mov rax, rdx ; first argument
436
mov rbx, r8 ; second argument
437
mov rdi, r9 ; third argument
438
lea r12, caml_apply3 ; code pointer
439
441
PUBLIC caml_ml_array_bound_error
446
448
PUBLIC caml_system__frametable
447
449
caml_system__frametable LABEL QWORD
448
QWORD 1 ; one descriptor
449
QWORD L107 ; return address into callback
450
WORD -1 ; negative frame size => use callback link
451
WORD 0 ; no roots here
450
QWORD 1 ; one descriptor
451
QWORD L107 ; return address into callback
452
WORD -1 ; negative frame size => use callback link
453
WORD 0 ; no roots here
454
456
PUBLIC caml_negf_mask