asm_calljavafunction2 (untested)
[cacao.git] / src / vm / jit / mips / codegen.c
1 /* jit/mips/codegen.c - machine code generator 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             Reinhard Grafl
30
31    Contains the codegenerator for an MIPS (R4000 or higher) processor.
32    This module generates MIPS machine code for a sequence of
33    intermediate code commands (ICMDs).
34
35    $Id: codegen.c 828 2004-01-03 16:20:06Z stefan $
36
37 */
38
39
40 #include <stdio.h>
41 #include <signal.h>
42 #include <unistd.h>
43 #include <sys/mman.h>
44 #include "types.h"
45 #include "codegen.h"
46 #include "jit.h"
47 #include "reg.h"
48 #include "builtin.h"
49 #include "asmpart.h"
50 #include "jni.h"
51 #include "loader.h"
52 #include "tables.h"
53 #include "native.h"
54
55 /* include independent code generation stuff */
56 #include "codegen.inc"
57 #include "reg.inc"
58
59
60 /* *****************************************************************************
61
62 Datatypes and Register Allocations:
63 ----------------------------------- 
64
65 On 64-bit-machines (like the MIPS) all operands are stored in the
66 registers in a 64-bit form, even when the correspondig JavaVM operands
67 only need 32 bits. This is done by a canonical representation:
68
69 32-bit integers are allways stored as sign-extended 64-bit values (this
70 approach is directly supported by the MIPS architecture and is very easy
71 to implement).
72
73 32-bit-floats are stored in a 64-bit double precision register by simply
74 expanding the exponent and mantissa with zeroes. (also supported by the
75 architecture)
76
77
78 Stackframes:
79
80 The calling conventions and the layout of the stack is  explained in detail
81 in the documention file: calling.doc
82
83 *******************************************************************************/
84
85
86 /* register descripton - array ************************************************/
87
88 /* #define REG_RES   0         reserved register for OS or code generator     */
89 /* #define REG_RET   1         return value register                          */
90 /* #define REG_EXC   2         exception value register (only old jit)        */
91 /* #define REG_SAV   3         (callee) saved register                        */
92 /* #define REG_TMP   4         scratch temporary register (caller saved)      */
93 /* #define REG_ARG   5         argument register (caller saved)               */
94
95 /* #define REG_END   -1        last entry in tables */
96  
97 int nregdescint[] = {
98         REG_RES, REG_RES, REG_RET, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, 
99         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
100         REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
101         REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
102         REG_END };
103
104 /* for use of reserved registers, see comment above */
105         
106 int nregdescfloat[] = {
107         REG_RET, REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
108         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_ARG, REG_ARG, REG_ARG, REG_ARG, 
109         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
110         REG_SAV, REG_TMP, REG_SAV, REG_TMP, REG_SAV, REG_TMP, REG_SAV, REG_TMP,
111         REG_END };
112
113 /* for use of reserved registers, see comment above */
114
115
116 /* parameter allocation mode */
117
118 int nreg_parammode = PARAMMODE_NUMBERED;  
119
120    /* parameter-registers will be allocated by assigning the
121       1. parameter:   int/float-reg a0
122       2. parameter:   int/float-reg a1  
123       3. parameter:   int/float-reg a2 ....
124    */
125
126
127 /* stackframe-infos ***********************************************************/
128
129 int parentargs_base; /* offset in stackframe for the parameter from the caller*/
130
131 /* -> see file 'calling.doc' */
132
133
134 /* additional functions and macros to generate code ***************************/
135
136 /* #define BlockPtrOfPC(pc)        block+block_index[pc] */
137 #define BlockPtrOfPC(pc)  ((basicblock *) iptr->target)
138
139
140 #ifdef STATISTICS
141 #define COUNT_SPILLS count_spills++
142 #else
143 #define COUNT_SPILLS
144 #endif
145
146
147 /* gen_nullptr_check(objreg) */
148
149 #ifdef SOFTNULLPTRCHECK
150 #define gen_nullptr_check(objreg) \
151         if (checknull) {\
152         M_BEQZ((objreg), 0);\
153         codegen_addxnullrefs(mcodeptr);\
154         M_NOP;\
155         }
156 #else
157 #define gen_nullptr_check(objreg)
158 #endif
159
160
161 /* MCODECHECK(icnt) */
162
163 #define MCODECHECK(icnt) \
164         if((mcodeptr+(icnt))>mcodeend)mcodeptr=codegen_increase((u1*)mcodeptr)
165
166 /* M_INTMOVE:
167      generates an integer-move from register a to b.
168      if a and b are the same int-register, no code will be generated.
169 */ 
170
171 #define M_INTMOVE(a,b) if(a!=b){M_MOV(a,b);}
172
173
174 /* M_FLTMOVE:
175     generates a floating-point-move from register a to b.
176     if a and b are the same float-register, no code will be generated
177 */ 
178
179 #define M_FLTMOVE(a,b) {if(a!=b){M_DMOV(a,b);}}
180
181 #define M_TFLTMOVE(t,a,b) \
182         {if(a!=b) \
183                 if ((t)==TYPE_DBL) \
184                     {M_DMOV(a,b);} \
185                 else {M_FMOV(a,b);} \
186         }
187
188 #define M_TFLD(t,a,b,disp) \
189     if ((t)==TYPE_DBL) \
190           {M_DLD(a,b,disp);} \
191     else \
192           {M_FLD(a,b,disp);}
193
194 #define M_TFST(t,a,b,disp) \
195     if ((t)==TYPE_DBL) \
196           {M_DST(a,b,disp);} \
197     else \
198           {M_FST(a,b,disp);}
199
200 #define M_CCFLTMOVE(t1,t2,a,b) \
201         if ((t1)==(t2)) \
202           {M_TFLTMOVE(t1,a,b);} \
203         else \
204           if ((t1)==TYPE_DBL) \
205                 {M_CVTDF(a,b);} \
206           else \
207                 {M_CVTFD(a,b);}
208
209 #define M_CCFLD(t1,t2,a,b,disp) \
210     if ((t1)==(t2)) \
211           {M_DLD(a,b,disp);} \
212         else { \
213           M_DLD(REG_FTMP1,b,disp); \
214           if ((t1)==TYPE_DBL) \
215             {M_CVTDF(REG_FTMP1,a);} \
216           else \
217             {M_CVTFD(REG_FTMP1,a);} \
218         }
219           
220 #define M_CCFST(t1,t2,a,b,disp) \
221     if ((t1)==(t2)) \
222           {M_DST(a,b,disp);} \
223         else { \
224           if ((t1)==TYPE_DBL) \
225             {M_CVTDF(a,REG_FTMP1);} \
226           else \
227             {M_CVTFD(a,REG_FTMP1);} \
228           M_DST(REG_FTMP1,b,disp); \
229         }
230           
231
232 /* var_to_reg_xxx:
233     this function generates code to fetch data from a pseudo-register
234     into a real register. 
235     If the pseudo-register has actually been assigned to a real 
236     register, no code will be emitted, since following operations
237     can use this register directly.
238     
239     v: pseudoregister to be fetched from
240     tempregnum: temporary register to be used if v is actually spilled to ram
241
242     return: the register number, where the operand can be found after 
243             fetching (this wil be either tempregnum or the register
244             number allready given to v)
245 */
246
247 #define var_to_reg_int(regnr,v,tempnr) { \
248         if ((v)->flags & INMEMORY) \
249                 {COUNT_SPILLS;M_LLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \
250         else regnr=(v)->regoff; \
251 }
252
253
254 #define var_to_reg_flt(regnr,v,tempnr) { \
255         if ((v)->flags & INMEMORY) \
256                 {COUNT_SPILLS;M_DLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \
257         else regnr=(v)->regoff; \
258 }
259
260
261 /* reg_of_var:
262     This function determines a register, to which the result of an operation
263     should go, when it is ultimatively intended to store the result in
264     pseudoregister v.
265     If v is assigned to an actual register, this register will be returned.
266     Otherwise (when v is spilled) this function returns tempregnum.
267     If not already done, regoff and flags are set in the stack location.
268 */        
269
270 static int reg_of_var(stackptr v, int tempregnum)
271 {
272         varinfo      *var;
273
274         switch (v->varkind) {
275                 case TEMPVAR:
276                         if (!(v->flags & INMEMORY))
277                                 return(v->regoff);
278                         break;
279                 case STACKVAR:
280                         var = &(interfaces[v->varnum][v->type]);
281                         v->regoff = var->regoff;
282                         if (!(var->flags & INMEMORY))
283                                 return(var->regoff);
284                         break;
285                 case LOCALVAR:
286                         var = &(locals[v->varnum][v->type]);
287                         v->regoff = var->regoff;
288                         if (!(var->flags & INMEMORY))
289                                 return(var->regoff);
290                         break;
291                 case ARGVAR:
292                         v->regoff = v->varnum;
293                         if (IS_FLT_DBL_TYPE(v->type)) {
294                                 if (v->varnum < fltreg_argnum) {
295                                         v->regoff = argfltregs[v->varnum];
296                                         return(argfltregs[v->varnum]);
297                                         }
298                                 }
299                         else
300                                 if (v->varnum < intreg_argnum) {
301                                         v->regoff = argintregs[v->varnum];
302                                         return(argintregs[v->varnum]);
303                                         }
304                         v->regoff -= intreg_argnum;
305                         break;
306                 }
307         v->flags |= INMEMORY;
308         return tempregnum;
309 }
310
311
312 /* store_reg_to_var_xxx:
313     This function generates the code to store the result of an operation
314     back into a spilled pseudo-variable.
315     If the pseudo-variable has not been spilled in the first place, this 
316     function will generate nothing.
317     
318     v ............ Pseudovariable
319     tempregnum ... Number of the temporary registers as returned by
320                    reg_of_var.
321 */      
322
323 #define store_reg_to_var_int(sptr, tempregnum) {       \
324         if ((sptr)->flags & INMEMORY) {                    \
325                 COUNT_SPILLS;                                  \
326                 M_LST(tempregnum, REG_SP, 8 * (sptr)->regoff); \
327                 }                                              \
328         }
329
330 #define store_reg_to_var_flt(sptr, tempregnum) {       \
331         if ((sptr)->flags & INMEMORY) {                    \
332                 COUNT_SPILLS;                                  \
333                 M_DST(tempregnum, REG_SP, 8 * (sptr)->regoff); \
334                 }                                              \
335         }
336
337
338 /* NullPointerException handlers and exception handling initialisation        */
339
340 /* NullPointerException signal handler for hardware null pointer check */
341
342 void catch_NullPointerException(int sig, int code, struct sigcontext *sigctx)
343 {
344         sigset_t nsig;
345         int      instr;
346         long     faultaddr;
347
348         /* Reset signal handler - necessary for SysV, does no harm for BSD */
349
350         instr = *((int*)(sigctx->sc_pc));
351         faultaddr = sigctx->sc_regs[(instr >> 21) & 0x1f];
352
353         if (faultaddr == 0) {
354                 sigemptyset(&nsig);
355                 sigaddset(&nsig, sig);
356                 sigprocmask(SIG_UNBLOCK, &nsig, NULL);           /* unblock signal    */
357                 sigctx->sc_regs[REG_ITMP1_XPTR] =
358                                             (long) proto_java_lang_NullPointerException;
359                 sigctx->sc_regs[REG_ITMP2_XPC] = sigctx->sc_pc;
360                 sigctx->sc_pc = (long) asm_handle_exception;
361                 }
362         else {
363         faultaddr += (long) ((instr << 16) >> 16);
364                 fprintf(stderr, "faulting address: 0x%lx at 0x%lx\n", (long) faultaddr, (long) sigctx->sc_pc);
365                 panic("Stack overflow");
366                 }
367 }
368
369
370 #include <sys/fpu.h>
371
372 void init_exceptions(void)
373 {
374         struct sigaction sa;
375         sigset_t unblockmask;
376
377         createcalljava();
378         
379         /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a
380            dummy allocation here to ensure that the GC is initialized.
381         */
382         heap_allocate(1, 0, NULL);
383
384         /* install signal handlers we need to convert to exceptions */
385
386         sigemptyset(&unblockmask);
387         sa.sa_flags = 0;
388         sa.sa_sigaction = catch_NullPointerException;
389         sigemptyset(&sa.sa_mask);
390
391         if (!checknull) {
392
393 #if defined(SIGSEGV)
394                 sigaction(SIGSEGV, &sa, NULL);
395                 sigaddset(&unblockmask, SIGSEGV);
396 #endif
397
398 #if defined(SIGBUS)
399                 sigaction(SIGBUS, &sa, NULL);
400                 sigaddset(&unblockmask, SIGBUS);
401 #endif
402         }
403
404         sigprocmask(SIG_UNBLOCK, &unblockmask, NULL);
405
406         /* Turn off flush-to-zero */
407         {
408                 union fpc_csr n;
409                 n.fc_word = get_fpc_csr();
410                 n.fc_struct.flush = 0;
411                 set_fpc_csr(n.fc_word);
412         }
413 }
414
415
416 /* function gen_mcode **********************************************************
417
418         generates machine code
419
420 *******************************************************************************/
421
422 #define         MethodPointer   -8
423 #define         FrameSize       -12
424 #define     IsSync          -16
425 #define     IsLeaf          -20
426 #define     IntSave         -24
427 #define     FltSave         -28
428 #define     ExTableSize     -32
429 #define     ExTableStart    -32
430
431 #if POINTERSIZE==8
432 #define     ExEntrySize     -32
433 #define     ExStartPC       -8
434 #define     ExEndPC         -16
435 #define     ExHandlerPC     -24
436 #define     ExCatchType     -32
437 #else
438 #define     ExEntrySize     -16
439 #define     ExStartPC       -4
440 #define     ExEndPC         -8
441 #define     ExHandlerPC     -12
442 #define     ExCatchType     -16
443 #endif
444
445 void codegen()
446 {
447         int  len, s1, s2, s3, d;
448         s4   a;
449         s4          *mcodeptr;
450         stackptr    src;
451         varinfo     *var;
452         basicblock  *bptr;
453         instruction *iptr;
454         xtable *ex;
455
456         {
457         int p, pa, t, l, r;
458
459         savedregs_num = (isleafmethod) ? 0 : 1;           /* space to save the RA */
460
461         /* space to save used callee saved registers */
462
463         savedregs_num += (savintregcnt - maxsavintreguse);
464         savedregs_num += (savfltregcnt - maxsavfltreguse);
465
466         parentargs_base = maxmemuse + savedregs_num;
467
468 #ifdef USE_THREADS                 /* space to save argument of monitor_enter */
469
470         if (checksync && (method->flags & ACC_SYNCHRONIZED))
471                 parentargs_base++;
472
473 #endif
474
475         /* adjust frame size for 16 byte alignment */
476
477         if (parentargs_base & 1)
478                 parentargs_base++;
479
480         /* create method header */
481
482 #if POINTERSIZE==4
483         (void) dseg_addaddress(method);                         /* Filler         */
484 #endif
485         (void) dseg_addaddress(method);                         /* MethodPointer  */
486         (void) dseg_adds4(parentargs_base * 8);                 /* FrameSize      */
487
488 #ifdef USE_THREADS
489
490         /* IsSync contains the offset relative to the stack pointer for the
491            argument of monitor_exit used in the exception handler. Since the
492            offset could be zero and give a wrong meaning of the flag it is
493            offset by one.
494         */
495
496         if (checksync && (method->flags & ACC_SYNCHRONIZED))
497                 (void) dseg_adds4((maxmemuse + 1) * 8);             /* IsSync         */
498         else
499
500 #endif
501
502         (void) dseg_adds4(0);                                   /* IsSync         */
503                                                
504         (void) dseg_adds4(isleafmethod);                        /* IsLeaf         */
505         (void) dseg_adds4(savintregcnt - maxsavintreguse);      /* IntSave        */
506         (void) dseg_adds4(savfltregcnt - maxsavfltreguse);      /* FltSave        */
507         (void) dseg_adds4(exceptiontablelength);                /* ExTableSize    */
508
509         /* create exception table */
510
511         for (ex = extable; ex != NULL; ex = ex->down) {
512
513 #ifdef LOOP_DEBUG       
514                 if (ex->start != NULL)
515                         printf("adding start - %d - ", ex->start->debug_nr);
516                 else {
517                         printf("PANIC - start is NULL");
518                         exit(-1);
519                 }
520 #endif
521
522                 dseg_addtarget(ex->start);
523
524 #ifdef LOOP_DEBUG                       
525                 if (ex->end != NULL)
526                         printf("adding end - %d - ", ex->end->debug_nr);
527                 else {
528                         printf("PANIC - end is NULL");
529                         exit(-1);
530                 }
531 #endif
532
533                 dseg_addtarget(ex->end);
534
535 #ifdef LOOP_DEBUG               
536                 if (ex->handler != NULL)
537                         printf("adding handler - %d\n", ex->handler->debug_nr);
538                 else {
539                         printf("PANIC - handler is NULL");
540                         exit(-1);
541                 }
542 #endif
543
544                 dseg_addtarget(ex->handler);
545            
546                 (void) dseg_addaddress(ex->catchtype);
547                 }
548         
549         /* initialize mcode variables */
550         
551         mcodeptr = (s4*) mcodebase;
552         mcodeend = (s4*) (mcodebase + mcodesize);
553         MCODECHECK(128 + mparamcount);
554
555         /* create stack frame (if necessary) */
556
557         if (parentargs_base)
558                 {M_LDA (REG_SP, REG_SP, -parentargs_base * 8);}
559
560         /* save return address and used callee saved registers */
561
562         p = parentargs_base;
563         if (!isleafmethod)
564                 {p--;  M_LST (REG_RA, REG_SP, 8*p);}
565         for (r = savintregcnt - 1; r >= maxsavintreguse; r--)
566                 {p--; M_LST (savintregs[r], REG_SP, 8 * p);}
567         for (r = savfltregcnt - 1; r >= maxsavfltreguse; r--)
568                 {p--; M_DST (savfltregs[r], REG_SP, 8 * p);}
569
570         /* save monitorenter argument */
571
572 #ifdef USE_THREADS
573         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
574                 if (method->flags & ACC_STATIC) {
575                         p = dseg_addaddress (class);
576                         M_ALD(REG_ITMP1, REG_PV, p);
577                         M_AST(REG_ITMP1, REG_SP, 8 * maxmemuse);
578                         } 
579                 else {
580                         M_AST (argintregs[0], REG_SP, 8 * maxmemuse);
581                         }
582                 }                       
583 #endif
584
585         /* copy argument registers to stack and call trace function with pointer
586            to arguments on stack. ToDo: save floating point registers !!!!!!!!!
587         */
588
589         if (runverbose) {
590                 M_LDA (REG_SP, REG_SP, -(18*8));
591
592                 M_LST(REG_RA,        REG_SP,  1*8);
593
594                 M_LST(argintregs[0], REG_SP,  2*8);
595                 M_LST(argintregs[1], REG_SP,  3*8);
596                 M_LST(argintregs[2], REG_SP,  4*8);
597                 M_LST(argintregs[3], REG_SP,  5*8);
598                 M_LST(argintregs[4], REG_SP,  6*8);
599                 M_LST(argintregs[5], REG_SP,  7*8);
600                 M_LST(argintregs[6], REG_SP,  8*8);
601                 M_LST(argintregs[7], REG_SP,  9*8);
602
603                 M_DST(argfltregs[0], REG_SP, 10*8);
604                 M_DST(argfltregs[1], REG_SP, 11*8);
605                 M_DST(argfltregs[2], REG_SP, 12*8);
606                 M_DST(argfltregs[3], REG_SP, 13*8);
607                 M_DST(argfltregs[4], REG_SP, 14*8);
608                 M_DST(argfltregs[5], REG_SP, 15*8);
609                 M_DST(argfltregs[6], REG_SP, 16*8);
610                 M_DST(argfltregs[7], REG_SP, 17*8);
611
612                 p = dseg_addaddress (method);
613                 M_ALD(REG_ITMP1, REG_PV, p);
614                 M_LST(REG_ITMP1, REG_SP, 0);
615                 p = dseg_addaddress ((void*) (builtin_trace_args));
616                 M_ALD(REG_ITMP3, REG_PV, p);
617                 M_JSR(REG_RA, REG_ITMP3);
618                 M_NOP;
619
620                 M_LLD(REG_RA,        REG_SP,  1*8);
621
622                 M_LLD(argintregs[0], REG_SP,  2*8);
623                 M_LLD(argintregs[1], REG_SP,  3*8);
624                 M_LLD(argintregs[2], REG_SP,  4*8);
625                 M_LLD(argintregs[3], REG_SP,  5*8);
626                 M_LLD(argintregs[4], REG_SP,  6*8);
627                 M_LLD(argintregs[5], REG_SP,  7*8);
628                 M_LLD(argintregs[6], REG_SP,  8*8);
629                 M_LLD(argintregs[7], REG_SP,  9*8);
630
631                 M_DLD(argfltregs[0], REG_SP, 10*8);
632                 M_DLD(argfltregs[1], REG_SP, 11*8);
633                 M_DLD(argfltregs[2], REG_SP, 12*8);
634                 M_DLD(argfltregs[3], REG_SP, 13*8);
635                 M_DLD(argfltregs[4], REG_SP, 14*8);
636                 M_DLD(argfltregs[5], REG_SP, 15*8);
637                 M_DLD(argfltregs[6], REG_SP, 16*8);
638                 M_DLD(argfltregs[7], REG_SP, 17*8);
639
640                 M_LDA (REG_SP, REG_SP, 18*8);
641                 }
642
643         /* take arguments out of register or stack frame */
644
645         for (p = 0, l = 0; p < mparamcount; p++) {
646                 t = mparamtypes[p];
647                 var = &(locals[l][t]);
648                 l++;
649                 if (IS_2_WORD_TYPE(t))    /* increment local counter for 2 word types */
650                         l++;
651                 if (var->type < 0)
652                         continue;
653                 r = var->regoff; 
654                 if (IS_INT_LNG_TYPE(t)) {                    /* integer args          */
655                         if (p < INT_ARG_CNT) {                   /* register arguments    */
656                                 if (!(var->flags & INMEMORY))        /* reg arg -> register   */
657                                         {M_INTMOVE (argintregs[p], r);}
658                                 else                                 /* reg arg -> spilled    */
659                                         M_LST (argintregs[p], REG_SP, 8 * r);
660                                 }
661                         else {                                   /* stack arguments       */
662                                 pa = p - INT_ARG_CNT;
663                                 if (!(var->flags & INMEMORY))        /* stack arg -> register */ 
664                                         M_LLD (r, REG_SP, 8 * (parentargs_base + pa));
665                                 else {                               /* stack arg -> spilled  */
666                                         M_LLD (REG_ITMP1, REG_SP, 8 * (parentargs_base + pa));
667                                         M_LST (REG_ITMP1, REG_SP, 8 * r);
668                                         }
669                                 }
670                         }
671                 else {                                       /* floating args         */   
672                         if (p < FLT_ARG_CNT) {                   /* register arguments    */
673                                 if (!(var->flags & INMEMORY))        /* reg arg -> register   */
674                                         {M_TFLTMOVE (var->type, argfltregs[p], r);}
675                                 else                                             /* reg arg -> spilled    */
676                                         M_DST (argfltregs[p], REG_SP, 8 * r);
677                                 }
678                         else {                                   /* stack arguments       */
679                                 pa = p - FLT_ARG_CNT;
680                                 if (!(var->flags & INMEMORY)) {      /* stack-arg -> register */
681                                         M_DLD (r, REG_SP, 8 * (parentargs_base + pa) );
682                                 } else {                             /* stack-arg -> spilled  */
683                                         M_DLD (REG_FTMP1, REG_SP, 8 * (parentargs_base + pa));
684                                         M_DST (REG_FTMP1, REG_SP, 8 * r);
685                                         }
686                                 }
687                         }
688                 }  /* end for */
689
690         /* call trace function */
691
692 #if 0
693         if (runverbose && !isleafmethod) {
694                 M_LDA (REG_SP, REG_SP, -8);
695                 p = dseg_addaddress (method);
696                 M_ALD(REG_ITMP1, REG_PV, p);
697                 M_AST(REG_ITMP1, REG_SP, 0);
698                 p = dseg_addaddress ((void*) (builtin_trace_args));
699                 M_ALD(REG_ITMP3, REG_PV, p);
700                 M_JSR(REG_RA, REG_ITMP3);
701                 M_NOP;
702                 M_LDA(REG_SP, REG_SP, 8);
703                 }
704 #endif
705
706         /* call monitorenter function */
707
708 #ifdef USE_THREADS
709         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
710                 int disp;
711                 p = dseg_addaddress ((void*) (builtin_monitorenter));
712                 M_ALD(REG_ITMP3, REG_PV, p);
713                 M_JSR(REG_RA, REG_ITMP3);
714                 M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);
715                 disp = -(int)((u1*) mcodeptr - mcodebase);
716                 M_LDA(REG_PV, REG_RA, disp);
717                 }                       
718 #endif
719         }
720
721         /* end of header generation */
722
723         /* walk through all basic blocks */
724         for (bptr = block; bptr != NULL; bptr = bptr->next) {
725
726                 bptr -> mpc = (int)((u1*) mcodeptr - mcodebase);
727
728                 if (bptr->flags >= BBREACHED) {
729
730                 /* branch resolving */
731
732                 {
733                 branchref *brefs;
734                 for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) {
735                         gen_resolvebranch((u1*) mcodebase + brefs->branchpos, 
736                                           brefs->branchpos, bptr->mpc);
737                         }
738                 }
739
740                 /* copy interface registers to their destination */
741
742                 src = bptr->instack;
743                 len = bptr->indepth;
744                 MCODECHECK(64+len);
745                 while (src != NULL) {
746                         len--;
747                         if ((len == 0) && (bptr->type != BBTYPE_STD)) {
748                                 d = reg_of_var(src, REG_ITMP1);
749                                 M_INTMOVE(REG_ITMP1, d);
750                                 store_reg_to_var_int(src, d);
751                                 }
752                         else {
753                                 d = reg_of_var(src, REG_IFTMP);
754                                 if ((src->varkind != STACKVAR)) {
755                                         s2 = src->type;
756                                         if (IS_FLT_DBL_TYPE(s2)) {
757                                                 if (!(interfaces[len][s2].flags & INMEMORY)) {
758                                                         s1 = interfaces[len][s2].regoff;
759                                                         M_TFLTMOVE(s2,s1,d);
760                                                         }
761                                                 else {
762                                                         M_DLD(d, REG_SP, 8 * interfaces[len][s2].regoff);
763                                                         }
764                                                 store_reg_to_var_flt(src, d);
765                                                 }
766                                         else {
767                                                 if (!(interfaces[len][s2].flags & INMEMORY)) {
768                                                         s1 = interfaces[len][s2].regoff;
769                                                         M_INTMOVE(s1,d);
770                                                         }
771                                                 else {
772                                                         M_LLD(d, REG_SP, 8 * interfaces[len][s2].regoff);
773                                                         }
774                                                 store_reg_to_var_int(src, d);
775                                                 }
776                                         }
777                                 }
778                         src = src->prev;
779                         }
780
781                 /* walk through all instructions */
782                 
783                 src = bptr->instack;
784                 len = bptr->icount;
785                 for (iptr = bptr->iinstr;
786                     len > 0;
787                     src = iptr->dst, len--, iptr++) {
788
789         MCODECHECK(64);           /* an instruction usually needs < 64 words      */
790         switch (iptr->opc) {
791
792                 case ICMD_NOP:        /* ...  ==> ...                                 */
793                         break;
794
795                 case ICMD_NULLCHECKPOP: /* ..., objectref  ==> ...                    */
796
797                         var_to_reg_int(s1, src, REG_ITMP1);
798                         M_BEQZ(s1, 0);
799                         codegen_addxnullrefs(mcodeptr);
800                         M_NOP;
801                         break;
802
803                 /* constant operations ************************************************/
804
805 #define ICONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_IADD_IMM(REG_ZERO,c,r);} \
806                     else if(((c)>=0)&&((c)<=0xffff)){M_OR_IMM(REG_ZERO,c,r);} \
807                     else{a=dseg_adds4(c);M_ILD(r,REG_PV,a);}
808
809 #define LCONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_LADD_IMM(REG_ZERO,c,r);} \
810                     else if(((c)>=0)&&((c)<=0xffff)){M_OR_IMM(REG_ZERO,c,r);} \
811                     else{a=dseg_adds8(c);M_LLD(r,REG_PV,a);}
812
813                 case ICMD_ICONST:     /* ...  ==> ..., constant                       */
814                                       /* op1 = 0, val.i = constant                    */
815
816                         d = reg_of_var(iptr->dst, REG_ITMP1);
817                         ICONST(d, iptr->val.i);
818                         store_reg_to_var_int(iptr->dst, d);
819                         break;
820
821                 case ICMD_LCONST:     /* ...  ==> ..., constant                       */
822                                       /* op1 = 0, val.l = constant                    */
823
824                         d = reg_of_var(iptr->dst, REG_ITMP1);
825                         LCONST(d, iptr->val.l);
826                         store_reg_to_var_int(iptr->dst, d);
827                         break;
828
829                 case ICMD_FCONST:     /* ...  ==> ..., constant                       */
830                                       /* op1 = 0, val.f = constant                    */
831
832                         d = reg_of_var (iptr->dst, REG_FTMP1);
833                         a = dseg_addfloat (iptr->val.f);
834                         M_FLD(d, REG_PV, a);
835                         store_reg_to_var_flt (iptr->dst, d);
836                         break;
837                         
838                 case ICMD_DCONST:     /* ...  ==> ..., constant                       */
839                                       /* op1 = 0, val.d = constant                    */
840
841                         d = reg_of_var (iptr->dst, REG_FTMP1);
842                         a = dseg_adddouble (iptr->val.d);
843                         M_DLD(d, REG_PV, a);
844                         store_reg_to_var_flt (iptr->dst, d);
845                         break;
846
847                 case ICMD_ACONST:     /* ...  ==> ..., constant                       */
848                                       /* op1 = 0, val.a = constant                    */
849
850                         d = reg_of_var(iptr->dst, REG_ITMP1);
851                         if (iptr->val.a) {
852                                 a = dseg_addaddress (iptr->val.a);
853                                 M_ALD(d, REG_PV, a);
854                                 }
855                         else {
856                                 M_INTMOVE(REG_ZERO, d);
857                                 }
858                         store_reg_to_var_int(iptr->dst, d);
859                         break;
860
861
862                 /* load/store operations **********************************************/
863
864                 case ICMD_ILOAD:      /* ...  ==> ..., content of local variable      */
865                 case ICMD_LLOAD:      /* op1 = local variable                         */
866                 case ICMD_ALOAD:
867
868                         d = reg_of_var(iptr->dst, REG_ITMP1);
869                         if ((iptr->dst->varkind == LOCALVAR) &&
870                             (iptr->dst->varnum == iptr->op1))
871                                 break;
872                         var = &(locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
873                         if (var->flags & INMEMORY)
874                                 M_LLD(d, REG_SP, 8 * var->regoff);
875                         else
876                                 {M_INTMOVE(var->regoff,d);}
877                         store_reg_to_var_int(iptr->dst, d);
878                         break;
879
880                 case ICMD_FLOAD:      /* ...  ==> ..., content of local variable      */
881                 case ICMD_DLOAD:      /* op1 = local variable                         */
882
883                         d = reg_of_var(iptr->dst, REG_FTMP1);
884                         if ((iptr->dst->varkind == LOCALVAR) &&
885                             (iptr->dst->varnum == iptr->op1))
886                                 break;
887                         var = &(locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
888                         {
889                                 int t2 = ((iptr->opc == ICMD_FLOAD) ? TYPE_FLT : TYPE_DBL);
890                                 if (var->flags & INMEMORY)
891                                         {M_CCFLD(var->type,t2,d, REG_SP, 8 * var->regoff);}
892                                 else
893                                         {M_CCFLTMOVE(var->type,t2,var->regoff,d);}
894                         }
895                         store_reg_to_var_flt(iptr->dst, d);
896                         break;
897
898
899                 case ICMD_ISTORE:     /* ..., value  ==> ...                          */
900                 case ICMD_LSTORE:     /* op1 = local variable                         */
901                 case ICMD_ASTORE:
902
903                         if ((src->varkind == LOCALVAR) &&
904                             (src->varnum == iptr->op1))
905                                 break;
906                         var = &(locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
907                         if (var->flags & INMEMORY) {
908                                 var_to_reg_int(s1, src, REG_ITMP1);
909                                 M_LST(s1, REG_SP, 8 * var->regoff);
910                                 }
911                         else {
912                                 var_to_reg_int(s1, src, var->regoff);
913                                 M_INTMOVE(s1, var->regoff);
914                                 }
915                         break;
916
917                 case ICMD_FSTORE:     /* ..., value  ==> ...                          */
918                 case ICMD_DSTORE:     /* op1 = local variable                         */
919
920                         if ((src->varkind == LOCALVAR) &&
921                             (src->varnum == iptr->op1))
922                                 break;
923                         var = &(locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
924                         {
925                                 int t1 = ((iptr->opc == ICMD_FSTORE) ? TYPE_FLT : TYPE_DBL);
926                                 if (var->flags & INMEMORY) {
927                                         var_to_reg_flt(s1, src, REG_FTMP1);
928                                         M_CCFST(t1,var->type,s1, REG_SP, 8 * var->regoff);
929                                         }
930                                 else {
931                                         var_to_reg_flt(s1, src, var->regoff);
932                                         M_CCFLTMOVE(t1,var->type,s1, var->regoff);
933                                         }
934                         }
935                         break;
936
937
938                 /* pop/dup/swap operations ********************************************/
939
940                 /* attention: double and longs are only one entry in CACAO ICMDs      */
941
942                 case ICMD_POP:        /* ..., value  ==> ...                          */
943                 case ICMD_POP2:       /* ..., value, value  ==> ...                   */
944                         break;
945
946 #define M_COPY(from,to) \
947                         d = reg_of_var(to, REG_IFTMP); \
948                         if ((from->regoff != to->regoff) || \
949                             ((from->flags ^ to->flags) & INMEMORY)) { \
950                                 if (IS_FLT_DBL_TYPE(from->type)) { \
951                                         var_to_reg_flt(s1, from, d); \
952                                         M_TFLTMOVE(from->type,s1,d); \
953                                         store_reg_to_var_flt(to, d); \
954                                         }\
955                                 else { \
956                                         var_to_reg_int(s1, from, d); \
957                                         M_INTMOVE(s1,d); \
958                                         store_reg_to_var_int(to, d); \
959                                         }\
960                                 }
961
962                 case ICMD_DUP:        /* ..., a ==> ..., a, a                         */
963                         M_COPY(src, iptr->dst);
964                         break;
965
966                 case ICMD_DUP_X1:     /* ..., a, b ==> ..., b, a, b                   */
967
968                         M_COPY(src,       iptr->dst->prev->prev);
969
970                 case ICMD_DUP2:       /* ..., a, b ==> ..., a, b, a, b                */
971
972                         M_COPY(src,       iptr->dst);
973                         M_COPY(src->prev, iptr->dst->prev);
974                         break;
975
976                 case ICMD_DUP2_X1:    /* ..., a, b, c ==> ..., b, c, a, b, c          */
977
978                         M_COPY(src->prev,       iptr->dst->prev->prev->prev);
979
980                 case ICMD_DUP_X2:     /* ..., a, b, c ==> ..., c, a, b, c             */
981
982                         M_COPY(src,             iptr->dst);
983                         M_COPY(src->prev,       iptr->dst->prev);
984                         M_COPY(src->prev->prev, iptr->dst->prev->prev);
985                         M_COPY(src, iptr->dst->prev->prev->prev);
986                         break;
987
988                 case ICMD_DUP2_X2:    /* ..., a, b, c, d ==> ..., c, d, a, b, c, d    */
989
990                         M_COPY(src,                   iptr->dst);
991                         M_COPY(src->prev,             iptr->dst->prev);
992                         M_COPY(src->prev->prev,       iptr->dst->prev->prev);
993                         M_COPY(src->prev->prev->prev, iptr->dst->prev->prev->prev);
994                         M_COPY(src,       iptr->dst->prev->prev->prev->prev);
995                         M_COPY(src->prev, iptr->dst->prev->prev->prev->prev->prev);
996                         break;
997
998                 case ICMD_SWAP:       /* ..., a, b ==> ..., b, a                      */
999
1000                         M_COPY(src, iptr->dst->prev);
1001                         M_COPY(src->prev, iptr->dst);
1002                         break;
1003
1004
1005                 /* integer operations *************************************************/
1006
1007                 case ICMD_INEG:       /* ..., value  ==> ..., - value                 */
1008
1009                         var_to_reg_int(s1, src, REG_ITMP1); 
1010                         d = reg_of_var(iptr->dst, REG_ITMP3);
1011                         M_ISUB(REG_ZERO, s1, d);
1012                         store_reg_to_var_int(iptr->dst, d);
1013                         break;
1014
1015                 case ICMD_LNEG:       /* ..., value  ==> ..., - value                 */
1016
1017                         var_to_reg_int(s1, src, REG_ITMP1);
1018                         d = reg_of_var(iptr->dst, REG_ITMP3);
1019                         M_LSUB(REG_ZERO, s1, d);
1020                         store_reg_to_var_int(iptr->dst, d);
1021                         break;
1022
1023                 case ICMD_I2L:        /* ..., value  ==> ..., value                   */
1024
1025                         var_to_reg_int(s1, src, REG_ITMP1);
1026                         d = reg_of_var(iptr->dst, REG_ITMP3);
1027                         M_INTMOVE(s1, d);
1028                         store_reg_to_var_int(iptr->dst, d);
1029                         break;
1030
1031                 case ICMD_L2I:        /* ..., value  ==> ..., value                   */
1032
1033                         var_to_reg_int(s1, src, REG_ITMP1);
1034                         d = reg_of_var(iptr->dst, REG_ITMP3);
1035                         M_ISLL_IMM(s1, 0, d );
1036                         store_reg_to_var_int(iptr->dst, d);
1037                         break;
1038
1039                 case ICMD_INT2BYTE:   /* ..., value  ==> ..., value                   */
1040
1041                         var_to_reg_int(s1, src, REG_ITMP1);
1042                         d = reg_of_var(iptr->dst, REG_ITMP3);
1043                         M_LSLL_IMM(s1, 56, d);
1044                         M_LSRA_IMM( d, 56, d);
1045                         store_reg_to_var_int(iptr->dst, d);
1046                         break;
1047
1048                 case ICMD_INT2CHAR:   /* ..., value  ==> ..., value                   */
1049
1050                         var_to_reg_int(s1, src, REG_ITMP1);
1051                         d = reg_of_var(iptr->dst, REG_ITMP3);
1052             M_CZEXT(s1, d);
1053                         store_reg_to_var_int(iptr->dst, d);
1054                         break;
1055
1056                 case ICMD_INT2SHORT:  /* ..., value  ==> ..., value                   */
1057
1058                         var_to_reg_int(s1, src, REG_ITMP1);
1059                         d = reg_of_var(iptr->dst, REG_ITMP3);
1060                         M_LSLL_IMM(s1, 48, d);
1061                         M_LSRA_IMM( d, 48, d);
1062                         store_reg_to_var_int(iptr->dst, d);
1063                         break;
1064
1065
1066                 case ICMD_IADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1067
1068                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1069                         var_to_reg_int(s2, src, REG_ITMP2);
1070                         d = reg_of_var(iptr->dst, REG_ITMP3);
1071                         M_IADD(s1, s2, d);
1072                         store_reg_to_var_int(iptr->dst, d);
1073                         break;
1074
1075                 case ICMD_IADDCONST:  /* ..., value  ==> ..., value + constant        */
1076                                       /* val.i = constant                             */
1077
1078                         var_to_reg_int(s1, src, REG_ITMP1);
1079                         d = reg_of_var(iptr->dst, REG_ITMP3);
1080                         if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
1081                                 M_IADD_IMM(s1, iptr->val.i, d);
1082                                 }
1083                         else {
1084                                 ICONST(REG_ITMP2, iptr->val.i);
1085                                 M_IADD(s1, REG_ITMP2, d);
1086                                 }
1087                         store_reg_to_var_int(iptr->dst, d);
1088                         break;
1089
1090                 case ICMD_LADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1091
1092                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1093                         var_to_reg_int(s2, src, REG_ITMP2);
1094                         d = reg_of_var(iptr->dst, REG_ITMP3);
1095                         M_LADD(s1, s2, d);
1096                         store_reg_to_var_int(iptr->dst, d);
1097                         break;
1098
1099                 case ICMD_LADDCONST:  /* ..., value  ==> ..., value + constant        */
1100                                       /* val.l = constant                             */
1101
1102                         var_to_reg_int(s1, src, REG_ITMP1);
1103                         d = reg_of_var(iptr->dst, REG_ITMP3);
1104                         if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
1105                                 M_LADD_IMM(s1, iptr->val.l, d);
1106                                 }
1107                         else {
1108                                 LCONST(REG_ITMP2, iptr->val.l);
1109                                 M_LADD(s1, REG_ITMP2, d);
1110                                 }
1111                         store_reg_to_var_int(iptr->dst, d);
1112                         break;
1113
1114                 case ICMD_ISUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1115
1116                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1117                         var_to_reg_int(s2, src, REG_ITMP2);
1118                         d = reg_of_var(iptr->dst, REG_ITMP3);
1119                         M_ISUB(s1, s2, d);
1120                         store_reg_to_var_int(iptr->dst, d);
1121                         break;
1122
1123                 case ICMD_ISUBCONST:  /* ..., value  ==> ..., value + constant        */
1124                                       /* val.i = constant                             */
1125
1126                         var_to_reg_int(s1, src, REG_ITMP1);
1127                         d = reg_of_var(iptr->dst, REG_ITMP3);
1128                         if ((iptr->val.i >= -32767) && (iptr->val.i <= 32768)) {
1129                                 M_IADD_IMM(s1, -iptr->val.i, d);
1130                                 }
1131                         else {
1132                                 ICONST(REG_ITMP2, iptr->val.i);
1133                                 M_ISUB(s1, REG_ITMP2, d);
1134                                 }
1135                         store_reg_to_var_int(iptr->dst, d);
1136                         break;
1137
1138                 case ICMD_LSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1139
1140                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1141                         var_to_reg_int(s2, src, REG_ITMP2);
1142                         d = reg_of_var(iptr->dst, REG_ITMP3);
1143                         M_LSUB(s1, s2, d);
1144                         store_reg_to_var_int(iptr->dst, d);
1145                         break;
1146
1147                 case ICMD_LSUBCONST:  /* ..., value  ==> ..., value - constant        */
1148                                       /* val.l = constant                             */
1149
1150                         var_to_reg_int(s1, src, REG_ITMP1);
1151                         d = reg_of_var(iptr->dst, REG_ITMP3);
1152                         if ((iptr->val.l >= -32767) && (iptr->val.l <= 32768)) {
1153                                 M_LADD_IMM(s1, -iptr->val.l, d);
1154                                 }
1155                         else {
1156                                 LCONST(REG_ITMP2, iptr->val.l);
1157                                 M_LSUB(s1, REG_ITMP2, d);
1158                                 }
1159                         store_reg_to_var_int(iptr->dst, d);
1160                         break;
1161
1162                 case ICMD_IMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
1163
1164                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1165                         var_to_reg_int(s2, src, REG_ITMP2);
1166                         d = reg_of_var(iptr->dst, REG_ITMP3);
1167                         M_IMUL(s1, s2);
1168                         M_MFLO(d);
1169                         M_NOP;
1170                         M_NOP;
1171                         store_reg_to_var_int(iptr->dst, d);
1172                         break;
1173
1174                 case ICMD_IMULCONST:  /* ..., value  ==> ..., value * constant        */
1175                                       /* val.i = constant                             */
1176
1177                         var_to_reg_int(s1, src, REG_ITMP1);
1178                         d = reg_of_var(iptr->dst, REG_ITMP3);
1179                         ICONST(REG_ITMP2, iptr->val.i);
1180                         M_IMUL(s1, REG_ITMP2);
1181                         M_MFLO(d);
1182                         M_NOP;
1183                         M_NOP;
1184                         store_reg_to_var_int(iptr->dst, d);
1185                         break;
1186
1187                 case ICMD_LMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
1188
1189                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1190                         var_to_reg_int(s2, src, REG_ITMP2);
1191                         d = reg_of_var(iptr->dst, REG_ITMP3);
1192                         M_LMUL(s1, s2);
1193                         M_MFLO(d);
1194                         M_NOP;
1195                         M_NOP;
1196                         store_reg_to_var_int(iptr->dst, d);
1197                         break;
1198
1199                 case ICMD_LMULCONST:  /* ..., value  ==> ..., value * constant        */
1200                                       /* val.l = constant                             */
1201
1202                         var_to_reg_int(s1, src, REG_ITMP1);
1203                         d = reg_of_var(iptr->dst, REG_ITMP3);
1204                         LCONST(REG_ITMP2, iptr->val.l);
1205                         M_LMUL(s1, REG_ITMP2);
1206                         M_MFLO(d);
1207                         M_NOP;
1208                         M_NOP;
1209                         store_reg_to_var_int(iptr->dst, d);
1210                         break;
1211
1212                 case ICMD_IDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
1213
1214                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1215                         var_to_reg_int(s2, src, REG_ITMP2);
1216                         d = reg_of_var(iptr->dst, REG_ITMP3);
1217                         M_IDIV(s1, s2);
1218                         M_MFLO(d);
1219                         M_NOP;
1220                         M_NOP;
1221                         store_reg_to_var_int(iptr->dst, d);
1222                         break;
1223 #if 0
1224                 case ICMD_IDIVCONST:  /* ..., value  ==> ..., value / constant        */
1225                                       /* val.i = constant                             */
1226
1227                         var_to_reg_int(s1, src, REG_ITMP1);
1228                         d = reg_of_var(iptr->dst, REG_ITMP3);
1229                         ICONST(REG_ITMP2, iptr->val.i);
1230                         M_IDIV(s1, REG_ITMP2);
1231                         M_MFLO(d);
1232                         M_NOP;
1233                         M_NOP;
1234                         store_reg_to_var_int(iptr->dst, d);
1235                         break;
1236 #endif
1237                 case ICMD_LDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
1238
1239                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1240                         var_to_reg_int(s2, src, REG_ITMP2);
1241                         d = reg_of_var(iptr->dst, REG_ITMP3);
1242                         M_LDIV(s1, s2);
1243                         M_MFLO(d);
1244                         M_NOP;
1245                         M_NOP;
1246                         store_reg_to_var_int(iptr->dst, d);
1247                         break;
1248 #if 0
1249                 case ICMD_LDIVCONST:  /* ..., value  ==> ..., value / constant        */
1250                                       /* val.l = constant                             */
1251
1252                         var_to_reg_int(s1, src, REG_ITMP1);
1253                         d = reg_of_var(iptr->dst, REG_ITMP3);
1254                         LCONST(REG_ITMP2, iptr->val.l);
1255                         M_LDIV(s1, REG_ITMP2);
1256                         M_MFLO(d);
1257                         M_NOP;
1258                         M_NOP;
1259                         store_reg_to_var_int(iptr->dst, d);
1260                         break;
1261 #endif
1262                 case ICMD_IREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
1263
1264                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1265                         var_to_reg_int(s2, src, REG_ITMP2);
1266                         d = reg_of_var(iptr->dst, REG_ITMP3);
1267                         M_IDIV(s1, s2);
1268                         M_MFHI(d);
1269                         M_NOP;
1270                         M_NOP;
1271                         store_reg_to_var_int(iptr->dst, d);
1272                         break;
1273 #if 0
1274                 case ICMD_IREMCONST:  /* ..., value  ==> ..., value % constant        */
1275                                       /* val.i = constant                             */
1276
1277                         var_to_reg_int(s1, src, REG_ITMP1);
1278                         d = reg_of_var(iptr->dst, REG_ITMP3);
1279                         ICONST(REG_ITMP2, iptr->val.i);
1280                         M_IDIV(s1, REG_ITMP2);
1281                         M_MFHI(d);
1282                         M_NOP;
1283                         M_NOP;
1284                         store_reg_to_var_int(iptr->dst, d);
1285                         break;
1286 #endif
1287                 case ICMD_LREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
1288
1289                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1290                         var_to_reg_int(s2, src, REG_ITMP2);
1291                         d = reg_of_var(iptr->dst, REG_ITMP3);
1292                         M_LDIV(s1, s2);
1293                         M_MFHI(d);
1294                         M_NOP;
1295                         M_NOP;
1296                         store_reg_to_var_int(iptr->dst, d);
1297                         break;
1298 #if 0
1299                 case ICMD_LREMCONST:  /* ..., value  ==> ..., value % constant        */
1300                                       /* val.l = constant                             */
1301
1302                         var_to_reg_int(s1, src, REG_ITMP1);
1303                         d = reg_of_var(iptr->dst, REG_ITMP3);
1304                         LCONST(REG_ITMP2, iptr->val.l);
1305                         M_LDIV(s1, REG_ITMP2);
1306                         M_MFHI(d);
1307                         M_NOP;
1308                         M_NOP;
1309                         store_reg_to_var_int(iptr->dst, d);
1310                         break;
1311 #endif
1312                 case ICMD_IDIVPOW2:   /* ..., value  ==> ..., value << constant       */
1313                 case ICMD_LDIVPOW2:   /* val.i = constant                             */
1314                                       
1315                         var_to_reg_int(s1, src, REG_ITMP1);
1316                         d = reg_of_var(iptr->dst, REG_ITMP3);
1317                         M_LSRA_IMM(s1, 63, REG_ITMP2);
1318                         M_LSRL_IMM(REG_ITMP2, 64 - iptr->val.i, REG_ITMP2);
1319                         M_LADD(s1, REG_ITMP2, REG_ITMP2);
1320                         M_LSRA_IMM(REG_ITMP2, iptr->val.i, d);
1321                         store_reg_to_var_int(iptr->dst, d);
1322                         break;
1323
1324                 case ICMD_ISHL:       /* ..., val1, val2  ==> ..., val1 << val2       */
1325
1326                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1327                         var_to_reg_int(s2, src, REG_ITMP2);
1328                         d = reg_of_var(iptr->dst, REG_ITMP3);
1329                         M_ISLL(s1, s2, d);
1330                         store_reg_to_var_int(iptr->dst, d);
1331                         break;
1332
1333                 case ICMD_ISHLCONST:  /* ..., value  ==> ..., value << constant       */
1334                                       /* val.i = constant                             */
1335
1336                         var_to_reg_int(s1, src, REG_ITMP1);
1337                         d = reg_of_var(iptr->dst, REG_ITMP3);
1338                         M_ISLL_IMM(s1, iptr->val.i, d);
1339                         store_reg_to_var_int(iptr->dst, d);
1340                         break;
1341
1342                 case ICMD_ISHR:       /* ..., val1, val2  ==> ..., val1 >> val2       */
1343
1344                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1345                         var_to_reg_int(s2, src, REG_ITMP2);
1346                         d = reg_of_var(iptr->dst, REG_ITMP3);
1347                         M_ISRA(s1, s2, d);
1348                         store_reg_to_var_int(iptr->dst, d);
1349                         break;
1350
1351                 case ICMD_ISHRCONST:  /* ..., value  ==> ..., value >> constant       */
1352                                       /* val.i = constant                             */
1353
1354                         var_to_reg_int(s1, src, REG_ITMP1);
1355                         d = reg_of_var(iptr->dst, REG_ITMP3);
1356                         M_ISRA_IMM(s1, iptr->val.i, d);
1357                         store_reg_to_var_int(iptr->dst, d);
1358                         break;
1359
1360                 case ICMD_IUSHR:      /* ..., val1, val2  ==> ..., val1 >>> val2      */
1361
1362                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1363                         var_to_reg_int(s2, src, REG_ITMP2);
1364                         d = reg_of_var(iptr->dst, REG_ITMP3);
1365                         M_ISRL(s1, s2, d);
1366                         store_reg_to_var_int(iptr->dst, d);
1367                         break;
1368
1369                 case ICMD_IUSHRCONST: /* ..., value  ==> ..., value >>> constant      */
1370                                       /* val.i = constant                             */
1371
1372                         var_to_reg_int(s1, src, REG_ITMP1);
1373                         d = reg_of_var(iptr->dst, REG_ITMP3);
1374                         M_ISRL_IMM(s1, iptr->val.i, d);
1375                         store_reg_to_var_int(iptr->dst, d);
1376                         break;
1377
1378                 case ICMD_LSHL:       /* ..., val1, val2  ==> ..., val1 << val2       */
1379
1380                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1381                         var_to_reg_int(s2, src, REG_ITMP2);
1382                         d = reg_of_var(iptr->dst, REG_ITMP3);
1383                         M_LSLL(s1, s2, d);
1384                         store_reg_to_var_int(iptr->dst, d);
1385                         break;
1386
1387                 case ICMD_LSHLCONST:  /* ..., value  ==> ..., value << constant       */
1388                                       /* val.i = constant                             */
1389
1390                         var_to_reg_int(s1, src, REG_ITMP1);
1391                         d = reg_of_var(iptr->dst, REG_ITMP3);
1392                         M_LSLL_IMM(s1, iptr->val.i, d);
1393                         store_reg_to_var_int(iptr->dst, d);
1394                         break;
1395
1396                 case ICMD_LSHR:       /* ..., val1, val2  ==> ..., val1 >> val2       */
1397
1398                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1399                         var_to_reg_int(s2, src, REG_ITMP2);
1400                         d = reg_of_var(iptr->dst, REG_ITMP3);
1401                         M_LSRA(s1, s2, d);
1402                         store_reg_to_var_int(iptr->dst, d);
1403                         break;
1404
1405                 case ICMD_LSHRCONST:  /* ..., value  ==> ..., value >> constant       */
1406                                       /* val.i = constant                             */
1407
1408                         var_to_reg_int(s1, src, REG_ITMP1);
1409                         d = reg_of_var(iptr->dst, REG_ITMP3);
1410                         M_LSRA_IMM(s1, iptr->val.i, d);
1411                         store_reg_to_var_int(iptr->dst, d);
1412                         break;
1413
1414                 case ICMD_LUSHR:      /* ..., val1, val2  ==> ..., val1 >>> val2      */
1415
1416                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1417                         var_to_reg_int(s2, src, REG_ITMP2);
1418                         d = reg_of_var(iptr->dst, REG_ITMP3);
1419                         M_LSRL(s1, s2, d);
1420                         store_reg_to_var_int(iptr->dst, d);
1421                         break;
1422
1423                 case ICMD_LUSHRCONST: /* ..., value  ==> ..., value >>> constant      */
1424                                       /* val.i = constant                             */
1425
1426                         var_to_reg_int(s1, src, REG_ITMP1);
1427                         d = reg_of_var(iptr->dst, REG_ITMP3);
1428                         M_LSRL_IMM(s1, iptr->val.i, d);
1429                         store_reg_to_var_int(iptr->dst, d);
1430                         break;
1431
1432                 case ICMD_IAND:       /* ..., val1, val2  ==> ..., val1 & val2        */
1433                 case ICMD_LAND:
1434
1435                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1436                         var_to_reg_int(s2, src, REG_ITMP2);
1437                         d = reg_of_var(iptr->dst, REG_ITMP3);
1438                         M_AND(s1, s2, d);
1439                         store_reg_to_var_int(iptr->dst, d);
1440                         break;
1441
1442                 case ICMD_IANDCONST:  /* ..., value  ==> ..., value & constant        */
1443                                       /* val.i = constant                             */
1444
1445                         var_to_reg_int(s1, src, REG_ITMP1);
1446                         d = reg_of_var(iptr->dst, REG_ITMP3);
1447                         if ((iptr->val.i >= 0) && (iptr->val.i <= 0xffff)) {
1448                                 M_AND_IMM(s1, iptr->val.i, d);
1449                                 }
1450                         else {
1451                                 ICONST(REG_ITMP2, iptr->val.i);
1452                                 M_AND(s1, REG_ITMP2, d);
1453                                 }
1454                         store_reg_to_var_int(iptr->dst, d);
1455                         break;
1456
1457                 case ICMD_IREMPOW2:   /* ..., value  ==> ..., value % constant        */
1458                                       /* val.i = constant                             */
1459
1460                         var_to_reg_int(s1, src, REG_ITMP1);
1461                         d = reg_of_var(iptr->dst, REG_ITMP3);
1462                         if (s1 == d) {
1463                                 M_MOV(s1, REG_ITMP1);
1464                                 s1 = REG_ITMP1;
1465                                 }
1466                         if ((iptr->val.i >= 0) && (iptr->val.i <= 0xffff)) {
1467                                 M_AND_IMM(s1, iptr->val.i, d);
1468                                 M_BGEZ(s1, 4);
1469                                 M_NOP;
1470                                 M_ISUB(REG_ZERO, s1, d);
1471                                 M_AND_IMM(d, iptr->val.i, d);
1472                                 }
1473                         else {
1474                                 ICONST(REG_ITMP2, iptr->val.i);
1475                                 M_AND(s1, REG_ITMP2, d);
1476                                 M_BGEZ(s1, 4);
1477                                 M_NOP;
1478                                 M_ISUB(REG_ZERO, s1, d);
1479                                 M_AND(d, REG_ITMP2, d);
1480                                 }
1481                         M_ISUB(REG_ZERO, d, d);
1482                         store_reg_to_var_int(iptr->dst, d);
1483                         break;
1484
1485                 case ICMD_IREM0X10001:  /* ..., value  ==> ..., value % 0x100001      */
1486                 
1487 /*          b = value & 0xffff;
1488                         a = value >> 16;
1489                         a = ((b - a) & 0xffff) + (b < a);
1490 */
1491                         var_to_reg_int(s1, src, REG_ITMP1);
1492                         d = reg_of_var(iptr->dst, REG_ITMP3);
1493                         if (s1 == d) {
1494                                 M_MOV(s1, REG_ITMP3);
1495                                 s1 = REG_ITMP3;
1496                                 }
1497                         M_BLTZ(s1, 7);
1498             M_CZEXT(s1, REG_ITMP2);                             /* delay slot */
1499                         M_ISRA_IMM(s1, 16, d);
1500                         M_CMPLT(REG_ITMP2, d, REG_ITMP1);
1501                         M_ISUB(REG_ITMP2, d, d);
1502             M_CZEXT(d, d);
1503                         M_BR(7);
1504                         M_IADD(d, REG_ITMP1, d);                            /* delay slot */
1505
1506                         M_LUI(REG_ITMP2, 1);
1507                         M_IADD_IMM(REG_ITMP2, 1, REG_ITMP2);
1508                         M_IDIV(s1, REG_ITMP2);
1509                         M_MFHI(d);
1510                         M_NOP;
1511                         M_NOP;
1512                         store_reg_to_var_int(iptr->dst, d);
1513                         break;
1514
1515                 case ICMD_LANDCONST:  /* ..., value  ==> ..., value & constant        */
1516                                       /* val.l = constant                             */
1517
1518                         var_to_reg_int(s1, src, REG_ITMP1);
1519                         d = reg_of_var(iptr->dst, REG_ITMP3);
1520                         if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
1521                                 M_AND_IMM(s1, iptr->val.l, d);
1522                                 }
1523                         else {
1524                                 LCONST(REG_ITMP2, iptr->val.l);
1525                                 M_AND(s1, REG_ITMP2, d);
1526                                 }
1527                         store_reg_to_var_int(iptr->dst, d);
1528                         break;
1529
1530                 case ICMD_LREMPOW2:   /* ..., value  ==> ..., value % constant        */
1531                                       /* val.l = constant                             */
1532
1533                         var_to_reg_int(s1, src, REG_ITMP1);
1534                         d = reg_of_var(iptr->dst, REG_ITMP3);
1535                         if (s1 == d) {
1536                                 M_MOV(s1, REG_ITMP1);
1537                                 s1 = REG_ITMP1;
1538                                 }
1539                         if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
1540                                 M_AND_IMM(s1, iptr->val.l, d);
1541                                 M_BGEZ(s1, 4);
1542                                 M_NOP;
1543                                 M_LSUB(REG_ZERO, s1, d);
1544                                 M_AND_IMM(d, iptr->val.l, d);
1545                                 }
1546                         else {
1547                                 LCONST(REG_ITMP2, iptr->val.l);
1548                                 M_AND(s1, REG_ITMP2, d);
1549                                 M_BGEZ(s1, 4);
1550                                 M_NOP;
1551                                 M_LSUB(REG_ZERO, s1, d);
1552                                 M_AND(d, REG_ITMP2, d);
1553                                 }
1554                         M_LSUB(REG_ZERO, d, d);
1555                         store_reg_to_var_int(iptr->dst, d);
1556                         break;
1557
1558                 case ICMD_LREM0X10001:/* ..., value  ==> ..., value % 0x10001         */
1559
1560                         var_to_reg_int(s1, src, REG_ITMP1);
1561                         d = reg_of_var(iptr->dst, REG_ITMP3);
1562                         M_LUI(REG_ITMP2, 1);
1563                         M_LADD_IMM(REG_ITMP2, 1, REG_ITMP2);
1564                         M_LDIV(s1, REG_ITMP2);
1565                         M_MFHI(d);
1566                         M_NOP;
1567                         M_NOP;
1568                         store_reg_to_var_int(iptr->dst, d);
1569                         break;
1570
1571                 case ICMD_IOR:        /* ..., val1, val2  ==> ..., val1 | val2        */
1572                 case ICMD_LOR:
1573
1574                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1575                         var_to_reg_int(s2, src, REG_ITMP2);
1576                         d = reg_of_var(iptr->dst, REG_ITMP3);
1577                         M_OR( s1,s2, d);
1578                         store_reg_to_var_int(iptr->dst, d);
1579                         break;
1580
1581                 case ICMD_IORCONST:   /* ..., value  ==> ..., value | constant        */
1582                                       /* val.i = constant                             */
1583
1584                         var_to_reg_int(s1, src, REG_ITMP1);
1585                         d = reg_of_var(iptr->dst, REG_ITMP3);
1586                         if ((iptr->val.i >= 0) && (iptr->val.i <= 0xffff)) {
1587                                 M_OR_IMM(s1, iptr->val.i, d);
1588                                 }
1589                         else {
1590                                 ICONST(REG_ITMP2, iptr->val.i);
1591                                 M_OR(s1, REG_ITMP2, d);
1592                                 }
1593                         store_reg_to_var_int(iptr->dst, d);
1594                         break;
1595
1596                 case ICMD_LORCONST:   /* ..., value  ==> ..., value | constant        */
1597                                       /* val.l = constant                             */
1598
1599                         var_to_reg_int(s1, src, REG_ITMP1);
1600                         d = reg_of_var(iptr->dst, REG_ITMP3);
1601                         if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
1602                                 M_OR_IMM(s1, iptr->val.l, d);
1603                                 }
1604                         else {
1605                                 LCONST(REG_ITMP2, iptr->val.l);
1606                                 M_OR(s1, REG_ITMP2, d);
1607                                 }
1608                         store_reg_to_var_int(iptr->dst, d);
1609                         break;
1610
1611                 case ICMD_IXOR:       /* ..., val1, val2  ==> ..., val1 ^ val2        */
1612                 case ICMD_LXOR:
1613
1614                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1615                         var_to_reg_int(s2, src, REG_ITMP2);
1616                         d = reg_of_var(iptr->dst, REG_ITMP3);
1617                         M_XOR(s1, s2, d);
1618                         store_reg_to_var_int(iptr->dst, d);
1619                         break;
1620
1621                 case ICMD_IXORCONST:  /* ..., value  ==> ..., value ^ constant        */
1622                                       /* val.i = constant                             */
1623
1624                         var_to_reg_int(s1, src, REG_ITMP1);
1625                         d = reg_of_var(iptr->dst, REG_ITMP3);
1626                         if ((iptr->val.i >= 0) && (iptr->val.i <= 0xffff)) {
1627                                 M_XOR_IMM(s1, iptr->val.i, d);
1628                                 }
1629                         else {
1630                                 ICONST(REG_ITMP2, iptr->val.i);
1631                                 M_XOR(s1, REG_ITMP2, d);
1632                                 }
1633                         store_reg_to_var_int(iptr->dst, d);
1634                         break;
1635
1636                 case ICMD_LXORCONST:  /* ..., value  ==> ..., value ^ constant        */
1637                                       /* val.l = constant                             */
1638
1639                         var_to_reg_int(s1, src, REG_ITMP1);
1640                         d = reg_of_var(iptr->dst, REG_ITMP3);
1641                         if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
1642                                 M_XOR_IMM(s1, iptr->val.l, d);
1643                                 }
1644                         else {
1645                                 LCONST(REG_ITMP2, iptr->val.l);
1646                                 M_XOR(s1, REG_ITMP2, d);
1647                                 }
1648                         store_reg_to_var_int(iptr->dst, d);
1649                         break;
1650
1651
1652                 case ICMD_LCMP:       /* ..., val1, val2  ==> ..., val1 cmp val2      */
1653
1654                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1655                         var_to_reg_int(s2, src, REG_ITMP2);
1656                         d = reg_of_var(iptr->dst, REG_ITMP3);
1657                         M_CMPLT(s1, s2, REG_ITMP3);
1658                         M_CMPLT(s2, s1, REG_ITMP1);
1659                         M_LSUB (REG_ITMP1, REG_ITMP3, d);
1660                         store_reg_to_var_int(iptr->dst, d);
1661                         break;
1662
1663
1664                 case ICMD_IINC:       /* ..., value  ==> ..., value + constant        */
1665                                       /* op1 = variable, val.i = constant             */
1666
1667                         var = &(locals[iptr->op1][TYPE_INT]);
1668                         if (var->flags & INMEMORY) {
1669                                 s1 = REG_ITMP1;
1670                                 M_LLD(s1, REG_SP, 8 * var->regoff);
1671                                 }
1672                         else
1673                                 s1 = var->regoff;
1674                         M_IADD_IMM(s1, iptr->val.i, s1);
1675                         if (var->flags & INMEMORY)
1676                                 M_LST(s1, REG_SP, 8 * var->regoff);
1677                         break;
1678
1679
1680                 /* floating operations ************************************************/
1681
1682                 case ICMD_FNEG:       /* ..., value  ==> ..., - value                 */
1683
1684                         var_to_reg_flt(s1, src, REG_FTMP1);
1685                         d = reg_of_var(iptr->dst, REG_FTMP3);
1686                         M_FNEG(s1, d);
1687                         store_reg_to_var_flt(iptr->dst, d);
1688                         break;
1689
1690                 case ICMD_DNEG:       /* ..., value  ==> ..., - value                 */
1691
1692                         var_to_reg_flt(s1, src, REG_FTMP1);
1693                         d = reg_of_var(iptr->dst, REG_FTMP3);
1694                         M_DNEG(s1, d);
1695                         store_reg_to_var_flt(iptr->dst, d);
1696                         break;
1697
1698                 case ICMD_FADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1699
1700                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1701                         var_to_reg_flt(s2, src, REG_FTMP2);
1702                         d = reg_of_var(iptr->dst, REG_FTMP3);
1703                         M_FADD(s1, s2, d);
1704                         store_reg_to_var_flt(iptr->dst, d);
1705                         break;
1706
1707                 case ICMD_DADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
1708
1709                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1710                         var_to_reg_flt(s2, src, REG_FTMP2);
1711                         d = reg_of_var(iptr->dst, REG_FTMP3);
1712                         M_DADD(s1, s2, d);
1713                         store_reg_to_var_flt(iptr->dst, d);
1714                         break;
1715
1716                 case ICMD_FSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1717
1718                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1719                         var_to_reg_flt(s2, src, REG_FTMP2);
1720                         d = reg_of_var(iptr->dst, REG_FTMP3);
1721                         M_FSUB(s1, s2, d);
1722                         store_reg_to_var_flt(iptr->dst, d);
1723                         break;
1724
1725                 case ICMD_DSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
1726
1727                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1728                         var_to_reg_flt(s2, src, REG_FTMP2);
1729                         d = reg_of_var(iptr->dst, REG_FTMP3);
1730                         M_DSUB(s1, s2, d);
1731                         store_reg_to_var_flt(iptr->dst, d);
1732                         break;
1733
1734                 case ICMD_FMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
1735
1736                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1737                         var_to_reg_flt(s2, src, REG_FTMP2);
1738                         d = reg_of_var(iptr->dst, REG_FTMP3);
1739                         M_FMUL(s1, s2, d);
1740                         store_reg_to_var_flt(iptr->dst, d);
1741                         break;
1742
1743                 case ICMD_DMUL:       /* ..., val1, val2  ==> ..., val1 *** val2        */
1744
1745                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1746                         var_to_reg_flt(s2, src, REG_FTMP2);
1747                         d = reg_of_var(iptr->dst, REG_FTMP3);
1748                         M_DMUL(s1, s2, d);
1749                         store_reg_to_var_flt(iptr->dst, d);
1750                         break;
1751
1752                 case ICMD_FDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
1753
1754                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1755                         var_to_reg_flt(s2, src, REG_FTMP2);
1756                         d = reg_of_var(iptr->dst, REG_FTMP3);
1757                         M_FDIV(s1, s2, d);
1758                         store_reg_to_var_flt(iptr->dst, d);
1759                         break;
1760
1761                 case ICMD_DDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
1762
1763                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1764                         var_to_reg_flt(s2, src, REG_FTMP2);
1765                         d = reg_of_var(iptr->dst, REG_FTMP3);
1766                         M_DDIV(s1, s2, d);
1767                         store_reg_to_var_flt(iptr->dst, d);
1768                         break;
1769                 
1770                 case ICMD_FREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
1771                         panic("FREM");
1772
1773                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1774                         var_to_reg_flt(s2, src, REG_FTMP2);
1775                         d = reg_of_var(iptr->dst, REG_FTMP3);
1776                         M_FDIV(s1,s2, REG_FTMP3);
1777                         M_FLOORFL(REG_FTMP3, REG_FTMP3);
1778                         M_CVTLF(REG_FTMP3, REG_FTMP3);
1779                         M_FMUL(REG_FTMP3, s2, REG_FTMP3);
1780                         M_FSUB(s1, REG_FTMP3, d);
1781                         store_reg_to_var_flt(iptr->dst, d);
1782                     break;
1783
1784                 case ICMD_DREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
1785
1786                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1787                         var_to_reg_flt(s2, src, REG_FTMP2);
1788                         d = reg_of_var(iptr->dst, REG_FTMP3);
1789                         M_DDIV(s1,s2, REG_FTMP3);
1790                         M_FLOORDL(REG_FTMP3, REG_FTMP3);
1791                         M_CVTLD(REG_FTMP3, REG_FTMP3);
1792                         M_DMUL(REG_FTMP3, s2, REG_FTMP3);
1793                         M_DSUB(s1, REG_FTMP3, d);
1794                         store_reg_to_var_flt(iptr->dst, d);
1795                     break;
1796
1797                 case ICMD_I2F:       /* ..., value  ==> ..., (float) value            */
1798                 case ICMD_L2F:
1799                         var_to_reg_int(s1, src, REG_ITMP1);
1800                         d = reg_of_var(iptr->dst, REG_FTMP3);
1801                         M_MOVLD(s1, d);
1802                         M_CVTLF(d, d);
1803                         store_reg_to_var_flt(iptr->dst, d);
1804                         break;
1805
1806                 case ICMD_I2D:       /* ..., value  ==> ..., (double) value           */
1807                 case ICMD_L2D:
1808                         var_to_reg_int(s1, src, REG_ITMP1);
1809                         d = reg_of_var(iptr->dst, REG_FTMP3);
1810                         M_MOVLD(s1, d);
1811                         M_CVTLD(d, d);
1812                         store_reg_to_var_flt(iptr->dst, d);
1813                         break;
1814                         
1815                 case ICMD_F2I:       /* ..., (float) value  ==> ..., (int) value      */
1816
1817                         var_to_reg_flt(s1, src, REG_FTMP1);
1818                         d = reg_of_var(iptr->dst, REG_ITMP3);
1819                         M_TRUNCFI(s1, REG_FTMP1);
1820                         M_MOVDI(REG_FTMP1, d);
1821                         M_NOP;
1822                         store_reg_to_var_int(iptr->dst, d);
1823                         break;
1824                 
1825                 case ICMD_D2I:       /* ..., (double) value  ==> ..., (int) value     */
1826
1827                         var_to_reg_flt(s1, src, REG_FTMP1);
1828                         d = reg_of_var(iptr->dst, REG_ITMP3);
1829                         M_TRUNCDI(s1, REG_FTMP1);
1830                         M_MOVDI(REG_FTMP1, d);
1831                         M_NOP;
1832                         store_reg_to_var_int(iptr->dst, d);
1833                         break;
1834                 
1835                 case ICMD_F2L:       /* ..., (float) value  ==> ..., (long) value     */
1836
1837                         var_to_reg_flt(s1, src, REG_FTMP1);
1838                         d = reg_of_var(iptr->dst, REG_ITMP3);
1839                         M_TRUNCFL(s1, REG_FTMP1);
1840                         M_MOVDL(REG_FTMP1, d);
1841                         M_NOP;
1842                         store_reg_to_var_int(iptr->dst, d);
1843                         break;
1844
1845                 case ICMD_D2L:       /* ..., (double) value  ==> ..., (long) value    */
1846
1847                         var_to_reg_flt(s1, src, REG_FTMP1);
1848                         d = reg_of_var(iptr->dst, REG_ITMP3);
1849                         M_TRUNCDL(s1, REG_FTMP1);
1850                         M_MOVDL(REG_FTMP1, d);
1851                         M_NOP;
1852                         store_reg_to_var_int(iptr->dst, d);
1853                         break;
1854
1855                 case ICMD_F2D:       /* ..., value  ==> ..., (double) value           */
1856
1857                         var_to_reg_flt(s1, src, REG_FTMP1);
1858                         d = reg_of_var(iptr->dst, REG_FTMP3);
1859                         M_CVTFD(s1, d);
1860                         store_reg_to_var_flt(iptr->dst, d);
1861                         break;
1862                                         
1863                 case ICMD_D2F:       /* ..., value  ==> ..., (double) value           */
1864
1865                         var_to_reg_flt(s1, src, REG_FTMP1);
1866                         d = reg_of_var(iptr->dst, REG_FTMP3);
1867                         M_CVTDF(s1, d);
1868                         store_reg_to_var_flt(iptr->dst, d);
1869                         break;
1870                 
1871                 case ICMD_FCMPL:      /* ..., val1, val2  ==> ..., val1 fcmpl val2    */
1872
1873                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1874                         var_to_reg_flt(s2, src, REG_FTMP2);
1875                         d = reg_of_var(iptr->dst, REG_ITMP3);
1876                         M_FCMPULEF(s1, s2);
1877                         M_FBT(3);
1878                         M_LADD_IMM(REG_ZERO, 1, d);
1879                         M_BR(4);
1880                         M_NOP;
1881                         M_FCMPEQF(s1, s2);
1882                         M_LSUB_IMM(REG_ZERO, 1, d);
1883                         M_CMOVT(REG_ZERO, d);
1884                         store_reg_to_var_int(iptr->dst, d);
1885                         break;
1886
1887                 case ICMD_DCMPL:      /* ..., val1, val2  ==> ..., val1 fcmpl val2    */
1888
1889                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1890                         var_to_reg_flt(s2, src, REG_FTMP2);
1891                         d = reg_of_var(iptr->dst, REG_ITMP3);
1892                         M_FCMPULED(s1, s2);
1893                         M_FBT(3);
1894                         M_LADD_IMM(REG_ZERO, 1, d);
1895                         M_BR(4);
1896                         M_NOP;
1897                         M_FCMPEQD(s1, s2);
1898                         M_LSUB_IMM(REG_ZERO, 1, d);
1899                         M_CMOVT(REG_ZERO, d);
1900                         store_reg_to_var_int(iptr->dst, d);
1901                         break;
1902                         
1903                 case ICMD_FCMPG:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
1904
1905                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1906                         var_to_reg_flt(s2, src, REG_FTMP2);
1907                         d = reg_of_var(iptr->dst, REG_ITMP3);
1908                         M_FCMPOLTF(s1, s2);
1909                         M_FBF(3);
1910                         M_LSUB_IMM(REG_ZERO, 1, d);
1911                         M_BR(4);
1912                         M_NOP;
1913                         M_FCMPEQF(s1, s2);
1914                         M_LADD_IMM(REG_ZERO, 1, d);
1915                         M_CMOVT(REG_ZERO, d);
1916                         store_reg_to_var_int(iptr->dst, d);
1917                         break;
1918
1919                 case ICMD_DCMPG:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
1920
1921                         var_to_reg_flt(s1, src->prev, REG_FTMP1);
1922                         var_to_reg_flt(s2, src, REG_FTMP2);
1923                         d = reg_of_var(iptr->dst, REG_ITMP3);
1924                         M_FCMPOLTD(s1, s2);
1925                         M_FBF(3);
1926                         M_LSUB_IMM(REG_ZERO, 1, d);
1927                         M_BR(4);
1928                         M_NOP;
1929                         M_FCMPEQD(s1, s2);
1930                         M_LADD_IMM(REG_ZERO, 1, d);
1931                         M_CMOVT(REG_ZERO, d);
1932                         store_reg_to_var_int(iptr->dst, d);
1933                         break;
1934
1935
1936                 /* memory operations **************************************************/
1937
1938 #define gen_bound_check \
1939                         if (checkbounds) {\
1940                                 M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
1941                                 M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
1942                                 M_BEQZ(REG_ITMP3, 0);\
1943                                 codegen_addxboundrefs(mcodeptr);\
1944                                 M_NOP;\
1945                                 }
1946
1947                 case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
1948
1949                         var_to_reg_int(s1, src, REG_ITMP1);
1950                         d = reg_of_var(iptr->dst, REG_ITMP3);
1951                         gen_nullptr_check(s1);
1952                         M_ILD(d, s1, OFFSET(java_arrayheader, size));
1953                         store_reg_to_var_int(iptr->dst, d);
1954                         break;
1955
1956                 case ICMD_AALOAD:     /* ..., arrayref, index  ==> ..., value         */
1957
1958                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1959                         var_to_reg_int(s2, src, REG_ITMP2);
1960                         d = reg_of_var(iptr->dst, REG_ITMP3);
1961                         if (iptr->op1 == 0) {
1962                                 gen_nullptr_check(s1);
1963                                 gen_bound_check;
1964                                 }
1965                         M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
1966                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1967                         M_ALD(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1968                         store_reg_to_var_int(iptr->dst, d);
1969                         break;
1970
1971                 case ICMD_IALOAD:     /* ..., arrayref, index  ==> ..., value         */
1972
1973                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1974                         var_to_reg_int(s2, src, REG_ITMP2);
1975                         d = reg_of_var(iptr->dst, REG_ITMP3);
1976                         if (iptr->op1 == 0) {
1977                                 gen_nullptr_check(s1);
1978                                 gen_bound_check;
1979                                 }
1980                         M_ASLL_IMM(s2, 2, REG_ITMP2);
1981                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1982                         M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
1983                         store_reg_to_var_int(iptr->dst, d);
1984                         break;
1985
1986                 case ICMD_LALOAD:     /* ..., arrayref, index  ==> ..., value         */
1987
1988                         var_to_reg_int(s1, src->prev, REG_ITMP1);
1989                         var_to_reg_int(s2, src, REG_ITMP2);
1990                         d = reg_of_var(iptr->dst, REG_ITMP3);
1991                         if (iptr->op1 == 0) {
1992                                 gen_nullptr_check(s1);
1993                                 gen_bound_check;
1994                                 }
1995                         M_ASLL_IMM(s2, 3, REG_ITMP2);
1996                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
1997                         M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
1998                         store_reg_to_var_int(iptr->dst, d);
1999                         break;
2000
2001                 case ICMD_FALOAD:     /* ..., arrayref, index  ==> ..., value         */
2002
2003                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2004                         var_to_reg_int(s2, src, REG_ITMP2);
2005                         d = reg_of_var(iptr->dst, REG_FTMP3);
2006                         if (iptr->op1 == 0) {
2007                                 gen_nullptr_check(s1);
2008                                 gen_bound_check;
2009                                 }
2010                         M_ASLL_IMM(s2, 2, REG_ITMP2);
2011                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
2012                         M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
2013                         store_reg_to_var_flt(iptr->dst, d);
2014                         break;
2015
2016                 case ICMD_DALOAD:     /* ..., arrayref, index  ==> ..., value         */
2017
2018                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2019                         var_to_reg_int(s2, src, REG_ITMP2);
2020                         d = reg_of_var(iptr->dst, REG_FTMP3);
2021                         if (iptr->op1 == 0) {
2022                                 gen_nullptr_check(s1);
2023                                 gen_bound_check;
2024                                 }
2025                         M_ASLL_IMM(s2, 3, REG_ITMP2);
2026                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
2027                         M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0]));
2028                         store_reg_to_var_flt(iptr->dst, d);
2029                         break;
2030
2031                 case ICMD_CALOAD:     /* ..., arrayref, index  ==> ..., value         */
2032
2033                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2034                         var_to_reg_int(s2, src, REG_ITMP2);
2035                         d = reg_of_var(iptr->dst, REG_ITMP3);
2036                         if (iptr->op1 == 0) {
2037                                 gen_nullptr_check(s1);
2038                                 gen_bound_check;
2039                                 }
2040                         M_AADD(s2, s1, REG_ITMP1);
2041                         M_AADD(s2, REG_ITMP1, REG_ITMP1);
2042                         M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
2043                         store_reg_to_var_int(iptr->dst, d);
2044                         break;                  
2045
2046                 case ICMD_SALOAD:     /* ..., arrayref, index  ==> ..., value         */
2047
2048                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2049                         var_to_reg_int(s2, src, REG_ITMP2);
2050                         d = reg_of_var(iptr->dst, REG_ITMP3);
2051                         if (iptr->op1 == 0) {
2052                                 gen_nullptr_check(s1);
2053                                 gen_bound_check;
2054                                 }
2055                         M_AADD(s2, s1, REG_ITMP1);
2056                         M_AADD(s2, REG_ITMP1, REG_ITMP1);
2057                         M_SLDS(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
2058                         store_reg_to_var_int(iptr->dst, d);
2059                         break;
2060
2061                 case ICMD_BALOAD:     /* ..., arrayref, index  ==> ..., value         */
2062
2063                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2064                         var_to_reg_int(s2, src, REG_ITMP2);
2065                         d = reg_of_var(iptr->dst, REG_ITMP3);
2066                         if (iptr->op1 == 0) {
2067                                 gen_nullptr_check(s1);
2068                                 gen_bound_check;
2069                                 }
2070                         M_AADD(s2, s1, REG_ITMP1);
2071                         M_BLDS(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
2072                         store_reg_to_var_int(iptr->dst, d);
2073                         break;
2074
2075
2076                 case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
2077
2078                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2079                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2080                         if (iptr->op1 == 0) {
2081                                 gen_nullptr_check(s1);
2082                                 gen_bound_check;
2083                                 }
2084                         var_to_reg_int(s3, src, REG_ITMP3);
2085                         M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
2086                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
2087                         M_AST(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
2088                         break;
2089
2090                 case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
2091
2092                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2093                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2094                         if (iptr->op1 == 0) {
2095                                 gen_nullptr_check(s1);
2096                                 gen_bound_check;
2097                                 }
2098                         var_to_reg_int(s3, src, REG_ITMP3);
2099                         M_ASLL_IMM(s2, 2, REG_ITMP2);
2100                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
2101                         M_IST(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
2102                         break;
2103
2104                 case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
2105
2106                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2107                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2108                         if (iptr->op1 == 0) {
2109                                 gen_nullptr_check(s1);
2110                                 gen_bound_check;
2111                                 }
2112                         var_to_reg_int(s3, src, REG_ITMP3);
2113                         M_ASLL_IMM(s2, 3, REG_ITMP2);
2114                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
2115                         M_LST(s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
2116                         break;
2117
2118                 case ICMD_FASTORE:    /* ..., arrayref, index, value  ==> ...         */
2119
2120                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2121                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2122                         if (iptr->op1 == 0) {
2123                                 gen_nullptr_check(s1);
2124                                 gen_bound_check;
2125                                 }
2126                         var_to_reg_flt(s3, src, REG_FTMP3);
2127                         M_ASLL_IMM(s2, 2, REG_ITMP2);
2128                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
2129                         M_FST(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
2130                         break;
2131
2132                 case ICMD_DASTORE:    /* ..., arrayref, index, value  ==> ...         */
2133
2134                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2135                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2136                         if (iptr->op1 == 0) {
2137                                 gen_nullptr_check(s1);
2138                                 gen_bound_check;
2139                                 }
2140                         var_to_reg_flt(s3, src, REG_FTMP3);
2141                         M_ASLL_IMM(s2, 3, REG_ITMP2);
2142                         M_AADD(REG_ITMP2, s1, REG_ITMP1);
2143                         M_DST(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
2144                         break;
2145
2146                 case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
2147                 case ICMD_SASTORE:    /* ..., arrayref, index, value  ==> ...         */
2148
2149                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2150                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2151                         if (iptr->op1 == 0) {
2152                                 gen_nullptr_check(s1);
2153                                 gen_bound_check;
2154                                 }
2155                         var_to_reg_int(s3, src, REG_ITMP3);
2156                         M_AADD(s2, s1, REG_ITMP1);
2157                         M_AADD(s2, REG_ITMP1, REG_ITMP1);
2158                         M_SST(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
2159                         break;
2160
2161                 case ICMD_BASTORE:    /* ..., arrayref, index, value  ==> ...         */
2162
2163                         var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
2164                         var_to_reg_int(s2, src->prev, REG_ITMP2);
2165                         if (iptr->op1 == 0) {
2166                                 gen_nullptr_check(s1);
2167                                 gen_bound_check;
2168                                 }
2169                         var_to_reg_int(s3, src, REG_ITMP3);
2170                         M_AADD(s2, s1, REG_ITMP1);
2171                         M_BST(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
2172                         break;
2173
2174
2175                 case ICMD_PUTSTATIC:  /* ..., value  ==> ...                          */
2176                                       /* op1 = type, val.a = field address            */
2177
2178                         a = dseg_addaddress (&(((fieldinfo *)(iptr->val.a))->value));
2179                         M_ALD(REG_ITMP1, REG_PV, a);
2180                         switch (iptr->op1) {
2181                                 case TYPE_INT:
2182                                         var_to_reg_int(s2, src, REG_ITMP2);
2183                                         M_IST(s2, REG_ITMP1, 0);
2184                                         break;
2185                                 case TYPE_LNG:
2186                                         var_to_reg_int(s2, src, REG_ITMP2);
2187                                         M_LST(s2, REG_ITMP1, 0);
2188                                         break;
2189                                 case TYPE_ADR:
2190                                         var_to_reg_int(s2, src, REG_ITMP2);
2191                                         M_AST(s2, REG_ITMP1, 0);
2192                                         break;
2193                                 case TYPE_FLT:
2194                                         var_to_reg_flt(s2, src, REG_FTMP2);
2195                                         M_FST(s2, REG_ITMP1, 0);
2196                                         break;
2197                                 case TYPE_DBL:
2198                                         var_to_reg_flt(s2, src, REG_FTMP2);
2199                                         M_DST(s2, REG_ITMP1, 0);
2200                                         break;
2201                                 default: panic ("internal error");
2202                                 }
2203                         break;
2204
2205                 case ICMD_GETSTATIC:  /* ...  ==> ..., value                          */
2206                                       /* op1 = type, val.a = field address            */
2207
2208                         a = dseg_addaddress (&(((fieldinfo *)(iptr->val.a))->value));
2209                         M_ALD(REG_ITMP1, REG_PV, a);
2210                         switch (iptr->op1) {
2211                                 case TYPE_INT:
2212                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2213                                         M_ILD(d, REG_ITMP1, 0);
2214                                         store_reg_to_var_int(iptr->dst, d);
2215                                         break;
2216                                 case TYPE_LNG:
2217                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2218                                         M_LLD(d, REG_ITMP1, 0);
2219                                         store_reg_to_var_int(iptr->dst, d);
2220                                         break;
2221                                 case TYPE_ADR:
2222                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2223                                         M_ALD(d, REG_ITMP1, 0);
2224                                         store_reg_to_var_int(iptr->dst, d);
2225                                         break;
2226                                 case TYPE_FLT:
2227                                         d = reg_of_var(iptr->dst, REG_FTMP1);
2228                                         M_FLD(d, REG_ITMP1, 0);
2229                                         store_reg_to_var_flt(iptr->dst, d);
2230                                         break;
2231                                 case TYPE_DBL:                          
2232                                         d = reg_of_var(iptr->dst, REG_FTMP1);
2233                                         M_DLD(d, REG_ITMP1, 0);
2234                                         store_reg_to_var_flt(iptr->dst, d);
2235                                         break;
2236                                 default: panic ("internal error");
2237                                 }
2238                         break;
2239
2240
2241                 case ICMD_PUTFIELD:   /* ..., value  ==> ...                          */
2242                                       /* op1 = type, val.i = field offset             */
2243
2244                         a = ((fieldinfo *)(iptr->val.a))->offset;
2245                         switch (iptr->op1) {
2246                                 case TYPE_INT:
2247                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2248                                         var_to_reg_int(s2, src, REG_ITMP2);
2249                                         gen_nullptr_check(s1);
2250                                         M_IST(s2, s1, a);
2251                                         break;
2252                                 case TYPE_LNG:
2253                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2254                                         var_to_reg_int(s2, src, REG_ITMP2);
2255                                         gen_nullptr_check(s1);
2256                                         M_LST(s2, s1, a);
2257                                         break;
2258                                 case TYPE_ADR:
2259                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2260                                         var_to_reg_int(s2, src, REG_ITMP2);
2261                                         gen_nullptr_check(s1);
2262                                         M_AST(s2, s1, a);
2263                                         break;
2264                                 case TYPE_FLT:
2265                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2266                                         var_to_reg_flt(s2, src, REG_FTMP2);
2267                                         gen_nullptr_check(s1);
2268                                         M_FST(s2, s1, a);
2269                                         break;
2270                                 case TYPE_DBL:
2271                                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2272                                         var_to_reg_flt(s2, src, REG_FTMP2);
2273                                         gen_nullptr_check(s1);
2274                                         M_DST(s2, s1, a);
2275                                         break;
2276                                 default: panic ("internal error");
2277                                 }
2278                         break;
2279
2280                 case ICMD_GETFIELD:   /* ...  ==> ..., value                          */
2281                                       /* op1 = type, val.i = field offset             */
2282
2283                         a = ((fieldinfo *)(iptr->val.a))->offset;
2284                         switch (iptr->op1) {
2285                                 case TYPE_INT:
2286                                         var_to_reg_int(s1, src, REG_ITMP1);
2287                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2288                                         gen_nullptr_check(s1);
2289                                         M_ILD(d, s1, a);
2290                                         store_reg_to_var_int(iptr->dst, d);
2291                                         break;
2292                                 case TYPE_LNG:
2293                                         var_to_reg_int(s1, src, REG_ITMP1);
2294                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2295                                         gen_nullptr_check(s1);
2296                                         M_LLD(d, s1, a);
2297                                         store_reg_to_var_int(iptr->dst, d);
2298                                         break;
2299                                 case TYPE_ADR:
2300                                         var_to_reg_int(s1, src, REG_ITMP1);
2301                                         d = reg_of_var(iptr->dst, REG_ITMP3);
2302                                         gen_nullptr_check(s1);
2303                                         M_ALD(d, s1, a);
2304                                         store_reg_to_var_int(iptr->dst, d);
2305                                         break;
2306                                 case TYPE_FLT:
2307                                         var_to_reg_int(s1, src, REG_ITMP1);
2308                                         d = reg_of_var(iptr->dst, REG_FTMP1);
2309                                         gen_nullptr_check(s1);
2310                                         M_FLD(d, s1, a);
2311                                         store_reg_to_var_flt(iptr->dst, d);
2312                                         break;
2313                                 case TYPE_DBL:                          
2314                                         var_to_reg_int(s1, src, REG_ITMP1);
2315                                         d = reg_of_var(iptr->dst, REG_FTMP1);
2316                                         gen_nullptr_check(s1);
2317                                         M_DLD(d, s1, a);
2318                                         store_reg_to_var_flt(iptr->dst, d);
2319                                         break;
2320                                 default: panic ("internal error");
2321                                 }
2322                         break;
2323
2324
2325                 /* branch operations **************************************************/
2326
2327 #define ALIGNCODENOP {if((int)((long)mcodeptr&7)){M_NOP;}}
2328
2329                 case ICMD_ATHROW:       /* ..., objectref ==> ... (, objectref)       */
2330
2331                         var_to_reg_int(s1, src, REG_ITMP1);
2332                         M_INTMOVE(s1, REG_ITMP1_XPTR);
2333                         a = dseg_addaddress(asm_handle_exception);
2334                         M_ALD(REG_ITMP2, REG_PV, a);
2335                         M_JSR(REG_ITMP2_XPC, REG_ITMP2);
2336                         M_NOP;
2337                         M_NOP;              /* nop ensures that XPC is less than the end */
2338                                             /* of basic block                            */
2339                         ALIGNCODENOP;
2340                         break;
2341
2342                 case ICMD_GOTO:         /* ... ==> ...                                */
2343                                         /* op1 = target JavaVM pc                     */
2344                         M_BR(0);
2345                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2346                         M_NOP;
2347                         ALIGNCODENOP;
2348                         break;
2349
2350                 case ICMD_JSR:          /* ... ==> ...                                */
2351                                         /* op1 = target JavaVM pc                     */
2352
2353                         dseg_addtarget(BlockPtrOfPC(iptr->op1));
2354                         M_ALD(REG_ITMP1, REG_PV, -dseglen);
2355                         M_JSR(REG_ITMP1, REG_ITMP1);        /* REG_ITMP1 = return address */
2356                         M_NOP;
2357                         break;
2358                         
2359                 case ICMD_RET:          /* ... ==> ...                                */
2360                                         /* op1 = local variable                       */
2361                         var = &(locals[iptr->op1][TYPE_ADR]);
2362                         if (var->flags & INMEMORY) {
2363                                 M_ALD(REG_ITMP1, REG_SP, 8 * var->regoff);
2364                                 M_RET(REG_ITMP1);
2365                                 }
2366                         else
2367                                 M_RET(var->regoff);
2368                         M_NOP;
2369                         ALIGNCODENOP;
2370                         break;
2371
2372                 case ICMD_IFNULL:       /* ..., value ==> ...                         */
2373                                         /* op1 = target JavaVM pc                     */
2374
2375                         var_to_reg_int(s1, src, REG_ITMP1);
2376                         M_BEQZ(s1, 0);
2377                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2378                         M_NOP;
2379                         break;
2380
2381                 case ICMD_IFNONNULL:    /* ..., value ==> ...                         */
2382                                         /* op1 = target JavaVM pc                     */
2383
2384                         var_to_reg_int(s1, src, REG_ITMP1);
2385                         M_BNEZ(s1, 0);
2386                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2387                         M_NOP;
2388                         break;
2389
2390                 case ICMD_IFEQ:         /* ..., value ==> ...                         */
2391                                         /* op1 = target JavaVM pc, val.i = constant   */
2392
2393                         var_to_reg_int(s1, src, REG_ITMP1);
2394                         if (iptr->val.i == 0) {
2395                                 M_BEQZ(s1, 0);
2396                                 }
2397                         else {
2398                                 ICONST(REG_ITMP2, iptr->val.i);
2399                                 M_BEQ(s1, REG_ITMP2, 0);
2400                                 }
2401                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2402                         M_NOP;
2403                         break;
2404
2405                 case ICMD_IFLT:         /* ..., value ==> ...                         */
2406                                         /* op1 = target JavaVM pc, val.i = constant   */
2407
2408                         var_to_reg_int(s1, src, REG_ITMP1);
2409                         if (iptr->val.i == 0) {
2410                                 M_BLTZ(s1, 0);
2411                                 }
2412                         else {
2413                                 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
2414                                         M_CMPLT_IMM(s1, iptr->val.i, REG_ITMP1);
2415                                         }
2416                                 else {
2417                                         ICONST(REG_ITMP2, iptr->val.i);
2418                                         M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2419                                         }
2420                                 M_BNEZ(REG_ITMP1, 0);
2421                                 }
2422                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2423                         M_NOP;
2424                         break;
2425
2426                 case ICMD_IFLE:         /* ..., value ==> ...                         */
2427                                         /* op1 = target JavaVM pc, val.i = constant   */
2428
2429                         var_to_reg_int(s1, src, REG_ITMP1);
2430                         if (iptr->val.i == 0) {
2431                                 M_BLEZ(s1, 0);
2432                                 }
2433                         else {
2434                                 if ((iptr->val.i >= -32769) && (iptr->val.i <= 32766)) {
2435                                         M_CMPLT_IMM(s1, iptr->val.i + 1, REG_ITMP1);
2436                                         M_BNEZ(REG_ITMP1, 0);
2437                                         }
2438                                 else {
2439                                         ICONST(REG_ITMP2, iptr->val.i);
2440                                         M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
2441                                         M_BEQZ(REG_ITMP1, 0);
2442                                         }
2443                                 }
2444                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2445                         M_NOP;
2446                         break;
2447
2448                 case ICMD_IFNE:         /* ..., value ==> ...                         */
2449                                         /* op1 = target JavaVM pc, val.i = constant   */
2450
2451                         var_to_reg_int(s1, src, REG_ITMP1);
2452                         if (iptr->val.i == 0) {
2453                                 M_BNEZ(s1, 0);
2454                                 }
2455                         else {
2456                                 ICONST(REG_ITMP2, iptr->val.i);
2457                                 M_BNE(s1, REG_ITMP2, 0);
2458                                 }
2459                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2460                         M_NOP;
2461                         break;
2462
2463                 case ICMD_IFGT:         /* ..., value ==> ...                         */
2464                                         /* op1 = target JavaVM pc, val.i = constant   */
2465
2466                         var_to_reg_int(s1, src, REG_ITMP1);
2467                         if (iptr->val.i == 0) {
2468                                 M_BGTZ(s1, 0);
2469                                 }
2470                         else {
2471                                 if ((iptr->val.i >= -32769) && (iptr->val.i <= 32766)) {
2472                                         M_CMPLT_IMM(s1, iptr->val.i + 1, REG_ITMP1);
2473                                         M_BEQZ(REG_ITMP1, 0);
2474                                         }
2475                                 else {
2476                                         ICONST(REG_ITMP2, iptr->val.i);
2477                                         M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
2478                                         M_BNEZ(REG_ITMP1, 0);
2479                                         }
2480                                 }
2481                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2482                         M_NOP;
2483                         break;
2484
2485                 case ICMD_IFGE:         /* ..., value ==> ...                         */
2486                                         /* op1 = target JavaVM pc, val.i = constant   */
2487
2488                         var_to_reg_int(s1, src, REG_ITMP1);
2489                         if (iptr->val.i == 0) {
2490                                 M_BGEZ(s1, 0);
2491                                 }
2492                         else {
2493                                 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
2494                                         M_CMPLT_IMM(s1, iptr->val.i, REG_ITMP1);
2495                                         }
2496                                 else {
2497                                         ICONST(REG_ITMP2, iptr->val.i);
2498                                         M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2499                                         }
2500                                 M_BEQZ(REG_ITMP1, 0);
2501                                 }
2502                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2503                         M_NOP;
2504                         break;
2505
2506                 case ICMD_IF_LEQ:       /* ..., value ==> ...                         */
2507                                         /* op1 = target JavaVM pc, val.l = constant   */
2508
2509                         var_to_reg_int(s1, src, REG_ITMP1);
2510                         if (iptr->val.l == 0) {
2511                                 M_BEQZ(s1, 0);
2512                                 }
2513                         else {
2514                                 LCONST(REG_ITMP2, iptr->val.l);
2515                                 M_BEQ(s1, REG_ITMP2, 0);
2516                                 }
2517                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2518                         M_NOP;
2519                         break;
2520
2521                 case ICMD_IF_LLT:       /* ..., value ==> ...                         */
2522                                         /* op1 = target JavaVM pc, val.l = constant   */
2523
2524                         var_to_reg_int(s1, src, REG_ITMP1);
2525                         if (iptr->val.l == 0) {
2526                                 M_BLTZ(s1, 0);
2527                                 }
2528                         else {
2529                                 if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2530                                         M_CMPLT_IMM(s1, iptr->val.l, REG_ITMP1);
2531                                         }
2532                                 else {
2533                                         LCONST(REG_ITMP2, iptr->val.l);
2534                                         M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2535                                         }
2536                                 M_BNEZ(REG_ITMP1, 0);
2537                                 }
2538                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2539                         M_NOP;
2540                         break;
2541
2542                 case ICMD_IF_LLE:       /* ..., value ==> ...                         */
2543                                         /* op1 = target JavaVM pc, val.l = constant   */
2544
2545                         var_to_reg_int(s1, src, REG_ITMP1);
2546                         if (iptr->val.l == 0) {
2547                                 M_BLEZ(s1, 0);
2548                                 }
2549                         else {
2550                                 if ((iptr->val.l >= -32769) && (iptr->val.l <= 32766)) {
2551                                         M_CMPLT_IMM(s1, iptr->val.l + 1, REG_ITMP1);
2552                                         M_BNEZ(REG_ITMP1, 0);
2553                                         }
2554                                 else {
2555                                         LCONST(REG_ITMP2, iptr->val.l);
2556                                         M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
2557                                         M_BEQZ(REG_ITMP1, 0);
2558                                         }
2559                                 }
2560                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2561                         M_NOP;
2562                         break;
2563
2564                 case ICMD_IF_LNE:       /* ..., value ==> ...                         */
2565                                         /* op1 = target JavaVM pc, val.l = constant   */
2566
2567                         var_to_reg_int(s1, src, REG_ITMP1);
2568                         if (iptr->val.l == 0) {
2569                                 M_BNEZ(s1, 0);
2570                                 }
2571                         else {
2572                                 LCONST(REG_ITMP2, iptr->val.l);
2573                                 M_BNE(s1, REG_ITMP2, 0);
2574                                 }
2575                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2576                         M_NOP;
2577                         break;
2578
2579                 case ICMD_IF_LGT:       /* ..., value ==> ...                         */
2580                                         /* op1 = target JavaVM pc, val.l = constant   */
2581
2582                         var_to_reg_int(s1, src, REG_ITMP1);
2583                         if (iptr->val.l == 0) {
2584                                 M_BGTZ(s1, 0);
2585                                 }
2586                         else {
2587                                 if ((iptr->val.l >= -32769) && (iptr->val.l <= 32766)) {
2588                                         M_CMPLT_IMM(s1, iptr->val.l + 1, REG_ITMP1);
2589                                         M_BEQZ(REG_ITMP1, 0);
2590                                         }
2591                                 else {
2592                                         LCONST(REG_ITMP2, iptr->val.l);
2593                                         M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
2594                                         M_BNEZ(REG_ITMP1, 0);
2595                                         }
2596                                 }
2597                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2598                         M_NOP;
2599                         break;
2600
2601                 case ICMD_IF_LGE:       /* ..., value ==> ...                         */
2602                                         /* op1 = target JavaVM pc, val.l = constant   */
2603
2604                         var_to_reg_int(s1, src, REG_ITMP1);
2605                         if (iptr->val.l == 0) {
2606                                 M_BGEZ(s1, 0);
2607                                 }
2608                         else {
2609                                 if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2610                                         M_CMPLT_IMM(s1, iptr->val.l, REG_ITMP1);
2611                                         }
2612                                 else {
2613                                         LCONST(REG_ITMP2, iptr->val.l);
2614                                         M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2615                                         }
2616                                 M_BEQZ(REG_ITMP1, 0);
2617                                 }
2618                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2619                         M_NOP;
2620                         break;
2621
2622                 case ICMD_IF_ICMPEQ:    /* ..., value, value ==> ...                  */
2623                 case ICMD_IF_LCMPEQ:    /* op1 = target JavaVM pc                     */
2624                 case ICMD_IF_ACMPEQ:
2625
2626                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2627                         var_to_reg_int(s2, src, REG_ITMP2);
2628                         M_BEQ(s1, s2, 0);
2629                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2630                         M_NOP;
2631                         break;
2632
2633                 case ICMD_IF_ICMPNE:    /* ..., value, value ==> ...                  */
2634                 case ICMD_IF_LCMPNE:    /* op1 = target JavaVM pc                     */
2635                 case ICMD_IF_ACMPNE:
2636
2637                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2638                         var_to_reg_int(s2, src, REG_ITMP2);
2639                         M_BNE(s1, s2, 0);
2640                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2641                         M_NOP;
2642                         break;
2643
2644                 case ICMD_IF_ICMPLT:    /* ..., value, value ==> ...                  */
2645                 case ICMD_IF_LCMPLT:    /* op1 = target JavaVM pc                     */
2646
2647                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2648                         var_to_reg_int(s2, src, REG_ITMP2);
2649                         M_CMPLT(s1, s2, REG_ITMP1);
2650                         M_BNEZ(REG_ITMP1, 0);
2651                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2652                         M_NOP;
2653                         break;
2654
2655                 case ICMD_IF_ICMPGT:    /* ..., value, value ==> ...                  */
2656                 case ICMD_IF_LCMPGT:    /* op1 = target JavaVM pc                     */
2657
2658                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2659                         var_to_reg_int(s2, src, REG_ITMP2);
2660                         M_CMPGT(s1, s2, REG_ITMP1);
2661                         M_BNEZ(REG_ITMP1, 0);
2662                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2663                         M_NOP;
2664                         break;
2665
2666                 case ICMD_IF_ICMPLE:    /* ..., value, value ==> ...                  */
2667                 case ICMD_IF_LCMPLE:    /* op1 = target JavaVM pc                     */
2668
2669                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2670                         var_to_reg_int(s2, src, REG_ITMP2);
2671                         M_CMPGT(s1, s2, REG_ITMP1);
2672                         M_BEQZ(REG_ITMP1, 0);
2673                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2674                         M_NOP;
2675                         break;
2676
2677                 case ICMD_IF_ICMPGE:    /* ..., value, value ==> ...                  */
2678                 case ICMD_IF_LCMPGE:    /* op1 = target JavaVM pc                     */
2679
2680                         var_to_reg_int(s1, src->prev, REG_ITMP1);
2681                         var_to_reg_int(s2, src, REG_ITMP2);
2682                         M_CMPLT(s1, s2, REG_ITMP1);
2683                         M_BEQZ(REG_ITMP1, 0);
2684                         codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
2685                         M_NOP;
2686                         break;
2687
2688 #ifdef CONDITIONAL_LOADCONST
2689                 /* (value xx 0) ? IFxx_ICONST : ELSE_ICONST                           */
2690
2691                 case ICMD_ELSE_ICONST:  /* handled by IFxx_ICONST                     */
2692                         break;
2693
2694                 case ICMD_IFEQ_ICONST:  /* ..., value ==> ..., constant               */
2695                                         /* val.i = constant                           */
2696
2697                         var_to_reg_int(s1, src, REG_ITMP1);
2698                         d = reg_of_var(iptr->dst, REG_ITMP3);
2699                         s3 = iptr->val.i;
2700                         if (iptr[1].opc == ICMD_ELSE_ICONST) {
2701                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2702                                         M_CMPEQ(s1, REG_ZERO, d);
2703                                         store_reg_to_var_int(iptr->dst, d);
2704                                         break;
2705                                         }
2706                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2707                                         M_CMPEQ(s1, REG_ZERO, d);
2708                                         M_XOR_IMM(d, 1, d);
2709                                         store_reg_to_var_int(iptr->dst, d);
2710                                         break;
2711                                         }
2712                                 if (s1 == d) {
2713                                         M_MOV(s1, REG_ITMP1);
2714                                         s1 = REG_ITMP1;
2715                                         }
2716                                 ICONST(d, iptr[1].val.i);
2717                                 }
2718                         if ((s3 >= 0) && (s3 <= 255)) {
2719                                 M_CMOVEQ_IMM(s1, s3, d);
2720                                 }
2721                         else {
2722                                 ICONST(REG_ITMP2, s3);
2723                                 M_CMOVEQ(s1, REG_ITMP2, d);
2724                                 }
2725                         store_reg_to_var_int(iptr->dst, d);
2726                         break;
2727
2728                 case ICMD_IFNE_ICONST:  /* ..., value ==> ..., constant               */
2729                                         /* val.i = constant                           */
2730
2731                         var_to_reg_int(s1, src, REG_ITMP1);
2732                         d = reg_of_var(iptr->dst, REG_ITMP3);
2733                         s3 = iptr->val.i;
2734                         if (iptr[1].opc == ICMD_ELSE_ICONST) {
2735                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2736                                         M_CMPEQ(s1, REG_ZERO, d);
2737                                         store_reg_to_var_int(iptr->dst, d);
2738                                         break;
2739                                         }
2740                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2741                                         M_CMPEQ(s1, REG_ZERO, d);
2742                                         M_XOR_IMM(d, 1, d);
2743                                         store_reg_to_var_int(iptr->dst, d);
2744                                         break;
2745                                         }
2746                                 if (s1 == d) {
2747                                         M_MOV(s1, REG_ITMP1);
2748                                         s1 = REG_ITMP1;
2749                                         }
2750                                 ICONST(d, iptr[1].val.i);
2751                                 }
2752                         if ((s3 >= 0) && (s3 <= 255)) {
2753                                 M_CMOVNE_IMM(s1, s3, d);
2754                                 }
2755                         else {
2756                                 ICONST(REG_ITMP2, s3);
2757                                 M_CMOVNE(s1, REG_ITMP2, d);
2758                                 }
2759                         store_reg_to_var_int(iptr->dst, d);
2760                         break;
2761
2762                 case ICMD_IFLT_ICONST:  /* ..., value ==> ..., constant               */
2763                                         /* val.i = constant                           */
2764
2765                         var_to_reg_int(s1, src, REG_ITMP1);
2766                         d = reg_of_var(iptr->dst, REG_ITMP3);
2767                         s3 = iptr->val.i;
2768                         if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2769                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2770                                         M_CMPLT(s1, REG_ZERO, d);
2771                                         store_reg_to_var_int(iptr->dst, d);
2772                                         break;
2773                                         }
2774                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2775                                         M_CMPLE(REG_ZERO, s1, d);
2776                                         store_reg_to_var_int(iptr->dst, d);
2777                                         break;
2778                                         }
2779                                 if (s1 == d) {
2780                                         M_MOV(s1, REG_ITMP1);
2781                                         s1 = REG_ITMP1;
2782                                         }
2783                                 ICONST(d, iptr[1].val.i);
2784                                 }
2785                         if ((s3 >= 0) && (s3 <= 255)) {
2786                                 M_CMOVLT_IMM(s1, s3, d);
2787                                 }
2788                         else {
2789                                 ICONST(REG_ITMP2, s3);
2790                                 M_CMOVLT(s1, REG_ITMP2, d);
2791                                 }
2792                         store_reg_to_var_int(iptr->dst, d);
2793                         break;
2794
2795                 case ICMD_IFGE_ICONST:  /* ..., value ==> ..., constant               */
2796                                         /* val.i = constant                           */
2797
2798                         var_to_reg_int(s1, src, REG_ITMP1);
2799                         d = reg_of_var(iptr->dst, REG_ITMP3);
2800                         s3 = iptr->val.i;
2801                         if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2802                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2803                                         M_CMPLE(REG_ZERO, s1, d);
2804                                         store_reg_to_var_int(iptr->dst, d);
2805                                         break;
2806                                         }
2807                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2808                                         M_CMPLT(s1, REG_ZERO, d);
2809                                         store_reg_to_var_int(iptr->dst, d);
2810                                         break;
2811                                         }
2812                                 if (s1 == d) {
2813                                         M_MOV(s1, REG_ITMP1);
2814                                         s1 = REG_ITMP1;
2815                                         }
2816                                 ICONST(d, iptr[1].val.i);
2817                                 }
2818                         if ((s3 >= 0) && (s3 <= 255)) {
2819                                 M_CMOVGE_IMM(s1, s3, d);
2820                                 }
2821                         else {
2822                                 ICONST(REG_ITMP2, s3);
2823                                 M_CMOVGE(s1, REG_ITMP2, d);
2824                                 }
2825                         store_reg_to_var_int(iptr->dst, d);
2826                         break;
2827
2828                 case ICMD_IFGT_ICONST:  /* ..., value ==> ..., constant               */
2829                                         /* val.i = constant                           */
2830
2831                         var_to_reg_int(s1, src, REG_ITMP1);
2832                         d = reg_of_var(iptr->dst, REG_ITMP3);
2833                         s3 = iptr->val.i;
2834                         if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2835                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2836                                         M_CMPLT(REG_ZERO, s1, d);
2837                                         store_reg_to_var_int(iptr->dst, d);
2838                                         break;
2839                                         }
2840                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2841                                         M_CMPLE(s1, REG_ZERO, d);
2842                                         store_reg_to_var_int(iptr->dst, d);
2843                                         break;
2844                                         }
2845                                 if (s1 == d) {
2846                                         M_MOV(s1, REG_ITMP1);
2847                                         s1 = REG_ITMP1;
2848                                         }
2849                                 ICONST(d, iptr[1].val.i);
2850                                 }
2851                         if ((s3 >= 0) && (s3 <= 255)) {
2852                                 M_CMOVGT_IMM(s1, s3, d);
2853                                 }
2854                         else {
2855                                 ICONST(REG_ITMP2, s3);
2856                                 M_CMOVGT(s1, REG_ITMP2, d);
2857                                 }
2858                         store_reg_to_var_int(iptr->dst, d);
2859                         break;
2860
2861                 case ICMD_IFLE_ICONST:  /* ..., value ==> ..., constant               */
2862                                         /* val.i = constant                           */
2863
2864                         var_to_reg_int(s1, src, REG_ITMP1);
2865                         d = reg_of_var(iptr->dst, REG_ITMP3);
2866                         s3 = iptr->val.i;
2867                         if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2868                                 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2869                                         M_CMPLE(s1, REG_ZERO, d);
2870                                         store_reg_to_var_int(iptr->dst, d);
2871                                         break;
2872                                         }
2873                                 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2874                                         M_CMPLT(REG_ZERO, s1, d);
2875                                         store_reg_to_var_int(iptr->dst, d);
2876                                         break;
2877                                         }
2878                                 if (s1 == d) {
2879                                         M_MOV(s1, REG_ITMP1);
2880                                         s1 = REG_ITMP1;
2881                                         }
2882                                 ICONST(d, iptr[1].val.i);
2883                                 }
2884                         if ((s3 >= 0) && (s3 <= 255)) {
2885                                 M_CMOVLE_IMM(s1, s3, d);
2886                                 }
2887                         else {
2888                                 ICONST(REG_ITMP2, s3);
2889                                 M_CMOVLE(s1, REG_ITMP2, d);
2890                                 }
2891                         store_reg_to_var_int(iptr->dst, d);
2892                         break;
2893 #endif
2894
2895
2896                 case ICMD_IRETURN:      /* ..., retvalue ==> ...                      */
2897                 case ICMD_LRETURN:
2898                 case ICMD_ARETURN:
2899
2900 #ifdef USE_THREADS
2901                         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
2902                                 int disp;
2903                                 a = dseg_addaddress ((void*) (builtin_monitorexit));
2904                                 M_ALD(REG_ITMP3, REG_PV, a);
2905                                 M_JSR(REG_RA, REG_ITMP3);
2906                                 M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);    /* delay slot */
2907                                 disp = -(int)((u1*) mcodeptr - mcodebase);
2908                                 M_LDA(REG_PV, REG_RA, disp);
2909                                 }                       
2910 #endif
2911                         var_to_reg_int(s1, src, REG_RESULT);
2912                         M_INTMOVE(s1, REG_RESULT);
2913                         goto nowperformreturn;
2914
2915                 case ICMD_FRETURN:      /* ..., retvalue ==> ...                      */
2916                 case ICMD_DRETURN:
2917
2918 #ifdef USE_THREADS
2919                         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
2920                                 int disp;
2921                                 a = dseg_addaddress ((void*) (builtin_monitorexit));
2922                                 M_ALD(REG_ITMP3, REG_PV, a);
2923                                 M_JSR(REG_RA, REG_ITMP3);
2924                                 M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);    /* delay slot */
2925                                 disp = -(int)((u1*) mcodeptr - mcodebase);
2926                                 M_LDA(REG_PV, REG_RA, disp);
2927                                 }                       
2928 #endif
2929                         var_to_reg_flt(s1, src, REG_FRESULT);
2930                         {
2931                                 int t = ((iptr->opc == ICMD_FRETURN) ? TYPE_FLT : TYPE_DBL);
2932                                 M_TFLTMOVE(t, s1, REG_FRESULT);
2933                         }
2934                         goto nowperformreturn;
2935
2936                 case ICMD_RETURN:      /* ...  ==> ...                                */
2937
2938 #ifdef USE_THREADS
2939                         if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
2940                                 int disp;
2941                                 a = dseg_addaddress ((void*) (builtin_monitorexit));
2942                                 M_ALD(REG_ITMP3, REG_PV, a);
2943                                 M_JSR(REG_RA, REG_ITMP3);
2944                                 M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);    /* delay slot */
2945                                 disp = -(int)((u1*) mcodeptr - mcodebase);
2946                                 M_LDA(REG_PV, REG_RA, disp);
2947                                 }                       
2948 #endif
2949
2950 nowperformreturn:
2951                         {
2952                         int r, p;
2953                         
2954                         p = parentargs_base;
2955                         
2956                         /* restore return address                                         */
2957
2958                         if (!isleafmethod)
2959                                 {p--;  M_LLD (REG_RA, REG_SP, 8 * p);}
2960
2961                         /* restore saved registers                                        */
2962
2963                         for (r = savintregcnt - 1; r >= maxsavintreguse; r--)
2964                                         {p--; M_LLD(savintregs[r], REG_SP, 8 * p);}
2965                         for (r = savfltregcnt - 1; r >= maxsavfltreguse; r--)
2966                                         {p--; M_DLD(savfltregs[r], REG_SP, 8 * p);}
2967
2968                         /* call trace function */
2969
2970                         if (runverbose) {
2971                                 M_LDA (REG_SP, REG_SP, -24);
2972                                 M_LST(REG_RA, REG_SP, 0);
2973                                 M_LST(REG_RESULT, REG_SP, 8);
2974                                 M_DST(REG_FRESULT, REG_SP,16);
2975                                 a = dseg_addaddress (method);
2976                                 M_ALD(argintregs[0], REG_PV, a);
2977                                 M_MOV(REG_RESULT, argintregs[1]);
2978                                 M_FLTMOVE(REG_FRESULT, argfltregs[2]);
2979                                 M_FMOV(REG_FRESULT, argfltregs[3]);
2980                                 a = dseg_addaddress ((void*) (builtin_displaymethodstop));
2981                                 M_ALD(REG_ITMP3, REG_PV, a);
2982                                 M_JSR (REG_RA, REG_ITMP3);
2983                                 M_NOP;
2984                                 M_DLD(REG_FRESULT, REG_SP,16);
2985                                 M_LLD(REG_RESULT, REG_SP, 8);
2986                                 M_LLD(REG_RA, REG_SP, 0);
2987                                 M_LDA (REG_SP, REG_SP, 24);
2988                                 }
2989
2990                         M_RET(REG_RA);
2991
2992                         /* deallocate stack                                               */
2993
2994                         if (parentargs_base)
2995                                 {M_LDA(REG_SP, REG_SP, parentargs_base*8);}
2996                         else
2997                                 {M_NOP;}
2998                         ALIGNCODENOP;
2999                         }
3000                         break;
3001
3002
3003                 case ICMD_TABLESWITCH:  /* ..., index ==> ...                         */
3004                         {
3005                         s4 i, l, *s4ptr;
3006                         void **tptr;
3007
3008                         tptr = (void **) iptr->target;
3009
3010                         s4ptr = iptr->val.a;
3011                         l = s4ptr[1];                          /* low     */
3012                         i = s4ptr[2];                          /* high    */
3013                         
3014                         var_to_reg_int(s1, src, REG_ITMP1);
3015                         if (l == 0)
3016                                 {M_INTMOVE(s1, REG_ITMP1);}
3017                         else if (l <= 32768) {
3018                                 M_IADD_IMM(s1, -l, REG_ITMP1);
3019                                 }
3020                         else {
3021                                 ICONST(REG_ITMP2, l);
3022                                 M_ISUB(s1, REG_ITMP2, REG_ITMP1);
3023                                 }
3024                         i = i - l + 1;
3025
3026                         /* range check */
3027
3028                         M_CMPULT_IMM(REG_ITMP1, i, REG_ITMP2);
3029                         M_BEQZ(REG_ITMP2, 0);
3030                         codegen_addreference((basicblock *) tptr[0], mcodeptr);
3031                         M_ASLL_IMM(REG_ITMP1, POINTERSHIFT, REG_ITMP1);      /* delay slot*/
3032
3033                         /* build jump table top down and use address of lowest entry */
3034
3035                         /* s4ptr += 3 + i; */
3036                         tptr += i;
3037
3038                         while (--i >= 0) {
3039                                 /* dseg_addtarget(BlockPtrOfPC(*--s4ptr)); */
3040                                 dseg_addtarget((basicblock *) tptr[0]); 
3041                                 --tptr;
3042                                 }
3043                         }
3044
3045                         /* length of dataseg after last dseg_addtarget is used by load */
3046
3047                         M_AADD(REG_ITMP1, REG_PV, REG_ITMP2);
3048                         M_ALD(REG_ITMP2, REG_ITMP2, -dseglen);
3049                         M_JMP(REG_ITMP2);
3050                         M_NOP;
3051                         ALIGNCODENOP;
3052                         break;
3053
3054
3055                 case ICMD_LOOKUPSWITCH: /* ..., key ==> ...                           */
3056                         {
3057                         s4 i, l, val, *s4ptr;
3058                         void **tptr;
3059
3060                         tptr = (void **) iptr->target;
3061
3062                         s4ptr = iptr->val.a;
3063                         l = s4ptr[0];                          /* default  */
3064                         i = s4ptr[1];                          /* count    */
3065                         
3066                         MCODECHECK((i<<2)+8);
3067                         var_to_reg_int(s1, src, REG_ITMP1);
3068                         while (--i >= 0) {
3069                                 s4ptr += 2;
3070                                 ++tptr;
3071
3072                                 val = s4ptr[0];
3073                                 ICONST(REG_ITMP2, val);
3074                                 M_BEQ(s1, REG_ITMP2, 0);
3075                                 codegen_addreference((basicblock *) tptr[0], mcodeptr); 
3076                                 M_NOP;
3077                                 }
3078
3079                         M_BR(0);
3080                         tptr = (void **) iptr->target;
3081                         codegen_addreference((basicblock *) tptr[0], mcodeptr);
3082                         M_NOP;
3083                         ALIGNCODENOP;
3084                         break;
3085                         }
3086
3087
3088                 case ICMD_BUILTIN3:     /* ..., arg1, arg2, arg3 ==> ...              */
3089                                         /* op1 = return type, val.a = function pointer*/
3090                         s3 = 3;
3091                         goto gen_method;
3092
3093                 case ICMD_BUILTIN2:     /* ..., arg1, arg2 ==> ...                    */
3094                                         /* op1 = return type, val.a = function pointer*/
3095                         s3 = 2;
3096                         goto gen_method;
3097
3098                 case ICMD_BUILTIN1:     /* ..., arg1 ==> ...                          */
3099                                         /* op1 = return type, val.a = function pointer*/
3100                         s3 = 1;
3101                         goto gen_method;
3102
3103                 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ...            */
3104                                         /* op1 = arg count, val.a = method pointer    */
3105
3106                 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
3107                                         /* op1 = arg count, val.a = method pointer    */
3108
3109                 case ICMD_INVOKEVIRTUAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
3110                                         /* op1 = arg count, val.a = method pointer    */
3111
3112                 case ICMD_INVOKEINTERFACE:/*.., objectref, [arg1, [arg2 ...]] ==> ... */
3113                                         /* op1 = arg count, val.a = method pointer    */
3114
3115                         s3 = iptr->op1;
3116
3117 gen_method: {
3118                         methodinfo   *m;
3119                         classinfo    *ci;
3120
3121                         MCODECHECK((s3 << 1) + 64);
3122
3123                         /* copy arguments to registers or stack location                  */
3124
3125                         for (; --s3 >= 0; src = src->prev) {
3126                                 if (src->varkind == ARGVAR)
3127                                         continue;
3128                                 if (IS_INT_LNG_TYPE(src->type)) {
3129                                         if (s3 < INT_ARG_CNT) {
3130                                                 s1 = argintregs[s3];
3131                                                 var_to_reg_int(d, src, s1);
3132                                                 M_INTMOVE(d, s1);
3133                                                 }
3134                                         else  {
3135                                                 var_to_reg_int(d, src, REG_ITMP1);
3136                                                 M_LST(d, REG_SP, 8 * (s3 - INT_ARG_CNT));
3137                                                 }
3138                                         }
3139                                 else
3140                                         if (s3 < FLT_ARG_CNT) {
3141                                                 s1 = argfltregs[s3];
3142                                                 var_to_reg_flt(d, src, s1);
3143                                                 M_TFLTMOVE(src->type,d, s1);
3144                                                 }
3145                                         else {
3146                                                 var_to_reg_flt(d, src, REG_FTMP1);
3147                                                 M_DST(d, REG_SP, 8 * (s3 - FLT_ARG_CNT));
3148                                                 }
3149                                 } /* end of for */
3150
3151                         m = iptr->val.a;
3152                         switch (iptr->opc) {
3153                                 case ICMD_BUILTIN3:
3154                                 case ICMD_BUILTIN2:
3155                                 case ICMD_BUILTIN1:
3156                                         a = dseg_addaddress ((void*) (m));
3157                                         M_ALD(REG_ITMP3, REG_PV, a); /* built-in-function pointer */
3158                                         M_JSR (REG_RA, REG_ITMP3);
3159                                         M_NOP;
3160                                         d = iptr->op1;                             /* return type */
3161                                         goto afteractualcall;
3162
3163                                 case ICMD_INVOKESTATIC:
3164                                 case ICMD_INVOKESPECIAL:
3165                                         a = dseg_addaddress (m->stubroutine);
3166
3167                                         M_ALD(REG_PV, REG_PV, a );        /* method pointer in pv */
3168
3169                                         d = m->returntype;
3170                                         goto makeactualcall;
3171
3172                                 case ICMD_INVOKEVIRTUAL:
3173
3174                                         gen_nullptr_check(argintregs[0]);
3175                                         M_ALD(REG_METHODPTR, argintregs[0],
3176                                                                  OFFSET(java_objectheader, vftbl));
3177                                         M_ALD(REG_PV, REG_METHODPTR, OFFSET(vftbl, table[0]) +
3178                                                                 sizeof(methodptr) * m->vftblindex);
3179
3180                                         d = m->returntype;
3181                                         goto makeactualcall;
3182
3183                                 case ICMD_INVOKEINTERFACE:
3184                                         ci = m->class;
3185                                         
3186                                         gen_nullptr_check(argintregs[0]);
3187                                         M_ALD(REG_METHODPTR, argintregs[0],
3188                                                                  OFFSET(java_objectheader, vftbl));    
3189                                         M_ALD(REG_METHODPTR, REG_METHODPTR,
3190                                               OFFSET(vftbl, interfacetable[0]) -
3191                                               sizeof(methodptr*) * ci->index);
3192                                         M_ALD(REG_PV, REG_METHODPTR,
3193                                                             sizeof(methodptr) * (m - ci->methods));
3194
3195                                         d = m->returntype;
3196                                         goto makeactualcall;
3197
3198                                 default:
3199                                         d = 0;
3200                                         error ("Unkown ICMD-Command: %d", iptr->opc);
3201                                 }
3202
3203 makeactualcall:
3204
3205                         M_JSR (REG_RA, REG_PV);
3206                         M_NOP;
3207
3208                         /* recompute pv */
3209
3210 afteractualcall:
3211
3212                         s1 = (int)((u1*) mcodeptr - mcodebase);
3213                         if (s1<=32768) M_LDA (REG_PV, REG_RA, -s1);
3214                         else {
3215                                         s4 ml=-s1, mh=0;
3216                                         while (ml<-32768) { ml+=65536; mh--; }
3217                                         M_LUI(REG_PV, mh);
3218                                         M_IADD_IMM(REG_PV, ml, REG_PV);
3219                                         M_LADD(REG_PV, REG_RA, REG_PV);
3220                                 }
3221
3222                         /* d contains return type */
3223
3224                         if (d != TYPE_VOID) {
3225                                 if (IS_INT_LNG_TYPE(iptr->dst->type)) {
3226                                         s1 = reg_of_var(iptr->dst, REG_RESULT);
3227                                         M_INTMOVE(REG_RESULT, s1);
3228                                         store_reg_to_var_int(iptr->dst, s1);
3229                                         }
3230                                 else {
3231                                         s1 = reg_of_var(iptr->dst, REG_FRESULT);
3232                                         M_TFLTMOVE(iptr->dst->type, REG_FRESULT, s1);
3233                                         store_reg_to_var_flt(iptr->dst, s1);
3234                                         }
3235                                 }
3236                         }
3237                         break;
3238
3239
3240                 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult            */
3241
3242                                       /* op1:   0 == array, 1 == class                */
3243                                       /* val.a: (classinfo*) superclass               */
3244
3245 /*          superclass is an interface:
3246  *
3247  *          return (sub != NULL) &&
3248  *                 (sub->vftbl->interfacetablelength > super->index) &&
3249  *                 (sub->vftbl->interfacetable[-super->index] != NULL);
3250  *
3251  *          superclass is a class:
3252  *
3253  *          return ((sub != NULL) && (0
3254  *                  <= (sub->vftbl->baseval - super->vftbl->baseval) <=
3255  *                  super->vftbl->diffvall));
3256  */
3257
3258                         {
3259                         classinfo *super = (classinfo*) iptr->val.a;
3260                         
3261                         var_to_reg_int(s1, src, REG_ITMP1);
3262                         d = reg_of_var(iptr->dst, REG_ITMP3);
3263                         if (s1 == d) {
3264                                 M_MOV(s1, REG_ITMP1);
3265                                 s1 = REG_ITMP1;
3266                                 }
3267                         M_CLR(d);
3268                         if (iptr->op1) {                               /* class/interface */
3269                                 if (super->flags & ACC_INTERFACE) {        /* interface       */
3270                                         M_BEQZ(s1, 8);
3271                                         M_NOP;
3272                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3273                                         M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength));
3274                                         M_IADD_IMM(REG_ITMP2, - super->index, REG_ITMP2);
3275                                         M_BLEZ(REG_ITMP2, 3);
3276                                         M_NOP;
3277                                         M_ALD(REG_ITMP1, REG_ITMP1,
3278                                               OFFSET(vftbl, interfacetable[0]) -
3279                                               super->index * sizeof(methodptr*));
3280                                         M_CMPULT(REG_ZERO, REG_ITMP1, d);      /* REG_ITMP1 != 0  */
3281                                         }
3282                                 else {                                     /* class           */
3283                                         /*
3284                                         s2 = super->vftbl->diffval;
3285                                         M_BEQZ(s1, 5);
3286                                         M_NOP;
3287                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3288                                         M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
3289                                         M_IADD_IMM(REG_ITMP1, - super->vftbl->baseval, REG_ITMP1);
3290                                         M_CMPULT_IMM(REG_ITMP1, s2 + 1, d);
3291                                         */
3292
3293                                         M_BEQZ(s1, 9);
3294                                         M_NOP;
3295                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3296                     a = dseg_addaddress ((void*) super->vftbl);
3297                     M_ALD(REG_ITMP2, REG_PV, a);
3298                     M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
3299                     M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval));
3300                     M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
3301                     M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1); 
3302                     M_CMPULT(REG_ITMP2, REG_ITMP1, d);
3303                                         M_XOR_IMM(d, 1, d);
3304
3305                                         }
3306                                 }
3307                         else
3308                                 panic ("internal error: no inlined array instanceof");
3309                         }
3310                         store_reg_to_var_int(iptr->dst, d);
3311                         break;
3312
3313                 case ICMD_CHECKCAST:  /* ..., objectref ==> ..., objectref            */
3314
3315                                       /* op1:   0 == array, 1 == class                */
3316                                       /* val.a: (classinfo*) superclass               */
3317
3318 /*          superclass is an interface:
3319  *
3320  *          OK if ((sub == NULL) ||
3321  *                 (sub->vftbl->interfacetablelength > super->index) &&
3322  *                 (sub->vftbl->interfacetable[-super->index] != NULL));
3323  *
3324  *          superclass is a class:
3325  *
3326  *          OK if ((sub == NULL) || (0
3327  *                 <= (sub->vftbl->baseval - super->vftbl->baseval) <=
3328  *                 super->vftbl->diffvall));
3329  */
3330
3331                         {
3332                         classinfo *super = (classinfo*) iptr->val.a;
3333                         
3334                         d = reg_of_var(iptr->dst, REG_ITMP3);
3335                         var_to_reg_int(s1, src, d);
3336                         if (iptr->op1) {                               /* class/interface */
3337                                 if (super->flags & ACC_INTERFACE) {        /* interface       */
3338                                         M_BEQZ(s1, 9);
3339                                         M_NOP;
3340                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3341                                         M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength));
3342                                         M_IADD_IMM(REG_ITMP2, - super->index, REG_ITMP2);
3343                                         M_BLEZ(REG_ITMP2, 0);
3344                                         codegen_addxcastrefs(mcodeptr);
3345                                         M_NOP;
3346                                         M_ALD(REG_ITMP2, REG_ITMP1,
3347                                               OFFSET(vftbl, interfacetable[0]) -
3348                                               super->index * sizeof(methodptr*));
3349                                         M_BEQZ(REG_ITMP2, 0);
3350                                         codegen_addxcastrefs(mcodeptr);
3351                                         M_NOP;
3352                                         }
3353                                 else {                                     /* class           */
3354
3355                                         /*
3356                                         s2 = super->vftbl->diffval;
3357                                         M_BEQZ(s1, 6 + (s2 != 0));
3358                                         M_NOP;
3359                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3360                                         M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
3361                                         M_IADD_IMM(REG_ITMP1, - super->vftbl->baseval, REG_ITMP1);
3362                                         if (s2 == 0) {
3363                                                 M_BNEZ(REG_ITMP1, 0);
3364                                                 }
3365                                         else{
3366                                                 M_CMPULT_IMM(REG_ITMP1, s2 + 1, REG_ITMP2);
3367                                                 M_BEQZ(REG_ITMP2, 0);
3368                                                 }
3369                                         */
3370
3371                                         M_BEQZ(s1, 10 + (d == REG_ITMP3));
3372                                         M_NOP;
3373                                         M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3374                     a = dseg_addaddress ((void*) super->vftbl);
3375                     M_ALD(REG_ITMP2, REG_PV, a);
3376                     M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
3377                                         if (d != REG_ITMP3) {
3378                                                 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval));
3379                                                 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
3380                                                 M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1); 
3381                                         } else {
3382                                                 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, baseval));
3383                                                 M_ISUB(REG_ITMP1, REG_ITMP2, REG_ITMP1); 
3384                                                 M_ALD(REG_ITMP2, REG_PV, a);
3385                                                 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
3386                                         }
3387                     M_CMPULT(REG_ITMP2, REG_ITMP1, REG_ITMP2);
3388                                         M_BNEZ(REG_ITMP2, 0);
3389
3390                                         codegen_addxcastrefs(mcodeptr);
3391                                         M_NOP;
3392                                         }
3393                                 }
3394                         else
3395                                 panic ("internal error: no inlined array checkcast");
3396                         }
3397                         M_INTMOVE(s1, d);
3398                         store_reg_to_var_int(iptr->dst, d);
3399                         break;
3400
3401                 case ICMD_CHECKASIZE:  /* ..., size ==> ..., size                     */
3402
3403                         var_to_reg_int(s1, src, REG_ITMP1);
3404                         M_BLTZ(s1, 0);
3405                         codegen_addxcheckarefs(mcodeptr);
3406                         M_NOP;
3407                         break;
3408
3409                 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref  */
3410                                       /* op1 = dimension, val.a = array descriptor    */
3411
3412                         /* check for negative sizes and copy sizes to stack if necessary  */
3413
3414                         MCODECHECK((iptr->op1 << 1) + 64);
3415
3416                         for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
3417                                 var_to_reg_int(s2, src, REG_ITMP1);
3418                                 M_BLTZ(s2, 0);
3419                                 codegen_addxcheckarefs(mcodeptr);
3420                                 M_NOP;
3421
3422                                 /* copy sizes to stack (argument numbers >= INT_ARG_CNT)      */
3423
3424                                 if (src->varkind != ARGVAR) {
3425                                         M_LST(s2, REG_SP, 8 * (s1 + INT_ARG_CNT));
3426                                         }
3427                                 }
3428
3429                         /* a0 = dimension count */
3430
3431                         ICONST(argintregs[0], iptr->op1);
3432
3433                         /* a1 = arraydescriptor */
3434
3435                         a = dseg_addaddress(iptr->val.a);
3436                         M_ALD(argintregs[1], REG_PV, a);
3437
3438                         /* a2 = pointer to dimensions = stack pointer */
3439
3440                         M_INTMOVE(REG_SP, argintregs[2]);
3441
3442                         a = dseg_addaddress((void*) (builtin_nmultianewarray));
3443                         M_ALD(REG_ITMP3, REG_PV, a);
3444                         M_JSR(REG_RA, REG_ITMP3);
3445                         M_NOP;
3446                         s1 = (int)((u1*) mcodeptr - mcodebase);
3447                         if (s1 <= 32768)
3448                                 M_LDA (REG_PV, REG_RA, -s1);
3449                         else {
3450                                 panic("To big");
3451                             }
3452                         s1 = reg_of_var(iptr->dst, REG_RESULT);
3453                         M_INTMOVE(REG_RESULT, s1);
3454                         store_reg_to_var_int(iptr->dst, s1);
3455                         break;
3456
3457
3458                 default: error ("Unknown pseudo command: %d", iptr->opc);
3459         
3460    
3461
3462         } /* switch */
3463                 
3464         } /* for instruction */
3465                 
3466         /* copy values to interface registers */
3467
3468         src = bptr->outstack;
3469         len = bptr->outdepth;
3470         MCODECHECK(64+len);
3471         while (src) {
3472                 len--;
3473                 if ((src->varkind != STACKVAR)) {
3474                         s2 = src->type;
3475                         if (IS_FLT_DBL_TYPE(s2)) {
3476                                 var_to_reg_flt(s1, src, REG_FTMP1);
3477                                 if (!(interfaces[len][s2].flags & INMEMORY)) {
3478                                         M_TFLTMOVE(s2,s1,interfaces[len][s2].regoff);
3479                                         }
3480                                 else {
3481                                         M_DST(s1, REG_SP, 8 * interfaces[len][s2].regoff);
3482                                         }
3483                                 }
3484                         else {
3485                                 var_to_reg_int(s1, src, REG_ITMP1);
3486                                 if (!(interfaces[len][s2].flags & INMEMORY)) {
3487                                         M_INTMOVE(s1,interfaces[len][s2].regoff);
3488                                         }
3489                                 else {
3490                                         M_LST(s1, REG_SP, 8 * interfaces[len][s2].regoff);
3491                                         }
3492                                 }
3493                         }
3494                 src = src->prev;
3495                 }
3496         } /* if (bptr -> flags >= BBREACHED) */
3497         } /* for basic block */
3498
3499         /* bptr -> mpc = (int)((u1*) mcodeptr - mcodebase); */
3500
3501         {
3502         /* generate bound check stubs */
3503
3504         s4 *xcodeptr = NULL;
3505         
3506         for (; xboundrefs != NULL; xboundrefs = xboundrefs->next) {
3507                 if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
3508                         gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
3509                                 xboundrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
3510                         continue;
3511                         }
3512
3513
3514                 gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
3515                                   xboundrefs->branchpos, (u1*) mcodeptr - mcodebase);
3516
3517                 MCODECHECK(8);
3518
3519                 M_LDA(REG_ITMP2_XPC, REG_PV, xboundrefs->branchpos - 4);
3520
3521                 if (xcodeptr != NULL) {
3522                         int disp = xcodeptr-mcodeptr;
3523                         M_BR(disp-1);
3524                         M_NOP;
3525                         }
3526                 else {
3527                         xcodeptr = mcodeptr;
3528
3529                         a = dseg_addaddress(asm_handle_exception);
3530                         M_ALD(REG_ITMP3, REG_PV, a);
3531
3532                         M_JMP(REG_ITMP3);
3533                         a = dseg_addaddress(proto_java_lang_ArrayIndexOutOfBoundsException);
3534                         M_ALD(REG_ITMP1_XPTR, REG_PV, a);
3535                         }
3536                 }
3537
3538         /* generate negative array size check stubs */
3539
3540         xcodeptr = NULL;
3541         
3542         for (; xcheckarefs != NULL; xcheckarefs = xcheckarefs->next) {
3543                 if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
3544                         gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
3545                                 xcheckarefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
3546                         continue;
3547                         }
3548
3549                 gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
3550                                   xcheckarefs->branchpos, (u1*) mcodeptr - mcodebase);
3551
3552                 MCODECHECK(8);
3553
3554                 M_LDA(REG_ITMP2_XPC, REG_PV, xcheckarefs->branchpos - 4);
3555
3556                 if (xcodeptr != NULL) {
3557                         int disp = xcodeptr-mcodeptr;
3558                         M_BR(disp-1);
3559                         M_NOP;
3560                         }
3561                 else {
3562                         xcodeptr = mcodeptr;
3563
3564                         a = dseg_addaddress(asm_handle_exception);
3565                         M_ALD(REG_ITMP3, REG_PV, a);
3566
3567                         M_JMP(REG_ITMP3);
3568                         a = dseg_addaddress(proto_java_lang_NegativeArraySizeException);
3569                         M_ALD(REG_ITMP1_XPTR, REG_PV, a);
3570                         }
3571                 }
3572
3573         /* generate cast check stubs */
3574
3575         xcodeptr = NULL;
3576         
3577         for (; xcastrefs != NULL; xcastrefs = xcastrefs->next) {
3578                 if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
3579                         gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
3580                                 xcastrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
3581                         continue;
3582                         }
3583
3584                 gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
3585                                   xcastrefs->branchpos, (u1*) mcodeptr - mcodebase);
3586
3587                 MCODECHECK(8);
3588
3589                 M_LDA(REG_ITMP2_XPC, REG_PV, xcastrefs->branchpos - 4);
3590
3591                 if (xcodeptr != NULL) {
3592                         int disp = xcodeptr-mcodeptr;
3593                         M_BR(disp-1);
3594                         M_NOP;
3595                         }
3596                 else {
3597                         xcodeptr = mcodeptr;
3598
3599                         a = dseg_addaddress(asm_handle_exception);
3600                         M_ALD(REG_ITMP3, REG_PV, a);
3601
3602                         M_JMP(REG_ITMP3);
3603                         a = dseg_addaddress(proto_java_lang_ClassCastException);
3604                         M_ALD(REG_ITMP1_XPTR, REG_PV, a);
3605                         }
3606                 }
3607
3608
3609 #ifdef SOFTNULLPTRCHECK
3610
3611         /* generate null pointer check stubs */
3612
3613         xcodeptr = NULL;
3614
3615         for (; xnullrefs != NULL; xnullrefs = xnullrefs->next) {
3616                 if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
3617                         gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
3618                                 xnullrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
3619                         continue;
3620                         }
3621
3622                 gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
3623                                   xnullrefs->branchpos, (u1*) mcodeptr - mcodebase);
3624
3625                 MCODECHECK(8);
3626
3627                 M_LDA(REG_ITMP2_XPC, REG_PV, xnullrefs->branchpos - 4);
3628
3629                 if (xcodeptr != NULL) {
3630                         int disp = xcodeptr-mcodeptr;
3631                         M_BR(disp-1);
3632                         M_NOP;
3633                         }
3634                 else {
3635                         xcodeptr = mcodeptr;
3636
3637                         a = dseg_addaddress(asm_handle_exception);
3638                         M_ALD(REG_ITMP3, REG_PV, a);
3639
3640                         M_JMP(REG_ITMP3);
3641                         a = dseg_addaddress(proto_java_lang_NullPointerException);
3642                         M_ALD(REG_ITMP1_XPTR, REG_PV, a);
3643                         }
3644                 }
3645
3646 #endif
3647         }
3648
3649         codegen_finish((int)((u1*) mcodeptr - mcodebase));
3650
3651         docacheflush((void*) method->entrypoint,
3652                           ((u1*) mcodeptr - mcodebase));
3653 }
3654
3655
3656 /* redefinition of code generation macros (compiling into array) **************/
3657
3658 /* 
3659 These macros are newly defined to allow code generation into an array.
3660 This is necessary, because the original M_.. macros generate code by
3661 calling 'codegen_adds4' that uses an additional data structure to
3662 receive the code.
3663
3664 For a faster (but less flexible) version to generate code, these
3665 macros directly use the (s4* p) - pointer to put the code directly
3666 in a locally defined array.
3667 This makes sense only for the stub-generation-routines below.
3668 */
3669
3670 #undef M_ITYPE
3671 #define M_ITYPE(op, rs, rt, imm)\
3672   *(p++) = (((op)<<26)|((rs)<<21)|((rt)<<16)|((imm)&0xffff))
3673
3674 #undef M_JTYPE
3675 #define M_JTYPE(op, imm)\
3676   *(p++) = (((op)<<26)|((off)&0x3ffffff))
3677
3678 #undef M_RTYPE
3679 #define M_RTYPE(op, rs, rt, rd, sa, fu)\
3680   *(p++) = (((op)<<26)|((rs)<<21)|((rt)<<16)|((rd)<<11)|((sa)<<6)|(fu))
3681
3682
3683 /* function createcompilerstub *************************************************
3684
3685         creates a stub routine which calls the compiler
3686         
3687 *******************************************************************************/
3688
3689 #define COMPSTUBSIZE 4
3690
3691 u1 *createcompilerstub (methodinfo *m)
3692 {
3693         u8 *s = CNEW(u8, COMPSTUBSIZE);     /* memory to hold the stub            */
3694         s4 *p = (s4*) s;                    /* code generation pointer            */
3695         
3696                                             /* code for the stub                  */
3697         M_ALD(REG_PV, REG_PV, 24);          /* load pointer to the compiler       */
3698         M_NOP;
3699         M_JSR(REG_ITMP1, REG_PV);           /* jump to the compiler, return address
3700                                                in itmp1 is used as method pointer */
3701         M_NOP;
3702
3703         s[2] = (u8) m;                      /* literals to be adressed            */  
3704         s[3] = (u8) asm_call_jit_compiler;  /* jump directly via PV from above    */
3705
3706         (void) docacheflush((void*) s, (char*) p - (char*) s);
3707
3708 #ifdef STATISTICS
3709         count_cstub_len += COMPSTUBSIZE * 8;
3710 #endif
3711
3712         return (u1*) s;
3713 }
3714
3715
3716 /* function removecompilerstub *************************************************
3717
3718      deletes a compilerstub from memory  (simply by freeing it)
3719
3720 *******************************************************************************/
3721
3722 void removecompilerstub (u1 *stub) 
3723 {
3724         CFREE(stub, COMPSTUBSIZE * 8);
3725 }
3726
3727 /* function: createnativestub **************************************************
3728
3729         creates a stub routine which calls a native method
3730
3731 *******************************************************************************/
3732
3733 #define NATIVESTUBSIZE 20
3734 #define NATIVESTUBOFFSET 4
3735
3736 u1 *createnativestub (functionptr f, methodinfo *m)
3737 {
3738         u8 *s = CNEW(u8, NATIVESTUBSIZE);   /* memory to hold the stub            */
3739         u8 *cs = s + NATIVESTUBOFFSET;
3740         s4 *p = (s4*) (cs);                 /* code generation pointer            */
3741
3742         *(cs-1) = (u8) f;                   /* address of native method           */
3743         *(cs-2) = (u8) (&exceptionptr);     /* address of exceptionptr            */
3744         *(cs-3) = (u8) (asm_handle_nat_exception);/* addr of asm exception handler*/
3745         *(cs-4) = (u8) (&env);                /* addr of jni_environement         */
3746
3747         reg_init(m);
3748
3749         M_MOV  (argintregs[4], argintregs[5]);
3750         M_DMFC1 (REG_ITMP1, argfltregs[4]);
3751
3752         M_MOV  (argintregs[3], argintregs[4]);
3753         M_DMTC1 (REG_ITMP1, argfltregs[5]);
3754
3755         M_MOV  (argintregs[2], argintregs[3]);
3756         M_DMFC1 (REG_ITMP1, argfltregs[3]);
3757
3758         M_MOV  (argintregs[1], argintregs[2]);
3759         M_DMTC1 (REG_ITMP1, argfltregs[4]);
3760
3761         M_MOV  (argintregs[0], argintregs[1]);
3762         M_DMFC1 (REG_ITMP1, argfltregs[2]);
3763
3764         M_ALD  (argintregs[0], REG_PV, -4*8); /* load adress of jni_environement  */
3765         M_DMTC1 (REG_ITMP1, argfltregs[3]);
3766
3767         M_DMFC1 (REG_ITMP1, argfltregs[1]);
3768         M_DMFC1 (REG_ITMP2, argfltregs[0]);
3769
3770         M_DMTC1 (REG_ITMP1, argfltregs[2]);
3771         M_DMTC1 (REG_ITMP2, argfltregs[1]);
3772
3773         M_ALD  (REG_ITMP3, REG_PV, -1*8);   /* load adress of native method       */
3774         M_LDA  (REG_SP, REG_SP, -8);        /* build up stackframe                */
3775
3776         M_LST  (REG_RA, REG_SP, 0);         /* store return address               */
3777         M_JSR  (REG_RA, REG_ITMP3);         /* call native method                 */
3778
3779         M_NOP;                              /* delay slot                         */
3780         M_ALD  (REG_ITMP3, REG_PV, -2*8);   /* get address of exceptionptr        */
3781
3782         M_LLD  (REG_RA, REG_SP, 0);         /* load return address                */
3783         M_ALD  (REG_ITMP1, REG_ITMP3, 0);   /* load exception into reg. itmp1     */
3784
3785         M_BNEZ (REG_ITMP1, 2);              /* if no exception then return        */
3786         M_LDA  (REG_SP, REG_SP, 8);         /* remove stackframe, delay slot      */
3787
3788         M_RET  (REG_RA);                    /* return to caller                   */
3789         M_NOP;                              /* delay slot                         */
3790         
3791         M_AST  (REG_ZERO, REG_ITMP3, 0);    /* store NULL into exceptionptr       */
3792         M_ALD  (REG_ITMP3, REG_PV,-3*8);    /* load asm exception handler address */
3793
3794         M_JMP  (REG_ITMP3);                 /* jump to asm exception handler      */
3795         M_LDA  (REG_ITMP2, REG_RA, -4);     /* move fault address into reg. itmp2 */
3796                                             /* delay slot                         */
3797
3798         (void) docacheflush((void*) cs, (char*) p - (char*) cs);
3799
3800 #ifdef STATISTICS
3801         count_nstub_len += NATIVESTUBSIZE * 8;
3802 #endif
3803
3804         return (u1*) (s + NATIVESTUBOFFSET);
3805 }
3806
3807 /* function: removenativestub **************************************************
3808
3809     removes a previously created native-stub from memory
3810     
3811 *******************************************************************************/
3812
3813 void removenativestub (u1 *stub)
3814 {
3815         CFREE((u8*) stub - NATIVESTUBOFFSET, NATIVESTUBSIZE * 8);
3816 }
3817
3818
3819 /* function: createcalljava ****************************************************
3820
3821         creates the asm_calljavamethod (MIPS assembler does not like data in the
3822         text segment). Documentation can be found in asmpart.c.
3823         
3824 *******************************************************************************/
3825
3826 #define REG_FSS0    20
3827 #define REG_FSS1    22
3828 #define REG_FSS2    25
3829 #define REG_FSS3    27
3830 #define REG_FSS4    29
3831 #define REG_FSS5    31
3832
3833 #define CALL_JAVA_MEM_SIZE 61
3834 #define CALL_JAVA2_MEM_SIZE 61
3835 #define CALL_JAVA_ENTRY    20
3836 #define CALL_JAVA_XHANDLER 55
3837 #define CALL_JAVA2_XHANDLER 108
3838
3839 static s4 calljavamem[CALL_JAVA_MEM_SIZE];
3840 static s4 calljava2mem[CALL_JAVA2_MEM_SIZE];
3841
3842 void asm_calljavafunction_asm();
3843 void asm_calljavafunction2_asm();
3844
3845 void createcalljava ()
3846 {
3847         s4 *p;
3848         
3849         *((void**)(calljavamem + 4)) = NULL;
3850         *((void**)(calljavamem + 6)) = (void*) (calljavamem + CALL_JAVA_XHANDLER);
3851         *((void**)(calljavamem + 8)) = (void*) (calljavamem + CALL_JAVA_XHANDLER);
3852         *((void**)(calljavamem +10)) = (void*) (calljavamem + CALL_JAVA_ENTRY);
3853         *((void**)(calljava2mem + 4)) = NULL;
3854         *((void**)(calljava2mem + 6)) = (void*) (calljava2mem + CALL_JAVA2_XHANDLER);
3855         *((void**)(calljava2mem + 8)) = (void*) (calljava2mem + CALL_JAVA2_XHANDLER);
3856         *((void**)(calljava2mem +10)) = (void*) (calljava2mem + CALL_JAVA_ENTRY);
3857         
3858         calljavamem[12] = 1;                /* extable size                       */
3859         calljavamem[13] = 0;                /* fltsave                            */
3860         calljavamem[14] = 0;                /* intsave                            */
3861         calljavamem[15] = 0;                /* isleaf                             */
3862         calljavamem[16] = 0;                /* IsSync                             */
3863         calljavamem[17] = 80;               /* frame size                         */
3864         calljavamem[18] = 0;                /* method pointer (NULL)              */
3865         calljavamem[19] = 0;                /* method pointer (NULL)              */
3866
3867         calljava2mem[12] = 1;                /* extable size                      */
3868         calljava2mem[13] = 0;                /* fltsave                           */
3869         calljava2mem[14] = 1;                /* intsave                           */
3870         calljava2mem[15] = 0;                /* isleaf                            */
3871         calljava2mem[16] = 0;                /* IsSync                            */
3872         calljava2mem[17] = 88;               /* frame size                        */
3873         calljava2mem[18] = 0;                /* method pointer (NULL)             */
3874         calljava2mem[19] = 0;                /* method pointer (NULL)             */
3875
3876         p = calljavamem + CALL_JAVA_ENTRY;  /* code generation pointer            */
3877         memcpy(p, asm_calljavafunction_asm,
3878                         (CALL_JAVA_MEM_SIZE - CALL_JAVA_ENTRY) * (int) sizeof(s4));
3879
3880         p = calljava2mem + CALL_JAVA_ENTRY;  /* code generation pointer           */
3881         memcpy(p, asm_calljavafunction2_asm,
3882                         (CALL_JAVA2_MEM_SIZE - CALL_JAVA_ENTRY) * (int) sizeof(s4));
3883
3884         (void) docacheflush((void*)(calljavamem + CALL_JAVA_ENTRY),
3885                (CALL_JAVA_MEM_SIZE - CALL_JAVA_ENTRY) * (int) sizeof(s4));
3886         (void) docacheflush((void*)(calljava2mem + CALL_JAVA_ENTRY),
3887                (CALL_JAVA2_MEM_SIZE - CALL_JAVA_ENTRY) * (int) sizeof(s4));
3888 }
3889
3890
3891 typedef java_objectheader* (*asm_fptr)(methodinfo*, void*, void*, void*, void*);
3892 typedef java_objectheader* (*asm_fptr2)(methodinfo*, u4, u4, void*);
3893 typedef jdouble (*asm_fptr2double)(methodinfo*, u4, u4, void*);
3894 typedef jlong (*asm_fptr2long)(methodinfo*, u4, u4, void*);
3895
3896
3897 java_objectheader *asm_calljavafunction (methodinfo *m, void *arg1, void *arg2,
3898                                                       void *arg3, void *arg4)
3899 {
3900         return ((asm_fptr)(calljavamem + 20))(m, arg1, arg2, arg3, arg4);
3901 }
3902
3903 java_objectheader *asm_calljavafunction2(methodinfo *m, u4 count, u4 size , void *callblock)
3904 {
3905         return ((asm_fptr2)(calljava2mem + 20))(m, count, size, callblock);
3906 }
3907
3908 jdouble asm_calljavafunction2double(methodinfo *m, u4 count, u4 size , void *callblock)
3909 {
3910         return ((asm_fptr2double)(calljava2mem + 20))(m, count, size, callblock);
3911 }
3912
3913 jlong asm_calljavafunction2long(methodinfo *m, u4 count, u4 size , void *callblock)
3914 {
3915         return ((asm_fptr2long)(calljava2mem + 20))(m, count, size, callblock);
3916 }
3917
3918 void docacheflush(u1 *p, long bytelen)
3919 {
3920         u1 *e = p + bytelen;
3921         long psize = sysconf(_SC_PAGESIZE);
3922         p -= (long) p & (psize-1);
3923         e += psize - ((((long) e - 1) & (psize-1)) + 1);
3924         bytelen = e-p;
3925         mprotect(p, bytelen, PROT_READ|PROT_WRITE|PROT_EXEC);
3926 }
3927
3928
3929 /*
3930  * These are local overrides for various environment variables in Emacs.
3931  * Please do not remove this and leave it at the end of the file, where
3932  * Emacs will automagically detect them.
3933  * ---------------------------------------------------------------------
3934  * Local variables:
3935  * mode: c
3936  * indent-tabs-mode: t
3937  * c-basic-offset: 4
3938  * tab-width: 4
3939  * End:
3940  */