kvm: qemu: LSI SCSI and e1000 unregister callbacks
[kvm-userspace.git] / qemu / target-cris / op.c
blobaeb80de4a36baf1b0a5321c7ed832ed17ab28ad5
1 /*
2 * CRIS emulation micro-operations for qemu.
4 * Copyright (c) 2007 Edgar E. Iglesias, Axis Communications AB.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "exec.h"
21 #include "host-utils.h"
23 #define REGNAME r0
24 #define REG (env->regs[0])
25 #include "op_template.h"
27 #define REGNAME r1
28 #define REG (env->regs[1])
29 #include "op_template.h"
31 #define REGNAME r2
32 #define REG (env->regs[2])
33 #include "op_template.h"
35 #define REGNAME r3
36 #define REG (env->regs[3])
37 #include "op_template.h"
39 #define REGNAME r4
40 #define REG (env->regs[4])
41 #include "op_template.h"
43 #define REGNAME r5
44 #define REG (env->regs[5])
45 #include "op_template.h"
47 #define REGNAME r6
48 #define REG (env->regs[6])
49 #include "op_template.h"
51 #define REGNAME r7
52 #define REG (env->regs[7])
53 #include "op_template.h"
55 #define REGNAME r8
56 #define REG (env->regs[8])
57 #include "op_template.h"
59 #define REGNAME r9
60 #define REG (env->regs[9])
61 #include "op_template.h"
63 #define REGNAME r10
64 #define REG (env->regs[10])
65 #include "op_template.h"
67 #define REGNAME r11
68 #define REG (env->regs[11])
69 #include "op_template.h"
71 #define REGNAME r12
72 #define REG (env->regs[12])
73 #include "op_template.h"
75 #define REGNAME r13
76 #define REG (env->regs[13])
77 #include "op_template.h"
79 #define REGNAME r14
80 #define REG (env->regs[14])
81 #include "op_template.h"
83 #define REGNAME r15
84 #define REG (env->regs[15])
85 #include "op_template.h"
88 #define REGNAME p0
89 #define REG (env->pregs[0])
90 #include "op_template.h"
92 #define REGNAME p1
93 #define REG (env->pregs[1])
94 #include "op_template.h"
96 #define REGNAME p2
97 #define REG (env->pregs[2])
98 #include "op_template.h"
100 #define REGNAME p3
101 #define REG (env->pregs[3])
102 #include "op_template.h"
104 #define REGNAME p4
105 #define REG (env->pregs[4])
106 #include "op_template.h"
108 #define REGNAME p5
109 #define REG (env->pregs[5])
110 #include "op_template.h"
112 #define REGNAME p6
113 #define REG (env->pregs[6])
114 #include "op_template.h"
116 #define REGNAME p7
117 #define REG (env->pregs[7])
118 #include "op_template.h"
120 #define REGNAME p8
121 #define REG (env->pregs[8])
122 #include "op_template.h"
124 #define REGNAME p9
125 #define REG (env->pregs[9])
126 #include "op_template.h"
128 #define REGNAME p10
129 #define REG (env->pregs[10])
130 #include "op_template.h"
132 #define REGNAME p11
133 #define REG (env->pregs[11])
134 #include "op_template.h"
136 #define REGNAME p12
137 #define REG (env->pregs[12])
138 #include "op_template.h"
140 #define REGNAME p13
141 #define REG (env->pregs[13])
142 #include "op_template.h"
144 #define REGNAME p14
145 #define REG (env->pregs[14])
146 #include "op_template.h"
148 #define REGNAME p15
149 #define REG (env->pregs[15])
150 #include "op_template.h"
152 /* Microcode. */
154 void OPPROTO op_break_im(void)
156 env->trapnr = PARAM1;
157 env->exception_index = EXCP_BREAK;
158 cpu_loop_exit();
161 void OPPROTO op_debug(void)
163 env->exception_index = EXCP_DEBUG;
164 cpu_loop_exit();
167 void OPPROTO op_exec_insn(void)
169 env->stats.exec_insns++;
170 RETURN();
172 void OPPROTO op_exec_load(void)
174 env->stats.exec_loads++;
175 RETURN();
177 void OPPROTO op_exec_store(void)
179 env->stats.exec_stores++;
180 RETURN();
183 void OPPROTO op_ccs_lshift (void)
185 uint32_t ccs;
187 /* Apply the ccs shift. */
188 ccs = env->pregs[PR_CCS];
189 ccs = (ccs & 0xc0000000) | ((ccs << 12) >> 2);
190 env->pregs[PR_CCS] = ccs;
191 RETURN();
193 void OPPROTO op_ccs_rshift (void)
195 uint32_t ccs;
197 /* Apply the ccs shift. */
198 ccs = env->pregs[PR_CCS];
199 ccs = (ccs & 0xc0000000) | (ccs >> 10);
200 env->pregs[PR_CCS] = ccs;
201 RETURN();
204 void OPPROTO op_setf (void)
206 env->pregs[PR_CCS] |= PARAM1;
207 RETURN();
210 void OPPROTO op_clrf (void)
212 env->pregs[PR_CCS] &= ~PARAM1;
213 RETURN();
216 void OPPROTO op_movl_debug1_T0 (void)
218 env->debug1 = T0;
219 RETURN();
222 void OPPROTO op_movl_debug2_T0 (void)
224 env->debug2 = T0;
225 RETURN();
228 void OPPROTO op_movl_debug3_T0 (void)
230 env->debug3 = T0;
231 RETURN();
233 void OPPROTO op_movl_debug1_T1 (void)
235 env->debug1 = T1;
236 RETURN();
239 void OPPROTO op_movl_debug2_T1 (void)
241 env->debug2 = T1;
242 RETURN();
245 void OPPROTO op_movl_debug3_T1 (void)
247 env->debug3 = T1;
248 RETURN();
250 void OPPROTO op_movl_debug3_im (void)
252 env->debug3 = PARAM1;
253 RETURN();
255 void OPPROTO op_movl_T0_flags (void)
257 T0 = env->pregs[PR_CCS];
258 RETURN();
260 void OPPROTO op_movl_flags_T0 (void)
262 env->pregs[PR_CCS] = T0;
263 RETURN();
266 void OPPROTO op_movl_sreg_T0 (void)
268 env->sregs[env->pregs[PR_SRS]][PARAM1] = T0;
269 RETURN();
272 void OPPROTO op_movl_tlb_lo_T0 (void)
274 int srs;
275 srs = env->pregs[PR_SRS];
276 if (srs == 1 || srs == 2)
278 int set;
279 int idx;
280 uint32_t lo, hi;
282 idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
283 set >>= 4;
284 set &= 3;
286 idx &= 31;
287 /* We've just made a write to tlb_lo. */
288 lo = env->sregs[SFR_RW_MM_TLB_LO];
289 hi = env->sregs[SFR_RW_MM_TLB_HI];
290 env->tlbsets[srs - 1][set][idx].lo = lo;
291 env->tlbsets[srs - 1][set][idx].hi = hi;
294 RETURN();
297 void OPPROTO op_movl_T0_sreg (void)
299 T0 = env->sregs[env->pregs[PR_SRS]][PARAM1];
300 RETURN();
303 void OPPROTO op_update_cc (void)
305 env->cc_op = PARAM1;
306 env->cc_dest = PARAM2;
307 env->cc_src = PARAM3;
308 RETURN();
311 void OPPROTO op_update_cc_op (void)
313 env->cc_op = PARAM1;
314 RETURN();
317 void OPPROTO op_update_cc_mask (void)
319 env->cc_mask = PARAM1;
320 RETURN();
323 void OPPROTO op_update_cc_dest_T0 (void)
325 env->cc_dest = T0;
326 RETURN();
329 void OPPROTO op_update_cc_result_T0 (void)
331 env->cc_result = T0;
332 RETURN();
335 void OPPROTO op_update_cc_size_im (void)
337 env->cc_size = PARAM1;
338 RETURN();
341 void OPPROTO op_update_cc_src_T1 (void)
343 env->cc_src = T1;
344 RETURN();
346 void OPPROTO op_update_cc_x (void)
348 env->cc_x_live = PARAM1;
349 env->cc_x = PARAM2;
350 RETURN();
353 /* FIXME: is this allowed? */
354 extern inline void evaluate_flags_writeback(uint32_t flags)
356 int x;
358 /* Extended arithmetics, leave the z flag alone. */
359 env->debug3 = env->pregs[PR_CCS];
361 if (env->cc_x_live)
362 x = env->cc_x;
363 else
364 x = env->pregs[PR_CCS] & X_FLAG;
366 if ((x || env->cc_op == CC_OP_ADDC)
367 && flags & Z_FLAG)
368 env->cc_mask &= ~Z_FLAG;
370 /* all insn clear the x-flag except setf or clrf. */
371 env->pregs[PR_CCS] &= ~(env->cc_mask | X_FLAG);
372 flags &= env->cc_mask;
373 env->pregs[PR_CCS] |= flags;
374 RETURN();
377 void OPPROTO op_evaluate_flags_muls(void)
379 uint32_t src;
380 uint32_t dst;
381 uint32_t res;
382 uint32_t flags = 0;
383 /* were gonna have to redo the muls. */
384 int64_t tmp, t0 ,t1;
385 int32_t mof;
386 int dneg;
388 src = env->cc_src;
389 dst = env->cc_dest;
390 res = env->cc_result;
393 /* cast into signed values to make GCC sign extend. */
394 t0 = (int32_t)src;
395 t1 = (int32_t)dst;
396 dneg = ((int32_t)res) < 0;
398 tmp = t0 * t1;
399 mof = tmp >> 32;
400 if (tmp == 0)
401 flags |= Z_FLAG;
402 else if (tmp < 0)
403 flags |= N_FLAG;
404 if ((dneg && mof != -1)
405 || (!dneg && mof != 0))
406 flags |= V_FLAG;
407 evaluate_flags_writeback(flags);
408 RETURN();
411 void OPPROTO op_evaluate_flags_mulu(void)
413 uint32_t src;
414 uint32_t dst;
415 uint32_t res;
416 uint32_t flags = 0;
417 /* were gonna have to redo the muls. */
418 uint64_t tmp, t0 ,t1;
419 uint32_t mof;
421 src = env->cc_src;
422 dst = env->cc_dest;
423 res = env->cc_result;
426 /* cast into signed values to make GCC sign extend. */
427 t0 = src;
428 t1 = dst;
430 tmp = t0 * t1;
431 mof = tmp >> 32;
432 if (tmp == 0)
433 flags |= Z_FLAG;
434 else if (tmp >> 63)
435 flags |= N_FLAG;
436 if (mof)
437 flags |= V_FLAG;
439 evaluate_flags_writeback(flags);
440 RETURN();
443 void OPPROTO op_evaluate_flags_mcp(void)
445 uint32_t src;
446 uint32_t dst;
447 uint32_t res;
448 uint32_t flags = 0;
450 src = env->cc_src;
451 dst = env->cc_dest;
452 res = env->cc_result;
454 if ((res & 0x80000000L) != 0L)
456 flags |= N_FLAG;
457 if (((src & 0x80000000L) == 0L)
458 && ((dst & 0x80000000L) == 0L))
460 flags |= V_FLAG;
462 else if (((src & 0x80000000L) != 0L) &&
463 ((dst & 0x80000000L) != 0L))
465 flags |= R_FLAG;
468 else
470 if (res == 0L)
471 flags |= Z_FLAG;
472 if (((src & 0x80000000L) != 0L)
473 && ((dst & 0x80000000L) != 0L))
474 flags |= V_FLAG;
475 if ((dst & 0x80000000L) != 0L
476 || (src & 0x80000000L) != 0L)
477 flags |= R_FLAG;
480 evaluate_flags_writeback(flags);
481 RETURN();
484 void OPPROTO op_evaluate_flags_alu_4(void)
486 uint32_t src;
487 uint32_t dst;
488 uint32_t res;
489 uint32_t flags = 0;
491 src = env->cc_src;
492 dst = env->cc_dest;
493 res = env->cc_result;
495 if ((res & 0x80000000L) != 0L)
497 flags |= N_FLAG;
498 if (((src & 0x80000000L) == 0L)
499 && ((dst & 0x80000000L) == 0L))
501 flags |= V_FLAG;
503 else if (((src & 0x80000000L) != 0L) &&
504 ((dst & 0x80000000L) != 0L))
506 flags |= C_FLAG;
509 else
511 if (res == 0L)
512 flags |= Z_FLAG;
513 if (((src & 0x80000000L) != 0L)
514 && ((dst & 0x80000000L) != 0L))
515 flags |= V_FLAG;
516 if ((dst & 0x80000000L) != 0L
517 || (src & 0x80000000L) != 0L)
518 flags |= C_FLAG;
521 if (env->cc_op == CC_OP_SUB
522 || env->cc_op == CC_OP_CMP) {
523 flags ^= C_FLAG;
525 evaluate_flags_writeback(flags);
526 RETURN();
529 void OPPROTO op_evaluate_flags_move_4 (void)
531 uint32_t src;
532 uint32_t res;
533 uint32_t flags = 0;
535 src = env->cc_src;
536 res = env->cc_result;
538 if ((int32_t)res < 0)
539 flags |= N_FLAG;
540 else if (res == 0L)
541 flags |= Z_FLAG;
543 evaluate_flags_writeback(flags);
544 RETURN();
546 void OPPROTO op_evaluate_flags_move_2 (void)
548 uint32_t src;
549 uint32_t flags = 0;
550 uint16_t res;
552 src = env->cc_src;
553 res = env->cc_result;
555 if ((int16_t)res < 0L)
556 flags |= N_FLAG;
557 else if (res == 0)
558 flags |= Z_FLAG;
560 evaluate_flags_writeback(flags);
561 RETURN();
564 /* TODO: This is expensive. We could split things up and only evaluate part of
565 CCR on a need to know basis. For now, we simply re-evaluate everything. */
566 void OPPROTO op_evaluate_flags (void)
568 uint32_t src;
569 uint32_t dst;
570 uint32_t res;
571 uint32_t flags = 0;
573 src = env->cc_src;
574 dst = env->cc_dest;
575 res = env->cc_result;
578 /* Now, evaluate the flags. This stuff is based on
579 Per Zander's CRISv10 simulator. */
580 switch (env->cc_size)
582 case 1:
583 if ((res & 0x80L) != 0L)
585 flags |= N_FLAG;
586 if (((src & 0x80L) == 0L)
587 && ((dst & 0x80L) == 0L))
589 flags |= V_FLAG;
591 else if (((src & 0x80L) != 0L)
592 && ((dst & 0x80L) != 0L))
594 flags |= C_FLAG;
597 else
599 if ((res & 0xFFL) == 0L)
601 flags |= Z_FLAG;
603 if (((src & 0x80L) != 0L)
604 && ((dst & 0x80L) != 0L))
606 flags |= V_FLAG;
608 if ((dst & 0x80L) != 0L
609 || (src & 0x80L) != 0L)
611 flags |= C_FLAG;
614 break;
615 case 2:
616 if ((res & 0x8000L) != 0L)
618 flags |= N_FLAG;
619 if (((src & 0x8000L) == 0L)
620 && ((dst & 0x8000L) == 0L))
622 flags |= V_FLAG;
624 else if (((src & 0x8000L) != 0L)
625 && ((dst & 0x8000L) != 0L))
627 flags |= C_FLAG;
630 else
632 if ((res & 0xFFFFL) == 0L)
634 flags |= Z_FLAG;
636 if (((src & 0x8000L) != 0L)
637 && ((dst & 0x8000L) != 0L))
639 flags |= V_FLAG;
641 if ((dst & 0x8000L) != 0L
642 || (src & 0x8000L) != 0L)
644 flags |= C_FLAG;
647 break;
648 case 4:
649 if ((res & 0x80000000L) != 0L)
651 flags |= N_FLAG;
652 if (((src & 0x80000000L) == 0L)
653 && ((dst & 0x80000000L) == 0L))
655 flags |= V_FLAG;
657 else if (((src & 0x80000000L) != 0L) &&
658 ((dst & 0x80000000L) != 0L))
660 flags |= C_FLAG;
663 else
665 if (res == 0L)
666 flags |= Z_FLAG;
667 if (((src & 0x80000000L) != 0L)
668 && ((dst & 0x80000000L) != 0L))
669 flags |= V_FLAG;
670 if ((dst & 0x80000000L) != 0L
671 || (src & 0x80000000L) != 0L)
672 flags |= C_FLAG;
674 break;
675 default:
676 break;
679 if (env->cc_op == CC_OP_SUB
680 || env->cc_op == CC_OP_CMP) {
681 flags ^= C_FLAG;
683 evaluate_flags_writeback(flags);
684 RETURN();
687 void OPPROTO op_extb_T0_T0 (void)
689 T0 = ((int8_t)T0);
690 RETURN();
692 void OPPROTO op_extb_T1_T0 (void)
694 T1 = ((int8_t)T0);
695 RETURN();
697 void OPPROTO op_extb_T1_T1 (void)
699 T1 = ((int8_t)T1);
700 RETURN();
702 void OPPROTO op_zextb_T0_T0 (void)
704 T0 = ((uint8_t)T0);
705 RETURN();
707 void OPPROTO op_zextb_T1_T0 (void)
709 T1 = ((uint8_t)T0);
710 RETURN();
712 void OPPROTO op_zextb_T1_T1 (void)
714 T1 = ((uint8_t)T1);
715 RETURN();
717 void OPPROTO op_extw_T0_T0 (void)
719 T0 = ((int16_t)T0);
720 RETURN();
722 void OPPROTO op_extw_T1_T0 (void)
724 T1 = ((int16_t)T0);
725 RETURN();
727 void OPPROTO op_extw_T1_T1 (void)
729 T1 = ((int16_t)T1);
730 RETURN();
733 void OPPROTO op_zextw_T0_T0 (void)
735 T0 = ((uint16_t)T0);
736 RETURN();
738 void OPPROTO op_zextw_T1_T0 (void)
740 T1 = ((uint16_t)T0);
741 RETURN();
744 void OPPROTO op_zextw_T1_T1 (void)
746 T1 = ((uint16_t)T1);
747 RETURN();
750 void OPPROTO op_movl_T0_im (void)
752 T0 = PARAM1;
753 RETURN();
755 void OPPROTO op_movl_T1_im (void)
757 T1 = PARAM1;
758 RETURN();
761 void OPPROTO op_addl_T0_im (void)
763 T0 += PARAM1;
764 RETURN();
767 void OPPROTO op_addl_T1_im (void)
769 T1 += PARAM1;
770 RETURN();
773 void OPPROTO op_subl_T0_im (void)
775 T0 -= PARAM1;
776 RETURN();
779 void OPPROTO op_addxl_T0_C (void)
781 if (env->pregs[PR_CCS] & X_FLAG)
782 T0 += !!(env->pregs[PR_CCS] & C_FLAG);
783 RETURN();
785 void OPPROTO op_subxl_T0_C (void)
787 if (env->pregs[PR_CCS] & X_FLAG)
788 T0 -= !!(env->pregs[PR_CCS] & C_FLAG);
789 RETURN();
791 void OPPROTO op_addl_T0_C (void)
793 T0 += !!(env->pregs[PR_CCS] & C_FLAG);
794 RETURN();
796 void OPPROTO op_addl_T0_R (void)
798 T0 += !!(env->pregs[PR_CCS] & R_FLAG);
799 RETURN();
802 void OPPROTO op_clr_R (void)
804 env->pregs[PR_CCS] &= ~R_FLAG;
805 RETURN();
809 void OPPROTO op_andl_T0_im (void)
811 T0 &= PARAM1;
812 RETURN();
815 void OPPROTO op_andl_T1_im (void)
817 T1 &= PARAM1;
818 RETURN();
821 void OPPROTO op_movl_T0_T1 (void)
823 T0 = T1;
824 RETURN();
827 void OPPROTO op_swp_T0_T1 (void)
829 T0 ^= T1;
830 T1 ^= T0;
831 T0 ^= T1;
832 RETURN();
835 void OPPROTO op_movl_T1_T0 (void)
837 T1 = T0;
838 RETURN();
841 void OPPROTO op_movl_pc_T0 (void)
843 env->pc = T0;
844 RETURN();
847 void OPPROTO op_movl_T0_0 (void)
849 T0 = 0;
850 RETURN();
853 void OPPROTO op_addl_T0_T1 (void)
855 T0 += T1;
856 RETURN();
859 void OPPROTO op_subl_T0_T1 (void)
861 T0 -= T1;
862 RETURN();
865 void OPPROTO op_absl_T1_T1 (void)
867 int32_t st = T1;
869 T1 = st < 0 ? -st : st;
870 RETURN();
873 void OPPROTO op_muls_T0_T1 (void)
875 int64_t tmp, t0 ,t1;
877 /* cast into signed values to make GCC sign extend these babies. */
878 t0 = (int32_t)T0;
879 t1 = (int32_t)T1;
881 tmp = t0 * t1;
882 T0 = tmp & 0xffffffff;
883 env->pregs[PR_MOF] = tmp >> 32;
884 RETURN();
887 void OPPROTO op_mulu_T0_T1 (void)
889 uint64_t tmp, t0 ,t1;
890 t0 = T0;
891 t1 = T1;
893 tmp = t0 * t1;
894 T0 = tmp & 0xffffffff;
895 env->pregs[PR_MOF] = tmp >> 32;
896 RETURN();
899 void OPPROTO op_dstep_T0_T1 (void)
901 T0 <<= 1;
902 if (T0 >= T1)
903 T0 -= T1;
904 RETURN();
907 void OPPROTO op_orl_T0_T1 (void)
909 T0 |= T1;
910 RETURN();
913 void OPPROTO op_andl_T0_T1 (void)
915 T0 &= T1;
916 RETURN();
919 void OPPROTO op_xorl_T0_T1 (void)
921 T0 ^= T1;
922 RETURN();
925 void OPPROTO op_lsll_T0_T1 (void)
927 int s = T1;
928 if (s > 31)
929 T0 = 0;
930 else
931 T0 <<= s;
932 RETURN();
935 void OPPROTO op_lsll_T0_im (void)
937 T0 <<= PARAM1;
938 RETURN();
941 void OPPROTO op_lsrl_T0_T1 (void)
943 int s = T1;
944 if (s > 31)
945 T0 = 0;
946 else
947 T0 >>= s;
948 RETURN();
951 /* Rely on GCC emitting an arithmetic shift for signed right shifts. */
952 void OPPROTO op_asrl_T0_T1 (void)
954 int s = T1;
955 if (s > 31)
956 T0 = T0 & 0x80000000 ? -1 : 0;
957 else
958 T0 = (int32_t)T0 >> s;
959 RETURN();
962 void OPPROTO op_btst_T0_T1 (void)
964 /* FIXME: clean this up. */
966 /* des ref:
967 The N flag is set according to the selected bit in the dest reg.
968 The Z flag is set if the selected bit and all bits to the right are
969 zero.
970 The X flag is cleared.
971 Other flags are left untouched.
972 The destination reg is not affected.*/
973 unsigned int fz, sbit, bset, mask, masked_t0;
975 sbit = T1 & 31;
976 bset = !!(T0 & (1 << sbit));
977 mask = sbit == 31 ? -1 : (1 << (sbit + 1)) - 1;
978 masked_t0 = T0 & mask;
979 fz = !(masked_t0 | bset);
981 /* Clear the X, N and Z flags. */
982 T0 = env->pregs[PR_CCS] & ~(X_FLAG | N_FLAG | Z_FLAG);
983 /* Set the N and Z flags accordingly. */
984 T0 |= (bset << 3) | (fz << 2);
985 RETURN();
988 void OPPROTO op_bound_T0_T1 (void)
990 if (T0 > T1)
991 T0 = T1;
992 RETURN();
995 void OPPROTO op_lz_T0_T1 (void)
997 T0 = clz32(T1);
998 RETURN();
1001 void OPPROTO op_negl_T0_T1 (void)
1003 T0 = -T1;
1004 RETURN();
1007 void OPPROTO op_negl_T1_T1 (void)
1009 T1 = -T1;
1010 RETURN();
1013 void OPPROTO op_not_T0_T0 (void)
1015 T0 = ~(T0);
1016 RETURN();
1018 void OPPROTO op_not_T1_T1 (void)
1020 T1 = ~(T1);
1021 RETURN();
1024 void OPPROTO op_swapw_T0_T0 (void)
1026 T0 = (T0 << 16) | ((T0 >> 16));
1027 RETURN();
1030 void OPPROTO op_swapb_T0_T0 (void)
1032 T0 = ((T0 << 8) & 0xff00ff00) | ((T0 >> 8) & 0x00ff00ff);
1033 RETURN();
1036 void OPPROTO op_swapr_T0_T0 (void)
1038 T0 = (((T0 << 7) & 0x80808080) |
1039 ((T0 << 5) & 0x40404040) |
1040 ((T0 << 3) & 0x20202020) |
1041 ((T0 << 1) & 0x10101010) |
1042 ((T0 >> 1) & 0x08080808) |
1043 ((T0 >> 3) & 0x04040404) |
1044 ((T0 >> 5) & 0x02020202) |
1045 ((T0 >> 7) & 0x01010101));
1046 RETURN();
1049 void OPPROTO op_tst_cc_eq (void) {
1050 uint32_t flags = env->pregs[PR_CCS];
1051 int z_set;
1053 z_set = !!(flags & Z_FLAG);
1054 T0 = z_set;
1055 RETURN();
1058 void OPPROTO op_tst_cc_eq_fast (void) {
1059 T0 = !(env->cc_result);
1060 RETURN();
1063 void OPPROTO op_tst_cc_ne (void) {
1064 uint32_t flags = env->pregs[PR_CCS];
1065 int z_set;
1067 z_set = !!(flags & Z_FLAG);
1068 T0 = !z_set;
1069 RETURN();
1071 void OPPROTO op_tst_cc_ne_fast (void) {
1072 T0 = !!(env->cc_result);
1073 RETURN();
1076 void OPPROTO op_tst_cc_cc (void) {
1077 uint32_t flags = env->pregs[PR_CCS];
1078 int c_set;
1080 c_set = !!(flags & C_FLAG);
1081 T0 = !c_set;
1082 RETURN();
1084 void OPPROTO op_tst_cc_cs (void) {
1085 uint32_t flags = env->pregs[PR_CCS];
1086 int c_set;
1088 c_set = !!(flags & C_FLAG);
1089 T0 = c_set;
1090 RETURN();
1093 void OPPROTO op_tst_cc_vc (void) {
1094 uint32_t flags = env->pregs[PR_CCS];
1095 int v_set;
1097 v_set = !!(flags & V_FLAG);
1098 T0 = !v_set;
1099 RETURN();
1101 void OPPROTO op_tst_cc_vs (void) {
1102 uint32_t flags = env->pregs[PR_CCS];
1103 int v_set;
1105 v_set = !!(flags & V_FLAG);
1106 T0 = v_set;
1107 RETURN();
1109 void OPPROTO op_tst_cc_pl (void) {
1110 uint32_t flags = env->pregs[PR_CCS];
1111 int n_set;
1113 n_set = !!(flags & N_FLAG);
1114 T0 = !n_set;
1115 RETURN();
1117 void OPPROTO op_tst_cc_pl_fast (void) {
1118 T0 = ((int32_t)env->cc_result) >= 0;
1119 RETURN();
1122 void OPPROTO op_tst_cc_mi (void) {
1123 uint32_t flags = env->pregs[PR_CCS];
1124 int n_set;
1126 n_set = !!(flags & N_FLAG);
1127 T0 = n_set;
1128 RETURN();
1130 void OPPROTO op_tst_cc_mi_fast (void) {
1131 T0 = ((int32_t)env->cc_result) < 0;
1132 RETURN();
1135 void OPPROTO op_tst_cc_ls (void) {
1136 uint32_t flags = env->pregs[PR_CCS];
1137 int c_set;
1138 int z_set;
1140 c_set = !!(flags & C_FLAG);
1141 z_set = !!(flags & Z_FLAG);
1142 T0 = c_set || z_set;
1143 RETURN();
1145 void OPPROTO op_tst_cc_hi (void) {
1146 uint32_t flags = env->pregs[PR_CCS];
1147 int z_set;
1148 int c_set;
1150 z_set = !!(flags & Z_FLAG);
1151 c_set = !!(flags & C_FLAG);
1152 T0 = !c_set && !z_set;
1153 RETURN();
1157 void OPPROTO op_tst_cc_ge (void) {
1158 uint32_t flags = env->pregs[PR_CCS];
1159 int n_set;
1160 int v_set;
1162 n_set = !!(flags & N_FLAG);
1163 v_set = !!(flags & V_FLAG);
1164 T0 = (n_set && v_set) || (!n_set && !v_set);
1165 RETURN();
1168 void OPPROTO op_tst_cc_ge_fast (void) {
1169 T0 = ((int32_t)env->cc_src < (int32_t)env->cc_dest);
1170 RETURN();
1173 void OPPROTO op_tst_cc_lt (void) {
1174 uint32_t flags = env->pregs[PR_CCS];
1175 int n_set;
1176 int v_set;
1178 n_set = !!(flags & N_FLAG);
1179 v_set = !!(flags & V_FLAG);
1180 T0 = (n_set && !v_set) || (!n_set && v_set);
1181 RETURN();
1184 void OPPROTO op_tst_cc_gt (void) {
1185 uint32_t flags = env->pregs[PR_CCS];
1186 int n_set;
1187 int v_set;
1188 int z_set;
1190 n_set = !!(flags & N_FLAG);
1191 v_set = !!(flags & V_FLAG);
1192 z_set = !!(flags & Z_FLAG);
1193 T0 = (n_set && v_set && !z_set)
1194 || (!n_set && !v_set && !z_set);
1195 RETURN();
1198 void OPPROTO op_tst_cc_le (void) {
1199 uint32_t flags = env->pregs[PR_CCS];
1200 int n_set;
1201 int v_set;
1202 int z_set;
1204 n_set = !!(flags & N_FLAG);
1205 v_set = !!(flags & V_FLAG);
1206 z_set = !!(flags & Z_FLAG);
1207 T0 = z_set || (n_set && !v_set) || (!n_set && v_set);
1208 RETURN();
1211 void OPPROTO op_tst_cc_p (void) {
1212 uint32_t flags = env->pregs[PR_CCS];
1213 int p_set;
1215 p_set = !!(flags & P_FLAG);
1216 T0 = p_set;
1217 RETURN();
1220 /* Evaluate the if the branch should be taken or not. Needs to be done in
1221 the original sequence. The acutal branch is rescheduled to right after the
1222 delay-slot. */
1223 void OPPROTO op_evaluate_bcc (void)
1225 env->btaken = T0;
1226 RETURN();
1229 /* this one is used on every alu op, optimize it!. */
1230 void OPPROTO op_goto_if_not_x (void)
1232 if (env->pregs[PR_CCS] & X_FLAG)
1233 GOTO_LABEL_PARAM(1);
1234 RETURN();
1237 void OPPROTO op_cc_jmp (void)
1239 if (env->btaken)
1240 env->pc = PARAM1;
1241 else
1242 env->pc = PARAM2;
1243 RETURN();
1246 void OPPROTO op_cc_ngoto (void)
1248 if (!env->btaken)
1249 GOTO_LABEL_PARAM(1);
1250 RETURN();
1253 void OPPROTO op_movl_btarget_T0 (void)
1255 env->btarget = T0;
1256 RETURN();
1259 void OPPROTO op_jmp1 (void)
1261 env->pc = env->btarget;
1262 RETURN();
1265 /* Load and store */
1266 #define MEMSUFFIX _raw
1267 #include "op_mem.c"
1268 #undef MEMSUFFIX
1269 #if !defined(CONFIG_USER_ONLY)
1270 #define MEMSUFFIX _user
1271 #include "op_mem.c"
1272 #undef MEMSUFFIX
1274 #define MEMSUFFIX _kernel
1275 #include "op_mem.c"
1276 #undef MEMSUFFIX
1277 #endif