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