~ubuntu-branches/debian/sid/ocaml/sid

« back to all changes in this revision

Viewing changes to asmrun/amd64nt.asm

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-04-21 21:35:08 UTC
  • mfrom: (1.1.11 upstream) (12.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110421213508-kg34453aqmb0moha
* Fixes related to -output-obj with g++ (in debian/patches):
  - add Declare-primitive-name-table-as-const-char
  - add Avoid-multiple-declarations-in-generated-.c-files-in
  - fix Embed-bytecode-in-C-object-when-using-custom: the closing
    brace for extern "C" { ... } was missing in some cases

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;*********************************************************************
2
 
;                                                                     
3
 
;                           Objective Caml                            
4
 
;
5
 
;            Xavier Leroy, projet Gallium, INRIA Rocquencourt         
6
 
;
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.     
 
2
;
 
3
;                           Objective Caml
 
4
;
 
5
;            Xavier Leroy, projet Gallium, INRIA Rocquencourt
 
6
;
 
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.
11
11
;
12
12
;*********************************************************************
13
13
 
14
 
; $Id: amd64nt.asm 7942 2007-03-01 10:26:51Z xleroy $
 
14
; $Id: amd64nt.asm 10215 2010-03-28 08:04:39Z xleroy $
15
15
 
16
16
; Asm part of the runtime system, AMD64 processor, Intel syntax
17
17
 
46
46
        mov     caml_last_return_address, rax
47
47
        lea     rax, [rsp+8]
48
48
        mov     caml_bottom_of_stack, rax
49
 
L105:  
 
49
L105:
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
54
54
        push    r13
55
55
        push    r12
56
56
        push    rbp
65
65
        push    rbx
66
66
        push    rax
67
67
        mov     caml_gc_regs, rsp
68
 
    ; Save floating-point registers 
 
68
    ; Save floating-point registers
69
69
        sub     rsp, 16*8
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
 
89
        add rsp, 32      ; PR#5008
 
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]
116
118
        pop     rbp
117
119
        pop     r12
118
120
        pop     r13
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
122
 
    ; Return to caller 
 
124
    ; Return to caller
123
125
        ret
124
126
 
125
127
        PUBLIC  caml_alloc1
181
183
        jb      L103
182
184
        ret
183
185
L103:
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
189
191
        call    L105
190
 
        pop     rax                      ; recover desired size 
 
192
        pop     rax                      ; recover desired size
191
193
        jmp     caml_allocN
192
194
 
193
 
; Call a C function from Caml 
 
195
; Call a C function from Caml
194
196
 
195
197
        PUBLIC  caml_c_call
196
198
        ALIGN   16
197
199
caml_c_call:
198
 
    ; Record lowest stack address and return address 
 
200
    ; Record lowest stack address and return address
199
201
        pop     r12
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)
206
208
        call    rax
207
 
    ; Reload alloc ptr 
 
209
    ; Reload alloc ptr
208
210
        mov     r15, caml_young_ptr
209
 
    ; Return to caller 
 
211
    ; Return to caller
210
212
        push    r12
211
213
        ret
212
214
 
213
 
; Start the Caml program 
 
215
; Start the Caml program
214
216
 
215
217
        PUBLIC  caml_start_program
216
218
        ALIGN   16
217
219
caml_start_program:
218
 
    ; Save callee-save registers 
 
220
    ; Save callee-save registers
219
221
        push    rbx
220
222
        push    rbp
221
223
        push    rsi
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*
241
243
L106:
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
251
253
        lea     r13, L108
252
254
        push    r13
253
255
        push    r14
254
256
        mov     r14, rsp
255
 
    ; Call the Caml code 
 
257
    ; Call the Caml code
256
258
        call    r12
257
259
L107:
258
 
    ; Pop the exception handler 
 
260
    ; Pop the exception handler
259
261
        pop     r14
260
 
        pop     r12    ; dummy register 
 
262
        pop     r12    ; dummy register
261
263
L109:
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
268
270
        pop     caml_gc_regs
269
271
        add     rsp, 8
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]
291
293
        ret
292
294
L108:
293
295
    ; Exception handler
294
 
    ; Mark the bucket as an exception result and return it 
 
296
    ; Mark the bucket as an exception result and return it
295
297
        or      rax, 2
296
298
        jmp     L109
297
299
 
318
320
        pop     r14                  ; Recover previous exception handler
319
321
        ret                          ; Branch to handler
320
322
 
321
 
; Raise an exception from C 
 
323
; Raise an exception from C
322
324
 
323
325
        PUBLIC  caml_raise_exception
324
326
        ALIGN   16
327
329
        jne     L111
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
332
334
        ret
333
335
L111:
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
345
347
        ret
346
348
 
347
 
; Callback from C to Caml 
 
349
; Callback from C to Caml
348
350
 
349
351
        PUBLIC  caml_callback_exn
350
352
        ALIGN   16
351
353
caml_callback_exn:
352
 
    ; Save callee-save registers 
 
354
    ; Save callee-save registers
353
355
        push    rbx
354
356
        push    rbp
355
357
        push    rsi
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
376
378
        jmp     L106
377
379
 
378
380
        PUBLIC  caml_callback2_exn
379
381
        ALIGN   16
380
382
caml_callback2_exn:
381
 
    ; Save callee-save registers 
 
383
    ; Save callee-save registers
382
384
        push    rbx
383
385
        push    rbp
384
386
        push    rsi
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
406
408
        jmp     L106
407
409
 
408
410
        PUBLIC  caml_callback3_exn
409
411
        ALIGN   16
410
412
caml_callback3_exn:
411
 
    ; Save callee-save registers 
 
413
    ; Save callee-save registers
412
414
        push    rbx
413
415
        push    rbp
414
416
        push    rsi
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
437
439
        jmp     L106
438
440
 
439
441
        PUBLIC  caml_ml_array_bound_error
445
447
        .DATA
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
452
454
        ALIGN   8
453
455
 
454
456
        PUBLIC  caml_negf_mask