Fix incorrect return type.
[qemu/mini2440.git] / target-sparc / op.c
blob67de62f4cf83a6e006315d5cbaf25a8473db5d22
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;
419 src1 = T0;
420 T0 += T1 + FLAG_SET(PSR_CARRY);
421 env->psr = 0;
422 #ifdef TARGET_SPARC64
423 if (!(T0 & 0xffffffff))
424 env->psr |= PSR_ZERO;
425 if ((int32_t) T0 < 0)
426 env->psr |= PSR_NEG;
427 if ((T0 & 0xffffffff) < (src1 & 0xffffffff))
428 env->psr |= PSR_CARRY;
429 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff) ^ -1) &
430 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
431 env->psr |= PSR_OVF;
433 env->xcc = 0;
434 if (!T0)
435 env->xcc |= PSR_ZERO;
436 if ((int64_t) T0 < 0)
437 env->xcc |= PSR_NEG;
438 if (T0 < src1)
439 env->xcc |= PSR_CARRY;
440 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1ULL << 63))
441 env->xcc |= PSR_OVF;
442 #else
443 if (!T0)
444 env->psr |= PSR_ZERO;
445 if ((int32_t) T0 < 0)
446 env->psr |= PSR_NEG;
447 if (T0 < src1)
448 env->psr |= PSR_CARRY;
449 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
450 env->psr |= PSR_OVF;
451 #endif
452 FORCE_RET();
455 void OPPROTO op_sub_T1_T0(void)
457 T0 -= T1;
460 void OPPROTO op_sub_T1_T0_cc(void)
462 target_ulong src1;
464 src1 = T0;
465 T0 -= T1;
466 env->psr = 0;
467 #ifdef TARGET_SPARC64
468 if (!(T0 & 0xffffffff))
469 env->psr |= PSR_ZERO;
470 if ((int32_t) T0 < 0)
471 env->psr |= PSR_NEG;
472 if ((src1 & 0xffffffff) < (T1 & 0xffffffff))
473 env->psr |= PSR_CARRY;
474 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) &
475 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
476 env->psr |= PSR_OVF;
478 env->xcc = 0;
479 if (!T0)
480 env->xcc |= PSR_ZERO;
481 if ((int64_t) T0 < 0)
482 env->xcc |= PSR_NEG;
483 if (src1 < T1)
484 env->xcc |= PSR_CARRY;
485 if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63))
486 env->xcc |= PSR_OVF;
487 #else
488 if (!T0)
489 env->psr |= PSR_ZERO;
490 if ((int32_t) T0 < 0)
491 env->psr |= PSR_NEG;
492 if (src1 < T1)
493 env->psr |= PSR_CARRY;
494 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
495 env->psr |= PSR_OVF;
496 #endif
497 FORCE_RET();
500 void OPPROTO op_subx_T1_T0(void)
502 T0 -= T1 + FLAG_SET(PSR_CARRY);
505 void OPPROTO op_subx_T1_T0_cc(void)
507 target_ulong src1;
509 src1 = T0;
510 T0 -= T1 + FLAG_SET(PSR_CARRY);
511 env->psr = 0;
512 #ifdef TARGET_SPARC64
513 if (!(T0 & 0xffffffff))
514 env->psr |= PSR_ZERO;
515 if ((int32_t) T0 < 0)
516 env->psr |= PSR_NEG;
517 if ((src1 & 0xffffffff) < (T1 & 0xffffffff))
518 env->psr |= PSR_CARRY;
519 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) &
520 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
521 env->psr |= PSR_OVF;
523 env->xcc = 0;
524 if (!T0)
525 env->xcc |= PSR_ZERO;
526 if ((int64_t) T0 < 0)
527 env->xcc |= PSR_NEG;
528 if (src1 < T1)
529 env->xcc |= PSR_CARRY;
530 if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63))
531 env->xcc |= PSR_OVF;
532 #else
533 if (!T0)
534 env->psr |= PSR_ZERO;
535 if ((int32_t) T0 < 0)
536 env->psr |= PSR_NEG;
537 if (src1 < T1)
538 env->psr |= PSR_CARRY;
539 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
540 env->psr |= PSR_OVF;
541 #endif
542 FORCE_RET();
545 void OPPROTO op_and_T1_T0(void)
547 T0 &= T1;
550 void OPPROTO op_or_T1_T0(void)
552 T0 |= T1;
555 void OPPROTO op_xor_T1_T0(void)
557 T0 ^= T1;
560 void OPPROTO op_andn_T1_T0(void)
562 T0 &= ~T1;
565 void OPPROTO op_orn_T1_T0(void)
567 T0 |= ~T1;
570 void OPPROTO op_xnor_T1_T0(void)
572 T0 ^= ~T1;
575 void OPPROTO op_umul_T1_T0(void)
577 uint64_t res;
578 res = (uint64_t) T0 * (uint64_t) T1;
579 #ifdef TARGET_SPARC64
580 T0 = res;
581 #else
582 T0 = res & 0xffffffff;
583 #endif
584 env->y = res >> 32;
587 void OPPROTO op_smul_T1_T0(void)
589 uint64_t res;
590 res = (int64_t) ((int32_t) T0) * (int64_t) ((int32_t) T1);
591 #ifdef TARGET_SPARC64
592 T0 = res;
593 #else
594 T0 = res & 0xffffffff;
595 #endif
596 env->y = res >> 32;
599 void OPPROTO op_mulscc_T1_T0(void)
601 unsigned int b1, N, V, b2;
602 target_ulong src1;
604 N = FLAG_SET(PSR_NEG);
605 V = FLAG_SET(PSR_OVF);
606 b1 = N ^ V;
607 b2 = T0 & 1;
608 T0 = (b1 << 31) | (T0 >> 1);
609 if (!(env->y & 1))
610 T1 = 0;
611 /* do addition and update flags */
612 src1 = T0;
613 T0 += T1;
614 env->psr = 0;
615 if (!T0)
616 env->psr |= PSR_ZERO;
617 if ((int32_t) T0 < 0)
618 env->psr |= PSR_NEG;
619 if (T0 < src1)
620 env->psr |= PSR_CARRY;
621 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
622 env->psr |= PSR_OVF;
623 env->y = (b2 << 31) | (env->y >> 1);
624 FORCE_RET();
627 void OPPROTO op_udiv_T1_T0(void)
629 uint64_t x0;
630 uint32_t x1;
632 x0 = T0 | ((uint64_t) (env->y) << 32);
633 x1 = T1;
634 x0 = x0 / x1;
635 if (x0 > 0xffffffff) {
636 T0 = 0xffffffff;
637 T1 = 1;
638 } else {
639 T0 = x0;
640 T1 = 0;
642 FORCE_RET();
645 void OPPROTO op_sdiv_T1_T0(void)
647 int64_t x0;
648 int32_t x1;
650 x0 = T0 | ((int64_t) (env->y) << 32);
651 x1 = T1;
652 x0 = x0 / x1;
653 if ((int32_t) x0 != x0) {
654 T0 = x0 < 0? 0x80000000: 0x7fffffff;
655 T1 = 1;
656 } else {
657 T0 = x0;
658 T1 = 0;
660 FORCE_RET();
663 void OPPROTO op_div_cc(void)
665 env->psr = 0;
666 #ifdef TARGET_SPARC64
667 if (!T0)
668 env->psr |= PSR_ZERO;
669 if ((int32_t) T0 < 0)
670 env->psr |= PSR_NEG;
671 if (T1)
672 env->psr |= PSR_OVF;
674 env->xcc = 0;
675 if (!T0)
676 env->xcc |= PSR_ZERO;
677 if ((int64_t) T0 < 0)
678 env->xcc |= PSR_NEG;
679 #else
680 if (!T0)
681 env->psr |= PSR_ZERO;
682 if ((int32_t) T0 < 0)
683 env->psr |= PSR_NEG;
684 if (T1)
685 env->psr |= PSR_OVF;
686 #endif
687 FORCE_RET();
690 #ifdef TARGET_SPARC64
691 void OPPROTO op_mulx_T1_T0(void)
693 T0 *= T1;
694 FORCE_RET();
697 void OPPROTO op_udivx_T1_T0(void)
699 T0 /= T1;
700 FORCE_RET();
703 void OPPROTO op_sdivx_T1_T0(void)
705 if (T0 == INT64_MIN && T1 == -1)
706 T0 = INT64_MIN;
707 else
708 T0 /= (target_long) T1;
709 FORCE_RET();
711 #endif
713 void OPPROTO op_logic_T0_cc(void)
715 env->psr = 0;
716 #ifdef TARGET_SPARC64
717 if (!(T0 & 0xffffffff))
718 env->psr |= PSR_ZERO;
719 if ((int32_t) T0 < 0)
720 env->psr |= PSR_NEG;
722 env->xcc = 0;
723 if (!T0)
724 env->xcc |= PSR_ZERO;
725 if ((int64_t) T0 < 0)
726 env->xcc |= PSR_NEG;
727 #else
728 if (!T0)
729 env->psr |= PSR_ZERO;
730 if ((int32_t) T0 < 0)
731 env->psr |= PSR_NEG;
732 #endif
733 FORCE_RET();
736 void OPPROTO op_sll(void)
738 T0 <<= T1;
741 #ifdef TARGET_SPARC64
742 void OPPROTO op_srl(void)
744 T0 = (T0 & 0xffffffff) >> T1;
747 void OPPROTO op_srlx(void)
749 T0 >>= T1;
752 void OPPROTO op_sra(void)
754 T0 = ((int32_t) (T0 & 0xffffffff)) >> T1;
757 void OPPROTO op_srax(void)
759 T0 = ((int64_t) T0) >> T1;
761 #else
762 void OPPROTO op_srl(void)
764 T0 >>= T1;
767 void OPPROTO op_sra(void)
769 T0 = ((int32_t) T0) >> T1;
771 #endif
773 /* Load and store */
774 #define MEMSUFFIX _raw
775 #include "op_mem.h"
776 #if !defined(CONFIG_USER_ONLY)
777 #define MEMSUFFIX _user
778 #include "op_mem.h"
780 #define MEMSUFFIX _kernel
781 #include "op_mem.h"
782 #endif
784 void OPPROTO op_ldfsr(void)
786 PUT_FSR32(env, *((uint32_t *) &FT0));
787 helper_ldfsr();
790 void OPPROTO op_stfsr(void)
792 *((uint32_t *) &FT0) = GET_FSR32(env);
795 #ifndef TARGET_SPARC64
796 void OPPROTO op_rdpsr(void)
798 do_rdpsr();
801 void OPPROTO op_wrpsr(void)
803 do_wrpsr();
804 FORCE_RET();
807 void OPPROTO op_rett(void)
809 helper_rett();
810 FORCE_RET();
813 /* XXX: use another pointer for %iN registers to avoid slow wrapping
814 handling ? */
815 void OPPROTO op_save(void)
817 uint32_t cwp;
818 cwp = (env->cwp - 1) & (NWINDOWS - 1);
819 if (env->wim & (1 << cwp)) {
820 raise_exception(TT_WIN_OVF);
822 set_cwp(cwp);
823 FORCE_RET();
826 void OPPROTO op_restore(void)
828 uint32_t cwp;
829 cwp = (env->cwp + 1) & (NWINDOWS - 1);
830 if (env->wim & (1 << cwp)) {
831 raise_exception(TT_WIN_UNF);
833 set_cwp(cwp);
834 FORCE_RET();
836 #else
837 void OPPROTO op_rdccr(void)
839 T0 = GET_CCR(env);
842 void OPPROTO op_wrccr(void)
844 PUT_CCR(env, T0);
847 void OPPROTO op_rdtick(void)
849 T0 = 0; // XXX read cycle counter and bit 31
852 void OPPROTO op_wrtick(void)
854 // XXX write cycle counter and bit 31
857 void OPPROTO op_rdtpc(void)
859 T0 = env->tpc[env->tl];
862 void OPPROTO op_wrtpc(void)
864 env->tpc[env->tl] = T0;
867 void OPPROTO op_rdtnpc(void)
869 T0 = env->tnpc[env->tl];
872 void OPPROTO op_wrtnpc(void)
874 env->tnpc[env->tl] = T0;
877 void OPPROTO op_rdtstate(void)
879 T0 = env->tstate[env->tl];
882 void OPPROTO op_wrtstate(void)
884 env->tstate[env->tl] = T0;
887 void OPPROTO op_rdtt(void)
889 T0 = env->tt[env->tl];
892 void OPPROTO op_wrtt(void)
894 env->tt[env->tl] = T0;
897 void OPPROTO op_rdpstate(void)
899 T0 = env->pstate;
902 void OPPROTO op_wrpstate(void)
904 do_wrpstate();
907 // CWP handling is reversed in V9, but we still use the V8 register
908 // order.
909 void OPPROTO op_rdcwp(void)
911 T0 = NWINDOWS - 1 - env->cwp;
914 void OPPROTO op_wrcwp(void)
916 env->cwp = NWINDOWS - 1 - T0;
919 /* XXX: use another pointer for %iN registers to avoid slow wrapping
920 handling ? */
921 void OPPROTO op_save(void)
923 uint32_t cwp;
924 cwp = (env->cwp - 1) & (NWINDOWS - 1);
925 if (env->cansave == 0) {
926 raise_exception(TT_SPILL | (env->otherwin != 0 ?
927 (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
928 ((env->wstate & 0x7) << 2)));
929 } else {
930 if (env->cleanwin - env->canrestore == 0) {
931 // XXX Clean windows without trap
932 raise_exception(TT_CLRWIN);
933 } else {
934 env->cansave--;
935 env->canrestore++;
936 set_cwp(cwp);
939 FORCE_RET();
942 void OPPROTO op_restore(void)
944 uint32_t cwp;
945 cwp = (env->cwp + 1) & (NWINDOWS - 1);
946 if (env->canrestore == 0) {
947 raise_exception(TT_FILL | (env->otherwin != 0 ?
948 (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
949 ((env->wstate & 0x7) << 2)));
950 } else {
951 env->cansave++;
952 env->canrestore--;
953 set_cwp(cwp);
955 FORCE_RET();
957 #endif
959 void OPPROTO op_exception(void)
961 env->exception_index = PARAM1;
962 cpu_loop_exit();
965 void OPPROTO op_trap_T0(void)
967 env->exception_index = TT_TRAP + (T0 & 0x7f);
968 cpu_loop_exit();
971 void OPPROTO op_trapcc_T0(void)
973 if (T2) {
974 env->exception_index = TT_TRAP + (T0 & 0x7f);
975 cpu_loop_exit();
977 FORCE_RET();
980 void OPPROTO op_trap_ifnofpu(void)
982 if (!env->psref) {
983 env->exception_index = TT_NFPU_INSN;
984 cpu_loop_exit();
986 FORCE_RET();
989 void OPPROTO op_fpexception_im(void)
991 env->exception_index = TT_FP_EXCP;
992 env->fsr &= ~FSR_FTT_MASK;
993 env->fsr |= PARAM1;
994 cpu_loop_exit();
995 FORCE_RET();
998 void OPPROTO op_debug(void)
1000 helper_debug();
1003 void OPPROTO op_exit_tb(void)
1005 EXIT_TB();
1008 void OPPROTO op_eval_ba(void)
1010 T2 = 1;
1013 void OPPROTO op_eval_be(void)
1015 T2 = FLAG_SET(PSR_ZERO);
1018 void OPPROTO op_eval_ble(void)
1020 target_ulong Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1022 T2 = Z | (N ^ V);
1025 void OPPROTO op_eval_bl(void)
1027 target_ulong N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1029 T2 = N ^ V;
1032 void OPPROTO op_eval_bleu(void)
1034 target_ulong Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
1036 T2 = C | Z;
1039 void OPPROTO op_eval_bcs(void)
1041 T2 = FLAG_SET(PSR_CARRY);
1044 void OPPROTO op_eval_bvs(void)
1046 T2 = FLAG_SET(PSR_OVF);
1049 void OPPROTO op_eval_bn(void)
1051 T2 = 0;
1054 void OPPROTO op_eval_bneg(void)
1056 T2 = FLAG_SET(PSR_NEG);
1059 void OPPROTO op_eval_bne(void)
1061 T2 = !FLAG_SET(PSR_ZERO);
1064 void OPPROTO op_eval_bg(void)
1066 target_ulong Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1068 T2 = !(Z | (N ^ V));
1071 void OPPROTO op_eval_bge(void)
1073 target_ulong N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1075 T2 = !(N ^ V);
1078 void OPPROTO op_eval_bgu(void)
1080 target_ulong Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
1082 T2 = !(C | Z);
1085 void OPPROTO op_eval_bcc(void)
1087 T2 = !FLAG_SET(PSR_CARRY);
1090 void OPPROTO op_eval_bpos(void)
1092 T2 = !FLAG_SET(PSR_NEG);
1095 void OPPROTO op_eval_bvc(void)
1097 T2 = !FLAG_SET(PSR_OVF);
1100 #ifdef TARGET_SPARC64
1101 void OPPROTO op_eval_xbe(void)
1103 T2 = XFLAG_SET(PSR_ZERO);
1106 void OPPROTO op_eval_xble(void)
1108 target_ulong Z = XFLAG_SET(PSR_ZERO), N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1110 T2 = Z | (N ^ V);
1113 void OPPROTO op_eval_xbl(void)
1115 target_ulong N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1117 T2 = N ^ V;
1120 void OPPROTO op_eval_xbleu(void)
1122 target_ulong Z = XFLAG_SET(PSR_ZERO), C = XFLAG_SET(PSR_CARRY);
1124 T2 = C | Z;
1127 void OPPROTO op_eval_xbcs(void)
1129 T2 = XFLAG_SET(PSR_CARRY);
1132 void OPPROTO op_eval_xbvs(void)
1134 T2 = XFLAG_SET(PSR_OVF);
1137 void OPPROTO op_eval_xbneg(void)
1139 T2 = XFLAG_SET(PSR_NEG);
1142 void OPPROTO op_eval_xbne(void)
1144 T2 = !XFLAG_SET(PSR_ZERO);
1147 void OPPROTO op_eval_xbg(void)
1149 target_ulong Z = XFLAG_SET(PSR_ZERO), N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1151 T2 = !(Z | (N ^ V));
1154 void OPPROTO op_eval_xbge(void)
1156 target_ulong N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1158 T2 = !(N ^ V);
1161 void OPPROTO op_eval_xbgu(void)
1163 target_ulong Z = XFLAG_SET(PSR_ZERO), C = XFLAG_SET(PSR_CARRY);
1165 T2 = !(C | Z);
1168 void OPPROTO op_eval_xbcc(void)
1170 T2 = !XFLAG_SET(PSR_CARRY);
1173 void OPPROTO op_eval_xbpos(void)
1175 T2 = !XFLAG_SET(PSR_NEG);
1178 void OPPROTO op_eval_xbvc(void)
1180 T2 = !XFLAG_SET(PSR_OVF);
1182 #endif
1184 #define FCC
1185 #define FFLAG_SET(x) (env->fsr & x? 1: 0)
1186 #include "fbranch_template.h"
1188 #ifdef TARGET_SPARC64
1189 #define FCC _fcc1
1190 #define FFLAG_SET(x) ((env->fsr & ((uint64_t)x >> 32))? 1: 0)
1191 #include "fbranch_template.h"
1192 #define FCC _fcc2
1193 #define FFLAG_SET(x) ((env->fsr & ((uint64_t)x >> 34))? 1: 0)
1194 #include "fbranch_template.h"
1195 #define FCC _fcc3
1196 #define FFLAG_SET(x) ((env->fsr & ((uint64_t)x >> 36))? 1: 0)
1197 #include "fbranch_template.h"
1198 #endif
1200 #ifdef TARGET_SPARC64
1201 void OPPROTO op_eval_brz(void)
1203 T2 = (T0 == 0);
1206 void OPPROTO op_eval_brnz(void)
1208 T2 = (T0 != 0);
1211 void OPPROTO op_eval_brlz(void)
1213 T2 = ((int64_t)T0 < 0);
1216 void OPPROTO op_eval_brlez(void)
1218 T2 = ((int64_t)T0 <= 0);
1221 void OPPROTO op_eval_brgz(void)
1223 T2 = ((int64_t)T0 > 0);
1226 void OPPROTO op_eval_brgez(void)
1228 T2 = ((int64_t)T0 >= 0);
1231 void OPPROTO op_jmp_im64(void)
1233 env->pc = PARAMQ1;
1236 void OPPROTO op_movq_npc_im64(void)
1238 env->npc = PARAMQ1;
1240 #endif
1242 void OPPROTO op_jmp_im(void)
1244 env->pc = (uint32_t)PARAM1;
1247 void OPPROTO op_movl_npc_im(void)
1249 env->npc = (uint32_t)PARAM1;
1252 void OPPROTO op_movl_npc_T0(void)
1254 env->npc = T0;
1257 void OPPROTO op_mov_pc_npc(void)
1259 env->pc = env->npc;
1262 void OPPROTO op_next_insn(void)
1264 env->pc = env->npc;
1265 env->npc = env->npc + 4;
1268 void OPPROTO op_goto_tb0(void)
1270 GOTO_TB(op_goto_tb0, PARAM1, 0);
1273 void OPPROTO op_goto_tb1(void)
1275 GOTO_TB(op_goto_tb1, PARAM1, 1);
1278 void OPPROTO op_jmp_label(void)
1280 GOTO_LABEL_PARAM(1);
1283 void OPPROTO op_jnz_T2_label(void)
1285 if (T2)
1286 GOTO_LABEL_PARAM(1);
1287 FORCE_RET();
1290 void OPPROTO op_jz_T2_label(void)
1292 if (!T2)
1293 GOTO_LABEL_PARAM(1);
1294 FORCE_RET();
1297 void OPPROTO op_flush_T0(void)
1299 helper_flush(T0);
1302 void OPPROTO op_fnegs(void)
1304 FT0 = -FT1;
1307 void OPPROTO op_fabss(void)
1309 do_fabss();
1312 #ifdef TARGET_SPARC64
1313 void OPPROTO op_fnegd(void)
1315 DT0 = -DT1;
1318 void OPPROTO op_fabsd(void)
1320 do_fabsd();
1322 #endif
1324 void OPPROTO op_fsqrts(void)
1326 do_fsqrts();
1329 void OPPROTO op_fsqrtd(void)
1331 do_fsqrtd();
1334 void OPPROTO op_fmuls(void)
1336 FT0 *= FT1;
1339 void OPPROTO op_fmuld(void)
1341 DT0 *= DT1;
1344 void OPPROTO op_fsmuld(void)
1346 DT0 = FT0 * FT1;
1349 void OPPROTO op_fadds(void)
1351 FT0 += FT1;
1354 void OPPROTO op_faddd(void)
1356 DT0 += DT1;
1359 void OPPROTO op_fsubs(void)
1361 FT0 -= FT1;
1364 void OPPROTO op_fsubd(void)
1366 DT0 -= DT1;
1369 void OPPROTO op_fdivs(void)
1371 FT0 /= FT1;
1374 void OPPROTO op_fdivd(void)
1376 DT0 /= DT1;
1379 void OPPROTO op_fcmps(void)
1381 do_fcmps();
1384 void OPPROTO op_fcmpd(void)
1386 do_fcmpd();
1389 #ifdef TARGET_SPARC64
1390 void OPPROTO op_fcmps_fcc1(void)
1392 do_fcmps_fcc1();
1395 void OPPROTO op_fcmpd_fcc1(void)
1397 do_fcmpd_fcc1();
1400 void OPPROTO op_fcmps_fcc2(void)
1402 do_fcmps_fcc2();
1405 void OPPROTO op_fcmpd_fcc2(void)
1407 do_fcmpd_fcc2();
1410 void OPPROTO op_fcmps_fcc3(void)
1412 do_fcmps_fcc3();
1415 void OPPROTO op_fcmpd_fcc3(void)
1417 do_fcmpd_fcc3();
1419 #endif
1421 #ifdef USE_INT_TO_FLOAT_HELPERS
1422 void OPPROTO op_fitos(void)
1424 do_fitos();
1427 void OPPROTO op_fitod(void)
1429 do_fitod();
1431 #else
1432 void OPPROTO op_fitos(void)
1434 FT0 = (float) *((int32_t *)&FT1);
1437 void OPPROTO op_fitod(void)
1439 DT0 = (double) *((int32_t *)&FT1);
1442 #ifdef TARGET_SPARC64
1443 void OPPROTO op_fxtos(void)
1445 FT0 = (float) *((int64_t *)&DT1);
1448 void OPPROTO op_fxtod(void)
1450 DT0 = (double) *((int64_t *)&DT1);
1452 #endif
1453 #endif
1455 void OPPROTO op_fdtos(void)
1457 FT0 = (float) DT1;
1460 void OPPROTO op_fstod(void)
1462 DT0 = (double) FT1;
1465 void OPPROTO op_fstoi(void)
1467 *((int32_t *)&FT0) = (int32_t) FT1;
1470 void OPPROTO op_fdtoi(void)
1472 *((int32_t *)&FT0) = (int32_t) DT1;
1475 #ifdef TARGET_SPARC64
1476 void OPPROTO op_fstox(void)
1478 *((int64_t *)&DT0) = (int64_t) FT1;
1481 void OPPROTO op_fdtox(void)
1483 *((int64_t *)&DT0) = (int64_t) DT1;
1486 void OPPROTO op_fmovs_cc(void)
1488 if (T2)
1489 FT0 = FT1;
1492 void OPPROTO op_fmovd_cc(void)
1494 if (T2)
1495 DT0 = DT1;
1498 void OPPROTO op_mov_cc(void)
1500 if (T2)
1501 T0 = T1;
1504 void OPPROTO op_flushw(void)
1506 if (env->cansave != NWINDOWS - 2) {
1507 raise_exception(TT_SPILL | (env->otherwin != 0 ?
1508 (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
1509 ((env->wstate & 0x7) << 2)));
1513 void OPPROTO op_saved(void)
1515 env->cansave++;
1516 if (env->otherwin == 0)
1517 env->canrestore--;
1520 void OPPROTO op_restored(void)
1522 env->canrestore++;
1523 if (env->cleanwin < NWINDOWS - 1)
1524 env->cleanwin++;
1525 if (env->otherwin == 0)
1526 env->cansave--;
1527 else
1528 env->otherwin--;
1531 void OPPROTO op_popc(void)
1533 do_popc();
1536 void OPPROTO op_done(void)
1538 do_done();
1541 void OPPROTO op_retry(void)
1543 do_retry();
1546 void OPPROTO op_sir(void)
1548 // XXX
1552 void OPPROTO op_ld_asi_reg()
1554 T0 += PARAM1;
1555 helper_ld_asi(env->asi, PARAM2, PARAM3);
1558 void OPPROTO op_st_asi_reg()
1560 T0 += PARAM1;
1561 helper_st_asi(env->asi, PARAM2, PARAM3);
1563 #endif
1565 void OPPROTO op_ld_asi()
1567 helper_ld_asi(PARAM1, PARAM2, PARAM3);
1570 void OPPROTO op_st_asi()
1572 helper_st_asi(PARAM1, PARAM2, PARAM3);