Replaced proto_ exceptions with dynamic ones.
[cacao.git] / src / vm / jit / powerpc / asmpart.S
1 /* jit/powerpc/asmpart.S - Java-C interface functions for powerpc
2                 
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    Institut f. Computersprachen, TU Wien
5    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6    S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
7    J. Wenninger
8
9    This file is part of CACAO.
10
11    This program is free software.text;  you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation;  either version 2, or (at
14    your option) any later version.
15
16    This program is distributed in the hope that it will be useful, but
17    WITHOUT ANY WARRANTY ;  without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program;  if not, write to the Free Software
23    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24    02111-1307, USA.
25
26    Contact: cacao@complang.tuwien.ac.at
27
28    Authors: Andreas Krall
29             Reinhard Grafl
30
31    $Id: asmpart.S 979 2004-03-25 23:46:22Z twisti $
32
33 */
34
35
36 #include "offsets.h"
37
38
39 #define     MethodPointer   -8
40 #define     FrameSize       -12
41 #define     IsSync          -16
42 #define     IsLeaf          -20
43 #define     IntSave         -24
44 #define     FltSave         -28
45 #define     ExTableSize     -32
46 #define     ExTableStart    -32
47
48 #define     ExEntrySize     -16
49 #define     ExStartPC       -4
50 #define     ExEndPC         -8
51 #define     ExHandlerPC     -12
52 #define     ExCatchType     -16
53
54 #define itmp1 r11
55 #define itmp2 r12
56 #define itmp3 r0
57
58 #define xptr itmp1
59 #define xpc itmp2
60
61 #define pv r13
62 #define mptr r12
63 #define mptrn 12
64
65
66         .text
67
68         .align 2
69
70         .globl _asm_docalljavamethod
71         .globl _asm_calljavafunction2
72         .globl _asm_calljavafunction2long
73         .globl _asm_calljavafunction2double
74         .globl _asm_call_jit_compiler
75
76         .globl _jit_compile
77         .globl _asm_handle_nat_exception
78         .globl _asm_handle_exception
79         .globl _asm_check_clinit
80         .globl _asm_builtin_checkarraycast
81         .globl _asm_builtin_aastore
82         .globl _builtin_canstore
83         .globl _builtin_trace_exception
84         .globl _builtin_monitorenter
85         .globl _builtin_monitorexit
86         .globl _builtin_ldiv
87         .globl _builtin_lrem
88         .globl _builtin_checkarraycast
89         .globl _asm_builtin_monitorenter
90         .globl _asm_builtin_monitorexit
91         .globl _asm_builtin_idiv
92         .globl _asm_builtin_irem
93         .globl _asm_builtin_ldiv
94         .globl _asm_builtin_lrem
95         .globl _asm_cacheflush
96         .globl _asm_initialize_thread_stack
97         .globl _asm_perform_threadswitch
98         .globl _asm_switchstackandcall
99
100         .globl _string_java_lang_NullPointerException
101         .globl _string_java_lang_ArrayIndexOutOfBoundsException
102         .globl _string_java_lang_ArrayStoreException
103         .globl _string_java_lang_ArithmeticException
104         .globl _string_java_lang_ArithmeticException_message
105         .globl _string_java_lang_ClassCastException
106
107         .globl _builtin_throw_exception
108         .globl _class_init
109         .globl _catch_Handler
110         .globl _new_exception
111         .globl _new_exception_message
112         .globl _new_exception_int
113
114         .globl _asm_sighandler
115
116 jitcompile:
117         .long _jit_compile
118
119 class_init:
120         .long _class_init
121                 
122 builtinthrow:
123         .long _builtin_throw_exception
124
125 builtin_traceexception:
126         .long _builtin_trace_exception
127 builtin_monitorenter:
128         .long _builtin_monitorenter
129 builtin_monitorexit:
130         .long _builtin_monitorexit
131 builtin_ldiv:
132         .long _builtin_ldiv
133 builtin_lrem:
134         .long _builtin_lrem
135
136 builtincanstore:
137         .long _builtin_canstore
138 builtincheckarraycast:
139         .long _builtin_checkarraycast
140         
141 new_exception:
142         .long _new_exception
143 new_exception_message:
144         .long _new_exception_message
145 new_exception_int:
146         .long _new_exception_int
147
148 string_java_lang_NullPointerException:
149         .long _string_java_lang_NullPointerException
150 string_java_lang_ArrayIndexOutOfBoundsException:
151         .long _string_java_lang_ArrayIndexOutOfBoundsException
152 string_java_lang_ArrayStoreException:
153         .long _string_java_lang_ArrayStoreException
154 string_java_lang_ArithmeticException:
155         .long _string_java_lang_ArithmeticException
156 string_java_lang_ArithmeticException_message:
157         .long _string_java_lang_ArithmeticException_message
158 string_java_lang_ClassCastException:
159         .long _string_java_lang_ClassCastException
160
161 catch_Handler:
162         .long _catch_Handler
163
164                 
165 #define     MethodPointer   -8
166 #define     FrameSize       -12
167 #define     IsSync          -16
168 #define     IsLeaf          -20
169 #define     IntSave         -24
170 #define     FltSave         -28
171 #define     ExTableSize     -32
172 #define     ExTableStart    -32
173
174 #define     ExEntrySize     -16
175 #define     ExStartPC       -4
176 #define     ExEndPC         -8
177 #define     ExHandlerPC     -12
178 #define     ExCatchType     -16
179
180
181         .align 2
182     .long   0                         /* catch type all                       */
183     .long   calljava_xhandler         /* handler pc                           */
184     .long   calljava_xhandler         /* end pc                               */
185     .long   _asm_calljavafunction     /* start pc                             */
186     .long   1                         /* extable size                         */
187     .long   0                         /* fltsave                              */
188     .long   0                         /* intsave                              */
189     .long   0                         /* isleaf                               */
190     .long   0                         /* IsSync                               */
191     .long   24                        /* frame size                           */
192     .long   0                         /* method pointer (pointer to name)     */
193         .long   0                         /* padding                              */
194
195
196 _asm_docalljavamethod:
197         mflr    r0
198         stw     r31,-4(r1)
199 //      stw     r30,-8(r1)
200         stw     pv,-12(r1)
201         stw     r0,8(r1)
202         stwu    r1,-148(r1)
203         bl      0f
204 0:
205         mflr    r31
206
207         stw             r16,40(r1)
208         stw             r17,44(r1)
209         stw             r18,48(r1)
210         stw             r19,52(r1)
211         stw             r20,56(r1)
212         stw             r21,60(r1)
213         stw             r22,64(r1)
214         stw             r23,68(r1)
215         stfd    f16,72(r1)
216         stfd    f17,80(r1)
217         stfd    f18,88(r1)
218         stfd    f19,96(r1)
219         stfd    f20,104(r1)
220         stfd    f21,112(r1)
221         stfd    f22,120(r1)
222         stfd    f23,128(r1)
223
224         stw     r3,36(r1)
225         addi    r2,r1,36
226         mr      r3,r4
227         mr      r4,r5
228         mr      r5,r6
229         mr      r6,r7
230
231 //      addis   mptr,r31,ha16(_asm_call_jit_compiler-0b)
232         addi    mptr,r31,lo16(_asm_call_jit_compiler-0b)
233         stw     mptr,32(r1)
234         addi    mptr,r1,28
235
236         lwz     pv,4(mptr)
237         mtctr   pv
238         bctrl
239 1:
240         mflr    itmp1
241         addi    pv,itmp1,lo16(_asm_docalljavamethod-1b)
242
243 calljava_regrestore:
244         lwz     r16,40(r1)
245         lwz             r17,44(r1)
246         lwz             r18,48(r1)
247         lwz             r19,52(r1)
248         lwz             r20,56(r1)
249         lwz             r21,60(r1)
250         lwz             r22,64(r1)
251         lwz             r23,68(r1)
252         lfd             f16,72(r1)
253         lfd             f17,80(r1)
254         lfd             f18,88(r1)
255         lfd             f19,96(r1)
256         lfd             f20,104(r1)
257         lfd             f21,112(r1)
258         lfd             f22,120(r1)
259         lfd             f23,128(r1)
260
261         lwz     r0,148+8(r1)
262         mtlr    r0
263         addi    r1,r1,148
264         lwz     pv,-12(r1)
265 //      lwz     r30,-8(r1)
266         lwz     r31,-4(r1)
267         blr
268
269 calljava_xhandler:
270         mr      r3,itmp1
271 //      addis   pv,r31,ha16(builtinthrow-0b)
272         lwz     itmp1,lo16(builtinthrow-0b)(r31)
273         mtctr   itmp1
274         bctrl
275         b       calljava_regrestore
276
277
278
279
280         .align 2
281     .long   0                         /* catch type all                       */
282     .long   calljava_xhandler2        /* handler pc                           */
283     .long   calljava_xhandler2        /* end pc                               */
284     .long   _asm_calljavafunction2    /* start pc                             */
285     .long   1                         /* extable size                         */
286     .long   0                         /* fltsave                              */
287     .long   0                         /* intsave                              */
288     .long   0                         /* isleaf                               */
289     .long   0                         /* IsSync                               */
290     .long   24                        /* frame size                           */
291     .long   0                         /* method pointer (pointer to name)     */
292         .long   0                         /* padding                              */
293
294 _asm_calljavafunction2:
295 _asm_calljavafunction2long:
296 _asm_calljavafunction2double:
297         mflr    r0
298         stw     r31,-4(r1)
299 //      stw     r30,-8(r1)
300         stw     pv,-12(r1)
301         stw     r0,8(r1)
302         addi    r1,r1,-148
303         bl      0f
304 0:
305         mflr    r31
306
307         stw     r16,40(r1)
308         stw         r17,44(r1)
309         stw     r18,48(r1)
310         stw         r19,52(r1)
311         stw     r20,56(r1)
312         stw     r21,60(r1)
313         stw     r22,64(r1)
314         stw     r23,68(r1)
315         stfd    f16,72(r1)
316         stfd    f17,80(r1)
317         stfd    f18,88(r1)
318         stfd    f19,96(r1)
319         stfd    f20,104(r1)
320         stfd    f21,112(r1)
321         stfd    f22,120(r1)
322         stfd    f23,128(r1)
323
324         stw     r3,36(r1)                 /* save method pointer for compiler     */
325         addi    r2,r1,36
326         mr      itmp1,r6                  /* pointer to arg block                 */
327         mr      itmp2,r4                  /* arg count                            */
328
329         mr.     itmp2,itmp2
330         ble     calljava_argsloaded
331
332         addi    itmp2,itmp2,-1
333         lwz     r3,offjniitem+4(itmp1)
334         mr.     itmp2,itmp2
335         ble     calljava_argsloaded
336
337         addi    itmp2,itmp2,-1
338         lwz     r4,offjniitem+sizejniblock*1+4(itmp1)
339         mr.     itmp2,itmp2
340         ble     calljava_argsloaded
341     addi    itmp2,itmp2,-1
342
343     addi    itmp2,itmp2,-1
344     lwz     r5,offjniitem+sizejniblock*2+4(itmp1)
345     mr.     itmp2,itmp2
346     ble     calljava_argsloaded
347     addi    itmp2,itmp2,-1
348
349     addi    itmp2,itmp2,-1
350     lwz     r6,offjniitem+sizejniblock*3+4(itmp1)
351     mr.     itmp2,itmp2
352     ble     calljava_argsloaded
353     addi    itmp2,itmp2,-1
354
355 calljava_argsloaded:
356 //      addis   mptr,r31,ha16(_asm_call_jit_compiler-0b)
357         addi    mptr,r31,lo16(_asm_call_jit_compiler-0b)
358         stw     mptr,32(r1)
359         addi    mptr,r1,28
360
361         lwz     pv,4(mptr)
362         mtctr   pv
363         bctrl
364 1:
365         mflr    itmp1
366         addi    pv,itmp1,lo16(_asm_docalljavamethod-1b)
367         
368 calljava_regrestore2:
369         lwz             r16,40(r1)
370         lwz             r17,44(r1)
371         lwz             r18,48(r1)
372         lwz             r19,52(r1)
373         lwz             r20,56(r1)
374         lwz             r21,60(r1)
375         lwz             r22,64(r1)
376         lwz             r23,68(r1)
377         lfd             f16,72(r1)
378         lfd             f17,80(r1)
379         lfd             f18,88(r1)
380         lfd             f19,96(r1)
381         lfd             f20,104(r1)
382         lfd             f21,112(r1)
383         lfd             f22,120(r1)
384         lfd             f23,128(r1)
385
386         lwz     r0,148+8(r1)
387         mtlr    r0
388         addi    r1,r1,148
389         lwz     pv,-12(r1)
390 //      lwz     r30,-8(r1)
391         lwz     r31,-4(r1)
392         blr
393
394 calljava_xhandler2:
395         mr      r3,itmp1
396 //      addis   pv,r31,ha16(builtinthrow-0b)
397         lwz     itmp1,lo16(builtinthrow-0b)(r31)
398         mtctr   itmp1
399         bctrl
400         b       calljava_regrestore2
401
402
403 _asm_call_jit_compiler:
404 0:
405         mflr    itmp1
406         stw     r31,-4(r1)
407 //      stw     pv,-8(r1)
408         stw     r29,-12(r1)
409         stw     itmp1,8(r1)
410         addi    r1,r1,-176
411         mr      r31,pv
412
413         lwz     itmp3,-12(itmp1)
414         srwi    itmp3,itmp3,16
415         andi.   itmp3,itmp3,31
416         cmpwi   itmp3,mptrn
417         beq     noregchange
418         lwz     itmp3,4(itmp1)
419         extsh   itmp3,itmp3
420         add     mptr,itmp3,itmp1
421         lwz     itmp3,8(itmp1)
422         srwi    itmp3,itmp3,16
423         cmpwi   itmp3,0x3dad
424         bne     noregchange
425         lwz     itmp3,8(itmp1)
426         slwi    itmp3,itmp3,16
427         add     mptr,mptr,itmp3
428                 
429 noregchange:
430         mr      r29,mptr
431         stw     r3,28(r1)
432         stw     r4,32(r1)
433         stw     r5,36(r1)
434         stw     r6,40(r1)
435         stw     r7,44(r1)
436         stw     r8,48(r1)
437         stw     r9,52(r1)
438         stfd    f1,56(r1)
439         stfd    f2,64(r1)
440         stfd    f3,72(r1)
441         stfd    f4,80(r1)
442         stfd    f5,88(r1)
443         stfd    f6,96(r1)
444         stfd    f7,104(r1)
445         stfd    f8,112(r1)
446         stfd    f9,120(r1)
447         stfd    f10,128(r1)
448         stfd    f11,136(r1)
449         stfd    f12,144(r1)
450         stfd    f13,152(r1)
451         stw     r10,160(r1)
452
453         lwz     r3,0(r2)
454 //      addis   pv,r31,ha16(jitcompile-0b)
455         lwz     itmp1,lo16(jitcompile-0b)(r31)
456         mtctr   itmp1
457         bctrl
458
459         mr      pv,r3
460         mr      mptr,r29
461         lwz     r3,28(r1)
462         lwz             r4,32(r1)
463         lwz             r5,36(r1)
464         lwz             r6,40(r1)
465         lwz             r7,44(r1)
466         lwz             r8,48(r1)
467         lwz             r9,52(r1)
468         lfd             f1,56(r1)
469         lfd             f2,64(r1)
470         lfd             f3,72(r1)
471         lfd             f4,80(r1)
472         lfd             f5,88(r1)
473         lfd             f6,96(r1)
474         lfd             f7,104(r1)
475         lfd             f8,112(r1)
476         lfd             f9,120(r1)
477         lfd             f10,128(r1)
478         lfd             f11,136(r1)
479         lfd             f12,144(r1)
480         lfd             f13,152(r1)
481         lwz             r10,160(r1)
482
483         lwz     itmp1,176+8(r1)
484         lwz     itmp3,-12(itmp1)
485         extsh   itmp3,itmp3
486         add     mptr,mptr,itmp3
487         stw     pv,0(mptr)
488
489         mtctr   pv
490
491         lwz     r0,176+8(r1)
492         mtlr    r0
493         addi    r1,r1,176
494         lwz     r29,-12(r1)
495 //      lwz     pv,-8(r1)
496         lwz     r31,-4(r1)
497         bctr
498
499
500
501 _asm_handle_nat_exception:
502         mflr    r2
503         lwz     itmp3,4(r2)
504         extsh   itmp3,itmp3
505         add     pv,itmp3,r2
506         lwz     itmp3,8(r2)
507         srwi    itmp3,itmp3,16
508         cmpwi   itmp3,0x3dad
509         bne     _asm_handle_exception
510         lwz     itmp3,8(r2)
511         slwi    itmp3,itmp3,16
512         add     pv,pv,itmp3
513
514 _asm_handle_exception:
515         addi    r1,r1,-18*4
516         stw     r0,0*4(r1)
517         stw     r2,1*4(r1)
518         stw     r3,2*4(r1)
519         stw     r4,3*4(r1)
520         stw     r5,4*4(r1)
521         stw     r6,5*4(r1)
522         stw     r7,6*4(r1)
523         stw     r8,7*4(r1)
524         stw     r9,8*4(r1)
525         stw     r10,9*4(r1)
526         stw     r16,10*4(r1)
527         stw     r17,11*4(r1)
528         stw     r18,12*4(r1)
529         stw     r19,13*4(r1)
530         stw     r20,14*4(r1)
531         stw     r21,15*4(r1)
532         stw     r22,16*4(r1)
533         stw     r23,17*4(r1)
534
535         li      r2,1
536 ex_stack_loop:
537         addi    r1,r1,-4*4
538         stw     xptr,0*4(r1)
539         stw     xpc,1*4(r1)
540         mflr    xptr
541         stw     xptr,2*4(r1)
542         stw     r2,3*4(r1)
543
544         lwz     r3,0*4(r1)            /* exception pointer                        */
545         lwz     r4,MethodPointer(pv)  /* method pointer                           */
546         mr      r5,xpc                /* exception pc                             */
547 /*      mr      r6,r2 */
548         li      r6,0                  /* line number                              */
549         li      r7,4                  /* set no unwind flag                       */
550
551         bl      0f
552 0:
553         mflr    itmp1
554         lwz     itmp1,lo16(builtin_traceexception-0b)(itmp1)
555         mtctr   itmp1
556         addi    r1,r1,-(24+5*4)       /* 24 linkage area + 5 argument * 4         */
557         bctrl
558         addi    r1,r1,(24+5*4)
559
560         lwz     xptr,2*4(r1)
561         mtlr    xptr
562         lwz     xptr,0*4(r1)          /* restore xptr                             */
563         lwz     xpc,1*4(r1)
564         lwz     r2,3*4(r1)
565         addi    r1,r1,4*4
566
567         lwz     r3,ExTableSize(pv)    /* r3 = exception table size                */
568         mr.     r3,r3                 /* if empty table skip                      */
569         beq     empty_table
570
571         addi    r4,pv,ExTableStart    /* r4 = start of exception table            */
572
573 ex_table_loop:
574         lwz     r5,ExStartPC(r4)
575         cmplw   r5,xpc
576         bgt     ex_table_cont
577         lwz     r5,ExEndPC(r4)
578         cmplw   xpc,r5
579         bge     ex_table_cont
580         lwz     r7,ExCatchType(r4)
581         mr.     r7,r7
582         beq     ex_handle_it
583
584         lwz     r6,offobjvftbl(xptr)  /* r6 = vftblptr(xptr)                      */
585         lwz     r7,offclassvftbl(r7)  /* r7 = vftblptr(catchtype) class (not obj) */
586         lwz     r6,offbaseval(r6)     /* r6 = baseval(xptr)                       */
587         lwz     r8,offbaseval(r7)     /* r8 = baseval(catchtype)                  */
588         lwz     r7,offdiffval(r7)     /* r7 = diffval(catchtype)                  */
589         subf    r6,r8,r6              /* r6 = baseval(xptr) - baseval(catchtype)  */
590         cmplw   r6,r7                 /* xptr is instanceof catchtype             */
591         bgt     ex_table_cont         /* if (false) continue                      */
592
593 ex_handle_it:
594         lwz     xpc,ExHandlerPC(r4)   /* xpc = exception handler pc               */
595         mr.     r2,r2
596         beq     ex_jump
597
598         lwz     r0,0*4(r1)
599         lwz     r2,1*4(r1)
600         lwz     r3,2*4(r1)
601         lwz     r4,3*4(r1)
602         lwz     r5,4*4(r1)
603         lwz     r6,5*4(r1)
604         lwz     r7,6*4(r1)
605         lwz     r8,7*4(r1)
606         lwz     r9,8*4(r1)
607         lwz     r10,9*4(r1)
608         lwz     r16,10*4(r1)
609         lwz     r17,11*4(r1)
610         lwz     r18,12*4(r1)
611         lwz     r19,13*4(r1)
612         lwz     r20,14*4(r1)
613         lwz     r21,15*4(r1)
614         lwz     r22,16*4(r1)
615         lwz     r23,17*4(r1)
616         addi    r1,r1,18*4
617
618 ex_jump:
619         mtctr   xpc
620         bctr
621
622 ex_table_cont:
623         addi    r4,r4,ExEntrySize
624         addic.  r3,r3,-1
625         bgt     ex_table_loop
626
627 empty_table:
628         mr.     r2,r2                 /* if here the first time, then             */
629         beq     ex_already_cleared
630         addi    r1,r1,18*4            /* deallocate stack and                     */
631         li      r2,0                  /* clear the no unwind flag                 */
632 ex_already_cleared:
633         lwz     r3,IsSync(pv)
634         mr.     r3,r3
635         beq     no_monitor_exit
636         add     r3,r1,r3
637         lwz     r6,-4(r3)
638
639         addi    r1,r1,-6*4
640         stw     r3,0*4(r1)
641         stw     r4,1*4(r1)
642         stw     r2,2*4(r1)
643         stw     xptr,3*4(r1)
644         stw     xpc,4*4(r1)
645         mflr    xptr
646         stw     xptr,5*4(r1)
647
648         mr      r3,r6
649         bl      0f
650 0:
651         mflr    itmp1
652         lwz     itmp1,lo16(builtin_monitorexit-0b)(itmp1)
653         mtctr   itmp1
654         addi    r1,r1,-40
655         bctrl
656         addi    r1,r1,40
657
658         lwz     xptr,5*4(r1)
659         mtlr    xptr
660         lwz     r3,0*4(r1)
661         lwz     r4,1*4(r1)
662         lwz     r2,2*4(r1)
663         lwz     xptr,3*4(r1)
664         lwz     xpc,4*4(r1)
665         addi    r1,r1,6*4
666
667 no_monitor_exit:
668         lwz     r3,FrameSize(pv)      /* r3 = frame size                          */
669         add     r1,r1,r3              /* unwind stack                             */
670         mr      r3,r1                 /* r3 = pointer to save area                */
671         lwz     r4,IsLeaf(pv)         /* r4 = is leaf procedure                   */
672         mr.     r4,r4
673         bne     ex_no_restore         /* if (leaf) skip                           */
674         lwz     r4,8(r3)              /* restore ra                               */
675         mtlr    r4                    /* t0--                                     */
676 ex_no_restore:
677         mflr    r4                    /* the new xpc is ra                        */
678         mr      xpc,r4
679         lwz     r4,IntSave(pv)        /* r4 = saved int register count            */
680         bl      ex_int1
681 ex_int1:
682         mflr    r5
683         addi    r5,r5,lo16(ex_int2-ex_int1)
684         slwi    r4,r4,2
685         subf    r5,r4,r5
686         mtctr   r5
687         bctr
688         lwz     r14,-40(r3)
689         lwz     r15,-36(r3)
690         lwz     r24,-32(r3)
691         lwz     r25,-28(r3)
692         lwz     r26,-24(r3)
693         lwz     r27,-20(r3)
694         lwz     r28,-16(r3)
695         lwz     r29,-12(r3)
696         lwz     r30,-8(r3)
697         lwz     r31,-4(r3)
698 ex_int2:
699         subf    r3,r4,r3
700
701         lwz     r4,FltSave(pv)
702         bl      ex_flt1
703 ex_flt1:
704         mflr    r5
705         addi    r5,r5,lo16(ex_flt2-ex_flt1)
706         slwi    r4,r4,2
707         subf    r5,r4,r5
708         mtctr   r5
709         bctr
710         lfd     f14,-80(r3)
711         lfd     f15,-72(r3)
712         lfd     f24,-64(r3)
713         lfd     f25,-56(r3)
714         lfd     f26,-48(r3)
715         lfd     f27,-40(r3)
716         lfd     f28,-32(r3)
717         lfd     f29,-24(r3)
718         lfd     f30,-16(r3)
719         lfd     f31,-8(r3)
720 ex_flt2:
721         mtlr    xpc
722         lwz     itmp3,4(xpc)
723         extsh   itmp3,itmp3
724         add     pv,itmp3,xpc
725         lwz     itmp3,8(xpc)
726         srwi    itmp3,itmp3,16
727         cmpwi   itmp3,0x3dad
728         bne     ex_stack_loop
729         lwz     itmp3,8(xpc)
730         slwi    itmp3,itmp3,16
731         add     pv,pv,itmp3
732         b       ex_stack_loop
733
734
735 /********************* asm_check_clinit ****************************************
736 *                                                                              *
737 *   call static class initializer for PUT/GETSTATIC instructions               *
738 *                                                                              *
739 *******************************************************************************/
740
741 _asm_check_clinit:
742 0:
743         lwz     itmp2,offclassinit(itmp1)
744         mr.     itmp2,itmp2
745         bne     L_is_initialized
746
747         mflr    r0
748         stw     r0,8(r1)
749         addi    r1,r1,-(24*8)
750
751     stw     r3,3*8(r1)                  /* save argument registers            */
752     stw     r4,4*8(r1)                  /* preserve linkage area (24 bytes)   */
753     stw     r5,5*8(r1)
754     stw     r6,6*8(r1)
755     stw     r7,7*8(r1)
756     stw     r8,8*8(r1)
757     stw     r9,9*8(r1)
758         stw     r10,10*8(r1)
759
760         stfd    f1,11*8(r1)
761     stfd    f2,12*8(r1)
762     stfd    f3,13*8(r1)
763     stfd    f4,14*8(r1)
764     stfd    f5,15*8(r1)
765     stfd    f6,16*8(r1)
766     stfd    f7,17*8(r1)
767     stfd    f8,18*8(r1)
768     stfd    f9,19*8(r1)
769     stfd    f10,20*8(r1)
770     stfd    f11,21*8(r1)
771     stfd    f12,22*8(r1)
772     stfd    f13,23*8(r1)
773                 
774         mr      r3,itmp1
775         lwz     itmp1,lo16(class_init-0b)(pv)
776         mtctr   itmp1
777         bctrl
778
779         lwz     r3,3*8(r1)
780         lwz     r4,4*8(r1)
781         lwz     r5,5*8(r1)
782         lwz     r6,6*8(r1)
783         lwz     r7,7*8(r1)
784         lwz     r8,8*8(r1)
785         lwz     r9,9*8(r1)
786         lwz     r10,10*8(r1)
787
788     lfd     f1,11*8(r1)
789     lfd     f2,12*8(r1)
790     lfd     f3,13*8(r1)
791     lfd         f4,14*8(r1)
792     lfd         f5,15*8(r1)
793     lfd         f6,16*8(r1)
794     lfd         f7,17*8(r1)
795     lfd         f8,18*8(r1)
796     lfd         f9,19*8(r1)
797     lfd         f10,20*8(r1)
798     lfd         f11,21*8(r1)
799     lfd         f12,22*8(r1)
800     lfd         f13,23*8(r1)
801                 
802         lwz     r0,(24*8)+8(r1)
803         mtlr    r0
804         addi    r1,r1,(24*8)
805
806 L_is_initialized:
807         blr
808
809
810 /******************* function asm_builtin_checkarraycast ***********************
811 *                                                                              *
812 *   Does the cast check and eventually throws an exception                     *
813 *                                                                              *
814 *******************************************************************************/
815                 
816 _asm_builtin_checkarraycast:
817 0:
818         mflr    r0
819         stw     r0,8(r1)
820         stwu    r1,-48(r1)
821
822         stw     r3,32(r1)
823         lwz     itmp1,lo16(builtincheckarraycast-0b)(pv)
824         mtctr   itmp1
825         bctrl
826
827         lwz     r0,48+8(r1)
828         mtlr    r0
829         mr.     r3,r3
830         beq     nb_carray_throw
831         lwz     r3,32(r1)
832         addi    r1,r1,48
833         blr
834
835 nb_carray_throw:
836         addi    r1,r1,48
837         mflr    r0
838         stw     r0,8(r1)
839         addi    r1,r1,-(24+4)
840         lwz     r3,lo16(string_java_lang_ClassCastException-0b)(pv)
841         lwz     r3,0(r3)
842         lwz     itmp1,lo16(new_exception-0b)(pv)
843         mtctr   itmp1
844         bctrl
845         mr      xptr,r3
846         addi    r1,r1,24+4
847         lwz     r0,8(r1)
848         mr      xpc,r0
849         mtlr    r0
850         b       _asm_handle_nat_exception
851
852
853 /******************* function asm_builtin_aastore ******************************
854 *                                                                              *
855 *   Does the cast check and eventually throws an exception                     *
856 *                                                                              *
857 *******************************************************************************/
858         
859 _asm_builtin_aastore:
860 0:
861         mr.     r3,r3
862         beq     nb_aastore_null
863         mflr    r0
864         stw     r0,8(r1)
865         addi    r1,r1,-48
866
867         lwz     itmp1,offarraysize(r3)
868         slwi    itmp3,r4,2
869         add     itmp2,r3,itmp3
870         cmplw   r4,itmp1
871         bge     nb_aastore_bound
872         mr      r4,r5
873         stw     itmp2,32(r1)
874         stw     r4,36(r1)
875 //      addis   pv,r31,ha16(builtincanstore-0b)
876         lwz     itmp1,lo16(builtincanstore-0b)(pv)
877         mtctr   itmp1
878         bctrl
879
880         lwz     r0,48+8(r1)
881         mtlr    r0
882         lwz     itmp1,32(r1)
883         lwz     itmp2,36(r1)
884         addi    r1,r1,48
885         mr.     r3,r3
886         beq     nb_aastore_store
887         stw     itmp2,offobjarrdata(itmp1)
888         blr
889
890 nb_aastore_null:
891         mflr    r0
892         stw     r0,8(r1)
893         addi    r1,r1,-(24+4)
894         lwz     r3,lo16(string_java_lang_NullPointerException-0b)(pv)
895         lwz     r3,0(r3)
896         lwz     itmp1,lo16(new_exception-0b)(pv)
897         mtctr   itmp1
898         bctrl
899         mr      xptr,r3
900         addi    r1,r1,(24+4)
901         lwz     r0,8(r1)
902         mr      xpc,r0
903         mtlr    r0
904         b       _asm_handle_nat_exception
905
906 nb_aastore_bound:
907         addi    r1,r1,48
908         mflr    r0
909         stw     r0,8(r1)
910         addi    r1,r1,-(24+2*4)
911         lwz     r3,lo16(string_java_lang_ArrayIndexOutOfBoundsException-0b)(pv)
912         lwz     r3,0(r3)
913         lwz     itmp1,lo16(new_exception_int-0b)(pv)
914         mtctr   itmp1
915         bctrl                         /* r4 already contains the index            */
916         mr      xptr,r3
917         addi    r1,r1,(24+2*4)
918         lwz     r0,8(r1)
919         mr      xpc,r0
920         mtlr    r0
921         b       _asm_handle_nat_exception
922
923 nb_aastore_store:
924         mflr    r0
925         stw     r0,8(r1)
926         addi    r1,r1,-(24+4)
927         lwz     r3,lo16(string_java_lang_ArrayStoreException-0b)(pv)
928         lwz     r3,0(r3)
929         lwz     itmp1,lo16(new_exception-0b)(pv)
930         mtctr   itmp1
931         bctrl
932         mr      xptr,r3
933         addi    r1,r1,(24+4)
934         lwz     r0,8(r1)
935         mr      xpc,r0
936         mtlr    r0
937         b       _asm_handle_nat_exception
938
939
940 _asm_builtin_monitorenter:
941 0:
942         lwz     itmp2,lo16(builtin_monitorenter-0b)(pv)
943         mr.     r3,r3
944         beq     nb_monitorenter
945         mtctr   itmp2
946         bctr
947
948 nb_monitorenter:
949         mflr    r0
950         stw     r0,8(r1)
951         addi    r1,r1,-(24+4)
952         lwz     r3,lo16(string_java_lang_NullPointerException-0b)(pv)
953         lwz     r3,0(r3)
954         lwz     itmp1,lo16(new_exception-0b)(pv)
955         mtctr   itmp1
956         bctrl
957         mr      xptr,r3
958         addi    r1,r1,24+4
959         lwz     r0,8(r1)
960 /*      addi    xpc,r0,-4 */
961         mr      xpc,r0
962         addi    xpc,xpc,-4
963
964         mtlr    r0
965         b       _asm_handle_nat_exception
966
967
968 _asm_builtin_monitorexit:
969 0:
970         lwz     itmp2,lo16(builtin_monitorexit-0b)(pv)
971         mr.     r3,r3
972         beq     nb_monitorexit
973         mtctr   itmp2
974         bctr
975
976 nb_monitorexit:
977         mflr    r0
978         stw     r0,8(r1)
979         addi    r1,r1,-(24+4)
980         lwz     r3,lo16(string_java_lang_NullPointerException-0b)(pv)
981         lwz     r3,0(r3)
982         lwz     itmp1,lo16(new_exception-0b)(pv)
983         mtctr   itmp1
984         bctrl
985         mr      xptr,r3
986         addi    r1,r1,24+4
987         lwz     r0,8(r1)
988 /*      addi    xpc,r0,-4 */
989         mr      xpc,r0
990         addi    xpc,xpc,-4
991
992         mtlr    r0
993         b       _asm_handle_nat_exception
994         
995         
996 _asm_builtin_idiv:
997 0:
998         mr.     r4,r4
999         beq     nb_idiv
1000         lis     itmp3,0x8000
1001         cmpw    r3,itmp3
1002         bne     normal_idiv
1003         cmpwi   r4,-1
1004         bne     normal_idiv
1005         blr
1006
1007 normal_idiv:
1008         divw    r3,r3,r4
1009         blr
1010
1011 nb_idiv:
1012         mflr    r0
1013         stw     r0,8(r1)
1014         addi    r1,r1,-(24+2*4)
1015         lwz     r3,lo16(string_java_lang_ArithmeticException-0b)(pv)
1016         lwz     r3,0(r3)
1017         lwz     r4,lo16(string_java_lang_ArithmeticException_message-0b)(pv)
1018         lwz     r4,0(r4)
1019         lwz     itmp1,lo16(new_exception_message-0b)(pv)
1020         mtctr   itmp1
1021         bctrl
1022         mr      xptr,r3
1023         addi    r1,r1,(24+2*4)
1024         lwz     r0,8(r1)
1025         mr      xpc,r0
1026         mtlr    r0
1027         b       _asm_handle_nat_exception
1028
1029
1030 _asm_builtin_irem:
1031 0:
1032         mr      itmp2,r3
1033         mr.     r4,r4
1034         beq     nb_irem
1035         lis     itmp3,0x8000
1036         cmpw    itmp2,itmp3
1037         bne     normal_irem
1038         cmpwi   r4,-1
1039         bne     normal_irem
1040         li      r3,0
1041         beqlr
1042
1043 normal_irem:
1044         divw    itmp3,itmp2,r4
1045         mullw   itmp3,itmp3,r4
1046         subf    r3,itmp3,itmp2
1047         blr
1048
1049 nb_irem:
1050         mflr    r0
1051         stw     r0,8(r1)
1052         addi    r1,r1,-(24+2*4)
1053         lwz     r3,lo16(string_java_lang_ArithmeticException-0b)(pv)
1054         lwz     r3,0(r3)
1055         lwz     r4,lo16(string_java_lang_ArithmeticException_message-0b)(pv)
1056         lwz     r4,0(r4)
1057         lwz     itmp1,lo16(new_exception_message-0b)(pv)
1058         mtctr   itmp1
1059         bctrl
1060         mr      xptr,r3
1061         addi    r1,r1,(24+2*4)
1062         lwz     r0,8(r1)
1063         mr      xpc,r0
1064         mtlr    r0
1065         b       _asm_handle_nat_exception
1066
1067
1068 _asm_builtin_ldiv:
1069 0:
1070         or.     r0,r5,r6
1071         beq     nb_ldiv
1072         lwz     itmp1,lo16(builtin_ldiv-0b)(pv)
1073         mtctr   itmp1
1074         bctr
1075
1076 nb_ldiv:
1077         mflr    r0
1078         stw     r0,8(r1)
1079         addi    r1,r1,-(24+2*4)
1080         lwz     r3,lo16(string_java_lang_ArithmeticException-0b)(pv)
1081         lwz     r3,0(r3)
1082         lwz     r4,lo16(string_java_lang_ArithmeticException_message-0b)(pv)
1083         lwz     r4,0(r4)
1084         lwz     itmp1,lo16(new_exception_message-0b)(pv)
1085         mtctr   itmp1
1086         bctrl
1087         mr      xptr,r3
1088         addi    r1,r1,(24+2*4)
1089         lwz     r0,8(r1)
1090         mr      xpc,r0
1091         mtlr    r0
1092         b       _asm_handle_nat_exception
1093
1094
1095  _asm_builtin_lrem:
1096 0:
1097         or.     r0,r5,r6
1098         beq     nb_lrem
1099         lwz     itmp1,lo16(builtin_lrem-0b)(pv)
1100         mtctr   itmp1
1101         bctr
1102
1103 nb_lrem:
1104         mflr    r0
1105         stw     r0,8(r1)
1106         addi    r1,r1,-(24+2*4)
1107         lwz     r3,lo16(string_java_lang_ArithmeticException-0b)(pv)
1108         lwz     r3,0(r3)
1109         lwz     r4,lo16(string_java_lang_ArithmeticException_message-0b)(pv)
1110         lwz     r4,0(r4)
1111         lwz     itmp1,lo16(new_exception_message-0b)(pv)
1112         mtctr   itmp1
1113         bctrl
1114         mr      xptr,r3
1115         addi    r1,r1,(24+2*4)
1116         lwz     r0,8(r1)
1117         mr      xpc,r0
1118         mtlr    r0
1119         b       _asm_handle_nat_exception
1120
1121
1122 _asm_cacheflush:
1123         addi    r4,r4,31
1124         mr      r5,r3
1125         add     r4,r3,r4
1126 1:
1127         cmplw   r3,r4
1128         bge     0f
1129         dcbst   0,r3
1130         addi    r3,r3,32
1131         b       1b
1132 0:
1133         sync
1134 1:
1135         cmplw   r5,r4
1136         bge     0f
1137         icbi    0,r5
1138         addi    r5,r5,32
1139         b       1b
1140 0:
1141         sync
1142         isync
1143         blr
1144
1145
1146         .align 3
1147 doublezero:
1148         .double 0.0
1149
1150 _asm_initialize_thread_stack:
1151         addi r4,r4,-256
1152         stw r3,120(r4)
1153         li r3,0
1154         stw r3,124(r4)
1155         stw r3,0(r4)
1156         stw r3,4(r4)
1157         stw r3,8(r4)
1158         stw r3,12(r4)
1159         stw r3,16(r4)
1160         stw r3,20(r4)
1161         stw r3,24(r4)
1162         stw r3,28(r4)
1163         stw r3,32(r4)
1164         stw r3,36(r4)
1165
1166         stw r3,128(r4)
1167         stw r3,132(r4)
1168         stw r3,136(r4)
1169         stw r3,140(r4)
1170         stw r3,144(r4)
1171         stw r3,148(r4)
1172         stw r3,152(r4)
1173         stw r3,156(r4)
1174
1175         mflr r0
1176         bl 0f
1177 0:
1178         mflr r3
1179         mtlr r0
1180         lfd f0,lo16(doublezero-0b)(r3)
1181
1182         stfd f0,40(r4)
1183         stfd f0,48(r4)
1184         stfd f0,56(r4)
1185         stfd f0,64(r4)
1186         stfd f0,72(r4)
1187         stfd f0,80(r4)
1188         stfd f0,88(r4)
1189         stfd f0,96(r4)
1190         stfd f0,104(r4)
1191         stfd f0,112(r4)
1192
1193         stfd f0,160(r4)
1194         stfd f0,168(r4)
1195         stfd f0,176(r4)
1196         stfd f0,184(r4)
1197         stfd f0,192(r4)
1198         stfd f0,200(r4)
1199         stfd f0,208(r4)
1200         stfd f0,216(r4)
1201
1202         mr r3,r4
1203         blr
1204
1205
1206 _asm_perform_threadswitch:
1207         mflr r0
1208         addi r1,r1,-224
1209         stw r0,120(r1)
1210         stw pv,124(r1)
1211         stw r14,0(r1)
1212         stw r15,4(r1)
1213         stw r24,8(r1)
1214         stw r25,12(r1)
1215         stw r26,16(r1)
1216         stw r27,20(r1)
1217         stw r28,24(r1)
1218         stw r29,28(r1)
1219         stw r30,32(r1)
1220         stw r31,36(r1)
1221         stfd f14,40(r1)
1222         stfd f15,48(r1)
1223         stfd f24,56(r1)
1224         stfd f25,64(r1)
1225         stfd f26,72(r1)
1226         stfd f27,80(r1)
1227         stfd f28,88(r1)
1228         stfd f29,96(r1)
1229         stfd f30,104(r1)
1230         stfd f31,112(r1)
1231
1232         stw r16,128(r1)
1233         stw r17,132(r1)
1234         stw r18,136(r1)
1235         stw r19,140(r1)
1236         stw r20,144(r1)
1237         stw r21,148(r1)
1238         stw r22,152(r1)
1239         stw r23,156(r1)
1240         stfd f16,160(r1)
1241         stfd f17,168(r1)
1242         stfd f18,176(r1)
1243         stfd f19,184(r1)
1244         stfd f20,192(r1)
1245         stfd f21,200(r1)
1246         stfd f22,208(r1)
1247         stfd f23,216(r1)
1248
1249         stw r1,0(r3)
1250         stw r1,0(r5)
1251         lwz r1,0(r4)
1252
1253         lwz r0,120(r1)
1254         lwz pv,124(r1)
1255         lwz r14,0(r1)
1256         lwz r15,4(r1)
1257         lwz r24,8(r1)
1258         lwz r25,12(r1)
1259         lwz r26,16(r1)
1260         lwz r27,20(r1)
1261         lwz r28,24(r1)
1262         lwz r29,28(r1)
1263         lwz r30,32(r1)
1264         lwz r31,36(r1)
1265         lfd f14,40(r1)
1266         lfd f15,48(r1)
1267         lfd f24,56(r1)
1268         lfd f25,64(r1)
1269         lfd f26,72(r1)
1270         lfd f27,80(r1)
1271         lfd f28,88(r1)
1272         lfd f29,96(r1)
1273         lfd f30,104(r1)
1274         lfd f31,112(r1)
1275
1276         lwz r16,128(r1)
1277         lwz r17,132(r1)
1278         lwz r18,136(r1)
1279         lwz r19,140(r1)
1280         lwz r20,144(r1)
1281         lwz r21,148(r1)
1282         lwz r22,152(r1)
1283         lwz r23,156(r1)
1284         lfd f16,160(r1)
1285         lfd f17,168(r1)
1286         lfd f18,176(r1)
1287         lfd f19,184(r1)
1288         lfd f20,192(r1)
1289         lfd f21,200(r1)
1290         lfd f22,208(r1)
1291         lfd f23,216(r1)
1292
1293         mtlr r0
1294         addi r1,r1,224
1295         blr
1296
1297
1298 _asm_switchstackandcall:
1299         mflr r0
1300         addi r3,r3,-48
1301         stw r0,40(r3)
1302         stw r1,44(r3)
1303         stw r1,0(r5)
1304         mr r1,r3
1305
1306         mtctr r4
1307         mr r3,r6
1308         bctrl
1309
1310         lwz r0,40(r1)
1311         mtlr r0
1312         lwz r1,44(r1)
1313         blr
1314
1315
1316 #define C_RED_ZONE 224
1317
1318 _asm_sighandler:
1319         addi r1,r1,-32*4 - 32 - C_RED_ZONE
1320         stmw r0,32(r1)
1321         mflr r0
1322         stw r0,28(r1)
1323
1324         bl 0f
1325 0:
1326         mflr r31
1327         lwz r0,lo16(catch_Handler-0b)(r31)
1328         mtctr r0
1329         addi r3,r1,32
1330         bctrl
1331         
1332         lwz r0,28(r1)
1333         mtlr r0
1334         cmpwi r3,0
1335         bne 1f
1336         lmw r2,32+8(r1)
1337         lwz r0,32(r1)
1338         addi r1,r1,32*4 + 32 + C_RED_ZONE
1339         b _asm_handle_exception
1340
1341 1:
1342         mtctr r3
1343         lmw r2,32+8(r1)
1344         lwz r0,32(r1)
1345         addi r1,r1,32*4 + 32 + C_RED_ZONE
1346         bctr
1347
1348
1349 /*
1350  * These are local overrides for various environment variables in Emacs.
1351  * Please do not remove this and leave it at the end of the file, where
1352  * Emacs will automagically detect them.
1353  * ---------------------------------------------------------------------
1354  * Local variables:
1355  * mode: asm
1356  * indent-tabs-mode: t
1357  * c-basic-offset: 4
1358  * tab-width: 4
1359  * End:
1360  */