e4c45db366f030924affb9295465f2f82889d2af
[cacao.git] / jit / alpha / asmpart.S
1 /* -*- mode: asm; tab-width: 4 -*- */
2 /****************************** asmpart.S **************************************
3 *                                                                              *
4 *   It contains the Java-C interface functions for Alpha processors.           *
5 *                                                                              *
6 *   Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst              *
7 *                                                                              *
8 *   See file COPYRIGHT for information on usage and disclaimer of warranties   *
9 *                                                                              *
10 *   Authors: Andreas  Krall      EMAIL: cacao@complang.tuwien.ac.at            *
11 *            Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at            *
12 *                                                                              *
13 *   Last Change: 2003/02/17                                                    *
14 *                                                                              *
15 *******************************************************************************/
16
17 #include "offsets.h"
18
19 #define v0      $0
20
21 #define t0      $1
22 #define t1      $2
23 #define t2      $3
24 #define t3      $4
25 #define t4      $5
26 #define t5      $6
27 #define t6      $7
28 #define t7      $8
29
30 #define s0      $9
31 #define s1      $10
32 #define s2      $11
33 #define s3      $12
34 #define s4      $13
35 #define s5      $14
36 #define s6      $15
37
38 #define a0      $16
39 #define a1      $17
40 #define a2      $18
41 #define a3      $19
42 #define a4      $20
43 #define a5      $21
44
45 #define t8      $22
46 #define t9      $23
47 #define t10     $24
48 #define t11     $25
49 #define ra      $26
50 #define t12     $27
51
52 #define pv      t12
53 #define AT      $at
54 #define gp      $29
55 #define sp      $30
56 #define zero    $31
57
58 #define itmp1   $25
59 #define itmp2   $28
60 #define itmp3   $29
61
62 #define xptr    itmp1
63 #define xpc     itmp2
64
65 #define sf0     $f2
66 #define sf1     $f3
67 #define sf2     $f4
68 #define sf3     $f5
69 #define sf4     $f6
70 #define sf5     $f7
71 #define sf6     $f8
72 #define sf7     $f9
73
74 #define fzero   $f31
75
76
77 #define PAL_imb 134
78
79         .text
80         .set    noat
81         .set    noreorder
82
83
84 /********************* exported functions and variables ***********************/
85
86         .globl has_no_x_instr_set
87         .globl synchronize_caches
88         .globl asm_calljavamethod
89         .globl asm_calljavafunction
90         .globl asm_calljavafunction2
91         .globl asm_calljavafunction2double
92         .globl asm_calljavafunction2long
93         .globl asm_call_jit_compiler
94         .globl asm_dumpregistersandcall
95         .globl asm_handle_exception
96         .globl asm_handle_nat_exception
97         .globl asm_builtin_checkcast    
98         .globl asm_builtin_checkarraycast
99         .globl asm_builtin_aastore
100         .globl asm_builtin_monitorenter
101         .globl asm_builtin_monitorexit
102         .globl asm_builtin_idiv
103         .globl asm_builtin_irem
104         .globl asm_builtin_ldiv
105         .globl asm_builtin_lrem
106         .globl asm_perform_threadswitch
107         .globl asm_initialize_thread_stack
108         .globl asm_switchstackandcall
109         .globl asm_getcallingmethod
110         .globl asm_builtin_trace
111         .globl asm_builtin_exittrace
112
113 /*************************** imported functions *******************************/
114
115         .globl jit_compile
116         .globl builtin_monitorexit
117         .globl builtin_throw_exception
118         .globl builtin_trace_exception
119         .globl class_java_lang_Object
120
121
122 /*********************** function has_no_x_instr_set ***************************
123 *                                                                              *
124 *   determines if the byte support instruction set (21164a and higher)         *
125 *   is available.                                                              *
126 *                                                                              *
127 *******************************************************************************/
128
129         .ent    has_no_x_instr_set
130 has_no_x_instr_set:
131
132         .long   0x47e03c20                /* amask   1,v0                         */
133         jmp     zero,(ra)                 /* return                               */
134
135         .end    has_no_x_instr_set
136
137
138 /********************* function synchronize_caches ****************************/
139
140         .ent    synchronize_caches
141 synchronize_caches:
142
143         call_pal PAL_imb                  /* synchronise instruction cache        */
144         jmp     zero,(ra)                 /* return                               */
145
146         .end    synchronize_caches
147
148
149 /********************* function asm_calljavamethod *****************************
150 *                                                                              *
151 *   This function calls a Java-method (which possibly needs compilation)       *
152 *   with up to 4 parameters.                                                   *
153 *                                                                              *
154 *   This functions calls the JIT-compiler which eventually translates the      *
155 *   method into machine code.                                                  *
156 *                                                                              *
157 *   An possibly throwed exception will be returned to the caller as function   *
158 *   return value, so the java method cannot return a fucntion value (this      *
159 *   function usually calls 'main' and '<clinit>' which do not return a         *
160 *   function value).                                                           *
161 *                                                                              *
162 *   C-prototype:                                                               *
163 *    javaobject_header *asm_calljavamethod (methodinfo *m,                     *
164 *         void *arg1, void *arg2, void *arg3, void *arg4);                     *
165 *                                                                              *
166 *******************************************************************************/
167
168 #define         MethodPointer   -8
169 #define         FrameSize       -12
170 #define     IsSync          -16
171 #define     IsLeaf          -20
172 #define     IntSave         -24
173 #define     FltSave         -28
174 #define     ExTableSize     -32
175 #define     ExTableStart    -32
176
177 #define     ExEntrySize     -32
178 #define     ExStartPC       -8
179 #define     ExEndPC         -16
180 #define     ExHandlerPC     -24
181 #define     ExCatchType     -32
182
183         .ent    asm_calljavamethod
184
185 call_name:
186         .ascii  "calljavamethod\0\0"
187
188         .align  3
189         .quad   0                         /* catch type all                       */
190         .quad   calljava_xhandler         /* handler pc                           */
191         .quad   calljava_xhandler         /* end pc                               */
192         .quad   asm_calljavamethod        /* start pc                             */
193         .long   1                         /* extable size                         */
194         .long   0                         /* fltsave                              */
195         .long   0                         /* intsave                              */
196         .long   0                         /* isleaf                               */
197         .long   0                         /* IsSync                               */
198         .long   32                        /* frame size                           */
199         .quad   0                         /* method pointer (pointer to name)     */
200
201 asm_calljavamethod:
202
203         ldgp    gp,0(pv)
204         lda     sp,-32(sp)                /* allocate stack space                 */
205         stq     gp,24(sp)                 /* save global pointer                  */
206         stq     ra,0(sp)                  /* save return address                  */
207
208         stq     a0,16(sp)                 /* save method pointer for compiler     */
209         lda     v0,16(sp)                 /* pass pointer to method pointer via v0*/
210
211         mov     a1,a0                     /* pass the remaining parameters        */
212         mov     a2,a1
213         mov     a3,a2
214         mov     a4,a3
215
216         lda     $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
217         stq     $28,8(sp)                 /* store function address               */
218         mov     sp,$28                    /* set method pointer                   */
219
220         ldq     pv,8($28)                 /* method call as in Java               */
221         jmp     ra,(pv)                   /* call JIT compiler                    */
222 calljava_jit:
223         lda     pv,-64(ra)                /* asm_calljavamethod-calljava_jit !!!!!*/
224
225 calljava_return:
226
227         ldq     ra,0(sp)                  /* restore return address               */
228         ldq     gp,24(sp)                 /* restore global pointer               */
229         lda     sp,32(sp)                 /* free stack space                     */
230     clr     v0
231
232 calljava_ret:
233         jmp     zero,(ra)
234
235 calljava_xhandler:
236
237         ldq     gp,24(sp)                 /* restore global pointer               */
238         mov     itmp1,a0
239         jsr     ra,builtin_throw_exception
240         ldq     ra,0(sp)                  /* restore return address               */
241         lda     sp,32(sp)                 /* free stack space                     */
242         jmp     zero,(ra)
243         .end    asm_calljavamethod
244
245
246 /********************* function asm_calljavafunction ***************************
247 *                                                                              *
248 *   This function calls a Java-method (which possibly needs compilation)       *
249 *   with up to 4 address parameters.                                           *
250 *                                                                              *
251 *   This functions calls the JIT-compiler which eventually translates the      *
252 *   method into machine code.                                                  *
253 *                                                                              *
254 *   C-prototype:                                                               *
255 *    javaobject_header *asm_calljavamethod (methodinfo *m,                     *
256 *         void *arg1, void *arg2, void *arg3, void *arg4);                     *
257 *                                                                              *
258 *******************************************************************************/
259
260         .ent    asm_calljavafunction
261
262 call_name2:
263         .ascii  "calljavafunction\0\0"
264
265         .align  3
266         .quad   0                         /* catch type all                       */
267         .quad   calljava_xhandler2        /* handler pc                           */
268         .quad   calljava_xhandler2        /* end pc                               */
269         .quad   asm_calljavafunction      /* start pc                             */
270         .long   1                         /* extable size                         */
271         .long   0                         /* fltsave                              */
272         .long   0                         /* intsave                              */
273         .long   0                         /* isleaf                               */
274         .long   0                         /* IsSync                               */
275         .long   32                        /* frame size                           */
276         .quad   0                         /* method pointer (pointer to name)     */
277
278 asm_calljavafunction:
279
280         ldgp    gp,0(pv)
281         lda     sp,-32(sp)                /* allocate stack space                 */
282         stq     gp,24(sp)                 /* save global pointer                  */
283         stq     ra,0(sp)                  /* save return address                  */
284
285         stq     a0,16(sp)                 /* save method pointer for compiler     */
286         lda     v0,16(sp)                 /* pass pointer to method pointer via v0*/
287
288         mov     a1,a0                     /* pass the remaining parameters        */
289         mov     a2,a1
290         mov     a3,a2
291         mov     a4,a3
292
293         lda     $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
294         stq     $28,8(sp)                 /* store function address               */
295         mov     sp,$28                    /* set method pointer                   */
296
297         ldq     pv,8($28)                 /* method call as in Java               */
298         jmp     ra,(pv)                   /* call JIT compiler                    */
299 calljava_jit2:
300         lda     pv,-64(ra)                /* asm_calljavafunction-calljava_jit !!!!!*/
301
302 calljava_return2:
303
304         ldq     ra,0(sp)                  /* restore return address               */
305         ldq     gp,24(sp)                 /* restore global pointer               */
306         lda     sp,32(sp)                 /* free stack space                     */
307
308 calljava_ret2:
309         jmp     zero,(ra)
310
311 calljava_xhandler2:
312
313         ldq     gp,24(sp)                 /* restore global pointer               */
314         mov     itmp1,a0
315         jsr     ra,builtin_throw_exception
316         ldq     ra,0(sp)                  /* restore return address               */
317         lda     sp,32(sp)                 /* free stack space                     */
318         jmp     zero,(ra)
319         .end    asm_calljavafunction
320
321
322
323
324         .ent    asm_calljavafunction2
325         .ent    asm_calljavafunction2double
326         .ent    asm_calljavafunction2long
327
328 call_name3:
329         .ascii  "calljavafunction2\0\0"
330
331         .align  3
332         .quad   0                         /* catch type all                       */
333         .quad   calljava_xhandler3        /* handler pc                           */
334         .quad   calljava_xhandler3        /* end pc                               */
335         .quad   asm_calljavafunction2     /* start pc                             */
336         .long   1                         /* extable size                         */
337         .long   0                         /* fltsave                              */
338         .long   1                         /* intsave                              */
339         .long   0                         /* isleaf                               */
340         .long   0                         /* IsSync                               */
341         .long   40                        /* frame size                           */
342         .quad   0                         /* method pointer (pointer to name)     */
343
344 asm_calljavafunction2:
345
346         ldgp    gp,0(pv)
347         lda     sp,-40(sp)                /* allocate stack space                 */
348         stq     ra,0(sp)                  /* save return address                  */
349         stq     s6,24(sp)
350         stq     gp,8(sp)                  /* save global pointer                  */
351
352         stq     a0,32(sp)                 /* save method pointer for compiler     */
353         mov     a3,t0                     /* pointer to arg block                 */
354         mov     a1,s6                     /* arg count                            */
355
356         ble     s6,calljava_argsloaded
357         lda     s6,-1(s6)
358         ldq     a0,offjniitem(t0)
359         ldt     $f16,offjniitem(t0)
360         ble     s6,calljava_argsloaded
361         lda     s6,-1(s6)
362         ldq     a1,offjniitem+sizejniblock*1(t0)
363         ldt     $f17,offjniitem+sizejniblock*1(t0)
364         ble     s6,calljava_argsloaded
365         lda     s6,-1(s6)
366         ldq     a2,offjniitem+sizejniblock*2(t0)
367         ldt     $f18,offjniitem+sizejniblock*2(t0)
368         ble     s6,calljava_argsloaded
369         lda     s6,-1(s6)
370         ldq     a3,offjniitem+sizejniblock*3(t0)
371         ldt     $f19,offjniitem+sizejniblock*3(t0)
372         ble     s6,calljava_argsloaded
373         lda     s6,-1(s6)
374         ldq     a4,offjniitem+sizejniblock*4(t0)
375         ldt     $f20,offjniitem+sizejniblock*4(t0)
376         ble     s6,calljava_argsloaded
377         lda     s6,-1(s6)
378         ldq     a5,offjniitem+sizejniblock*5(t0)
379         ldt     $f21,offjniitem+sizejniblock*5(t0)
380 calljava_argsloaded:
381         mov     sp,t4
382         ble     s6,calljava_nocopy
383         negq    s6,t1
384         s8addq  t1,sp,sp
385         s8addq  t1,t4,t2
386
387 calljava_copyloop:
388         ldq     t3,offjniitem+sizejniblock*6(t0)
389         stq     t3,0(t2)
390         lda     t1,1(t1)
391         lda     t0,sizejniblock(t0)
392         lda     t2,8(t2)
393         bne     t1,calljava_copyloop
394
395 calljava_nocopy:
396         lda     v0,32(t4)                 /* pass pointer to method pointer via v0*/
397
398         lda     $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
399         stq     $28,16(t4)                /* store function address               */
400         lda     $28,8(t4)                 /* set method pointer                   */
401
402         ldq     pv,8($28)                 /* method call as in Java               */
403         jmp     ra,(pv)                   /* call JIT compiler                    */
404 calljava_jit3:
405         lda     pv,-200(ra)               /* asm_calljavafunction-calljava_jit !!!*/
406
407         s8addq  s6,sp,sp
408 calljava_return3:
409
410         ldq     ra,0(sp)                  /* restore return address               */
411         ldq     gp,8(sp)                  /* restore global pointer               */
412         ldq     s6,24(sp)
413         lda     sp,40(sp)                 /* free stack space                     */
414
415 calljava_ret3:
416         jmp     zero,(ra)
417
418 calljava_xhandler3:
419
420         s8addq  s6,sp,sp
421         ldq     gp,8(sp)                  /* restore global pointer               */
422         mov     itmp1,a0
423         jsr     ra,builtin_throw_exception
424         ldq     ra,0(sp)                  /* restore return address               */
425         ldq     s6,24(sp)
426         lda     sp,40(sp)                 /* free stack space                     */
427         jmp     zero,(ra)
428         .end    asm_calljavafunction2
429                                                 
430
431 /****************** function asm_call_jit_compiler *****************************
432 *                                                                              *
433 *   invokes the compiler for untranslated JavaVM methods.                      *
434 *                                                                              *
435 *   Register R0 contains a pointer to the method info structure (prepared      *
436 *   by createcompilerstub). Using the return address in R26 and the            *
437 *   offset in the LDA instruction or using the value in methodptr R28 the      *
438 *   patching address for storing the method address can be computed:           *
439 *                                                                              *
440 *   method address was either loaded using                                     *
441 *   M_LDQ (REG_PV, REG_PV, a)        ; invokestatic/special    ($27)           *
442 *   M_LDA (REG_PV, REG_RA, low)                                                *
443 *   M_LDAH(REG_PV, REG_RA, high)     ; optional                                *
444 *   or                                                                         *
445 *   M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28)           *
446 *   in the static case the method pointer can be computed using the            *
447 *   return address and the lda function following the jmp instruction          *
448 *                                                                              *
449 *******************************************************************************/
450
451
452         .ent    asm_call_jit_compiler
453 asm_call_jit_compiler:
454
455         ldgp    gp,0(pv)
456         ldl     t8,-8(ra)             /* load instruction LDQ PV,xxx($yy)         */
457         srl     t8,16,t8              /* shift right register number $yy          */
458         and     t8,31,t8              /* isolate register number                  */
459         subl    t8,28,t8              /* test for REG_METHODPTR                   */
460         beq     t8,noregchange       
461         ldl     t8,0(ra)              /* load instruction LDA PV,xxx(RA)          */
462         sll     t8,48,t8
463         sra     t8,48,t8              /* isolate offset                           */
464         addq    t8,ra,$28             /* compute update address                   */
465         ldl     t8,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
466         srl     t8,16,t8              /* isolate instruction code                 */
467         lda     t8,-0x177b(t8)        /* test for LDAH                            */
468         bne     t8,noregchange       
469         ldl     t8,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
470         sll     t8,16,t8              /* compute high offset                      */
471         addl    t8,0,t8               /* sign extend high offset                  */
472         addq    t8,$28,$28            /* compute update address                   */
473 noregchange:
474         lda     sp,-14*8(sp)          /* reserve stack space                      */
475         stq     a0,0*8(sp)            /* save all argument registers              */
476         stq     a1,1*8(sp)            /* they could be used by method             */
477         stq     a2,2*8(sp)
478         stq     a3,3*8(sp)
479         stq     a4,4*8(sp)
480         stq     a5,5*8(sp)
481         stt     $f16,6*8(sp)
482         stt     $f17,7*8(sp)
483         stt     $f18,8*8(sp)
484         stt     $f19,9*8(sp)
485         stt     $f20,10*8(sp)
486         stt     $f21,11*8(sp)
487         stq     $28,12*8(sp)          /* save method pointer                      */
488         stq     ra,13*8(sp)           /* save return address                      */
489
490         ldq     a0,0(v0)              /* pass 'methodinfo' pointer to             */
491         jsr     ra,jit_compile        /* jit compiler                             */
492         ldgp    gp,0(ra)
493
494         call_pal PAL_imb              /* synchronise instruction cache            */
495
496         ldq     a0,0*8(sp)            /* load argument registers                  */
497         ldq     a1,1*8(sp)
498         ldq     a2,2*8(sp)
499         ldq     a3,3*8(sp)
500         ldq     a4,4*8(sp)
501         ldq     a5,5*8(sp)
502         ldt     $f16,6*8(sp)
503         ldt     $f17,7*8(sp)
504         ldt     $f18,8*8(sp)
505         ldt     $f19,9*8(sp)
506         ldt     $f20,10*8(sp)
507         ldt     $f21,11*8(sp)
508         ldq     $28,12*8(sp)          /* load method pointer                      */
509         ldq     ra,13*8(sp)           /* load return address                      */
510         lda     sp,14*8(sp)           /* deallocate stack area                    */
511
512         ldl     t8,-8(ra)             /* load instruction LDQ PV,xxx($yy)         */
513         sll     t8,48,t8
514         sra     t8,48,t8              /* isolate offset                           */
515
516         addq    t8,$28,t8             /* compute update address via method pointer*/
517         stq     v0,0(t8)              /* save new method address there            */
518
519         mov     v0,pv                 /* load method address into pv              */
520
521         jmp     zero,(pv)             /* and call method. The method returns      */
522                                       /* directly to the caller (ra).             */
523
524         .end    asm_call_jit_compiler
525
526
527 /****************** function asm_dumpregistersandcall **************************
528 *                                                                              *
529 *   This funtion saves all callee saved registers and calls the function       *
530 *   which is passed as parameter.                                              *
531 *                                                                              *
532 *   This function is needed by the garbage collector, which needs to access    *
533 *   all registers which are stored on the stack. Unused registers are          *
534 *   cleared to avoid interferances with the GC.                                *
535 *                                                                              *
536 *   void asm_dumpregistersandcall (functionptr f);                             *
537 *                                                                              *
538 *******************************************************************************/
539
540         .ent    asm_dumpregistersandcall
541 asm_dumpregistersandcall:
542         lda     sp,-16*8(sp)          /* allocate stack                           */
543         stq     ra,0(sp)              /* save return address                      */
544
545         stq     s0,1*8(sp)            /* save all callee saved registers          */
546         stq     s1,2*8(sp)            /* intialize the remaining registers        */
547         stq     s2,3*8(sp)
548         stq     s3,4*8(sp)
549         stq     s4,5*8(sp)
550         stq     s5,6*8(sp)
551         stq     s6,7*8(sp)
552         stt     $f2,8*8(sp)
553         stt     $f3,9*8(sp)
554         stt     $f4,10*8(sp)
555         stt     $f5,11*8(sp)
556         stt     $f6,12*8(sp)
557         stt     $f7,13*8(sp)
558         stt     $f8,14*8(sp)
559         stt     $f9,15*8(sp)
560
561         clr     v0                   /* intialize the remaining registers         */
562         clr     t0
563         clr     t1
564         clr     t2
565         clr     t3
566         clr     t4
567         clr     t5
568         clr     t6
569         clr     t7
570         clr     a1
571         clr     a2
572         clr     a3
573         clr     a4
574         clr     a5
575         clr     t8
576         clr     t9
577         clr     t10
578         clr     t11
579         clr     t12
580         clr     $28
581         clr     $29
582         cpys    $f31,$f31,$f0
583         cpys    $f31,$f31,$f1
584         cpys    $f31,$f31,$f10
585         cpys    $f31,$f31,$f11
586         cpys    $f31,$f31,$f12
587         cpys    $f31,$f31,$f13
588         cpys    $f31,$f31,$f14
589         cpys    $f31,$f31,$f15
590         cpys    $f31,$f31,$f16
591         cpys    $f31,$f31,$f17
592         cpys    $f31,$f31,$f18
593         cpys    $f31,$f31,$f19
594         cpys    $f31,$f31,$f20
595         cpys    $f31,$f31,$f21
596         cpys    $f31,$f31,$f22
597         cpys    $f31,$f31,$f23
598         cpys    $f31,$f31,$f24
599         cpys    $f31,$f31,$f25
600         cpys    $f31,$f31,$f26
601         cpys    $f31,$f31,$f27
602         cpys    $f31,$f31,$f28
603         cpys    $f31,$f31,$f29
604         cpys    $f31,$f31,$f30
605
606         mov     a0,pv                 /* load function pointer                    */
607         jmp     ra,(pv)               /* and call function                        */
608
609         ldq     ra,0(sp)              /* load return address                      */
610         lda     sp,16*8(sp)           /* deallocate stack                         */
611         jmp     zero,(ra)             /* return                                   */
612
613         .end    asm_dumpregistersandcall
614
615
616 /********************* function asm_handle_exception ***************************
617 *                                                                              *
618 *   This function handles an exception. It does not use the usual calling      *
619 *   conventions. The exception pointer is passed in REG_ITMP1 and the          *
620 *   pc from the exception raising position is passed in REG_ITMP2. It searches *
621 *   the local exception table for a handler. If no one is found, it unwinds    *
622 *   stacks and continues searching the callers.                                *
623 *                                                                              *
624 *   void asm_handle_exception (exceptionptr, exceptionpc);                     *
625 *                                                                              *
626 *******************************************************************************/
627
628         .ent    asm_handle_nat_exception
629 asm_handle_nat_exception:
630
631         ldl     t0,0(ra)              /* load instruction LDA PV,xxx(RA)          */
632         sll     t0,48,t0
633         sra     t0,48,t0              /* isolate offset                           */
634         addq    t0,ra,pv              /* compute update address                   */
635         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
636         srl     t0,16,t0              /* isolate instruction code                 */
637         lda     t0,-0x177b(t0)        /* test for LDAH                            */
638         bne     t0,asm_handle_exception       
639         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
640         sll     t0,16,t0              /* compute high offset                      */
641         addl    t0,0,t0               /* sign extend high offset                  */
642         addq    t0,pv,pv              /* compute update address                   */
643
644         .aent    asm_handle_exception
645 asm_handle_exception:
646
647         lda     sp,-18*8(sp)          /* allocate stack                           */
648         stq     t0,0*8(sp)            /* save possible used registers             */
649         stq     t1,1*8(sp)            /* also registers used by trace_exception   */
650         stq     t2,2*8(sp)
651         stq     t3,3*8(sp)
652         stq     t4,4*8(sp)
653         stq     t5,5*8(sp)
654         stq     t6,6*8(sp)
655         stq     t7,7*8(sp)
656         stq     t8,8*8(sp)
657         stq     t9,9*8(sp)
658         stq     t10,10*8(sp)
659         stq     v0,11*8(sp)
660         stq     a0,12*8(sp)
661         stq     a1,13*8(sp)
662         stq     a2,14*8(sp)
663         stq     a3,15*8(sp)
664         stq     a4,16*8(sp)
665         stq     a5,17*8(sp)
666
667         lda     t3,1(zero)            /* set no unwind flag                       */
668 ex_stack_loop:
669         lda     sp,-5*8(sp)           /* allocate stack                           */
670         stq     xptr,0*8(sp)          /* save used register                       */
671         stq     xpc,1*8(sp)
672         stq     pv,2*8(sp)
673         stq     ra,3*8(sp)
674         stq     t3,4*8(sp)
675
676         mov     xptr,a0
677         ldq     a1,MethodPointer(pv)
678         mov     xpc,a2
679         mov     t3,a3
680         br      ra,ex_trace           /* set ra for gp loading                    */
681 ex_trace:
682         ldgp    gp,0(ra)              /* load gp                                  */
683         jsr     ra,builtin_trace_exception /* trace_exception(xptr,methodptr)     */
684         
685         ldq     xptr,0*8(sp)          /* restore used register                    */
686         ldq     xpc,1*8(sp)
687         ldq     pv,2*8(sp)
688         ldq     ra,3*8(sp)
689         ldq     t3,4*8(sp)
690         lda     sp,5*8(sp)            /* deallocate stack                         */
691         
692         ldl     t0,ExTableSize(pv)    /* t0 = exception table size                */
693         beq     t0,empty_table        /* if empty table skip                      */
694         lda     t1,ExTableStart(pv)   /* t1 = start of exception table            */
695
696 ex_table_loop:
697         ldq     t2,ExStartPC(t1)      /* t2 = exception start pc                  */
698         cmple   t2,xpc,t2             /* t2 = (startpc <= xpc)                    */
699         beq     t2,ex_table_cont      /* if (false) continue                      */
700         ldq     t2,ExEndPC(t1)        /* t2 = exception end pc                    */
701         cmplt   xpc,t2,t2             /* t2 = (xpc < endpc)                       */
702         beq     t2,ex_table_cont      /* if (false) continue                      */
703         ldq     a1,ExCatchType(t1)    /* arg1 = exception catch type              */
704         beq     a1,ex_handle_it       /* NULL catches everything                  */
705
706         ldq     a0,offobjvftbl(xptr)  /* a0 = vftblptr(xptr)                      */
707         ldq     a1,offclassvftbl(a1)    /* a1 = vftblptr(catchtype) class (not obj) */
708         ldl     a0,offbaseval(a0)     /* a0 = baseval(xptr)                       */
709         ldl     v0,offbaseval(a1)     /* a2 = baseval(catchtype)                  */
710         ldl     a1,offdiffval(a1)     /* a1 = diffval(catchtype)                  */
711         subl    a0,v0,a0              /* a0 = baseval(xptr) - baseval(catchtype)  */
712         cmpule  a0,a1,v0              /* v0 = xptr is instanceof catchtype        */
713         beq     v0,ex_table_cont      /* if (false) continue                      */
714
715 ex_handle_it:
716
717         ldq     xpc,ExHandlerPC(t1)   /* xpc = exception handler pc               */
718
719         beq     t3,ex_jump            /* if (!(no stack unwinding) skip           */
720
721         ldq     t0,0*8(sp)            /* restore possible used registers          */
722         ldq     t1,1*8(sp)            /* also registers used by trace_exception   */
723         ldq     t2,2*8(sp)
724         ldq     t3,3*8(sp)
725         ldq     t4,4*8(sp)
726         ldq     t5,5*8(sp)
727         ldq     t6,6*8(sp)
728         ldq     t7,7*8(sp)
729         ldq     t8,8*8(sp)
730         ldq     t9,9*8(sp)
731         ldq     t10,10*8(sp)
732         ldq     v0,11*8(sp)
733         ldq     a0,12*8(sp)
734         ldq     a1,13*8(sp)
735         ldq     a2,14*8(sp)
736         ldq     a3,15*8(sp)
737         ldq     a4,16*8(sp)
738         ldq     a5,17*8(sp)
739         lda     sp,18*8(sp)           /* deallocate stack                         */
740
741 ex_jump:
742         jmp     zero,(xpc)            /* jump to the handler                      */
743
744 ex_table_cont:
745         lda     t1,ExEntrySize(t1)    /* next exception table entry               */
746         subl    t0,1,t0               /* decrement entry counter                  */
747         bgt     t0,ex_table_loop      /* if (t0 > 0) next entry                   */
748
749 empty_table:
750         beq     t3,ex_already_cleared /* if here the first time, then             */
751         lda     sp,18*8(sp)           /* deallocate stack and                     */
752         clr     t3                    /* clear the no unwind flag                 */
753 ex_already_cleared:
754         ldl     t0,IsSync(pv)         /* t0 = SyncOffset                          */
755         beq     t0,no_monitor_exit    /* if zero no monitorexit                   */
756         addq    sp,t0,t0              /* add stackptr to Offset                   */
757         ldq     a0,-8(t0)             /* load monitorexit pointer                 */
758
759         lda     sp,-7*8(sp)           /* allocate stack                           */
760         stq     t0,0*8(sp)            /* save used register                       */
761         stq     t1,1*8(sp)
762         stq     t3,2*8(sp)
763         stq     xptr,3*8(sp)
764         stq     xpc,4*8(sp)
765         stq     pv,5*8(sp)
766         stq     ra,6*8(sp)
767
768         br      ra,ex_mon_load        /* set ra for gp loading                    */
769 ex_mon_load:
770         ldgp    gp,0(ra)              /* load gp                                  */
771         jsr     ra,builtin_monitorexit/* builtin_monitorexit(objectptr)           */
772         
773         ldq     t0,0*8(sp)            /* restore used register                    */
774         ldq     t1,1*8(sp)
775         ldq     t3,2*8(sp)
776         ldq     xptr,3*8(sp)
777         ldq     xpc,4*8(sp)
778         ldq     pv,5*8(sp)
779         ldq     ra,6*8(sp)
780         lda     sp,7*8(sp)            /* deallocate stack                         */
781
782 no_monitor_exit:
783         ldl     t0,FrameSize(pv)      /* t0 = frame size                          */
784         addq    sp,t0,sp              /* unwind stack                             */
785         mov     sp,t0                 /* t0 = pointer to save area                */
786         ldl     t1,IsLeaf(pv)         /* t1 = is leaf procedure                   */
787         bne     t1,ex_no_restore      /* if (leaf) skip                           */
788         ldq     ra,-8(t0)             /* restore ra                               */
789         lda     t0,-8(t0)             /* t0--                                     */
790 ex_no_restore:
791         mov     ra,xpc                /* the new xpc is ra                        */
792         ldl     t1,IntSave(pv)        /* t1 = saved int register count            */
793         br      t2,ex_int1            /* t2 = current pc                          */
794 ex_int1:
795         lda     t2,44(t2)             /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
796         negl    t1,t1                 /* negate register count                    */
797         s4addq  t1,t2,t2              /* t2 = ex_int_sav - 4 * register count     */
798         jmp     zero,(t2)             /* jump to save position                    */
799         ldq     s0,-56(t0)
800         ldq     s1,-48(t0)
801         ldq     s2,-40(t0)
802         ldq     s3,-32(t0)
803         ldq     s4,-24(t0)
804         ldq     s5,-16(t0)
805         ldq     s6,-8(t0)
806 ex_int2:
807         s8addq  t1,t0,t0              /* t0 = t0 - 8 * register count             */
808
809         ldl     t1,FltSave(pv)        /* t1 = saved flt register count            */
810         br      t2,ex_flt1            /* t2 = current pc                          */
811 ex_flt1:
812         lda     t2,48(t2)             /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
813         negl    t1,t1                 /* negate register count                    */
814         s4addq  t1,t2,t2              /* t2 = ex_flt_sav - 4 * register count     */
815         jmp     zero,(t2)             /* jump to save position                    */
816         ldt     $f2,-64(t0)
817         ldt     $f3,-56(t0)
818         ldt     $f4,-48(t0)
819         ldt     $f5,-40(t0)
820         ldt     $f6,-32(t0)
821         ldt     $f7,-24(t0)
822         ldt     $f8,-16(t0)
823         ldt     $f9,-8(t0)
824 ex_flt2:
825         ldl     t0,0(ra)              /* load instruction LDA PV,xxx(RA)          */
826         sll     t0,48,t0
827         sra     t0,48,t0              /* isolate offset                           */
828         addq    t0,ra,pv              /* compute update address                   */
829         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
830         srl     t0,16,t0              /* isolate instruction code                 */
831         lda     t0,-0x177b(t0)        /* test for LDAH                            */
832         bne     t0,ex_stack_loop       
833         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(RA)         */
834         sll     t0,16,t0              /* compute high offset                      */
835         addl    t0,0,t0               /* sign extend high offset                  */
836         addq    t0,pv,pv              /* compute update address                   */
837         br      ex_stack_loop
838
839         .end    asm_handle_nat_exception
840
841
842 /********************* function asm_builtin_monitorenter ***********************
843 *                                                                              *
844 *   Does null check and calls monitorenter or throws an exception              *
845 *                                                                              *
846 *******************************************************************************/
847
848         .ent    asm_builtin_monitorenter
849 asm_builtin_monitorenter:
850
851         ldgp    gp,0(pv)
852         lda     pv,builtin_monitorenter
853         beq     a0,nb_monitorenter        /* if (null) throw exception            */
854         jmp     zero,(pv)                 /* else call builtin_monitorenter       */
855
856 nb_monitorenter:
857         ldq     xptr,proto_java_lang_NullPointerException
858         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
859         br      asm_handle_nat_exception
860         .end    asm_builtin_monitorenter
861
862
863 /********************* function asm_builtin_monitorexit ************************
864 *                                                                              *
865 *   Does null check and calls monitorexit or throws an exception               *
866 *                                                                              *
867 *******************************************************************************/
868
869         .ent    asm_builtin_monitorexit
870 asm_builtin_monitorexit:
871
872         ldgp    gp,0(pv)
873         lda     pv,builtin_monitorexit
874         beq     a0,nb_monitorexit         /* if (null) throw exception            */
875         jmp     zero,(pv)                 /* else call builtin_monitorexit        */
876
877 nb_monitorexit:
878         ldq     xptr,proto_java_lang_NullPointerException
879         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
880         br      asm_handle_nat_exception
881         .end    asm_builtin_monitorexit
882
883
884 /************************ function asm_builtin_idiv ****************************
885 *                                                                              *
886 *   Does null check and calls idiv or throws an exception                      *
887 *                                                                              *
888 *******************************************************************************/
889
890         .ent    asm_builtin_idiv
891 asm_builtin_idiv:
892
893         ldgp    gp,0(pv)
894         lda     pv,builtin_idiv
895         beq     a1,nb_idiv                /* if (null) throw exception            */
896         jmp     zero,(pv)                 /* else call builtin_idiv               */
897
898 nb_idiv:
899         ldq     xptr,proto_java_lang_ArithmeticException
900         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
901         br      asm_handle_nat_exception
902         .end    asm_builtin_idiv
903
904
905 /************************ function asm_builtin_ldiv ****************************
906 *                                                                              *
907 *   Does null check and calls ldiv or throws an exception                      *
908 *                                                                              *
909 *******************************************************************************/
910
911         .ent    asm_builtin_ldiv
912 asm_builtin_ldiv:
913
914         ldgp    gp,0(pv)
915         lda     pv,builtin_ldiv
916         beq     a1,nb_ldiv                /* if (null) throw exception            */
917         jmp     zero,(pv)                 /* else call builtin_ldiv               */
918
919 nb_ldiv:
920         ldq     xptr,proto_java_lang_ArithmeticException
921         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
922         br      asm_handle_nat_exception
923         .end    asm_builtin_ldiv
924
925
926 /************************ function asm_builtin_irem ****************************
927 *                                                                              *
928 *   Does null check and calls irem or throws an exception                      *
929 *                                                                              *
930 *******************************************************************************/
931
932         .ent    asm_builtin_irem
933 asm_builtin_irem:
934
935         ldgp    gp,0(pv)
936         lda     pv,builtin_irem
937         beq     a1,nb_irem                /* if (null) throw exception            */
938         jmp     zero,(pv)                 /* else call builtin_irem               */
939
940 nb_irem:
941         ldq     xptr,proto_java_lang_ArithmeticException
942         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
943         br      asm_handle_nat_exception
944         .end    asm_builtin_irem
945
946
947 /************************ function asm_builtin_lrem ****************************
948 *                                                                              *
949 *   Does null check and calls lrem or throws an exception                      *
950 *                                                                              *
951 *******************************************************************************/
952
953         .ent    asm_builtin_lrem
954 asm_builtin_lrem:
955
956         ldgp    gp,0(pv)
957         lda     pv,builtin_lrem
958         beq     a1,nb_lrem                /* if (null) throw exception            */
959         jmp     zero,(pv)                 /* else call builtin_lrem               */
960
961 nb_lrem:
962         ldq     xptr,proto_java_lang_ArithmeticException
963         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
964         br      asm_handle_nat_exception
965         .end    asm_builtin_lrem
966
967
968  /*********************** function new_builtin_checkcast ************************
969  *                                                                              *
970  *   Does the cast check and eventually throws an exception                     *
971  *                                                                              *
972  *******************************************************************************/
973
974     .ent    asm_builtin_checkcast
975 asm_builtin_checkcast:
976
977     ldgp    gp,0(pv)
978     lda     sp,-16(sp)                  # allocate stack space
979     stq     ra,0(sp)                    # save return address
980     stq     a0,8(sp)                    # save object pointer
981     jsr     ra,builtin_checkcast        # builtin_checkcast
982     ldgp    gp,0(ra)
983     beq     v0,nb_ccast_throw           # if (false) throw exception
984     ldq     ra,0(sp)                    # restore return address
985     ldq     v0,8(sp)                    # return object pointer
986     lda     sp,16(sp)                   # free stack space
987     jmp     zero,(ra)
988
989 nb_ccast_throw:
990     ldq     xptr,proto_java_lang_ClassCastException
991     ldq     ra,0(sp)                    # restore return address
992     lda     sp,16(sp)                   # free stack space
993     lda     xpc,-4(ra)                  # faulting address is return adress - 4
994     br      asm_handle_nat_exception
995     .end    asm_builtin_checkcast
996
997                 
998 /******************* function asm_builtin_checkarraycast ***********************
999 *                                                                              *
1000 *   Does the cast check and eventually throws an exception                     *
1001 *                                                                              *
1002 *******************************************************************************/
1003
1004         .ent    asm_builtin_checkarraycast
1005 asm_builtin_checkarraycast:
1006
1007         ldgp    gp,0(pv)
1008         lda     sp,-16(sp)                /* allocate stack space                 */
1009         stq     ra,0(sp)                  /* save return address                  */
1010         stq     a0,8(sp)                  /* save object pointer                  */
1011         jsr     ra,builtin_checkarraycast /* builtin_checkarraycast               */
1012         ldgp    gp,0(ra)
1013         beq     v0,nb_carray_throw        /* if (false) throw exception           */
1014         ldq     ra,0(sp)                  /* restore return address               */
1015         ldq     v0,8(sp)                  /* return object pointer                */
1016         lda     sp,16(sp)                 /* free stack space                     */
1017         jmp     zero,(ra)
1018
1019 nb_carray_throw:
1020         ldq     xptr,proto_java_lang_ClassCastException
1021         ldq     ra,0(sp)                  /* restore return address               */
1022         lda     sp,16(sp)                 /* free stack space                     */
1023         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
1024         br      asm_handle_nat_exception
1025         .end    asm_builtin_checkarraycast
1026
1027
1028 /******************* function asm_builtin_aastore ******************************
1029 *                                                                              *
1030 *   Does the cast check and eventually throws an exception                     *
1031 *                                                                              *
1032 *******************************************************************************/
1033
1034         .ent    asm_builtin_aastore
1035 asm_builtin_aastore:
1036
1037         ldgp    gp,0(pv)
1038         beq     a0,nb_aastore_null        /* if null pointer throw exception      */
1039         ldl     t0,offarraysize(a0)       /* load size                            */
1040         lda     sp,-24(sp)                /* allocate stack space                 */
1041         stq     ra,0(sp)                  /* save return address                  */
1042         s8addq  a1,a0,t1                  /* add index*8 to arrayref              */
1043         cmpult  a1,t0,t0                  /* do bound check                       */
1044         beq     t0,nb_aastore_bound       /* if out of bounds throw exception     */
1045         mov     a2,a1                     /* object is second argument            */
1046         stq     t1,8(sp)                  /* save store position                  */
1047         stq     a1,16(sp)                 /* save object                          */
1048         jsr     ra,builtin_canstore       /* builtin_canstore(arrayref,object)    */
1049         ldgp    gp,0(ra)
1050         ldq     ra,0(sp)                  /* restore return address               */
1051         ldq     a0,8(sp)                  /* restore store position               */
1052         ldq     a1,16(sp)                 /* restore object                       */
1053         lda     sp,24(sp)                 /* free stack space                     */
1054         beq     v0,nb_aastore_throw       /* if (false) throw exception           */
1055         stq     a1,offobjarrdata(a0)      /* store objectptr in array             */
1056         jmp     zero,(ra)
1057
1058 nb_aastore_null:
1059         ldq     xptr,proto_java_lang_NullPointerException
1060         mov     ra,xpc                    /* faulting address is return adress    */
1061         br      asm_handle_nat_exception
1062
1063 nb_aastore_bound:
1064         ldq     xptr,proto_java_lang_ArrayIndexOutOfBoundsException
1065         lda     sp,24(sp)                 /* free stack space                     */
1066         mov     ra,xpc                    /* faulting address is return adress    */
1067         br      asm_handle_nat_exception
1068
1069 nb_aastore_throw:
1070         ldq     xptr,proto_java_lang_ArrayStoreException
1071         mov     ra,xpc                    /* faulting address is return adress    */
1072         br      asm_handle_nat_exception
1073
1074         .end    asm_builtin_aastore
1075
1076
1077 /******************* function asm_initialize_thread_stack **********************
1078 *                                                                              *
1079 *   initialized a thread stack                                                 *
1080 *                                                                              *
1081 *******************************************************************************/
1082
1083         .ent    asm_initialize_thread_stack
1084 asm_initialize_thread_stack:
1085
1086         lda     a1,-128(a1)
1087         stq     zero, 0(a1)
1088         stq     zero, 8(a1)
1089         stq     zero, 16(a1)
1090         stq     zero, 24(a1)
1091         stq     zero, 32(a1)
1092         stq     zero, 40(a1)
1093         stq     zero, 48(a1)
1094         stt     fzero, 56(a1)
1095         stt     fzero, 64(a1)
1096         stt     fzero, 72(a1)
1097         stt     fzero, 80(a1)
1098         stt     fzero, 88(a1)
1099         stt     fzero, 96(a1)
1100         stt     fzero, 104(a1)
1101         stt     fzero, 112(a1)
1102         stq     a0, 120(a1)
1103         mov     a1, v0
1104         jmp     zero,(ra)
1105         .end    asm_initialize_thread_stack
1106
1107
1108 /******************* function asm_perform_threadswitch *************************
1109 *                                                                              *
1110 *   void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop);         *
1111 *                                                                              *
1112 *   performs a threadswitch                                                    *
1113 *                                                                              *
1114 *******************************************************************************/
1115
1116         .ent    asm_perform_threadswitch
1117 asm_perform_threadswitch:
1118
1119         subq    sp,128,sp
1120         stq     s0, 0(sp)
1121         stq     s1, 8(sp)
1122         stq     s2, 16(sp)
1123         stq     s3, 24(sp)
1124         stq     s4, 32(sp)
1125         stq     s5, 40(sp)
1126         stq     s6, 48(sp)
1127         stt     sf0, 56(sp)
1128         stt     sf1, 64(sp)
1129         stt     sf2, 72(sp)
1130         stt     sf3, 80(sp)
1131         stt     sf4, 88(sp)
1132         stt     sf5, 96(sp)
1133         stt     sf6, 104(sp)
1134         stt     sf7, 112(sp)
1135         stq     ra, 120(sp)
1136         stq     sp, 0(a0)
1137         stq     sp, 0(a2)
1138         ldq     sp, 0(a1)
1139         ldq     s0, 0(sp)
1140         ldq     s1, 8(sp)
1141         ldq     s2, 16(sp)
1142         ldq     s3, 24(sp)
1143         ldq     s4, 32(sp)
1144         ldq     s5, 40(sp)
1145         ldq     s6, 48(sp)
1146         ldt     sf0, 56(sp)
1147         ldt     sf1, 64(sp)
1148         ldt     sf2, 72(sp)
1149         ldt     sf3, 80(sp)
1150         ldt     sf4, 88(sp)
1151         ldt     sf5, 96(sp)
1152         ldt     sf6, 104(sp)
1153         ldt     sf7, 112(sp)
1154         ldq     ra, 120(sp)
1155         mov     ra, pv
1156         addq    sp, 128, sp
1157         jmp     zero,(ra)
1158         .end    asm_perform_threadswitch
1159
1160
1161 /********************* function asm_switchstackandcall *************************
1162 *                                                                              *
1163 *  void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1164 *                               void *p);                                      *
1165 *                                                                              *
1166 *   Switches to a new stack, calls a function and switches back.               *
1167 *       a0      new stack pointer                                              *
1168 *       a1      function pointer                                               *
1169 *               a2              pointer to variable where stack top should be stored           *
1170 *               a3      pointer to user data, is passed to the function                *
1171 *                                                                              *
1172 *******************************************************************************/
1173
1174
1175         .ent    asm_switchstackandcall
1176 asm_switchstackandcall:
1177         lda     a0,-2*8(a0)     /* allocate new stack                                 */
1178         stq     ra,0(a0)        /* save return address on new stack                   */
1179         stq     sp,1*8(a0)      /* save old stack pointer on new stack                */
1180         stq sp,0(a2)        /* save old stack pointer to variable                 */
1181         mov     a0,sp           /* switch to new stack                                */
1182         
1183         mov     a1,pv           /* load function pointer                              */
1184         mov a3,a0           /* pass pointer */
1185         jmp     ra,(pv)         /* and call function                                  */
1186
1187         ldq     ra,0(sp)        /* load return address                                */
1188         ldq     sp,1*8(sp)      /* switch to old stack                                */
1189
1190         jmp     zero,(ra)       /* return                                             */
1191
1192         .end    asm_switchstackandcall
1193
1194                 
1195 /********************* function asm_getcallingmethod ***************************
1196 *                                                                              *
1197 *   classinfo *asm_getcallingmethodclass ();                                                               *
1198 *                                                                                                                                                          *    
1199 *   goes back stack frames to get the calling method                                               *       
1200 *                                                                                                                                                          *    
1201 *                               t2 .. sp                                                                                                       *
1202 *                               t3 .. ra                                                                                                       *
1203 *                               t4 .. pv                                                                                                       *
1204 *                                                                              *
1205 *******************************************************************************/
1206
1207
1208         .ent    asm_getcallingmethod
1209 asm_getcallingmethod:
1210
1211         ldq             t3,16(sp)             /* load return address of native function   */                            
1212         addq    sp,24,t2                          /* skip frames of C-Function and nativestub */        
1213                 
1214     /* determine pv (t3) of java-function from ra */
1215
1216         ldl     t0,0(t3)              /* load instruction LDA PV,xxx(RA)          */
1217         sll     t0,48,t0
1218         sra     t0,48,t0              /* isolate offset                           */
1219         addq    t0,t3,t4              /* compute update address                   */
1220         ldl     t0,4(t3)              /* load instruction LDAH PV,xxx(PV)         */
1221         srl     t0,16,t0              /* isolate instruction code                 */
1222         lda     t0,-0x177b(t0)        /* test for LDAH                            */
1223         bne     t0,pv_ok1       
1224         ldl     t0,0(t3)              /* load instruction LDA PV,xxx(RA)          */
1225         sll     t0,16,t0              /* compute high offset                      */
1226         addl    t0,0,t0               /* sign extend high offset                  */
1227         addq    t0,t4,t4              /* compute update address                   */
1228
1229 pv_ok1:                 
1230         ldl     t0,FrameSize(t4)      /* t0 = frame size                          */            
1231         addq    t2,t0,t2                          /* skip frame of java function                          */
1232         ldq             t3,-8(t2)                         /* load new ra                              */                                                                
1233
1234     /* determine pv (t3) of java-function from ra */
1235
1236         ldl     t0,0(t3)              /* load instruction LDA PV,xxx(RA)          */
1237         sll     t0,48,t0
1238         sra     t0,48,t0              /* isolate offset                           */
1239         addq    t0,t3,t4              /* compute update address                   */
1240         ldl     t0,4(t3)              /* load instruction LDAH PV,xxx(PV)         */
1241         srl     t0,16,t0              /* isolate instruction code                 */
1242         lda     t0,-0x177b(t0)        /* test for LDAH                            */
1243         bne     t0,pv_ok2
1244         ldl     t0,0(t3)              /* load instruction LDA PV,xxx(RA)          */
1245         sll     t0,16,t0              /* compute high offset                      */
1246         addl    t0,0,t0               /* sign extend high offset                  */
1247         addq    t0,t4,t4              /* compute update address                   */
1248
1249 pv_ok2:         
1250         ldq     v0,MethodPointer(t4)  /*                                                                                  */
1251
1252                                                                                 
1253         jmp     zero,(ra)                                 /* return                                   */
1254
1255         .end    asm_getcallingmethod
1256
1257
1258
1259
1260
1261
1262
1263
1264 /*********************** function asm_builtin_trace ****************************
1265 *                                                                              *
1266 *   Intended to be called from the native stub. Saves all argument registers   *
1267 *   and calls builtin_trace_args.                                              *
1268 *                                                                              *
1269 *******************************************************************************/
1270
1271         .ent asm_builtin_trace
1272 asm_builtin_trace:
1273         ldgp gp,0(pv)
1274         lda sp,-112(sp)
1275         stq itmp1,0(sp)
1276         stq ra,8(sp)
1277         stq a0,16(sp)
1278         stq a1,24(sp)
1279         stq a2,32(sp)
1280         stq a3,40(sp)
1281         stq a4,48(sp)
1282         stq a5,56(sp)
1283         stt $f16,64(sp)
1284         stt $f17,72(sp)
1285         stt $f18,80(sp)
1286         stt $f19,88(sp)
1287         stt $f20,96(sp)
1288         stt $f21,104(sp)
1289         
1290         jsr ra,builtin_trace_args
1291         
1292         ldq ra,8(sp)
1293         ldq a0,16(sp)
1294         ldq a1,24(sp)
1295         ldq a2,32(sp)
1296         ldq a3,40(sp)
1297         ldq a4,48(sp)
1298         ldq a5,56(sp)
1299         ldt $f16,64(sp)
1300         ldt $f17,72(sp)
1301         ldt $f18,80(sp)
1302         ldt $f19,88(sp)
1303         ldt $f20,96(sp)
1304         ldt $f21,104(sp)
1305         lda sp,112(sp)
1306         jmp zero,(ra)
1307
1308         .end asm_builtin_trace
1309
1310
1311 /********************* function asm_builtin_exittrace **************************
1312 *                                                                              *
1313 *   Intended to be called from the native stub. Saves return value and calls   *
1314 *   builtin_displaymethodstop.                                                 *
1315 *                                                                              *
1316 *******************************************************************************/
1317
1318         .ent asm_builtin_exittrace
1319 asm_builtin_exittrace:
1320         ldgp gp,0(pv)
1321         lda sp,-24(sp)
1322         stq ra,0(sp)
1323         stq v0,8(sp)
1324         stt $f0,16(sp)
1325         
1326         jsr ra,builtin_displaymethodstop
1327         
1328         ldq ra,0(sp)
1329         ldq v0,8(sp)
1330         ldt $f0,16(sp)
1331         lda sp,24(sp)
1332         jmp zero,(ra)
1333
1334         .end asm_builtin_exittrace