2f2cdf49ff6d0556f0b337c293e549525617602d
[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    $Id: asmpart.S 8216 2007-07-19 13:51:21Z michi $
26
27 */
28
29
30 #include "config.h"
31
32 #include "md-abi.h"
33 #include "md-asm.h"
34
35 #include "vm/jit/abi-asm.h"
36 #include "vm/jit/methodheader.h"
37 #include "vm/jit/powerpc/offsets.h"
38
39
40         .text
41
42         .align 2
43
44
45 /* export functions ***********************************************************/
46
47         .globl asm_vm_call_method
48         .globl asm_vm_call_method_int
49         .globl asm_vm_call_method_long
50         .globl asm_vm_call_method_float
51         .globl asm_vm_call_method_double
52
53         .globl asm_vm_call_method_exception_handler
54         .globl asm_vm_call_method_end
55
56         .globl asm_call_jit_compiler
57
58         .globl asm_handle_nat_exception
59         .globl asm_handle_exception
60
61         .globl asm_abstractmethoderror
62
63 #if defined(ENABLE_REPLACEMENT)
64         .globl asm_replacement_out
65         .globl asm_replacement_in
66 #endif
67
68         .globl asm_cacheflush
69
70         .globl asm_compare_and_swap
71         .globl asm_memory_barrier
72
73         .globl asm_criticalsections
74         .globl asm_getclassvalues_atomic
75
76
77 /* asm_vm_call_method **********************************************************
78 *                                                                              *
79 *   This function calls a Java-method (which possibly needs compilation)       *
80 *   with up to 4 address parameters.                                           *
81 *                                                                              *
82 *   This functions calls the JIT-compiler which eventually translates the      *
83 *   method into machine code.                                                  *
84 *                                                                              *
85 *   C-prototype:                                                               *
86 *    javaobject_header *asm_calljavamethod (methodinfo *m,                     *
87 *         void *arg1, void *arg2, void *arg3, void *arg4);                     *
88 *                                                                              *
89 *******************************************************************************/
90
91         .align 2
92
93         .long   0                         /* catch type all                       */
94         .long   0                         /* exception handler pc                 */
95         .long   0                         /* end pc                               */
96         .long   0                         /* start pc                             */
97         .long   1                         /* extable size                         */
98         .long   0                         /* line number table start              */
99         .long   0                         /* line number table size               */
100         .long   0                         /* fltsave                              */
101         .long   0                         /* intsave                              */
102         .long   0                         /* IsLeaf                               */
103         .long   0                         /* IsSync                               */
104         .long   0                         /* frame size                           */
105         .long   0                         /* codeinfo pointer                     */
106
107 asm_vm_call_method:
108 asm_vm_call_method_int:
109 asm_vm_call_method_long:
110 asm_vm_call_method_float:
111 asm_vm_call_method_double:
112         mflr    r0
113         stw     r0,LA_LR_OFFSET(sp)
114         stwu    sp,-40*4(sp)              /* keep stack 16-byte aligned           */
115
116         stw     s0,8*4(sp)                /* save used callee saved registers     */
117         stw     a0,9*4(sp)                /* save method pointer for compiler     */
118
119 #if defined(__DARWIN__)
120         stw     itmp1,10*4(sp)            /* register r11 is callee saved         */
121 #endif
122         stw     pv,11*4(sp)               /* save PV register                     */
123
124         stw     itmp3,12*4(sp)            /* registers r14-r31 are callee saved   */
125         stfd    ftmp1,14*4(sp)            /* registers f14-f31 are callee saved   */
126         stfd    ftmp2,16*4(sp)
127
128 #if defined(__DARWIN__)
129         stw     t1,18*4(sp)
130         stw     t2,19*4(sp)
131         stw     t3,20*4(sp)
132         stw     t4,21*4(sp)
133         stw     t5,22*4(sp)
134         stw     t6,23*4(sp)
135         stw     t7,24*4(sp)
136
137         stfd    ft0,26*4(sp)
138         stfd    ft1,28*4(sp)
139         stfd    ft2,30*4(sp)
140         stfd    ft3,32*4(sp)
141         stfd    ft4,34*4(sp)
142         stfd    ft5,36*4(sp)
143 #else
144         SAVE_TEMPORARY_REGISTERS(18)      /* the offset has to be even            */
145 #endif
146
147         mr      itmp2,a1                  /* arg count                            */
148         mr      itmp1,a2                  /* pointer to arg block                 */
149
150         mr      t4,itmp2                  /* save argument count                  */
151         mr      t5,itmp1                  /* save argument block pointer          */
152
153         mr      s0,sp                     /* save current sp to s0                */
154
155         addi    itmp1,itmp1,-sizevmarg    /* initialize pointer (smaller code)    */
156         addi    itmp2,itmp2,1             /* initialize argument count            */
157         li      t0,0                      /* initialize integer argument counter  */
158         li      t1,0                      /* initialize float argument counter    */
159         li      t6,0                      /* initialize integer register counter  */
160 #if defined(__DARWIN__)
161         li      t7,0                      /* initialize stack slot counter        */
162 #endif
163
164         mflr    r0                        /* save link register (PIC code)        */
165         bl      L_asm_vm_call_method_get_pc
166 L_asm_vm_call_method_get_pc:
167         mflr    t3                        /* t3 contains the current pc           */
168         mtlr    r0
169
170 L_register_copy:
171         addi    itmp1,itmp1,sizevmarg     /* goto next argument block             */
172         addi    itmp2,itmp2,-1            /* argument count - 1                   */
173         mr.     itmp2,itmp2
174         beq     L_register_copy_done
175
176         lwz     itmp3,offvmargtype+4(itmp1)
177         andi.   r0,itmp3,0x0002           /* is this a float/double type?         */
178         bne     L_register_handle_float
179         
180 L_register_handle_int:
181         cmpwi   t6,INT_ARG_CNT            /* are we out of integer argument       */
182         beq     L_register_copy           /* registers? yes, next loop            */
183
184         andi.   r0,itmp3,0x0001           /* is this a 2-word type?               */
185         bne     L_register_handle_long
186
187 #if defined(__DARWIN__)
188         addis   itmp3,t3,ha16(L_jumptable_int - L_asm_vm_call_method_get_pc)
189         la      itmp3,lo16(L_jumptable_int - L_asm_vm_call_method_get_pc)(itmp3)
190 #else
191         lis     itmp3,L_jumptable_int@ha
192         addi    itmp3,itmp3,L_jumptable_int@l
193 #endif
194
195         slwi    t2,t6,2                   /* multiple of 4-bytes                  */
196         add     itmp3,itmp3,t2            /* calculate address of jumptable       */
197         lwz     itmp3,0(itmp3)            /* load function address                */
198         mtctr   itmp3
199         addi    t0,t0,1                   /* integer argument counter             */
200         addi    t6,t6,1                   /* integer argument register counter    */
201 #if defined(__DARWIN__)
202         addi    t7,t7,1                   /* stack slot counter                   */
203 #endif
204         bctr
205
206 L_register_handle_long:
207 #if defined(__DARWIN__)
208         addis   itmp3,t3,ha16(L_jumptable_long - L_asm_vm_call_method_get_pc)
209         la      itmp3,lo16(L_jumptable_long - L_asm_vm_call_method_get_pc)(itmp3)
210 #else
211         lis     itmp3,L_jumptable_long@ha
212         addi    itmp3,itmp3,L_jumptable_long@l
213 #endif
214 #if !defined(__DARWIN__)
215         addi    t6,t6,1                   /* align to even numbers                */
216         andi.   t6,t6,0xfffe
217 #endif
218
219         cmpwi   t6,(INT_ARG_CNT - 1)      /* are we out of integer argument       */
220         blt     L_register_handle_long_continue /* registers?                     */
221
222         li      t6,INT_ARG_CNT            /* yes, set integer argument register   */
223         b       L_register_copy           /* count to max and next loop           */
224
225 L_register_handle_long_continue:
226         slwi    t2,t6,2                   /* multiple of 4-bytes                  */
227         add     itmp3,itmp3,t2            /* calculate address of jumptable       */
228         lwz     itmp3,0(itmp3)            /* load function address                */
229         mtctr   itmp3
230         addi    t0,t0,1                   /* integer argument counter             */
231         addi    t6,t6,2                   /* integer argument register counter    */
232 #if defined(__DARWIN__)
233         addi    t7,t7,2                   /* stack slot counter                   */
234 #endif
235         bctr
236
237 L_register_handle_float:
238         cmpwi   t1,FLT_ARG_CNT            /* are we out of float argument         */
239         beq     L_register_copy           /* registers? yes, next loop            */
240
241         andi.   r0,itmp3,0x0001           /* is this a 2-word type?               */
242         bne     L_register_handle_double
243
244 #if defined(__DARWIN__)
245         addis   itmp3,t3,ha16(L_jumptable_float - L_asm_vm_call_method_get_pc)
246         la      itmp3,lo16(L_jumptable_float - L_asm_vm_call_method_get_pc)(itmp3)
247 #else
248         lis     itmp3,L_jumptable_float@ha
249         addi    itmp3,itmp3,L_jumptable_float@l
250 #endif
251
252         slwi    t2,t1,2                   /* multiple of 4-bytes                  */
253         add     itmp3,itmp3,t2            /* calculate address of jumptable       */
254         lwz     itmp3,0(itmp3)            /* load function address                */
255         mtctr   itmp3
256         addi    t1,t1,1                   /* float argument counter               */
257 #if defined(__DARWIN__)
258         addi    t7,t7,1                   /* stack slot counter                   */
259         addi    t6,t6,1                   /* skip 1 integer argument register     */
260 #endif
261         bctr
262
263 L_register_handle_double:
264 #if defined(__DARWIN__)
265         addis   itmp3,t3,ha16(L_jumptable_double - L_asm_vm_call_method_get_pc)
266         la      itmp3,lo16(L_jumptable_double - L_asm_vm_call_method_get_pc)(itmp3)
267 #else
268         lis     itmp3,L_jumptable_double@ha
269         addi    itmp3,itmp3,L_jumptable_double@l
270 #endif
271
272         slwi    t2,t1,2                   /* multiple of 4-bytes                  */
273         add     itmp3,itmp3,t2            /* calculate address of jumptable       */
274         lwz     itmp3,0(itmp3)            /* load function address                */
275         mtctr   itmp3
276         addi    t1,t1,1                   /* float argument counter               */
277 #if defined(__DARWIN__)
278         addi    t7,t7,2                   /* stack slot counter                   */
279         addi    t6,t6,2                   /* skip 2 integer argument registers    */
280 #endif
281         bctr
282
283 L_register_copy_done:
284                                           /* calculate remaining arguments        */
285         sub     itmp3,t4,t0               /* - integer arguments in registers     */
286         sub     itmp3,itmp3,t1            /* - float arguments in registers       */
287         mr.     itmp3,itmp3
288         beq     L_stack_copy_done
289
290         mr      itmp2,t4                  /* restore argument count               */
291         mr      itmp1,t5                  /* restore argument block pointer       */
292
293         slwi    t4,itmp3,3                /* XXX use 8-bytes slots for now        */
294         addi    t4,t4,LA_SIZE             /* add size of linkage area             */
295
296 #if defined(__DARWIN__)
297         slwi    t5,t7,2                   /* add stack space for arguments        */
298         add     t4,t4,t5
299 #endif
300
301         sub     sp,sp,t4
302
303         mr      t6,sp                     /* use t6 as temporary sp               */
304         addi    t6,t6,LA_SIZE             /* skip linkage area                    */
305 #if defined(__DARWIN__)
306         add     t6,t6,t5                  /* skip stack space for arguments       */
307 #endif
308
309         addi    itmp1,itmp1,-sizevmarg    /* initialize pointer (smaller code)    */
310         addi    itmp2,itmp2,1             /* initialize argument count            */
311         
312 L_stack_copy_loop:
313         addi    itmp1,itmp1,sizevmarg     /* goto next argument block             */
314         addi    itmp2,itmp2,-1            /* argument count - 1                   */
315         mr.     itmp2,itmp2
316         beq     L_stack_copy_done
317         
318         lwz     itmp3,offvmargtype+4(itmp1)
319         andi.   r0,itmp3,0x0002           /* is this a float/double type?         */
320         bne     L_stack_handle_float
321
322 L_stack_handle_int:
323         addi    t0,t0,-1                  /* arguments assigned to registers      */
324         mr.     t0,t0
325         bge     L_stack_copy_loop
326
327         andi.   r0,itmp3,0x0001           /* is this a 2-word type?               */
328         bne     L_stack_handle_long
329
330         lwz     itmp3,offvmargdata+4(itmp1) /* get integer argument               */
331         stw     itmp3,0(t6)               /* and store it on the stack            */
332         addi    t6,t6,4                   /* increase temporary sp by 1 slot      */
333         b       L_stack_copy_loop
334
335 L_stack_handle_long:
336 #if !defined(__DARWIN__)
337         addi    t6,t6,4                   /* align stack to 8-bytes               */
338         rlwinm  t6,t6,0,30,28             /* clear lower 4-bits                   */
339 #endif
340
341         lwz     itmp3,offvmargdata+0(itmp1) /* get long argument                  */
342         stw     itmp3,0(t6)               /* and store it on the stack            */
343         lwz     itmp3,offvmargdata+4(itmp1)
344         stw     itmp3,4(t6)
345         addi    t6,t6,8                   /* increase temporary sp by 2 slots     */
346         b       L_stack_copy_loop
347                 
348 L_stack_handle_float:
349         addi    t1,t1,-1                  /* arguments assigned to registers      */
350         mr.     t1,t1
351         bge     L_stack_copy_loop
352
353         andi.   r0,itmp3,0x0001           /* is this a 2-word type?               */
354         bne     L_stack_handle_double
355
356         lfs     ftmp3,offvmargdata(itmp1) /* get float argument                   */
357         stfs    ftmp3,0(t6)               /* and store it on the stack            */
358         addi    t6,t6,4                   /* increase temporary sp by 1 slot      */
359         b       L_stack_copy_loop
360
361 L_stack_handle_double:
362 #if !defined(__DARWIN__)
363         addi    t6,t6,4                   /* align stack to 8-bytes               */
364         rlwinm  t6,t6,0,30,28             /* clear lower 4-bits                   */
365 #endif
366
367         lfd     ftmp3,offvmargdata(itmp1) /* get double argument                  */
368         stfd    ftmp3,0(t6)               /* and store it on the stack            */
369         addi    t6,t6,8                   /* increase temporary sp by 2 slots     */
370         b       L_stack_copy_loop
371
372 L_stack_copy_done:
373         lwz     itmp1,9*4(s0)             /* pass method pointer via tmp1         */
374
375 #if defined(__DARWIN__)
376         addis   mptr,t3,ha16(L_asm_call_jit_compiler - L_asm_vm_call_method_get_pc)
377         la      mptr,lo16(L_asm_call_jit_compiler - L_asm_vm_call_method_get_pc)(mptr)
378 #else
379         lis     mptr,L_asm_call_jit_compiler@ha
380         addi    mptr,mptr,L_asm_call_jit_compiler@l
381 #endif
382         stw     mptr,7*4(s0)
383         addi    mptr,s0,7*4
384
385         lwz     pv,0*4(mptr)
386         mtctr   pv
387         bctrl
388 1:
389         mflr    itmp1
390 #if defined(__DARWIN__)
391         addi    pv,itmp1,lo16(asm_vm_call_method - 1b)
392 #else
393         addi    pv,itmp1,(asm_vm_call_method - 1b)@l
394 #endif
395
396 L_asm_vm_call_method_return:
397         mr      sp,s0                     /* restore the function's sp            */
398
399         lwz     s0,8*4(sp)                /* restore used callee saved registers  */
400
401 #if defined(__DARWIN__)
402         lwz     itmp1,10*4(sp)            /* register r11 is callee saved         */
403 #endif
404         lwz     pv,11*4(sp)               /* save PV register                     */
405
406         lwz     itmp3,12*4(sp)
407         lfd     ftmp1,14*4(sp)            /* registers f14-f31 are callee saved   */
408         lfd     ftmp2,16*4(sp)
409
410 #if defined(__DARWIN__)
411         lwz     t1,18*4(sp)
412         lwz     t2,19*4(sp)
413         lwz     t3,20*4(sp)
414         lwz     t4,21*4(sp)
415         lwz     t5,22*4(sp)
416         lwz     t6,23*4(sp)
417         lwz     t7,24*4(sp)
418
419         lfd     ft0,26*4(sp)
420         lfd     ft1,28*4(sp)
421         lfd     ft2,30*4(sp)
422         lfd     ft3,32*4(sp)
423         lfd     ft4,34*4(sp)
424         lfd     ft5,36*4(sp)
425 #else
426         RESTORE_TEMPORARY_REGISTERS(18)   /* the offset has to be even            */
427 #endif
428
429         lwz     r0,40*4+LA_LR_OFFSET(sp)
430         mtlr    r0
431         addi    sp,sp,40*4
432         blr
433
434 asm_vm_call_method_exception_handler:
435         mr      a0,itmp1
436         bl      builtin_throw_exception
437         b       L_asm_vm_call_method_return
438
439
440         .data
441         .align  2
442
443 L_jumptable_int:
444         .long   L_handle_a0
445         .long   L_handle_a1
446         .long   L_handle_a2
447         .long   L_handle_a3
448         .long   L_handle_a4
449         .long   L_handle_a5
450         .long   L_handle_a6
451         .long   L_handle_a7
452
453         .text
454         .align  2
455
456 L_handle_a0:
457         lwz     a0,offvmargdata+4(itmp1)
458         b       L_register_copy
459 L_handle_a1:
460         lwz     a1,offvmargdata+4(itmp1)
461         b       L_register_copy
462 L_handle_a2:
463         lwz     a2,offvmargdata+4(itmp1)
464         b       L_register_copy
465 L_handle_a3:
466         lwz     a3,offvmargdata+4(itmp1)
467         b       L_register_copy
468 L_handle_a4:
469         lwz     a4,offvmargdata+4(itmp1)
470         b       L_register_copy
471 L_handle_a5:
472         lwz     a5,offvmargdata+4(itmp1)
473         b       L_register_copy
474 L_handle_a6:
475         lwz     a6,offvmargdata+4(itmp1)
476         b       L_register_copy
477 L_handle_a7:
478         lwz     a7,offvmargdata+4(itmp1)
479         b       L_register_copy
480
481
482         .data
483         .align  2
484
485 L_jumptable_long:
486 #if defined(__DARWIN__)
487         .long   L_handle_a0_a1
488         .long   L_handle_a1_a2
489         .long   L_handle_a2_a3
490         .long   L_handle_a3_a4
491         .long   L_handle_a4_a5
492         .long   L_handle_a5_a6
493         .long   L_handle_a6_a7
494 #else
495         /* we have two entries here, so we get the even argument register
496         alignment for linux */
497
498         .long   L_handle_a0_a1
499         .long   0
500         .long   L_handle_a2_a3
501         .long   0
502         .long   L_handle_a4_a5
503         .long   0
504         .long   L_handle_a6_a7
505 #endif
506
507         .text
508         .align  2
509
510 L_handle_a0_a1:
511         lwz     a0,offvmargdata+0(itmp1)
512         lwz     a1,offvmargdata+4(itmp1)
513         b       L_register_copy
514 #if defined(__DARWIN__)
515 L_handle_a1_a2:
516         lwz     a1,offvmargdata+0(itmp1)
517         lwz     a2,offvmargdata+4(itmp1)
518         b       L_register_copy
519 #endif
520 L_handle_a2_a3:
521         lwz     a2,offvmargdata+0(itmp1)
522         lwz     a3,offvmargdata+4(itmp1)
523         b       L_register_copy
524 #if defined(__DARWIN__)
525 L_handle_a3_a4:
526         lwz     a3,offvmargdata+0(itmp1)
527         lwz     a4,offvmargdata+4(itmp1)
528         b       L_register_copy
529 #endif
530 L_handle_a4_a5:
531         lwz     a4,offvmargdata+0(itmp1)
532         lwz     a5,offvmargdata+4(itmp1)
533         b       L_register_copy
534 #if defined(__DARWIN__)
535 L_handle_a5_a6:
536         lwz     a5,offvmargdata+0(itmp1)
537         lwz     a6,offvmargdata+4(itmp1)
538         b       L_register_copy
539 #endif
540 L_handle_a6_a7:
541         lwz     a6,offvmargdata+0(itmp1)
542         lwz     a7,offvmargdata+4(itmp1)
543         b       L_register_copy
544
545
546         .data
547         .align  2
548
549 L_jumptable_float:
550         .long   L_handle_fa0
551         .long   L_handle_fa1
552         .long   L_handle_fa2
553         .long   L_handle_fa3
554         .long   L_handle_fa4
555         .long   L_handle_fa5
556         .long   L_handle_fa6
557         .long   L_handle_fa7
558
559 #if defined(__DARWIN__)
560         .long   L_handle_fa8
561         .long   L_handle_fa9
562         .long   L_handle_fa10
563         .long   L_handle_fa11
564         .long   L_handle_fa12
565 #endif
566
567         .text
568         .align  2
569
570 L_handle_fa0:
571         lfs     fa0,offvmargdata(itmp1)
572         b       L_register_copy
573 L_handle_fa1:
574         lfs     fa1,offvmargdata(itmp1)
575         b       L_register_copy
576 L_handle_fa2:
577         lfs     fa2,offvmargdata(itmp1)
578         b       L_register_copy
579 L_handle_fa3:
580         lfs     fa3,offvmargdata(itmp1)
581         b       L_register_copy
582 L_handle_fa4:
583         lfs     fa4,offvmargdata(itmp1)
584         b       L_register_copy
585 L_handle_fa5:
586         lfs     fa5,offvmargdata(itmp1)
587         b       L_register_copy
588 L_handle_fa6:
589         lfs     fa6,offvmargdata(itmp1)
590         b       L_register_copy
591 L_handle_fa7:
592         lfs     fa7,offvmargdata(itmp1)
593         b       L_register_copy
594
595 #if defined(__DARWIN__)
596 L_handle_fa8:
597         lfs     fa8,offvmargdata(itmp1)
598         b       L_register_copy
599 L_handle_fa9:
600         lfs     fa9,offvmargdata(itmp1)
601         b       L_register_copy
602 L_handle_fa10:
603         lfs     fa10,offvmargdata(itmp1)
604         b       L_register_copy
605 L_handle_fa11:
606         lfs     fa11,offvmargdata(itmp1)
607         b       L_register_copy
608 L_handle_fa12:
609         lfs     fa12,offvmargdata(itmp1)
610         b       L_register_copy
611 #endif
612
613
614         .data
615         .align  2
616
617 L_jumptable_double:
618         .long   L_handle_fda0
619         .long   L_handle_fda1
620         .long   L_handle_fda2
621         .long   L_handle_fda3
622         .long   L_handle_fda4
623         .long   L_handle_fda5
624         .long   L_handle_fda6
625         .long   L_handle_fda7
626
627 #if defined(__DARWIN__)
628         .long   L_handle_fda8
629         .long   L_handle_fda9
630         .long   L_handle_fda10
631         .long   L_handle_fda11
632         .long   L_handle_fda12
633 #endif
634
635         .text
636         .align  2
637
638 L_handle_fda0:
639         lfd     fa0,offvmargdata(itmp1)
640         b       L_register_copy
641 L_handle_fda1:
642         lfd     fa1,offvmargdata(itmp1)
643         b       L_register_copy
644 L_handle_fda2:
645         lfd     fa2,offvmargdata(itmp1)
646         b       L_register_copy
647 L_handle_fda3:
648         lfd     fa3,offvmargdata(itmp1)
649         b       L_register_copy
650 L_handle_fda4:
651         lfd     fa4,offvmargdata(itmp1)
652         b       L_register_copy
653 L_handle_fda5:
654         lfd     fa5,offvmargdata(itmp1)
655         b       L_register_copy
656 L_handle_fda6:
657         lfd     fa6,offvmargdata(itmp1)
658         b       L_register_copy
659 L_handle_fda7:
660         lfd     fa7,offvmargdata(itmp1)
661         b       L_register_copy
662
663 #if defined(__DARWIN__)
664 L_handle_fda8:
665         lfd     fa8,offvmargdata(itmp1)
666         b       L_register_copy
667 L_handle_fda9:
668         lfd     fa9,offvmargdata(itmp1)
669         b       L_register_copy
670 L_handle_fda10:
671         lfd     fa10,offvmargdata(itmp1)
672         b       L_register_copy
673 L_handle_fda11:
674         lfd     fa11,offvmargdata(itmp1)
675         b       L_register_copy
676 L_handle_fda12:
677         lfd     fa12,offvmargdata(itmp1)
678         b       L_register_copy
679 #endif
680
681 asm_vm_call_method_end:
682         nop
683
684 /* asm_call_jit_compiler *******************************************************
685
686    Invokes the compiler for untranslated JavaVM methods.
687
688 *******************************************************************************/
689
690 asm_call_jit_compiler:
691 L_asm_call_jit_compiler:                /* required for PIC code              */
692         mflr    r0
693         stw     r0,LA_LR_OFFSET(sp)         /* save return address                */
694         stwu    sp,-(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)(sp)
695
696 #if defined(__DARWIN__)
697         stw     a0,LA_SIZE+(4+0)*4(sp)
698         stw     a1,LA_SIZE+(4+1)*4(sp)
699         stw     a2,LA_SIZE+(4+2)*4(sp)
700         stw     a3,LA_SIZE+(4+3)*4(sp)
701         stw     a4,LA_SIZE+(4+4)*4(sp)
702         stw     a5,LA_SIZE+(4+5)*4(sp)
703         stw     a6,LA_SIZE+(4+6)*4(sp)
704         stw     a7,LA_SIZE+(4+7)*4(sp)
705
706         stfd    fa0,LA_SIZE+(4+8)*4(sp)
707         stfd    fa1,LA_SIZE+(4+10)*4(sp)
708         stfd    fa2,LA_SIZE+(4+12)*4(sp)
709         stfd    fa3,LA_SIZE+(4+14)*4(sp)
710         stfd    fa4,LA_SIZE+(4+16)*4(sp)
711         stfd    fa5,LA_SIZE+(4+18)*4(sp)
712         stfd    fa6,LA_SIZE+(4+20)*4(sp)
713         stfd    fa7,LA_SIZE+(4+22)*4(sp)
714         stfd    fa8,LA_SIZE+(4+24)*4(sp)
715         stfd    fa9,LA_SIZE+(4+26)*4(sp)
716         stfd    fa10,LA_SIZE+(4+28)*4(sp)
717         stfd    fa11,LA_SIZE+(4+30)*4(sp)
718         stfd    fa12,LA_SIZE+(4+32)*4(sp)
719 #else
720         SAVE_ARGUMENT_REGISTERS(LA_SIZE_IN_POINTERS)
721 #endif
722
723         mr      a0,itmp1
724         mr      a1,mptr
725         addi    a2,sp,(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)
726         lwz     a3,(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)+LA_LR_OFFSET(sp)
727         bl      jit_asm_compile
728         mr      pv,v0                       /* move address to pv register        */
729
730 #if defined(__DARWIN__)
731         lwz     a0,LA_SIZE+(4+0)*4(sp)
732         lwz     a1,LA_SIZE+(4+1)*4(sp)
733         lwz     a2,LA_SIZE+(4+2)*4(sp)
734         lwz     a3,LA_SIZE+(4+3)*4(sp)
735         lwz     a4,LA_SIZE+(4+4)*4(sp)
736         lwz     a5,LA_SIZE+(4+5)*4(sp)
737         lwz     a6,LA_SIZE+(4+6)*4(sp)
738         lwz     a7,LA_SIZE+(4+7)*4(sp)
739
740         lfd     fa0,LA_SIZE+(4+8)*4(sp)
741         lfd     fa1,LA_SIZE+(4+10)*4(sp)
742         lfd     fa2,LA_SIZE+(4+12)*4(sp)
743         lfd     fa3,LA_SIZE+(4+14)*4(sp)
744         lfd     fa4,LA_SIZE+(4+16)*4(sp)
745         lfd     fa5,LA_SIZE+(4+18)*4(sp)
746         lfd     fa6,LA_SIZE+(4+20)*4(sp)
747         lfd     fa7,LA_SIZE+(4+22)*4(sp)
748         lfd     fa8,LA_SIZE+(4+24)*4(sp)
749         lfd     fa9,LA_SIZE+(4+26)*4(sp)
750         lfd     fa10,LA_SIZE+(4+28)*4(sp)
751         lfd     fa11,LA_SIZE+(4+30)*4(sp)
752         lfd     fa12,LA_SIZE+(4+32)*4(sp)
753 #else
754         RESTORE_ARGUMENT_REGISTERS(LA_SIZE_IN_POINTERS)
755 #endif
756
757         lwz     itmp1,(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)+LA_LR_OFFSET(sp)
758         mtlr    itmp1
759
760         addi    sp,sp,(LA_SIZE + 4*4 + INT_ARG_CNT*4 + FLT_ARG_CNT*8)
761
762         mr.     pv,pv                       /* test for exception                 */
763         beq     L_asm_call_jit_compiler_exception
764
765         mtctr   pv                          /* move method address to control reg */
766         bctr                                /* and call the Java method           */
767
768 L_asm_call_jit_compiler_exception:
769         mflr    r0
770         stw     r0,LA_LR_OFFSET(sp)
771         stwu    sp,-LA_SIZE_ALIGNED(sp)     /* preserve linkage area              */
772         bl      exceptions_get_and_clear_exception
773         lwz     xpc,LA_SIZE_ALIGNED+LA_LR_OFFSET(sp)
774         mtlr    xpc     
775         addi    sp,sp,LA_SIZE_ALIGNED
776
777         mr      xptr,v0                     /* get exception                      */
778         addi    xpc,xpc,-4                  /* exception address is ra - 4        */
779         b       L_asm_handle_nat_exception
780
781
782 /********************* function asm_handle_exception ***************************
783 *                                                                              *
784 *   This function handles an exception. It does not use the usual calling      *
785 *   conventions. The exception pointer is passed in REG_ITMP1 and the          *
786 *   pc from the exception raising position is passed in REG_ITMP2. It searches *
787 *   the local exception table for a handler. If no one is found, it unwinds    *
788 *   stacks and continues searching the callers.                                *
789 *                                                                              *
790 *   void asm_handle_exception (exceptionptr, exceptionpc);                     *
791 *                                                                              *
792 *******************************************************************************/
793                 
794 asm_handle_nat_exception:
795 L_asm_handle_nat_exception:             /* required for PIC code              */
796 L_asm_handle_exception_stack_loop:
797         mflr    r0
798         addi    sp,sp,-(LA_SIZE+((4+6)*4))  /* allocate stack (+4 for darwin)     */
799         stw     xptr,LA_SIZE+(4+0)*4(sp)    /* save exception pointer             */
800         stw     xpc,LA_SIZE+(4+1)*4(sp)     /* save exception pc                  */
801         stw     r0,LA_SIZE+(4+3)*4(sp)      /* save return address                */
802         li      itmp3,0
803         stw     itmp3,LA_SIZE+(4+4)*4(sp)   /* save maybe-leaf flag (cleared)     */
804
805         mr      a0,r0                       /* pass return address                */
806         bl      md_codegen_get_pv_from_pc   /* get PV from RA                     */
807         stw     v0,LA_SIZE+(4+2)*4(sp)      /* save data segment pointer          */
808
809         lwz     a0,LA_SIZE+(4+0)*4(sp)      /* pass xptr                          */
810         lwz     a1,LA_SIZE+(4+1)*4(sp)      /* pass xpc                           */
811         lwz     a2,LA_SIZE+(4+2)*4(sp)      /* pass PV (v0 == a0)                 */
812         addi    a3,sp,LA_SIZE+((4+6)*4)     /* pass Java SP                       */
813
814         b       L_asm_handle_exception_continue
815
816 asm_handle_exception:
817 L_asm_handle_exception:                 /* required for PIC code              */
818         addi    sp,sp,-(ARG_CNT+TMP_CNT)*8  /* create maybe-leaf stackframe       */
819
820 #if defined(__DARWIN__)
821 #else
822         SAVE_ARGUMENT_REGISTERS(0)          /* we save arg and temp registers in  */
823         SAVE_TEMPORARY_REGISTERS(ARG_CNT)   /* case this is a leaf method         */
824 #endif
825
826         addi    sp,sp,-(LA_SIZE+(4+6)*4)    /* allocate stack                     */
827         stw     xptr,LA_SIZE+(4+0)*4(sp)    /* save xptr                          */
828         stw     pv,LA_SIZE+(4+2)*4(sp)      /* save PV                            */
829         mflr    r0                          /* save RA                            */
830         stw     r0,LA_SIZE+(4+3)*4(sp)
831         li      t0,1                        /* set maybe-leaf flag                */
832         stw     t0,LA_SIZE+(4+4)*4(sp)      /* save maybe-leaf flag               */
833
834         mr      a0,xptr                     /* pass exception pointer             */
835         mr      a1,xpc                      /* pass exception pc                  */
836         mr      a2,pv                       /* pass data segment pointer          */
837         addi    a3,sp,LA_SIZE+(ARG_CNT+TMP_CNT)*8+(4+6)*4
838
839 L_asm_handle_exception_continue:
840         bl      exceptions_handle_exception
841
842         mr.     v0,v0
843         beq     L_asm_handle_exception_not_catched
844
845         mr      xpc,v0                      /* move handlerpc into xpc            */
846         lwz     xptr,LA_SIZE+(4+0)*4(sp)    /* restore xptr                       */
847         lwz     pv,LA_SIZE+(4+2)*4(sp)      /* restore PV                         */
848         lwz     r0,LA_SIZE+(4+3)*4(sp)      /* restore RA                         */
849         mtlr    r0
850         lwz     t0,LA_SIZE+(4+4)*4(sp)      /* get maybe-leaf flag                */
851         addi    sp,sp,LA_SIZE+(4+6)*4       /* free stack frame                   */
852
853         mr.     t0,t0
854         beq     L_asm_handle_exception_no_leaf
855
856 #if defined(__DARWIN__)
857 #else
858         RESTORE_ARGUMENT_REGISTERS(0)       /* if this is a leaf method, we have  */
859         RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers  */
860 #endif
861
862         addi    sp,sp,(ARG_CNT+TMP_CNT)*8   /* remove maybe-leaf stackframe       */
863
864 L_asm_handle_exception_no_leaf:
865         mtctr   xpc                         /* jump to the handler                */
866         bctr
867
868 L_asm_handle_exception_not_catched:
869         lwz     xptr,LA_SIZE+(4+0)*4(sp)    /* restore xptr                       */
870         lwz     pv,LA_SIZE+(4+2)*4(sp)      /* restore PV                         */
871         lwz     r0,LA_SIZE+(4+3)*4(sp)      /* restore RA                         */
872         mtlr    r0
873         lwz     t0,LA_SIZE+(4+4)*4(sp)      /* get maybe-leaf flag                */
874         addi    sp,sp,LA_SIZE+(4+6)*4       /* free stack frame                   */
875
876         mr.     t0,t0
877         beq     L_asm_handle_exception_no_leaf_stack
878
879         addi    sp,sp,(ARG_CNT+TMP_CNT)*8   /* remove maybe-leaf stackframe       */
880         li      t0,0                        /* clear the maybe-leaf flag          */
881
882 L_asm_handle_exception_no_leaf_stack:
883         lwz     t1,FrameSize(pv)            /* get frame size                     */
884         add     t1,sp,t1                    /* pointer to save area               */
885
886         lwz     t2,IsLeaf(pv)               /* is leaf procedure                  */
887         mr.     t2,t2
888         bne     L_asm_handle_exception_no_ra_restore
889
890         lwz     r0,LA_LR_OFFSET(t1)         /* restore ra                         */
891         mtlr    r0
892
893 L_asm_handle_exception_no_ra_restore:
894         mflr    xpc                         /* the new xpc is ra                  */
895         mr      t4,xpc                      /* save RA                            */
896         lwz     t2,IntSave(pv)              /* t2 = saved int register count      */
897         bl      ex_int1
898 ex_int1:
899         mflr    t3                          /* t3 = current pc                    */
900 #if defined(__DARWIN__)
901         addi    t3,t3,lo16(ex_int2-ex_int1)
902 #else
903         addi    t3,t3,(ex_int2-ex_int1)@l
904 #endif
905         slwi    t2,t2,2                     /* t2 = register count * 4            */
906         subf    t3,t2,t3                    /* t3 = IntSave - t2                  */
907         mtctr   t3
908         bctr
909
910         lwz     s0,-10*4(t1)
911         lwz     s1,-9*4(t1)
912         lwz     s2,-8*4(t1)
913         lwz     s3,-7*4(t1)
914         lwz     s4,-6*4(t1)
915         lwz     s5,-5*4(t1)
916         lwz     s6,-4*4(t1)
917         lwz     s7,-3*4(t1)
918         lwz     s8,-2*4(t1)
919         lwz     s9,-1*4(t1)
920
921 ex_int2:
922         subf    t1,t2,t1                    /* t1 = t1 - register count * 4       */
923
924         lwz     t2,FltSave(pv)
925         bl      ex_flt1
926 ex_flt1:
927         mflr    t3
928 #if defined(__DARWIN__)
929         addi    t3,t3,lo16(ex_flt2-ex_flt1)
930 #else
931         addi    t3,t3,(ex_flt2-ex_flt1)@l
932 #endif
933         slwi    t2,t2,2                     /* t2 = register count * 4            */
934         subf    t3,t2,t3                    /* t3 = FltSave - t2                  */
935         mtctr   t3
936         bctr
937
938         lfd     fs0,-10*8(t1)
939         lfd     fs1,-9*8(t1)
940         lfd     fs2,-8*8(t1)
941         lfd     fs3,-7*8(t1)
942         lfd     fs4,-6*8(t1)
943         lfd     fs5,-5*8(t1)
944         lfd     fs6,-4*8(t1)
945         lfd     fs7,-3*8(t1)
946         lfd     fs8,-2*8(t1)
947         lfd     fs9,-1*8(t1)
948
949 ex_flt2:
950         mtlr    t4                          /* restore RA                         */
951         lwz     t1,FrameSize(pv)            /* get frame size                     */
952         add     sp,sp,t1                    /* unwind stack                       */
953         b       L_asm_handle_exception_stack_loop
954
955
956 /* asm_abstractmethoderror *****************************************************
957
958    Creates and throws an AbstractMethodError.
959
960 *******************************************************************************/
961
962 asm_abstractmethoderror:
963         mflr    r0
964         stw     r0,LA_LR_OFFSET(sp)
965         stwu    sp,-LA_SIZE_ALIGNED(sp)     /* preserve linkage area              */
966         addi    a0,sp,LA_SIZE_ALIGNED       /* pass java sp                       */
967         mr      a1,r0                       /* pass exception address             */
968         bl      exceptions_asm_new_abstractmethoderror
969         lwz     r0,LA_SIZE_ALIGNED+LA_LR_OFFSET(sp)
970         mtlr    r0                          /* restore return address             */
971         addi    sp,sp,LA_SIZE_ALIGNED
972
973         mr      xptr,v0                     /* get exception pointer              */
974         mr      xpc,r0                      /* we can't use r0 directly in addi   */
975         addi    xpc,xpc,-4                  /* exception address is ra - 4        */
976         b       L_asm_handle_nat_exception
977
978
979 #if defined(ENABLE_REPLACEMENT)
980
981 /* asm_replacement_out *********************************************************
982
983    This code is jumped to from the replacement-out stubs that are executed
984    when a thread reaches an activated replacement point.
985
986    The purpose of asm_replacement_out is to read out the parts of the
987    execution state that cannot be accessed from C code, store this state,
988    and then call the C function replace_me.
989
990    Stack layout:
991       16                start of stack inside method to replace
992       0   rplpoint *    info on the replacement point that was reached
993
994    NOTE: itmp3 has been clobbered by the replacement-out stub!
995
996 *******************************************************************************/
997
998 /* some room to accomodate changes of the stack frame size during replacement */
999         /* XXX we should find a cleaner solution here */
1000 #define REPLACEMENT_ROOM  512
1001
1002 #define sizeexecutionstate_ALIGNED  ((sizeexecutionstate + 15) & ~15)
1003
1004 asm_replacement_out:
1005     /* create stack frame */
1006         addi    sp,sp,-(sizeexecutionstate_ALIGNED + REPLACEMENT_ROOM)
1007
1008         /* save link register */
1009         mflr    itmp3
1010
1011         /* save registers in execution state */
1012         stw     r0 ,( 0*4+offes_intregs)(sp)
1013         stw     r1 ,( 1*4+offes_intregs)(sp)
1014         stw     r2 ,( 2*4+offes_intregs)(sp)
1015         stw     r3 ,( 3*4+offes_intregs)(sp)
1016         stw     r4 ,( 4*4+offes_intregs)(sp)
1017         stw     r5 ,( 5*4+offes_intregs)(sp)
1018         stw     r6 ,( 6*4+offes_intregs)(sp)
1019         stw     r7 ,( 7*4+offes_intregs)(sp)
1020         stw     r8 ,( 8*4+offes_intregs)(sp)
1021         stw     r9 ,( 9*4+offes_intregs)(sp)
1022         stw     r10,(10*4+offes_intregs)(sp)
1023         stw     r11,(11*4+offes_intregs)(sp)
1024         stw     r12,(12*4+offes_intregs)(sp)
1025         stw     r13,(13*4+offes_intregs)(sp)
1026         stw     r14,(14*4+offes_intregs)(sp)
1027         stw     r15,(15*4+offes_intregs)(sp)
1028         stw     r16,(16*4+offes_intregs)(sp) /* link register stored as itmp3 */
1029         stw     r17,(17*4+offes_intregs)(sp)
1030         stw     r18,(18*4+offes_intregs)(sp)
1031         stw     r19,(19*4+offes_intregs)(sp)
1032         stw     r20,(20*4+offes_intregs)(sp)
1033         stw     r21,(21*4+offes_intregs)(sp)
1034         stw     r22,(22*4+offes_intregs)(sp)
1035         stw     r23,(23*4+offes_intregs)(sp)
1036         stw     r24,(24*4+offes_intregs)(sp)
1037         stw     r25,(25*4+offes_intregs)(sp)
1038         stw     r26,(26*4+offes_intregs)(sp)
1039         stw     r27,(27*4+offes_intregs)(sp)
1040         stw     r28,(28*4+offes_intregs)(sp)
1041         stw     r29,(29*4+offes_intregs)(sp)
1042         stw     r30,(30*4+offes_intregs)(sp)
1043         stw     r31,(31*4+offes_intregs)(sp)
1044         
1045         stfd    fr0 ,( 0*8+offes_fltregs)(sp)
1046         stfd    fr1 ,( 1*8+offes_fltregs)(sp)
1047         stfd    fr2 ,( 2*8+offes_fltregs)(sp)
1048         stfd    fr3 ,( 3*8+offes_fltregs)(sp)
1049         stfd    fr4 ,( 4*8+offes_fltregs)(sp)
1050         stfd    fr5 ,( 5*8+offes_fltregs)(sp)
1051         stfd    fr6 ,( 6*8+offes_fltregs)(sp)
1052         stfd    fr7 ,( 7*8+offes_fltregs)(sp)
1053         stfd    fr8 ,( 8*8+offes_fltregs)(sp)
1054         stfd    fr9 ,( 9*8+offes_fltregs)(sp)
1055         stfd    fr10,(10*8+offes_fltregs)(sp)
1056         stfd    fr11,(11*8+offes_fltregs)(sp)
1057         stfd    fr12,(12*8+offes_fltregs)(sp)
1058         stfd    fr13,(13*8+offes_fltregs)(sp)
1059         stfd    fr14,(14*8+offes_fltregs)(sp)
1060         stfd    fr15,(15*8+offes_fltregs)(sp)
1061         stfd    fr16,(16*8+offes_fltregs)(sp)
1062         stfd    fr17,(17*8+offes_fltregs)(sp)
1063         stfd    fr18,(18*8+offes_fltregs)(sp)
1064         stfd    fr19,(19*8+offes_fltregs)(sp)
1065         stfd    fr20,(20*8+offes_fltregs)(sp)
1066         stfd    fr21,(21*8+offes_fltregs)(sp)
1067         stfd    fr22,(22*8+offes_fltregs)(sp)
1068         stfd    fr23,(23*8+offes_fltregs)(sp)
1069         stfd    fr24,(24*8+offes_fltregs)(sp)
1070         stfd    fr25,(25*8+offes_fltregs)(sp)
1071         stfd    fr26,(26*8+offes_fltregs)(sp)
1072         stfd    fr27,(27*8+offes_fltregs)(sp)
1073         stfd    fr28,(28*8+offes_fltregs)(sp)
1074         stfd    fr29,(29*8+offes_fltregs)(sp)
1075         stfd    fr30,(30*8+offes_fltregs)(sp)
1076         stfd    fr31,(31*8+offes_fltregs)(sp)
1077         
1078         /* calculate sp of method */
1079         addi    itmp1,sp,(sizeexecutionstate_ALIGNED + REPLACEMENT_ROOM + 4*4)
1080         stw     itmp1,(offes_sp)(sp)
1081
1082         /* store pv */
1083         stw     pv,(offes_pv)(sp)
1084
1085         /* call replace_me */
1086         lwz     a0,-(4*4)(itmp1)            /* arg0: rplpoint *                   */
1087         mr      a1,sp                       /* arg1: execution state              */
1088         addi    sp,sp,-(LA_SIZE_ALIGNED)
1089         b       replace_me                  /* call C function replace_me         */
1090
1091 /* asm_replacement_in **********************************************************
1092
1093    This code writes the given execution state and jumps to the replacement
1094    code.
1095
1096    This function never returns!
1097
1098    NOTE: itmp3 is not restored!
1099
1100    C prototype:
1101       void asm_replacement_in(executionstate *es, replace_safestack_t *st);
1102
1103 *******************************************************************************/
1104
1105 asm_replacement_in:
1106         /* a0 == executionstate *es      */
1107         /* a1 == replace_safestack_t *st */
1108
1109         /* get arguments */
1110         mr              s1,a1                       /* replace_safestack_t *st            */
1111         mr              s2,a0                       /* executionstate *es == safe stack   */
1112
1113         /* switch to the safe stack */
1114         mr              sp,s2
1115
1116         /* reserve linkage area */
1117         addi    sp,sp,-(LA_SIZE_ALIGNED)
1118
1119         /* call replace_build_execution_state(st) */
1120         mr              a0,s1
1121         bl              replace_build_execution_state
1122
1123         /* set new sp */
1124         lwz             sp,(offes_sp)(s2)
1125
1126         /* build stack frame */
1127         addi    sp,sp,-(sizeexecutionstate_ALIGNED)
1128
1129         /* call replace_free_safestack(st,& of allocated executionstate_t) */
1130         mr              a1,sp /* tmpes */
1131         mr              a0,s1 /* st    */
1132         addi    sp,sp,-(LA_SIZE_ALIGNED)  /* reserve linkage area */
1133         bl              replace_free_safestack
1134         addi    sp,sp,+(LA_SIZE_ALIGNED)  /* tear down linkage area */
1135
1136         /* set new pv */
1137         lwz     pv,(offes_pv)(sp)
1138         
1139         /* copy registers from execution state */
1140         lwz     r0 ,( 0*4+offes_intregs)(sp)
1141         /* r1 is sp                       */
1142         /* r2 is reserved                 */
1143         lwz     a0 ,( 3*4+offes_intregs)(sp)
1144         lwz     r4 ,( 4*4+offes_intregs)(sp)
1145         lwz     r5 ,( 5*4+offes_intregs)(sp)
1146         lwz     r6 ,( 6*4+offes_intregs)(sp)
1147         lwz     r7 ,( 7*4+offes_intregs)(sp)
1148         lwz     r8 ,( 8*4+offes_intregs)(sp)
1149         lwz     r9 ,( 9*4+offes_intregs)(sp)
1150         lwz     r10,(10*4+offes_intregs)(sp)
1151         lwz     r11,(11*4+offes_intregs)(sp)
1152         lwz     r12,(12*4+offes_intregs)(sp)
1153         /* r13 is pv                      */
1154         lwz     r14,(14*4+offes_intregs)(sp)
1155         lwz     r15,(15*4+offes_intregs)(sp)
1156         lwz     r16,(16*4+offes_intregs)(sp) /* itmp3, later to link register */
1157         lwz     r17,(17*4+offes_intregs)(sp)
1158         lwz     r18,(18*4+offes_intregs)(sp)
1159         lwz     r19,(19*4+offes_intregs)(sp)
1160         lwz     r20,(20*4+offes_intregs)(sp)
1161         lwz     r21,(21*4+offes_intregs)(sp)
1162         lwz     r22,(22*4+offes_intregs)(sp)
1163         lwz     r23,(23*4+offes_intregs)(sp)
1164         lwz     r24,(24*4+offes_intregs)(sp)
1165         lwz     r25,(25*4+offes_intregs)(sp)
1166         lwz     r26,(26*4+offes_intregs)(sp)
1167         lwz     r27,(27*4+offes_intregs)(sp)
1168         lwz     r28,(28*4+offes_intregs)(sp)
1169         lwz     r29,(29*4+offes_intregs)(sp)
1170         lwz     r30,(30*4+offes_intregs)(sp)
1171         lwz     r31,(31*4+offes_intregs)(sp)
1172         
1173         lfd     fr0 ,( 0*8+offes_fltregs)(sp)
1174         lfd     fr1 ,( 1*8+offes_fltregs)(sp)
1175         lfd     fr2 ,( 2*8+offes_fltregs)(sp)
1176         lfd     fr3 ,( 3*8+offes_fltregs)(sp)
1177         lfd     fr4 ,( 4*8+offes_fltregs)(sp)
1178         lfd     fr5 ,( 5*8+offes_fltregs)(sp)
1179         lfd     fr6 ,( 6*8+offes_fltregs)(sp)
1180         lfd     fr7 ,( 7*8+offes_fltregs)(sp)
1181         lfd     fr8 ,( 8*8+offes_fltregs)(sp)
1182         lfd     fr9 ,( 9*8+offes_fltregs)(sp)
1183         lfd     fr10,(10*8+offes_fltregs)(sp)
1184         lfd     fr11,(11*8+offes_fltregs)(sp)
1185         lfd     fr12,(12*8+offes_fltregs)(sp)
1186         lfd     fr13,(13*8+offes_fltregs)(sp)
1187         lfd     fr14,(14*8+offes_fltregs)(sp)
1188         lfd     fr15,(15*8+offes_fltregs)(sp)
1189         lfd     fr16,(16*8+offes_fltregs)(sp)
1190         lfd     fr17,(17*8+offes_fltregs)(sp)
1191         lfd     fr18,(18*8+offes_fltregs)(sp)
1192         lfd     fr19,(19*8+offes_fltregs)(sp)
1193         lfd     fr20,(20*8+offes_fltregs)(sp)
1194         lfd     fr21,(21*8+offes_fltregs)(sp)
1195         lfd     fr22,(22*8+offes_fltregs)(sp)
1196         lfd     fr23,(23*8+offes_fltregs)(sp)
1197         lfd     fr24,(24*8+offes_fltregs)(sp)
1198         lfd     fr25,(25*8+offes_fltregs)(sp)
1199         lfd     fr26,(26*8+offes_fltregs)(sp)
1200         lfd     fr27,(27*8+offes_fltregs)(sp)
1201         lfd     fr28,(28*8+offes_fltregs)(sp)
1202         lfd     fr29,(29*8+offes_fltregs)(sp)
1203         lfd     fr30,(30*8+offes_fltregs)(sp)
1204         lfd     fr31,(31*8+offes_fltregs)(sp)
1205
1206         /* restore link register */
1207
1208         mtlr    itmp3
1209         
1210         /* load new pc */
1211
1212         lwz     itmp3,offes_pc(sp)
1213
1214         /* remove stack frame */
1215
1216         addi    sp,sp,+(sizeexecutionstate_ALIGNED)
1217
1218         /* jump to new code */
1219
1220         mtctr   itmp3
1221         bctr
1222
1223 #endif /* defined(ENABLE_REPLACEMENT) */
1224
1225 /*********************************************************************/
1226
1227 asm_cacheflush:
1228         add     a1,a0,a1
1229         rlwinm  a0,a0,0,0,26
1230         addi    a1,a1,31
1231         rlwinm  a1,a1,0,0,26
1232         mr      a2,a0
1233 1:
1234         cmplw   a0,a1
1235         bge     0f
1236         dcbst   0,a0
1237         addi    a0,a0,32
1238         b       1b
1239 0:
1240         sync
1241 1:
1242         cmplw   a2,a1
1243         bge     0f
1244         icbi    0,a2
1245         addi    a2,a2,32
1246         b       1b
1247 0:
1248         sync
1249         isync
1250         blr
1251
1252
1253 /* asm_compare_and_swap ********************************************************
1254
1255    XXX
1256
1257 *******************************************************************************/
1258
1259 asm_compare_and_swap:
1260 1:
1261         lwarx   a6,0,a0 
1262         subf.   r0,a6,a1 
1263         bne-    2f 
1264         or      r0,a2,a2 
1265         stwcx.  r0,0,a0 
1266         bne-    1b 
1267 2: 
1268         mr      a0,a6
1269         blr
1270
1271
1272 /* asm_memory_barrier **********************************************************
1273
1274    XXX
1275
1276 *******************************************************************************/
1277
1278 asm_memory_barrier:
1279         sync
1280         blr
1281
1282
1283 asm_getclassvalues_atomic:
1284 _crit_restart:
1285 _crit_begin:
1286         lwz     a3,offbaseval(a0)
1287         lwz     a4,offdiffval(a0)
1288         lwz     a5,offbaseval(a1)
1289 _crit_end:
1290         stw     a3,offcast_super_baseval(a2)
1291         stw     a4,offcast_super_diffval(a2)
1292         stw     a5,offcast_sub_baseval(a2)
1293         blr
1294
1295         .data
1296
1297 asm_criticalsections:
1298 #if defined(ENABLE_THREADS)
1299         .long   _crit_begin
1300         .long   _crit_end
1301         .long   _crit_restart
1302 #endif
1303         .long 0
1304
1305
1306 #if defined(__DARWIN__)
1307
1308 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1309         .align 2
1310 L_builtin_throw_exception$stub:
1311         .indirect_symbol _builtin_throw_exception
1312         mflr r0
1313         bcl 20,31,L00$_builtin_throw_exception
1314 L00$_builtin_throw_exception:
1315         mflr r11
1316         addis r11,r11,ha16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)
1317         mtlr r0
1318         lwzu r12,lo16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)(r11)
1319         mtctr r12
1320         bctr
1321 .data
1322 .lazy_symbol_pointer
1323 L_builtin_throw_exception$lazy_ptr:
1324         .indirect_symbol _builtin_throw_exception
1325         .long dyld_stub_binding_helper
1326
1327
1328 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1329         .align 2
1330 L_md_codegen_get_pv_from_pc$stub:
1331         .indirect_symbol _md_codegen_get_pv_from_pc
1332         mflr r0
1333         bcl 20,31,L00$_md_codegen_get_pv_from_pc
1334 L00$_md_codegen_get_pv_from_pc:
1335         mflr r11
1336         addis r11,r11,ha16(L_md_codegen_get_pv_from_pc$lazy_ptr - L00$_md_codegen_get_pv_from_pc)
1337         mtlr r0
1338         lwzu r12,lo16(L_md_codegen_get_pv_from_pc$lazy_ptr - L00$_md_codegen_get_pv_from_pc)(r11)
1339         mtctr r12
1340         bctr
1341 .data
1342 .lazy_symbol_pointer
1343 L_md_codegen_get_pv_from_pc$lazy_ptr:
1344         .indirect_symbol _md_codegen_get_pv_from_pc
1345         .long dyld_stub_binding_helper
1346
1347
1348 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1349         .align 2
1350 L_exceptions_handle_exception$stub:
1351         .indirect_symbol _exceptions_handle_exception
1352         mflr r0
1353         bcl 20,31,L00$_exceptions_handle_exception
1354 L00$_exceptions_handle_exception:
1355         mflr r11
1356         addis r11,r11,ha16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)
1357         mtlr r0
1358         lwzu r12,lo16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)(r11)
1359         mtctr r12
1360         bctr
1361 .data
1362 .lazy_symbol_pointer
1363 L_exceptions_handle_exception$lazy_ptr:
1364         .indirect_symbol _exceptions_handle_exception
1365         .long dyld_stub_binding_helper
1366
1367
1368 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1369         .align 2
1370 L_stacktrace_create_extern_stackframeinfo$stub:
1371         .indirect_symbol _stacktrace_create_extern_stackframeinfo
1372         mflr r0
1373         bcl 20,31,L00$_stacktrace_create_extern_stackframeinfo
1374 L00$_stacktrace_create_extern_stackframeinfo:
1375         mflr r11
1376         addis r11,r11,ha16(L_stacktrace_create_extern_stackframeinfo$lazy_ptr - L00$_stacktrace_create_extern_stackframeinfo)
1377         mtlr r0
1378         lwzu r12,lo16(L_stacktrace_create_extern_stackframeinfo$lazy_ptr - L00$_stacktrace_create_extern_stackframeinfo)(r11)
1379         mtctr r12
1380         bctr
1381 .data
1382 .lazy_symbol_pointer
1383 L_stacktrace_create_extern_stackframeinfo$lazy_ptr:
1384         .indirect_symbol _stacktrace_create_extern_stackframeinfo
1385         .long dyld_stub_binding_helper
1386
1387
1388 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1389         .align 2
1390 L_jit_asm_compile$stub:
1391         .indirect_symbol _jit_asm_compile
1392         mflr r0
1393         bcl 20,31,L00$_jit_asm_compile
1394 L00$_jit_asm_compile:
1395         mflr r11
1396         addis r11,r11,ha16(L_jit_asm_compile$lazy_ptr - L00$_jit_asm_compile)
1397         mtlr r0
1398         lwzu r12,lo16(L_jit_asm_compile$lazy_ptr - L00$_jit_asm_compile)(r11)
1399         mtctr r12
1400         bctr
1401 .data
1402 .lazy_symbol_pointer
1403 L_jit_asm_compile$lazy_ptr:
1404         .indirect_symbol _jit_asm_compile
1405         .long dyld_stub_binding_helper
1406
1407
1408 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1409         .align 2
1410 L_stacktrace_remove_stackframeinfo$stub:
1411         .indirect_symbol _stacktrace_remove_stackframeinfo
1412         mflr r0
1413         bcl 20,31,L00$_stacktrace_remove_stackframeinfo
1414 L00$_stacktrace_remove_stackframeinfo:
1415         mflr r11
1416         addis r11,r11,ha16(L_stacktrace_remove_stackframeinfo$lazy_ptr - L00$_stacktrace_remove_stackframeinfo)
1417         mtlr r0
1418         lwzu r12,lo16(L_stacktrace_remove_stackframeinfo$lazy_ptr - L00$_stacktrace_remove_stackframeinfo)(r11)
1419         mtctr r12
1420         bctr
1421 .data
1422 .lazy_symbol_pointer
1423 L_stacktrace_remove_stackframeinfo$lazy_ptr:
1424         .indirect_symbol _stacktrace_remove_stackframeinfo
1425         .long dyld_stub_binding_helper
1426
1427
1428 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1429         .align 2
1430 L_exceptions_get_and_clear_exception$stub:
1431         .indirect_symbol _exceptions_get_and_clear_exception
1432         mflr r0
1433         bcl 20,31,L00$_exceptions_get_and_clear_exception
1434 L00$_exceptions_get_and_clear_exception:
1435         mflr r11
1436         addis r11,r11,ha16(L_exceptions_get_and_clear_exception$lazy_ptr - L00$_exceptions_get_and_clear_exception)
1437         mtlr r0
1438         lwzu r12,lo16(L_exceptions_get_and_clear_exception$lazy_ptr - L00$_exceptions_get_and_clear_exception)(r11)
1439         mtctr r12
1440         bctr
1441 .data
1442 .lazy_symbol_pointer
1443 L_exceptions_get_and_clear_exception$lazy_ptr:
1444         .indirect_symbol _exceptions_get_and_clear_exception
1445         .long dyld_stub_binding_helper
1446
1447
1448 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1449         .align 2
1450 L_exceptions_asm_new_abstractmethoderror$stub:
1451         .indirect_symbol _exceptions_asm_new_abstractmethoderror
1452         mflr r0
1453         bcl 20,31,L00$_exceptions_asm_new_abstractmethoderror
1454 L00$_exceptions_asm_new_abstractmethoderror:
1455         mflr r11
1456         addis r11,r11,ha16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)
1457         mtlr r0
1458         lwzu r12,lo16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)(r11)
1459         mtctr r12
1460         bctr
1461 .data
1462 .lazy_symbol_pointer
1463 L_exceptions_asm_new_abstractmethoderror$lazy_ptr:
1464         .indirect_symbol _exceptions_asm_new_abstractmethoderror
1465         .long dyld_stub_binding_helper
1466
1467
1468 # if defined(ENABLE_REPLACEMENT)
1469
1470 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1471         .align 2
1472 L_replace_me$stub:
1473         .indirect_symbol _replace_me
1474         mflr r0
1475         bcl 20,31,L00$_replace_me
1476 L00$_replace_me:
1477         mflr r11
1478         addis r11,r11,ha16(L_replace_me$lazy_ptr - L00$_replace_me)
1479         mtlr r0
1480         lwzu r12,lo16(L_replace_me$lazy_ptr - L00$_replace_me)(r11)
1481         mtctr r12
1482         bctr
1483 .data
1484 .lazy_symbol_pointer
1485 L_replace_me$lazy_ptr:
1486         .indirect_symbol _replace_me
1487         .long dyld_stub_binding_helper
1488
1489
1490 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1491         .align 2
1492 L_replace_build_execution_state$stub:
1493         .indirect_symbol _replace_build_execution_state
1494         mflr r0
1495         bcl 20,31,L00$_replace_build_execution_state
1496 L00$_replace_build_execution_state:
1497         mflr r11
1498         addis r11,r11,ha16(L_replace_build_execution_state$lazy_ptr - L00$_replace_build_execution_state)
1499         mtlr r0
1500         lwzu r12,lo16(L_replace_build_execution_state$lazy_ptr - L00$_replace_build_execution_state)(r11)
1501         mtctr r12
1502         bctr
1503 .data
1504 .lazy_symbol_pointer
1505 L_replace_build_execution_state$lazy_ptr:
1506         .indirect_symbol _replace_build_execution_state
1507         .long dyld_stub_binding_helper
1508
1509
1510 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
1511         .align 2
1512 L_replace_free_safestack$stub:
1513         .indirect_symbol _replace_free_safestack
1514         mflr r0
1515         bcl 20,31,L00$_replace_free_safestack
1516 L00$_replace_free_safestack:
1517         mflr r11
1518         addis r11,r11,ha16(L_replace_free_safestack$lazy_ptr - L00$_replace_free_safestack)
1519         mtlr r0
1520         lwzu r12,lo16(L_replace_free_safestack$lazy_ptr - L00$_replace_free_safestack)(r11)
1521         mtctr r12
1522         bctr
1523 .data
1524 .lazy_symbol_pointer
1525 L_replace_free_safestack$lazy_ptr:
1526         .indirect_symbol _replace_free_safestack
1527         .long dyld_stub_binding_helper
1528
1529 # endif /* ENABLE_REPLACEMENT */
1530
1531 #endif /* defined(__DARWIN__) */
1532
1533
1534 /* disable exec-stacks ********************************************************/
1535
1536 #if defined(__linux__) && defined(__ELF__)
1537         .section .note.GNU-stack,"",%progbits
1538 #endif
1539
1540
1541 /*
1542  * These are local overrides for various environment variables in Emacs.
1543  * Please do not remove this and leave it at the end of the file, where
1544  * Emacs will automagically detect them.
1545  * ---------------------------------------------------------------------
1546  * Local variables:
1547  * mode: asm
1548  * indent-tabs-mode: t
1549  * c-basic-offset: 4
1550  * tab-width: 4
1551  * End:
1552  * vim:noexpandtab:sw=4:ts=4:
1553  */