* Removed all Id tags.
[cacao.git] / src / vm / jit / x86_64 / asmpart.S
1 /* src/vm/jit/x86_64/asmpart.S - Java-C interface functions for x86_64
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #include "config.h"
29
30 #include "vm/jit/x86_64/arch.h"
31 #include "vm/jit/x86_64/md-abi.h"
32 #include "vm/jit/x86_64/md-asm.h"
33
34 #include "vm/jit/abi-asm.h"
35 #include "vm/jit/methodheader.h"
36
37
38         .text
39
40
41 /* export functions ***********************************************************/
42
43         .globl asm_vm_call_method
44         .globl asm_vm_call_method_int
45         .globl asm_vm_call_method_long
46         .globl asm_vm_call_method_float
47         .globl asm_vm_call_method_double
48         .globl asm_vm_call_method_exception_handler
49         .globl asm_vm_call_method_end
50
51         .globl asm_call_jit_compiler
52
53         .globl asm_handle_exception
54         .globl asm_handle_nat_exception
55
56         .globl asm_abstractmethoderror
57
58         .globl asm_patcher_wrapper
59
60 #if defined(ENABLE_REPLACEMENT)
61         .globl asm_replacement_out
62         .globl asm_replacement_in
63 #endif
64
65         .globl asm_builtin_f2i
66         .globl asm_builtin_f2l
67         .globl asm_builtin_d2i
68         .globl asm_builtin_d2l
69
70         .globl asm_compare_and_swap
71         .globl asm_memory_barrier
72
73
74 /********************* function asm_calljavafunction ***************************
75 *                                                                              *
76 *   This function calls a Java-method (which possibly needs compilation)       *
77 *   with up to 4 address parameters.                                           *
78 *                                                                              *
79 *   This functions calls the JIT-compiler which eventually translates the      *
80 *   method into machine code.                                                  *
81 *                                                                              *
82 *   C-prototype:                                                               *
83 *    javaobject_header *asm_calljavamethod (methodinfo *m,                     *
84 *         void *arg1, void *arg2, void *arg3, void *arg4);                     *
85 *                                                                              *
86 *******************************************************************************/
87
88         .align  8
89
90         .quad   0                           /* catch type all                     */
91         .quad   0                           /* handler pc                         */
92         .quad   0                           /* end pc                             */
93         .quad   0                           /* start pc                           */
94         .long   1                           /* extable size                       */
95         .long   0                           /* ALIGNMENT PADDING                  */
96         .quad   0                           /* line number table  start           */
97         .quad   0                           /* line number table  size            */
98         .long   0                           /* ALIGNMENT PADDING                  */
99         .long   0                           /* fltsave                            */
100         .long   0                           /* intsave                            */
101         .long   0                           /* isleaf                             */
102         .long   0                           /* IsSync                             */
103         .long   0                           /* frame size                         */
104         .quad   0                           /* codeinfo pointer                   */
105
106 asm_vm_call_method:
107 asm_vm_call_method_int:
108 asm_vm_call_method_long:
109 asm_vm_call_method_float:
110 asm_vm_call_method_double:
111         sub     $(7*8),sp                   /* keep stack 16-byte aligned         */
112         mov     %rbx,0*8(sp)                /* %rbx is not a callee saved in cacao*/
113         mov     s0,1*8(sp)
114         mov     s1,2*8(sp)
115         mov     s2,3*8(sp)
116         mov     s3,4*8(sp)
117         mov     s4,5*8(sp)
118
119         mov     a0,6*8(sp)                  /* store method PV                    */
120
121         mov     sp,s0                       /* save stack pointer                 */
122
123         mov     a1,t0                       /* address of data structure          */
124         mov     a2,itmp1                    /* number of stack arguments          */
125
126         mov     0*8(t0),a0
127         mov     1*8(t0),a1
128         mov     2*8(t0),a2
129         mov     3*8(t0),a3
130         mov     4*8(t0),a4
131         mov     5*8(t0),a5
132
133         movq    6*8(t0),fa0
134         movq    7*8(t0),fa1
135         movq    8*8(t0),fa2
136         movq    9*8(t0),fa3
137         movq    10*8(t0),fa4
138         movq    11*8(t0),fa5
139         movq    12*8(t0),fa6
140         movq    13*8(t0),fa7
141
142         cmp     $0,itmp1l
143         je      L_asm_vm_call_method_stack_copy_done
144
145         mov     itmp1,itmp2
146         add     $1,itmp2                    /* keep stack 16-byte aligned         */
147         and     $0xfffffffffffffffe,itmp2
148         shl     $3,itmp2                    /* calculate stack size               */
149         sub     itmp2,sp                    /* create stack frame                 */
150         mov     sp,itmp2                    /* temporary stack pointer            */
151
152 L_asm_vm_call_method_stack_copy_loop:
153         mov     14*8(t0),itmp3              /* load argument                      */
154         mov     itmp3,0(itmp2)              /* store argument on stack            */
155
156         sub     $1,itmp1l                   /* subtract 1 argument                */
157         add     $8,t0                       /* set address of next argument       */
158         add     $8,itmp2                    /* increase SP                        */
159
160         cmp     $0,itmp1l
161         jg      L_asm_vm_call_method_stack_copy_loop
162
163 L_asm_vm_call_method_stack_copy_done:
164         lea     (6*8-256)(s0),mptr          /* We subtract 256 to force the next  */
165                                             /* move instruction to have a 32-bit  */
166                                             /* offset.                            */
167
168         mov     (0*8+256)(mptr),itmp3       /* load PV                            */
169         call    *itmp3
170
171         mov     s0,sp                       /* restore SP                         */
172
173 L_asm_vm_call_method_return:
174         mov     0*8(sp),%rbx                /* restore callee saved registers     */
175         mov     1*8(sp),s0
176         mov     2*8(sp),s1
177         mov     3*8(sp),s2
178         mov     4*8(sp),s3
179         mov     5*8(sp),s4
180         add     $(7*8),sp                   /* free stack space                   */
181         ret
182                 
183 asm_vm_call_method_exception_handler:
184         mov     xptr,a0                     /* pass exception pointer             */
185         call    builtin_throw_exception@PLT
186         jmp     L_asm_vm_call_method_return
187
188 asm_vm_call_method_end:
189         nop
190
191
192 /****************** function asm_call_jit_compiler *****************************
193 *                                                                              *
194 *   invokes the compiler for untranslated JavaVM methods.                      *
195 *                                                                              *
196 *   Register R0 contains a pointer to the method info structure (prepared      *
197 *   by createcompilerstub). Using the return address in R26 and the            *
198 *   offset in the LDA instruction or using the value in methodptr R28 the      *
199 *   patching address for storing the method address can be computed:           *
200 *                                                                              *
201 *   method address was either loaded using                                     *
202 *                                                                              *
203 *   i386_mov_imm_reg(a, REG_ITMP2)                ; invokestatic/special       *
204 *   i386_call_reg(REG_ITMP2)                                                   *
205 *                                                                              *
206 *   or                                                                         *
207 *                                                                              *
208 *   i386_mov_membase_reg(REG_SP, 0, REG_ITMP2)    ; invokevirtual/interface    *
209 *   i386_mov_membase_reg(REG_ITMP2, OFFSET(, vftbl), REG_ITMP3)                *
210 *   i386_mov_membase_reg(REG_ITMP3, OFFSET(vftbl, table[0]) + \                *
211 *       sizeof(methodptr) * m->vftblindex, REG_ITMP1)                          *
212 *   i386_call_reg(REG_ITMP1)                                                   *
213 *                                                                              *
214 *   in the static case the method pointer can be computed using the            *
215 *   return address and the lda function following the jmp instruction          *
216 *                                                                              *
217 *******************************************************************************/
218
219 asm_call_jit_compiler:
220 L_asm_call_jit_compiler:                /* required for PIC code              */
221         sub     $(ARG_CNT+1)*8,sp           /* +1: keep stack 16-byte aligned     */
222
223         SAVE_ARGUMENT_REGISTERS(0)
224
225         mov     itmp1,a0                    /* pass methodinfo pointer            */
226         mov     mptr,a1                     /* pass method pointer                */
227         mov     sp,a2                       /* pass java sp                       */
228         add     $(1+ARG_CNT+1)*8,a2
229         mov     (ARG_CNT+1)*8(sp),a3        /* pass ra to java function           */
230         call    jit_asm_compile@PLT
231
232         RESTORE_ARGUMENT_REGISTERS(0)
233
234         add     $(ARG_CNT+1)*8,sp           /* remove stack frame                 */
235
236         test    v0,v0                       /* check for exception                */
237         je      L_asm_call_jit_compiler_exception
238
239         jmp     *v0                         /* ...and now call the new method     */
240
241 L_asm_call_jit_compiler_exception:
242         call    exceptions_get_and_clear_exception@PLT
243         pop     xpc                         /* delete return address              */
244         sub     $3,xpc                      /* faulting address is ra - 3         */
245         jmp     L_asm_handle_exception
246
247
248 /* asm_handle_exception ********************************************************
249 *                                                                              *
250 *   This function handles an exception. It does not use the usual calling      *
251 *   conventions. The exception pointer is passed in REG_ITMP1 and the          *
252 *   pc from the exception raising position is passed in REG_ITMP2. It searches *
253 *   the local exception table for a handler. If no one is found, it unwinds    *
254 *   stacks and continues searching the callers.                                *
255 *                                                                              *
256 *******************************************************************************/
257
258 asm_handle_nat_exception:
259         add     $8,sp                       /* clear return address of native stub*/
260                 
261 asm_handle_exception:
262 L_asm_handle_exception:                 /* required for PIC code              */
263         sub     $((ARG_CNT+TMP_CNT)*8),sp   /* create maybe-leaf stackframe       */
264
265         SAVE_ARGUMENT_REGISTERS(0)          /* we save arg and temp registers in  */
266         SAVE_TEMPORARY_REGISTERS(ARG_CNT)   /* case this is a leaf method         */
267
268         mov     $((ARG_CNT+TMP_CNT)*8),a3   /* prepare a3 for handle_exception    */
269         mov     $1,t0                       /* set maybe-leaf flag                */
270
271 L_asm_handle_exception_stack_loop:
272         sub     $(6*8),sp
273         mov     xptr,0*8(sp)                /* save exception pointer             */
274         mov     xpc,1*8(sp)                 /* save exception pc                  */
275         add     sp,a3                       /* calculate Java sp into a3...       */
276         add     $(6*8),a3
277         mov     a3,3*8(sp)                  /* ...and save it                     */
278         mov     t0,4*8(sp)                  /* save maybe-leaf flag               */
279
280         mov     xpc,a0                      /* exception pc                       */
281         call    codegen_get_pv_from_pc@PLT
282         mov     v0,2*8(sp)                  /* save data segment pointer          */
283         
284         mov     0*8(sp),a0                  /* pass exception pointer             */
285         mov     1*8(sp),a1                  /* pass exception pc                  */
286         mov     v0,a2                       /* pass data segment pointer          */
287         mov     3*8(sp),a3                  /* pass Java stack pointer            */
288         call    exceptions_handle_exception@PLT
289
290         test    v0,v0
291         jz      L_asm_handle_exception_not_catched
292
293         mov     v0,xpc                      /* move handlerpc into xpc            */
294         mov     0*8(sp),xptr                /* restore exception pointer          */
295         mov     4*8(sp),t0                  /* get maybe-leaf flag                */
296         add     $(6*8),sp                   /* free stack frame                   */
297
298         test    t0,t0                       /* test for maybe-leaf flag           */
299         jz      L_asm_handle_exception_no_leaf
300
301         RESTORE_ARGUMENT_REGISTERS(0)       /* if this is a leaf method, we have  */
302         RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers  */
303
304         add     $((ARG_CNT+TMP_CNT)*8),sp   /* remove maybe-leaf stackframe       */
305
306 L_asm_handle_exception_no_leaf:
307         jmp     *xpc                        /* jump to the handler                */
308
309 L_asm_handle_exception_not_catched:
310         mov     0*8(sp),xptr                /* restore exception pointer          */
311         mov     2*8(sp),itmp3               /* restore data segment pointer       */
312         mov     4*8(sp),t0                  /* get maybe-leaf flag                */
313         add     $(6*8),sp
314
315         test    t0,t0
316         jz      L_asm_handle_exception_no_leaf_stack
317
318         add     $((ARG_CNT+TMP_CNT)*8),sp   /* remove maybe-leaf stackframe       */
319         xor     t0,t0                       /* clear the isleaf flags             */
320
321 L_asm_handle_exception_no_leaf_stack:
322         mov     FrameSize(itmp3),itmp2l     /* get frame size                     */
323         add     sp,itmp2                    /* pointer to save area               */
324         
325         mov     IntSave(itmp3),a0l          /* a0l = saved int register count     */
326         test    a0l,a0l
327         je      noint
328         
329         cmp     $1,a0l
330         je      int1
331         cmp     $2,a0l
332         je      int2
333         cmp     $3,a0l
334         je      int3
335         cmp     $4,a0l
336         je      int4
337         
338         mov     -5*8(itmp2),s0
339 int4:   
340         mov     -4*8(itmp2),s1
341 int3:   
342         mov     -3*8(itmp2),s2
343 int2:   
344         mov     -2*8(itmp2),s3
345 int1:   
346         mov     -1*8(itmp2),s4
347
348         shl     $3,a0l                      /* multiply by 8 bytes                */
349         sub     a0,itmp2
350                 
351 noint:
352 #if 0
353         mov     FltSave(itmp3),a0l          /* a0l = saved flt register count     */
354         test    a0l,a0l
355         je      noflt
356         
357         cmpl    $1,a0l
358         je      flt1
359         cmpl    $2,a0l
360         je      flt2
361         cmpl    $3,a0l
362         je      flt3
363         cmpl    $4,a0l
364         je      flt4
365
366         movq    -5*8(itmp2),%xmm11
367 flt4:   
368         movq    -4*8(itmp2),%xmm12
369 flt3:   
370         movq    -3*8(itmp2),%xmm13
371 flt2:   
372         movq    -2*8(itmp2),%xmm14
373 flt1:   
374         movq    -1*8(itmp2),%xmm15
375                 
376 noflt:
377 #endif
378         mov     FrameSize(itmp3),itmp2l     /* get frame size                     */
379         add     itmp2,sp                    /* unwind stack                       */
380
381                                             /* exception pointer is still set     */
382         pop     xpc                         /* the new xpc is return address      */
383         sub     $3,xpc                      /* subtract 3 bytes for call          */
384
385         xor     a3,a3                       /* prepare a3 for handle_exception    */
386         
387         jmp             L_asm_handle_exception_stack_loop
388
389
390 /* asm_abstractmethoderror *****************************************************
391
392    Creates and throws an AbstractMethodError.
393
394 *******************************************************************************/
395
396 asm_abstractmethoderror:
397         mov     sp,a0                       /* pass java sp                       */
398         add     $1*8,a0
399         mov     0*8(sp),a1                  /* pass exception address             */
400         sub     $3,a1
401         call    exceptions_asm_new_abstractmethoderror@PLT
402                                             /* exception pointer is return value  */
403         pop     xpc                         /* get exception address              */
404         sub     $3,xpc                      /* exception address is ra - 3        */
405         jmp     L_asm_handle_exception
406
407
408 /* asm_patcher_wrapper *********************************************************
409
410    XXX
411
412    Stack layout:
413      40   return address
414      32   pointer to virtual java_objectheader
415      24   machine code (which is patched back later)
416      16   unresolved class/method/field reference
417       8   data segment displacement from load instructions
418       0   pointer to patcher function
419      -8   bp
420
421 *******************************************************************************/
422
423 asm_patcher_wrapper:
424         push    bp                          /* save base pointer                  */
425         mov     sp,bp                       /* move actual sp to bp               */
426         sub     $(3+ARG_CNT+TMP_CNT)*8,sp
427         and     $0xfffffffffffffff0,sp      /* align sp to 16-byte (this is for   */
428                                             /* leaf functions)                    */
429
430         SAVE_ARGUMENT_REGISTERS(3)
431         SAVE_TEMPORARY_REGISTERS(3+ARG_CNT)
432
433         mov     itmp1,0*8(sp)               /* save itmp1 and itmp2               */
434         mov     itmp2,1*8(sp)               /* can be used by some instructions   */
435
436         mov     bp,a0                       /* pass SP of patcher stub            */
437         add     $(1*8),a0
438         mov     $0,a1                       /* pass PV (if NULL, use findmethod)  */
439         mov     $0,a2                       /* pass RA (it's on the stack)        */
440         call    patcher_wrapper@PLT
441         mov     v0,2*8(sp)                  /* save return value                  */
442
443         RESTORE_ARGUMENT_REGISTERS(3)
444         RESTORE_TEMPORARY_REGISTERS(3+ARG_CNT)
445
446         mov     0*8(sp),itmp1               /* restore itmp1 and itmp2            */
447         mov     1*8(sp),itmp2               /* can be used by some instructions   */
448         mov     2*8(sp),itmp3               /* restore return value               */
449
450         mov     bp,sp                       /* restore original sp                */
451         pop     bp                          /* restore bp                         */
452         add     $(5*8),sp                   /* remove patcher stackframe, keep RA */
453
454         test    itmp3,itmp3                 /* exception thrown?                  */
455         jne     L_asm_patcher_wrapper_exception
456         ret                                 /* call new patched code              */
457
458 L_asm_patcher_wrapper_exception:
459         mov     itmp3,xptr                  /* get exception                      */
460         pop     xpc                         /* get and remove return address      */
461         jmp     L_asm_handle_exception
462
463 #if defined(ENABLE_REPLACEMENT)
464
465 /* asm_replacement_out *********************************************************
466
467    This code is jumped to from the replacement-out stubs that are executed
468    when a thread reaches an activated replacement point.
469
470    The purpose of asm_replacement_out is to read out the parts of the
471    execution state that cannot be accessed from C code, store this state,
472    and then call the C function replace_me.
473
474    Stack layout:
475       8                 start of stack inside method to replace
476       0   rplpoint *    info on the replacement point that was reached
477
478 *******************************************************************************/
479
480 /* some room to accomodate changes of the stack frame size during replacement */
481         /* XXX we should find a cleaner solution here */
482 #define REPLACEMENT_ROOM  512
483
484 asm_replacement_out:
485     /* create stack frame */
486         sub     $(sizeexecutionstate + REPLACEMENT_ROOM),sp
487
488         /* save registers in execution state */
489         mov     %rax,(RAX*8+offes_intregs)(sp)
490         mov     %rbx,(RBX*8+offes_intregs)(sp)
491         mov     %rcx,(RCX*8+offes_intregs)(sp)
492         mov     %rdx,(RDX*8+offes_intregs)(sp)
493         mov     %rsi,(RSI*8+offes_intregs)(sp)
494         mov     %rdi,(RDI*8+offes_intregs)(sp)
495         mov     %rbp,(RBP*8+offes_intregs)(sp)
496         movq    $0  ,(RSP*8+offes_intregs)(sp) /* not used */
497         mov     %r8 ,(R8 *8+offes_intregs)(sp)
498         mov     %r9 ,(R9 *8+offes_intregs)(sp)
499         mov     %r10,(R10*8+offes_intregs)(sp)
500         mov     %r11,(R11*8+offes_intregs)(sp)
501         mov     %r12,(R12*8+offes_intregs)(sp)
502         mov     %r13,(R13*8+offes_intregs)(sp)
503         mov     %r14,(R14*8+offes_intregs)(sp)
504         mov     %r15,(R15*8+offes_intregs)(sp)
505
506         movq    %xmm0 ,(XMM0 *8+offes_fltregs)(sp)
507         movq    %xmm1 ,(XMM1 *8+offes_fltregs)(sp)
508         movq    %xmm2 ,(XMM2 *8+offes_fltregs)(sp)
509         movq    %xmm3 ,(XMM3 *8+offes_fltregs)(sp)
510         movq    %xmm4 ,(XMM4 *8+offes_fltregs)(sp)
511         movq    %xmm5 ,(XMM5 *8+offes_fltregs)(sp)
512         movq    %xmm6 ,(XMM6 *8+offes_fltregs)(sp)
513         movq    %xmm7 ,(XMM7 *8+offes_fltregs)(sp)
514         movq    %xmm8 ,(XMM8 *8+offes_fltregs)(sp)
515         movq    %xmm9 ,(XMM9 *8+offes_fltregs)(sp)
516         movq    %xmm10,(XMM10*8+offes_fltregs)(sp)
517         movq    %xmm11,(XMM11*8+offes_fltregs)(sp)
518         movq    %xmm12,(XMM12*8+offes_fltregs)(sp)
519         movq    %xmm13,(XMM13*8+offes_fltregs)(sp)
520         movq    %xmm14,(XMM14*8+offes_fltregs)(sp)
521         movq    %xmm15,(XMM15*8+offes_fltregs)(sp)
522
523         /* calculate sp of method */
524         mov     sp,itmp1
525         add     $(sizeexecutionstate + REPLACEMENT_ROOM + 8),itmp1
526         mov     itmp1,(offes_sp)(sp)
527
528         /* pv must be looked up via AVL tree */
529         movq    $0,(offes_pv)(sp)
530
531         /* call replace_me */
532         mov     -8(itmp1),a0                /* rplpoint *                         */
533     mov     sp,a1                       /* arg1: execution state              */
534     call    replace_me@PLT              /* call C function replace_me         */
535     call    abort@PLT                   /* NEVER REACHED                      */
536
537 /* asm_replacement_in **********************************************************
538
539    This code writes the given execution state and jumps to the replacement
540    code.
541
542    This function never returns!
543
544    C prototype:
545       void asm_replacement_in(executionstate *es, replace_safestack_t *st);
546
547 *******************************************************************************/
548
549 asm_replacement_in:
550         /* get arguments */
551         mov     a1,s1                       /* replace_safestack_t *st            */
552         mov     a0,%rbp                     /* executionstate *es == safe stack   */
553
554         /* switch to the safe stack */
555         mov     %rbp,sp
556
557         /* call replace_build_execution_state(st) */
558         mov             s1,a0
559         call    replace_build_execution_state@PLT
560
561         /* set new sp */
562         mov     (offes_sp)(%rbp),sp
563
564         /* push address of new code */
565         pushq   (offes_pc)(%rbp)
566
567         /* allocate an executionstate_t on the stack */
568         sub             $(sizeexecutionstate),sp
569
570         /* call replace_free_safestack(st,& of allocated executionstate_t) */
571         mov             sp,a1
572         mov             s1,a0
573         call    replace_free_safestack@PLT
574
575         /* copy registers from execution state */
576         movq    (XMM0 *8+offes_fltregs)(sp),%xmm0
577         movq    (XMM1 *8+offes_fltregs)(sp),%xmm1
578         movq    (XMM2 *8+offes_fltregs)(sp),%xmm2
579         movq    (XMM3 *8+offes_fltregs)(sp),%xmm3
580         movq    (XMM4 *8+offes_fltregs)(sp),%xmm4
581         movq    (XMM5 *8+offes_fltregs)(sp),%xmm5
582         movq    (XMM6 *8+offes_fltregs)(sp),%xmm6
583         movq    (XMM7 *8+offes_fltregs)(sp),%xmm7
584         movq    (XMM8 *8+offes_fltregs)(sp),%xmm8
585         movq    (XMM9 *8+offes_fltregs)(sp),%xmm9
586         movq    (XMM10*8+offes_fltregs)(sp),%xmm10
587         movq    (XMM11*8+offes_fltregs)(sp),%xmm11
588         movq    (XMM12*8+offes_fltregs)(sp),%xmm12
589         movq    (XMM13*8+offes_fltregs)(sp),%xmm13
590         movq    (XMM14*8+offes_fltregs)(sp),%xmm14
591         movq    (XMM15*8+offes_fltregs)(sp),%xmm15
592
593         mov     (RAX*8+offes_intregs)(sp),%rax
594         mov     (RBX*8+offes_intregs)(sp),%rbx
595         mov     (RCX*8+offes_intregs)(sp),%rcx
596         mov     (RDX*8+offes_intregs)(sp),%rdx
597         mov     (RSI*8+offes_intregs)(sp),%rsi
598         mov     (RDI*8+offes_intregs)(sp),%rdi
599         mov     (RBP*8+offes_intregs)(sp),%rbp
600         mov     (R8 *8+offes_intregs)(sp),%r8
601         mov     (R9 *8+offes_intregs)(sp),%r9
602         mov     (R10*8+offes_intregs)(sp),%r10
603         mov     (R11*8+offes_intregs)(sp),%r11
604         mov     (R12*8+offes_intregs)(sp),%r12
605         mov     (R13*8+offes_intregs)(sp),%r13
606         mov     (R14*8+offes_intregs)(sp),%r14
607         mov     (R15*8+offes_intregs)(sp),%r15
608
609         /* pop the execution state off the stack */
610         add             $(sizeexecutionstate),sp
611
612         /* jump to new code */
613         ret
614
615 #endif /* defined(ENABLE_REPLACEMENT) */
616
617
618 /* asm_builtin_x2x *************************************************************
619 *                                                                              *
620 *   Wrapper functions for float to int corner cases                            *
621 *                                                                              *
622 *******************************************************************************/
623
624 asm_builtin_f2i:
625         sub     $(ARG_CNT*8),sp
626         
627         SAVE_ARGUMENT_REGISTERS(0)
628         
629         movq    ftmp1,fa0
630         call    builtin_f2i@PLT
631         
632         RESTORE_ARGUMENT_REGISTERS(0)
633         
634         add     $(ARG_CNT*8),sp
635         ret
636
637
638 asm_builtin_f2l:
639         sub     $(ARG_CNT*8),sp
640         
641         SAVE_ARGUMENT_REGISTERS(0)
642         
643         movq    ftmp1,fa0
644         call    builtin_f2l@PLT
645         
646         RESTORE_ARGUMENT_REGISTERS(0)
647         
648         add     $(ARG_CNT*8),sp
649         ret
650
651
652 asm_builtin_d2i:
653         sub     $(ARG_CNT*8),sp
654         
655         SAVE_ARGUMENT_REGISTERS(0)
656         
657         movq    ftmp1,fa0
658         call    builtin_d2i@PLT
659         
660         RESTORE_ARGUMENT_REGISTERS(0)
661         
662         add     $(ARG_CNT*8),sp
663         ret
664
665
666 asm_builtin_d2l:
667         sub     $(ARG_CNT*8),sp
668         
669         SAVE_ARGUMENT_REGISTERS(0)
670         
671         movq    ftmp1,fa0
672         call    builtin_d2l@PLT
673         
674         RESTORE_ARGUMENT_REGISTERS(0)
675         
676         add     $(ARG_CNT*8),sp
677         ret
678
679
680 /* asm_compare_and_swap ********************************************************
681
682    Does an atomic compare and swap.  Required for the lock
683    implementation.
684
685 *******************************************************************************/
686
687 asm_compare_and_swap:
688         mov     a1,v0                       /* v0 is %rax                         */
689         lock cmpxchg a2,(a0)
690         ret
691
692
693 /* asm_memory_barrier **********************************************************
694
695    A memory barrier for the Java Memory Model.
696
697 *******************************************************************************/
698
699 asm_memory_barrier:
700         mfence
701         ret
702
703
704 /* disable exec-stacks ********************************************************/
705
706 #if defined(__linux__) && defined(__ELF__)
707         .section .note.GNU-stack,"",%progbits
708 #endif
709
710
711 /*
712  * These are local overrides for various environment variables in Emacs.
713  * Please do not remove this and leave it at the end of the file, where
714  * Emacs will automagically detect them.
715  * ---------------------------------------------------------------------
716  * Local variables:
717  * mode: asm
718  * indent-tabs-mode: t
719  * c-basic-offset: 4
720  * tab-width: 4
721  * End:
722  * vim:noexpandtab:sw=4:ts=4:
723  */