darwin fix
[qemu/mdroth.git] / target-sparc / op.c
blob1ec15d28b1376f27669883f1fc36d510068c1574
1 /*
2 SPARC micro operations
4 Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
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
21 #include "exec.h"
23 /*XXX*/
24 #define REGNAME g0
25 #define REG (env->gregs[0])
26 #include "op_template.h"
27 #define REGNAME g1
28 #define REG (env->gregs[1])
29 #include "op_template.h"
30 #define REGNAME g2
31 #define REG (env->gregs[2])
32 #include "op_template.h"
33 #define REGNAME g3
34 #define REG (env->gregs[3])
35 #include "op_template.h"
36 #define REGNAME g4
37 #define REG (env->gregs[4])
38 #include "op_template.h"
39 #define REGNAME g5
40 #define REG (env->gregs[5])
41 #include "op_template.h"
42 #define REGNAME g6
43 #define REG (env->gregs[6])
44 #include "op_template.h"
45 #define REGNAME g7
46 #define REG (env->gregs[7])
47 #include "op_template.h"
48 #define REGNAME i0
49 #define REG (REGWPTR[16])
50 #include "op_template.h"
51 #define REGNAME i1
52 #define REG (REGWPTR[17])
53 #include "op_template.h"
54 #define REGNAME i2
55 #define REG (REGWPTR[18])
56 #include "op_template.h"
57 #define REGNAME i3
58 #define REG (REGWPTR[19])
59 #include "op_template.h"
60 #define REGNAME i4
61 #define REG (REGWPTR[20])
62 #include "op_template.h"
63 #define REGNAME i5
64 #define REG (REGWPTR[21])
65 #include "op_template.h"
66 #define REGNAME i6
67 #define REG (REGWPTR[22])
68 #include "op_template.h"
69 #define REGNAME i7
70 #define REG (REGWPTR[23])
71 #include "op_template.h"
72 #define REGNAME l0
73 #define REG (REGWPTR[8])
74 #include "op_template.h"
75 #define REGNAME l1
76 #define REG (REGWPTR[9])
77 #include "op_template.h"
78 #define REGNAME l2
79 #define REG (REGWPTR[10])
80 #include "op_template.h"
81 #define REGNAME l3
82 #define REG (REGWPTR[11])
83 #include "op_template.h"
84 #define REGNAME l4
85 #define REG (REGWPTR[12])
86 #include "op_template.h"
87 #define REGNAME l5
88 #define REG (REGWPTR[13])
89 #include "op_template.h"
90 #define REGNAME l6
91 #define REG (REGWPTR[14])
92 #include "op_template.h"
93 #define REGNAME l7
94 #define REG (REGWPTR[15])
95 #include "op_template.h"
96 #define REGNAME o0
97 #define REG (REGWPTR[0])
98 #include "op_template.h"
99 #define REGNAME o1
100 #define REG (REGWPTR[1])
101 #include "op_template.h"
102 #define REGNAME o2
103 #define REG (REGWPTR[2])
104 #include "op_template.h"
105 #define REGNAME o3
106 #define REG (REGWPTR[3])
107 #include "op_template.h"
108 #define REGNAME o4
109 #define REG (REGWPTR[4])
110 #include "op_template.h"
111 #define REGNAME o5
112 #define REG (REGWPTR[5])
113 #include "op_template.h"
114 #define REGNAME o6
115 #define REG (REGWPTR[6])
116 #include "op_template.h"
117 #define REGNAME o7
118 #define REG (REGWPTR[7])
119 #include "op_template.h"
121 #define REGNAME f0
122 #define REG (env->fpr[0])
123 #include "fop_template.h"
124 #define REGNAME f1
125 #define REG (env->fpr[1])
126 #include "fop_template.h"
127 #define REGNAME f2
128 #define REG (env->fpr[2])
129 #include "fop_template.h"
130 #define REGNAME f3
131 #define REG (env->fpr[3])
132 #include "fop_template.h"
133 #define REGNAME f4
134 #define REG (env->fpr[4])
135 #include "fop_template.h"
136 #define REGNAME f5
137 #define REG (env->fpr[5])
138 #include "fop_template.h"
139 #define REGNAME f6
140 #define REG (env->fpr[6])
141 #include "fop_template.h"
142 #define REGNAME f7
143 #define REG (env->fpr[7])
144 #include "fop_template.h"
145 #define REGNAME f8
146 #define REG (env->fpr[8])
147 #include "fop_template.h"
148 #define REGNAME f9
149 #define REG (env->fpr[9])
150 #include "fop_template.h"
151 #define REGNAME f10
152 #define REG (env->fpr[10])
153 #include "fop_template.h"
154 #define REGNAME f11
155 #define REG (env->fpr[11])
156 #include "fop_template.h"
157 #define REGNAME f12
158 #define REG (env->fpr[12])
159 #include "fop_template.h"
160 #define REGNAME f13
161 #define REG (env->fpr[13])
162 #include "fop_template.h"
163 #define REGNAME f14
164 #define REG (env->fpr[14])
165 #include "fop_template.h"
166 #define REGNAME f15
167 #define REG (env->fpr[15])
168 #include "fop_template.h"
169 #define REGNAME f16
170 #define REG (env->fpr[16])
171 #include "fop_template.h"
172 #define REGNAME f17
173 #define REG (env->fpr[17])
174 #include "fop_template.h"
175 #define REGNAME f18
176 #define REG (env->fpr[18])
177 #include "fop_template.h"
178 #define REGNAME f19
179 #define REG (env->fpr[19])
180 #include "fop_template.h"
181 #define REGNAME f20
182 #define REG (env->fpr[20])
183 #include "fop_template.h"
184 #define REGNAME f21
185 #define REG (env->fpr[21])
186 #include "fop_template.h"
187 #define REGNAME f22
188 #define REG (env->fpr[22])
189 #include "fop_template.h"
190 #define REGNAME f23
191 #define REG (env->fpr[23])
192 #include "fop_template.h"
193 #define REGNAME f24
194 #define REG (env->fpr[24])
195 #include "fop_template.h"
196 #define REGNAME f25
197 #define REG (env->fpr[25])
198 #include "fop_template.h"
199 #define REGNAME f26
200 #define REG (env->fpr[26])
201 #include "fop_template.h"
202 #define REGNAME f27
203 #define REG (env->fpr[27])
204 #include "fop_template.h"
205 #define REGNAME f28
206 #define REG (env->fpr[28])
207 #include "fop_template.h"
208 #define REGNAME f29
209 #define REG (env->fpr[29])
210 #include "fop_template.h"
211 #define REGNAME f30
212 #define REG (env->fpr[30])
213 #include "fop_template.h"
214 #define REGNAME f31
215 #define REG (env->fpr[31])
216 #include "fop_template.h"
218 #ifdef TARGET_SPARC64
219 #define REGNAME f32
220 #define REG (env->fpr[32])
221 #include "fop_template.h"
222 #define REGNAME f34
223 #define REG (env->fpr[34])
224 #include "fop_template.h"
225 #define REGNAME f36
226 #define REG (env->fpr[36])
227 #include "fop_template.h"
228 #define REGNAME f38
229 #define REG (env->fpr[38])
230 #include "fop_template.h"
231 #define REGNAME f40
232 #define REG (env->fpr[40])
233 #include "fop_template.h"
234 #define REGNAME f42
235 #define REG (env->fpr[42])
236 #include "fop_template.h"
237 #define REGNAME f44
238 #define REG (env->fpr[44])
239 #include "fop_template.h"
240 #define REGNAME f46
241 #define REG (env->fpr[46])
242 #include "fop_template.h"
243 #define REGNAME f48
244 #define REG (env->fpr[47])
245 #include "fop_template.h"
246 #define REGNAME f50
247 #define REG (env->fpr[50])
248 #include "fop_template.h"
249 #define REGNAME f52
250 #define REG (env->fpr[52])
251 #include "fop_template.h"
252 #define REGNAME f54
253 #define REG (env->fpr[54])
254 #include "fop_template.h"
255 #define REGNAME f56
256 #define REG (env->fpr[56])
257 #include "fop_template.h"
258 #define REGNAME f58
259 #define REG (env->fpr[58])
260 #include "fop_template.h"
261 #define REGNAME f60
262 #define REG (env->fpr[60])
263 #include "fop_template.h"
264 #define REGNAME f62
265 #define REG (env->fpr[62])
266 #include "fop_template.h"
267 #endif
269 #ifdef TARGET_SPARC64
270 #ifdef WORDS_BIGENDIAN
271 typedef union UREG64 {
272 struct { uint16_t v3, v2, v1, v0; } w;
273 struct { uint32_t v1, v0; } l;
274 uint64_t q;
275 } UREG64;
276 #else
277 typedef union UREG64 {
278 struct { uint16_t v0, v1, v2, v3; } w;
279 struct { uint32_t v0, v1; } l;
280 uint64_t q;
281 } UREG64;
282 #endif
284 #define PARAMQ1 \
286 UREG64 __p;\
287 __p.l.v1 = PARAM1;\
288 __p.l.v0 = PARAM2;\
289 __p.q;\
292 void OPPROTO op_movq_T0_im64(void)
294 T0 = PARAMQ1;
297 void OPPROTO op_movq_T1_im64(void)
299 T1 = PARAMQ1;
302 #define XFLAG_SET(x) ((env->xcc&x)?1:0)
304 #else
305 #define EIP (env->pc)
306 #endif
308 #define FLAG_SET(x) ((env->psr&x)?1:0)
310 void OPPROTO op_movl_T0_0(void)
312 T0 = 0;
315 void OPPROTO op_movl_T0_im(void)
317 T0 = (uint32_t)PARAM1;
320 void OPPROTO op_movl_T1_im(void)
322 T1 = (uint32_t)PARAM1;
325 void OPPROTO op_movl_T2_im(void)
327 T2 = (uint32_t)PARAM1;
330 void OPPROTO op_movl_T0_sim(void)
332 T0 = (int32_t)PARAM1;
335 void OPPROTO op_movl_T1_sim(void)
337 T1 = (int32_t)PARAM1;
340 void OPPROTO op_movl_T2_sim(void)
342 T2 = (int32_t)PARAM1;
345 void OPPROTO op_movl_T0_env(void)
347 T0 = *(uint32_t *)((char *)env + PARAM1);
350 void OPPROTO op_movl_env_T0(void)
352 *(uint32_t *)((char *)env + PARAM1) = T0;
355 void OPPROTO op_movtl_T0_env(void)
357 T0 = *(target_ulong *)((char *)env + PARAM1);
360 void OPPROTO op_movtl_env_T0(void)
362 *(target_ulong *)((char *)env + PARAM1) = T0;
365 void OPPROTO op_add_T1_T0(void)
367 T0 += T1;
370 void OPPROTO op_add_T1_T0_cc(void)
372 target_ulong src1;
374 src1 = T0;
375 T0 += T1;
376 env->psr = 0;
377 #ifdef TARGET_SPARC64
378 if (!(T0 & 0xffffffff))
379 env->psr |= PSR_ZERO;
380 if ((int32_t) T0 < 0)
381 env->psr |= PSR_NEG;
382 if ((T0 & 0xffffffff) < (src1 & 0xffffffff))
383 env->psr |= PSR_CARRY;
384 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff) ^ -1) &
385 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
386 env->psr |= PSR_OVF;
388 env->xcc = 0;
389 if (!T0)
390 env->xcc |= PSR_ZERO;
391 if ((int64_t) T0 < 0)
392 env->xcc |= PSR_NEG;
393 if (T0 < src1)
394 env->xcc |= PSR_CARRY;
395 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1ULL << 63))
396 env->xcc |= PSR_OVF;
397 #else
398 if (!T0)
399 env->psr |= PSR_ZERO;
400 if ((int32_t) T0 < 0)
401 env->psr |= PSR_NEG;
402 if (T0 < src1)
403 env->psr |= PSR_CARRY;
404 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
405 env->psr |= PSR_OVF;
406 #endif
407 FORCE_RET();
410 void OPPROTO op_addx_T1_T0(void)
412 T0 += T1 + FLAG_SET(PSR_CARRY);
415 void OPPROTO op_addx_T1_T0_cc(void)
417 target_ulong src1;
418 src1 = T0;
419 if (FLAG_SET(PSR_CARRY))
421 T0 += T1 + 1;
422 env->psr = 0;
423 #ifdef TARGET_SPARC64
424 if ((T0 & 0xffffffff) <= (src1 & 0xffffffff))
425 env->psr |= PSR_CARRY;
426 env->xcc = 0;
427 if (T0 <= src1)
428 env->xcc |= PSR_CARRY;
429 #else
430 if (T0 <= src1)
431 env->psr |= PSR_CARRY;
432 #endif
434 else
436 T0 += T1;
437 env->psr = 0;
438 #ifdef TARGET_SPARC64
439 if ((T0 & 0xffffffff) < (src1 & 0xffffffff))
440 env->psr |= PSR_CARRY;
441 env->xcc = 0;
442 if (T0 < src1)
443 env->xcc |= PSR_CARRY;
444 #else
445 if (T0 < src1)
446 env->psr |= PSR_CARRY;
447 #endif
449 #ifdef TARGET_SPARC64
450 if (!(T0 & 0xffffffff))
451 env->psr |= PSR_ZERO;
452 if ((int32_t) T0 < 0)
453 env->psr |= PSR_NEG;
454 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff) ^ -1) &
455 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
456 env->psr |= PSR_OVF;
458 if (!T0)
459 env->xcc |= PSR_ZERO;
460 if ((int64_t) T0 < 0)
461 env->xcc |= PSR_NEG;
462 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1ULL << 63))
463 env->xcc |= PSR_OVF;
464 #else
465 if (!T0)
466 env->psr |= PSR_ZERO;
467 if ((int32_t) T0 < 0)
468 env->psr |= PSR_NEG;
469 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
470 env->psr |= PSR_OVF;
471 #endif
472 FORCE_RET();
475 void OPPROTO op_sub_T1_T0(void)
477 T0 -= T1;
480 void OPPROTO op_sub_T1_T0_cc(void)
482 target_ulong src1;
484 src1 = T0;
485 T0 -= T1;
486 env->psr = 0;
487 #ifdef TARGET_SPARC64
488 if (!(T0 & 0xffffffff))
489 env->psr |= PSR_ZERO;
490 if ((int32_t) T0 < 0)
491 env->psr |= PSR_NEG;
492 if ((src1 & 0xffffffff) < (T1 & 0xffffffff))
493 env->psr |= PSR_CARRY;
494 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) &
495 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
496 env->psr |= PSR_OVF;
498 env->xcc = 0;
499 if (!T0)
500 env->xcc |= PSR_ZERO;
501 if ((int64_t) T0 < 0)
502 env->xcc |= PSR_NEG;
503 if (src1 < T1)
504 env->xcc |= PSR_CARRY;
505 if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63))
506 env->xcc |= PSR_OVF;
507 #else
508 if (!T0)
509 env->psr |= PSR_ZERO;
510 if ((int32_t) T0 < 0)
511 env->psr |= PSR_NEG;
512 if (src1 < T1)
513 env->psr |= PSR_CARRY;
514 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
515 env->psr |= PSR_OVF;
516 #endif
517 FORCE_RET();
520 void OPPROTO op_subx_T1_T0(void)
522 T0 -= T1 + FLAG_SET(PSR_CARRY);
525 void OPPROTO op_subx_T1_T0_cc(void)
527 target_ulong src1;
528 src1 = T0;
529 if (FLAG_SET(PSR_CARRY))
531 T0 -= T1 + 1;
532 env->psr = 0;
533 #ifdef TARGET_SPARC64
534 if ((src1 & 0xffffffff) <= (T1 & 0xffffffff))
535 env->psr |= PSR_CARRY;
536 env->xcc = 0;
537 if (src1 <= T1)
538 env->xcc |= PSR_CARRY;
539 #else
540 if (src1 <= T1)
541 env->psr |= PSR_CARRY;
542 #endif
544 else
546 T0 -= T1;
547 env->psr = 0;
548 #ifdef TARGET_SPARC64
549 if ((src1 & 0xffffffff) < (T1 & 0xffffffff))
550 env->psr |= PSR_CARRY;
551 env->xcc = 0;
552 if (src1 < T1)
553 env->xcc |= PSR_CARRY;
554 #else
555 if (src1 < T1)
556 env->psr |= PSR_CARRY;
557 #endif
559 #ifdef TARGET_SPARC64
560 if (!(T0 & 0xffffffff))
561 env->psr |= PSR_ZERO;
562 if ((int32_t) T0 < 0)
563 env->psr |= PSR_NEG;
564 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) &
565 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
566 env->psr |= PSR_OVF;
568 if (!T0)
569 env->xcc |= PSR_ZERO;
570 if ((int64_t) T0 < 0)
571 env->xcc |= PSR_NEG;
572 if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63))
573 env->xcc |= PSR_OVF;
574 #else
575 if (!T0)
576 env->psr |= PSR_ZERO;
577 if ((int32_t) T0 < 0)
578 env->psr |= PSR_NEG;
579 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
580 env->psr |= PSR_OVF;
581 #endif
582 FORCE_RET();
585 void OPPROTO op_and_T1_T0(void)
587 T0 &= T1;
590 void OPPROTO op_or_T1_T0(void)
592 T0 |= T1;
595 void OPPROTO op_xor_T1_T0(void)
597 T0 ^= T1;
600 void OPPROTO op_andn_T1_T0(void)
602 T0 &= ~T1;
605 void OPPROTO op_orn_T1_T0(void)
607 T0 |= ~T1;
610 void OPPROTO op_xnor_T1_T0(void)
612 T0 ^= ~T1;
615 void OPPROTO op_umul_T1_T0(void)
617 uint64_t res;
618 res = (uint64_t) T0 * (uint64_t) T1;
619 #ifdef TARGET_SPARC64
620 T0 = res;
621 #else
622 T0 = res & 0xffffffff;
623 #endif
624 env->y = res >> 32;
627 void OPPROTO op_smul_T1_T0(void)
629 uint64_t res;
630 res = (int64_t) ((int32_t) T0) * (int64_t) ((int32_t) T1);
631 #ifdef TARGET_SPARC64
632 T0 = res;
633 #else
634 T0 = res & 0xffffffff;
635 #endif
636 env->y = res >> 32;
639 void OPPROTO op_mulscc_T1_T0(void)
641 unsigned int b1, N, V, b2;
642 target_ulong src1;
644 N = FLAG_SET(PSR_NEG);
645 V = FLAG_SET(PSR_OVF);
646 b1 = N ^ V;
647 b2 = T0 & 1;
648 T0 = (b1 << 31) | (T0 >> 1);
649 if (!(env->y & 1))
650 T1 = 0;
651 /* do addition and update flags */
652 src1 = T0;
653 T0 += T1;
654 env->psr = 0;
655 if (!T0)
656 env->psr |= PSR_ZERO;
657 if ((int32_t) T0 < 0)
658 env->psr |= PSR_NEG;
659 if (T0 < src1)
660 env->psr |= PSR_CARRY;
661 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
662 env->psr |= PSR_OVF;
663 env->y = (b2 << 31) | (env->y >> 1);
664 FORCE_RET();
667 void OPPROTO op_udiv_T1_T0(void)
669 uint64_t x0;
670 uint32_t x1;
672 x0 = T0 | ((uint64_t) (env->y) << 32);
673 x1 = T1;
674 x0 = x0 / x1;
675 if (x0 > 0xffffffff) {
676 T0 = 0xffffffff;
677 T1 = 1;
678 } else {
679 T0 = x0;
680 T1 = 0;
682 FORCE_RET();
685 void OPPROTO op_sdiv_T1_T0(void)
687 int64_t x0;
688 int32_t x1;
690 x0 = T0 | ((int64_t) (env->y) << 32);
691 x1 = T1;
692 x0 = x0 / x1;
693 if ((int32_t) x0 != x0) {
694 T0 = x0 < 0? 0x80000000: 0x7fffffff;
695 T1 = 1;
696 } else {
697 T0 = x0;
698 T1 = 0;
700 FORCE_RET();
703 void OPPROTO op_div_cc(void)
705 env->psr = 0;
706 #ifdef TARGET_SPARC64
707 if (!T0)
708 env->psr |= PSR_ZERO;
709 if ((int32_t) T0 < 0)
710 env->psr |= PSR_NEG;
711 if (T1)
712 env->psr |= PSR_OVF;
714 env->xcc = 0;
715 if (!T0)
716 env->xcc |= PSR_ZERO;
717 if ((int64_t) T0 < 0)
718 env->xcc |= PSR_NEG;
719 #else
720 if (!T0)
721 env->psr |= PSR_ZERO;
722 if ((int32_t) T0 < 0)
723 env->psr |= PSR_NEG;
724 if (T1)
725 env->psr |= PSR_OVF;
726 #endif
727 FORCE_RET();
730 #ifdef TARGET_SPARC64
731 void OPPROTO op_mulx_T1_T0(void)
733 T0 *= T1;
734 FORCE_RET();
737 void OPPROTO op_udivx_T1_T0(void)
739 T0 /= T1;
740 FORCE_RET();
743 void OPPROTO op_sdivx_T1_T0(void)
745 if (T0 == INT64_MIN && T1 == -1)
746 T0 = INT64_MIN;
747 else
748 T0 /= (target_long) T1;
749 FORCE_RET();
751 #endif
753 void OPPROTO op_logic_T0_cc(void)
755 env->psr = 0;
756 #ifdef TARGET_SPARC64
757 if (!(T0 & 0xffffffff))
758 env->psr |= PSR_ZERO;
759 if ((int32_t) T0 < 0)
760 env->psr |= PSR_NEG;
762 env->xcc = 0;
763 if (!T0)
764 env->xcc |= PSR_ZERO;
765 if ((int64_t) T0 < 0)
766 env->xcc |= PSR_NEG;
767 #else
768 if (!T0)
769 env->psr |= PSR_ZERO;
770 if ((int32_t) T0 < 0)
771 env->psr |= PSR_NEG;
772 #endif
773 FORCE_RET();
776 void OPPROTO op_sll(void)
778 T0 <<= T1;
781 #ifdef TARGET_SPARC64
782 void OPPROTO op_srl(void)
784 T0 = (T0 & 0xffffffff) >> T1;
787 void OPPROTO op_srlx(void)
789 T0 >>= T1;
792 void OPPROTO op_sra(void)
794 T0 = ((int32_t) (T0 & 0xffffffff)) >> T1;
797 void OPPROTO op_srax(void)
799 T0 = ((int64_t) T0) >> T1;
801 #else
802 void OPPROTO op_srl(void)
804 T0 >>= T1;
807 void OPPROTO op_sra(void)
809 T0 = ((int32_t) T0) >> T1;
811 #endif
813 /* Load and store */
814 #define MEMSUFFIX _raw
815 #include "op_mem.h"
816 #if !defined(CONFIG_USER_ONLY)
817 #define MEMSUFFIX _user
818 #include "op_mem.h"
820 #define MEMSUFFIX _kernel
821 #include "op_mem.h"
822 #endif
824 void OPPROTO op_ldfsr(void)
826 PUT_FSR32(env, *((uint32_t *) &FT0));
827 helper_ldfsr();
830 void OPPROTO op_stfsr(void)
832 *((uint32_t *) &FT0) = GET_FSR32(env);
835 #ifndef TARGET_SPARC64
836 void OPPROTO op_rdpsr(void)
838 do_rdpsr();
841 void OPPROTO op_wrpsr(void)
843 do_wrpsr();
844 FORCE_RET();
847 void OPPROTO op_wrwim(void)
849 #if NWINDOWS == 32
850 env->wim = T0;
851 #else
852 env->wim = T0 & ((1 << NWINDOWS) - 1);
853 #endif
856 void OPPROTO op_rett(void)
858 helper_rett();
859 FORCE_RET();
862 /* XXX: use another pointer for %iN registers to avoid slow wrapping
863 handling ? */
864 void OPPROTO op_save(void)
866 uint32_t cwp;
867 cwp = (env->cwp - 1) & (NWINDOWS - 1);
868 if (env->wim & (1 << cwp)) {
869 raise_exception(TT_WIN_OVF);
871 set_cwp(cwp);
872 FORCE_RET();
875 void OPPROTO op_restore(void)
877 uint32_t cwp;
878 cwp = (env->cwp + 1) & (NWINDOWS - 1);
879 if (env->wim & (1 << cwp)) {
880 raise_exception(TT_WIN_UNF);
882 set_cwp(cwp);
883 FORCE_RET();
885 #else
886 void OPPROTO op_rdccr(void)
888 T0 = GET_CCR(env);
891 void OPPROTO op_wrccr(void)
893 PUT_CCR(env, T0);
896 void OPPROTO op_rdtick(void)
898 T0 = 0; // XXX read cycle counter and bit 31
901 void OPPROTO op_wrtick(void)
903 // XXX write cycle counter and bit 31
906 void OPPROTO op_rdtpc(void)
908 T0 = env->tpc[env->tl];
911 void OPPROTO op_wrtpc(void)
913 env->tpc[env->tl] = T0;
916 void OPPROTO op_rdtnpc(void)
918 T0 = env->tnpc[env->tl];
921 void OPPROTO op_wrtnpc(void)
923 env->tnpc[env->tl] = T0;
926 void OPPROTO op_rdtstate(void)
928 T0 = env->tstate[env->tl];
931 void OPPROTO op_wrtstate(void)
933 env->tstate[env->tl] = T0;
936 void OPPROTO op_rdtt(void)
938 T0 = env->tt[env->tl];
941 void OPPROTO op_wrtt(void)
943 env->tt[env->tl] = T0;
946 void OPPROTO op_rdpstate(void)
948 T0 = env->pstate;
951 void OPPROTO op_wrpstate(void)
953 do_wrpstate();
956 // CWP handling is reversed in V9, but we still use the V8 register
957 // order.
958 void OPPROTO op_rdcwp(void)
960 T0 = NWINDOWS - 1 - env->cwp;
963 void OPPROTO op_wrcwp(void)
965 env->cwp = NWINDOWS - 1 - T0;
968 /* XXX: use another pointer for %iN registers to avoid slow wrapping
969 handling ? */
970 void OPPROTO op_save(void)
972 uint32_t cwp;
973 cwp = (env->cwp - 1) & (NWINDOWS - 1);
974 if (env->cansave == 0) {
975 raise_exception(TT_SPILL | (env->otherwin != 0 ?
976 (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
977 ((env->wstate & 0x7) << 2)));
978 } else {
979 if (env->cleanwin - env->canrestore == 0) {
980 // XXX Clean windows without trap
981 raise_exception(TT_CLRWIN);
982 } else {
983 env->cansave--;
984 env->canrestore++;
985 set_cwp(cwp);
988 FORCE_RET();
991 void OPPROTO op_restore(void)
993 uint32_t cwp;
994 cwp = (env->cwp + 1) & (NWINDOWS - 1);
995 if (env->canrestore == 0) {
996 raise_exception(TT_FILL | (env->otherwin != 0 ?
997 (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
998 ((env->wstate & 0x7) << 2)));
999 } else {
1000 env->cansave++;
1001 env->canrestore--;
1002 set_cwp(cwp);
1004 FORCE_RET();
1006 #endif
1008 void OPPROTO op_exception(void)
1010 env->exception_index = PARAM1;
1011 cpu_loop_exit();
1014 void OPPROTO op_trap_T0(void)
1016 env->exception_index = TT_TRAP + (T0 & 0x7f);
1017 cpu_loop_exit();
1020 void OPPROTO op_trapcc_T0(void)
1022 if (T2) {
1023 env->exception_index = TT_TRAP + (T0 & 0x7f);
1024 cpu_loop_exit();
1026 FORCE_RET();
1029 void OPPROTO op_fpexception_im(void)
1031 env->exception_index = TT_FP_EXCP;
1032 env->fsr &= ~FSR_FTT_MASK;
1033 env->fsr |= PARAM1;
1034 cpu_loop_exit();
1035 FORCE_RET();
1038 void OPPROTO op_debug(void)
1040 helper_debug();
1043 void OPPROTO op_exit_tb(void)
1045 EXIT_TB();
1048 void OPPROTO op_eval_ba(void)
1050 T2 = 1;
1053 void OPPROTO op_eval_be(void)
1055 T2 = FLAG_SET(PSR_ZERO);
1058 void OPPROTO op_eval_ble(void)
1060 target_ulong Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1062 T2 = Z | (N ^ V);
1065 void OPPROTO op_eval_bl(void)
1067 target_ulong N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1069 T2 = N ^ V;
1072 void OPPROTO op_eval_bleu(void)
1074 target_ulong Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
1076 T2 = C | Z;
1079 void OPPROTO op_eval_bcs(void)
1081 T2 = FLAG_SET(PSR_CARRY);
1084 void OPPROTO op_eval_bvs(void)
1086 T2 = FLAG_SET(PSR_OVF);
1089 void OPPROTO op_eval_bn(void)
1091 T2 = 0;
1094 void OPPROTO op_eval_bneg(void)
1096 T2 = FLAG_SET(PSR_NEG);
1099 void OPPROTO op_eval_bne(void)
1101 T2 = !FLAG_SET(PSR_ZERO);
1104 void OPPROTO op_eval_bg(void)
1106 target_ulong Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1108 T2 = !(Z | (N ^ V));
1111 void OPPROTO op_eval_bge(void)
1113 target_ulong N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1115 T2 = !(N ^ V);
1118 void OPPROTO op_eval_bgu(void)
1120 target_ulong Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
1122 T2 = !(C | Z);
1125 void OPPROTO op_eval_bcc(void)
1127 T2 = !FLAG_SET(PSR_CARRY);
1130 void OPPROTO op_eval_bpos(void)
1132 T2 = !FLAG_SET(PSR_NEG);
1135 void OPPROTO op_eval_bvc(void)
1137 T2 = !FLAG_SET(PSR_OVF);
1140 #ifdef TARGET_SPARC64
1141 void OPPROTO op_eval_xbe(void)
1143 T2 = XFLAG_SET(PSR_ZERO);
1146 void OPPROTO op_eval_xble(void)
1148 target_ulong Z = XFLAG_SET(PSR_ZERO), N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1150 T2 = Z | (N ^ V);
1153 void OPPROTO op_eval_xbl(void)
1155 target_ulong N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1157 T2 = N ^ V;
1160 void OPPROTO op_eval_xbleu(void)
1162 target_ulong Z = XFLAG_SET(PSR_ZERO), C = XFLAG_SET(PSR_CARRY);
1164 T2 = C | Z;
1167 void OPPROTO op_eval_xbcs(void)
1169 T2 = XFLAG_SET(PSR_CARRY);
1172 void OPPROTO op_eval_xbvs(void)
1174 T2 = XFLAG_SET(PSR_OVF);
1177 void OPPROTO op_eval_xbneg(void)
1179 T2 = XFLAG_SET(PSR_NEG);
1182 void OPPROTO op_eval_xbne(void)
1184 T2 = !XFLAG_SET(PSR_ZERO);
1187 void OPPROTO op_eval_xbg(void)
1189 target_ulong Z = XFLAG_SET(PSR_ZERO), N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1191 T2 = !(Z | (N ^ V));
1194 void OPPROTO op_eval_xbge(void)
1196 target_ulong N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1198 T2 = !(N ^ V);
1201 void OPPROTO op_eval_xbgu(void)
1203 target_ulong Z = XFLAG_SET(PSR_ZERO), C = XFLAG_SET(PSR_CARRY);
1205 T2 = !(C | Z);
1208 void OPPROTO op_eval_xbcc(void)
1210 T2 = !XFLAG_SET(PSR_CARRY);
1213 void OPPROTO op_eval_xbpos(void)
1215 T2 = !XFLAG_SET(PSR_NEG);
1218 void OPPROTO op_eval_xbvc(void)
1220 T2 = !XFLAG_SET(PSR_OVF);
1222 #endif
1224 #define FCC
1225 #define FFLAG_SET(x) (env->fsr & x? 1: 0)
1226 #include "fbranch_template.h"
1228 #ifdef TARGET_SPARC64
1229 #define FCC _fcc1
1230 #define FFLAG_SET(x) ((env->fsr & ((uint64_t)x >> 32))? 1: 0)
1231 #include "fbranch_template.h"
1232 #define FCC _fcc2
1233 #define FFLAG_SET(x) ((env->fsr & ((uint64_t)x >> 34))? 1: 0)
1234 #include "fbranch_template.h"
1235 #define FCC _fcc3
1236 #define FFLAG_SET(x) ((env->fsr & ((uint64_t)x >> 36))? 1: 0)
1237 #include "fbranch_template.h"
1238 #endif
1240 #ifdef TARGET_SPARC64
1241 void OPPROTO op_eval_brz(void)
1243 T2 = (T0 == 0);
1246 void OPPROTO op_eval_brnz(void)
1248 T2 = (T0 != 0);
1251 void OPPROTO op_eval_brlz(void)
1253 T2 = ((int64_t)T0 < 0);
1256 void OPPROTO op_eval_brlez(void)
1258 T2 = ((int64_t)T0 <= 0);
1261 void OPPROTO op_eval_brgz(void)
1263 T2 = ((int64_t)T0 > 0);
1266 void OPPROTO op_eval_brgez(void)
1268 T2 = ((int64_t)T0 >= 0);
1271 void OPPROTO op_jmp_im64(void)
1273 env->pc = PARAMQ1;
1276 void OPPROTO op_movq_npc_im64(void)
1278 env->npc = PARAMQ1;
1280 #endif
1282 void OPPROTO op_jmp_im(void)
1284 env->pc = (uint32_t)PARAM1;
1287 void OPPROTO op_movl_npc_im(void)
1289 env->npc = (uint32_t)PARAM1;
1292 void OPPROTO op_movl_npc_T0(void)
1294 env->npc = T0;
1297 void OPPROTO op_mov_pc_npc(void)
1299 env->pc = env->npc;
1302 void OPPROTO op_next_insn(void)
1304 env->pc = env->npc;
1305 env->npc = env->npc + 4;
1308 void OPPROTO op_goto_tb0(void)
1310 GOTO_TB(op_goto_tb0, PARAM1, 0);
1313 void OPPROTO op_goto_tb1(void)
1315 GOTO_TB(op_goto_tb1, PARAM1, 1);
1318 void OPPROTO op_jmp_label(void)
1320 GOTO_LABEL_PARAM(1);
1323 void OPPROTO op_jnz_T2_label(void)
1325 if (T2)
1326 GOTO_LABEL_PARAM(1);
1327 FORCE_RET();
1330 void OPPROTO op_jz_T2_label(void)
1332 if (!T2)
1333 GOTO_LABEL_PARAM(1);
1334 FORCE_RET();
1337 void OPPROTO op_flush_T0(void)
1339 helper_flush(T0);
1342 #define F_OP(name, p) void OPPROTO op_f##name##p(void)
1344 #define F_BINOP(name) \
1345 F_OP(name, s) \
1347 FT0 = float32_ ## name (FT0, FT1, &env->fp_status); \
1349 F_OP(name, d) \
1351 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
1354 F_BINOP(add);
1355 F_BINOP(sub);
1356 F_BINOP(mul);
1357 F_BINOP(div);
1358 #undef F_BINOP
1360 void OPPROTO op_fsmuld(void)
1362 DT0 = float64_mul(float32_to_float64(FT0, &env->fp_status),
1363 float32_to_float64(FT1, &env->fp_status),
1364 &env->fp_status);
1367 #define F_HELPER(name) \
1368 F_OP(name, s) \
1370 do_f##name##s(); \
1372 F_OP(name, d) \
1374 do_f##name##d(); \
1377 F_HELPER(sqrt);
1379 F_OP(neg, s)
1381 FT0 = float32_chs(FT1);
1384 F_OP(abs, s)
1386 do_fabss();
1389 F_HELPER(cmp);
1391 #ifdef TARGET_SPARC64
1392 F_OP(neg, d)
1394 DT0 = float64_chs(DT1);
1397 F_OP(abs, d)
1399 do_fabsd();
1402 void OPPROTO op_fcmps_fcc1(void)
1404 do_fcmps_fcc1();
1407 void OPPROTO op_fcmpd_fcc1(void)
1409 do_fcmpd_fcc1();
1412 void OPPROTO op_fcmps_fcc2(void)
1414 do_fcmps_fcc2();
1417 void OPPROTO op_fcmpd_fcc2(void)
1419 do_fcmpd_fcc2();
1422 void OPPROTO op_fcmps_fcc3(void)
1424 do_fcmps_fcc3();
1427 void OPPROTO op_fcmpd_fcc3(void)
1429 do_fcmpd_fcc3();
1431 #endif
1433 /* Integer to float conversion. */
1434 #ifdef USE_INT_TO_FLOAT_HELPERS
1435 F_HELPER(ito);
1436 #else
1437 F_OP(ito, s)
1439 FT0 = int32_to_float32(*((int32_t *)&FT1), &env->fp_status);
1442 F_OP(ito, d)
1444 DT0 = int32_to_float64(*((int32_t *)&FT1), &env->fp_status);
1447 #ifdef TARGET_SPARC64
1448 F_OP(xto, s)
1450 FT0 = int64_to_float32(*((int64_t *)&DT1), &env->fp_status);
1453 F_OP(xto, d)
1455 DT0 = int64_to_float64(*((int64_t *)&DT1), &env->fp_status);
1457 #endif
1458 #endif
1459 #undef F_HELPER
1461 /* floating point conversion */
1462 void OPPROTO op_fdtos(void)
1464 FT0 = float64_to_float32(DT1, &env->fp_status);
1467 void OPPROTO op_fstod(void)
1469 DT0 = float32_to_float64(FT1, &env->fp_status);
1472 /* Float to integer conversion. */
1473 void OPPROTO op_fstoi(void)
1475 *((int32_t *)&FT0) = float32_to_int32(FT1, &env->fp_status);
1478 void OPPROTO op_fdtoi(void)
1480 *((int32_t *)&FT0) = float64_to_int32(DT1, &env->fp_status);
1483 #ifdef TARGET_SPARC64
1484 void OPPROTO op_fstox(void)
1486 *((int64_t *)&DT0) = float32_to_int64(FT1, &env->fp_status);
1489 void OPPROTO op_fdtox(void)
1491 *((int64_t *)&DT0) = float64_to_int64(DT1, &env->fp_status);
1494 void OPPROTO op_fmovs_cc(void)
1496 if (T2)
1497 FT0 = FT1;
1500 void OPPROTO op_fmovd_cc(void)
1502 if (T2)
1503 DT0 = DT1;
1506 void OPPROTO op_mov_cc(void)
1508 if (T2)
1509 T0 = T1;
1512 void OPPROTO op_flushw(void)
1514 if (env->cansave != NWINDOWS - 2) {
1515 raise_exception(TT_SPILL | (env->otherwin != 0 ?
1516 (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
1517 ((env->wstate & 0x7) << 2)));
1521 void OPPROTO op_saved(void)
1523 env->cansave++;
1524 if (env->otherwin == 0)
1525 env->canrestore--;
1526 else
1527 env->otherwin--;
1528 FORCE_RET();
1531 void OPPROTO op_restored(void)
1533 env->canrestore++;
1534 if (env->cleanwin < NWINDOWS - 1)
1535 env->cleanwin++;
1536 if (env->otherwin == 0)
1537 env->cansave--;
1538 else
1539 env->otherwin--;
1540 FORCE_RET();
1543 void OPPROTO op_popc(void)
1545 do_popc();
1548 void OPPROTO op_done(void)
1550 do_done();
1553 void OPPROTO op_retry(void)
1555 do_retry();
1558 void OPPROTO op_sir(void)
1560 // XXX
1564 void OPPROTO op_ld_asi_reg()
1566 T0 += PARAM1;
1567 helper_ld_asi(env->asi, PARAM2, PARAM3);
1570 void OPPROTO op_st_asi_reg()
1572 T0 += PARAM1;
1573 helper_st_asi(env->asi, PARAM2, PARAM3);
1575 #endif
1577 void OPPROTO op_ld_asi()
1579 helper_ld_asi(PARAM1, PARAM2, PARAM3);
1582 void OPPROTO op_st_asi()
1584 helper_st_asi(PARAM1, PARAM2, PARAM3);
1587 #ifdef TARGET_SPARC64
1588 void OPPROTO op_alignaddr()
1590 uint64_t tmp;
1592 tmp = T0 + T1;
1593 env->gsr &= ~7ULL;
1594 env->gsr |= tmp & 7ULL;
1595 T0 = tmp & ~7ULL;
1598 void OPPROTO op_faligndata()
1600 uint64_t tmp;
1602 tmp = (*((uint64_t *)&DT0)) << ((env->gsr & 7) * 8);
1603 tmp |= (*((uint64_t *)&DT1)) >> (64 - (env->gsr & 7) * 8);
1604 (*((uint64_t *)&DT0)) = tmp;
1606 #endif