Clean up more tracing.
[external/binutils.git] / sim / v850 / simops.c
1 #include <signal.h>
2 #include "sim-main.h"
3 #include "v850_sim.h"
4 #include "simops.h"
5
6 #ifdef HAVE_UTIME_H
7 #include <utime.h>
8 #endif
9
10 #ifdef HAVE_TIME_H
11 #include <time.h>
12 #endif
13
14 #ifdef HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17
18 #ifdef HAVE_STRING_H
19 #include <string.h>
20 #else
21 #ifdef HAVE_STRINGS_H
22 #include <strings.h>
23 #endif
24 #endif
25
26
27
28
29
30  /* FIXME - should be including a version of syscall.h that does not
31     pollute the name space */
32 #include "../../libgloss/v850/sys/syscall.h"
33
34 #include "libiberty.h"
35
36 #include <errno.h>
37 #if !defined(__GO32__) && !defined(_WIN32)
38 #include <sys/stat.h>
39 #include <sys/times.h>
40 #include <sys/time.h>
41 #endif
42
43 /* start-sanitize-v850e */
44 /* This is an array of the bit positions of registers r20 .. r31 in
45    that order in a prepare/dispose instruction.  */
46 int type1_regs[12] = { 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 0, 21 };
47 /* end-sanitize-v850e */
48 /* start-sanitize-v850eq */
49 /* This is an array of the bit positions of registers r16 .. r31 in
50    that order in a push/pop instruction.  */
51 int type2_regs[16] = { 3, 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
52 /* This is an array of the bit positions of registers r1 .. r15 in
53    that order in a push/pop instruction.  */
54 int type3_regs[15] = { 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
55 /* end-sanitize-v850eq */
56
57 #ifdef DEBUG
58 #ifndef SIZE_INSTRUCTION
59 #define SIZE_INSTRUCTION 18
60 #endif
61
62 #ifndef SIZE_VALUES
63 #define SIZE_VALUES 11
64 #endif
65
66
67 unsigned32 trace_values[3];
68 int trace_num_values;
69 unsigned32 trace_pc;
70 const char *trace_name;
71 const char *trace_module;
72
73
74 void
75 trace_input (name, type, size)
76      char *name;
77      enum op_types type;
78      int size;
79 {
80
81   if (!TRACE_ALU_P (STATE_CPU (simulator, 0)))
82     return;
83
84   trace_pc = PC;
85   trace_name = name;
86   trace_module = "alu";
87
88   switch (type)
89     {
90     default:
91     case OP_UNKNOWN:
92     case OP_NONE:
93     case OP_TRAP:
94       trace_num_values = 0;
95       break;
96       
97     case OP_REG:
98     case OP_REG_REG_MOVE:
99       trace_values[0] = State.regs[OP[0]];
100       trace_num_values = 1;
101       break;
102       
103       /* start-sanitize-v850e */
104     case OP_BIT_CHANGE:
105       /* end-sanitize-v850e */
106     case OP_REG_REG:
107     case OP_REG_REG_CMP:
108       trace_values[0] = State.regs[OP[1]];
109       trace_values[1] = State.regs[OP[0]];
110       trace_num_values = 2;
111       break;
112       
113     case OP_IMM_REG:
114     case OP_IMM_REG_CMP:
115       trace_values[0] = SEXT5 (OP[0]);
116       trace_values[1] = OP[1];
117       trace_num_values = 2;
118       break;
119       
120     case OP_IMM_REG_MOVE:
121       trace_values[0] = SEXT5 (OP[0]);
122       trace_num_values = 1;
123       break;
124       
125     case OP_COND_BR:
126       trace_values[0] = State.pc;
127       trace_values[1] = SEXT9 (OP[0]);
128       trace_values[2] = PSW;
129       trace_num_values = 3;
130       break;
131       
132     case OP_LOAD16:
133       trace_values[0] = OP[1] * size;
134       trace_values[1] = State.regs[30];
135       trace_num_values = 2;
136       break;
137       
138     case OP_STORE16:
139       trace_values[0] = State.regs[OP[0]];
140       trace_values[1] = OP[1] * size;
141       trace_values[2] = State.regs[30];
142       trace_num_values = 3;
143       break;
144       
145     case OP_LOAD32:
146       trace_values[0] = EXTEND16 (OP[2]);
147       trace_values[1] = State.regs[OP[0]];
148       trace_num_values = 2;
149       break;
150       
151     case OP_STORE32:
152       trace_values[0] = State.regs[OP[1]];
153       trace_values[1] = EXTEND16 (OP[2]);
154       trace_values[2] = State.regs[OP[0]];
155       trace_num_values = 3;
156       break;
157       
158     case OP_JUMP:
159       trace_values[0] = SEXT22 (OP[0]);
160       trace_values[1] = State.pc;
161       trace_num_values = 2;
162       break;
163       
164     case OP_IMM_REG_REG:
165       trace_values[0] = EXTEND16 (OP[0]) << size;
166       trace_values[1] = State.regs[OP[1]];
167       trace_num_values = 2;
168       break;
169       
170     case OP_IMM16_REG_REG:
171       trace_values[0] = EXTEND16 (OP[2]) << size;
172       trace_values[1] = State.regs[OP[1]];
173       trace_num_values = 2;
174       break;
175       
176     case OP_UIMM_REG_REG:
177       trace_values[0] = (OP[0] & 0xffff) << size;
178       trace_values[1] = State.regs[OP[1]];
179       trace_num_values = 2;
180       break;
181       
182     case OP_UIMM16_REG_REG:
183       trace_values[0] = (OP[2]) << size;
184       trace_values[1] = State.regs[OP[1]];
185       trace_num_values = 2;
186       break;
187       
188     case OP_BIT:
189       trace_num_values = 0;
190       break;
191       
192     case OP_EX1:
193       trace_values[0] = PSW;
194       trace_num_values = 1;
195       break;
196       
197     case OP_EX2:
198       trace_num_values = 0;
199       break;
200       
201     case OP_LDSR:
202       trace_values[0] = State.regs[OP[0]];
203       trace_num_values = 1;
204       break;
205       
206     case OP_STSR:
207       trace_values[0] = State.sregs[OP[1]];
208       trace_num_values = 1;
209     }
210   
211 }
212
213 void
214 trace_result (int has_result, unsigned32 result)
215 {
216   char buf[1000];
217   char *chp;
218
219   buf[0] = '\0';
220   chp = buf;
221
222   /* write out the values saved during the trace_input call */
223   {
224     int i;
225     for (i = 0; i < trace_num_values; i++)
226       {
227         sprintf (chp, "%*s0x%.8lx", SIZE_VALUES - 10, "", trace_values[i]);
228         chp = strchr (chp, '\0');
229       }
230     while (i++ < 3)
231       {
232         sprintf (chp, "%*s", SIZE_VALUES, "");
233         chp = strchr (chp, '\0');
234       }
235   }
236
237   /* append any result to the end of the buffer */
238   if (has_result)
239     sprintf (chp, " :: 0x%.8lx", (unsigned long)result);
240   
241   trace_one_insn (simulator, STATE_CPU (simulator, 0), trace_pc,
242                   TRACE_LINENUM_P (STATE_CPU (simulator, 0)),
243                   "simops", __LINE__, trace_module, 
244                   "%-*s -%s", SIZE_INSTRUCTION, trace_name, buf);
245 }
246
247 void
248 trace_output (result)
249      enum op_types result;
250 {
251   if (!TRACE_ALU_P (STATE_CPU (simulator, 0)))
252     return;
253
254   switch (result)
255     {
256     default:
257     case OP_UNKNOWN:
258     case OP_NONE:
259     case OP_TRAP:
260     case OP_REG:
261     case OP_REG_REG_CMP:
262     case OP_IMM_REG_CMP:
263     case OP_COND_BR:
264     case OP_STORE16:
265     case OP_STORE32:
266     case OP_BIT:
267     case OP_EX2:
268       trace_result (0, 0);
269       break;
270       
271     case OP_LOAD16:
272     case OP_STSR:
273       trace_result (1, State.regs[OP[0]]);
274       break;
275       
276     case OP_REG_REG:
277     case OP_REG_REG_MOVE:
278     case OP_IMM_REG:
279     case OP_IMM_REG_MOVE:
280     case OP_LOAD32:
281     case OP_EX1:
282       trace_result (1, State.regs[OP[1]]);
283       break;
284       
285     case OP_IMM_REG_REG:
286     case OP_UIMM_REG_REG:
287     case OP_IMM16_REG_REG:
288     case OP_UIMM16_REG_REG:
289       trace_result (1, State.regs[OP[1]]);
290       break;
291       
292     case OP_JUMP:
293       if (OP[1] != 0)
294         trace_result (1, State.regs[OP[1]]);
295       else
296         trace_result (0, 0);
297       break;
298       
299     case OP_LDSR:
300       trace_result (1, State.sregs[OP[1]]);
301       break;
302     }
303 }
304 #endif
305
306 \f
307 /* Returns 1 if the specific condition is met, returns 0 otherwise.  */
308 static unsigned int
309 condition_met (unsigned code)
310 {
311   unsigned int psw = PSW;
312
313   switch (code & 0xf)
314     {
315       case 0x0: return ((psw & PSW_OV) != 0); 
316       case 0x1: return ((psw & PSW_CY) != 0);
317       case 0x2: return ((psw & PSW_Z) != 0);
318       case 0x3: return ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0);
319       case 0x4: return ((psw & PSW_S) != 0);
320     /*case 0x5: return 1;*/
321       case 0x6: return ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0);
322       case 0x7: return (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) || ((psw & PSW_Z) != 0)) != 0);
323       case 0x8: return ((psw & PSW_OV) == 0);
324       case 0x9: return ((psw & PSW_CY) == 0);
325       case 0xa: return ((psw & PSW_Z) == 0);
326       case 0xb: return ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0);
327       case 0xc: return ((psw & PSW_S) == 0);
328       case 0xd: return ((psw & PSW_SAT) != 0);
329       case 0xe: return ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0);
330       case 0xf: return (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) || ((psw & PSW_Z) != 0)) == 0);
331     }
332   
333   return 1;
334 }
335 /* start-sanitize-v850e */
336
337 static unsigned long
338 Add32 (unsigned long a1, unsigned long a2, int * carry)
339 {
340   unsigned long result = (a1 + a2);
341
342   * carry = (result < a1);
343
344   return result;
345 }
346
347 static void
348 Multiply64 (boolean sign, unsigned long op0)
349 {
350   unsigned long op1;
351   unsigned long lo;
352   unsigned long mid1;
353   unsigned long mid2;
354   unsigned long hi;
355   unsigned long RdLo;
356   unsigned long RdHi;
357   int           carry;
358   
359   op1 = State.regs[ OP[1] ];
360
361   if (sign)
362     {
363       /* Compute sign of result and adjust operands if necessary.  */
364           
365       sign = (op0 ^ op1) & 0x80000000;
366           
367       if (((signed long) op0) < 0)
368         op0 = - op0;
369           
370       if (((signed long) op1) < 0)
371         op1 = - op1;
372     }
373       
374   /* We can split the 32x32 into four 16x16 operations. This ensures
375      that we do not lose precision on 32bit only hosts: */
376   lo   = ( (op0        & 0xFFFF) *  (op1        & 0xFFFF));
377   mid1 = ( (op0        & 0xFFFF) * ((op1 >> 16) & 0xFFFF));
378   mid2 = (((op0 >> 16) & 0xFFFF) *  (op1        & 0xFFFF));
379   hi   = (((op0 >> 16) & 0xFFFF) * ((op1 >> 16) & 0xFFFF));
380   
381   /* We now need to add all of these results together, taking care
382      to propogate the carries from the additions: */
383   RdLo = Add32 (lo, (mid1 << 16), & carry);
384   RdHi = carry;
385   RdLo = Add32 (RdLo, (mid2 << 16), & carry);
386   RdHi += (carry + ((mid1 >> 16) & 0xFFFF) + ((mid2 >> 16) & 0xFFFF) + hi);
387
388   if (sign)
389     {
390       /* Negate result if necessary.  */
391       
392       RdLo = ~ RdLo;
393       RdHi = ~ RdHi;
394       if (RdLo == 0xFFFFFFFF)
395         {
396           RdLo = 0;
397           RdHi += 1;
398         }
399       else
400         RdLo += 1;
401     }
402   
403   /* Don't store into register 0.  */
404   if (OP[1])
405     State.regs[ OP[1]       ] = RdLo;
406   if (OP[2] >> 11)
407     State.regs[ OP[2] >> 11 ] = RdHi;
408
409   return;
410 }
411
412 /* end-sanitize-v850e */
413 \f
414 /* Read a null terminated string from memory, return in a buffer */
415 static char *
416 fetch_str (sd, addr)
417      SIM_DESC sd;
418      address_word addr;
419 {
420   char *buf;
421   int nr = 0;
422   while (sim_core_read_1 (STATE_CPU (sd, 0),
423                           PC, sim_core_read_map, addr + nr) != 0)
424     nr++;
425   buf = NZALLOC (char, nr + 1);
426   sim_read (simulator, addr, buf, nr);
427   return buf;
428 }
429
430 /* Read a null terminated argument vector from memory, return in a
431    buffer */
432 static char **
433 fetch_argv (sd, addr)
434      SIM_DESC sd;
435      address_word addr;
436 {
437   int max_nr = 64;
438   int nr = 0;
439   char **buf = xmalloc (max_nr * sizeof (char*));
440   while (1)
441     {
442       unsigned32 a = sim_core_read_4 (STATE_CPU (sd, 0),
443                                       PC, sim_core_read_map, addr + nr * 4);
444       if (a == 0) break;
445       buf[nr] = fetch_str (sd, a);
446       nr ++;
447       if (nr == max_nr - 1)
448         {
449           max_nr += 50;
450           buf = xrealloc (buf, max_nr * sizeof (char*));
451         }
452     }
453   buf[nr] = 0;
454   return buf;
455 }
456
457 \f
458 /* sld.b */
459 int
460 OP_300 ()
461 {
462   unsigned long result;
463   
464   result = load_mem (State.regs[30] + (OP[3] & 0x7f), 1);
465
466 /* start-sanitize-v850eq */
467   if (PSW & PSW_US)
468     {
469       trace_input ("sld.bu", OP_LOAD16, 1);
470       State.regs[ OP[1] ] = result;
471     }
472   else
473     {
474 /* end-sanitize-v850eq */
475   trace_input ("sld.b", OP_LOAD16, 1);
476   
477   State.regs[ OP[1] ] = EXTEND8 (result);
478 /* start-sanitize-v850eq */
479     }
480 /* end-sanitize-v850eq */
481   
482   trace_output (OP_LOAD16);
483   
484   return 2;
485 }
486
487 /* sld.h */
488 int
489 OP_400 ()
490 {
491   unsigned long result;
492   
493   result = load_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 2);
494
495 /* start-sanitize-v850eq */
496   if (PSW & PSW_US)
497     {
498       trace_input ("sld.hu", OP_LOAD16, 2);
499       State.regs[ OP[1] ] = result;
500     }
501   else
502     {
503 /* end-sanitize-v850eq */
504   trace_input ("sld.h", OP_LOAD16, 2);
505   
506   State.regs[ OP[1] ] = EXTEND16 (result);
507 /* start-sanitize-v850eq */
508     }
509 /* end-sanitize-v850eq */
510   
511   trace_output (OP_LOAD16);
512
513   return 2;
514 }
515
516 /* sld.w */
517 int
518 OP_500 ()
519 {
520   trace_input ("sld.w", OP_LOAD16, 4);
521   
522   State.regs[ OP[1] ] = load_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 4);
523   
524   trace_output (OP_LOAD16);
525   
526   return 2;
527 }
528
529 /* sst.b */
530 int
531 OP_380 ()
532 {
533   trace_input ("sst.b", OP_STORE16, 1);
534
535   store_mem (State.regs[30] + (OP[3] & 0x7f), 1, State.regs[ OP[1] ]);
536   
537   trace_output (OP_STORE16);
538
539   return 2;
540 }
541
542 /* sst.h */
543 int
544 OP_480 ()
545 {
546   trace_input ("sst.h", OP_STORE16, 2);
547
548   store_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 2, State.regs[ OP[1] ]);
549   
550   trace_output (OP_STORE16);
551
552   return 2;
553 }
554
555 /* sst.w */
556 int
557 OP_501 ()
558 {
559   trace_input ("sst.w", OP_STORE16, 4);
560
561   store_mem (State.regs[30] + ((OP[3] & 0x7e) << 1), 4, State.regs[ OP[1] ]);
562   
563   trace_output (OP_STORE16);
564
565   return 2;
566 }
567
568 /* ld.b */
569 int
570 OP_700 ()
571 {
572   int adr;
573
574   trace_input ("ld.b", OP_LOAD32, 1);
575
576   adr = State.regs[ OP[0] ] + EXTEND16 (OP[2]);
577
578   State.regs[ OP[1] ] = EXTEND8 (load_mem (adr, 1));
579   
580   trace_output (OP_LOAD32);
581
582   return 4;
583 }
584
585 /* ld.h */
586 int
587 OP_720 ()
588 {
589   int adr;
590
591   trace_input ("ld.h", OP_LOAD32, 2);
592
593   adr = State.regs[ OP[0] ] + EXTEND16 (OP[2]);
594   adr &= ~0x1;
595   
596   State.regs[ OP[1] ] = EXTEND16 (load_mem (adr, 2));
597   
598   trace_output (OP_LOAD32);
599
600   return 4;
601 }
602
603 /* ld.w */
604 int
605 OP_10720 ()
606 {
607   int adr;
608
609   trace_input ("ld.w", OP_LOAD32, 4);
610
611   adr = State.regs[ OP[0] ] + EXTEND16 (OP[2] & ~1);
612   adr &= ~0x3;
613   
614   State.regs[ OP[1] ] = load_mem (adr, 4);
615   
616   trace_output (OP_LOAD32);
617
618   return 4;
619 }
620
621 /* st.b */
622 int
623 OP_740 ()
624 {
625   trace_input ("st.b", OP_STORE32, 1);
626
627   store_mem (State.regs[ OP[0] ] + EXTEND16 (OP[2]), 1, State.regs[ OP[1] ]);
628   
629   trace_output (OP_STORE32);
630
631   return 4;
632 }
633
634 /* st.h */
635 int
636 OP_760 ()
637 {
638   int adr;
639   
640   trace_input ("st.h", OP_STORE32, 2);
641
642   adr = State.regs[ OP[0] ] + EXTEND16 (OP[2]);
643   adr &= ~1;
644   
645   store_mem (adr, 2, State.regs[ OP[1] ]);
646   
647   trace_output (OP_STORE32);
648
649   return 4;
650 }
651
652 /* st.w */
653 int
654 OP_10760 ()
655 {
656   int adr;
657   
658   trace_input ("st.w", OP_STORE32, 4);
659
660   adr = State.regs[ OP[0] ] + EXTEND16 (OP[2] & ~1);
661   adr &= ~3;
662   
663   store_mem (adr, 4, State.regs[ OP[1] ]);
664   
665   trace_output (OP_STORE32);
666
667   return 4;
668 }
669
670 static int
671 branch (int code)
672 {
673   trace_input ("Bcond", OP_COND_BR, 0);
674   trace_output (OP_COND_BR);
675
676   if (condition_met (code))
677     return SEXT9 (((OP[3] & 0x70) >> 3) | ((OP[3] & 0xf800) >> 7));
678   else
679     return 2;
680 }
681
682 /* bv disp9 */
683 int
684 OP_580 ()
685 {
686   return branch (0);
687 }
688
689 /* bl disp9 */
690 int
691 OP_581 ()
692 {
693   return branch (1);
694 }
695
696 /* be disp9 */
697 int
698 OP_582 ()
699 {
700   return branch (2);
701 }
702
703 /* bnh disp 9*/
704 int
705 OP_583 ()
706 {
707   return branch (3);
708 }
709
710 /* bn disp9 */
711 int
712 OP_584 ()
713 {
714   return branch (4);
715 }
716
717 /* br disp9 */
718 int
719 OP_585 ()
720 {
721   return branch (5);
722 }
723
724 /* blt disp9 */
725 int
726 OP_586 ()
727 {
728   return branch (6);
729 }
730
731 /* ble disp9 */
732 int
733 OP_587 ()
734 {
735   return branch (7);
736 }
737
738 /* bnv disp9 */
739 int
740 OP_588 ()
741 {
742   return branch (8);
743 }
744
745 /* bnl disp9 */
746 int
747 OP_589 ()
748 {
749   return branch (9);
750 }
751
752 /* bne disp9 */
753 int
754 OP_58A ()
755 {
756   return branch (10);
757 }
758
759 /* bh disp9 */
760 int
761 OP_58B ()
762 {
763   return branch (11);
764 }
765
766 /* bp disp9 */
767 int
768 OP_58C ()
769 {
770   return branch (12);
771 }
772
773 /* bsa disp9 */
774 int
775 OP_58D ()
776 {
777   return branch (13);
778 }
779
780 /* bge disp9 */
781 int
782 OP_58E ()
783 {
784   return branch (14);
785 }
786
787 /* bgt disp9 */
788 int
789 OP_58F ()
790 {
791   return branch (15);
792 }
793
794 /* jarl/jr disp22, reg */
795 int
796 OP_780 ()
797 {
798   trace_input ("jarl/jr", OP_JUMP, 0);
799
800   if (OP[ 1 ] != 0)
801     State.regs[ OP[1] ] = PC + 4;
802   
803   trace_output (OP_JUMP);
804   
805   return SEXT22 (((OP[3] & 0x3f) << 16) | OP[2]);
806 }
807
808 /* add reg, reg */
809 int
810 OP_1C0 ()
811 {
812   unsigned int op0, op1, result, z, s, cy, ov;
813
814   trace_input ("add", OP_REG_REG, 0);
815   
816   /* Compute the result.  */
817   
818   op0 = State.regs[ OP[0] ];
819   op1 = State.regs[ OP[1] ];
820   
821   result = op0 + op1;
822
823   /* Compute the condition codes.  */
824   z = (result == 0);
825   s = (result & 0x80000000);
826   cy = (result < op0 || result < op1);
827   ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
828         && (op0 & 0x80000000) != (result & 0x80000000));
829
830   /* Store the result and condition codes.  */
831   State.regs[OP[1]] = result;
832   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
833   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
834                      | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
835   trace_output (OP_REG_REG);
836
837   return 2;
838 }
839
840 /* add sign_extend(imm5), reg */
841 int
842 OP_240 ()
843 {
844   unsigned int op0, op1, result, z, s, cy, ov;
845   int temp;
846
847   trace_input ("add", OP_IMM_REG, 0);
848
849   /* Compute the result.  */
850   temp = SEXT5 (OP[0]);
851   op0 = temp;
852   op1 = State.regs[OP[1]];
853   result = op0 + op1;
854   
855   /* Compute the condition codes.  */
856   z = (result == 0);
857   s = (result & 0x80000000);
858   cy = (result < op0 || result < op1);
859   ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
860         && (op0 & 0x80000000) != (result & 0x80000000));
861
862   /* Store the result and condition codes.  */
863   State.regs[OP[1]] = result;
864   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
865   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
866                 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
867   trace_output (OP_IMM_REG);
868
869   return 2;
870 }
871
872 /* addi sign_extend(imm16), reg, reg */
873 int
874 OP_600 ()
875 {
876   unsigned int op0, op1, result, z, s, cy, ov;
877
878   trace_input ("addi", OP_IMM16_REG_REG, 0);
879
880   /* Compute the result.  */
881
882   op0 = EXTEND16 (OP[2]);
883   op1 = State.regs[ OP[0] ];
884   result = op0 + op1;
885   
886   /* Compute the condition codes.  */
887   z = (result == 0);
888   s = (result & 0x80000000);
889   cy = (result < op0 || result < op1);
890   ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
891         && (op0 & 0x80000000) != (result & 0x80000000));
892
893   /* Store the result and condition codes.  */
894   State.regs[OP[1]] = result;
895   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
896   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
897                 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
898   trace_output (OP_IMM16_REG_REG);
899
900   return 4;
901 }
902
903 /* sub reg1, reg2 */
904 int
905 OP_1A0 ()
906 {
907   unsigned int op0, op1, result, z, s, cy, ov;
908
909   trace_input ("sub", OP_REG_REG, 0);
910   /* Compute the result.  */
911   op0 = State.regs[ OP[0] ];
912   op1 = State.regs[ OP[1] ];
913   result = op1 - op0;
914
915   /* Compute the condition codes.  */
916   z = (result == 0);
917   s = (result & 0x80000000);
918   cy = (op1 < op0);
919   ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
920         && (op1 & 0x80000000) != (result & 0x80000000));
921
922   /* Store the result and condition codes.  */
923   State.regs[OP[1]] = result;
924   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
925   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
926                 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
927   trace_output (OP_REG_REG);
928
929   return 2;
930 }
931
932 /* subr reg1, reg2 */
933 int
934 OP_180 ()
935 {
936   unsigned int op0, op1, result, z, s, cy, ov;
937
938   trace_input ("subr", OP_REG_REG, 0);
939   /* Compute the result.  */
940   op0 = State.regs[ OP[0] ];
941   op1 = State.regs[ OP[1] ];
942   result = op0 - op1;
943
944   /* Compute the condition codes.  */
945   z = (result == 0);
946   s = (result & 0x80000000);
947   cy = (op0 < op1);
948   ov = ((op0 & 0x80000000) != (op1 & 0x80000000)
949         && (op0 & 0x80000000) != (result & 0x80000000));
950
951   /* Store the result and condition codes.  */
952   State.regs[OP[1]] = result;
953   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
954   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
955                 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
956   trace_output (OP_REG_REG);
957
958   return 2;
959 }
960
961 /* sxh reg1 */
962 int
963 OP_E0 ()
964 {
965   trace_input ("mulh", OP_REG_REG, 0);
966       
967   State.regs[ OP[1] ] = (EXTEND16 (State.regs[ OP[1] ]) * EXTEND16 (State.regs[ OP[0] ]));
968       
969   trace_output (OP_REG_REG);
970
971   return 2;
972 }
973
974 /* mulh sign_extend(imm5), reg2 */
975 int
976 OP_2E0 ()
977 {
978   trace_input ("mulh", OP_IMM_REG, 0);
979   
980   State.regs[ OP[1] ] = EXTEND16 (State.regs[ OP[1] ]) * SEXT5 (OP[0]);
981   
982   trace_output (OP_IMM_REG);
983
984   return 2;
985 }
986
987 /* mulhi imm16, reg1, reg2 */
988 int
989 OP_6E0 ()
990 {
991   trace_input ("mulhi", OP_IMM16_REG_REG, 0);
992   
993   State.regs[ OP[1] ] = EXTEND16 (State.regs[ OP[0] ]) * EXTEND16 (OP[2]);
994       
995   trace_output (OP_IMM16_REG_REG);
996   
997   return 4;
998 }
999
1000 /* divh reg1, reg2 */
1001 int
1002 OP_40 ()
1003 {
1004   unsigned int op0, op1, result, ov, s, z;
1005   int temp;
1006
1007   trace_input ("divh", OP_REG_REG, 0);
1008
1009   /* Compute the result.  */
1010   temp = EXTEND16 (State.regs[ OP[0] ]);
1011   op0 = temp;
1012   op1 = State.regs[OP[1]];
1013   
1014   if (op0 == 0xffffffff && op1 == 0x80000000)
1015     {
1016       result = 0x80000000;
1017       ov = 1;
1018     }
1019   else if (op0 != 0)
1020     {
1021       result = op1 / op0;
1022       ov = 0;
1023     }
1024   else
1025     {
1026       result = 0x0;
1027       ov = 1;
1028     }
1029   
1030   /* Compute the condition codes.  */
1031   z = (result == 0);
1032   s = (result & 0x80000000);
1033   
1034   /* Store the result and condition codes.  */
1035   State.regs[OP[1]] = result;
1036   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1037   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1038           | (ov ? PSW_OV : 0));
1039   trace_output (OP_REG_REG);
1040
1041   return 2;
1042 }
1043
1044 /* cmp reg, reg */
1045 int
1046 OP_1E0 ()
1047 {
1048   unsigned int op0, op1, result, z, s, cy, ov;
1049
1050   trace_input ("cmp", OP_REG_REG_CMP, 0);
1051   /* Compute the result.  */
1052   op0 = State.regs[ OP[0] ];
1053   op1 = State.regs[ OP[1] ];
1054   result = op1 - op0;
1055
1056   /* Compute the condition codes.  */
1057   z = (result == 0);
1058   s = (result & 0x80000000);
1059   cy = (op1 < op0);
1060   ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1061         && (op1 & 0x80000000) != (result & 0x80000000));
1062
1063   /* Set condition codes.  */
1064   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1065   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1066                 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1067   trace_output (OP_REG_REG_CMP);
1068
1069   return 2;
1070 }
1071
1072 /* cmp sign_extend(imm5), reg */
1073 int
1074 OP_260 ()
1075 {
1076   unsigned int op0, op1, result, z, s, cy, ov;
1077   int temp;
1078
1079   /* Compute the result.  */
1080   trace_input ("cmp", OP_IMM_REG_CMP, 0);
1081   temp = SEXT5 (OP[0]);
1082   op0 = temp;
1083   op1 = State.regs[OP[1]];
1084   result = op1 - op0;
1085
1086   /* Compute the condition codes.  */
1087   z = (result == 0);
1088   s = (result & 0x80000000);
1089   cy = (op1 < op0);
1090   ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1091         && (op1 & 0x80000000) != (result & 0x80000000));
1092
1093   /* Set condition codes.  */
1094   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1095   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1096                 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1097   trace_output (OP_IMM_REG_CMP);
1098
1099   return 2;
1100 }
1101
1102 /* setf cccc,reg2 */
1103 int
1104 OP_7E0 ()
1105 {
1106   trace_input ("setf", OP_EX1, 0);
1107
1108   State.regs[ OP[1] ] = condition_met (OP[0]);
1109   
1110   trace_output (OP_EX1);
1111
1112   return 4;
1113 }
1114
1115 /* satadd reg,reg */
1116 int
1117 OP_C0 ()
1118 {
1119   unsigned int op0, op1, result, z, s, cy, ov, sat;
1120   
1121   trace_input ("satadd", OP_REG_REG, 0);
1122   /* Compute the result.  */
1123   op0 = State.regs[ OP[0] ];
1124   op1 = State.regs[ OP[1] ];
1125   result = op0 + op1;
1126   
1127   /* Compute the condition codes.  */
1128   z = (result == 0);
1129   s = (result & 0x80000000);
1130   cy = (result < op0 || result < op1);
1131   ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1132         && (op0 & 0x80000000) != (result & 0x80000000));
1133   sat = ov;
1134   
1135   /* Store the result and condition codes.  */
1136   State.regs[OP[1]] = result;
1137   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1138   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1139           | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1140           | (sat ? PSW_SAT : 0));
1141   
1142   /* Handle saturated results.  */
1143   if (sat && s)
1144     State.regs[OP[1]] = 0x80000000;
1145   else if (sat)
1146     State.regs[OP[1]] = 0x7fffffff;
1147   trace_output (OP_REG_REG);
1148
1149   return 2;
1150 }
1151
1152 /* satadd sign_extend(imm5), reg */
1153 int
1154 OP_220 ()
1155 {
1156   unsigned int op0, op1, result, z, s, cy, ov, sat;
1157
1158   int temp;
1159
1160   trace_input ("satadd", OP_IMM_REG, 0);
1161
1162   /* Compute the result.  */
1163   temp = SEXT5 (OP[0]);
1164   op0 = temp;
1165   op1 = State.regs[OP[1]];
1166   result = op0 + op1;
1167
1168   /* Compute the condition codes.  */
1169   z = (result == 0);
1170   s = (result & 0x80000000);
1171   cy = (result < op0 || result < op1);
1172   ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1173         && (op0 & 0x80000000) != (result & 0x80000000));
1174   sat = ov;
1175
1176   /* Store the result and condition codes.  */
1177   State.regs[OP[1]] = result;
1178   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1179   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1180                 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1181                 | (sat ? PSW_SAT : 0));
1182
1183   /* Handle saturated results.  */
1184   if (sat && s)
1185     State.regs[OP[1]] = 0x80000000;
1186   else if (sat)
1187     State.regs[OP[1]] = 0x7fffffff;
1188   trace_output (OP_IMM_REG);
1189
1190   return 2;
1191 }
1192
1193 /* satsub reg1, reg2 */
1194 int
1195 OP_A0 ()
1196 {
1197   unsigned int op0, op1, result, z, s, cy, ov, sat;
1198   
1199   trace_input ("satsub", OP_REG_REG, 0);
1200   
1201   /* Compute the result.  */
1202   op0 = State.regs[ OP[0] ];
1203   op1 = State.regs[ OP[1] ];
1204   result = op1 - op0;
1205   
1206   /* Compute the condition codes.  */
1207   z = (result == 0);
1208   s = (result & 0x80000000);
1209   cy = (op1 < op0);
1210   ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1211         && (op1 & 0x80000000) != (result & 0x80000000));
1212   sat = ov;
1213   
1214   /* Store the result and condition codes.  */
1215   State.regs[OP[1]] = result;
1216   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1217   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1218           | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1219           | (sat ? PSW_SAT : 0));
1220   
1221   /* Handle saturated results.  */
1222   if (sat && s)
1223     State.regs[OP[1]] = 0x80000000;
1224   else if (sat)
1225     State.regs[OP[1]] = 0x7fffffff;
1226   trace_output (OP_REG_REG);
1227   return 2;
1228 }
1229
1230 /* satsubi sign_extend(imm16), reg */
1231 int
1232 OP_660 ()
1233 {
1234   unsigned int op0, op1, result, z, s, cy, ov, sat;
1235   int temp;
1236
1237   trace_input ("satsubi", OP_IMM_REG, 0);
1238
1239   /* Compute the result.  */
1240   temp = EXTEND16 (OP[2]);
1241   op0 = temp;
1242   op1 = State.regs[ OP[0] ];
1243   result = op1 - op0;
1244
1245   /* Compute the condition codes.  */
1246   z = (result == 0);
1247   s = (result & 0x80000000);
1248   cy = (op1 < op0);
1249   ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1250         && (op1 & 0x80000000) != (result & 0x80000000));
1251   sat = ov;
1252
1253   /* Store the result and condition codes.  */
1254   State.regs[OP[1]] = result;
1255   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1256   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1257                 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1258                 | (sat ? PSW_SAT : 0));
1259
1260   /* Handle saturated results.  */
1261   if (sat && s)
1262     State.regs[OP[1]] = 0x80000000;
1263   else if (sat)
1264     State.regs[OP[1]] = 0x7fffffff;
1265   trace_output (OP_IMM_REG);
1266
1267   return 4;
1268 }
1269
1270 /* satsubr reg,reg */
1271 int
1272 OP_80 ()
1273 {
1274   unsigned int op0, op1, result, z, s, cy, ov, sat;
1275   
1276   trace_input ("satsubr", OP_REG_REG, 0);
1277   
1278   /* Compute the result.  */
1279   op0 = State.regs[ OP[0] ];
1280   op1 = State.regs[ OP[1] ];
1281   result = op0 - op1;
1282   
1283   /* Compute the condition codes.  */
1284   z = (result == 0);
1285   s = (result & 0x80000000);
1286   cy = (result < op0);
1287   ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1288         && (op1 & 0x80000000) != (result & 0x80000000));
1289   sat = ov;
1290   
1291   /* Store the result and condition codes.  */
1292   State.regs[OP[1]] = result;
1293   PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1294   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1295           | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1296           | (sat ? PSW_SAT : 0));
1297   
1298   /* Handle saturated results.  */
1299   if (sat && s)
1300     State.regs[OP[1]] = 0x80000000;
1301   else if (sat)
1302     State.regs[OP[1]] = 0x7fffffff;
1303   trace_output (OP_REG_REG);
1304
1305   return 2;
1306 }
1307
1308 /* tst reg,reg */
1309 int
1310 OP_160 ()
1311 {
1312   unsigned int op0, op1, result, z, s;
1313
1314   trace_input ("tst", OP_REG_REG_CMP, 0);
1315
1316   /* Compute the result.  */
1317   op0 = State.regs[ OP[0] ];
1318   op1 = State.regs[ OP[1] ];
1319   result = op0 & op1;
1320
1321   /* Compute the condition codes.  */
1322   z = (result == 0);
1323   s = (result & 0x80000000);
1324
1325   /* Store the condition codes.  */
1326   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1327   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1328   trace_output (OP_REG_REG_CMP);
1329
1330   return 2;
1331 }
1332
1333 /* mov sign_extend(imm5), reg */
1334 int
1335 OP_200 ()
1336 {
1337   int value = SEXT5 (OP[0]);
1338   
1339   trace_input ("mov", OP_IMM_REG_MOVE, 0);
1340   
1341   State.regs[ OP[1] ] = value;
1342   
1343   trace_output (OP_IMM_REG_MOVE);
1344   
1345   return 2;
1346 }
1347
1348 /* movhi imm16, reg, reg */
1349 int
1350 OP_640 ()
1351 {
1352   trace_input ("movhi", OP_UIMM16_REG_REG, 16);
1353       
1354   State.regs[ OP[1] ] = State.regs[ OP[0] ] + (OP[2] << 16);
1355       
1356   trace_output (OP_UIMM16_REG_REG);
1357
1358   return 4;
1359 }
1360
1361 /* sar zero_extend(imm5),reg1 */
1362 int
1363 OP_2A0 ()
1364 {
1365   unsigned int op0, op1, result, z, s, cy;
1366
1367   trace_input ("sar", OP_IMM_REG, 0);
1368   op0 = OP[0];
1369   op1 = State.regs[ OP[1] ];
1370   result = (signed)op1 >> op0;
1371
1372   /* Compute the condition codes.  */
1373   z = (result == 0);
1374   s = (result & 0x80000000);
1375   cy = (op1 & (1 << (op0 - 1)));
1376
1377   /* Store the result and condition codes.  */
1378   State.regs[ OP[1] ] = result;
1379   PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1380   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1381                 | (cy ? PSW_CY : 0));
1382   trace_output (OP_IMM_REG);
1383
1384   return 2;
1385 }
1386
1387 /* sar reg1, reg2 */
1388 int
1389 OP_A007E0 ()
1390 {
1391   unsigned int op0, op1, result, z, s, cy;
1392
1393   trace_input ("sar", OP_REG_REG, 0);
1394   
1395   op0 = State.regs[ OP[0] ] & 0x1f;
1396   op1 = State.regs[ OP[1] ];
1397   result = (signed)op1 >> op0;
1398
1399   /* Compute the condition codes.  */
1400   z = (result == 0);
1401   s = (result & 0x80000000);
1402   cy = (op1 & (1 << (op0 - 1)));
1403
1404   /* Store the result and condition codes.  */
1405   State.regs[OP[1]] = result;
1406   PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1407   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1408                 | (cy ? PSW_CY : 0));
1409   trace_output (OP_REG_REG);
1410
1411   return 4;
1412 }
1413
1414 /* shl zero_extend(imm5),reg1 */
1415 int
1416 OP_2C0 ()
1417 {
1418   unsigned int op0, op1, result, z, s, cy;
1419
1420   trace_input ("shl", OP_IMM_REG, 0);
1421   op0 = OP[0];
1422   op1 = State.regs[ OP[1] ];
1423   result = op1 << op0;
1424
1425   /* Compute the condition codes.  */
1426   z = (result == 0);
1427   s = (result & 0x80000000);
1428   cy = (op1 & (1 << (32 - op0)));
1429
1430   /* Store the result and condition codes.  */
1431   State.regs[OP[1]] = result;
1432   PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1433   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1434                 | (cy ? PSW_CY : 0));
1435   trace_output (OP_IMM_REG);
1436
1437   return 2;
1438 }
1439
1440 /* shl reg1, reg2 */
1441 int
1442 OP_C007E0 ()
1443 {
1444   unsigned int op0, op1, result, z, s, cy;
1445
1446   trace_input ("shl", OP_REG_REG, 0);
1447   op0 = State.regs[ OP[0] ] & 0x1f;
1448   op1 = State.regs[ OP[1] ];
1449   result = op1 << op0;
1450
1451   /* Compute the condition codes.  */
1452   z = (result == 0);
1453   s = (result & 0x80000000);
1454   cy = (op1 & (1 << (32 - op0)));
1455
1456   /* Store the result and condition codes.  */
1457   State.regs[OP[1]] = result;
1458   PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1459   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1460                 | (cy ? PSW_CY : 0));
1461   trace_output (OP_REG_REG);
1462
1463   return 4;
1464 }
1465
1466 /* shr zero_extend(imm5),reg1 */
1467 int
1468 OP_280 ()
1469 {
1470   unsigned int op0, op1, result, z, s, cy;
1471
1472   trace_input ("shr", OP_IMM_REG, 0);
1473   op0 = OP[0];
1474   op1 = State.regs[ OP[1] ];
1475   result = op1 >> op0;
1476
1477   /* Compute the condition codes.  */
1478   z = (result == 0);
1479   s = (result & 0x80000000);
1480   cy = (op1 & (1 << (op0 - 1)));
1481
1482   /* Store the result and condition codes.  */
1483   State.regs[OP[1]] = result;
1484   PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1485   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1486                 | (cy ? PSW_CY : 0));
1487   trace_output (OP_IMM_REG);
1488
1489   return 2;
1490 }
1491
1492 /* shr reg1, reg2 */
1493 int
1494 OP_8007E0 ()
1495 {
1496   unsigned int op0, op1, result, z, s, cy;
1497
1498   trace_input ("shr", OP_REG_REG, 0);
1499   op0 = State.regs[ OP[0] ] & 0x1f;
1500   op1 = State.regs[ OP[1] ];
1501   result = op1 >> op0;
1502
1503   /* Compute the condition codes.  */
1504   z = (result == 0);
1505   s = (result & 0x80000000);
1506   cy = (op1 & (1 << (op0 - 1)));
1507
1508   /* Store the result and condition codes.  */
1509   State.regs[OP[1]] = result;
1510   PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1511   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1512                 | (cy ? PSW_CY : 0));
1513   trace_output (OP_REG_REG);
1514
1515   return 4;
1516 }
1517
1518 /* or reg, reg */
1519 int
1520 OP_100 ()
1521 {
1522   unsigned int op0, op1, result, z, s;
1523
1524   trace_input ("or", OP_REG_REG, 0);
1525
1526   /* Compute the result.  */
1527   op0 = State.regs[ OP[0] ];
1528   op1 = State.regs[ OP[1] ];
1529   result = op0 | op1;
1530
1531   /* Compute the condition codes.  */
1532   z = (result == 0);
1533   s = (result & 0x80000000);
1534
1535   /* Store the result and condition codes.  */
1536   State.regs[OP[1]] = result;
1537   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1538   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1539   trace_output (OP_REG_REG);
1540
1541   return 2;
1542 }
1543
1544 /* ori zero_extend(imm16), reg, reg */
1545 int
1546 OP_680 ()
1547 {
1548   unsigned int op0, op1, result, z, s;
1549
1550   trace_input ("ori", OP_UIMM16_REG_REG, 0);
1551   op0 = OP[2];
1552   op1 = State.regs[ OP[0] ];
1553   result = op0 | op1;
1554
1555   /* Compute the condition codes.  */
1556   z = (result == 0);
1557   s = (result & 0x80000000);
1558
1559   /* Store the result and condition codes.  */
1560   State.regs[OP[1]] = result;
1561   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1562   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1563   trace_output (OP_UIMM16_REG_REG);
1564
1565   return 4;
1566 }
1567
1568 /* and reg, reg */
1569 int
1570 OP_140 ()
1571 {
1572   unsigned int op0, op1, result, z, s;
1573
1574   trace_input ("and", OP_REG_REG, 0);
1575
1576   /* Compute the result.  */
1577   op0 = State.regs[ OP[0] ];
1578   op1 = State.regs[ OP[1] ];
1579   result = op0 & op1;
1580
1581   /* Compute the condition codes.  */
1582   z = (result == 0);
1583   s = (result & 0x80000000);
1584
1585   /* Store the result and condition codes.  */
1586   State.regs[OP[1]] = result;
1587   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1588   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1589   trace_output (OP_REG_REG);
1590
1591   return 2;
1592 }
1593
1594 /* andi zero_extend(imm16), reg, reg */
1595 int
1596 OP_6C0 ()
1597 {
1598   unsigned int result, z;
1599
1600   trace_input ("andi", OP_UIMM16_REG_REG, 0);
1601
1602   result = OP[2] & State.regs[ OP[0] ];
1603
1604   /* Compute the condition codes.  */
1605   z = (result == 0);
1606
1607   /* Store the result and condition codes.  */
1608   State.regs[ OP[1] ] = result;
1609   
1610   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1611   PSW |= (z ? PSW_Z : 0);
1612   
1613   trace_output (OP_UIMM16_REG_REG);
1614
1615   return 4;
1616 }
1617
1618 /* xor reg, reg */
1619 int
1620 OP_120 ()
1621 {
1622   unsigned int op0, op1, result, z, s;
1623
1624   trace_input ("xor", OP_REG_REG, 0);
1625
1626   /* Compute the result.  */
1627   op0 = State.regs[ OP[0] ];
1628   op1 = State.regs[ OP[1] ];
1629   result = op0 ^ op1;
1630
1631   /* Compute the condition codes.  */
1632   z = (result == 0);
1633   s = (result & 0x80000000);
1634
1635   /* Store the result and condition codes.  */
1636   State.regs[OP[1]] = result;
1637   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1638   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1639   trace_output (OP_REG_REG);
1640
1641   return 2;
1642 }
1643
1644 /* xori zero_extend(imm16), reg, reg */
1645 int
1646 OP_6A0 ()
1647 {
1648   unsigned int op0, op1, result, z, s;
1649
1650   trace_input ("xori", OP_UIMM16_REG_REG, 0);
1651   op0 = OP[2];
1652   op1 = State.regs[ OP[0] ];
1653   result = op0 ^ op1;
1654
1655   /* Compute the condition codes.  */
1656   z = (result == 0);
1657   s = (result & 0x80000000);
1658
1659   /* Store the result and condition codes.  */
1660   State.regs[OP[1]] = result;
1661   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1662   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1663   trace_output (OP_UIMM16_REG_REG);
1664
1665   return 4;
1666 }
1667
1668 /* not reg1, reg2 */
1669 int
1670 OP_20 ()
1671 {
1672   unsigned int op0, result, z, s;
1673
1674   trace_input ("not", OP_REG_REG_MOVE, 0);
1675   /* Compute the result.  */
1676   op0 = State.regs[ OP[0] ];
1677   result = ~op0;
1678
1679   /* Compute the condition codes.  */
1680   z = (result == 0);
1681   s = (result & 0x80000000);
1682
1683   /* Store the result and condition codes.  */
1684   State.regs[OP[1]] = result;
1685   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1686   PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1687   trace_output (OP_REG_REG_MOVE);
1688
1689   return 2;
1690 }
1691
1692 /* set1 */
1693 int
1694 OP_7C0 ()
1695 {
1696   unsigned int op0, op1, op2;
1697   int temp;
1698
1699   trace_input ("set1", OP_BIT, 0);
1700   op0 = State.regs[ OP[0] ];
1701   op1 = OP[1] & 0x7;
1702   temp = EXTEND16 (OP[2]);
1703   op2 = temp;
1704   temp = load_mem (op0 + op2, 1);
1705   PSW &= ~PSW_Z;
1706   if ((temp & (1 << op1)) == 0)
1707     PSW |= PSW_Z;
1708   temp |= (1 << op1);
1709   store_mem (op0 + op2, 1, temp);
1710   trace_output (OP_BIT);
1711
1712   return 4;
1713 }
1714
1715 /* not1 */
1716 int
1717 OP_47C0 ()
1718 {
1719   unsigned int op0, op1, op2;
1720   int temp;
1721
1722   trace_input ("not1", OP_BIT, 0);
1723   op0 = State.regs[ OP[0] ];
1724   op1 = OP[1] & 0x7;
1725   temp = EXTEND16 (OP[2]);
1726   op2 = temp;
1727   temp = load_mem (op0 + op2, 1);
1728   PSW &= ~PSW_Z;
1729   if ((temp & (1 << op1)) == 0)
1730     PSW |= PSW_Z;
1731   temp ^= (1 << op1);
1732   store_mem (op0 + op2, 1, temp);
1733   trace_output (OP_BIT);
1734
1735   return 4;
1736 }
1737
1738 /* clr1 */
1739 int
1740 OP_87C0 ()
1741 {
1742   unsigned int op0, op1, op2;
1743   int temp;
1744
1745   trace_input ("clr1", OP_BIT, 0);
1746   op0 = State.regs[ OP[0] ];
1747   op1 = OP[1] & 0x7;
1748   temp = EXTEND16 (OP[2]);
1749   op2 = temp;
1750   temp = load_mem (op0 + op2, 1);
1751   PSW &= ~PSW_Z;
1752   if ((temp & (1 << op1)) == 0)
1753     PSW |= PSW_Z;
1754   temp &= ~(1 << op1);
1755   store_mem (op0 + op2, 1, temp);
1756   trace_output (OP_BIT);
1757
1758   return 4;
1759 }
1760
1761 /* tst1 */
1762 int
1763 OP_C7C0 ()
1764 {
1765   unsigned int op0, op1, op2;
1766   int temp;
1767
1768   trace_input ("tst1", OP_BIT, 0);
1769   op0 = State.regs[ OP[0] ];
1770   op1 = OP[1] & 0x7;
1771   temp = EXTEND16 (OP[2]);
1772   op2 = temp;
1773   temp = load_mem (op0 + op2, 1);
1774   PSW &= ~PSW_Z;
1775   if ((temp & (1 << op1)) == 0)
1776     PSW |= PSW_Z;
1777   trace_output (OP_BIT);
1778
1779   return 4;
1780 }
1781
1782 /* di */
1783 int
1784 OP_16007E0 ()
1785 {
1786   trace_input ("di", OP_NONE, 0);
1787   PSW |= PSW_ID;
1788   trace_output (OP_NONE);
1789
1790   return 4;
1791 }
1792
1793 /* ei */
1794 int
1795 OP_16087E0 ()
1796 {
1797   trace_input ("ei", OP_NONE, 0);
1798   PSW &= ~PSW_ID;
1799   trace_output (OP_NONE);
1800
1801   return 4;
1802 }
1803
1804 /* halt */
1805 int
1806 OP_12007E0 ()
1807 {
1808   trace_input ("halt", OP_NONE, 0);
1809   /* FIXME this should put processor into a mode where NMI still handled */
1810   trace_output (OP_NONE);
1811   sim_engine_halt (simulator, STATE_CPU (simulator, 0), NULL, PC,
1812                    sim_stopped, SIGTRAP);
1813   return 0;
1814 }
1815
1816 /* trap */
1817 int
1818 OP_10007E0 ()
1819 {
1820   trace_input ("trap", OP_TRAP, 0);
1821   trace_output (OP_TRAP);
1822
1823   /* Trap 31 is used for simulating OS I/O functions */
1824
1825   if (OP[0] == 31)
1826     {
1827       int save_errno = errno;   
1828       errno = 0;
1829
1830 /* Registers passed to trap 0 */
1831
1832 #define FUNC   State.regs[6]    /* function number, return value */
1833 #define PARM1  State.regs[7]    /* optional parm 1 */
1834 #define PARM2  State.regs[8]    /* optional parm 2 */
1835 #define PARM3  State.regs[9]    /* optional parm 3 */
1836
1837 /* Registers set by trap 0 */
1838
1839 #define RETVAL State.regs[10]   /* return value */
1840 #define RETERR State.regs[11]   /* return error code */
1841
1842 /* Turn a pointer in a register into a pointer into real memory. */
1843
1844 #define MEMPTR(x) (map (x))
1845
1846       switch (FUNC)
1847         {
1848
1849 #ifdef HAVE_FORK
1850 #ifdef SYS_fork
1851         case SYS_fork:
1852           RETVAL = fork ();
1853           break;
1854 #endif
1855 #endif
1856
1857 #ifdef HAVE_EXECVE
1858 #ifdef SYS_execv
1859         case SYS_execve:
1860           {
1861             char *path = fetch_str (simulator, PARM1);
1862             char **argv = fetch_argv (simulator, PARM2);
1863             char **envp = fetch_argv (simulator, PARM3);
1864             RETVAL = execve (path, argv, envp);
1865             zfree (path);
1866             freeargv (argv);
1867             freeargv (envp);
1868             break;
1869           }
1870 #endif
1871 #endif
1872
1873 #if HAVE_EXECV
1874 #ifdef SYS_execv
1875         case SYS_execv:
1876           {
1877             char *path = fetch_str (simulator, PARM1);
1878             char **argv = fetch_argv (simulator, PARM2);
1879             RETVAL = execv (path, argv);
1880             zfree (path);
1881             freeargv (argv);
1882             break;
1883           }
1884 #endif
1885 #endif
1886
1887 #if 0
1888 #ifdef SYS_pipe
1889         case SYS_pipe:
1890           {
1891             reg_t buf;
1892             int host_fd[2];
1893
1894             buf = PARM1;
1895             RETVAL = pipe (host_fd);
1896             SW (buf, host_fd[0]);
1897             buf += sizeof(uint16);
1898             SW (buf, host_fd[1]);
1899           }
1900           break;
1901 #endif
1902 #endif
1903
1904 #if 0
1905 #ifdef SYS_wait
1906         case SYS_wait:
1907           {
1908             int status;
1909
1910             RETVAL = wait (&status);
1911             SW (PARM1, status);
1912           }
1913           break;
1914 #endif
1915 #endif
1916
1917 #ifdef SYS_read
1918         case SYS_read:
1919           {
1920             char *buf = zalloc (PARM3);
1921             RETVAL = sim_io_read (simulator, PARM1, buf, PARM3);
1922             sim_write (simulator, PARM2, buf, PARM3);
1923             zfree (buf);
1924             break;
1925           }
1926 #endif
1927
1928 #ifdef SYS_write
1929         case SYS_write:
1930           {
1931             char *buf = zalloc (PARM3);
1932             sim_read (simulator, PARM2, buf, PARM3);
1933             if (PARM1 == 1)
1934               RETVAL = sim_io_write_stdout (simulator, buf, PARM3);
1935             else
1936               RETVAL = sim_io_write (simulator, PARM1, buf, PARM3);
1937             zfree (buf);
1938             break;
1939           }
1940 #endif
1941
1942 #ifdef SYS_lseek
1943         case SYS_lseek:
1944           RETVAL = sim_io_lseek (simulator, PARM1, PARM2, PARM3);
1945           break;
1946 #endif
1947
1948 #ifdef SYS_close
1949         case SYS_close:
1950           RETVAL = sim_io_close (simulator, PARM1);
1951           break;
1952 #endif
1953
1954 #ifdef SYS_open
1955         case SYS_open:
1956           {
1957             char *buf = fetch_str (simulator, PARM1);
1958             RETVAL = sim_io_open (simulator, buf, PARM2);
1959             zfree (buf);
1960             break;
1961           }
1962 #endif
1963
1964 #ifdef SYS_exit
1965         case SYS_exit:
1966           if ((PARM1 & 0xffff0000) == 0xdead0000 && (PARM1 & 0xffff) != 0)
1967             /* get signal encoded by kill */
1968             sim_engine_halt (simulator, STATE_CPU (simulator, 0), NULL, PC,
1969                              sim_signalled, PARM1 & 0xffff);
1970           else if (PARM1 == 0xdead)
1971             /* old libraries */
1972             sim_engine_halt (simulator, STATE_CPU (simulator, 0), NULL, PC,
1973                              sim_exited, SIGABRT);
1974           else
1975             /* PARM1 has exit status */
1976             sim_engine_halt (simulator, STATE_CPU (simulator, 0), NULL, PC,
1977                              sim_exited, PARM1);
1978           break;
1979 #endif
1980
1981 #if !defined(__GO32__) && !defined(_WIN32)
1982 #ifdef SYS_stat
1983         case SYS_stat:  /* added at hmsi */
1984           /* stat system call */
1985           {
1986             struct stat host_stat;
1987             reg_t buf;
1988             char *path = fetch_str (simulator, PARM1);
1989
1990             RETVAL = stat (path, &host_stat);
1991
1992             zfree (path);
1993             buf = PARM2;
1994
1995             /* Just wild-assed guesses.  */
1996             store_mem (buf, 2, host_stat.st_dev);
1997             store_mem (buf + 2, 2, host_stat.st_ino);
1998             store_mem (buf + 4, 4, host_stat.st_mode);
1999             store_mem (buf + 8, 2, host_stat.st_nlink);
2000             store_mem (buf + 10, 2, host_stat.st_uid);
2001             store_mem (buf + 12, 2, host_stat.st_gid);
2002             store_mem (buf + 14, 2, host_stat.st_rdev);
2003             store_mem (buf + 16, 4, host_stat.st_size);
2004             store_mem (buf + 20, 4, host_stat.st_atime);
2005             store_mem (buf + 28, 4, host_stat.st_mtime);
2006             store_mem (buf + 36, 4, host_stat.st_ctime);
2007           }
2008           break;
2009 #endif
2010 #endif
2011
2012 #ifdef HAVE_CHOWN
2013 #ifdef SYS_chown
2014         case SYS_chown:
2015           {
2016             char *path = fetch_str (simulator, PARM1);
2017             RETVAL = chown (path, PARM2, PARM3);
2018             zfree (path);
2019           }
2020           break;
2021 #endif
2022 #endif
2023
2024 #if HAVE_CHMOD
2025 #ifdef SYS_chmod
2026         case SYS_chmod:
2027           {
2028             char *path = fetch_str (simulator, PARM1);
2029             RETVAL = chmod (path, PARM2);
2030             zfree (path);
2031           }
2032           break;
2033 #endif
2034 #endif
2035
2036 #ifdef SYS_time
2037 #if HAVE_TIME
2038         case SYS_time:
2039           {
2040             time_t now;
2041             RETVAL = time (&now);
2042             store_mem (PARM1, 4, now);
2043           }
2044           break;
2045 #endif
2046 #endif
2047
2048 #if !defined(__GO32__) && !defined(_WIN32)
2049 #ifdef SYS_times
2050         case SYS_times:
2051           {
2052             struct tms tms;
2053             RETVAL = times (&tms);
2054             store_mem (PARM1, 4, tms.tms_utime);
2055             store_mem (PARM1 + 4, 4, tms.tms_stime);
2056             store_mem (PARM1 + 8, 4, tms.tms_cutime);
2057             store_mem (PARM1 + 12, 4, tms.tms_cstime);
2058             break;
2059           }
2060 #endif
2061 #endif
2062
2063 #ifdef SYS_gettimeofday
2064 #if !defined(__GO32__) && !defined(_WIN32)
2065         case SYS_gettimeofday:
2066           {
2067             struct timeval t;
2068             struct timezone tz;
2069             RETVAL = gettimeofday (&t, &tz);
2070             store_mem (PARM1, 4, t.tv_sec);
2071             store_mem (PARM1 + 4, 4, t.tv_usec);
2072             store_mem (PARM2, 4, tz.tz_minuteswest);
2073             store_mem (PARM2 + 4, 4, tz.tz_dsttime);
2074             break;
2075           }
2076 #endif
2077 #endif
2078
2079 #ifdef SYS_utime
2080 #if HAVE_UTIME
2081         case SYS_utime:
2082           {
2083             /* Cast the second argument to void *, to avoid type mismatch
2084                if a prototype is present.  */
2085             sim_io_error (simulator, "Utime not supported");
2086             /* RETVAL = utime (path, (void *) MEMPTR (PARM2)); */
2087           }
2088           break;
2089 #endif
2090 #endif
2091
2092         default:
2093           abort ();
2094         }
2095       RETERR = errno;
2096       errno = save_errno;
2097
2098       return 4;
2099     }
2100   else
2101     {                           /* Trap 0 -> 30 */
2102       EIPC = PC + 4;
2103       EIPSW = PSW;
2104       /* Mask out EICC */
2105       ECR &= 0xffff0000;
2106       ECR |= 0x40 + OP[0];
2107       /* Flag that we are now doing exception processing.  */
2108       PSW |= PSW_EP | PSW_ID;
2109       PC = ((OP[0] < 0x10) ? 0x40 : 0x50) - 4;
2110
2111       return 0;
2112     }
2113 }
2114
2115 /* start-sanitize-v850e */
2116 /* tst1 reg2, [reg1] */
2117 int
2118 OP_E607E0 (void)
2119 {
2120   int temp;
2121
2122   trace_input ("tst1", OP_BIT, 1);
2123
2124   temp = load_mem (State.regs[ OP[0] ], 1);
2125   
2126   PSW &= ~PSW_Z;
2127   if ((temp & (1 << State.regs[ OP[1] & 0x7 ])) == 0)
2128     PSW |= PSW_Z;
2129   
2130   trace_output (OP_BIT);
2131
2132   return 4;
2133 }
2134
2135 /* end-sanitize-v850e */
2136 /* start-sanitize-v850e */
2137 /* mulu reg1, reg2, reg3 */
2138 int
2139 OP_22207E0 (void)
2140 {
2141   trace_input ("mulu", OP_REG_REG_REG, 0);
2142
2143   Multiply64 (false, State.regs[ OP[0] ]);
2144
2145   trace_output (OP_REG_REG_REG);
2146
2147   return 4;
2148 }
2149
2150 /* end-sanitize-v850e */
2151 /* start-sanitize-v850e */
2152
2153 #define BIT_CHANGE_OP( name, binop )            \
2154   unsigned int bit;                             \
2155   unsigned int temp;                            \
2156                                                 \
2157   trace_input (name, OP_BIT_CHANGE, 0);         \
2158                                                 \
2159   bit  = 1 << State.regs[ OP[1] & 0x7 ];        \
2160   temp = load_mem (State.regs[ OP[0] ], 1);     \
2161                                                 \
2162   PSW &= ~PSW_Z;                                \
2163   if ((temp & bit) == 0)                        \
2164     PSW |= PSW_Z;                               \
2165   temp binop bit;                               \
2166                                                 \
2167   store_mem (State.regs[ OP[0] ], 1, temp);     \
2168                                                 \
2169   trace_output (OP_BIT_CHANGE);                 \
2170                                                 \
2171   return 4;
2172
2173 /* clr1 reg2, [reg1] */
2174 int
2175 OP_E407E0 (void)
2176 {
2177   BIT_CHANGE_OP ("clr1", &= ~ );
2178 }
2179
2180 /* not1 reg2, [reg1] */
2181 int
2182 OP_E207E0 (void)
2183 {
2184   BIT_CHANGE_OP ("not1", ^= );
2185 }
2186
2187 /* set1 */
2188 int
2189 OP_E007E0 (void)
2190 {
2191   BIT_CHANGE_OP ("set1", |= );
2192 }
2193
2194 /* sasf */
2195 int
2196 OP_20007E0 (void)
2197 {
2198   trace_input ("sasf", OP_EX1, 0);
2199   
2200   State.regs[ OP[1] ] = (State.regs[ OP[1] ] << 1) | condition_met (OP[0]);
2201   
2202   trace_output (OP_EX1);
2203
2204   return 4;
2205 }
2206 /* end-sanitize-v850e */
2207 /* start-sanitize-v850eq */
2208 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2209 void
2210 divun
2211 (
2212   unsigned int       N,
2213   unsigned long int  als,
2214   unsigned long int  sfi,
2215   unsigned long int *  quotient_ptr,
2216   unsigned long int *  remainder_ptr,
2217   boolean *          overflow_ptr
2218 )
2219 {
2220   unsigned long   ald = sfi >> (N - 1);
2221   unsigned long   alo = als;
2222   unsigned int    Q   = 1;
2223   unsigned int    C;
2224   unsigned int    S   = 0;
2225   unsigned int    i;
2226   unsigned int    R1  = 1;
2227   unsigned int    DBZ = (als == 0) ? 1 : 0;
2228   unsigned long   alt = Q ? ~als : als;
2229
2230   /* 1st Loop */
2231   alo = ald + alt + Q;
2232   C   = (((alt >> 31) & (ald >> 31))
2233          | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2234   C   = C ^ Q;
2235   Q   = ~(C ^ S) & 1;
2236   R1  = (alo == 0) ? 0 : (R1 & Q);
2237   if ((S ^ (alo>>31)) && !C)
2238     {
2239       DBZ = 1;
2240     }
2241   S   = alo >> 31;
2242   sfi = (sfi << (32-N+1)) | Q;
2243   ald = (alo << 1) | (sfi >> 31);
2244
2245   /* 2nd - N-1th Loop */
2246   for (i = 2; i < N; i++)
2247     {
2248       alt = Q ? ~als : als;
2249       alo = ald + alt + Q;
2250       C   = (((alt >> 31) & (ald >> 31))
2251              | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2252       C   = C ^ Q;
2253       Q   = ~(C ^ S) & 1;
2254       R1  = (alo == 0) ? 0 : (R1 & Q);
2255       if ((S ^ (alo>>31)) && !C && !DBZ)
2256         {
2257           DBZ = 1;
2258         }
2259       S   = alo >> 31;
2260       sfi = (sfi << 1) | Q;
2261       ald = (alo << 1) | (sfi >> 31);
2262     }
2263   
2264   /* Nth Loop */
2265   alt = Q ? ~als : als;
2266   alo = ald + alt + Q;
2267   C   = (((alt >> 31) & (ald >> 31))
2268          | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2269   C   = C ^ Q;
2270   Q   = ~(C ^ S) & 1;
2271   R1  = (alo == 0) ? 0 : (R1 & Q);
2272   if ((S ^ (alo>>31)) && !C)
2273     {
2274       DBZ = 1;
2275     }
2276   
2277   * quotient_ptr  = (sfi << 1) | Q;
2278   * remainder_ptr = Q ? alo : (alo + als);
2279   * overflow_ptr  = DBZ | R1;
2280 }
2281
2282 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2283 void
2284 divn
2285 (
2286   unsigned int       N,
2287   unsigned long int  als,
2288   unsigned long int  sfi,
2289   signed long int *  quotient_ptr,
2290   signed long int *  remainder_ptr,
2291   boolean *          overflow_ptr
2292 )
2293 {
2294   unsigned long   ald = (signed long) sfi >> (N - 1);
2295   unsigned long   alo = als;
2296   unsigned int    SS  = als >> 31;
2297   unsigned int    SD  = sfi >> 31;
2298   unsigned int    R1  = 1;
2299   unsigned int    OV;
2300   unsigned int    DBZ = als == 0 ? 1 : 0;
2301   unsigned int    Q   = ~(SS ^ SD) & 1;
2302   unsigned int    C;
2303   unsigned int    S;
2304   unsigned int    i;
2305   unsigned long   alt = Q ? ~als : als;
2306
2307
2308   /* 1st Loop */
2309   
2310   alo = ald + alt + Q;
2311   C   = (((alt >> 31) & (ald >> 31))
2312          | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2313   Q   = C ^ SS;
2314   R1  = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2315   S   = alo >> 31;
2316   sfi = (sfi << (32-N+1)) | Q;
2317   ald = (alo << 1) | (sfi >> 31);
2318   if ((alo >> 31) ^ (ald >> 31))
2319     {
2320       DBZ = 1;
2321     }
2322
2323   /* 2nd - N-1th Loop */
2324   
2325   for (i = 2; i < N; i++)
2326     {
2327       alt = Q ? ~als : als;
2328       alo = ald + alt + Q;
2329       C   = (((alt >> 31) & (ald >> 31))
2330              | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2331       Q   = C ^ SS;
2332       R1  = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2333       S   = alo >> 31;
2334       sfi = (sfi << 1) | Q;
2335       ald = (alo << 1) | (sfi >> 31);
2336       if ((alo >> 31) ^ (ald >> 31))
2337         {
2338           DBZ = 1;
2339         }
2340     }
2341
2342   /* Nth Loop */
2343   alt = Q ? ~als : als;
2344   alo = ald + alt + Q;
2345   C   = (((alt >> 31) & (ald >> 31))
2346          | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2347   Q   = C ^ SS;
2348   R1  = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2349   sfi = (sfi << (32-N+1));
2350   ald = alo;
2351
2352   /* End */
2353   if (alo != 0)
2354     {
2355       alt = Q ? ~als : als;
2356       alo = ald + alt + Q;
2357     }
2358   R1  = R1 & ((~alo >> 31) ^ SD);
2359   if ((alo != 0) && ((Q ^ (SS ^ SD)) ^ R1)) alo = ald;
2360   if (N != 32)
2361     ald = sfi = (long) ((sfi >> 1) | (SS ^ SD) << 31) >> (32-N-1) | Q;
2362   else
2363     ald = sfi = sfi | Q;
2364   
2365   OV = DBZ | ((alo == 0) ? 0 : R1);
2366   
2367   * remainder_ptr = alo;
2368
2369   /* Adj */
2370   if (((alo != 0) && ((SS ^ SD) ^ R1))
2371       || ((alo == 0) && (SS ^ R1)))
2372     alo = ald + 1;
2373   else
2374     alo = ald;
2375   
2376   OV  = (DBZ | R1) ? OV : ((alo >> 31) & (~ald >> 31));
2377
2378   * quotient_ptr  = alo;
2379   * overflow_ptr  = OV;
2380 }
2381
2382 /* sdivun imm5, reg1, reg2, reg3 */
2383 int
2384 OP_1C207E0 (void)
2385 {
2386   unsigned long int  quotient;
2387   unsigned long int  remainder;
2388   unsigned long int  divide_by;
2389   unsigned long int  divide_this;
2390   boolean            overflow = false;
2391   unsigned int       imm5;
2392       
2393   trace_input ("sdivun", OP_IMM_REG_REG_REG, 0);
2394
2395   imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2396
2397   divide_by   = State.regs[ OP[0] ];
2398   divide_this = State.regs[ OP[1] ] << imm5;
2399
2400   divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2401   
2402   State.regs[ OP[1]       ] = quotient;
2403   State.regs[ OP[2] >> 11 ] = remainder;
2404   
2405   /* Set condition codes.  */
2406   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2407   
2408   if (overflow)      PSW |= PSW_OV;
2409   if (quotient == 0) PSW |= PSW_Z;
2410   if (quotient & 0x80000000) PSW |= PSW_S;
2411   
2412   trace_output (OP_IMM_REG_REG_REG);
2413
2414   return 4;
2415 }
2416
2417 /* sdivn imm5, reg1, reg2, reg3 */
2418 int
2419 OP_1C007E0 (void)
2420 {
2421   signed long int  quotient;
2422   signed long int  remainder;
2423   signed long int  divide_by;
2424   signed long int  divide_this;
2425   boolean          overflow = false;
2426   unsigned int     imm5;
2427       
2428   trace_input ("sdivn", OP_IMM_REG_REG_REG, 0);
2429
2430   imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2431
2432   divide_by   = State.regs[ OP[0] ];
2433   divide_this = State.regs[ OP[1] ] << imm5;
2434
2435   divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2436   
2437   State.regs[ OP[1]       ] = quotient;
2438   State.regs[ OP[2] >> 11 ] = remainder;
2439   
2440   /* Set condition codes.  */
2441   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2442   
2443   if (overflow)      PSW |= PSW_OV;
2444   if (quotient == 0) PSW |= PSW_Z;
2445   if (quotient <  0) PSW |= PSW_S;
2446   
2447   trace_output (OP_IMM_REG_REG_REG);
2448
2449   return 4;
2450 }
2451
2452 /* sdivhun imm5, reg1, reg2, reg3 */
2453 int
2454 OP_18207E0 (void)
2455 {
2456   unsigned long int  quotient;
2457   unsigned long int  remainder;
2458   unsigned long int  divide_by;
2459   unsigned long int  divide_this;
2460   boolean            overflow = false;
2461   unsigned int       imm5;
2462       
2463   trace_input ("sdivhun", OP_IMM_REG_REG_REG, 0);
2464
2465   imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2466
2467   divide_by   = State.regs[ OP[0] ] & 0xffff;
2468   divide_this = State.regs[ OP[1] ] << imm5;
2469
2470   divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2471   
2472   State.regs[ OP[1]       ] = quotient;
2473   State.regs[ OP[2] >> 11 ] = remainder;
2474   
2475   /* Set condition codes.  */
2476   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2477   
2478   if (overflow)      PSW |= PSW_OV;
2479   if (quotient == 0) PSW |= PSW_Z;
2480   if (quotient & 0x80000000) PSW |= PSW_S;
2481   
2482   trace_output (OP_IMM_REG_REG_REG);
2483
2484   return 4;
2485 }
2486
2487 /* sdivhn imm5, reg1, reg2, reg3 */
2488 int
2489 OP_18007E0 (void)
2490 {
2491   signed long int  quotient;
2492   signed long int  remainder;
2493   signed long int  divide_by;
2494   signed long int  divide_this;
2495   boolean          overflow = false;
2496   unsigned int     imm5;
2497       
2498   trace_input ("sdivhn", OP_IMM_REG_REG_REG, 0);
2499
2500   imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2501
2502   divide_by   = EXTEND16 (State.regs[ OP[0] ]);
2503   divide_this = State.regs[ OP[1] ] << imm5;
2504
2505   divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2506   
2507   State.regs[ OP[1]       ] = quotient;
2508   State.regs[ OP[2] >> 11 ] = remainder;
2509   
2510   /* Set condition codes.  */
2511   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2512   
2513   if (overflow)      PSW |= PSW_OV;
2514   if (quotient == 0) PSW |= PSW_Z;
2515   if (quotient <  0) PSW |= PSW_S;
2516   
2517   trace_output (OP_IMM_REG_REG_REG);
2518
2519   return 4;
2520 }
2521
2522 /* end-sanitize-v850eq */
2523 /* start-sanitize-v850e */
2524 /* divu  reg1, reg2, reg3 */
2525 int
2526 OP_2C207E0 (void)
2527 {
2528   unsigned long int quotient;
2529   unsigned long int remainder;
2530   unsigned long int divide_by;
2531   unsigned long int divide_this;
2532   boolean           overflow = false;
2533   
2534   trace_input ("divu", OP_REG_REG_REG, 0);
2535   
2536   /* Compute the result.  */
2537   
2538   divide_by   = State.regs[ OP[0] ];
2539   divide_this = State.regs[ OP[1] ];
2540   
2541   if (divide_by == 0)
2542     {
2543       overflow = true;
2544       divide_by  = 1;
2545     }
2546   
2547   State.regs[ OP[1]       ] = quotient  = divide_this / divide_by;
2548   State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
2549   
2550   /* Set condition codes.  */
2551   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2552   
2553   if (overflow)      PSW |= PSW_OV;
2554   if (quotient == 0) PSW |= PSW_Z;
2555   if (quotient & 0x80000000) PSW |= PSW_S;
2556   
2557   trace_output (OP_REG_REG_REG);
2558
2559   return 4;
2560 }
2561
2562 /* end-sanitize-v850e */
2563 /* start-sanitize-v850e */
2564 /* div  reg1, reg2, reg3 */
2565 int
2566 OP_2C007E0 (void)
2567 {
2568   signed long int quotient;
2569   signed long int remainder;
2570   signed long int divide_by;
2571   signed long int divide_this;
2572   boolean         overflow = false;
2573   
2574   trace_input ("div", OP_REG_REG_REG, 0);
2575   
2576   /* Compute the result.  */
2577   
2578   divide_by   = State.regs[ OP[0] ];
2579   divide_this = State.regs[ OP[1] ];
2580   
2581   if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
2582     {
2583       overflow  = true;
2584       divide_by = 1;
2585     }
2586   
2587   State.regs[ OP[1]       ] = quotient  = divide_this / divide_by;
2588   State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
2589   
2590   /* Set condition codes.  */
2591   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2592   
2593   if (overflow)      PSW |= PSW_OV;
2594   if (quotient == 0) PSW |= PSW_Z;
2595   if (quotient <  0) PSW |= PSW_S;
2596   
2597   trace_output (OP_REG_REG_REG);
2598
2599   return 4;
2600 }
2601
2602 /* end-sanitize-v850e */
2603 /* start-sanitize-v850e */
2604 /* divhu  reg1, reg2, reg3 */
2605 int
2606 OP_28207E0 (void)
2607 {
2608   unsigned long int quotient;
2609   unsigned long int remainder;
2610   unsigned long int divide_by;
2611   unsigned long int divide_this;
2612   boolean           overflow = false;
2613   
2614   trace_input ("divhu", OP_REG_REG_REG, 0);
2615   
2616   /* Compute the result.  */
2617   
2618   divide_by   = State.regs[ OP[0] ] & 0xffff;
2619   divide_this = State.regs[ OP[1] ];
2620   
2621   if (divide_by == 0)
2622     {
2623       overflow = true;
2624       divide_by  = 1;
2625     }
2626   
2627   State.regs[ OP[1]       ] = quotient  = divide_this / divide_by;
2628   State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
2629   
2630   /* Set condition codes.  */
2631   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2632   
2633   if (overflow)      PSW |= PSW_OV;
2634   if (quotient == 0) PSW |= PSW_Z;
2635   if (quotient & 0x80000000) PSW |= PSW_S;
2636   
2637   trace_output (OP_REG_REG_REG);
2638
2639   return 4;
2640 }
2641
2642 /* end-sanitize-v850e */
2643 /* start-sanitize-v850e */
2644 /* divh  reg1, reg2, reg3 */
2645 int
2646 OP_28007E0 (void)
2647 {
2648   signed long int quotient;
2649   signed long int remainder;
2650   signed long int divide_by;
2651   signed long int divide_this;
2652   boolean         overflow = false;
2653   
2654   trace_input ("divh", OP_REG_REG_REG, 0);
2655   
2656   /* Compute the result.  */
2657   
2658   divide_by  = State.regs[ OP[0] ];
2659   divide_this = EXTEND16 (State.regs[ OP[1] ]);
2660   
2661   if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
2662     {
2663       overflow = true;
2664       divide_by  = 1;
2665     }
2666   
2667   State.regs[ OP[1]       ] = quotient  = divide_this / divide_by;
2668   State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
2669   
2670   /* Set condition codes.  */
2671   PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2672   
2673   if (overflow)      PSW |= PSW_OV;
2674   if (quotient == 0) PSW |= PSW_Z;
2675   if (quotient <  0) PSW |= PSW_S;
2676   
2677   trace_output (OP_REG_REG_REG);
2678
2679   return 4;
2680 }
2681
2682 /* end-sanitize-v850e */
2683 /* start-sanitize-v850e */
2684 /* mulu imm9, reg2, reg3 */
2685 int
2686 OP_24207E0 (void)
2687 {
2688   trace_input ("mulu", OP_IMM_REG_REG, 0);
2689
2690   Multiply64 (false, (OP[3] & 0x1f) | ((OP[3] >> 13) & 0x1e0));
2691
2692   trace_output (OP_IMM_REG_REG);
2693
2694   return 4;
2695 }
2696
2697 /* end-sanitize-v850e */
2698 /* start-sanitize-v850e */
2699 /* mul imm9, reg2, reg3 */
2700 int
2701 OP_24007E0 (void)
2702 {
2703   trace_input ("mul", OP_IMM_REG_REG, 0);
2704
2705   Multiply64 (true, (OP[3] & 0x1f) | ((OP[3] >> 13) & 0x1e0));
2706
2707   trace_output (OP_IMM_REG_REG);
2708
2709   return 4;
2710 }
2711
2712 /* end-sanitize-v850e */
2713 /* start-sanitize-v850e */
2714 /* cmov imm5, reg2, reg3 */
2715 int
2716 OP_30007E0 (void)
2717 {
2718   trace_input ("cmov", OP_IMM_REG_REG, 0);
2719
2720   State.regs[ OP[2] >> 11 ] = condition_met (OP[0]) ? SEXT5( OP[0] ) : State.regs[ OP[1] ];
2721   
2722   trace_output (OP_IMM_REG_REG);
2723
2724   return 4;
2725   
2726 }
2727
2728 /* end-sanitize-v850e */
2729 /* start-sanitize-v850e */
2730 /* ld.hu */
2731 int
2732 OP_107E0 (void)
2733 {
2734   int adr;
2735
2736   trace_input ("ld.hu", OP_LOAD32, 2);
2737
2738   adr = State.regs[ OP[0] ] + EXTEND16 (OP[2] & ~1);
2739   adr &= ~0x1;
2740       
2741   State.regs[ OP[1] ] = load_mem (adr, 2);
2742       
2743   trace_output (OP_LOAD32);
2744   
2745   return 4;
2746 }
2747
2748 /* end-sanitize-v850e */
2749 /* start-sanitize-v850e */
2750 /* ld.bu */
2751 int
2752 OP_10780 (void)
2753 {
2754   int adr;
2755
2756   trace_input ("ld.bu", OP_LOAD32, 1);
2757
2758   adr = (State.regs[ OP[0] ]
2759          + (EXTEND16 (OP[2] & ~1) | ((OP[3] >> 5) & 1)));
2760       
2761   State.regs[ OP[1] ] = load_mem (adr, 1);
2762   
2763   trace_output (OP_LOAD32);
2764   
2765   return 4;
2766 }
2767
2768 /* prepare list12, imm5, imm32 */
2769 int
2770 OP_1B0780 (void)
2771 {
2772   int  i;
2773   
2774   trace_input ("prepare", OP_PUSHPOP1, 0);
2775   
2776   /* Store the registers with lower number registers being placed at higher addresses.  */
2777   for (i = 0; i < 12; i++)
2778     if ((OP[3] & (1 << type1_regs[ i ])))
2779       {
2780         SP -= 4;
2781         store_mem (SP, 4, State.regs[ 20 + i ]);
2782       }
2783   
2784   SP -= (OP[3] & 0x3e) << 1;
2785
2786   EP = load_mem (PC + 4, 4);
2787   
2788   trace_output (OP_PUSHPOP1);
2789
2790   return 8;
2791 }
2792
2793 /* prepare list12, imm5, imm16-32 */
2794 int
2795 OP_130780 (void)
2796 {
2797   int  i;
2798   
2799   trace_input ("prepare", OP_PUSHPOP1, 0);
2800   
2801   /* Store the registers with lower number registers being placed at higher addresses.  */
2802   for (i = 0; i < 12; i++)
2803     if ((OP[3] & (1 << type1_regs[ i ])))
2804       {
2805         SP -= 4;
2806         store_mem (SP, 4, State.regs[ 20 + i ]);
2807       }
2808   
2809   SP -= (OP[3] & 0x3e) << 1;
2810
2811   EP = load_mem (PC + 4, 2) << 16;
2812   
2813   trace_output (OP_PUSHPOP1);
2814
2815   return 6;
2816 }
2817
2818 /* prepare list12, imm5, imm16 */
2819 int
2820 OP_B0780 (void)
2821 {
2822   int  i;
2823   
2824   trace_input ("prepare", OP_PUSHPOP1, 0);
2825   
2826   /* Store the registers with lower number registers being placed at higher addresses.  */
2827   for (i = 0; i < 12; i++)
2828     if ((OP[3] & (1 << type1_regs[ i ])))
2829       {
2830         SP -= 4;
2831         store_mem (SP, 4, State.regs[ 20 + i ]);
2832       }
2833   
2834   SP -= (OP[3] & 0x3e) << 1;
2835
2836   EP = EXTEND16 (load_mem (PC + 4, 2));
2837   
2838   trace_output (OP_PUSHPOP1);
2839
2840   return 6;
2841 }
2842
2843 /* prepare list12, imm5, sp */
2844 int
2845 OP_30780 (void)
2846 {
2847   int  i;
2848   
2849   trace_input ("prepare", OP_PUSHPOP1, 0);
2850   
2851   /* Store the registers with lower number registers being placed at higher addresses.  */
2852   for (i = 0; i < 12; i++)
2853     if ((OP[3] & (1 << type1_regs[ i ])))
2854       {
2855         SP -= 4;
2856         store_mem (SP, 4, State.regs[ 20 + i ]);
2857       }
2858   
2859   SP -= (OP[3] & 0x3e) << 1;
2860
2861   EP = SP;
2862   
2863   trace_output (OP_PUSHPOP1);
2864
2865   return 4;
2866 }
2867
2868 /* end-sanitize-v850e */
2869 /* start-sanitize-v850e */
2870 /* sld.hu */
2871 int
2872 OP_70 (void)
2873 {
2874   unsigned long result;
2875   
2876   result  = load_mem (State.regs[30] + ((OP[3] & 0xf) << 1), 2);
2877
2878   /* start-sanitize-v850eq */
2879   if (PSW & PSW_US)
2880     {
2881       trace_input ("sld.h", OP_LOAD16, 2);
2882       State.regs[ OP[1] ] = EXTEND16 (result);
2883     }
2884   else
2885     {
2886 /* end-sanitize-v850eq */
2887   trace_input ("sld.hu", OP_LOAD16, 2);
2888   
2889   State.regs[ OP[1] ] = result;
2890 /* start-sanitize-v850eq */
2891     }
2892 /* end-sanitize-v850eq */
2893   
2894   trace_output (OP_LOAD16);
2895   
2896   return 2;
2897 }
2898
2899 /* end-sanitize-v850e */
2900 /* start-sanitize-v850e */
2901 /* cmov reg1, reg2, reg3 */
2902 int
2903 OP_32007E0 (void)
2904 {
2905   trace_input ("cmov", OP_REG_REG_REG, 0);
2906
2907   State.regs[ OP[2] >> 11 ] = condition_met (OP[0]) ? State.regs[ OP[0] ] : State.regs[ OP[1] ];
2908   
2909   trace_output (OP_REG_REG_REG);
2910
2911   return 4;
2912 }
2913
2914 /* end-sanitize-v850e */
2915 /* start-sanitize-v850e */
2916 /* mul reg1, reg2, reg3 */
2917 int
2918 OP_22007E0 (void)
2919 {
2920   trace_input ("mul", OP_REG_REG_REG, 0);
2921
2922   Multiply64 (true, State.regs[ OP[0] ]);
2923
2924   trace_output (OP_REG_REG_REG);
2925
2926   return 4;
2927 }
2928
2929 /* end-sanitize-v850e */
2930 /* start-sanitize-v850eq */
2931
2932 /* popmh list18 */
2933 int
2934 OP_307F0 (void)
2935 {
2936   int i;
2937   
2938   trace_input ("popmh", OP_PUSHPOP2, 0);
2939   
2940   if (OP[3] & (1 << 19))
2941     {
2942       if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
2943         {
2944           FEPSW = load_mem ( SP      & ~ 3, 4);
2945           FEPC  = load_mem ((SP + 4) & ~ 3, 4);
2946         }
2947       else
2948         {
2949           EIPSW = load_mem ( SP      & ~ 3, 4);
2950           EIPC  = load_mem ((SP + 4) & ~ 3, 4);
2951         }
2952       
2953       SP += 8;
2954     }
2955   
2956   /* Load the registers with lower number registers being retrieved from higher addresses.  */
2957   for (i = 16; i--;)
2958     if ((OP[3] & (1 << type2_regs[ i ])))
2959       {
2960         State.regs[ i + 16 ] = load_mem (SP & ~ 3, 4);
2961         SP += 4;
2962       }
2963   
2964   trace_output (OP_PUSHPOP2);
2965
2966   return 4;
2967 }
2968
2969 /* popml lsit18 */
2970 int
2971 OP_107F0 (void)
2972 {
2973   int i;
2974
2975   trace_input ("popml", OP_PUSHPOP3, 0);
2976
2977   if (OP[3] & (1 << 19))
2978     {
2979       if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
2980         {
2981           FEPSW = load_mem ( SP      & ~ 3, 4);
2982           FEPC =  load_mem ((SP + 4) & ~ 3, 4);
2983         }
2984       else
2985         {
2986           EIPSW = load_mem ( SP      & ~ 3, 4);
2987           EIPC  = load_mem ((SP + 4) & ~ 3, 4);
2988         }
2989       
2990       SP += 8;
2991     }
2992   
2993   if (OP[3] & (1 << 3))
2994     {
2995       PSW = load_mem (SP & ~ 3, 4);
2996       SP += 4;
2997     }
2998   
2999   /* Load the registers with lower number registers being retrieved from higher addresses.  */
3000   for (i = 15; i--;)
3001     if ((OP[3] & (1 << type3_regs[ i ])))
3002       {
3003         State.regs[ i + 1 ] = load_mem (SP & ~ 3, 4);
3004         SP += 4;
3005       }
3006   
3007   trace_output (OP_PUSHPOP2);
3008
3009   return 4;
3010 }
3011
3012 /* pushmh list18 */
3013 int
3014 OP_307E0 (void)
3015 {
3016   int i;
3017
3018   trace_input ("pushmh", OP_PUSHPOP2, 0);
3019   
3020   /* Store the registers with lower number registers being placed at higher addresses.  */
3021   for (i = 0; i < 16; i++)
3022     if ((OP[3] & (1 << type2_regs[ i ])))
3023       {
3024         SP -= 4;
3025         store_mem (SP & ~ 3, 4, State.regs[ i + 16 ]);
3026       }
3027   
3028   if (OP[3] & (1 << 19))
3029     {
3030       SP -= 8;
3031       
3032       if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3033         {
3034           store_mem ((SP + 4) & ~ 3, 4, FEPC);
3035           store_mem ( SP      & ~ 3, 4, FEPSW);
3036         }
3037       else
3038         {
3039           store_mem ((SP + 4) & ~ 3, 4, EIPC);
3040           store_mem ( SP      & ~ 3, 4, EIPSW);
3041         }
3042     }
3043   
3044   trace_output (OP_PUSHPOP2);
3045
3046   return 4;
3047 }
3048
3049 /* end-sanitize-v850eq */