Removed deprecated .globl defines: asm_builtin_checkcast, asm_builtin_trace, asm_buil...
[cacao.git] / src / vm / jit / alpha / asmpart.S
1 /* vm/jit/alpha/asmpart.S - Java-C interface functions for alpha
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; 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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Andreas Krall
28             Reinhard Grafl
29
30    Changes: Joseph Wenninger
31
32    $Id: asmpart.S 2142 2005-03-30 12:53:56Z twisti $
33
34 */
35
36
37 #include "config.h"        
38 #include "vm/jit/alpha/offsets.h"
39 #include "vm/jit/alpha/asmoffsets.h"
40
41
42 #define v0      $0
43
44 #define t0      $1
45 #define t1      $2
46 #define t2      $3
47 #define t3      $4
48 #define t4      $5
49 #define t5      $6
50 #define t6      $7
51 #define t7      $8
52
53 #define s0      $9
54 #define s1      $10
55 #define s2      $11
56 #define s3      $12
57 #define s4      $13
58 #define s5      $14
59 #define s6      $15
60
61 #define a0      $16
62 #define a1      $17
63 #define a2      $18
64 #define a3      $19
65 #define a4      $20
66 #define a5      $21
67
68 #define t8      $22
69 #define t9      $23
70 #define t10     $24
71 #define t11     $25
72 #define ra      $26
73 #define t12     $27
74
75 #define pv      t12
76 #define AT      $at
77 #define gp      $29
78 #define sp      $30
79 #define zero    $31
80
81 #define itmp1   $25
82 #define itmp2   $28
83 #define itmp3   $29
84
85 #define xptr    itmp1
86 #define xpc     itmp2
87
88 #define sf0     $f2
89 #define sf1     $f3
90 #define sf2     $f4
91 #define sf3     $f5
92 #define sf4     $f6
93 #define sf5     $f7
94 #define sf6     $f8
95 #define sf7     $f9
96
97 #define fzero   $f31
98
99
100 #define PAL_imb 0x86
101
102         .text
103         .set    noat
104         .set    noreorder
105
106
107 /********************* exported functions and variables ***********************/
108
109         .globl has_no_x_instr_set
110
111         .globl asm_calljavafunction
112
113         .globl asm_calljavafunction2
114         .globl asm_calljavafunction2int
115         .globl asm_calljavafunction2long
116         .globl asm_calljavafunction2float
117         .globl asm_calljavafunction2double
118
119         .globl asm_call_jit_compiler
120         .globl asm_throw_and_handle_exception
121         .globl asm_throw_and_handle_nat_exception
122         .globl asm_throw_and_handle_arithmetic_exception
123         .globl asm_throw_and_handle_arrayindexoutofbounds_exception
124         .globl asm_handle_exception
125         .globl asm_handle_nat_exception
126         .globl asm_check_clinit
127         .globl asm_builtin_checkarraycast
128         .globl asm_builtin_aastore
129
130 #if defined(USE_THREADS)
131         .globl asm_builtin_monitorenter
132         .globl asm_builtin_monitorexit
133 #endif
134
135         .globl asm_builtin_idiv
136         .globl asm_builtin_irem
137         .globl asm_builtin_ldiv
138         .globl asm_builtin_lrem
139         .globl asm_perform_threadswitch
140         .globl asm_initialize_thread_stack
141         .globl asm_switchstackandcall
142         .globl asm_criticalsections
143         .globl asm_getclassvalues_atomic
144         .globl asm_prepare_native_stackinfo
145         .globl asm_remove_native_stackinfo
146         .globl asm_refillin_and_handle_exception
147
148
149 /*********************** function has_no_x_instr_set ***************************
150 *                                                                              *
151 *   determines if the byte support instruction set (21164a and higher)         *
152 *   is available.                                                              *
153 *                                                                              *
154 *******************************************************************************/
155
156         .ent    has_no_x_instr_set
157 has_no_x_instr_set:
158
159         .long   0x47e03c20                /* amask   1,v0                         */
160         jmp     zero,(ra)                 /* return                               */
161
162         .end    has_no_x_instr_set
163
164
165 /********************* function asm_calljavafunction ***************************
166 *                                                                              *
167 *   This function calls a Java-method (which possibly needs compilation)       *
168 *   with up to 4 address parameters.                                           *
169 *                                                                              *
170 *   This functions calls the JIT-compiler which eventually translates the      *
171 *   method into machine code.                                                  *
172 *                                                                              *
173 *   C-prototype:                                                               *
174 *    javaobject_header *asm_calljavafunction (methodinfo *m,                   *
175 *         void *arg1, void *arg2, void *arg3, void *arg4);                     *
176 *                                                                              *
177 *******************************************************************************/
178
179         .ent    asm_calljavafunction
180
181 call_name:
182         .ascii  "calljavafunction\0\0"
183
184         .align  2 /*3*/
185         .quad   0                         /* catch type all                       */
186         .quad   calljava_xhandler         /* handler pc                           */
187         .quad   calljava_xhandler         /* end pc                               */
188         .quad   asm_calljavafunction      /* start pc                             */
189         .long   1                         /* extable size                         */
190         .long   0                         /* PADDING */
191         .quad   0                         /* line number table start             */
192         .quad   0                         /* line number table size             */
193         .long   0                         /* PADDING */
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_calljavafunction:
202         ldgp    gp,0(pv)
203         lda     sp,-32(sp)                /* allocate stack space                 */
204         stq     gp,24(sp)                 /* save global pointer                  */
205         stq     ra,0(sp)                  /* save return address                  */
206
207         stq     a0,16(sp)                 /* save method pointer for compiler     */
208         lda     v0,16(sp)                 /* pass pointer to method pointer via v0*/
209
210         mov     a1,a0                     /* pass the remaining parameters        */
211         mov     a2,a1
212         mov     a3,a2
213         mov     a4,a3
214
215         lda     $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
216         stq     $28,8(sp)                 /* store function address               */
217         mov     sp,$28                    /* set method pointer                   */
218
219         ldq     pv,8($28)                 /* method call as in Java               */
220         jmp     ra,(pv)                   /* call JIT compiler                    */
221 calljava_jit:
222         lda     pv,-64(ra)                /* asm_calljavafunction-calljava_jit !!!!!*/
223
224 calljava_return:
225         ldq     ra,0(sp)                  /* restore return address               */
226         ldq     gp,24(sp)                 /* restore global pointer               */
227         lda     sp,32(sp)                 /* free stack space                     */
228
229 calljava_ret:
230         jmp     zero,(ra)
231
232 calljava_xhandler:
233         ldq     gp,24(sp)                 /* restore global pointer               */
234         mov     itmp1,a0
235         jsr     ra,builtin_throw_exception
236         ldq     ra,0(sp)                  /* restore return address               */
237         lda     sp,32(sp)                 /* free stack space                     */
238         jmp     zero,(ra)
239         .end    asm_calljavafunction
240
241
242
243
244         .ent    asm_calljavafunction2
245
246 call_name2:
247         .align  3
248
249         .quad   0                         /* catch type all                       */
250         .quad   calljava_xhandler2        /* handler pc                           */
251         .quad   calljava_xhandler2        /* end pc                               */
252         .quad   asm_calljavafunction2     /* start pc                             */
253         .long   1                         /* extable size                         */
254         .long   0                         /* PADDING */
255         .quad   0                         /* line number table start             */
256         .quad   0                         /* line number table size             */
257         .long   0                         /* PADDING */
258         .long   0                         /* fltsave                              */
259         .long   1                         /* intsave                              */
260         .long   0                         /* isleaf                               */
261         .long   0                         /* IsSync                               */
262         .long   40                        /* frame size                           */
263         .quad   0                         /* method pointer (pointer to name)     */
264
265 asm_calljavafunction2:
266 asm_calljavafunction2int:
267 asm_calljavafunction2long:
268 asm_calljavafunction2float:
269 asm_calljavafunction2double:
270         ldgp    gp,0(pv)
271         lda     sp,-40(sp)                /* allocate stack space                 */
272         stq     ra,0(sp)                  /* save return address                  */
273         stq     s6,24(sp)
274         stq     gp,8(sp)                  /* save global pointer                  */
275
276         stq     a0,32(sp)                 /* save method pointer for compiler     */
277         mov     a3,t0                     /* pointer to arg block                 */
278         mov     a1,s6                     /* arg count                            */
279
280         ble     s6,calljava_argsloaded
281         lda     s6,-1(s6)
282         ldq     a0,offjniitem(t0)
283         ldt     $f16,offjniitem(t0)
284         ble     s6,calljava_argsloaded
285         lda     s6,-1(s6)
286         ldq     a1,offjniitem+sizejniblock*1(t0)
287         ldt     $f17,offjniitem+sizejniblock*1(t0)
288         ble     s6,calljava_argsloaded
289         lda     s6,-1(s6)
290         ldq     a2,offjniitem+sizejniblock*2(t0)
291         ldt     $f18,offjniitem+sizejniblock*2(t0)
292         ble     s6,calljava_argsloaded
293         lda     s6,-1(s6)
294         ldq     a3,offjniitem+sizejniblock*3(t0)
295         ldt     $f19,offjniitem+sizejniblock*3(t0)
296         ble     s6,calljava_argsloaded
297         lda     s6,-1(s6)
298         ldq     a4,offjniitem+sizejniblock*4(t0)
299         ldt     $f20,offjniitem+sizejniblock*4(t0)
300         ble     s6,calljava_argsloaded
301         lda     s6,-1(s6)
302         ldq     a5,offjniitem+sizejniblock*5(t0)
303         ldt     $f21,offjniitem+sizejniblock*5(t0)
304 calljava_argsloaded:
305         mov     sp,t4
306         ble     s6,calljava_nocopy
307         negq    s6,t1
308         s8addq  t1,sp,sp
309         s8addq  t1,t4,t2
310
311 calljava_copyloop:
312         ldq     t3,offjniitem+sizejniblock*6(t0)
313         stq     t3,0(t2)
314         lda     t1,1(t1)
315         lda     t0,sizejniblock(t0)
316         lda     t2,8(t2)
317         bne     t1,calljava_copyloop
318
319 calljava_nocopy:
320         lda     v0,32(t4)                 /* pass pointer to method pointer via v0*/
321
322         lda     $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
323         stq     $28,16(t4)                /* store function address               */
324         lda     $28,8(t4)                 /* set method pointer                   */
325
326         ldq     pv,8($28)                 /* method call as in Java               */
327         jmp     ra,(pv)                   /* call JIT compiler                    */
328 calljava_jit2:
329         lda     pv,-200(ra)               /* asm_calljavafunction-calljava_jit !!!*/
330
331         s8addq  s6,sp,sp
332 calljava_return2:
333         ldq     ra,0(sp)                  /* restore return address               */
334         ldq     gp,8(sp)                  /* restore global pointer               */
335         ldq     s6,24(sp)
336         lda     sp,40(sp)                 /* free stack space                     */
337
338 calljava_ret2:
339         jmp     zero,(ra)
340
341 calljava_xhandler2:
342         s8addq  s6,sp,sp
343         ldq     gp,8(sp)                  /* restore global pointer               */
344         mov     itmp1,a0
345         jsr     ra,builtin_throw_exception
346         ldq     ra,0(sp)                  /* restore return address               */
347         ldq     s6,24(sp)
348         lda     sp,40(sp)                 /* free stack space                     */
349         jmp     zero,(ra)
350         .end    asm_calljavafunction2
351
352
353 /****************** function asm_call_jit_compiler *****************************
354 *                                                                              *
355 *   invokes the compiler for untranslated JavaVM methods.                      *
356 *                                                                              *
357 *   Register R0 contains a pointer to the method info structure (prepared      *
358 *   by createcompilerstub). Using the return address in R26 and the            *
359 *   offset in the LDA instruction or using the value in methodptr R28 the      *
360 *   patching address for storing the method address can be computed:           *
361 *                                                                              *
362 *   method address was either loaded using                                     *
363 *   M_LDQ (REG_PV, REG_PV, a)        ; invokestatic/special    ($27)           *
364 *   M_LDA (REG_PV, REG_RA, low)                                                *
365 *   M_LDAH(REG_PV, REG_RA, high)     ; optional                                *
366 *   or                                                                         *
367 *   M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28)           *
368 *   in the static case the method pointer can be computed using the            *
369 *   return address and the lda function following the jmp instruction          *
370 *                                                                              *
371 *******************************************************************************/
372
373         .ent    asm_call_jit_compiler
374
375 asm_call_jit_compiler:
376         ldgp    gp,0(pv)
377         ldl     t8,-8(ra)             /* load instruction LDQ PV,xxx($yy)         */
378         srl     t8,16,t8              /* shift right register number $yy          */
379         and     t8,31,t8              /* isolate register number                  */
380         subl    t8,28,t8              /* test for REG_METHODPTR                   */
381         beq     t8,noregchange       
382         ldl     t8,0(ra)              /* load instruction LDA PV,xxx(RA)          */
383         sll     t8,48,t8
384         sra     t8,48,t8              /* isolate offset                           */
385         addq    t8,ra,$28             /* compute update address                   */
386         ldl     t8,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
387         srl     t8,16,t8              /* isolate instruction code                 */
388         lda     t8,-0x177b(t8)        /* test for LDAH                            */
389         bne     t8,noregchange       
390         ldl     t8,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
391         sll     t8,16,t8              /* compute high offset                      */
392         addl    t8,0,t8               /* sign extend high offset                  */
393         addq    t8,$28,$28            /* compute update address                   */
394 noregchange:
395         lda     sp,-14*8(sp)          /* reserve stack space                      */
396         stq     a0,0*8(sp)            /* save all argument registers              */
397         stq     a1,1*8(sp)            /* they could be used by method             */
398         stq     a2,2*8(sp)
399         stq     a3,3*8(sp)
400         stq     a4,4*8(sp)
401         stq     a5,5*8(sp)
402         stt     $f16,6*8(sp)
403         stt     $f17,7*8(sp)
404         stt     $f18,8*8(sp)
405         stt     $f19,9*8(sp)
406         stt     $f20,10*8(sp)
407         stt     $f21,11*8(sp)
408         stq     $28,12*8(sp)          /* save method pointer                      */
409         stq     ra,13*8(sp)           /* save return address                      */
410
411         ldq     a0,0(v0)              /* pass 'methodinfo' pointer to             */
412         jsr     ra,jit_compile        /* jit compiler                             */
413         ldgp    gp,0(ra)
414
415         ldq     a0,0*8(sp)            /* load argument registers                  */
416         ldq     a1,1*8(sp)
417         ldq     a2,2*8(sp)
418         ldq     a3,3*8(sp)
419         ldq     a4,4*8(sp)
420         ldq     a5,5*8(sp)
421         ldt     $f16,6*8(sp)
422         ldt     $f17,7*8(sp)
423         ldt     $f18,8*8(sp)
424         ldt     $f19,9*8(sp)
425         ldt     $f20,10*8(sp)
426         ldt     $f21,11*8(sp)
427         ldq     $28,12*8(sp)          /* load method pointer                      */
428         ldq     ra,13*8(sp)           /* load return address                      */
429         lda     sp,14*8(sp)           /* deallocate stack area                    */
430
431         beq     v0,asm_call_jit_compiler_exception
432
433         ldl     t8,-8(ra)             /* load instruction LDQ PV,xxx($yy)         */
434         sll     t8,48,t8
435         sra     t8,48,t8              /* isolate offset                           */
436
437         addq    t8,$28,t8             /* compute update address via method pointer*/
438         stq     v0,0(t8)              /* save new method address there            */
439
440         call_pal PAL_imb              /* synchronise instruction cache            */
441
442         mov     v0,pv                 /* load method address into pv              */
443         jmp     zero,(pv)             /* and call method. The method returns      */
444                                       /* directly to the caller (ra).             */
445
446 asm_call_jit_compiler_exception:
447 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
448         subq    sp,1*8,sp
449         stq     ra,0*8(sp)
450         jsr     ra,builtin_asm_get_exceptionptrptr
451         ldq     ra,0*8(sp)
452         addq    sp,1*8,sp
453 #else
454         lda     v0,_exceptionptr
455 #endif
456         ldq     xptr,0(v0)            /* get the exception pointer                */
457         stq     zero,0(v0)            /* clear the exception pointer              */
458
459         subq    ra,4,xpc
460         br      asm_handle_nat_exception
461
462         .end    asm_call_jit_compiler
463
464
465 /**************** function asm_refillin_and_handle_exception *******************
466 *                                                                              *
467 *   This function handles an exception. It does not use the usual calling      *
468 *   conventions. The exception is passed in REG_ITMP1 and the                  *
469 *   pc from the exception raising position is passed in REG_ITMP2.             *
470 *   a0 contains the PV of the function causing the problem                     *
471 *                                                                              *
472 *   void asm_handle_arithmetic_exception (exceptionclass, exceptionpc);        *
473 *                                                                              *
474 *******************************************************************************/
475         .ent asm_refillin_and_handle_exception
476 asm_refillin_and_handle_exception:
477         ldgp    gp,0(pv)
478         ldl     t0,0(ra)              /* load instruction LDA PV,xxx(RA)          */
479         sll     t0,48,t0
480         sra     t0,48,t0              /* isolate offset                           */
481         addq    t0,ra,pv              /* compute update address                   */
482         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
483         srl     t0,16,t0              /* isolate instruction code                 */
484         lda     t0,-0x177b(t0)        /* test for LDAH                            */
485         bne     t0, asm_refillin_and_handle_exception_cont
486         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
487         sll     t0,16,t0              /* compute high offset                      */
488         addl    t0,0,t0               /* sign extend high offset                  */
489         addq    t0,pv,pv              /* compute update address                   */
490
491 asm_refillin_and_handle_exception_cont:
492
493         mov     sp,t0
494         lda     sp,-6*8(sp) /* prepare stackframe*/
495         stq     pv,5*8(sp) /* store pv of caller */
496         stq     xptr,4*8(sp) /*exception ptr*/
497         stq     xpc,3*8(sp) /*address of failure*/
498         stq     t0,2*8(sp) /*begin of java stack frame*/
499         stq     pv,1*8(sp) /* store pv of caller */
500         stq     zero,0*8(sp)    /*builtin (invisible) function */
501         jsr     ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
502         ldgp    gp,0(ra)
503
504         ldq     a2,utf_void__java_lang_Throwable
505         ldq     a1,utf_fillInStackTrace
506         ldq     t0,6*8(sp)
507         ldq     t1,offobjvftbl(t0)      
508         ldq     a0,offclass(t1)
509         jsr     ra,class_resolvemethod
510         ldgp    gp,0(ra)
511         /* now we have the method */
512
513         /*refillin */
514         mov     v0,a0
515         ldq     a1,6*8(sp)
516         jsr     ra,asm_calljavafunction
517         ldgp    gp,0(ra)
518
519         /*remove frame*/
520         jsr ra,asm_remove_native_stackinfo
521         ldgp    gp,0(ra)
522
523
524         /*finish*/
525         ldq     xpc,0(sp)       
526         ldq     xptr,1*8(sp)
527         ldq     pv,2*8(sp)
528         lda sp,3*8(sp)
529         br asm_handle_exception
530
531         .end asm_refillin_and_handle_exception
532
533 /****** function asm_throw_and_handle_arrayindexoutofbounds_exception **********
534 *                                                                              *
535 *   This function handles an exception. It does not use the usual calling      *
536 *   conventions. The integer parameter is passed in REG_ITMP1 and the          *
537 *   pc from the exception raising position is passed in REG_ITMP2.             *
538 *                                                                              *
539 *   void asm_handle_arithmetic_exception (exceptionclass, exceptionpc);        *
540 *                                                                              *
541 *******************************************************************************/
542
543         .ent asm_throw_and_handle_arrayindexoutofbounds_exception
544
545 asm_throw_and_handle_arrayindexoutofbounds_exception:
546         ldgp    gp,0(pv)
547
548         ldl     t0,0(ra)              /* load instruction LDA PV,xxx(RA)          */
549         sll     t0,48,t0
550         sra     t0,48,t0              /* isolate offset                           */
551         addq    t0,ra,pv              /* compute update address                   */
552         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
553         srl     t0,16,t0              /* isolate instruction code                 */
554         lda     t0,-0x177b(t0)        /* test for LDAH                            */
555         bne     t0,asm_throw_and_handle_arrayindexoutofbounds_exception_cont
556         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
557         sll     t0,16,t0              /* compute high offset                      */
558         addl    t0,0,t0               /* sign extend high offset                  */
559         addq    t0,pv,pv              /* compute update address                   */
560
561 asm_throw_and_handle_arrayindexoutofbounds_exception_cont:
562         mov     sp,t0
563         lda     sp,-6*8(sp) /*prepare stackframe*/
564         stq     pv,5*8(sp)  /*pv of failure*/
565         stq     itmp1,4*8(sp) /*int parameter  of the exception*/
566         stq     xpc,3*8(sp) /*address of failure */
567         stq     t0,2*8(sp) /*store begin of java stack frame*/
568         stq     pv,1*8(sp) /*store pv of caller in structure*/
569         stq     zero,0*8(sp) /*builtin (invisible function)*/
570
571         jsr     ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
572         ldgp    gp,0(ra)
573
574         ldq     a0,6*8(sp)  /*int  of exception*/
575         jsr     ra,new_arrayindexoutofboundsexception
576         ldgp    gp,0(ra)
577
578         mov     v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
579
580         jsr     ra,asm_remove_native_stackinfo
581         ldgp    gp,0(ra)
582
583         ldq     itmp2,0(sp)     
584         ldq     pv,2*8(sp)
585         lda     sp,3*8(sp)
586         br      asm_handle_exception
587
588         .end asm_throw_and_handle_arrayindexoutofbounds_exception
589
590
591 /* asm_throw_and_handle_arithmetic_exception ***********************************
592
593    DOCUMENT ME!
594
595 *******************************************************************************/
596
597         .ent asm_throw_and_handle_arithmetic_exception
598
599 asm_throw_and_handle_arithmetic_exception:
600         ldl     t0,0(ra)              /* load instruction LDA PV,xxx(RA)          */
601         sll     t0,48,t0
602         sra     t0,48,t0              /* isolate offset                           */
603         addq    t0,ra,pv              /* compute update address                   */
604         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
605         srl     t0,16,t0              /* isolate instruction code                 */
606         lda     t0,-0x177b(t0)        /* test for LDAH                            */
607         bne     t0,asm_throw_and_handle_arithmetic_exception_cont
608         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
609         sll     t0,16,t0              /* compute high offset                      */
610         addl    t0,0,t0               /* sign extend high offset                  */
611         addq    t0,pv,pv              /* compute update address                   */
612
613 asm_throw_and_handle_arithmetic_exception_cont:
614         mov     sp,t0
615         lda     sp,-6*8(sp) /*prepare stackframe*/
616         stq     pv,5*8(sp)  /*pv of failure*/
617         stq     itmp1,4*8(sp) /*exception string of the exception*/
618         stq     xpc,3*8(sp) /*address of failure */
619         stq     t0,2*8(sp) /*store begin of java stack frame*/
620         stq     pv,1*8(sp) /*store pv of caller in structure*/
621         stq     zero,0*8(sp) /*builtin (invisible function)*/
622         jsr     ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
623         ldgp    gp,0(ra)
624
625         jsr     ra,new_arithmeticexception
626         ldgp    gp,0(ra)
627         mov     v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
628
629         jsr ra,asm_remove_native_stackinfo
630         ldgp    gp,0(ra)
631
632         ldq itmp2,0(sp) 
633         ldq    pv,2*8(sp)
634         lda sp,3*8(sp)
635         br asm_handle_exception
636
637         .end asm_throw_and_handle_arithmetic_exception
638
639
640 /* asm_throw_and_handle_exception **********************************************
641
642    DOCUMENT ME!!!
643
644 *******************************************************************************/
645
646         .ent asm_throw_and_handle_nat_exception
647
648 asm_throw_and_handle_nat_exception:
649         ldgp    gp,0(pv)
650         ldl     t0,0(ra)              /* load instruction LDA PV,xxx(RA)          */
651         sll     t0,48,t0
652         sra     t0,48,t0              /* isolate offset                           */
653         addq    t0,ra,pv              /* compute update address                   */
654         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
655         srl     t0,16,t0              /* isolate instruction code                 */
656         lda     t0,-0x177b(t0)        /* test for LDAH                            */
657         bne     t0,asm_throw_and_handle_exception
658         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
659         sll     t0,16,t0              /* compute high offset                      */
660         addl    t0,0,t0               /* sign extend high offset                  */
661         addq    t0,pv,pv              /* compute update address                   */
662
663         .aent asm_throw_and_handle_exception
664
665 asm_throw_and_handle_exception:
666         mov     sp,t0
667         lda     sp,-6*8(sp)           /* prepare stackframe                       */
668         stq     pv,5*8(sp)            /* pv of failure                            */
669         stq     xptr,4*8(sp)          /* classname of the exception               */
670         stq     xpc,3*8(sp)           /* address of failure                       */
671         stq     t0,2*8(sp)            /* store begin of java stack frame          */
672         stq     pv,1*8(sp)            /* store pv of caller in structure          */
673         stq     zero,0*8(sp)          /* builtin (invisible function)             */
674                                       /* puts 2 additional quadwords on stack     */
675         jsr     ra,asm_prepare_native_stackinfo
676         ldgp    gp,0(ra)
677
678         ldq     a0,6*8(sp)            /* classname of exception                   */
679         jsr     ra,new_exception
680         ldgp    gp,0(ra)
681
682         mov     v0,xptr               /* xptr (itmp1) is not touched in           */
683                                       /* asm_remove_native_stackinfo              */
684
685         jsr     ra,asm_remove_native_stackinfo
686         ldgp    gp,0(ra)
687
688         ldq     itmp2,0(sp)
689         ldq     pv,2*8(sp)
690         lda     sp,3*8(sp)
691         br      asm_handle_exception
692
693         .end asm_throw_and_handle_nat_exception
694
695
696 /********************* function asm_handle_exception ***************************
697 *                                                                              *
698 *   This function handles an exception. It does not use the usual calling      *
699 *   conventions. The exception pointer is passed in REG_ITMP1 and the          *
700 *   pc from the exception raising position is passed in REG_ITMP2. It searches *
701 *   the local exception table for a handler. If no one is found, it unwinds    *
702 *   stacks and continues searching the callers.                                *
703 *                                                                              *
704 *   void asm_handle_exception (exceptionptr, exceptionpc);                     *
705 *                                                                              *
706 *******************************************************************************/
707
708         .ent    asm_handle_nat_exception
709
710 asm_handle_nat_exception:
711         ldl     t0,0(ra)              /* load instruction LDA PV,xxx(RA)          */
712         sll     t0,48,t0
713         sra     t0,48,t0              /* isolate offset                           */
714         addq    t0,ra,pv              /* compute update address                   */
715         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
716         srl     t0,16,t0              /* isolate instruction code                 */
717         lda     t0,-0x177b(t0)        /* test for LDAH                            */
718         bne     t0,asm_handle_exception
719         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
720         sll     t0,16,t0              /* compute high offset                      */
721         addl    t0,0,t0               /* sign extend high offset                  */
722         addq    t0,pv,pv              /* compute update address                   */
723
724         .aent    asm_handle_exception
725
726 asm_handle_exception:
727         lda     sp,-18*8(sp)          /* allocate stack                           */
728         stq     t0,0*8(sp)            /* save possible used registers             */
729         stq     t1,1*8(sp)            /* also registers used by trace_exception   */
730         stq     t2,2*8(sp)
731         stq     t3,3*8(sp)
732         stq     t4,4*8(sp)
733         stq     t5,5*8(sp)
734         stq     t6,6*8(sp)
735         stq     t7,7*8(sp)
736         stq     t8,8*8(sp)
737         stq     t9,9*8(sp)
738         stq     t10,10*8(sp)
739         stq     v0,11*8(sp)
740         stq     a0,12*8(sp)
741         stq     a1,13*8(sp)
742         stq     a2,14*8(sp)
743         stq     a3,15*8(sp)
744         stq     a4,16*8(sp)
745         stq     a5,17*8(sp)
746
747         lda     t3,1(zero)            /* set no unwind flag                       */
748 ex_stack_loop:
749         lda     sp,-5*8(sp)           /* allocate stack                           */
750         stq     xptr,0*8(sp)          /* save used register                       */
751         stq     xpc,1*8(sp)
752         stq     pv,2*8(sp)
753         stq     ra,3*8(sp)
754         stq     t3,4*8(sp)
755
756         mov     xptr,a0
757         ldq     a1,MethodPointer(pv)
758         mov     xpc,a2
759 /*      mov     t3,a3 */
760         lda             a3,0(zero)
761         lda             a4,1(zero)
762         br      ra,ex_trace           /* set ra for gp loading                    */
763 ex_trace:
764         ldgp    gp,0(ra)              /* load gp                                  */
765         jsr     ra,builtin_trace_exception /* trace_exception(xptr,methodptr)     */
766         
767         ldq     xptr,0*8(sp)          /* restore used register                    */
768         ldq     xpc,1*8(sp)
769         ldq     pv,2*8(sp)
770         ldq     ra,3*8(sp)
771         ldq     t3,4*8(sp)
772         lda     sp,5*8(sp)            /* deallocate stack                         */
773         
774         ldl     t0,ExTableSize(pv)    /* t0 = exception table size                */
775         beq     t0,empty_table        /* if empty table skip                      */
776
777         lda     t1,ExTableStart(pv)   /* t1 = start of exception table            */
778
779 ex_table_loop:
780         ldq     t2,ExStartPC(t1)      /* t2 = exception start pc                  */
781         cmple   t2,xpc,t2             /* t2 = (startpc <= xpc)                    */
782         beq     t2,ex_table_cont      /* if (false) continue                      */
783         ldq     t2,ExEndPC(t1)        /* t2 = exception end pc                    */
784         cmplt   xpc,t2,t2             /* t2 = (xpc < endpc)                       */
785         beq     t2,ex_table_cont      /* if (false) continue                      */
786         ldq     a1,ExCatchType(t1)    /* arg1 = exception catch type              */
787         beq     a1,ex_handle_it       /* NULL catches everything                  */
788
789         ldl     itmp3,offclassloaded(a1)
790         bne     itmp3,L_class_loaded
791
792         subq    sp,8*8,sp             /* allocate stack                           */
793         stq     t0,0*8(sp)            /* save used register                       */
794         stq     t1,1*8(sp)
795         stq     t3,2*8(sp)
796         stq     xptr,3*8(sp)
797         stq     xpc,4*8(sp)
798         stq     pv,5*8(sp)
799         stq     ra,6*8(sp)
800         stq     a1,7*8(sp)
801
802         mov     a1,a0
803
804         br      ra,L_class_load_ra    /* set ra for gp loading                    */
805 L_class_load_ra:
806         ldgp    gp,0(ra)              /* load gp                                  */
807         jsr     ra,class_load         /* class_load(exceptionclass)               */
808
809         ldq     t0,0*8(sp)            /* restore used register                    */
810         ldq     t1,1*8(sp)
811         ldq     t3,2*8(sp)
812         ldq     xptr,3*8(sp)
813         ldq     xpc,4*8(sp)
814         ldq     pv,5*8(sp)
815         ldq     ra,6*8(sp)
816         ldq     a1,7*8(sp)
817         addq    sp,8*8,sp             /* deallocate stack                         */
818
819 L_class_loaded:
820         ldl     itmp3,offclasslinked(a1)
821         subq    sp,8*8,sp             /* allocate stack                           */
822         stq     a1,7*8(sp)
823         bne     itmp3,L_class_linked
824
825         stq     t0,0*8(sp)            /* save used register                       */
826         stq     t1,1*8(sp)
827         stq     t3,2*8(sp)
828         stq     xptr,3*8(sp)
829         stq     xpc,4*8(sp)
830         stq     pv,5*8(sp)
831         stq     ra,6*8(sp)
832
833         mov     a1,a0
834
835         br      ra,L_class_link_ra    /* set ra for gp loading                    */
836 L_class_link_ra:
837         ldgp    gp,0(ra)              /* load gp                                  */
838         jsr     ra,class_link         /* class_load(exceptionclass)               */
839
840         ldq     t0,0*8(sp)            /* restore used register                    */
841         ldq     t1,1*8(sp)
842         ldq     t3,2*8(sp)
843         ldq     xptr,3*8(sp)
844         ldq     xpc,4*8(sp)
845         ldq     pv,5*8(sp)
846         ldq     ra,6*8(sp)
847
848 L_class_linked:
849 _crit_restart1:
850         ldq     a1,7*8(sp)
851 _crit_begin1:
852         ldq     a0,offobjvftbl(xptr)  /* a0 = vftblptr(xptr)                      */
853         ldq     a1,offclassvftbl(a1)  /* a1 = vftblptr(catchtype) class (not obj) */
854         ldl     a0,offbaseval(a0)     /* a0 = baseval(xptr)                       */
855         ldl     v0,offbaseval(a1)     /* a2 = baseval(catchtype)                  */
856         ldl     a1,offdiffval(a1)     /* a1 = diffval(catchtype)                  */
857 _crit_end1:
858         subl    a0,v0,a0              /* a0 = baseval(xptr) - baseval(catchtype)  */
859         cmpule  a0,a1,v0              /* v0 = xptr is instanceof catchtype        */
860         addq    sp,8*8,sp             /* deallocate stack                         */
861         beq     v0,ex_table_cont      /* if (false) continue                      */
862
863 ex_handle_it:
864         ldq     xpc,ExHandlerPC(t1)   /* xpc = exception handler pc               */
865
866         beq     t3,ex_jump            /* if (!(no stack unwinding) skip           */
867
868         ldq     t0,0*8(sp)            /* restore possible used registers          */
869         ldq     t1,1*8(sp)            /* also registers used by trace_exception   */
870         ldq     t2,2*8(sp)
871         ldq     t3,3*8(sp)
872         ldq     t4,4*8(sp)
873         ldq     t5,5*8(sp)
874         ldq     t6,6*8(sp)
875         ldq     t7,7*8(sp)
876         ldq     t8,8*8(sp)
877         ldq     t9,9*8(sp)
878         ldq     t10,10*8(sp)
879         ldq     v0,11*8(sp)
880         ldq     a0,12*8(sp)
881         ldq     a1,13*8(sp)
882         ldq     a2,14*8(sp)
883         ldq     a3,15*8(sp)
884         ldq     a4,16*8(sp)
885         ldq     a5,17*8(sp)
886         lda     sp,18*8(sp)           /* deallocate stack                         */
887
888 ex_jump:
889         jmp     zero,(xpc)            /* jump to the handler                      */
890
891 ex_table_cont:
892         lda     t1,ExEntrySize(t1)    /* next exception table entry               */
893         subl    t0,1,t0               /* decrement entry counter                  */
894         bgt     t0,ex_table_loop      /* if (t0 > 0) next entry                   */
895
896 empty_table:
897         beq     t3,ex_already_cleared /* if here the first time, then             */
898         lda     sp,18*8(sp)           /* deallocate stack and                     */
899         clr     t3                    /* clear the no unwind flag                 */
900 ex_already_cleared:
901         ldl     t0,IsSync(pv)         /* t0 = SyncOffset                          */
902         beq     t0,no_monitor_exit    /* if zero no monitorexit                   */
903
904 #if defined(USE_THREADS)
905         addq    sp,t0,t0              /* add stackptr to Offset                   */
906         ldq     a0,-8(t0)             /* load monitorexit pointer                 */
907
908         lda     sp,-7*8(sp)           /* allocate stack                           */
909         stq     t0,0*8(sp)            /* save used register                       */
910         stq     t1,1*8(sp)
911         stq     t3,2*8(sp)
912         stq     xptr,3*8(sp)
913         stq     xpc,4*8(sp)
914         stq     pv,5*8(sp)
915         stq     ra,6*8(sp)
916
917         br      ra,ex_mon_load        /* set ra for gp loading                    */
918 ex_mon_load:
919         ldgp    gp,0(ra)              /* load gp                                  */
920         jsr     ra,builtin_monitorexit/* builtin_monitorexit(objectptr)           */
921         
922         ldq     t0,0*8(sp)            /* restore used register                    */
923         ldq     t1,1*8(sp)
924         ldq     t3,2*8(sp)
925         ldq     xptr,3*8(sp)
926         ldq     xpc,4*8(sp)
927         ldq     pv,5*8(sp)
928         ldq     ra,6*8(sp)
929         lda     sp,7*8(sp)            /* deallocate stack                         */
930 #endif
931
932 no_monitor_exit:
933         ldl     t0,FrameSize(pv)      /* t0 = frame size                          */
934         addq    sp,t0,sp              /* unwind stack                             */
935         mov     sp,t0                 /* t0 = pointer to save area                */
936         ldl     t1,IsLeaf(pv)         /* t1 = is leaf procedure                   */
937         bne     t1,ex_no_restore      /* if (leaf) skip                           */
938         ldq     ra,-8(t0)             /* restore ra                               */
939         lda     t0,-8(t0)             /* t0--                                     */
940 ex_no_restore:
941         mov     ra,xpc                /* the new xpc is ra                        */
942         ldl     t1,IntSave(pv)        /* t1 = saved int register count            */
943         br      t2,ex_int1            /* t2 = current pc                          */
944 ex_int1:
945         lda     t2,44(t2)             /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
946         negl    t1,t1                 /* negate register count                    */
947         s4addq  t1,t2,t2              /* t2 = ex_int_sav - 4 * register count     */
948         jmp     zero,(t2)             /* jump to save position                    */
949         ldq     s0,-56(t0)
950         ldq     s1,-48(t0)
951         ldq     s2,-40(t0)
952         ldq     s3,-32(t0)
953         ldq     s4,-24(t0)
954         ldq     s5,-16(t0)
955         ldq     s6,-8(t0)
956 ex_int2:
957         s8addq  t1,t0,t0              /* t0 = t0 - 8 * register count             */
958
959         ldl     t1,FltSave(pv)        /* t1 = saved flt register count            */
960         br      t2,ex_flt1            /* t2 = current pc                          */
961 ex_flt1:
962         lda     t2,48(t2)             /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
963         negl    t1,t1                 /* negate register count                    */
964         s4addq  t1,t2,t2              /* t2 = ex_flt_sav - 4 * register count     */
965         jmp     zero,(t2)             /* jump to save position                    */
966         ldt     $f2,-64(t0)
967         ldt     $f3,-56(t0)
968         ldt     $f4,-48(t0)
969         ldt     $f5,-40(t0)
970         ldt     $f6,-32(t0)
971         ldt     $f7,-24(t0)
972         ldt     $f8,-16(t0)
973         ldt     $f9,-8(t0)
974 ex_flt2:
975         ldl     t0,0(ra)              /* load instruction LDA PV,xxx(RA)          */
976         sll     t0,48,t0
977         sra     t0,48,t0              /* isolate offset                           */
978         addq    t0,ra,pv              /* compute update address                   */
979         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(PV)         */
980         srl     t0,16,t0              /* isolate instruction code                 */
981         lda     t0,-0x177b(t0)        /* test for LDAH                            */
982         bne     t0,ex_stack_loop       
983         ldl     t0,4(ra)              /* load instruction LDAH PV,xxx(RA)         */
984         sll     t0,16,t0              /* compute high offset                      */
985         addl    t0,0,t0               /* sign extend high offset                  */
986         addq    t0,pv,pv              /* compute update address                   */
987         br      ex_stack_loop
988
989         .end    asm_handle_nat_exception
990
991
992 /* asm_check_clinit ************************************************************
993
994    DOCUMENT ME!!!
995
996    Arguments:
997
998         itmp1: pointer to class
999
1000    Stack layout:
1001
1002         0   mcode  ; machine code to patch back in
1003
1004 *******************************************************************************/
1005                 
1006     .ent    asm_check_clinit
1007
1008 asm_check_clinit:
1009         ldgp    gp,0(itmp2)           /* function is called via `jsr ra,itmp1'    */
1010
1011         subq    sp,8*8,sp
1012
1013         stq             ra,0*8(sp)            /* save return address                      */
1014         stq     pv,1*8(sp)            /* save pv of calling java function         */
1015         stq             a0,2*8(sp)            /* save argument registers for leaf         */
1016         stq             a1,3*8(sp)            /* functions and native stub                */
1017         stq             a2,4*8(sp)
1018         stq             a3,5*8(sp)
1019         stq             a4,6*8(sp)
1020         stq             a5,7*8(sp)
1021                 
1022         ldl             itmp2,offclassinit(itmp1)
1023         bne             itmp2,L_is_initialized
1024         
1025         mov             itmp1,a0              /* move class pointer to a0                 */
1026         jsr             ra,class_init
1027     ldgp    gp,0(ra)
1028                 
1029         beq     v0,L_initializererror
1030
1031 L_is_initialized:
1032         ldq     ra,0*8(sp)            /* get return address                       */
1033         subq    ra,1*4,ra             /* go back 1 instruction                    */
1034         ldl     itmp1,8*8(sp)         /* load machine code from stack             */
1035         stl     itmp1,0(ra)           /* store the machine code                   */
1036
1037         call_pal PAL_imb              /* synchronise instruction cache            */
1038
1039         ldq             ra,0*8(sp)            /* restore return address                   */
1040         ldq     pv,1*8(sp)            /* restore pv of calling java function      */
1041         ldq             a0,2*8(sp)            /* restore argument registers               */
1042         ldq             a1,3*8(sp)
1043         ldq             a2,4*8(sp)
1044         ldq             a3,5*8(sp)
1045         ldq             a4,6*8(sp)
1046         ldq             a5,7*8(sp)
1047
1048         addq    sp,(8+1)*8,sp         /* remove stack frame (+1 for machine code) */
1049
1050         subq    ra,1*4,ra             /* go back 1 instruction                    */
1051         jmp             zero,(ra)             /* jump to the new code                     */
1052
1053 L_initializererror:
1054 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1055         jsr     ra,builtin_asm_get_exceptionptrptr
1056 #else
1057         lda     v0,_exceptionptr
1058 #endif
1059         ldq     xptr,0(v0)            /* get the exception pointer                */
1060         stq     zero,0(v0)            /* clear the exception pointer              */
1061
1062         ldq             ra,0*8(sp)            /* restore return address                   */
1063         ldq     pv,1*8(sp)            /* restore pv of calling java function      */
1064         ldq             a0,2*8(sp)            /* restore argument registers               */
1065         ldq             a1,3*8(sp)
1066         ldq             a2,4*8(sp)
1067         ldq             a3,5*8(sp)
1068         ldq             a4,6*8(sp)
1069         ldq             a5,7*8(sp)
1070
1071         addq    sp,(8+1)*8,sp         /* remove stack frame (+1 for machine code) */
1072
1073         subq    ra,4,xpc
1074         br      asm_handle_exception  /* we have the pv of the calling java func. */
1075
1076         .end    asm_check_clinit
1077
1078                 
1079 /********************* function asm_builtin_monitorenter ***********************
1080 *                                                                              *
1081 *   Does null check and calls monitorenter or throws an exception              *
1082 *                                                                              *
1083 *******************************************************************************/
1084
1085 #if defined(USE_THREADS)
1086         .ent    asm_builtin_monitorenter
1087
1088 asm_builtin_monitorenter:
1089         ldgp    gp,0(pv)
1090         lda     pv,builtin_monitorenter
1091         beq     a0,nb_monitorenter        /* if (null) throw exception            */
1092         jmp     zero,(pv)                 /* else call builtin_monitorenter       */
1093
1094 nb_monitorenter:
1095         lda xpc,-4(ra)
1096         ldq xptr,string_java_lang_NullPointerException
1097         jmp zero,asm_throw_and_handle_nat_exception
1098 #if 0
1099         subq    sp,8,sp
1100     stq     ra,0(sp)
1101     jsr     ra,new_nullpointerexception
1102     ldgp    gp,0(ra)
1103         mov     v0,xptr
1104     ldq     ra,0(sp)
1105         addq    sp,8,sp
1106         
1107         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
1108         br      asm_handle_nat_exception
1109 #endif
1110
1111         .end    asm_builtin_monitorenter
1112 #endif
1113
1114
1115 /********************* function asm_builtin_monitorexit ************************
1116 *                                                                              *
1117 *   Does null check and calls monitorexit or throws an exception               *
1118 *                                                                              *
1119 *******************************************************************************/
1120
1121 #if defined(USE_THREADS)
1122         .ent    asm_builtin_monitorexit
1123
1124 asm_builtin_monitorexit:
1125         ldgp    gp,0(pv)
1126         lda     pv,builtin_monitorexit
1127         beq     a0,nb_monitorexit         /* if (null) throw exception            */
1128         jmp     zero,(pv)                 /* else call builtin_monitorexit        */
1129
1130 nb_monitorexit:
1131         lda     xpc,-4(ra)
1132         ldq     xptr,string_java_lang_NullPointerException
1133         jmp     zero,asm_throw_and_handle_nat_exception
1134 #if 0
1135         subq    sp,8,sp
1136     stq     ra,0(sp)
1137     jsr     ra,new_nullpointerexception
1138     ldgp    gp,0(ra)
1139         mov     v0,xptr
1140     ldq     ra,0(sp)
1141         addq    sp,8,sp
1142         
1143         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
1144         br      asm_handle_nat_exception
1145 #endif
1146
1147         .end    asm_builtin_monitorexit
1148 #endif
1149
1150
1151 /************************ function asm_builtin_idiv ****************************
1152 *                                                                              *
1153 *   Does null check and calls idiv or throws an exception                      *
1154 *                                                                              *
1155 *******************************************************************************/
1156
1157         .ent    asm_builtin_idiv
1158
1159 asm_builtin_idiv:
1160         ldgp    gp,0(pv)
1161         lda     pv,builtin_idiv
1162         beq     a1,nb_idiv                /* if (null) throw exception            */
1163         jmp     zero,(pv)                 /* else call builtin_idiv               */
1164
1165 nb_idiv:
1166         ldq     xptr,string_java_lang_ArithmeticException_message
1167         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
1168         br      asm_throw_and_handle_arithmetic_exception
1169
1170         .end    asm_builtin_idiv
1171
1172
1173 /************************ function asm_builtin_ldiv ****************************
1174 *                                                                              *
1175 *   Does null check and calls ldiv or throws an exception                      *
1176 *                                                                              *
1177 *******************************************************************************/
1178
1179         .ent    asm_builtin_ldiv
1180
1181 asm_builtin_ldiv:
1182         ldgp    gp,0(pv)
1183         lda     pv,builtin_ldiv
1184         beq     a1,nb_ldiv                /* if (null) throw exception            */
1185         jmp     zero,(pv)                 /* else call builtin_ldiv               */
1186
1187 nb_ldiv:
1188         ldq     xptr,string_java_lang_ArithmeticException_message
1189         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
1190         br      asm_throw_and_handle_arithmetic_exception
1191
1192         .end    asm_builtin_ldiv
1193
1194
1195 /************************ function asm_builtin_irem ****************************
1196 *                                                                              *
1197 *   Does null check and calls irem or throws an exception                      *
1198 *                                                                              *
1199 *******************************************************************************/
1200
1201         .ent    asm_builtin_irem
1202
1203 asm_builtin_irem:
1204         ldgp    gp,0(pv)
1205         lda     pv,builtin_irem
1206         beq     a1,nb_irem                /* if (null) throw exception            */
1207         jmp     zero,(pv)                 /* else call builtin_irem               */
1208
1209 nb_irem:
1210         ldq     xptr,string_java_lang_ArithmeticException_message
1211         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
1212         br      asm_throw_and_handle_arithmetic_exception
1213
1214         .end    asm_builtin_irem
1215
1216
1217 /************************ function asm_builtin_lrem ****************************
1218 *                                                                              *
1219 *   Does null check and calls lrem or throws an exception                      *
1220 *                                                                              *
1221 *******************************************************************************/
1222
1223         .ent    asm_builtin_lrem
1224
1225 asm_builtin_lrem:
1226         ldgp    gp,0(pv)
1227         lda     pv,builtin_lrem
1228         beq     a1,nb_lrem                /* if (null) throw exception            */
1229         jmp     zero,(pv)                 /* else call builtin_lrem               */
1230
1231 nb_lrem:
1232         ldq     xptr,string_java_lang_ArithmeticException_message
1233         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
1234         br      asm_throw_and_handle_arithmetic_exception
1235
1236         .end    asm_builtin_lrem
1237
1238
1239 /******************* function asm_builtin_checkarraycast ***********************
1240 *                                                                              *
1241 *   Does the cast check and eventually throws an exception                     *
1242 *                                                                              *
1243 *******************************************************************************/
1244
1245         .ent    asm_builtin_checkarraycast
1246
1247 asm_builtin_checkarraycast:
1248         ldgp    gp,0(pv)
1249         lda     sp,-16(sp)                /* allocate stack space                 */
1250         stq     ra,0(sp)                  /* save return address                  */
1251         stq     a0,8(sp)                  /* save object pointer                  */
1252         jsr     ra,builtin_checkarraycast /* builtin_checkarraycast               */
1253         ldgp    gp,0(ra)
1254         beq     v0,nb_carray_throw        /* if (false) throw exception           */
1255         ldq     ra,0(sp)                  /* restore return address               */
1256         ldq     v0,8(sp)                  /* return object pointer                */
1257         lda     sp,16(sp)                 /* free stack space                     */
1258         jmp     zero,(ra)
1259
1260 nb_carray_throw:
1261         ldq     ra,0(sp)
1262         lda     sp,16(sp)
1263         lda     xpc,-4(ra)
1264         ldq     xptr,string_java_lang_ClassCastException
1265         jmp     zero,asm_throw_and_handle_nat_exception
1266 #if 0
1267         ldq     a0,string_java_lang_ClassCastException
1268     jsr     ra,new_exception
1269     ldgp    gp,0(ra)
1270         mov     v0,xptr
1271
1272         ldq     ra,0(sp)                  /* restore return address               */
1273         lda     sp,16(sp)                 /* free stack space                     */
1274         lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
1275         br      asm_handle_nat_exception
1276 #endif
1277
1278         .end    asm_builtin_checkarraycast
1279
1280
1281 /******************* function asm_builtin_aastore ******************************
1282 *                                                                              *
1283 *   Does the cast check and eventually throws an exception                     *
1284 *                                                                              *
1285 *******************************************************************************/
1286
1287         .ent    asm_builtin_aastore
1288
1289 asm_builtin_aastore:
1290         ldgp    gp,0(pv)
1291         beq     a0,nb_aastore_null        /* if null pointer throw exception      */
1292         ldl     t0,offarraysize(a0)       /* load size                            */
1293         lda     sp,-24(sp)                /* allocate stack space                 */
1294         stq     ra,0(sp)                  /* save return address                  */
1295         s8addq  a1,a0,t1                  /* add index*8 to arrayref              */
1296         cmpult  a1,t0,t0                  /* do bound check                       */
1297         beq     t0,nb_aastore_bound       /* if out of bounds throw exception     */
1298         mov     a2,a1                     /* object is second argument            */
1299         stq     t1,8(sp)                  /* save store position                  */
1300         stq     a1,16(sp)                 /* save object                          */
1301         jsr     ra,builtin_canstore       /* builtin_canstore(arrayref,object)    */
1302         ldgp    gp,0(ra)
1303         ldq     ra,0(sp)                  /* restore return address               */
1304         ldq     a0,8(sp)                  /* restore store position               */
1305         ldq     a1,16(sp)                 /* restore object                       */
1306         lda     sp,24(sp)                 /* free stack space                     */
1307         beq     v0,nb_aastore_throw       /* if (false) throw exception           */
1308         stq     a1,offobjarrdata(a0)      /* store objectptr in array             */
1309         jmp     zero,(ra)
1310
1311 nb_aastore_null:
1312         ldq     xptr,string_java_lang_NullPointerException
1313         mov     ra,xpc
1314         jmp     zero,asm_throw_and_handle_nat_exception
1315 #if 0   
1316         subq    sp,8,sp                   /* allocate stack space                 */
1317         stq     ra,0(sp)                  /* save return address                  */
1318     jsr     ra,new_nullpointerexception
1319     ldgp    gp,0(ra)
1320         mov     v0,xptr
1321         ldq     ra,0(sp)
1322         addq    sp,8,sp
1323
1324         mov     ra,xpc                    /* faulting address is return adress    */
1325         br      asm_handle_nat_exception
1326 #endif
1327 nb_aastore_bound:
1328         ldq     ra,0(sp)
1329         lda     sp,24(sp)
1330         mov     ra,xpc
1331         mov     a1,xptr
1332         jmp     zero,asm_throw_and_handle_arrayindexoutofbounds_exception
1333 #if 0
1334         ldq     a0,string_java_lang_ArrayIndexOutOfBoundsException
1335     jsr     ra,new_exception_int      /* a1 already contains the index        */
1336     ldgp    gp,0(ra)
1337         mov     v0,xptr
1338
1339         ldq     ra,0(sp)                  /* restore return address               */
1340         lda     sp,24(sp)                 /* free stack space                     */
1341         mov     ra,xpc                    /* faulting address is return adress    */
1342         br      asm_handle_nat_exception
1343 #endif
1344 nb_aastore_throw:
1345         mov     ra,xpc
1346         ldq     xptr,string_java_lang_ArrayStoreException
1347         jmp     zero,asm_throw_and_handle_nat_exception
1348 #if 0
1349         subq    sp,8,sp                   /* allocate stack space                 */
1350         stq     ra,0(sp)                  /* save return address                  */
1351     jsr     ra,new_arraystoreexception
1352     ldgp    gp,0(ra)
1353         mov     v0,xptr
1354         ldq     ra,0(sp)
1355         addq    sp,8,sp
1356
1357         mov     ra,xpc                    /* faulting address is return adress    */
1358         br      asm_handle_nat_exception
1359 #endif
1360         .end    asm_builtin_aastore
1361
1362
1363 /******************* function asm_initialize_thread_stack **********************
1364 *                                                                              *
1365 *   initialized a thread stack                                                 *
1366 *                                                                              *
1367 *******************************************************************************/
1368
1369         .ent    asm_initialize_thread_stack
1370
1371 asm_initialize_thread_stack:
1372         lda     a1,-128(a1)
1373         stq     zero, 0(a1)
1374         stq     zero, 8(a1)
1375         stq     zero, 16(a1)
1376         stq     zero, 24(a1)
1377         stq     zero, 32(a1)
1378         stq     zero, 40(a1)
1379         stq     zero, 48(a1)
1380         stt     fzero, 56(a1)
1381         stt     fzero, 64(a1)
1382         stt     fzero, 72(a1)
1383         stt     fzero, 80(a1)
1384         stt     fzero, 88(a1)
1385         stt     fzero, 96(a1)
1386         stt     fzero, 104(a1)
1387         stt     fzero, 112(a1)
1388         stq     a0, 120(a1)
1389         mov     a1, v0
1390         jmp     zero,(ra)
1391
1392         .end    asm_initialize_thread_stack
1393
1394
1395 /******************* function asm_perform_threadswitch *************************
1396 *                                                                              *
1397 *   void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop);         *
1398 *                                                                              *
1399 *   performs a threadswitch                                                    *
1400 *                                                                              *
1401 *******************************************************************************/
1402
1403         .ent    asm_perform_threadswitch
1404
1405 asm_perform_threadswitch:
1406         subq    sp,128,sp
1407         stq     s0, 0(sp)
1408         stq     s1, 8(sp)
1409         stq     s2, 16(sp)
1410         stq     s3, 24(sp)
1411         stq     s4, 32(sp)
1412         stq     s5, 40(sp)
1413         stq     s6, 48(sp)
1414         stt     sf0, 56(sp)
1415         stt     sf1, 64(sp)
1416         stt     sf2, 72(sp)
1417         stt     sf3, 80(sp)
1418         stt     sf4, 88(sp)
1419         stt     sf5, 96(sp)
1420         stt     sf6, 104(sp)
1421         stt     sf7, 112(sp)
1422         stq     ra, 120(sp)
1423         stq     sp, 0(a0)
1424         stq     sp, 0(a2)
1425         ldq     sp, 0(a1)
1426         ldq     s0, 0(sp)
1427         ldq     s1, 8(sp)
1428         ldq     s2, 16(sp)
1429         ldq     s3, 24(sp)
1430         ldq     s4, 32(sp)
1431         ldq     s5, 40(sp)
1432         ldq     s6, 48(sp)
1433         ldt     sf0, 56(sp)
1434         ldt     sf1, 64(sp)
1435         ldt     sf2, 72(sp)
1436         ldt     sf3, 80(sp)
1437         ldt     sf4, 88(sp)
1438         ldt     sf5, 96(sp)
1439         ldt     sf6, 104(sp)
1440         ldt     sf7, 112(sp)
1441         ldq     ra, 120(sp)
1442         mov     ra, pv
1443         addq    sp, 128, sp
1444         jmp     zero,(ra)
1445
1446         .end    asm_perform_threadswitch
1447
1448
1449 /********************* function asm_switchstackandcall *************************
1450 *                                                                              *
1451 *  void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1452 *                               void *p);                                      *
1453 *                                                                              *
1454 *   Switches to a new stack, calls a function and switches back.               *
1455 *       a0      new stack pointer                                              *
1456 *       a1      function pointer                                               *
1457 *               a2              pointer to variable where stack top should be stored           *
1458 *               a3      pointer to user data, is passed to the function                *
1459 *                                                                              *
1460 *******************************************************************************/
1461
1462
1463         .ent    asm_switchstackandcall
1464
1465 asm_switchstackandcall:
1466         lda     a0,-2*8(a0)     /* allocate new stack                                 */
1467         stq     ra,0(a0)        /* save return address on new stack                   */
1468         stq     sp,1*8(a0)      /* save old stack pointer on new stack                */
1469         stq sp,0(a2)        /* save old stack pointer to variable                 */
1470         mov     a0,sp           /* switch to new stack                                */
1471         
1472         mov     a1,pv           /* load function pointer                              */
1473         mov a3,a0           /* pass pointer */
1474         jmp     ra,(pv)         /* and call function                                  */
1475
1476         ldq     ra,0(sp)        /* load return address                                */
1477         ldq     sp,1*8(sp)      /* switch to old stack                                */
1478
1479         jmp     zero,(ra)       /* return                                             */
1480
1481         .end    asm_switchstackandcall
1482
1483         .ent    asm_getclassvalues_atomic
1484
1485 asm_getclassvalues_atomic:
1486 _crit_restart2:
1487 _crit_begin2:
1488         ldl     t0,offbaseval(a0)
1489         ldl     t1,offdiffval(a0)
1490         ldl     t2,offbaseval(a1)
1491 _crit_end2:
1492         stl     t0,offcast_super_baseval(a2)
1493         stl     t1,offcast_super_diffval(a2)
1494         stl     t2,offcast_sub_baseval(a2)
1495         jmp      zero,(ra)
1496
1497         .end    asm_getclassvalues_atomic
1498
1499     .data
1500
1501 asm_criticalsections:
1502 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1503     .quad   _crit_begin1
1504     .quad   _crit_end1
1505     .quad   _crit_restart1
1506     .quad   _crit_begin2
1507     .quad   _crit_end2
1508     .quad   _crit_restart2
1509 #endif
1510     .quad   0
1511
1512
1513         .ent asm_prepare_native_stackinfo
1514 asm_prepare_native_stackinfo:
1515         lda sp,-24(sp)
1516         stq ra,0(sp)
1517         jsr ra,builtin_asm_get_stackframeinfo
1518         stq v0,16(sp)
1519         ldq t0,0(v0)
1520         stq t0,8(sp)
1521         ldq ra,0(sp)
1522         lda sp,8(sp)
1523         stq sp,0(v0)
1524         ret
1525         .end asm_prepare_native_stackinfo
1526
1527         .ent asm_remove_native_stackinfo
1528 asm_remove_native_stackinfo:
1529         ldq t0,0(sp)
1530         ldq t1,8(sp)
1531         stq t0,0(t1)
1532         lda sp,40(sp)
1533         ret
1534         .end asm_remove_native_stackinfo
1535
1536 /*
1537  * These are local overrides for various environment variables in Emacs.
1538  * Please do not remove this and leave it at the end of the file, where
1539  * Emacs will automagically detect them.
1540  * ---------------------------------------------------------------------
1541  * Local variables:
1542  * mode: asm
1543  * indent-tabs-mode: t
1544  * c-basic-offset: 4
1545  * tab-width: 4
1546  * End:
1547  */