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