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