* linux/md-os.c (md_signal_handler_sigusr1): Implemented.
[cacao.git] / src / vm / jit / m68k / emit.c
1 /* src/vm/jit/m68k/emit.c
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: arch.h 5330 2006-09-05 18:43:12Z edwin $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33
34 #include "emit.h"
35 #include "vm/jit/emit-common.h"
36 #include "vm/exceptions.h"
37 #include "vm/jit/asmpart.h"
38 #include "vm/builtin.h"
39
40 #include "mm/memory.h"
41
42 #include "threads/lock-common.h"
43
44 #include "codegen.h"
45 #include "md-os.h"
46
47 /* emit_mov_imm_reg **************************************************************************
48  *
49  *      Loads an immededat operand into an integer data register
50  *
51  ********************************************************************************************/
52 void emit_mov_imm_reg (codegendata *cd, s4 imm, s4 dreg)
53 {
54         /* FIXME: -1 can be used as byte form 0xff, but this ifs cascade is plain wrong it seems */
55
56         if ( (imm & 0x0000007F) == imm) {
57                 /* use byte form */
58                 *((s2*)cd->mcodeptr) = 0x7000 | (dreg << 9) | imm;      /* MOVEQ.L */
59                 cd->mcodeptr += 2;
60         } else if ((imm  & 0x00007FFF) == imm)  {
61                 /* use word form */
62                 OPWORD( ((7<<6) | (dreg << 3) | 5), 7, 4);                      /* MVS.W */
63                 *((s2*)cd->mcodeptr) = (s2)imm;
64                 cd->mcodeptr += 2;
65         } else {
66                 /* use long form */
67                 OPWORD( ((2<<6) | (dreg << 3) | 0), 7, 4);
68                 *((s4*)cd->mcodeptr) = (s4)imm;
69                 cd->mcodeptr += 4;
70
71         }
72 }
73
74 /* emit_copy *******************************************************************
75
76    Generates a register/memory to register/memory copy.
77
78 *******************************************************************************/
79
80 void emit_copy(jitdata *jd, instruction *iptr)
81 {
82         codegendata *cd;
83         varinfo     *src;
84         varinfo     *dst;
85         s4           s1, d;
86
87         /* get required compiler data */
88
89         cd = jd->cd;
90
91         /* get source and destination variables */
92
93         src = VAROP(iptr->s1);
94         dst = VAROP(iptr->dst);
95
96         if ((src->vv.regoff != dst->vv.regoff) ||
97                 (IS_INMEMORY(src->flags ^ dst->flags))) {
98
99                 if ((src->type == TYPE_RET) || (dst->type == TYPE_RET)) {
100                         /* emit nothing, as the value won't be used anyway */
101                         return;
102                 }
103
104                 /* If one of the variables resides in memory, we can eliminate
105                    the register move from/to the temporary register with the
106                    order of getting the destination register and the load. */
107
108                 if (IS_INMEMORY(src->flags)) {
109                         if (IS_LNG_TYPE(src->type))
110                                 d = codegen_reg_of_var(iptr->opc, dst, REG_ITMP12_PACKED);
111                         else
112                                 d = codegen_reg_of_var(iptr->opc, dst, REG_IFTMP);
113
114                         s1 = emit_load(jd, iptr, src, d);
115                 }
116                 else {
117                         if (IS_LNG_TYPE(src->type))
118                                 s1 = emit_load(jd, iptr, src, REG_ITMP12_PACKED);
119                         else
120                                 s1 = emit_load(jd, iptr, src, REG_IFTMP);
121
122                         d = codegen_reg_of_var(iptr->opc, dst, s1);
123                 }
124
125                 if (s1 != d) {
126                         switch(src->type)       {
127                         case TYPE_INT: M_INTMOVE(s1, d); break;
128                         case TYPE_ADR: M_ADRMOVE(s1, d); break;
129                         case TYPE_LNG: M_LNGMOVE(s1, d); break;
130 #if !defined(ENABLE_SOFTFLOAT)
131                         case TYPE_FLT: M_FLTMOVE(s1, d); break;
132                         case TYPE_DBL: M_DBLMOVE(s1, d); break;
133 #else
134                         case TYPE_FLT: M_INTMOVE(s1, d); break;
135                         case TYPE_DBL: M_LNGMOVE(s1, d); break;
136 #endif
137                         default:
138                                 vm_abort("emit_copy: unknown type %d", src->type);
139                         }
140                 }
141
142                 emit_store(jd, iptr, dst, d);
143         }
144 }
145
146
147 /* emit_store ******************************************************************
148
149    Emits a possible store of the destination operand.
150
151 *******************************************************************************/
152
153 inline void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
154 {
155         codegendata  *cd;
156
157         /* get required compiler data */
158
159         cd = jd->cd;
160
161         if (IS_INMEMORY(dst->flags)) {
162                 COUNT_SPILLS;
163         
164                 switch(dst->type)       {
165 #if defined(ENABLE_SOFTFLOAT)
166                         case TYPE_DBL:
167 #endif
168                         case TYPE_LNG:
169                                 M_LST(d, REG_SP, dst->vv.regoff * 4);
170                                 break;
171 #if defined(ENABLE_SOFTFLOAT)
172                         case TYPE_FLT:
173 #endif
174                         case TYPE_INT:
175                                 M_IST(d, REG_SP, dst->vv.regoff * 4);
176                                 break;
177                         case TYPE_ADR:
178                                 M_AST(d, REG_SP, dst->vv.regoff * 4);
179                                 break;
180 #if !defined(ENABLE_SOFTFLOAT)
181                         case TYPE_DBL:
182                                 M_DST(d, REG_SP, dst->vv.regoff * 4);
183                                 break;
184                         case TYPE_FLT:
185                                 M_FST(d, REG_SP, dst->vv.regoff * 4);
186                                 break;
187 #endif
188                         default:
189                                 vm_abort("emit_store: unknown type %d", dst->type);
190                 }
191         }
192 }
193
194
195 /* emit_load *******************************************************************
196
197    Emits a possible load of an operand.
198
199 *******************************************************************************/
200
201 s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
202 {
203         codegendata *cd;
204         s4           disp;
205         s4           reg;
206
207         /* get required compiler data */
208
209         cd = jd->cd;
210
211         if (IS_INMEMORY(src->flags)) {
212                 COUNT_SPILLS;
213
214                 disp = src->vv.regoff * 4;
215         
216                 switch (src->type)      {
217 #if defined(ENABLE_SOFTFLOAT)
218                         case TYPE_FLT:
219 #endif
220                         case TYPE_INT: 
221                                 M_ILD(tempreg, REG_SP, disp);
222                                 break;
223 #if defined(ENABLE_SOFTFLOAT)
224                         case TYPE_DBL:
225 #endif
226                         case TYPE_LNG:
227                                 M_LLD(tempreg, REG_SP, disp);
228                                 break;
229                         case TYPE_ADR:
230                                 M_ALD(tempreg, REG_SP, disp);
231                                 break;
232 #if !defined(ENABLE_SOFTFLOAT)
233                         case TYPE_FLT:
234                                 M_FLD(tempreg, REG_SP, disp);
235                                 break;
236                         case TYPE_DBL:
237                                 M_DLD(tempreg, REG_SP, disp);
238                                 break;
239 #endif
240                         default:
241                                 vm_abort("emit_load: unknown type %d", src->type);
242                 }
243                 #if 0
244                 if (IS_FLT_DBL_TYPE(src->type)) {
245                         if (IS_2_WORD_TYPE(src->type)) {
246                                 M_DLD(tempreg, REG_SP, disp);
247                          } else {
248                                 M_FLD(tempreg, REG_SP, disp);
249                         }
250                 } else {
251                         if (IS_2_WORD_TYPE(src->type)) {
252                                 M_LLD(tempreg, REG_SP, disp);
253                         } else {
254                                 M_ILD(tempreg, REG_SP, disp);
255                         }
256                 }
257                 #endif
258
259                 reg = tempreg;
260         }
261         else
262                 reg = src->vv.regoff;
263
264         return reg;
265 }
266
267
268 /* emit_patcher_stubs **********************************************************
269
270    Generates the code for the patcher stubs.
271
272 *******************************************************************************/
273 void emit_patcher_stubs(jitdata *jd)
274 {
275         codegendata *cd;
276         patchref    *pref;
277         u8           mcode;
278         u1          *savedmcodeptr;
279         u1          *tmpmcodeptr;
280         s4           targetdisp;
281         s4           disp;
282
283         /* get required compiler data */
284
285         cd = jd->cd;
286
287         /* generate code patching stub call code */
288
289         targetdisp = 0;
290
291         for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
292                 /* check code segment size */
293
294                 MCODECHECK(512);
295
296                 /* Get machine code which is patched back in later. A
297                    `bsr.l' is 6 bytes long. */
298
299                 savedmcodeptr = cd->mcodebase + pref->branchpos;
300                 mcode = *((u8 *) savedmcodeptr);
301
302                 /* patch in `bsr.l' to call the following code */
303
304                 tmpmcodeptr  = cd->mcodeptr;    /* save current mcodeptr              */
305                 cd->mcodeptr = savedmcodeptr;   /* set mcodeptr to patch position     */
306
307                 M_BSR_IMM(tmpmcodeptr - (savedmcodeptr + PATCHER_CALL_SIZE) + 4);
308
309                 cd->mcodeptr = tmpmcodeptr;     /* restore the current mcodeptr       */
310
311                 /* save REG_ITMP3, restored in asm_patcher_wrapper  */
312                 M_IPUSH(REG_ITMP3);             
313
314                 /* move pointer to java_objectheader onto stack */
315
316 #if defined(ENABLE_THREADS)
317                 (void) dseg_add_unique_address(cd, NULL);                  /* flcword */
318                 (void) dseg_add_unique_address(cd, lock_get_initial_lock_word());
319                 disp = dseg_add_unique_address(cd, NULL);                  /* vftbl   */
320
321                 M_IMOV_IMM32(0, REG_ITMP3);
322                 dseg_adddata(cd);
323                 M_IADD_IMM(disp, REG_ITMP3);
324                 M_IPUSH(REG_ITMP3);
325 #else
326                 M_IPUSH_IMM(0);
327 #endif
328
329                 /* push move machine code bytes and classinfo pointer */
330
331                 M_IPUSH_IMM(mcode >> 32);
332                 M_IPUSH_IMM(mcode);
333                 M_IPUSH_IMM(pref->ref);
334                 M_IPUSH_IMM(pref->patcher);
335
336                 M_JMP_IMM(asm_patcher_wrapper);
337         }
338 }
339 s4 emit_load_low(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg) 
340 {
341         codegendata  *cd;
342         s4            disp;
343         s4            reg;
344
345 #if !defined(ENABLE_SOFTFLOAT)
346         assert(src->type == TYPE_LNG);
347 #else
348         assert(src->type == TYPE_LNG || src->type == TYPE_DBL);
349 #endif
350
351         /* get required compiler data */
352         cd = jd->cd;
353
354         if (IS_INMEMORY(src->flags)) {
355                 COUNT_SPILLS;
356
357                 disp = src->vv.regoff * 4;
358                 M_ILD(tempreg, REG_SP, disp + 4);
359                 reg = tempreg;
360         } else {
361                 reg = GET_LOW_REG(src->vv.regoff);
362         }
363         return reg;
364 }
365 s4 emit_load_high(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
366 {
367         codegendata  *cd;
368         s4            disp;
369         s4            reg;
370
371 #if !defined(ENABLE_SOFTFLOAT)
372         assert(src->type == TYPE_LNG);
373 #else
374         assert(src->type == TYPE_LNG || src->type == TYPE_DBL);
375 #endif
376         /* get required compiler data */
377         cd = jd->cd;
378
379         if (IS_INMEMORY(src->flags)) {
380                 COUNT_SPILLS;
381                 disp = src->vv.regoff * 4;
382                 M_ILD(tempreg, REG_SP, disp);
383                 reg = tempreg;
384         } else {
385                 reg = GET_HIGH_REG(src->vv.regoff);
386         }
387         return reg;
388 }
389 /* emit_branch *****************************************************************
390
391    Emits the code for conditional and unconditional branchs.
392
393 *******************************************************************************/
394 void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 opt) 
395
396         /* calculate the different displacements */
397         /* PC is a at branch instruction + 2 */
398         /* coditional and uncondition branching work the same way */
399         /* short branches have signed 16 bit offset */
400         /* long branches are signed 32 bit */
401         /* the 8 bit offset branching instructions are not used */
402
403         disp  =  disp - 2;
404
405         /* check displacement for overflow */
406         if ((disp & 0x0000FFFF) != disp)        {
407                 if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
408                         cd->flags |= (CODEGENDATA_FLAG_ERROR | CODEGENDATA_FLAG_LONGBRANCHES);
409                 }
410         }
411
412         /* check which branch to generate */
413
414         if (condition == BRANCH_UNCONDITIONAL) {
415                 if (CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd))      {
416                         M_BR_32(disp);
417                 } else  {
418                         M_BR_16(disp);
419                 }
420         } else {
421                 if (CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
422                         switch (condition) {
423                         case BRANCH_EQ:
424                                 M_BEQ_32(disp);
425                                 break;
426                         case BRANCH_NE:
427                                 M_BNE_32(disp);
428                                 break;
429                         case BRANCH_LT:
430                                 M_BLT_32(disp);
431                                 break;
432                         case BRANCH_GE:
433                                 M_BGE_32(disp);
434                                 break;
435                         case BRANCH_GT:
436                                 M_BGT_32(disp);
437                                 break;
438                         case BRANCH_LE:
439                                 M_BLE_32(disp);
440                                 break;
441                         case BRANCH_NAN:
442                                 M_BNAN_32(disp);
443                                 break;
444                         case BRANCH_UGT:
445                                 M_BHI_32(disp);
446                                 break;
447
448                         default:
449                                 vm_abort("emit_branch: unknown condition %d", condition);
450                         }
451                 } else {
452                         switch (condition) {
453                         case BRANCH_EQ:
454                                 M_BEQ_16(disp);
455                                 break;
456                         case BRANCH_NE:
457                                 M_BNE_16(disp);
458                                 break;
459                         case BRANCH_LT:
460                                 M_BLT_16(disp);
461                                 break;
462                         case BRANCH_GE:
463                                 M_BGE_16(disp);
464                                 break;
465                         case BRANCH_GT:
466                                 M_BGT_16(disp);
467                                 break;
468                         case BRANCH_LE:
469                                 M_BLE_16(disp);
470                                 break;
471                         case BRANCH_NAN:
472                                 M_BNAN_16(disp);
473                                 break;
474                         case BRANCH_UGT:
475                                 M_BHI_16(disp);
476                                 break;
477                         default:
478                                 vm_abort("emit_branch: unknown condition %d", condition);
479                         }
480                 }
481         }
482 }
483
484 /* emit_replacement_stubs ******************************************************
485
486    Generates the code for the replacement stubs.
487
488 *******************************************************************************/
489
490 #if defined(ENABLE_REPLACEMENT)
491 void emit_replacement_stubs(jitdata *jd)
492 {
493         codegendata *cd;
494         codeinfo    *code;
495         rplpoint    *rplp;
496         s4           i;
497         s4           branchmpc;
498         s4           outcode;
499
500         /* get required compiler data */
501
502         cd   = jd->cd;
503         code = jd->code;
504
505         rplp = code->rplpoints;
506
507         /* store beginning of replacement stubs */
508
509         code->replacementstubs = (u1*) (cd->mcodeptr - cd->mcodebase);
510
511         for (i = 0; i < code->rplpointcount; ++i, ++rplp) {
512                 /* do not generate stubs for non-trappable points */
513
514                 if (rplp->flags & RPLPOINT_FLAG_NOTRAP)
515                         continue;
516
517                 M_JSR_IMM(0);
518 #if 0
519                 /* check code segment size */
520
521                 MCODECHECK(512);
522
523                 /* note start of stub code */
524
525                 outcode = (s4) (cd->mcodeptr - cd->mcodebase);
526
527                 /* push address of `rplpoint` struct */
528                         
529                 M_PUSH_IMM(rplp);
530
531                 /* jump to replacement function */
532
533                 M_PUSH_IMM(asm_replacement_out);
534                 M_RET;
535
536                 /* add jump reference for COUNTDOWN points */
537
538                 if (rplp->flags & RPLPOINT_FLAG_COUNTDOWN) {
539
540                         branchmpc = (s4)rplp->pc + (7 + 6);
541
542                         md_codegen_patch_branch(cd, branchmpc, (s4) outcode);
543                 }
544
545                 assert(((cd->mcodeptr - cd->mcodebase) - outcode) == REPLACEMENT_STUB_SIZE);
546 #endif
547         }
548 }
549 #endif /* defined(ENABLE_REPLACEMENT) */
550         
551
552
553 #if !defined(NDEBUG)
554 /*
555  *      Trace functions. Implement -verbose:call flag
556  *      code marked by real NOP, but performance is no matter when using -verbose:call :)
557  */
558 void emit_verbosecall_enter(jitdata* jd) 
559
560         methodinfo   *m;
561         codegendata  *cd;
562         registerdata *rd;
563         methoddesc   *md;
564         s4      disp,i,t;
565
566
567         if (!JITDATA_HAS_FLAG_VERBOSECALL(jd))
568                 return;
569         
570         /* get required compiler data */
571         m  = jd->m;
572         cd = jd->cd;
573         rd = jd->rd;
574         md = m->parseddesc;
575
576         /* mark trace code */
577         M_NOP;
578
579         M_IPUSH(REG_D0);
580         M_IPUSH(REG_D1);
581         M_APUSH(REG_A0);
582         M_APUSH(REG_A1);
583
584 #if !defined(ENABLE_SOFTFLOAT)
585         M_AADD_IMM(-8*2, REG_SP);
586         M_FSTORE(REG_F0, REG_SP, 8);
587         M_FSTORE(REG_F1, REG_SP, 0);
588
589         disp = 4*4 + 8*2 + 4;   /* points to old argument stack initially */
590 #else
591         disp = 4*4 + 4;
592 #endif
593         /* builtin_verbosecall_enter takes all args as s8 type */
594         /* TRACE_ARGS_NUM is the number of args the builtin_verbosecall_enter expects */
595         M_IPUSH_IMM(m);
596         
597
598         /* travel up stack to the first argument of the function which needs to be copied */
599         for (i=0; (i < md->paramcount) && (i < TRACE_ARGS_NUM); i++)    {
600                 disp += 4;
601                 if (IS_2_WORD_TYPE(md->paramtypes[i].type)) {   
602                         disp += 4;
603                 }
604         }
605
606         /* disp now points to the first arg which gets copied to the trace stack, relative to REG_SP! */
607         for (i=TRACE_ARGS_NUM-1; i>=0; --i) {
608                 if (i < md->paramcount) {
609                         /* traced function has such an argument */
610                         t = md->paramtypes[i].type;
611                         
612                         if (IS_2_WORD_TYPE(t))  {
613                                 /* copy from original argument stack */
614                                 M_ILD(REG_ITMP1, REG_SP, disp);
615                                 M_IPUSH(REG_ITMP1);
616                                 M_ILD(REG_ITMP1, REG_SP, disp);
617                                 M_IPUSH(REG_ITMP1);
618                         } else  {
619                                 /* displacment is increased as 4 byte on original stack but 8 byte on trace stack */
620                                 M_ILD(REG_ITMP1, REG_SP, disp);
621                                 M_IPUSH(REG_ITMP1);
622                                 M_IPUSH_IMM(0);
623                                 disp += 4;
624                         }
625                 } else  {
626                         /* function has no arg here, push nothing and adapt displacement */
627                         M_IPUSH_IMM(0);
628                         M_IPUSH_IMM(0);
629                         disp += 8;
630                 }
631         }
632         M_JSR_IMM(builtin_verbosecall_enter);
633         /* pop arguments off stack */
634         M_AADD_IMM(TRACE_ARGS_NUM*8+4, REG_SP);
635
636 #if !defined(ENABLE_SOFTFLOAT)
637         M_FSTORE(REG_F1, REG_SP, 0);
638         M_FSTORE(REG_F0, REG_SP, 8);
639         M_AADD_IMM(8*2, REG_SP);
640 #endif
641
642         M_APOP(REG_A1);
643         M_APOP(REG_A0);
644         M_IPOP(REG_D1);
645         M_IPOP(REG_D0);
646
647         M_NOP;
648 }
649 void emit_verbosecall_exit(jitdata* jd) 
650
651         methodinfo   *m;
652         codegendata  *cd;
653         registerdata *rd;
654         methoddesc   *md;
655
656         if (!JITDATA_HAS_FLAG_VERBOSECALL(jd))
657                 return;
658
659         /* get required compiler data */
660         m  = jd->m;
661         cd = jd->cd;
662         rd = jd->rd;
663         md = m->parseddesc;
664
665         /* void builtin_verbosecall_exit(s8 l, double d, float f, methodinfo *m); */
666
667
668         /* mark trace code */
669         M_NOP;
670
671 #if !defined(ENABLE_SOFTFLOAT)
672         M_AADD_IMM(-8, REG_SP);
673         M_FSTORE(REG_F1, REG_SP, 0);
674 #endif
675
676         M_IPUSH_IMM(m);                                 /* push methodinfo */
677
678 #if !defined(ENABLE_SOFTFLOAT)
679         M_AADD_IMM(-3*4, REG_SP);
680         M_FST(REG_D0, REG_SP, 8);
681         M_DST(REG_D0, REG_SP, 0);
682 #else
683         M_IPUSH_IMM(0);
684
685         M_IPUSH_IMM(0);
686         M_IPUSH_IMM(0);
687 #endif
688
689         M_IPUSH(GET_HIGH_REG(REG_RESULT_PACKED))
690         M_IPUSH(GET_LOW_REG(REG_RESULT_PACKED))         /* push long result */
691
692         M_JSR_IMM(builtin_verbosecall_exit);
693
694         /* poping result registers from stack */
695         M_IPOP(GET_LOW_REG(REG_RESULT_PACKED))
696         M_IPOP(GET_HIGH_REG(REG_RESULT_PACKED))
697
698 #if !defined(ENABLE_SOFTFLOAT)
699         M_DLD(REG_D0, REG_SP, 0)
700         M_FLD(REG_D0, REG_SP, 8)
701 #endif
702         M_AADD_IMM(3*4 + 4, REG_SP);
703
704 #if !defined(ENABLE_SOFTFLOAT)
705         M_FLOAD(REG_F1, REG_SP, 0)
706         M_AADD_IMM(8, REG_SP);
707 #endif
708
709         M_NOP;
710 }
711 #endif
712
713 /* emit_classcast_check ********************************************************
714
715    Emit a ClassCastException check.
716
717 *******************************************************************************/
718
719 void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 reg, s4 s1)
720 {
721         if (INSTRUCTION_MUST_CHECK(iptr)) {
722                 switch (condition) {
723                 case BRANCH_LE:
724                         M_BGT(4);
725                         break;
726                 case BRANCH_EQ:
727                         M_BNE(4);
728                         break;
729                 case BRANCH_GT:
730                         M_BLE(4);
731                         break;
732                 case BRANCH_UGT:
733                         M_BLS(4);
734                         break;
735                 default:
736                         vm_abort("emit_classcast_check: unknown condition %d", condition);
737                 }
738                 M_TRAP_SETREGISTER(s1);
739                 M_TRAP(EXCEPTION_HARDWARE_CLASSCAST);
740         }
741 }
742
743 /* emit_arrayindexoutofbounds_check ********************************************
744
745    Emit a ArrayIndexOutOfBoundsException check.
746
747 *******************************************************************************/
748 void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1, s4 s2)
749 {
750         if (INSTRUCTION_MUST_CHECK(iptr)) {
751                 M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));
752                 M_ICMP(s2, REG_ITMP3);
753                 M_BHI(4);
754                 M_TRAP_SETREGISTER(s2);
755                 M_TRAP(EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS);
756         }
757 }
758
759 /* emit_nullpointer_check ******************************************************
760
761    Emit a NullPointerException check.
762
763 *******************************************************************************/
764 void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg)
765 {
766         if (INSTRUCTION_MUST_CHECK(iptr)) {
767                 /* XXX: this check is copied to call monitor_enter 
768                  * invocation at the beginning of codegen.c */
769                 M_ATST(reg);
770                 M_BNE(2);
771                 M_TRAP(M68K_EXCEPTION_HARDWARE_NULLPOINTER);
772         }
773 }
774
775 /* emit_arithmetic_check *******************************************************
776
777    Emit an ArithmeticException check.
778
779 *******************************************************************************/
780
781 void emit_arithmetic_check(codegendata *cd, instruction *iptr, s4 reg)
782 {
783         if (INSTRUCTION_MUST_CHECK(iptr)) {
784                 M_ITST(reg);
785                 M_BNE(2);
786                 M_TRAP(EXCEPTION_HARDWARE_ARITHMETIC);
787         }
788 }
789
790 /* emit_exception_check_ireg **************************************************
791
792    Emit an Exception check. Teste register is integer REG_RESULT
793
794 *******************************************************************************/
795 void emit_exception_check(codegendata *cd, instruction *iptr)
796 {
797         if (INSTRUCTION_MUST_CHECK(iptr)) {
798                 M_ITST(REG_RESULT);
799                 M_BNE(2);
800                 /*M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_EXCEPTION);*/
801                 M_TRAP(EXCEPTION_HARDWARE_EXCEPTION);
802         }
803 }
804
805
806 /*
807  * These are local overrides for various environment variables in Emacs.
808  * Please do not remove this and leave it at the end of the file, where
809  * Emacs will automagically detect them.
810  * ---------------------------------------------------------------------
811  * Local variables:
812  * mode: c
813  * indent-tabs-mode: t
814  * c-basic-offset: 4
815  * tab-width: 4
816  * End:
817  * vim:noexpandtab:sw=4:ts=4:
818  */