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