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