]>
git.proxmox.com Git - qemu.git/blob - target-ppc/op.c
2 * PPC emulation micro-operations for qemu.
4 * Copyright (c) 2003 Jocelyn Mayer
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
27 #define Ts0 (int32_t)T0
28 #define Ts1 (int32_t)T1
29 #define Ts2 (int32_t)T2
31 #define FT0 (env->ft0)
32 #define FT1 (env->ft1)
33 #define FT2 (env->ft2)
35 #define FTS0 ((float)env->ft0)
36 #define FTS1 ((float)env->ft1)
37 #define FTS2 ((float)env->ft2)
39 #define PPC_OP(name) void glue(op_, name)(void)
42 #include "op_template.h"
45 #include "op_template.h"
48 #include "op_template.h"
51 #include "op_template.h"
54 #include "op_template.h"
57 #include "op_template.h"
60 #include "op_template.h"
63 #include "op_template.h"
66 #include "op_template.h"
69 #include "op_template.h"
72 #include "op_template.h"
75 #include "op_template.h"
78 #include "op_template.h"
81 #include "op_template.h"
84 #include "op_template.h"
87 #include "op_template.h"
90 #include "op_template.h"
93 #include "op_template.h"
96 #include "op_template.h"
99 #include "op_template.h"
102 #include "op_template.h"
105 #include "op_template.h"
108 #include "op_template.h"
111 #include "op_template.h"
114 #include "op_template.h"
117 #include "op_template.h"
120 #include "op_template.h"
123 #include "op_template.h"
126 #include "op_template.h"
129 #include "op_template.h"
132 #include "op_template.h"
135 #include "op_template.h"
137 /* PPC state maintenance operations */
145 } else if (Ts0
> 0) {
160 } else if (Ts0
> 0) {
173 env
->crf
[0] = 0x02 | xer_ov
;
180 env
->crf
[0] = 0x04 | xer_ov
;
184 /* Set Rc1 (for floating point arithmetic) */
187 env
->crf
[1] = regs
->fpscr
[7];
210 /* Generate exceptions */
211 PPC_OP(raise_exception_err
)
213 do_raise_exception_err(PARAM(1), PARAM(2));
216 PPC_OP(raise_exception
)
218 do_raise_exception(PARAM(1));
229 #if defined (DEBUG_OP)
232 do_raise_exception(EXCP_DEBUG
);
236 /* Segment registers load and store with immediate index */
239 T0
= regs
->sr
[T1
>> 28];
245 do_store_sr(T1
>> 28);
266 /* Load/store special registers */
275 do_store_cr(PARAM(1));
281 T0
= (xer_so
<< 3) | (xer_ov
<< 2) | (xer_ca
<< 1);
326 T0
= regs
->spr
[PARAM(1)];
332 regs
->spr
[PARAM(1)] = T0
;
362 T0
= cpu_ppc_load_tbl(regs
);
368 T0
= cpu_ppc_load_tbu(regs
);
374 cpu_ppc_store_tbl(regs
, T0
);
380 cpu_ppc_store_tbu(regs
, T0
);
386 T0
= cpu_ppc_load_decr(regs
);
391 cpu_ppc_store_decr(regs
, T0
);
397 T0
= regs
->IBAT
[PARAM(1)][PARAM(2)];
402 do_store_ibat(PARAM(1), PARAM(2));
407 T0
= regs
->DBAT
[PARAM(1)][PARAM(2)];
412 do_store_dbat(PARAM(1), PARAM(2));
424 do_store_fpscr(PARAM(1));
430 regs
->fpscr
[7] &= ~0x8;
437 T0
= (T0
>> PARAM(1)) & 1;
443 T1
= (T1
>> PARAM(1)) & 1;
449 T1
= (T1
& PARAM(1)) | (T0
<< PARAM(2));
454 #define EIP regs->nip
463 JUMP_TB(b1
, PARAM1
, 0, PARAM2
);
474 JUMP_TB(btest
, PARAM1
, 0, PARAM2
);
476 JUMP_TB(btest
, PARAM1
, 1, PARAM3
);
501 /* tests with result in T0 */
508 PPC_OP(test_ctr_true
)
510 T0
= (regs
->ctr
!= 0 && (T0
& PARAM(1)) != 0);
513 PPC_OP(test_ctr_false
)
515 T0
= (regs
->ctr
!= 0 && (T0
& PARAM(1)) == 0);
520 T0
= (regs
->ctr
== 0);
523 PPC_OP(test_ctrz_true
)
525 T0
= (regs
->ctr
== 0 && (T0
& PARAM(1)) != 0);
528 PPC_OP(test_ctrz_false
)
530 T0
= (regs
->ctr
== 0 && (T0
& PARAM(1)) == 0);
535 T0
= (T0
& PARAM(1));
540 T0
= ((T0
& PARAM(1)) == 0);
543 /* CTR maintenance */
550 /*** Integer arithmetic ***/
562 if ((T2
^ T1
^ (-1)) & (T2
^ T0
) & (1 << 31)) {
593 if ((T2
^ T1
^ (-1)) & (T2
^ T0
) & (1 << 31)) {
603 /* candidate for helper (too long) */
608 if (T0
< T2
|| (xer_ca
== 1 && T0
== T2
)) {
620 if (T0
< T2
|| (xer_ca
== 1 && T0
== T2
)) {
625 if ((T2
^ T1
^ (-1)) & (T2
^ T0
) & (1 << 31)) {
641 /* add immediate carrying */
654 /* add to minus one extended */
668 if (T1
& (T1
^ T0
) & (1 << 31)) {
679 /* add to zero extended */
696 if ((T1
^ (-1)) & (T1
^ T0
) & (1 << 31)) {
711 /* candidate for helper (too long) */
714 if ((Ts0
== INT32_MIN
&& Ts1
== -1) || Ts1
== 0) {
715 Ts0
= (-1) * (T0
>> 31);
724 if ((Ts0
== INT32_MIN
&& Ts1
== -1) || Ts1
== 0) {
727 T0
= (-1) * (T0
>> 31);
735 /* divide word unsigned */
759 /* multiply high word */
762 Ts0
= ((int64_t)Ts0
* (int64_t)Ts1
) >> 32;
766 /* multiply high word unsigned */
769 T0
= ((uint64_t)T0
* (uint64_t)T1
) >> 32;
773 /* multiply low immediate */
780 /* multiply low word */
789 int64_t res
= (int64_t)Ts0
* (int64_t)Ts1
;
791 if ((int32_t)res
!= res
) {
804 if (T0
!= 0x80000000) {
812 if (T0
== 0x80000000) {
833 if (((~T2
) ^ T1
^ (-1)) & ((~T2
) ^ T0
) & (1 << 31)) {
842 /* substract from carrying */
863 if (((~T2
) ^ T1
^ (-1)) & ((~T2
) ^ T0
) & (1 << 31)) {
872 /* substract from extended */
873 /* candidate for helper (too long) */
876 T0
= T1
+ ~T0
+ xer_ca
;
877 if (T0
< T1
|| (xer_ca
== 1 && T0
== T1
)) {
888 T0
= T1
+ ~T0
+ xer_ca
;
889 if ((~T2
^ T1
^ (-1)) & (~T2
^ T0
) & (1 << 31)) {
895 if (T0
< T1
|| (xer_ca
== 1 && T0
== T1
)) {
903 /* substract from immediate carrying */
906 T0
= PARAM(1) + ~T0
+ 1;
907 if (T0
<= PARAM(1)) {
915 /* substract from minus one extended */
918 T0
= ~T0
+ xer_ca
- 1;
928 T0
= ~T0
+ xer_ca
- 1;
929 if (~T1
& (~T1
^ T0
) & (1 << 31)) {
940 /* substract from zero extended */
957 if ((~T1
^ (-1)) & ((~T1
) ^ T0
) & (1 << 31)) {
971 /*** Integer comparison ***/
977 } else if (Ts0
> Ts1
) {
985 /* compare immediate */
988 if (Ts0
< SPARAM(1)) {
990 } else if (Ts0
> SPARAM(1)) {
998 /* compare logical */
1003 } else if (T0
> T1
) {
1011 /* compare logical immediate */
1014 if (T0
< PARAM(1)) {
1016 } else if (T0
> PARAM(1)) {
1024 /*** Integer logical ***/
1046 /* count leading zero */
1050 for (T0
= 32; T1
> 0; T0
--)
1062 /* extend sign byte */
1069 /* extend sign half word */
1125 /*** Integer rotate ***/
1126 /* rotate left word immediate then mask insert */
1129 T0
= (rotl(T0
, PARAM(1)) & PARAM(2)) | (T1
& PARAM(3));
1133 /* rotate left immediate then and with mask insert */
1136 T0
= rotl(T0
, PARAM(1));
1142 T0
= T0
<< PARAM(1);
1148 T0
= T0
>> PARAM(1);
1152 /* rotate left word then and with mask insert */
1155 T0
= rotl(T0
, PARAM(1)) & PARAM(2);
1167 T0
= rotl(T0
, T1
) & PARAM(1);
1171 /*** Integer shift ***/
1172 /* shift left word */
1183 /* shift right algebraic word */
1190 /* shift right algebraic word immediate */
1194 Ts0
= Ts0
>> PARAM(1);
1195 if (Ts1
< 0 && (Ts1
& PARAM(2)) != 0) {
1203 /* shift right word */
1214 /*** Floating-Point arithmetic ***/
1222 /* fadds - fadds. */
1236 /* fsubs - fsubs. */
1250 /* fmuls - fmuls. */
1264 /* fdivs - fdivs. */
1271 /* fsqrt - fsqrt. */
1278 /* fsqrts - fsqrts. */
1292 /* frsqrte - frsqrte. */
1306 /*** Floating-Point multiply-and-add ***/
1307 /* fmadd - fmadd. */
1310 FT0
= (FT0
* FT1
) + FT2
;
1314 /* fmadds - fmadds. */
1317 FTS0
= (FTS0
* FTS1
) + FTS2
;
1321 /* fmsub - fmsub. */
1324 FT0
= (FT0
* FT1
) - FT2
;
1328 /* fmsubs - fmsubs. */
1331 FTS0
= (FTS0
* FTS1
) - FTS2
;
1335 /* fnmadd - fnmadd. - fnmadds - fnmadds. */
1342 /* fnmadds - fnmadds. */
1349 /* fnmsub - fnmsub. */
1356 /* fnmsubs - fnmsubs. */
1363 /*** Floating-Point round & convert ***/
1371 /* fctiw - fctiw. */
1378 /* fctiwz - fctiwz. */
1386 /*** Floating-Point compare ***/
1401 /*** Floating-point move ***/
1423 /* Load and store */
1424 #define MEMSUFFIX _raw
1426 #if !defined(CONFIG_USER_ONLY)
1427 #define MEMSUFFIX _user
1430 #define MEMSUFFIX _kernel
1434 /* Special op to check and maybe clear reservation */
1435 PPC_OP(check_reservation
)
1437 do_check_reservation();
1441 /* Return from interrupt */
1444 regs
->nip
= regs
->spr
[SRR0
] & ~0x00000003;
1446 T0
= regs
->spr
[SRR1
] & ~0xFFF00000;
1448 T0
= regs
->spr
[SRR1
] & ~0xFFFF0000;
1451 #if defined (DEBUG_OP)
1455 do_raise_exception(EXCP_RFI
);
1462 if ((Ts0
< Ts1
&& (PARAM(1) & 0x10)) ||
1463 (Ts0
> Ts1
&& (PARAM(1) & 0x08)) ||
1464 (Ts0
== Ts1
&& (PARAM(1) & 0x04)) ||
1465 (T0
< T1
&& (PARAM(1) & 0x02)) ||
1466 (T0
> T1
&& (PARAM(1) & 0x01)))
1467 do_raise_exception_err(EXCP_PROGRAM
, EXCP_TRAP
);
1473 if ((Ts0
< SPARAM(1) && (PARAM(2) & 0x10)) ||
1474 (Ts0
> SPARAM(1) && (PARAM(2) & 0x08)) ||
1475 (Ts0
== SPARAM(1) && (PARAM(2) & 0x04)) ||
1476 (T0
< (uint32_t)SPARAM(1) && (PARAM(2) & 0x02)) ||
1477 (T0
> (uint32_t)SPARAM(1) && (PARAM(2) & 0x01)))
1478 do_raise_exception_err(EXCP_PROGRAM
, EXCP_TRAP
);
1482 /* Instruction cache block invalidate */