2 * Copyright (c) 2012-2014 Bastian Koppelmann C-Lab/University Paderborn
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/host-utils.h"
20 #include "exec/helper-proto.h"
21 #include "exec/cpu_ldst.h"
23 /* Addressing mode helper */
25 static uint16_t reverse16(uint16_t val
)
27 uint8_t high
= (uint8_t)(val
>> 8);
28 uint8_t low
= (uint8_t)(val
& 0xff);
32 rl
= (uint16_t)((high
* 0x0202020202ULL
& 0x010884422010ULL
) % 1023);
33 rh
= (uint16_t)((low
* 0x0202020202ULL
& 0x010884422010ULL
) % 1023);
35 return (rh
<< 8) | rl
;
38 uint32_t helper_br_update(uint32_t reg
)
40 uint32_t index
= reg
& 0xffff;
41 uint32_t incr
= reg
>> 16;
42 uint32_t new_index
= reverse16(reverse16(index
) + reverse16(incr
));
43 return reg
- index
+ new_index
;
46 uint32_t helper_circ_update(uint32_t reg
, uint32_t off
)
48 uint32_t index
= reg
& 0xffff;
49 uint32_t length
= reg
>> 16;
50 int32_t new_index
= index
+ off
;
56 return reg
- index
+ new_index
;
59 static uint32_t ssov32(CPUTriCoreState
*env
, int64_t arg
)
62 int64_t max_pos
= INT32_MAX
;
63 int64_t max_neg
= INT32_MIN
;
65 env
->PSW_USB_V
= (1 << 31);
66 env
->PSW_USB_SV
= (1 << 31);
67 ret
= (target_ulong
)max_pos
;
70 env
->PSW_USB_V
= (1 << 31);
71 env
->PSW_USB_SV
= (1 << 31);
72 ret
= (target_ulong
)max_neg
;
75 ret
= (target_ulong
)arg
;
78 env
->PSW_USB_AV
= arg
^ arg
* 2u;
79 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
83 static uint32_t suov32_pos(CPUTriCoreState
*env
, uint64_t arg
)
86 uint64_t max_pos
= UINT32_MAX
;
88 env
->PSW_USB_V
= (1 << 31);
89 env
->PSW_USB_SV
= (1 << 31);
90 ret
= (target_ulong
)max_pos
;
93 ret
= (target_ulong
)arg
;
95 env
->PSW_USB_AV
= arg
^ arg
* 2u;
96 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
100 static uint32_t suov32_neg(CPUTriCoreState
*env
, int64_t arg
)
105 env
->PSW_USB_V
= (1 << 31);
106 env
->PSW_USB_SV
= (1 << 31);
110 ret
= (target_ulong
)arg
;
112 env
->PSW_USB_AV
= arg
^ arg
* 2u;
113 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
117 static uint32_t ssov16(CPUTriCoreState
*env
, int32_t hw0
, int32_t hw1
)
119 int32_t max_pos
= INT16_MAX
;
120 int32_t max_neg
= INT16_MIN
;
124 av0
= hw0
^ hw0
* 2u;
126 env
->PSW_USB_V
= (1 << 31);
128 } else if (hw0
< max_neg
) {
129 env
->PSW_USB_V
= (1 << 31);
133 av1
= hw1
^ hw1
* 2u;
135 env
->PSW_USB_V
= (1 << 31);
137 } else if (hw1
< max_neg
) {
138 env
->PSW_USB_V
= (1 << 31);
142 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
143 env
->PSW_USB_AV
= (av0
| av1
) << 16;
144 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
145 return (hw0
& 0xffff) | (hw1
<< 16);
148 static uint32_t suov16(CPUTriCoreState
*env
, int32_t hw0
, int32_t hw1
)
150 int32_t max_pos
= UINT16_MAX
;
154 av0
= hw0
^ hw0
* 2u;
156 env
->PSW_USB_V
= (1 << 31);
158 } else if (hw0
< 0) {
159 env
->PSW_USB_V
= (1 << 31);
163 av1
= hw1
^ hw1
* 2u;
165 env
->PSW_USB_V
= (1 << 31);
167 } else if (hw1
< 0) {
168 env
->PSW_USB_V
= (1 << 31);
172 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
173 env
->PSW_USB_AV
= (av0
| av1
) << 16;
174 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
175 return (hw0
& 0xffff) | (hw1
<< 16);
178 target_ulong
helper_add_ssov(CPUTriCoreState
*env
, target_ulong r1
,
181 int64_t t1
= sextract64(r1
, 0, 32);
182 int64_t t2
= sextract64(r2
, 0, 32);
183 int64_t result
= t1
+ t2
;
184 return ssov32(env
, result
);
187 target_ulong
helper_add_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
190 int32_t ret_hw0
, ret_hw1
;
192 ret_hw0
= sextract32(r1
, 0, 16) + sextract32(r2
, 0, 16);
193 ret_hw1
= sextract32(r1
, 16, 16) + sextract32(r2
, 16, 16);
194 return ssov16(env
, ret_hw0
, ret_hw1
);
197 target_ulong
helper_add_suov(CPUTriCoreState
*env
, target_ulong r1
,
200 int64_t t1
= extract64(r1
, 0, 32);
201 int64_t t2
= extract64(r2
, 0, 32);
202 int64_t result
= t1
+ t2
;
203 return suov32_pos(env
, result
);
206 target_ulong
helper_add_h_suov(CPUTriCoreState
*env
, target_ulong r1
,
209 int32_t ret_hw0
, ret_hw1
;
211 ret_hw0
= extract32(r1
, 0, 16) + extract32(r2
, 0, 16);
212 ret_hw1
= extract32(r1
, 16, 16) + extract32(r2
, 16, 16);
213 return suov16(env
, ret_hw0
, ret_hw1
);
216 target_ulong
helper_sub_ssov(CPUTriCoreState
*env
, target_ulong r1
,
219 int64_t t1
= sextract64(r1
, 0, 32);
220 int64_t t2
= sextract64(r2
, 0, 32);
221 int64_t result
= t1
- t2
;
222 return ssov32(env
, result
);
225 target_ulong
helper_sub_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
228 int32_t ret_hw0
, ret_hw1
;
230 ret_hw0
= sextract32(r1
, 0, 16) - sextract32(r2
, 0, 16);
231 ret_hw1
= sextract32(r1
, 16, 16) - sextract32(r2
, 16, 16);
232 return ssov16(env
, ret_hw0
, ret_hw1
);
235 target_ulong
helper_sub_suov(CPUTriCoreState
*env
, target_ulong r1
,
238 int64_t t1
= extract64(r1
, 0, 32);
239 int64_t t2
= extract64(r2
, 0, 32);
240 int64_t result
= t1
- t2
;
241 return suov32_neg(env
, result
);
244 target_ulong
helper_sub_h_suov(CPUTriCoreState
*env
, target_ulong r1
,
247 int32_t ret_hw0
, ret_hw1
;
249 ret_hw0
= extract32(r1
, 0, 16) - extract32(r2
, 0, 16);
250 ret_hw1
= extract32(r1
, 16, 16) - extract32(r2
, 16, 16);
251 return suov16(env
, ret_hw0
, ret_hw1
);
254 target_ulong
helper_mul_ssov(CPUTriCoreState
*env
, target_ulong r1
,
257 int64_t t1
= sextract64(r1
, 0, 32);
258 int64_t t2
= sextract64(r2
, 0, 32);
259 int64_t result
= t1
* t2
;
260 return ssov32(env
, result
);
263 target_ulong
helper_mul_suov(CPUTriCoreState
*env
, target_ulong r1
,
266 int64_t t1
= extract64(r1
, 0, 32);
267 int64_t t2
= extract64(r2
, 0, 32);
268 int64_t result
= t1
* t2
;
270 return suov32_pos(env
, result
);
273 target_ulong
helper_sha_ssov(CPUTriCoreState
*env
, target_ulong r1
,
276 int64_t t1
= sextract64(r1
, 0, 32);
277 int32_t t2
= sextract64(r2
, 0, 6);
286 return ssov32(env
, result
);
289 uint32_t helper_abs_ssov(CPUTriCoreState
*env
, target_ulong r1
)
292 result
= ((int32_t)r1
>= 0) ? r1
: (0 - r1
);
293 return ssov32(env
, result
);
296 uint32_t helper_abs_h_ssov(CPUTriCoreState
*env
, target_ulong r1
)
298 int32_t ret_h0
, ret_h1
;
300 ret_h0
= sextract32(r1
, 0, 16);
301 ret_h0
= (ret_h0
>= 0) ? ret_h0
: (0 - ret_h0
);
303 ret_h1
= sextract32(r1
, 16, 16);
304 ret_h1
= (ret_h1
>= 0) ? ret_h1
: (0 - ret_h1
);
306 return ssov16(env
, ret_h0
, ret_h1
);
309 target_ulong
helper_absdif_ssov(CPUTriCoreState
*env
, target_ulong r1
,
312 int64_t t1
= sextract64(r1
, 0, 32);
313 int64_t t2
= sextract64(r2
, 0, 32);
321 return ssov32(env
, result
);
324 uint32_t helper_absdif_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
328 int32_t ret_h0
, ret_h1
;
330 t1
= sextract32(r1
, 0, 16);
331 t2
= sextract32(r2
, 0, 16);
338 t1
= sextract32(r1
, 16, 16);
339 t2
= sextract32(r2
, 16, 16);
346 return ssov16(env
, ret_h0
, ret_h1
);
349 target_ulong
helper_madd32_ssov(CPUTriCoreState
*env
, target_ulong r1
,
350 target_ulong r2
, target_ulong r3
)
352 int64_t t1
= sextract64(r1
, 0, 32);
353 int64_t t2
= sextract64(r2
, 0, 32);
354 int64_t t3
= sextract64(r3
, 0, 32);
357 result
= t2
+ (t1
* t3
);
358 return ssov32(env
, result
);
361 target_ulong
helper_madd32_suov(CPUTriCoreState
*env
, target_ulong r1
,
362 target_ulong r2
, target_ulong r3
)
364 uint64_t t1
= extract64(r1
, 0, 32);
365 uint64_t t2
= extract64(r2
, 0, 32);
366 uint64_t t3
= extract64(r3
, 0, 32);
369 result
= t2
+ (t1
* t3
);
370 return suov32_pos(env
, result
);
373 uint64_t helper_madd64_ssov(CPUTriCoreState
*env
, target_ulong r1
,
374 uint64_t r2
, target_ulong r3
)
377 int64_t t1
= sextract64(r1
, 0, 32);
378 int64_t t3
= sextract64(r3
, 0, 32);
383 ovf
= (ret
^ mul
) & ~(mul
^ r2
);
386 env
->PSW_USB_AV
= t1
^ t1
* 2u;
387 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
389 if ((int64_t)ovf
< 0) {
390 env
->PSW_USB_V
= (1 << 31);
391 env
->PSW_USB_SV
= (1 << 31);
392 /* ext_ret > MAX_INT */
395 /* ext_ret < MIN_INT */
406 uint64_t helper_madd64_suov(CPUTriCoreState
*env
, target_ulong r1
,
407 uint64_t r2
, target_ulong r3
)
410 uint64_t t1
= extract64(r1
, 0, 32);
411 uint64_t t3
= extract64(r3
, 0, 32);
417 env
->PSW_USB_AV
= t1
^ t1
* 2u;
418 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
421 env
->PSW_USB_V
= (1 << 31);
422 env
->PSW_USB_SV
= (1 << 31);
431 target_ulong
helper_msub32_ssov(CPUTriCoreState
*env
, target_ulong r1
,
432 target_ulong r2
, target_ulong r3
)
434 int64_t t1
= sextract64(r1
, 0, 32);
435 int64_t t2
= sextract64(r2
, 0, 32);
436 int64_t t3
= sextract64(r3
, 0, 32);
439 result
= t2
- (t1
* t3
);
440 return ssov32(env
, result
);
443 target_ulong
helper_msub32_suov(CPUTriCoreState
*env
, target_ulong r1
,
444 target_ulong r2
, target_ulong r3
)
446 int64_t t1
= extract64(r1
, 0, 32);
447 int64_t t2
= extract64(r2
, 0, 32);
448 int64_t t3
= extract64(r3
, 0, 32);
451 result
= t2
- (t1
* t3
);
452 return suov32_neg(env
, result
);
455 uint64_t helper_msub64_ssov(CPUTriCoreState
*env
, target_ulong r1
,
456 uint64_t r2
, target_ulong r3
)
459 int64_t t1
= sextract64(r1
, 0, 32);
460 int64_t t3
= sextract64(r3
, 0, 32);
465 ovf
= (ret
^ r2
) & (mul
^ r2
);
468 env
->PSW_USB_AV
= t1
^ t1
* 2u;
469 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
471 if ((int64_t)ovf
< 0) {
472 env
->PSW_USB_V
= (1 << 31);
473 env
->PSW_USB_SV
= (1 << 31);
474 /* ext_ret > MAX_INT */
477 /* ext_ret < MIN_INT */
487 uint64_t helper_msub64_suov(CPUTriCoreState
*env
, target_ulong r1
,
488 uint64_t r2
, target_ulong r3
)
491 uint64_t t1
= extract64(r1
, 0, 32);
492 uint64_t t3
= extract64(r3
, 0, 32);
498 env
->PSW_USB_AV
= t1
^ t1
* 2u;
499 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
502 env
->PSW_USB_V
= (1 << 31);
503 env
->PSW_USB_SV
= (1 << 31);
512 uint32_t helper_abs_b(CPUTriCoreState
*env
, target_ulong arg
)
519 for (i
= 0; i
< 4; i
++) {
520 b
= sextract32(arg
, i
* 8, 8);
521 b
= (b
>= 0) ? b
: (0 - b
);
522 ovf
|= (b
> 0x7F) || (b
< -0x80);
524 ret
|= (b
& 0xff) << (i
* 8);
527 env
->PSW_USB_V
= ovf
<< 31;
528 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
529 env
->PSW_USB_AV
= avf
<< 24;
530 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
535 uint32_t helper_abs_h(CPUTriCoreState
*env
, target_ulong arg
)
542 for (i
= 0; i
< 2; i
++) {
543 h
= sextract32(arg
, i
* 16, 16);
544 h
= (h
>= 0) ? h
: (0 - h
);
545 ovf
|= (h
> 0x7FFF) || (h
< -0x8000);
547 ret
|= (h
& 0xffff) << (i
* 16);
550 env
->PSW_USB_V
= ovf
<< 31;
551 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
552 env
->PSW_USB_AV
= avf
<< 16;
553 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
558 uint32_t helper_absdif_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
566 for (i
= 0; i
< 4; i
++) {
567 extr_r2
= sextract32(r2
, i
* 8, 8);
568 b
= sextract32(r1
, i
* 8, 8);
569 b
= (b
> extr_r2
) ? (b
- extr_r2
) : (extr_r2
- b
);
570 ovf
|= (b
> 0x7F) || (b
< -0x80);
572 ret
|= (b
& 0xff) << (i
* 8);
575 env
->PSW_USB_V
= ovf
<< 31;
576 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
577 env
->PSW_USB_AV
= avf
<< 24;
578 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
582 uint32_t helper_absdif_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
590 for (i
= 0; i
< 2; i
++) {
591 extr_r2
= sextract32(r2
, i
* 16, 16);
592 h
= sextract32(r1
, i
* 16, 16);
593 h
= (h
> extr_r2
) ? (h
- extr_r2
) : (extr_r2
- h
);
594 ovf
|= (h
> 0x7FFF) || (h
< -0x8000);
596 ret
|= (h
& 0xffff) << (i
* 16);
599 env
->PSW_USB_V
= ovf
<< 31;
600 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
601 env
->PSW_USB_AV
= avf
<< 16;
602 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
607 uint32_t helper_add_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
610 int32_t extr_r1
, extr_r2
;
615 for (i
= 0; i
< 4; i
++) {
616 extr_r1
= sextract32(r1
, i
* 8, 8);
617 extr_r2
= sextract32(r2
, i
* 8, 8);
619 b
= extr_r1
+ extr_r2
;
620 ovf
|= ((b
> 0x7f) || (b
< -0x80));
622 ret
|= ((b
& 0xff) << (i
*8));
625 env
->PSW_USB_V
= (ovf
<< 31);
626 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
627 env
->PSW_USB_AV
= avf
<< 24;
628 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
633 uint32_t helper_add_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
636 int32_t extr_r1
, extr_r2
;
641 for (i
= 0; i
< 2; i
++) {
642 extr_r1
= sextract32(r1
, i
* 16, 16);
643 extr_r2
= sextract32(r2
, i
* 16, 16);
644 h
= extr_r1
+ extr_r2
;
645 ovf
|= ((h
> 0x7fff) || (h
< -0x8000));
647 ret
|= (h
& 0xffff) << (i
* 16);
650 env
->PSW_USB_V
= (ovf
<< 31);
651 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
652 env
->PSW_USB_AV
= (avf
<< 16);
653 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
658 uint32_t helper_sub_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
661 int32_t extr_r1
, extr_r2
;
666 for (i
= 0; i
< 4; i
++) {
667 extr_r1
= sextract32(r1
, i
* 8, 8);
668 extr_r2
= sextract32(r2
, i
* 8, 8);
670 b
= extr_r1
- extr_r2
;
671 ovf
|= ((b
> 0x7f) || (b
< -0x80));
673 ret
|= ((b
& 0xff) << (i
*8));
676 env
->PSW_USB_V
= (ovf
<< 31);
677 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
678 env
->PSW_USB_AV
= avf
<< 24;
679 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
684 uint32_t helper_sub_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
687 int32_t extr_r1
, extr_r2
;
692 for (i
= 0; i
< 2; i
++) {
693 extr_r1
= sextract32(r1
, i
* 16, 16);
694 extr_r2
= sextract32(r2
, i
* 16, 16);
695 h
= extr_r1
- extr_r2
;
696 ovf
|= ((h
> 0x7fff) || (h
< -0x8000));
698 ret
|= (h
& 0xffff) << (i
* 16);
701 env
->PSW_USB_V
= (ovf
<< 31);
702 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
703 env
->PSW_USB_AV
= avf
<< 16;
704 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
709 uint32_t helper_eq_b(target_ulong r1
, target_ulong r2
)
716 for (i
= 0; i
< 4; i
++) {
717 if ((r1
& msk
) == (r2
& msk
)) {
726 uint32_t helper_eq_h(target_ulong r1
, target_ulong r2
)
730 if ((r1
& 0xffff) == (r2
& 0xffff)) {
734 if ((r1
& 0xffff0000) == (r2
& 0xffff0000)) {
741 uint32_t helper_eqany_b(target_ulong r1
, target_ulong r2
)
746 for (i
= 0; i
< 4; i
++) {
747 ret
|= (sextract32(r1
, i
* 8, 8) == sextract32(r2
, i
* 8, 8));
753 uint32_t helper_eqany_h(target_ulong r1
, target_ulong r2
)
757 ret
= (sextract32(r1
, 0, 16) == sextract32(r2
, 0, 16));
758 ret
|= (sextract32(r1
, 16, 16) == sextract32(r2
, 16, 16));
763 uint32_t helper_lt_b(target_ulong r1
, target_ulong r2
)
768 for (i
= 0; i
< 4; i
++) {
769 if (sextract32(r1
, i
* 8, 8) < sextract32(r2
, i
* 8, 8)) {
770 ret
|= (0xff << (i
* 8));
777 uint32_t helper_lt_bu(target_ulong r1
, target_ulong r2
)
782 for (i
= 0; i
< 4; i
++) {
783 if (extract32(r1
, i
* 8, 8) < extract32(r2
, i
* 8, 8)) {
784 ret
|= (0xff << (i
* 8));
791 uint32_t helper_lt_h(target_ulong r1
, target_ulong r2
)
795 if (sextract32(r1
, 0, 16) < sextract32(r2
, 0, 16)) {
799 if (sextract32(r1
, 16, 16) < sextract32(r2
, 16, 16)) {
806 uint32_t helper_lt_hu(target_ulong r1
, target_ulong r2
)
810 if (extract32(r1
, 0, 16) < extract32(r2
, 0, 16)) {
814 if (extract32(r1
, 16, 16) < extract32(r2
, 16, 16)) {
821 #define EXTREMA_H_B(name, op) \
822 uint32_t helper_##name ##_b(target_ulong r1, target_ulong r2) \
824 int32_t i, extr_r1, extr_r2; \
827 for (i = 0; i < 4; i++) { \
828 extr_r1 = sextract32(r1, i * 8, 8); \
829 extr_r2 = sextract32(r2, i * 8, 8); \
830 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
831 ret |= (extr_r1 & 0xff) << (i * 8); \
836 uint32_t helper_##name ##_bu(target_ulong r1, target_ulong r2)\
839 uint32_t extr_r1, extr_r2; \
842 for (i = 0; i < 4; i++) { \
843 extr_r1 = extract32(r1, i * 8, 8); \
844 extr_r2 = extract32(r2, i * 8, 8); \
845 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
846 ret |= (extr_r1 & 0xff) << (i * 8); \
851 uint32_t helper_##name ##_h(target_ulong r1, target_ulong r2) \
853 int32_t extr_r1, extr_r2; \
856 extr_r1 = sextract32(r1, 0, 16); \
857 extr_r2 = sextract32(r2, 0, 16); \
858 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
859 ret = ret & 0xffff; \
861 extr_r1 = sextract32(r1, 16, 16); \
862 extr_r2 = sextract32(r2, 16, 16); \
863 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
864 ret |= extr_r1 << 16; \
869 uint32_t helper_##name ##_hu(target_ulong r1, target_ulong r2)\
871 uint32_t extr_r1, extr_r2; \
874 extr_r1 = extract32(r1, 0, 16); \
875 extr_r2 = extract32(r2, 0, 16); \
876 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
877 ret = ret & 0xffff; \
879 extr_r1 = extract32(r1, 16, 16); \
880 extr_r2 = extract32(r2, 16, 16); \
881 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
882 ret |= extr_r1 << (16); \
887 uint64_t helper_ix##name(uint64_t r1, uint32_t r2) \
889 int64_t r2l, r2h, r1hl; \
892 ret = ((r1 + 2) & 0xffff); \
893 r2l = sextract64(r2, 0, 16); \
894 r2h = sextract64(r2, 16, 16); \
895 r1hl = sextract64(r1, 32, 16); \
897 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
898 ret |= (r2l & 0xffff) << 32; \
899 ret |= extract64(r1, 0, 16) << 16; \
900 } else if ((r2h op r2l) && (r2h op r1hl)) { \
901 ret |= extract64(r2, 16, 16) << 32; \
902 ret |= extract64(r1 + 1, 0, 16) << 16; \
904 ret |= r1 & 0xffffffff0000ull; \
909 uint64_t helper_ix##name ##_u(uint64_t r1, uint32_t r2) \
911 int64_t r2l, r2h, r1hl; \
914 ret = ((r1 + 2) & 0xffff); \
915 r2l = extract64(r2, 0, 16); \
916 r2h = extract64(r2, 16, 16); \
917 r1hl = extract64(r1, 32, 16); \
919 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
920 ret |= (r2l & 0xffff) << 32; \
921 ret |= extract64(r1, 0, 16) << 16; \
922 } else if ((r2h op r2l) && (r2h op r1hl)) { \
923 ret |= extract64(r2, 16, 16) << 32; \
924 ret |= extract64(r1 + 1, 0, 16) << 16; \
926 ret |= r1 & 0xffffffff0000ull; \
936 uint32_t helper_clo(target_ulong r1
)
941 uint32_t helper_clo_h(target_ulong r1
)
943 uint32_t ret_hw0
= extract32(r1
, 0, 16);
944 uint32_t ret_hw1
= extract32(r1
, 16, 16);
946 ret_hw0
= clo32(ret_hw0
<< 16);
947 ret_hw1
= clo32(ret_hw1
<< 16);
956 return ret_hw0
| (ret_hw1
<< 16);
959 uint32_t helper_clz(target_ulong r1
)
964 uint32_t helper_clz_h(target_ulong r1
)
966 uint32_t ret_hw0
= extract32(r1
, 0, 16);
967 uint32_t ret_hw1
= extract32(r1
, 16, 16);
969 ret_hw0
= clz32(ret_hw0
<< 16);
970 ret_hw1
= clz32(ret_hw1
<< 16);
979 return ret_hw0
| (ret_hw1
<< 16);
982 uint32_t helper_cls(target_ulong r1
)
987 uint32_t helper_cls_h(target_ulong r1
)
989 uint32_t ret_hw0
= extract32(r1
, 0, 16);
990 uint32_t ret_hw1
= extract32(r1
, 16, 16);
992 ret_hw0
= clrsb32(ret_hw0
<< 16);
993 ret_hw1
= clrsb32(ret_hw1
<< 16);
1002 return ret_hw0
| (ret_hw1
<< 16);
1005 uint32_t helper_sh(target_ulong r1
, target_ulong r2
)
1007 int32_t shift_count
= sextract32(r2
, 0, 6);
1009 if (shift_count
== -32) {
1011 } else if (shift_count
< 0) {
1012 return r1
>> -shift_count
;
1014 return r1
<< shift_count
;
1018 uint32_t helper_sh_h(target_ulong r1
, target_ulong r2
)
1020 int32_t ret_hw0
, ret_hw1
;
1021 int32_t shift_count
;
1023 shift_count
= sextract32(r2
, 0, 5);
1025 if (shift_count
== -16) {
1027 } else if (shift_count
< 0) {
1028 ret_hw0
= extract32(r1
, 0, 16) >> -shift_count
;
1029 ret_hw1
= extract32(r1
, 16, 16) >> -shift_count
;
1030 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1032 ret_hw0
= extract32(r1
, 0, 16) << shift_count
;
1033 ret_hw1
= extract32(r1
, 16, 16) << shift_count
;
1034 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1038 uint32_t helper_sha(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1040 int32_t shift_count
;
1044 shift_count
= sextract32(r2
, 0, 6);
1045 t1
= sextract32(r1
, 0, 32);
1047 if (shift_count
== 0) {
1048 env
->PSW_USB_C
= env
->PSW_USB_V
= 0;
1050 } else if (shift_count
== -32) {
1051 env
->PSW_USB_C
= r1
;
1054 } else if (shift_count
> 0) {
1055 result
= t1
<< shift_count
;
1057 env
->PSW_USB_C
= ((result
& 0xffffffff00000000ULL
) != 0);
1059 env
->PSW_USB_V
= (((result
> 0x7fffffffLL
) ||
1060 (result
< -0x80000000LL
)) << 31);
1062 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1063 ret
= (uint32_t)result
;
1066 env
->PSW_USB_C
= (r1
& ((1 << -shift_count
) - 1));
1067 ret
= t1
>> -shift_count
;
1070 env
->PSW_USB_AV
= ret
^ ret
* 2u;
1071 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1076 uint32_t helper_sha_h(target_ulong r1
, target_ulong r2
)
1078 int32_t shift_count
;
1079 int32_t ret_hw0
, ret_hw1
;
1081 shift_count
= sextract32(r2
, 0, 5);
1083 if (shift_count
== 0) {
1085 } else if (shift_count
< 0) {
1086 ret_hw0
= sextract32(r1
, 0, 16) >> -shift_count
;
1087 ret_hw1
= sextract32(r1
, 16, 16) >> -shift_count
;
1088 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1090 ret_hw0
= sextract32(r1
, 0, 16) << shift_count
;
1091 ret_hw1
= sextract32(r1
, 16, 16) << shift_count
;
1092 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1096 uint32_t helper_bmerge(target_ulong r1
, target_ulong r2
)
1101 for (i
= 0; i
< 16; i
++) {
1102 ret
|= (r1
& 1) << (2 * i
+ 1);
1103 ret
|= (r2
& 1) << (2 * i
);
1110 uint64_t helper_bsplit(uint32_t r1
)
1116 for (i
= 0; i
< 32; i
= i
+ 2) {
1118 ret
|= (r1
& 1) << (i
/2);
1121 ret
|= (uint64_t)(r1
& 1) << (i
/2 + 32);
1127 uint32_t helper_parity(target_ulong r1
)
1134 for (i
= 0; i
< 8; i
++) {
1140 for (i
= 0; i
< 8; i
++) {
1147 for (i
= 0; i
< 8; i
++) {
1154 for (i
= 0; i
< 8; i
++) {
1163 uint32_t helper_pack(uint32_t carry
, uint32_t r1_low
, uint32_t r1_high
,
1167 int32_t fp_exp
, fp_frac
, temp_exp
, fp_exp_frac
;
1168 int32_t int_exp
= r1_high
;
1169 int32_t int_mant
= r1_low
;
1170 uint32_t flag_rnd
= (int_mant
& (1 << 7)) && (
1171 (int_mant
& (1 << 8)) ||
1172 (int_mant
& 0x7f) ||
1174 if (((int_mant
& (1<<31)) == 0) && (int_exp
== 255)) {
1176 fp_frac
= extract32(int_mant
, 8, 23);
1177 } else if ((int_mant
& (1<<31)) && (int_exp
>= 127)) {
1180 } else if ((int_mant
& (1<<31)) && (int_exp
<= -128)) {
1183 } else if (int_mant
== 0) {
1187 if (((int_mant
& (1 << 31)) == 0)) {
1190 temp_exp
= int_exp
+ 128;
1192 fp_exp_frac
= (((temp_exp
& 0xff) << 23) |
1193 extract32(int_mant
, 8, 23))
1195 fp_exp
= extract32(fp_exp_frac
, 23, 8);
1196 fp_frac
= extract32(fp_exp_frac
, 0, 23);
1198 ret
= r2
& (1 << 31);
1199 ret
= ret
+ (fp_exp
<< 23);
1200 ret
= ret
+ (fp_frac
& 0x7fffff);
1205 uint64_t helper_unpack(target_ulong arg1
)
1207 int32_t fp_exp
= extract32(arg1
, 23, 8);
1208 int32_t fp_frac
= extract32(arg1
, 0, 23);
1210 int32_t int_exp
, int_mant
;
1212 if (fp_exp
== 255) {
1214 int_mant
= (fp_frac
<< 7);
1215 } else if ((fp_exp
== 0) && (fp_frac
== 0)) {
1218 } else if ((fp_exp
== 0) && (fp_frac
!= 0)) {
1220 int_mant
= (fp_frac
<< 7);
1222 int_exp
= fp_exp
- 127;
1223 int_mant
= (fp_frac
<< 7);
1224 int_mant
|= (1 << 30);
1233 uint64_t helper_dvinit_b_13(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1236 int32_t abs_sig_dividend
, abs_base_dividend
, abs_divisor
;
1237 int32_t quotient_sign
;
1239 ret
= sextract32(r1
, 0, 32);
1242 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1247 abs_sig_dividend
= abs(r1
) >> 7;
1248 abs_base_dividend
= abs(r1
) & 0x7f;
1249 abs_divisor
= abs(r1
);
1252 if ((quotient_sign
) && (abs_divisor
)) {
1253 env
->PSW_USB_V
= (((abs_sig_dividend
== abs_divisor
) &&
1254 (abs_base_dividend
>= abs_divisor
)) ||
1255 (abs_sig_dividend
> abs_divisor
));
1257 env
->PSW_USB_V
= (abs_sig_dividend
>= abs_divisor
);
1259 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1260 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1261 env
->PSW_USB_AV
= 0;
1266 uint64_t helper_dvinit_b_131(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1268 uint64_t ret
= sextract32(r1
, 0, 32);
1271 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1275 env
->PSW_USB_V
= ((r2
== 0) || ((r2
== 0xffffffff) && (r1
== 0xffffff80)));
1276 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1277 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1278 env
->PSW_USB_AV
= 0;
1283 uint64_t helper_dvinit_h_13(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1286 int32_t abs_sig_dividend
, abs_base_dividend
, abs_divisor
;
1287 int32_t quotient_sign
;
1289 ret
= sextract32(r1
, 0, 32);
1292 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1297 abs_sig_dividend
= abs(r1
) >> 7;
1298 abs_base_dividend
= abs(r1
) & 0x7f;
1299 abs_divisor
= abs(r1
);
1302 if ((quotient_sign
) && (abs_divisor
)) {
1303 env
->PSW_USB_V
= (((abs_sig_dividend
== abs_divisor
) &&
1304 (abs_base_dividend
>= abs_divisor
)) ||
1305 (abs_sig_dividend
> abs_divisor
));
1307 env
->PSW_USB_V
= (abs_sig_dividend
>= abs_divisor
);
1309 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1310 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1311 env
->PSW_USB_AV
= 0;
1316 uint64_t helper_dvinit_h_131(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1318 uint64_t ret
= sextract32(r1
, 0, 32);
1321 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1325 env
->PSW_USB_V
= ((r2
== 0) || ((r2
== 0xffffffff) && (r1
== 0xffff8000)));
1326 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1327 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1328 env
->PSW_USB_AV
= 0;
1333 uint64_t helper_dvadj(uint64_t r1
, uint32_t r2
)
1335 int32_t x_sign
= (r1
>> 63);
1336 int32_t q_sign
= x_sign
^ (r2
>> 31);
1337 int32_t eq_pos
= x_sign
& ((r1
>> 32) == r2
);
1338 int32_t eq_neg
= x_sign
& ((r1
>> 32) == -r2
);
1340 uint64_t ret
, remainder
;
1342 if ((q_sign
& ~eq_neg
) | eq_pos
) {
1343 quotient
= (r1
+ 1) & 0xffffffff;
1345 quotient
= r1
& 0xffffffff;
1348 if (eq_pos
| eq_neg
) {
1351 remainder
= (r1
& 0xffffffff00000000ull
);
1353 ret
= remainder
|quotient
;
1357 uint64_t helper_dvstep(uint64_t r1
, uint32_t r2
)
1359 int32_t dividend_sign
= extract64(r1
, 63, 1);
1360 int32_t divisor_sign
= extract32(r2
, 31, 1);
1361 int32_t quotient_sign
= (dividend_sign
!= divisor_sign
);
1362 int32_t addend
, dividend_quotient
, remainder
;
1365 if (quotient_sign
) {
1370 dividend_quotient
= (int32_t)r1
;
1371 remainder
= (int32_t)(r1
>> 32);
1373 for (i
= 0; i
< 8; i
++) {
1374 remainder
= (remainder
<< 1) | extract32(dividend_quotient
, 31, 1);
1375 dividend_quotient
<<= 1;
1376 temp
= remainder
+ addend
;
1377 if ((temp
< 0) == dividend_sign
) {
1380 if (((temp
< 0) == dividend_sign
)) {
1381 dividend_quotient
= dividend_quotient
| !quotient_sign
;
1383 dividend_quotient
= dividend_quotient
| quotient_sign
;
1386 return ((uint64_t)remainder
<< 32) | (uint32_t)dividend_quotient
;
1389 uint64_t helper_dvstep_u(uint64_t r1
, uint32_t r2
)
1391 int32_t dividend_quotient
= extract64(r1
, 0, 32);
1392 int64_t remainder
= extract64(r1
, 32, 32);
1395 for (i
= 0; i
< 8; i
++) {
1396 remainder
= (remainder
<< 1) | extract32(dividend_quotient
, 31, 1);
1397 dividend_quotient
<<= 1;
1398 temp
= (remainder
& 0xffffffff) - r2
;
1402 dividend_quotient
= dividend_quotient
| !(temp
< 0);
1404 return ((uint64_t)remainder
<< 32) | (uint32_t)dividend_quotient
;
1407 uint64_t helper_mul_h(uint32_t arg00
, uint32_t arg01
,
1408 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
1411 uint32_t result0
, result1
;
1413 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
1414 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
1415 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
1416 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
1418 result1
= 0x7fffffff;
1420 result1
= (((uint32_t)(arg00
* arg10
)) << n
);
1423 result0
= 0x7fffffff;
1425 result0
= (((uint32_t)(arg01
* arg11
)) << n
);
1427 ret
= (((uint64_t)result1
<< 32)) | result0
;
1431 uint64_t helper_mulm_h(uint32_t arg00
, uint32_t arg01
,
1432 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
1435 int64_t result0
, result1
;
1437 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
1438 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
1439 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
1440 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
1443 result1
= 0x7fffffff;
1445 result1
= (((int32_t)arg00
* (int32_t)arg10
) << n
);
1448 result0
= 0x7fffffff;
1450 result0
= (((int32_t)arg01
* (int32_t)arg11
) << n
);
1452 ret
= (result1
+ result0
);
1456 uint32_t helper_mulr_h(uint32_t arg00
, uint32_t arg01
,
1457 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
1459 uint32_t result0
, result1
;
1461 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
1462 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
1463 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
1464 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
1467 result1
= 0x7fffffff;
1469 result1
= ((arg00
* arg10
) << n
) + 0x8000;
1472 result0
= 0x7fffffff;
1474 result0
= ((arg01
* arg11
) << n
) + 0x8000;
1476 return (result1
& 0xffff0000) | (result0
>> 16);
1479 /* context save area (CSA) related helpers */
1481 static int cdc_increment(target_ulong
*psw
)
1483 if ((*psw
& MASK_PSW_CDC
) == 0x7f) {
1488 /* check for overflow */
1489 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
1490 int mask
= (1u << (7 - lo
)) - 1;
1491 int count
= *psw
& mask
;
1499 static int cdc_decrement(target_ulong
*psw
)
1501 if ((*psw
& MASK_PSW_CDC
) == 0x7f) {
1504 /* check for underflow */
1505 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
1506 int mask
= (1u << (7 - lo
)) - 1;
1507 int count
= *psw
& mask
;
1515 static bool cdc_zero(target_ulong
*psw
)
1517 int cdc
= *psw
& MASK_PSW_CDC
;
1518 /* Returns TRUE if PSW.CDC.COUNT == 0 or if PSW.CDC ==
1519 7'b1111111, otherwise returns FALSE. */
1523 /* find CDC.COUNT */
1524 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
1525 int mask
= (1u << (7 - lo
)) - 1;
1526 int count
= *psw
& mask
;
1530 static void save_context_upper(CPUTriCoreState
*env
, int ea
)
1532 cpu_stl_data(env
, ea
, env
->PCXI
);
1533 cpu_stl_data(env
, ea
+4, env
->PSW
);
1534 cpu_stl_data(env
, ea
+8, env
->gpr_a
[10]);
1535 cpu_stl_data(env
, ea
+12, env
->gpr_a
[11]);
1536 cpu_stl_data(env
, ea
+16, env
->gpr_d
[8]);
1537 cpu_stl_data(env
, ea
+20, env
->gpr_d
[9]);
1538 cpu_stl_data(env
, ea
+24, env
->gpr_d
[10]);
1539 cpu_stl_data(env
, ea
+28, env
->gpr_d
[11]);
1540 cpu_stl_data(env
, ea
+32, env
->gpr_a
[12]);
1541 cpu_stl_data(env
, ea
+36, env
->gpr_a
[13]);
1542 cpu_stl_data(env
, ea
+40, env
->gpr_a
[14]);
1543 cpu_stl_data(env
, ea
+44, env
->gpr_a
[15]);
1544 cpu_stl_data(env
, ea
+48, env
->gpr_d
[12]);
1545 cpu_stl_data(env
, ea
+52, env
->gpr_d
[13]);
1546 cpu_stl_data(env
, ea
+56, env
->gpr_d
[14]);
1547 cpu_stl_data(env
, ea
+60, env
->gpr_d
[15]);
1550 static void save_context_lower(CPUTriCoreState
*env
, int ea
)
1552 cpu_stl_data(env
, ea
, env
->PCXI
);
1553 cpu_stl_data(env
, ea
+4, env
->gpr_a
[11]);
1554 cpu_stl_data(env
, ea
+8, env
->gpr_a
[2]);
1555 cpu_stl_data(env
, ea
+12, env
->gpr_a
[3]);
1556 cpu_stl_data(env
, ea
+16, env
->gpr_d
[0]);
1557 cpu_stl_data(env
, ea
+20, env
->gpr_d
[1]);
1558 cpu_stl_data(env
, ea
+24, env
->gpr_d
[2]);
1559 cpu_stl_data(env
, ea
+28, env
->gpr_d
[3]);
1560 cpu_stl_data(env
, ea
+32, env
->gpr_a
[4]);
1561 cpu_stl_data(env
, ea
+36, env
->gpr_a
[5]);
1562 cpu_stl_data(env
, ea
+40, env
->gpr_a
[6]);
1563 cpu_stl_data(env
, ea
+44, env
->gpr_a
[7]);
1564 cpu_stl_data(env
, ea
+48, env
->gpr_d
[4]);
1565 cpu_stl_data(env
, ea
+52, env
->gpr_d
[5]);
1566 cpu_stl_data(env
, ea
+56, env
->gpr_d
[6]);
1567 cpu_stl_data(env
, ea
+60, env
->gpr_d
[7]);
1570 static void restore_context_upper(CPUTriCoreState
*env
, int ea
,
1571 target_ulong
*new_PCXI
, target_ulong
*new_PSW
)
1573 *new_PCXI
= cpu_ldl_data(env
, ea
);
1574 *new_PSW
= cpu_ldl_data(env
, ea
+4);
1575 env
->gpr_a
[10] = cpu_ldl_data(env
, ea
+8);
1576 env
->gpr_a
[11] = cpu_ldl_data(env
, ea
+12);
1577 env
->gpr_d
[8] = cpu_ldl_data(env
, ea
+16);
1578 env
->gpr_d
[9] = cpu_ldl_data(env
, ea
+20);
1579 env
->gpr_d
[10] = cpu_ldl_data(env
, ea
+24);
1580 env
->gpr_d
[11] = cpu_ldl_data(env
, ea
+28);
1581 env
->gpr_a
[12] = cpu_ldl_data(env
, ea
+32);
1582 env
->gpr_a
[13] = cpu_ldl_data(env
, ea
+36);
1583 env
->gpr_a
[14] = cpu_ldl_data(env
, ea
+40);
1584 env
->gpr_a
[15] = cpu_ldl_data(env
, ea
+44);
1585 env
->gpr_d
[12] = cpu_ldl_data(env
, ea
+48);
1586 env
->gpr_d
[13] = cpu_ldl_data(env
, ea
+52);
1587 env
->gpr_d
[14] = cpu_ldl_data(env
, ea
+56);
1588 env
->gpr_d
[15] = cpu_ldl_data(env
, ea
+60);
1591 static void restore_context_lower(CPUTriCoreState
*env
, int ea
,
1592 target_ulong
*ra
, target_ulong
*pcxi
)
1594 *pcxi
= cpu_ldl_data(env
, ea
);
1595 *ra
= cpu_ldl_data(env
, ea
+4);
1596 env
->gpr_a
[2] = cpu_ldl_data(env
, ea
+8);
1597 env
->gpr_a
[3] = cpu_ldl_data(env
, ea
+12);
1598 env
->gpr_d
[0] = cpu_ldl_data(env
, ea
+16);
1599 env
->gpr_d
[1] = cpu_ldl_data(env
, ea
+20);
1600 env
->gpr_d
[2] = cpu_ldl_data(env
, ea
+24);
1601 env
->gpr_d
[3] = cpu_ldl_data(env
, ea
+28);
1602 env
->gpr_a
[4] = cpu_ldl_data(env
, ea
+32);
1603 env
->gpr_a
[5] = cpu_ldl_data(env
, ea
+36);
1604 env
->gpr_a
[6] = cpu_ldl_data(env
, ea
+40);
1605 env
->gpr_a
[7] = cpu_ldl_data(env
, ea
+44);
1606 env
->gpr_d
[4] = cpu_ldl_data(env
, ea
+48);
1607 env
->gpr_d
[5] = cpu_ldl_data(env
, ea
+52);
1608 env
->gpr_d
[6] = cpu_ldl_data(env
, ea
+56);
1609 env
->gpr_d
[7] = cpu_ldl_data(env
, ea
+60);
1612 void helper_call(CPUTriCoreState
*env
, uint32_t next_pc
)
1614 target_ulong tmp_FCX
;
1616 target_ulong new_FCX
;
1619 psw
= psw_read(env
);
1620 /* if (FCX == 0) trap(FCU); */
1621 if (env
->FCX
== 0) {
1624 /* if (PSW.CDE) then if (cdc_increment()) then trap(CDO); */
1625 if (psw
& MASK_PSW_CDE
) {
1626 if (cdc_increment(&psw
)) {
1631 psw
|= MASK_PSW_CDE
;
1632 /* tmp_FCX = FCX; */
1634 /* EA = {FCX.FCXS, 6'b0, FCX.FCXO, 6'b0}; */
1635 ea
= ((env
->FCX
& MASK_FCX_FCXS
) << 12) +
1636 ((env
->FCX
& MASK_FCX_FCXO
) << 6);
1637 /* new_FCX = M(EA, word); */
1638 new_FCX
= cpu_ldl_data(env
, ea
);
1639 /* M(EA, 16 * word) = {PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11],
1640 A[12], A[13], A[14], A[15], D[12], D[13], D[14],
1642 save_context_upper(env
, ea
);
1644 /* PCXI.PCPN = ICR.CCPN; */
1645 env
->PCXI
= (env
->PCXI
& 0xffffff) +
1646 ((env
->ICR
& MASK_ICR_CCPN
) << 24);
1647 /* PCXI.PIE = ICR.IE; */
1648 env
->PCXI
= ((env
->PCXI
& ~MASK_PCXI_PIE
) +
1649 ((env
->ICR
& MASK_ICR_IE
) << 15));
1651 env
->PCXI
|= MASK_PCXI_UL
;
1653 /* PCXI[19: 0] = FCX[19: 0]; */
1654 env
->PCXI
= (env
->PCXI
& 0xfff00000) + (env
->FCX
& 0xfffff);
1655 /* FCX[19: 0] = new_FCX[19: 0]; */
1656 env
->FCX
= (env
->FCX
& 0xfff00000) + (new_FCX
& 0xfffff);
1657 /* A[11] = next_pc[31: 0]; */
1658 env
->gpr_a
[11] = next_pc
;
1660 /* if (tmp_FCX == LCX) trap(FCD);*/
1661 if (tmp_FCX
== env
->LCX
) {
1664 psw_write(env
, psw
);
1667 void helper_ret(CPUTriCoreState
*env
)
1670 target_ulong new_PCXI
;
1671 target_ulong new_PSW
, psw
;
1673 psw
= psw_read(env
);
1674 /* if (PSW.CDE) then if (cdc_decrement()) then trap(CDU);*/
1675 if (env
->PSW
& MASK_PSW_CDE
) {
1676 if (cdc_decrement(&(env
->PSW
))) {
1680 /* if (PCXI[19: 0] == 0) then trap(CSU); */
1681 if ((env
->PCXI
& 0xfffff) == 0) {
1684 /* if (PCXI.UL == 0) then trap(CTYP); */
1685 if ((env
->PCXI
& MASK_PCXI_UL
) == 0) {
1688 /* PC = {A11 [31: 1], 1’b0}; */
1689 env
->PC
= env
->gpr_a
[11] & 0xfffffffe;
1691 /* EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0}; */
1692 ea
= ((env
->PCXI
& MASK_PCXI_PCXS
) << 12) +
1693 ((env
->PCXI
& MASK_PCXI_PCXO
) << 6);
1694 /* {new_PCXI, new_PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
1695 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
1696 restore_context_upper(env
, ea
, &new_PCXI
, &new_PSW
);
1697 /* M(EA, word) = FCX; */
1698 cpu_stl_data(env
, ea
, env
->FCX
);
1699 /* FCX[19: 0] = PCXI[19: 0]; */
1700 env
->FCX
= (env
->FCX
& 0xfff00000) + (env
->PCXI
& 0x000fffff);
1701 /* PCXI = new_PCXI; */
1702 env
->PCXI
= new_PCXI
;
1704 if (tricore_feature(env
, TRICORE_FEATURE_13
)) {
1706 psw_write(env
, new_PSW
);
1708 /* PSW = {new_PSW[31:26], PSW[25:24], new_PSW[23:0]}; */
1709 psw_write(env
, (new_PSW
& ~(0x3000000)) + (psw
& (0x3000000)));
1713 void helper_bisr(CPUTriCoreState
*env
, uint32_t const9
)
1715 target_ulong tmp_FCX
;
1717 target_ulong new_FCX
;
1719 if (env
->FCX
== 0) {
1724 ea
= ((env
->FCX
& 0xf0000) << 12) + ((env
->FCX
& 0xffff) << 6);
1726 /* new_FCX = M(EA, word); */
1727 new_FCX
= cpu_ldl_data(env
, ea
);
1728 /* M(EA, 16 * word) = {PCXI, A[11], A[2], A[3], D[0], D[1], D[2], D[3], A[4]
1729 , A[5], A[6], A[7], D[4], D[5], D[6], D[7]}; */
1730 save_context_lower(env
, ea
);
1733 /* PCXI.PCPN = ICR.CCPN */
1734 env
->PCXI
= (env
->PCXI
& 0xffffff) +
1735 ((env
->ICR
& MASK_ICR_CCPN
) << 24);
1736 /* PCXI.PIE = ICR.IE */
1737 env
->PCXI
= ((env
->PCXI
& ~MASK_PCXI_PIE
) +
1738 ((env
->ICR
& MASK_ICR_IE
) << 15));
1740 env
->PCXI
&= ~(MASK_PCXI_UL
);
1741 /* PCXI[19: 0] = FCX[19: 0] */
1742 env
->PCXI
= (env
->PCXI
& 0xfff00000) + (env
->FCX
& 0xfffff);
1743 /* FXC[19: 0] = new_FCX[19: 0] */
1744 env
->FCX
= (env
->FCX
& 0xfff00000) + (new_FCX
& 0xfffff);
1746 env
->ICR
|= MASK_ICR_IE
;
1748 env
->ICR
|= const9
; /* ICR.CCPN = const9[7: 0];*/
1750 if (tmp_FCX
== env
->LCX
) {
1755 void helper_rfe(CPUTriCoreState
*env
)
1758 target_ulong new_PCXI
;
1759 target_ulong new_PSW
;
1760 /* if (PCXI[19: 0] == 0) then trap(CSU); */
1761 if ((env
->PCXI
& 0xfffff) == 0) {
1762 /* raise csu trap */
1764 /* if (PCXI.UL == 0) then trap(CTYP); */
1765 if ((env
->PCXI
& MASK_PCXI_UL
) == 0) {
1766 /* raise CTYP trap */
1768 /* if (!cdc_zero() AND PSW.CDE) then trap(NEST); */
1769 if (!cdc_zero(&(env
->PSW
)) && (env
->PSW
& MASK_PSW_CDE
)) {
1770 /* raise MNG trap */
1772 /* ICR.IE = PCXI.PIE; */
1773 env
->ICR
= (env
->ICR
& ~MASK_ICR_IE
) + ((env
->PCXI
& MASK_PCXI_PIE
) >> 15);
1774 /* ICR.CCPN = PCXI.PCPN; */
1775 env
->ICR
= (env
->ICR
& ~MASK_ICR_CCPN
) +
1776 ((env
->PCXI
& MASK_PCXI_PCPN
) >> 24);
1777 /*EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0};*/
1778 ea
= ((env
->PCXI
& MASK_PCXI_PCXS
) << 12) +
1779 ((env
->PCXI
& MASK_PCXI_PCXO
) << 6);
1780 /*{new_PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
1781 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
1782 restore_context_upper(env
, ea
, &new_PCXI
, &new_PSW
);
1783 /* M(EA, word) = FCX;*/
1784 cpu_stl_data(env
, ea
, env
->FCX
);
1785 /* FCX[19: 0] = PCXI[19: 0]; */
1786 env
->FCX
= (env
->FCX
& 0xfff00000) + (env
->PCXI
& 0x000fffff);
1787 /* PCXI = new_PCXI; */
1788 env
->PCXI
= new_PCXI
;
1790 psw_write(env
, new_PSW
);
1793 void helper_ldlcx(CPUTriCoreState
*env
, uint32_t ea
)
1796 /* insn doesn't load PCXI and RA */
1797 restore_context_lower(env
, ea
, &dummy
, &dummy
);
1800 void helper_lducx(CPUTriCoreState
*env
, uint32_t ea
)
1803 /* insn doesn't load PCXI and PSW */
1804 restore_context_upper(env
, ea
, &dummy
, &dummy
);
1807 void helper_stlcx(CPUTriCoreState
*env
, uint32_t ea
)
1809 save_context_lower(env
, ea
);
1812 void helper_stucx(CPUTriCoreState
*env
, uint32_t ea
)
1814 save_context_upper(env
, ea
);
1817 void helper_psw_write(CPUTriCoreState
*env
, uint32_t arg
)
1819 psw_write(env
, arg
);
1822 uint32_t helper_psw_read(CPUTriCoreState
*env
)
1824 return psw_read(env
);
1828 static inline void QEMU_NORETURN
do_raise_exception_err(CPUTriCoreState
*env
,
1833 CPUState
*cs
= CPU(tricore_env_get_cpu(env
));
1834 cs
->exception_index
= exception
;
1835 env
->error_code
= error_code
;
1838 /* now we have a real cpu fault */
1839 cpu_restore_state(cs
, pc
);
1845 void tlb_fill(CPUState
*cs
, target_ulong addr
, int is_write
, int mmu_idx
,
1849 ret
= cpu_tricore_handle_mmu_fault(cs
, addr
, is_write
, mmu_idx
);
1851 TriCoreCPU
*cpu
= TRICORE_CPU(cs
);
1852 CPUTriCoreState
*env
= &cpu
->env
;
1853 do_raise_exception_err(env
, cs
->exception_index
,
1854 env
->error_code
, retaddr
);