* src/vm/signallocal.h (signal_handle): Changed signature.
[cacao.git] / src / vm / jit / powerpc / asmpart.S
1 /* src/vm/jit/powerpc/asmpart.S - Java-C interface functions for PowerPC
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.text;  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 "md-abi.h"
31 #include "md-asm.h"
32
33 #include "vm/jit/abi-asm.h"
34 #include "vm/jit/methodheader.h"
35
36
37         .text
38
39         .align 2
40
41
42 /* export functions ***********************************************************/
43
44         .globl asm_vm_call_method
45         .globl asm_vm_call_method_int
46         .globl asm_vm_call_method_long
47         .globl asm_vm_call_method_float
48         .globl asm_vm_call_method_double
49
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_nat_exception
56         .globl asm_handle_exception
57
58         .globl asm_abstractmethoderror
59
60         .globl asm_cacheflush
61
62         .globl asm_compare_and_swap
63         .globl asm_memory_barrier
64
65
66 /* asm_vm_call_method **********************************************************
67 *                                                                              *
68 *   This function calls a Java-method (which possibly needs compilation)       *
69 *   with up to 4 address parameters.                                           *
70 *                                                                              *
71 *   This functions calls the JIT-compiler which eventually translates the      *
72 *   method into machine code.                                                  *
73 *                                                                              *
74 *   C-prototype:                                                               *
75 *    javaobject_header *asm_calljavamethod (methodinfo *m,                     *
76 *         void *arg1, void *arg2, void *arg3, void *arg4);                     *
77 *                                                                              *
78 *******************************************************************************/
79
80         .align 2
81
82         .long   0                         /* catch type all                       */
83         .long   0                         /* exception handler pc                 */
84         .long   0                         /* end pc                               */
85         .long   0                         /* start pc                             */
86         .long   1                         /* extable size                         */
87         .long   0                         /* line number table start              */
88         .long   0                         /* line number table size               */
89         .long   0                         /* fltsave                              */
90         .long   0                         /* intsave                              */
91         .long   0                         /* IsLeaf                               */
92         .long   0                         /* IsSync                               */
93         .long   0                         /* frame size                           */
94         .long   0                         /* codeinfo pointer                     */
95
96 asm_vm_call_method:
97 asm_vm_call_method_int:
98 asm_vm_call_method_long:
99 asm_vm_call_method_float:
100 asm_vm_call_method_double:
101         mflr    r0
102         stw     r0,LA_LR_OFFSET(sp)
103         stwu    sp,-40*4(sp)              /* keep stack 16-byte aligned           */
104
105         stw     s0,8*4(sp)                /* save used callee saved registers     */
106         stw     a0,9*4(sp)                /* save method PV                       */
107
108 #if defined(__DARWIN__)
109         stw     itmp1,10*4(sp)            /* register r11 is callee saved         */
110 #endif
111         stw     pv,11*4(sp)               /* save PV register                     */
112
113         stw     itmp3,12*4(sp)            /* registers r14-r31 are callee saved   */
114         stfd    ftmp1,14*4(sp)            /* registers f14-f31 are callee saved   */
115         stfd    ftmp2,16*4(sp)
116
117 #if defined(__DARWIN__)
118         stw     t1,18*4(sp)
119         stw     t2,19*4(sp)
120         stw     t3,20*4(sp)
121         stw     t4,21*4(sp)
122         stw     t5,22*4(sp)
123         stw     t6,23*4(sp)
124         stw     t7,24*4(sp)
125
126         stfd    ft0,26*4(sp)
127         stfd    ft1,28*4(sp)
128         stfd    ft2,30*4(sp)
129         stfd    ft3,32*4(sp)
130         stfd    ft4,34*4(sp)
131         stfd    ft5,36*4(sp)
132 #else
133         SAVE_TEMPORARY_REGISTERS(18)        /* the offset has to be even          */
134 #endif
135
136         mr      t0,a1                       /* address of data structure          */
137         mr      t1,a2                       /* stack argument count               */
138
139         mr      s0,sp                       /* save SP                            */
140
141         lwz     a0,0*8+4(t0)                /* we are on big-endian               */
142         lwz     a1,1*8+4(t0)
143         lwz     a2,2*8+4(t0)
144         lwz     a3,3*8+4(t0)
145         lwz     a4,4*8+4(t0)
146         lwz     a5,5*8+4(t0)
147         lwz     a6,6*8+4(t0)
148         lwz     a7,7*8+4(t0)
149
150         lfd     fa0,8*8(t0)
151         lfd     fa1,9*8(t0)
152         lfd     fa2,10*8(t0)
153         lfd     fa3,11*8(t0)
154         lfd     fa4,12*8(t0)
155         lfd     fa5,13*8(t0)
156         lfd     fa6,14*8(t0)
157         lfd     fa7,15*8(t0)
158
159 #if defined(__DARWIN__)
160         lfd     fa8,16*8(t0)
161         lfd     fa9,17*8(t0)
162         lfd     fa10,18*8(t0)
163         lfd     fa11,19*8(t0)
164         lfd     fa12,20*8(t0)
165 #endif
166
167         mr.     t1,t1
168         beq     L_asm_vm_call_method_stack_copy_done
169
170         slwi    t2,t1,3                     /* calculate stackframe size (* 8)    */
171
172         sub     sp,sp,t2                    /* create stackframe                  */
173         mr      t2,sp                       /* temporary stack pointer            */
174
175 L_asm_vm_call_method_stack_copy_loop:
176 #if defined(__DARWIN__)
177         lwz     t3,21*8+0(t0)               /* load argument                      */
178         lwz     t4,21*8+4(t0)
179 #else
180         lwz     t3,16*8+0(t0)               /* load argument                      */
181         lwz     t4,16*8+4(t0)
182 #endif
183         stw     t3,0(t2)                    /* store argument on stack            */
184         stw     t4,4(t2)
185
186         addi    t0,t0,8                     /* load address of next argument      */
187         addi    t2,t2,8                     /* increase stack pointer             */
188         addi    t1,t1,-1                    /* subtract 1 argument                */
189         mr.     t1,t1
190         bgt     L_asm_vm_call_method_stack_copy_loop
191
192 L_asm_vm_call_method_stack_copy_done:
193         addi    mptr,s0,9*4                 /* get address of PV                  */
194         lwz     pv,0*4(mptr)                /* load PV                            */
195         mtctr   pv
196         bctrl
197 1:
198         mflr    itmp1
199 #if defined(__DARWIN__)
200         addi    pv,itmp1,lo16(asm_vm_call_method - 1b)
201 #else
202         addi    pv,itmp1,(asm_vm_call_method - 1b)@l
203 #endif
204
205 L_asm_vm_call_method_return:
206         mr      sp,s0                       /* restore the SP                     */
207
208         lwz     s0,8*4(sp)                  /* restore used callee saved registers*/
209
210 #if defined(__DARWIN__)
211         lwz     itmp1,10*4(sp)              /* register r11 is callee saved       */
212 #endif
213         lwz     pv,11*4(sp)                 /* save PV register                   */
214
215         lwz     itmp3,12*4(sp)
216         lfd     ftmp1,14*4(sp)              /* registers f14-f31 are callee saved */
217         lfd     ftmp2,16*4(sp)
218
219 #if defined(__DARWIN__)
220         lwz     t1,18*4(sp)
221         lwz     t2,19*4(sp)
222         lwz     t3,20*4(sp)
223         lwz     t4,21*4(sp)
224         lwz     t5,22*4(sp)
225         lwz     t6,23*4(sp)
226         lwz     t7,24*4(sp)
227
228         lfd     ft0,26*4(sp)
229         lfd     ft1,28*4(sp)
230         lfd     ft2,30*4(sp)
231         lfd     ft3,32*4(sp)
232         lfd     ft4,34*4(sp)
233         lfd     ft5,36*4(sp)
234 #else
235         RESTORE_TEMPORARY_REGISTERS(18)   /* the offset has to be even            */
236 #endif
237
238         lwz     r0,40*4+LA_LR_OFFSET(sp)
239         mtlr    r0
240         addi    sp,sp,40*4
241         blr
242
243 asm_vm_call_method_exception_handler:
244         mr      a0,itmp1
245         bl      builtin_throw_exception
246         b       L_asm_vm_call_method_return
247
248 asm_vm_call_method_end:
249         nop
250
251
252 /* asm_call_jit_compiler *******************************************************
253
254    Invokes the compiler for untranslated JavaVM methods.
255
256 *******************************************************************************/
257
258 asm_call_jit_compiler:
259 L_asm_call_jit_compiler:                /* required for PIC code              */
260         mflr    r0
261         stw     r0,LA_LR_OFFSET(sp)         /* save return address                */
262         stwu    sp,-(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)(sp)
263
264 #if defined(__DARWIN__)
265         stw     a0,LA_SIZE+(4+0)*4(sp)
266         stw     a1,LA_SIZE+(4+1)*4(sp)
267         stw     a2,LA_SIZE+(4+2)*4(sp)
268         stw     a3,LA_SIZE+(4+3)*4(sp)
269         stw     a4,LA_SIZE+(4+4)*4(sp)
270         stw     a5,LA_SIZE+(4+5)*4(sp)
271         stw     a6,LA_SIZE+(4+6)*4(sp)
272         stw     a7,LA_SIZE+(4+7)*4(sp)
273
274         stfd    fa0,LA_SIZE+(4+8)*4(sp)
275         stfd    fa1,LA_SIZE+(4+10)*4(sp)
276         stfd    fa2,LA_SIZE+(4+12)*4(sp)
277         stfd    fa3,LA_SIZE+(4+14)*4(sp)
278         stfd    fa4,LA_SIZE+(4+16)*4(sp)
279         stfd    fa5,LA_SIZE+(4+18)*4(sp)
280         stfd    fa6,LA_SIZE+(4+20)*4(sp)
281         stfd    fa7,LA_SIZE+(4+22)*4(sp)
282         stfd    fa8,LA_SIZE+(4+24)*4(sp)
283         stfd    fa9,LA_SIZE+(4+26)*4(sp)
284         stfd    fa10,LA_SIZE+(4+28)*4(sp)
285         stfd    fa11,LA_SIZE+(4+30)*4(sp)
286         stfd    fa12,LA_SIZE+(4+32)*4(sp)
287 #else
288         SAVE_ARGUMENT_REGISTERS(LA_SIZE_IN_POINTERS)
289 #endif
290
291         mr      a0,itmp1
292         mr      a1,mptr
293         addi    a2,sp,(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)
294         lwz     a3,(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)+LA_LR_OFFSET(sp)
295         bl      jit_asm_compile
296         mr      pv,v0                       /* move address to pv register        */
297
298 #if defined(__DARWIN__)
299         lwz     a0,LA_SIZE+(4+0)*4(sp)
300         lwz     a1,LA_SIZE+(4+1)*4(sp)
301         lwz     a2,LA_SIZE+(4+2)*4(sp)
302         lwz     a3,LA_SIZE+(4+3)*4(sp)
303         lwz     a4,LA_SIZE+(4+4)*4(sp)
304         lwz     a5,LA_SIZE+(4+5)*4(sp)
305         lwz     a6,LA_SIZE+(4+6)*4(sp)
306         lwz     a7,LA_SIZE+(4+7)*4(sp)
307
308         lfd     fa0,LA_SIZE+(4+8)*4(sp)
309         lfd     fa1,LA_SIZE+(4+10)*4(sp)
310         lfd     fa2,LA_SIZE+(4+12)*4(sp)
311         lfd     fa3,LA_SIZE+(4+14)*4(sp)
312         lfd     fa4,LA_SIZE+(4+16)*4(sp)
313         lfd     fa5,LA_SIZE+(4+18)*4(sp)
314         lfd     fa6,LA_SIZE+(4+20)*4(sp)
315         lfd     fa7,LA_SIZE+(4+22)*4(sp)
316         lfd     fa8,LA_SIZE+(4+24)*4(sp)
317         lfd     fa9,LA_SIZE+(4+26)*4(sp)
318         lfd     fa10,LA_SIZE+(4+28)*4(sp)
319         lfd     fa11,LA_SIZE+(4+30)*4(sp)
320         lfd     fa12,LA_SIZE+(4+32)*4(sp)
321 #else
322         RESTORE_ARGUMENT_REGISTERS(LA_SIZE_IN_POINTERS)
323 #endif
324
325         lwz     itmp1,(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)+LA_LR_OFFSET(sp)
326         mtlr    itmp1
327
328         addi    sp,sp,(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)
329
330         mr.     pv,pv                       /* test for exception                 */
331         beq     L_asm_call_jit_compiler_exception
332
333         mtctr   pv                          /* move method address to control reg */
334         bctr                                /* and call the Java method           */
335
336 L_asm_call_jit_compiler_exception:
337         mflr    r0
338         stw     r0,LA_LR_OFFSET(sp)
339         stwu    sp,-LA_SIZE_ALIGNED(sp)     /* preserve linkage area              */
340         bl      exceptions_get_and_clear_exception
341         lwz     xpc,LA_SIZE_ALIGNED+LA_LR_OFFSET(sp)
342         mtlr    xpc     
343         addi    sp,sp,LA_SIZE_ALIGNED
344
345         mr      xptr,v0                     /* get exception                      */
346         addi    xpc,xpc,-4                  /* exception address is ra - 4        */
347         b       L_asm_handle_nat_exception
348
349
350 /********************* function asm_handle_exception ***************************
351 *                                                                              *
352 *   This function handles an exception. It does not use the usual calling      *
353 *   conventions. The exception pointer is passed in REG_ITMP1 and the          *
354 *   pc from the exception raising position is passed in REG_ITMP2. It searches *
355 *   the local exception table for a handler. If no one is found, it unwinds    *
356 *   stacks and continues searching the callers.                                *
357 *                                                                              *
358 *   void asm_handle_exception (exceptionptr, exceptionpc);                     *
359 *                                                                              *
360 *******************************************************************************/
361                 
362 asm_handle_nat_exception:
363 L_asm_handle_nat_exception:             /* required for PIC code              */
364 L_asm_handle_exception_stack_loop:
365         mflr    r0
366         addi    sp,sp,-(LA_SIZE+((4+6)*4))  /* allocate stack (+4 for darwin)     */
367         stw     xptr,LA_SIZE+(4+0)*4(sp)    /* save exception pointer             */
368         stw     xpc,LA_SIZE+(4+1)*4(sp)     /* save exception pc                  */
369         stw     r0,LA_SIZE+(4+3)*4(sp)      /* save return address                */
370         li      itmp3,0
371         stw     itmp3,LA_SIZE+(4+4)*4(sp)   /* save maybe-leaf flag (cleared)     */
372
373         mr      a0,r0                       /* pass return address                */
374         bl      md_codegen_get_pv_from_pc   /* get PV from RA                     */
375         stw     v0,LA_SIZE+(4+2)*4(sp)      /* save data segment pointer          */
376
377         lwz     a0,LA_SIZE+(4+0)*4(sp)      /* pass xptr                          */
378         lwz     a1,LA_SIZE+(4+1)*4(sp)      /* pass xpc                           */
379         lwz     a2,LA_SIZE+(4+2)*4(sp)      /* pass PV (v0 == a0)                 */
380         addi    a3,sp,LA_SIZE+((4+6)*4)     /* pass Java SP                       */
381
382         b       L_asm_handle_exception_continue
383
384 asm_handle_exception:
385 L_asm_handle_exception:                 /* required for PIC code              */
386         addi    sp,sp,-(ARG_CNT+TMP_CNT)*8  /* create maybe-leaf stackframe       */
387
388 #if defined(__DARWIN__)
389 #else
390         SAVE_ARGUMENT_REGISTERS(0)          /* we save arg and temp registers in  */
391         SAVE_TEMPORARY_REGISTERS(ARG_CNT)   /* case this is a leaf method         */
392 #endif
393
394         addi    sp,sp,-(LA_SIZE+(4+6)*4)    /* allocate stack                     */
395         stw     xptr,LA_SIZE+(4+0)*4(sp)    /* save xptr                          */
396         stw     pv,LA_SIZE+(4+2)*4(sp)      /* save PV                            */
397         mflr    r0                          /* save RA                            */
398         stw     r0,LA_SIZE+(4+3)*4(sp)
399         li      t0,1                        /* set maybe-leaf flag                */
400         stw     t0,LA_SIZE+(4+4)*4(sp)      /* save maybe-leaf flag               */
401
402         mr      a0,xptr                     /* pass exception pointer             */
403         mr      a1,xpc                      /* pass exception pc                  */
404         mr      a2,pv                       /* pass data segment pointer          */
405         addi    a3,sp,LA_SIZE+(ARG_CNT+TMP_CNT)*8+(4+6)*4
406
407 L_asm_handle_exception_continue:
408         bl      exceptions_handle_exception
409
410         mr.     v0,v0
411         beq     L_asm_handle_exception_not_catched
412
413         mr      xpc,v0                      /* move handlerpc into xpc            */
414         lwz     xptr,LA_SIZE+(4+0)*4(sp)    /* restore xptr                       */
415         lwz     pv,LA_SIZE+(4+2)*4(sp)      /* restore PV                         */
416         lwz     r0,LA_SIZE+(4+3)*4(sp)      /* restore RA                         */
417         mtlr    r0
418         lwz     t0,LA_SIZE+(4+4)*4(sp)      /* get maybe-leaf flag                */
419         addi    sp,sp,LA_SIZE+(4+6)*4       /* free stack frame                   */
420
421         mr.     t0,t0
422         beq     L_asm_handle_exception_no_leaf
423
424 #if defined(__DARWIN__)
425 #else
426         RESTORE_ARGUMENT_REGISTERS(0)       /* if this is a leaf method, we have  */
427         RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers  */
428 #endif
429
430         addi    sp,sp,(ARG_CNT+TMP_CNT)*8   /* remove maybe-leaf stackframe       */
431
432 L_asm_handle_exception_no_leaf:
433         mtctr   xpc                         /* jump to the handler                */
434         bctr
435
436 L_asm_handle_exception_not_catched:
437         lwz     xptr,LA_SIZE+(4+0)*4(sp)    /* restore xptr                       */
438         lwz     pv,LA_SIZE+(4+2)*4(sp)      /* restore PV                         */
439         lwz     r0,LA_SIZE+(4+3)*4(sp)      /* restore RA                         */
440         mtlr    r0
441         lwz     t0,LA_SIZE+(4+4)*4(sp)      /* get maybe-leaf flag                */
442         addi    sp,sp,LA_SIZE+(4+6)*4       /* free stack frame                   */
443
444         mr.     t0,t0
445         beq     L_asm_handle_exception_no_leaf_stack
446
447         addi    sp,sp,(ARG_CNT+TMP_CNT)*8   /* remove maybe-leaf stackframe       */
448         li      t0,0                        /* clear the maybe-leaf flag          */
449
450 L_asm_handle_exception_no_leaf_stack:
451         lwz     t1,FrameSize(pv)            /* get frame size                     */
452         add     t1,sp,t1                    /* pointer to save area               */
453
454         lwz     t2,IsLeaf(pv)               /* is leaf procedure                  */
455         mr.     t2,t2
456         bne     L_asm_handle_exception_no_ra_restore
457
458         lwz     r0,LA_LR_OFFSET(t1)         /* restore ra                         */
459         mtlr    r0
460
461 L_asm_handle_exception_no_ra_restore:
462         mflr    xpc                         /* the new xpc is ra                  */
463         mr      t4,xpc                      /* save RA                            */
464         lwz     t2,IntSave(pv)              /* t2 = saved int register count      */
465         bl      ex_int1
466 ex_int1:
467         mflr    t3                          /* t3 = current pc                    */
468 #if defined(__DARWIN__)
469         addi    t3,t3,lo16(ex_int2-ex_int1)
470 #else
471         addi    t3,t3,(ex_int2-ex_int1)@l
472 #endif
473         slwi    t2,t2,2                     /* t2 = register count * 4            */
474         subf    t3,t2,t3                    /* t3 = IntSave - t2                  */
475         mtctr   t3
476         bctr
477
478         lwz     s0,-10*8(t1)
479         lwz     s1,-9*8(t1)
480         lwz     s2,-8*8(t1)
481         lwz     s3,-7*8(t1)
482         lwz     s4,-6*8(t1)
483         lwz     s5,-5*8(t1)
484         lwz     s6,-4*8(t1)
485         lwz     s7,-3*8(t1)
486         lwz     s8,-2*8(t1)
487         lwz     s9,-1*8(t1)
488
489 ex_int2:
490         subf    t1,t2,t1                    /* t1 = t1 - register count * 4       */
491
492         lwz     t2,FltSave(pv)
493         bl      ex_flt1
494 ex_flt1:
495         mflr    t3
496 #if defined(__DARWIN__)
497         addi    t3,t3,lo16(ex_flt2-ex_flt1)
498 #else
499         addi    t3,t3,(ex_flt2-ex_flt1)@l
500 #endif
501         slwi    t2,t2,2                     /* t2 = register count * 4            */
502         subf    t3,t2,t3                    /* t3 = FltSave - t2                  */
503         mtctr   t3
504         bctr
505
506         lfd     fs0,-10*8(t1)
507         lfd     fs1,-9*8(t1)
508         lfd     fs2,-8*8(t1)
509         lfd     fs3,-7*8(t1)
510         lfd     fs4,-6*8(t1)
511         lfd     fs5,-5*8(t1)
512         lfd     fs6,-4*8(t1)
513         lfd     fs7,-3*8(t1)
514         lfd     fs8,-2*8(t1)
515         lfd     fs9,-1*8(t1)
516
517 ex_flt2:
518         mtlr    t4                          /* restore RA                         */
519         lwz     t1,FrameSize(pv)            /* get frame size                     */
520         add     sp,sp,t1                    /* unwind stack                       */
521         b       L_asm_handle_exception_stack_loop
522
523
524 /* asm_abstractmethoderror *****************************************************
525
526    Creates and throws an AbstractMethodError.
527
528 *******************************************************************************/
529
530 asm_abstractmethoderror:
531         mflr    r0
532         stw     r0,LA_LR_OFFSET(sp)
533         stwu    sp,-LA_SIZE_ALIGNED(sp)     /* preserve linkage area              */
534         addi    a0,sp,LA_SIZE_ALIGNED       /* pass java sp                       */
535         mr      a1,r0                       /* pass exception address             */
536         bl      exceptions_asm_new_abstractmethoderror
537         lwz     r0,LA_SIZE_ALIGNED+LA_LR_OFFSET(sp)
538         mtlr    r0                          /* restore return address             */
539         addi    sp,sp,LA_SIZE_ALIGNED
540
541         mr      xptr,v0                     /* get exception pointer              */
542         mr      xpc,r0                      /* we can't use r0 directly in addi   */
543         addi    xpc,xpc,-4                  /* exception address is ra - 4        */
544         b       L_asm_handle_nat_exception
545
546
547 /*********************************************************************/
548
549 asm_cacheflush:
550         add     a1,a0,a1
551         rlwinm  a0,a0,0,0,26
552         addi    a1,a1,31
553         rlwinm  a1,a1,0,0,26
554         mr      a2,a0
555 1:
556         cmplw   a0,a1
557         bge     0f
558         dcbst   0,a0
559         addi    a0,a0,32
560         b       1b
561 0:
562         sync
563 1:
564         cmplw   a2,a1
565         bge     0f
566         icbi    0,a2
567         addi    a2,a2,32
568         b       1b
569 0:
570         sync
571         isync
572         blr
573
574
575 /* asm_compare_and_swap ********************************************************
576
577    XXX
578
579 *******************************************************************************/
580
581 asm_compare_and_swap:
582 1:
583         lwarx   a6,0,a0 
584         subf.   r0,a6,a1 
585         bne-    2f 
586         or      r0,a2,a2 
587         stwcx.  r0,0,a0 
588         bne-    1b 
589 2: 
590         mr      a0,a6
591         blr
592
593
594 /* asm_memory_barrier **********************************************************
595
596    XXX
597
598 *******************************************************************************/
599
600 asm_memory_barrier:
601         sync
602         blr
603
604
605 #if defined(__DARWIN__)
606
607 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
608         .align 2
609 L_builtin_throw_exception$stub:
610         .indirect_symbol _builtin_throw_exception
611         mflr r0
612         bcl 20,31,L00$_builtin_throw_exception
613 L00$_builtin_throw_exception:
614         mflr r11
615         addis r11,r11,ha16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)
616         mtlr r0
617         lwzu r12,lo16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)(r11)
618         mtctr r12
619         bctr
620 .data
621 .lazy_symbol_pointer
622 L_builtin_throw_exception$lazy_ptr:
623         .indirect_symbol _builtin_throw_exception
624         .long dyld_stub_binding_helper
625
626
627 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
628         .align 2
629 L_md_codegen_get_pv_from_pc$stub:
630         .indirect_symbol _md_codegen_get_pv_from_pc
631         mflr r0
632         bcl 20,31,L00$_md_codegen_get_pv_from_pc
633 L00$_md_codegen_get_pv_from_pc:
634         mflr r11
635         addis r11,r11,ha16(L_md_codegen_get_pv_from_pc$lazy_ptr - L00$_md_codegen_get_pv_from_pc)
636         mtlr r0
637         lwzu r12,lo16(L_md_codegen_get_pv_from_pc$lazy_ptr - L00$_md_codegen_get_pv_from_pc)(r11)
638         mtctr r12
639         bctr
640 .data
641 .lazy_symbol_pointer
642 L_md_codegen_get_pv_from_pc$lazy_ptr:
643         .indirect_symbol _md_codegen_get_pv_from_pc
644         .long dyld_stub_binding_helper
645
646
647 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
648         .align 2
649 L_exceptions_handle_exception$stub:
650         .indirect_symbol _exceptions_handle_exception
651         mflr r0
652         bcl 20,31,L00$_exceptions_handle_exception
653 L00$_exceptions_handle_exception:
654         mflr r11
655         addis r11,r11,ha16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)
656         mtlr r0
657         lwzu r12,lo16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)(r11)
658         mtctr r12
659         bctr
660 .data
661 .lazy_symbol_pointer
662 L_exceptions_handle_exception$lazy_ptr:
663         .indirect_symbol _exceptions_handle_exception
664         .long dyld_stub_binding_helper
665
666
667 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
668         .align 2
669 L_stacktrace_create_extern_stackframeinfo$stub:
670         .indirect_symbol _stacktrace_create_extern_stackframeinfo
671         mflr r0
672         bcl 20,31,L00$_stacktrace_create_extern_stackframeinfo
673 L00$_stacktrace_create_extern_stackframeinfo:
674         mflr r11
675         addis r11,r11,ha16(L_stacktrace_create_extern_stackframeinfo$lazy_ptr - L00$_stacktrace_create_extern_stackframeinfo)
676         mtlr r0
677         lwzu r12,lo16(L_stacktrace_create_extern_stackframeinfo$lazy_ptr - L00$_stacktrace_create_extern_stackframeinfo)(r11)
678         mtctr r12
679         bctr
680 .data
681 .lazy_symbol_pointer
682 L_stacktrace_create_extern_stackframeinfo$lazy_ptr:
683         .indirect_symbol _stacktrace_create_extern_stackframeinfo
684         .long dyld_stub_binding_helper
685
686
687 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
688         .align 2
689 L_jit_asm_compile$stub:
690         .indirect_symbol _jit_asm_compile
691         mflr r0
692         bcl 20,31,L00$_jit_asm_compile
693 L00$_jit_asm_compile:
694         mflr r11
695         addis r11,r11,ha16(L_jit_asm_compile$lazy_ptr - L00$_jit_asm_compile)
696         mtlr r0
697         lwzu r12,lo16(L_jit_asm_compile$lazy_ptr - L00$_jit_asm_compile)(r11)
698         mtctr r12
699         bctr
700 .data
701 .lazy_symbol_pointer
702 L_jit_asm_compile$lazy_ptr:
703         .indirect_symbol _jit_asm_compile
704         .long dyld_stub_binding_helper
705
706
707 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
708         .align 2
709 L_stacktrace_remove_stackframeinfo$stub:
710         .indirect_symbol _stacktrace_remove_stackframeinfo
711         mflr r0
712         bcl 20,31,L00$_stacktrace_remove_stackframeinfo
713 L00$_stacktrace_remove_stackframeinfo:
714         mflr r11
715         addis r11,r11,ha16(L_stacktrace_remove_stackframeinfo$lazy_ptr - L00$_stacktrace_remove_stackframeinfo)
716         mtlr r0
717         lwzu r12,lo16(L_stacktrace_remove_stackframeinfo$lazy_ptr - L00$_stacktrace_remove_stackframeinfo)(r11)
718         mtctr r12
719         bctr
720 .data
721 .lazy_symbol_pointer
722 L_stacktrace_remove_stackframeinfo$lazy_ptr:
723         .indirect_symbol _stacktrace_remove_stackframeinfo
724         .long dyld_stub_binding_helper
725
726
727 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
728         .align 2
729 L_exceptions_get_and_clear_exception$stub:
730         .indirect_symbol _exceptions_get_and_clear_exception
731         mflr r0
732         bcl 20,31,L00$_exceptions_get_and_clear_exception
733 L00$_exceptions_get_and_clear_exception:
734         mflr r11
735         addis r11,r11,ha16(L_exceptions_get_and_clear_exception$lazy_ptr - L00$_exceptions_get_and_clear_exception)
736         mtlr r0
737         lwzu r12,lo16(L_exceptions_get_and_clear_exception$lazy_ptr - L00$_exceptions_get_and_clear_exception)(r11)
738         mtctr r12
739         bctr
740 .data
741 .lazy_symbol_pointer
742 L_exceptions_get_and_clear_exception$lazy_ptr:
743         .indirect_symbol _exceptions_get_and_clear_exception
744         .long dyld_stub_binding_helper
745
746
747 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
748         .align 2
749 L_exceptions_asm_new_abstractmethoderror$stub:
750         .indirect_symbol _exceptions_asm_new_abstractmethoderror
751         mflr r0
752         bcl 20,31,L00$_exceptions_asm_new_abstractmethoderror
753 L00$_exceptions_asm_new_abstractmethoderror:
754         mflr r11
755         addis r11,r11,ha16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)
756         mtlr r0
757         lwzu r12,lo16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)(r11)
758         mtctr r12
759         bctr
760 .data
761 .lazy_symbol_pointer
762 L_exceptions_asm_new_abstractmethoderror$lazy_ptr:
763         .indirect_symbol _exceptions_asm_new_abstractmethoderror
764         .long dyld_stub_binding_helper
765
766
767 # if defined(ENABLE_REPLACEMENT)
768
769 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
770         .align 2
771 L_replace_me$stub:
772         .indirect_symbol _replace_me
773         mflr r0
774         bcl 20,31,L00$_replace_me
775 L00$_replace_me:
776         mflr r11
777         addis r11,r11,ha16(L_replace_me$lazy_ptr - L00$_replace_me)
778         mtlr r0
779         lwzu r12,lo16(L_replace_me$lazy_ptr - L00$_replace_me)(r11)
780         mtctr r12
781         bctr
782 .data
783 .lazy_symbol_pointer
784 L_replace_me$lazy_ptr:
785         .indirect_symbol _replace_me
786         .long dyld_stub_binding_helper
787
788
789 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
790         .align 2
791 L_replace_build_execution_state$stub:
792         .indirect_symbol _replace_build_execution_state
793         mflr r0
794         bcl 20,31,L00$_replace_build_execution_state
795 L00$_replace_build_execution_state:
796         mflr r11
797         addis r11,r11,ha16(L_replace_build_execution_state$lazy_ptr - L00$_replace_build_execution_state)
798         mtlr r0
799         lwzu r12,lo16(L_replace_build_execution_state$lazy_ptr - L00$_replace_build_execution_state)(r11)
800         mtctr r12
801         bctr
802 .data
803 .lazy_symbol_pointer
804 L_replace_build_execution_state$lazy_ptr:
805         .indirect_symbol _replace_build_execution_state
806         .long dyld_stub_binding_helper
807
808
809 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
810         .align 2
811 L_replace_free_safestack$stub:
812         .indirect_symbol _replace_free_safestack
813         mflr r0
814         bcl 20,31,L00$_replace_free_safestack
815 L00$_replace_free_safestack:
816         mflr r11
817         addis r11,r11,ha16(L_replace_free_safestack$lazy_ptr - L00$_replace_free_safestack)
818         mtlr r0
819         lwzu r12,lo16(L_replace_free_safestack$lazy_ptr - L00$_replace_free_safestack)(r11)
820         mtctr r12
821         bctr
822 .data
823 .lazy_symbol_pointer
824 L_replace_free_safestack$lazy_ptr:
825         .indirect_symbol _replace_free_safestack
826         .long dyld_stub_binding_helper
827
828 # endif /* ENABLE_REPLACEMENT */
829
830 #endif /* defined(__DARWIN__) */
831
832
833 /* disable exec-stacks ********************************************************/
834
835 #if defined(__linux__) && defined(__ELF__)
836         .section .note.GNU-stack,"",%progbits
837 #endif
838
839
840 /*
841  * These are local overrides for various environment variables in Emacs.
842  * Please do not remove this and leave it at the end of the file, where
843  * Emacs will automagically detect them.
844  * ---------------------------------------------------------------------
845  * Local variables:
846  * mode: asm
847  * indent-tabs-mode: t
848  * c-basic-offset: 4
849  * tab-width: 4
850  * End:
851  * vim:noexpandtab:sw=4:ts=4:
852  */