Commit d9bce9d99f4656ae0b0127f7472db9067b8f84ab

Authored by j_mayer
1 parent 5fd46862

Make it safe to use 64 bits GPR and/or 64 bits host registers.

For "symetry", add 64 bits versions of all modified functions.
As a side effect, add a lot of code provision for PowerPC 64 support.
Move overflow and carry checks in common routines for simple cases.
Add isel and popcntb instructions from PowerPC 2.03 specification.
Remove remaining micro-operations helpers prototypes from op.c.
Fix XER_BC field to be 7 bits long.
Add power management support for PowerPC 603 & 604.
Fix compilation warnings.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2482 c046a42c-6fe2-441c-8c8c-71466251a162
target-ppc/cpu.h
@@ -365,6 +365,8 @@ enum { @@ -365,6 +365,8 @@ enum {
365 PPC_E500_VECTOR = 0x20000000, 365 PPC_E500_VECTOR = 0x20000000,
366 /* PowerPC 4xx dedicated instructions */ 366 /* PowerPC 4xx dedicated instructions */
367 PPC_4xx_COMMON = 0x40000000, 367 PPC_4xx_COMMON = 0x40000000,
  368 + /* PowerPC 2.03 specification extensions */
  369 + PPC_203 = 0x80000000,
368 }; 370 };
369 371
370 /* CPU run-time flags (MMU and exception model) */ 372 /* CPU run-time flags (MMU and exception model) */
@@ -385,6 +387,8 @@ enum { @@ -385,6 +387,8 @@ enum {
385 PPC_FLAGS_MMU_403 = 0x00000005, 387 PPC_FLAGS_MMU_403 = 0x00000005,
386 /* Freescale e500 MMU model */ 388 /* Freescale e500 MMU model */
387 PPC_FLAGS_MMU_e500 = 0x00000006, 389 PPC_FLAGS_MMU_e500 = 0x00000006,
  390 + /* BookE MMU model */
  391 + PPC_FLAGS_MMU_BOOKE = 0x00000007,
388 /* Exception model */ 392 /* Exception model */
389 PPC_FLAGS_EXCP_MASK = 0x000000F0, 393 PPC_FLAGS_EXCP_MASK = 0x000000F0,
390 /* Standard PowerPC exception model */ 394 /* Standard PowerPC exception model */
@@ -407,6 +411,8 @@ enum { @@ -407,6 +411,8 @@ enum {
407 PPC_FLAGS_EXCP_74xx = 0x00000080, 411 PPC_FLAGS_EXCP_74xx = 0x00000080,
408 /* PowerPC 970 exception model */ 412 /* PowerPC 970 exception model */
409 PPC_FLAGS_EXCP_970 = 0x00000090, 413 PPC_FLAGS_EXCP_970 = 0x00000090,
  414 + /* BookE exception model */
  415 + PPC_FLAGS_EXCP_BOOKE = 0x000000A0,
410 }; 416 };
411 417
412 #define PPC_MMU(env) (env->flags & PPC_FLAGS_MMU_MASK) 418 #define PPC_MMU(env) (env->flags & PPC_FLAGS_MMU_MASK)
@@ -437,11 +443,11 @@ enum { @@ -437,11 +443,11 @@ enum {
437 /* PowerPC 440 */ 443 /* PowerPC 440 */
438 #define PPC_INSNS_440 (PPC_INSNS_EMB | PPC_CACHE_OPT | PPC_BOOKE | \ 444 #define PPC_INSNS_440 (PPC_INSNS_EMB | PPC_CACHE_OPT | PPC_BOOKE | \
439 PPC_4xx_COMMON | PPC_405_MAC | PPC_440_SPEC) 445 PPC_4xx_COMMON | PPC_405_MAC | PPC_440_SPEC)
440 -#define PPC_FLAGS_440 (PPC_FLAGS_TODO) 446 +#define PPC_FLAGS_440 (PPC_FLAGS_MMU_BOOKE | PPC_FLAGS_EXCP_BOOKE)
441 /* Generic BookE PowerPC */ 447 /* Generic BookE PowerPC */
442 #define PPC_INSNS_BOOKE (PPC_INSNS_EMB | PPC_BOOKE | PPC_MEM_EIEIO | \ 448 #define PPC_INSNS_BOOKE (PPC_INSNS_EMB | PPC_BOOKE | PPC_MEM_EIEIO | \
443 PPC_FLOAT | PPC_FLOAT_OPT | PPC_CACHE_OPT) 449 PPC_FLOAT | PPC_FLOAT_OPT | PPC_CACHE_OPT)
444 -#define PPC_FLAGS_BOOKE (PPC_FLAGS_MMU_SOFT_4xx | PPC_FLAGS_EXCP_40x) 450 +#define PPC_FLAGS_BOOKE (PPC_FLAGS_MMU_BOOKE | PPC_FLAGS_EXCP_BOOKE)
445 /* e500 core */ 451 /* e500 core */
446 #define PPC_INSNS_E500 (PPC_INSNS_EMB | PPC_BOOKE | PPC_MEM_EIEIO | \ 452 #define PPC_INSNS_E500 (PPC_INSNS_EMB | PPC_BOOKE | PPC_MEM_EIEIO | \
447 PPC_CACHE_OPT | PPC_E500_VECTOR) 453 PPC_CACHE_OPT | PPC_E500_VECTOR)
@@ -502,7 +508,6 @@ typedef struct ppc_dcr_t ppc_dcr_t; @@ -502,7 +508,6 @@ typedef struct ppc_dcr_t ppc_dcr_t;
502 typedef struct ppc_avr_t ppc_avr_t; 508 typedef struct ppc_avr_t ppc_avr_t;
503 typedef struct ppc_tlb_t ppc_tlb_t; 509 typedef struct ppc_tlb_t ppc_tlb_t;
504 510
505 -  
506 /* SPR access micro-ops generations callbacks */ 511 /* SPR access micro-ops generations callbacks */
507 struct ppc_spr_t { 512 struct ppc_spr_t {
508 void (*uea_read)(void *opaque, int spr_num); 513 void (*uea_read)(void *opaque, int spr_num);
@@ -619,6 +624,8 @@ struct CPUPPCState { @@ -619,6 +624,8 @@ struct CPUPPCState {
619 */ 624 */
620 target_ulong t0, t1, t2; 625 target_ulong t0, t1, t2;
621 #endif 626 #endif
  627 + ppc_avr_t t0_avr, t1_avr, t2_avr;
  628 +
622 /* general purpose registers */ 629 /* general purpose registers */
623 ppc_gpr_t gpr[32]; 630 ppc_gpr_t gpr[32];
624 /* LR */ 631 /* LR */
@@ -674,6 +681,9 @@ struct CPUPPCState { @@ -674,6 +681,9 @@ struct CPUPPCState {
674 /* Altivec registers */ 681 /* Altivec registers */
675 ppc_avr_t avr[32]; 682 ppc_avr_t avr[32];
676 uint32_t vscr; 683 uint32_t vscr;
  684 + /* SPE registers */
  685 + ppc_gpr_t spe_acc;
  686 + uint32_t spe_fscr;
677 687
678 /* Internal devices resources */ 688 /* Internal devices resources */
679 /* Time base and decrementer */ 689 /* Time base and decrementer */
@@ -762,8 +772,10 @@ void do_store_dbatu (CPUPPCState *env, int nr, target_ulong value); @@ -762,8 +772,10 @@ void do_store_dbatu (CPUPPCState *env, int nr, target_ulong value);
762 void do_store_dbatl (CPUPPCState *env, int nr, target_ulong value); 772 void do_store_dbatl (CPUPPCState *env, int nr, target_ulong value);
763 target_ulong do_load_sdr1 (CPUPPCState *env); 773 target_ulong do_load_sdr1 (CPUPPCState *env);
764 void do_store_sdr1 (CPUPPCState *env, target_ulong value); 774 void do_store_sdr1 (CPUPPCState *env, target_ulong value);
765 -target_ulong do_load_asr (CPUPPCState *env);  
766 -void do_store_asr (CPUPPCState *env, target_ulong value); 775 +#if defined(TARGET_PPC64)
  776 +target_ulong ppc_load_asr (CPUPPCState *env);
  777 +void ppc_store_asr (CPUPPCState *env, target_ulong value);
  778 +#endif
767 target_ulong do_load_sr (CPUPPCState *env, int srnum); 779 target_ulong do_load_sr (CPUPPCState *env, int srnum);
768 void do_store_sr (CPUPPCState *env, int srnum, target_ulong value); 780 void do_store_sr (CPUPPCState *env, int srnum, target_ulong value);
769 #endif 781 #endif
@@ -771,6 +783,7 @@ uint32_t ppc_load_xer (CPUPPCState *env); @@ -771,6 +783,7 @@ uint32_t ppc_load_xer (CPUPPCState *env);
771 void ppc_store_xer (CPUPPCState *env, uint32_t value); 783 void ppc_store_xer (CPUPPCState *env, uint32_t value);
772 target_ulong do_load_msr (CPUPPCState *env); 784 target_ulong do_load_msr (CPUPPCState *env);
773 void do_store_msr (CPUPPCState *env, target_ulong value); 785 void do_store_msr (CPUPPCState *env, target_ulong value);
  786 +void ppc_store_msr32 (CPUPPCState *env, uint32_t value);
774 787
775 void do_compute_hflags (CPUPPCState *env); 788 void do_compute_hflags (CPUPPCState *env);
776 789
@@ -787,6 +800,16 @@ void cpu_ppc_store_tbu (CPUPPCState *env, uint32_t value); @@ -787,6 +800,16 @@ void cpu_ppc_store_tbu (CPUPPCState *env, uint32_t value);
787 void cpu_ppc_store_tbl (CPUPPCState *env, uint32_t value); 800 void cpu_ppc_store_tbl (CPUPPCState *env, uint32_t value);
788 uint32_t cpu_ppc_load_decr (CPUPPCState *env); 801 uint32_t cpu_ppc_load_decr (CPUPPCState *env);
789 void cpu_ppc_store_decr (CPUPPCState *env, uint32_t value); 802 void cpu_ppc_store_decr (CPUPPCState *env, uint32_t value);
  803 +uint32_t cpu_ppc601_load_rtcl (CPUPPCState *env);
  804 +uint32_t cpu_ppc601_load_rtcu (CPUPPCState *env);
  805 +#if !defined(CONFIG_USER_ONLY)
  806 +void cpu_ppc601_store_rtcl (CPUPPCState *env, uint32_t value);
  807 +void cpu_ppc601_store_rtcu (CPUPPCState *env, uint32_t value);
  808 +target_ulong load_40x_pit (CPUPPCState *env);
  809 +void store_40x_pit (CPUPPCState *env, target_ulong val);
  810 +void store_booke_tcr (CPUPPCState *env, target_ulong val);
  811 +void store_booke_tsr (CPUPPCState *env, target_ulong val);
  812 +#endif
790 #endif 813 #endif
791 814
792 #define TARGET_PAGE_BITS 12 815 #define TARGET_PAGE_BITS 12
target-ppc/exec.h
@@ -34,19 +34,25 @@ register struct CPUPPCState *env asm(AREG0); @@ -34,19 +34,25 @@ register struct CPUPPCState *env asm(AREG0);
34 #define T1 (env->t1) 34 #define T1 (env->t1)
35 #define T2 (env->t2) 35 #define T2 (env->t2)
36 #else 36 #else
37 -/* This may be more efficient if HOST_LONG_BITS > TARGET_LONG_BITS  
38 - * To be set to one when we'll be sure it does not cause bugs....  
39 - */  
40 -#if 0  
41 register unsigned long T0 asm(AREG1); 37 register unsigned long T0 asm(AREG1);
42 register unsigned long T1 asm(AREG2); 38 register unsigned long T1 asm(AREG2);
43 register unsigned long T2 asm(AREG3); 39 register unsigned long T2 asm(AREG3);
44 -#else  
45 -register target_ulong T0 asm(AREG1);  
46 -register target_ulong T1 asm(AREG2);  
47 -register target_ulong T2 asm(AREG3);  
48 #endif 40 #endif
  41 +/* We may, sometime, need 64 bits registers on 32 bits target */
  42 +#if defined(TARGET_PPC64) || (HOST_LONG_BITS == 64)
  43 +#define T0_64 T0
  44 +#define T1_64 T0
  45 +#define T2_64 T0
  46 +#else
  47 +/* no registers can be used */
  48 +#define T0_64 (env->t0)
  49 +#define T1_64 (env->t1)
  50 +#define T2_64 (env->t2)
49 #endif 51 #endif
  52 +/* Provision for Altivec */
  53 +#define T0_avr (env->t0_avr)
  54 +#define T1_avr (env->t1_avr)
  55 +#define T2_avr (env->t2_avr)
50 56
51 /* XXX: to clean: remove this mess */ 57 /* XXX: to clean: remove this mess */
52 #define PARAM(n) ((uint32_t)PARAM##n) 58 #define PARAM(n) ((uint32_t)PARAM##n)
target-ppc/helper.c
@@ -37,12 +37,12 @@ @@ -37,12 +37,12 @@
37 /*****************************************************************************/ 37 /*****************************************************************************/
38 /* PowerPC MMU emulation */ 38 /* PowerPC MMU emulation */
39 39
40 -#if defined(CONFIG_USER_ONLY) 40 +#if defined(CONFIG_USER_ONLY)
41 int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw, 41 int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
42 int is_user, int is_softmmu) 42 int is_user, int is_softmmu)
43 { 43 {
44 int exception, error_code; 44 int exception, error_code;
45 - 45 +
46 if (rw == 2) { 46 if (rw == 2) {
47 exception = EXCP_ISI; 47 exception = EXCP_ISI;
48 error_code = 0; 48 error_code = 0;
@@ -277,7 +277,7 @@ static int ppc6xx_tlb_check (CPUState *env, mmu_ctx_t *ctx, @@ -277,7 +277,7 @@ static int ppc6xx_tlb_check (CPUState *env, mmu_ctx_t *ctx,
277 ppc_tlb_t *tlb; 277 ppc_tlb_t *tlb;
278 int nr, best, way; 278 int nr, best, way;
279 int ret; 279 int ret;
280 - 280 +
281 best = -1; 281 best = -1;
282 ret = -1; /* No TLB found */ 282 ret = -1; /* No TLB found */
283 for (way = 0; way < env->nb_ways; way++) { 283 for (way = 0; way < env->nb_ways; way++) {
@@ -672,7 +672,7 @@ int get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr, @@ -672,7 +672,7 @@ int get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr,
672 if (loglevel > 0) { 672 if (loglevel > 0) {
673 fprintf(logfile, "%s\n", __func__); 673 fprintf(logfile, "%s\n", __func__);
674 } 674 }
675 -#endif 675 +#endif
676 if ((access_type == ACCESS_CODE && msr_ir == 0) || 676 if ((access_type == ACCESS_CODE && msr_ir == 0) ||
677 (access_type != ACCESS_CODE && msr_dr == 0)) { 677 (access_type != ACCESS_CODE && msr_dr == 0)) {
678 /* No address translation */ 678 /* No address translation */
@@ -693,7 +693,7 @@ int get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr, @@ -693,7 +693,7 @@ int get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr,
693 __func__, eaddr, ctx->raddr); 693 __func__, eaddr, ctx->raddr);
694 } 694 }
695 #endif 695 #endif
696 - 696 +
697 return ret; 697 return ret;
698 } 698 }
699 699
@@ -715,7 +715,7 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw, @@ -715,7 +715,7 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
715 int exception = 0, error_code = 0; 715 int exception = 0, error_code = 0;
716 int access_type; 716 int access_type;
717 int ret = 0; 717 int ret = 0;
718 - 718 +
719 if (rw == 2) { 719 if (rw == 2) {
720 /* code access */ 720 /* code access */
721 rw = 0; 721 rw = 0;
@@ -975,6 +975,21 @@ void do_store_dbatl (CPUPPCState *env, int nr, target_ulong value) @@ -975,6 +975,21 @@ void do_store_dbatl (CPUPPCState *env, int nr, target_ulong value)
975 975
976 /*****************************************************************************/ 976 /*****************************************************************************/
977 /* Special registers manipulation */ 977 /* Special registers manipulation */
  978 +#if defined(TARGET_PPC64)
  979 +target_ulong ppc_load_asr (CPUPPCState *env)
  980 +{
  981 + return env->asr;
  982 +}
  983 +
  984 +void ppc_store_asr (CPUPPCState *env, target_ulong value)
  985 +{
  986 + if (env->asr != value) {
  987 + env->asr = value;
  988 + tlb_flush(env, 1);
  989 + }
  990 +}
  991 +#endif
  992 +
978 target_ulong do_load_sdr1 (CPUPPCState *env) 993 target_ulong do_load_sdr1 (CPUPPCState *env)
979 { 994 {
980 return env->sdr1; 995 return env->sdr1;
@@ -1039,7 +1054,7 @@ void ppc_store_xer (CPUPPCState *env, uint32_t value) @@ -1039,7 +1054,7 @@ void ppc_store_xer (CPUPPCState *env, uint32_t value)
1039 xer_ov = (value >> XER_OV) & 0x01; 1054 xer_ov = (value >> XER_OV) & 0x01;
1040 xer_ca = (value >> XER_CA) & 0x01; 1055 xer_ca = (value >> XER_CA) & 0x01;
1041 xer_cmp = (value >> XER_CMP) & 0xFF; 1056 xer_cmp = (value >> XER_CMP) & 0xFF;
1042 - xer_bc = (value >> XER_BC) & 0x3F; 1057 + xer_bc = (value >> XER_BC) & 0x7F;
1043 } 1058 }
1044 1059
1045 /* Swap temporary saved registers with GPRs */ 1060 /* Swap temporary saved registers with GPRs */
@@ -1066,34 +1081,34 @@ target_ulong do_load_msr (CPUPPCState *env) @@ -1066,34 +1081,34 @@ target_ulong do_load_msr (CPUPPCState *env)
1066 { 1081 {
1067 return 1082 return
1068 #if defined (TARGET_PPC64) 1083 #if defined (TARGET_PPC64)
1069 - (msr_sf << MSR_SF) |  
1070 - (msr_isf << MSR_ISF) |  
1071 - (msr_hv << MSR_HV) | 1084 + ((target_ulong)msr_sf << MSR_SF) |
  1085 + ((target_ulong)msr_isf << MSR_ISF) |
  1086 + ((target_ulong)msr_hv << MSR_HV) |
1072 #endif 1087 #endif
1073 - (msr_ucle << MSR_UCLE) |  
1074 - (msr_vr << MSR_VR) | /* VR / SPE */  
1075 - (msr_ap << MSR_AP) |  
1076 - (msr_sa << MSR_SA) |  
1077 - (msr_key << MSR_KEY) |  
1078 - (msr_pow << MSR_POW) | /* POW / WE */  
1079 - (msr_tlb << MSR_TLB) | /* TLB / TGPE / CE */  
1080 - (msr_ile << MSR_ILE) |  
1081 - (msr_ee << MSR_EE) |  
1082 - (msr_pr << MSR_PR) |  
1083 - (msr_fp << MSR_FP) |  
1084 - (msr_me << MSR_ME) |  
1085 - (msr_fe0 << MSR_FE0) |  
1086 - (msr_se << MSR_SE) | /* SE / DWE / UBLE */  
1087 - (msr_be << MSR_BE) | /* BE / DE */  
1088 - (msr_fe1 << MSR_FE1) |  
1089 - (msr_al << MSR_AL) |  
1090 - (msr_ip << MSR_IP) |  
1091 - (msr_ir << MSR_IR) | /* IR / IS */  
1092 - (msr_dr << MSR_DR) | /* DR / DS */  
1093 - (msr_pe << MSR_PE) | /* PE / EP */  
1094 - (msr_px << MSR_PX) | /* PX / PMM */  
1095 - (msr_ri << MSR_RI) |  
1096 - (msr_le << MSR_LE); 1088 + ((target_ulong)msr_ucle << MSR_UCLE) |
  1089 + ((target_ulong)msr_vr << MSR_VR) | /* VR / SPE */
  1090 + ((target_ulong)msr_ap << MSR_AP) |
  1091 + ((target_ulong)msr_sa << MSR_SA) |
  1092 + ((target_ulong)msr_key << MSR_KEY) |
  1093 + ((target_ulong)msr_pow << MSR_POW) | /* POW / WE */
  1094 + ((target_ulong)msr_tlb << MSR_TLB) | /* TLB / TGPE / CE */
  1095 + ((target_ulong)msr_ile << MSR_ILE) |
  1096 + ((target_ulong)msr_ee << MSR_EE) |
  1097 + ((target_ulong)msr_pr << MSR_PR) |
  1098 + ((target_ulong)msr_fp << MSR_FP) |
  1099 + ((target_ulong)msr_me << MSR_ME) |
  1100 + ((target_ulong)msr_fe0 << MSR_FE0) |
  1101 + ((target_ulong)msr_se << MSR_SE) | /* SE / DWE / UBLE */
  1102 + ((target_ulong)msr_be << MSR_BE) | /* BE / DE */
  1103 + ((target_ulong)msr_fe1 << MSR_FE1) |
  1104 + ((target_ulong)msr_al << MSR_AL) |
  1105 + ((target_ulong)msr_ip << MSR_IP) |
  1106 + ((target_ulong)msr_ir << MSR_IR) | /* IR / IS */
  1107 + ((target_ulong)msr_dr << MSR_DR) | /* DR / DS */
  1108 + ((target_ulong)msr_pe << MSR_PE) | /* PE / EP */
  1109 + ((target_ulong)msr_px << MSR_PX) | /* PX / PMM */
  1110 + ((target_ulong)msr_ri << MSR_RI) |
  1111 + ((target_ulong)msr_le << MSR_LE);
1097 } 1112 }
1098 1113
1099 void do_store_msr (CPUPPCState *env, target_ulong value) 1114 void do_store_msr (CPUPPCState *env, target_ulong value)
@@ -1156,6 +1171,17 @@ void do_store_msr (CPUPPCState *env, target_ulong value) @@ -1156,6 +1171,17 @@ void do_store_msr (CPUPPCState *env, target_ulong value)
1156 1171
1157 enter_pm = 0; 1172 enter_pm = 0;
1158 switch (PPC_EXCP(env)) { 1173 switch (PPC_EXCP(env)) {
  1174 + case PPC_FLAGS_EXCP_603:
  1175 + /* Don't handle SLEEP mode: we should disable all clocks...
  1176 + * No dynamic power-management.
  1177 + */
  1178 + if (msr_pow == 1 && (env->spr[SPR_HID0] & 0x00C00000) != 0)
  1179 + enter_pm = 1;
  1180 + break;
  1181 + case PPC_FLAGS_EXCP_604:
  1182 + if (msr_pow == 1)
  1183 + enter_pm = 1;
  1184 + break;
1159 case PPC_FLAGS_EXCP_7x0: 1185 case PPC_FLAGS_EXCP_7x0:
1160 if (msr_pow == 1 && (env->spr[SPR_HID0] & 0x00E00000) != 0) 1186 if (msr_pow == 1 && (env->spr[SPR_HID0] & 0x00E00000) != 0)
1161 enter_pm = 1; 1187 enter_pm = 1;
@@ -1171,15 +1197,22 @@ void do_store_msr (CPUPPCState *env, target_ulong value) @@ -1171,15 +1197,22 @@ void do_store_msr (CPUPPCState *env, target_ulong value)
1171 } 1197 }
1172 } 1198 }
1173 1199
  1200 +#if defined(TARGET_PPC64)
  1201 +void ppc_store_msr_32 (CPUPPCState *env, target_ulong value)
  1202 +{
  1203 + do_store_msr(env, (uint32_t)value);
  1204 +}
  1205 +#endif
  1206 +
1174 void do_compute_hflags (CPUPPCState *env) 1207 void do_compute_hflags (CPUPPCState *env)
1175 { 1208 {
1176 /* Compute current hflags */ 1209 /* Compute current hflags */
1177 env->hflags = (msr_pr << MSR_PR) | (msr_le << MSR_LE) | 1210 env->hflags = (msr_pr << MSR_PR) | (msr_le << MSR_LE) |
1178 (msr_fp << MSR_FP) | (msr_fe0 << MSR_FE0) | (msr_fe1 << MSR_FE1) | 1211 (msr_fp << MSR_FP) | (msr_fe0 << MSR_FE0) | (msr_fe1 << MSR_FE1) |
1179 - (msr_vr << MSR_VR) | (msr_ap << MSR_AP) | (msr_sa << MSR_SA) | 1212 + (msr_vr << MSR_VR) | (msr_ap << MSR_AP) | (msr_sa << MSR_SA) |
1180 (msr_se << MSR_SE) | (msr_be << MSR_BE); 1213 (msr_se << MSR_SE) | (msr_be << MSR_BE);
1181 #if defined (TARGET_PPC64) 1214 #if defined (TARGET_PPC64)
1182 - env->hflags |= (msr_sf << MSR_SF) | (msr_hv << MSR_HV); 1215 + env->hflags |= (msr_sf << (MSR_SF - 32)) | (msr_hv << (MSR_HV - 32));
1183 #endif 1216 #endif
1184 } 1217 }
1185 1218
@@ -1193,8 +1226,8 @@ void do_interrupt (CPUState *env) @@ -1193,8 +1226,8 @@ void do_interrupt (CPUState *env)
1193 #else /* defined (CONFIG_USER_ONLY) */ 1226 #else /* defined (CONFIG_USER_ONLY) */
1194 static void dump_syscall(CPUState *env) 1227 static void dump_syscall(CPUState *env)
1195 { 1228 {
1196 - fprintf(logfile, "syscall r0=0x%08x r3=0x%08x r4=0x%08x "  
1197 - "r5=0x%08x r6=0x%08x nip=0x%08x\n", 1229 + fprintf(logfile, "syscall r0=0x" REGX " r3=0x" REGX " r4=0x" REGX
  1230 + " r5=0x" REGX " r6=0x" REGX " nip=0x" REGX "\n",
1198 env->gpr[0], env->gpr[3], env->gpr[4], 1231 env->gpr[0], env->gpr[3], env->gpr[4],
1199 env->gpr[5], env->gpr[6], env->nip); 1232 env->gpr[5], env->gpr[6], env->nip);
1200 } 1233 }
target-ppc/op.c
@@ -26,9 +26,6 @@ @@ -26,9 +26,6 @@
26 26
27 /* XXX: this is to be suppressed */ 27 /* XXX: this is to be suppressed */
28 #define regs (env) 28 #define regs (env)
29 -#define Ts0 (int32_t)T0  
30 -#define Ts1 (int32_t)T1  
31 -#define Ts2 (int32_t)T2  
32 29
33 #define FT0 (env->ft0) 30 #define FT0 (env->ft0)
34 #define FT1 (env->ft1) 31 #define FT1 (env->ft1)
@@ -157,15 +154,31 @@ void OPPROTO op_reset_T0 (void) @@ -157,15 +154,31 @@ void OPPROTO op_reset_T0 (void)
157 154
158 PPC_OP(set_T0) 155 PPC_OP(set_T0)
159 { 156 {
160 - T0 = PARAM(1); 157 + T0 = (uint32_t)PARAM1;
161 RETURN(); 158 RETURN();
162 } 159 }
163 160
  161 +#if defined(TARGET_PPC64)
  162 +void OPPROTO op_set_T0_64 (void)
  163 +{
  164 + T0 = ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
  165 + RETURN();
  166 +}
  167 +#endif
  168 +
164 PPC_OP(set_T1) 169 PPC_OP(set_T1)
165 { 170 {
166 - T1 = PARAM(1); 171 + T1 = (uint32_t)PARAM1;
  172 + RETURN();
  173 +}
  174 +
  175 +#if defined(TARGET_PPC64)
  176 +void OPPROTO op_set_T1_64 (void)
  177 +{
  178 + T1 = ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
167 RETURN(); 179 RETURN();
168 } 180 }
  181 +#endif
169 182
170 #if 0 // unused 183 #if 0 // unused
171 PPC_OP(set_T2) 184 PPC_OP(set_T2)
@@ -181,6 +194,12 @@ void OPPROTO op_move_T1_T0 (void) @@ -181,6 +194,12 @@ void OPPROTO op_move_T1_T0 (void)
181 RETURN(); 194 RETURN();
182 } 195 }
183 196
  197 +void OPPROTO op_move_T2_T0 (void)
  198 +{
  199 + T2 = T0;
  200 + RETURN();
  201 +}
  202 +
184 /* Generate exceptions */ 203 /* Generate exceptions */
185 PPC_OP(raise_exception_err) 204 PPC_OP(raise_exception_err)
186 { 205 {
@@ -189,16 +208,23 @@ PPC_OP(raise_exception_err) @@ -189,16 +208,23 @@ PPC_OP(raise_exception_err)
189 208
190 PPC_OP(update_nip) 209 PPC_OP(update_nip)
191 { 210 {
192 - env->nip = PARAM(1); 211 + env->nip = (uint32_t)PARAM1;
193 RETURN(); 212 RETURN();
194 } 213 }
195 214
  215 +#if defined(TARGET_PPC64)
  216 +void OPPROTO op_update_nip_64 (void)
  217 +{
  218 + env->nip = ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
  219 + RETURN();
  220 +}
  221 +#endif
  222 +
196 PPC_OP(debug) 223 PPC_OP(debug)
197 { 224 {
198 do_raise_exception(EXCP_DEBUG); 225 do_raise_exception(EXCP_DEBUG);
199 } 226 }
200 227
201 -  
202 PPC_OP(exit_tb) 228 PPC_OP(exit_tb)
203 { 229 {
204 EXIT_TB(); 230 EXIT_TB();
@@ -293,6 +319,20 @@ PPC_OP(store_sdr1) @@ -293,6 +319,20 @@ PPC_OP(store_sdr1)
293 RETURN(); 319 RETURN();
294 } 320 }
295 321
  322 +#if defined (TARGET_PPC64)
  323 +void OPPROTO op_load_asr (void)
  324 +{
  325 + T0 = env->asr;
  326 + RETURN();
  327 +}
  328 +
  329 +void OPPROTO op_store_asr (void)
  330 +{
  331 + ppc_store_asr(env, T0);
  332 + RETURN();
  333 +}
  334 +#endif
  335 +
296 PPC_OP(load_msr) 336 PPC_OP(load_msr)
297 { 337 {
298 T0 = do_load_msr(env); 338 T0 = do_load_msr(env);
@@ -304,6 +344,14 @@ PPC_OP(store_msr) @@ -304,6 +344,14 @@ PPC_OP(store_msr)
304 do_store_msr(env, T0); 344 do_store_msr(env, T0);
305 RETURN(); 345 RETURN();
306 } 346 }
  347 +
  348 +#if defined (TARGET_PPC64)
  349 +void OPPROTO op_store_msr_32 (void)
  350 +{
  351 + ppc_store_msr_32(env, T0);
  352 + RETURN();
  353 +}
  354 +#endif
307 #endif 355 #endif
308 356
309 /* SPR */ 357 /* SPR */
@@ -459,7 +507,7 @@ PPC_OP(getbit_T1) @@ -459,7 +507,7 @@ PPC_OP(getbit_T1)
459 507
460 PPC_OP(setcrfbit) 508 PPC_OP(setcrfbit)
461 { 509 {
462 - T1 = (T1 & PARAM(1)) | (T0 << PARAM(2)); 510 + T1 = (T1 & PARAM(1)) | (T0 << PARAM(2));
463 RETURN(); 511 RETURN();
464 } 512 }
465 513
@@ -468,10 +516,18 @@ PPC_OP(setcrfbit) @@ -468,10 +516,18 @@ PPC_OP(setcrfbit)
468 516
469 PPC_OP(setlr) 517 PPC_OP(setlr)
470 { 518 {
471 - regs->lr = PARAM1; 519 + regs->lr = (uint32_t)PARAM1;
472 RETURN(); 520 RETURN();
473 } 521 }
474 522
  523 +#if defined (TARGET_PPC64)
  524 +void OPPROTO op_setlr_64 (void)
  525 +{
  526 + regs->lr = ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
  527 + RETURN();
  528 +}
  529 +#endif
  530 +
475 PPC_OP(goto_tb0) 531 PPC_OP(goto_tb0)
476 { 532 {
477 GOTO_TB(op_goto_tb0, PARAM1, 0); 533 GOTO_TB(op_goto_tb0, PARAM1, 0);
@@ -482,12 +538,20 @@ PPC_OP(goto_tb1) @@ -482,12 +538,20 @@ PPC_OP(goto_tb1)
482 GOTO_TB(op_goto_tb1, PARAM1, 1); 538 GOTO_TB(op_goto_tb1, PARAM1, 1);
483 } 539 }
484 540
485 -PPC_OP(b_T1) 541 +void OPPROTO op_b_T1 (void)
486 { 542 {
487 - regs->nip = T1 & ~3; 543 + regs->nip = (uint32_t)(T1 & ~3);
488 RETURN(); 544 RETURN();
489 } 545 }
490 546
  547 +#if defined (TARGET_PPC64)
  548 +void OPPROTO op_b_T1_64 (void)
  549 +{
  550 + regs->nip = (uint64_t)(T1 & ~3);
  551 + RETURN();
  552 +}
  553 +#endif
  554 +
491 PPC_OP(jz_T0) 555 PPC_OP(jz_T0)
492 { 556 {
493 if (!T0) 557 if (!T0)
@@ -495,16 +559,28 @@ PPC_OP(jz_T0) @@ -495,16 +559,28 @@ PPC_OP(jz_T0)
495 RETURN(); 559 RETURN();
496 } 560 }
497 561
498 -PPC_OP(btest_T1) 562 +void OPPROTO op_btest_T1 (void)
499 { 563 {
500 if (T0) { 564 if (T0) {
501 - regs->nip = T1 & ~3; 565 + regs->nip = (uint32_t)(T1 & ~3);
502 } else { 566 } else {
503 - regs->nip = PARAM1; 567 + regs->nip = (uint32_t)PARAM1;
504 } 568 }
505 RETURN(); 569 RETURN();
506 } 570 }
507 571
  572 +#if defined (TARGET_PPC64)
  573 +void OPPROTO op_btest_T1_64 (void)
  574 +{
  575 + if (T0) {
  576 + regs->nip = (uint64_t)(T1 & ~3);
  577 + } else {
  578 + regs->nip = ((uint64_t)PARAM1 << 32) | (uint64_t)PARAM2;
  579 + }
  580 + RETURN();
  581 +}
  582 +#endif
  583 +
508 PPC_OP(movl_T1_ctr) 584 PPC_OP(movl_T1_ctr)
509 { 585 {
510 T1 = regs->ctr; 586 T1 = regs->ctr;
@@ -518,42 +594,89 @@ PPC_OP(movl_T1_lr) @@ -518,42 +594,89 @@ PPC_OP(movl_T1_lr)
518 } 594 }
519 595
520 /* tests with result in T0 */ 596 /* tests with result in T0 */
  597 +void OPPROTO op_test_ctr (void)
  598 +{
  599 + T0 = (uint32_t)regs->ctr;
  600 + RETURN();
  601 +}
521 602
522 -PPC_OP(test_ctr) 603 +#if defined(TARGET_PPC64)
  604 +void OPPROTO op_test_ctr_64 (void)
523 { 605 {
524 - T0 = regs->ctr; 606 + T0 = (uint64_t)regs->ctr;
  607 + RETURN();
  608 +}
  609 +#endif
  610 +
  611 +void OPPROTO op_test_ctr_true (void)
  612 +{
  613 + T0 = ((uint32_t)regs->ctr != 0 && (T0 & PARAM1) != 0);
525 RETURN(); 614 RETURN();
526 } 615 }
527 616
528 -PPC_OP(test_ctr_true) 617 +#if defined(TARGET_PPC64)
  618 +void OPPROTO op_test_ctr_true_64 (void)
529 { 619 {
530 - T0 = (regs->ctr != 0 && (T0 & PARAM(1)) != 0); 620 + T0 = ((uint64_t)regs->ctr != 0 && (T0 & PARAM1) != 0);
531 RETURN(); 621 RETURN();
532 } 622 }
  623 +#endif
533 624
534 -PPC_OP(test_ctr_false) 625 +void OPPROTO op_test_ctr_false (void)
535 { 626 {
536 - T0 = (regs->ctr != 0 && (T0 & PARAM(1)) == 0); 627 + T0 = ((uint32_t)regs->ctr != 0 && (T0 & PARAM1) == 0);
537 RETURN(); 628 RETURN();
538 } 629 }
539 630
540 -PPC_OP(test_ctrz) 631 +#if defined(TARGET_PPC64)
  632 +void OPPROTO op_test_ctr_false_64 (void)
541 { 633 {
542 - T0 = (regs->ctr == 0); 634 + T0 = ((uint64_t)regs->ctr != 0 && (T0 & PARAM1) == 0);
543 RETURN(); 635 RETURN();
544 } 636 }
  637 +#endif
  638 +
  639 +void OPPROTO op_test_ctrz (void)
  640 +{
  641 + T0 = ((uint32_t)regs->ctr == 0);
  642 + RETURN();
  643 +}
  644 +
  645 +#if defined(TARGET_PPC64)
  646 +void OPPROTO op_test_ctrz_64 (void)
  647 +{
  648 + T0 = ((uint64_t)regs->ctr == 0);
  649 + RETURN();
  650 +}
  651 +#endif
  652 +
  653 +void OPPROTO op_test_ctrz_true (void)
  654 +{
  655 + T0 = ((uint32_t)regs->ctr == 0 && (T0 & PARAM1) != 0);
  656 + RETURN();
  657 +}
  658 +
  659 +#if defined(TARGET_PPC64)
  660 +void OPPROTO op_test_ctrz_true_64 (void)
  661 +{
  662 + T0 = ((uint64_t)regs->ctr == 0 && (T0 & PARAM1) != 0);
  663 + RETURN();
  664 +}
  665 +#endif
545 666
546 -PPC_OP(test_ctrz_true) 667 +void OPPROTO op_test_ctrz_false (void)
547 { 668 {
548 - T0 = (regs->ctr == 0 && (T0 & PARAM(1)) != 0); 669 + T0 = ((uint32_t)regs->ctr == 0 && (T0 & PARAM1) == 0);
549 RETURN(); 670 RETURN();
550 } 671 }
551 672
552 -PPC_OP(test_ctrz_false) 673 +#if defined(TARGET_PPC64)
  674 +void OPPROTO op_test_ctrz_false_64 (void)
553 { 675 {
554 - T0 = (regs->ctr == 0 && (T0 & PARAM(1)) == 0); 676 + T0 = ((uint64_t)regs->ctr == 0 && (T0 & PARAM1) == 0);
555 RETURN(); 677 RETURN();
556 } 678 }
  679 +#endif
557 680
558 PPC_OP(test_true) 681 PPC_OP(test_true)
559 { 682 {
@@ -582,30 +705,52 @@ PPC_OP(add) @@ -582,30 +705,52 @@ PPC_OP(add)
582 RETURN(); 705 RETURN();
583 } 706 }
584 707
585 -void OPPROTO op_addo (void) 708 +void OPPROTO op_check_addo (void)
586 { 709 {
587 - do_addo();  
588 - RETURN(); 710 + if (likely(!(((uint32_t)T2 ^ (uint32_t)T1 ^ UINT32_MAX) &
  711 + ((uint32_t)T2 ^ (uint32_t)T0) & (1UL << 31)))) {
  712 + xer_ov = 0;
  713 + } else {
  714 + xer_so = 1;
  715 + xer_ov = 1;
  716 + }
589 } 717 }
590 718
591 -/* add carrying */  
592 -PPC_OP(addc) 719 +#if defined(TARGET_PPC64)
  720 +void OPPROTO op_check_addo_64 (void)
593 { 721 {
594 - T2 = T0;  
595 - T0 += T1;  
596 - if (T0 < T2) {  
597 - xer_ca = 1; 722 + if (likely(!(((uint64_t)T2 ^ (uint64_t)T1 ^ UINT64_MAX) &
  723 + ((uint64_t)T2 ^ (uint64_t)T0) & (1UL << 63)))) {
  724 + xer_ov = 0;
598 } else { 725 } else {
  726 + xer_so = 1;
  727 + xer_ov = 1;
  728 + }
  729 +}
  730 +#endif
  731 +
  732 +/* add carrying */
  733 +void OPPROTO op_check_addc (void)
  734 +{
  735 + if (likely((uint32_t)T0 >= (uint32_t)T2)) {
599 xer_ca = 0; 736 xer_ca = 0;
  737 + } else {
  738 + xer_ca = 1;
600 } 739 }
601 RETURN(); 740 RETURN();
602 } 741 }
603 742
604 -void OPPROTO op_addco (void) 743 +#if defined(TARGET_PPC64)
  744 +void OPPROTO op_check_addc_64 (void)
605 { 745 {
606 - do_addco(); 746 + if (likely((uint64_t)T0 >= (uint64_t)T2)) {
  747 + xer_ca = 0;
  748 + } else {
  749 + xer_ca = 1;
  750 + }
607 RETURN(); 751 RETURN();
608 } 752 }
  753 +#endif
609 754
610 /* add extended */ 755 /* add extended */
611 void OPPROTO op_adde (void) 756 void OPPROTO op_adde (void)
@@ -614,11 +759,13 @@ void OPPROTO op_adde (void) @@ -614,11 +759,13 @@ void OPPROTO op_adde (void)
614 RETURN(); 759 RETURN();
615 } 760 }
616 761
617 -PPC_OP(addeo) 762 +#if defined(TARGET_PPC64)
  763 +void OPPROTO op_adde_64 (void)
618 { 764 {
619 - do_addeo(); 765 + do_adde_64();
620 RETURN(); 766 RETURN();
621 } 767 }
  768 +#endif
622 769
623 /* add immediate */ 770 /* add immediate */
624 PPC_OP(addi) 771 PPC_OP(addi)
@@ -627,28 +774,24 @@ PPC_OP(addi) @@ -627,28 +774,24 @@ PPC_OP(addi)
627 RETURN(); 774 RETURN();
628 } 775 }
629 776
630 -/* add immediate carrying */  
631 -PPC_OP(addic) 777 +/* add to minus one extended */
  778 +void OPPROTO op_add_me (void)
632 { 779 {
633 - T1 = T0;  
634 - T0 += PARAM(1);  
635 - if (T0 < T1) { 780 + T0 += xer_ca + (-1);
  781 + if (likely((uint32_t)T1 != 0))
636 xer_ca = 1; 782 xer_ca = 1;
637 - } else {  
638 - xer_ca = 0;  
639 - }  
640 RETURN(); 783 RETURN();
641 } 784 }
642 785
643 -/* add to minus one extended */  
644 -PPC_OP(addme) 786 +#if defined(TARGET_PPC64)
  787 +void OPPROTO op_add_me_64 (void)
645 { 788 {
646 - T1 = T0;  
647 T0 += xer_ca + (-1); 789 T0 += xer_ca + (-1);
648 - if (T1 != 0) 790 + if (likely((uint64_t)T1 != 0))
649 xer_ca = 1; 791 xer_ca = 1;
650 RETURN(); 792 RETURN();
651 } 793 }
  794 +#endif
652 795
653 void OPPROTO op_addmeo (void) 796 void OPPROTO op_addmeo (void)
654 { 797 {
@@ -656,35 +799,43 @@ void OPPROTO op_addmeo (void) @@ -656,35 +799,43 @@ void OPPROTO op_addmeo (void)
656 RETURN(); 799 RETURN();
657 } 800 }
658 801
  802 +void OPPROTO op_addmeo_64 (void)
  803 +{
  804 + do_addmeo();
  805 + RETURN();
  806 +}
  807 +
659 /* add to zero extended */ 808 /* add to zero extended */
660 -PPC_OP(addze) 809 +void OPPROTO op_add_ze (void)
661 { 810 {
662 - T1 = T0;  
663 T0 += xer_ca; 811 T0 += xer_ca;
664 - if (T0 < T1) {  
665 - xer_ca = 1;  
666 - } else {  
667 - xer_ca = 0;  
668 - }  
669 RETURN(); 812 RETURN();
670 } 813 }
671 814
672 -void OPPROTO op_addzeo (void) 815 +/* divide word */
  816 +void OPPROTO op_divw (void)
673 { 817 {
674 - do_addzeo(); 818 + if (unlikely(((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) ||
  819 + (int32_t)T1 == 0)) {
  820 + T0 = (int32_t)((-1) * ((uint32_t)T0 >> 31));
  821 + } else {
  822 + T0 = (int32_t)T0 / (int32_t)T1;
  823 + }
675 RETURN(); 824 RETURN();
676 } 825 }
677 826
678 -/* divide word */  
679 -PPC_OP(divw) 827 +#if defined(TARGET_PPC64)
  828 +void OPPROTO op_divd (void)
680 { 829 {
681 - if ((Ts0 == INT32_MIN && Ts1 == -1) || Ts1 == 0) {  
682 - T0 = (int32_t)((-1) * (T0 >> 31)); 830 + if (unlikely(((int64_t)T0 == INT64_MIN && (int64_t)T1 == -1) ||
  831 + (int64_t)T1 == 0)) {
  832 + T0 = (int64_t)((-1ULL) * ((uint64_t)T0 >> 63));
683 } else { 833 } else {
684 - T0 = (Ts0 / Ts1); 834 + T0 = (int64_t)T0 / (int64_t)T1;
685 } 835 }
686 RETURN(); 836 RETURN();
687 } 837 }
  838 +#endif
688 839
689 void OPPROTO op_divwo (void) 840 void OPPROTO op_divwo (void)
690 { 841 {
@@ -692,16 +843,36 @@ void OPPROTO op_divwo (void) @@ -692,16 +843,36 @@ void OPPROTO op_divwo (void)
692 RETURN(); 843 RETURN();
693 } 844 }
694 845
  846 +#if defined(TARGET_PPC64)
  847 +void OPPROTO op_divdo (void)
  848 +{
  849 + do_divdo();
  850 + RETURN();
  851 +}
  852 +#endif
  853 +
695 /* divide word unsigned */ 854 /* divide word unsigned */
696 -PPC_OP(divwu) 855 +void OPPROTO op_divwu (void)
  856 +{
  857 + if (unlikely(T1 == 0)) {
  858 + T0 = 0;
  859 + } else {
  860 + T0 = (uint32_t)T0 / (uint32_t)T1;
  861 + }
  862 + RETURN();
  863 +}
  864 +
  865 +#if defined(TARGET_PPC64)
  866 +void OPPROTO op_divdu (void)
697 { 867 {
698 - if (T1 == 0) { 868 + if (unlikely(T1 == 0)) {
699 T0 = 0; 869 T0 = 0;
700 } else { 870 } else {
701 T0 /= T1; 871 T0 /= T1;
702 } 872 }
703 RETURN(); 873 RETURN();
704 } 874 }
  875 +#endif
705 876
706 void OPPROTO op_divwuo (void) 877 void OPPROTO op_divwuo (void)
707 { 878 {
@@ -709,33 +880,71 @@ void OPPROTO op_divwuo (void) @@ -709,33 +880,71 @@ void OPPROTO op_divwuo (void)
709 RETURN(); 880 RETURN();
710 } 881 }
711 882
  883 +#if defined(TARGET_PPC64)
  884 +void OPPROTO op_divduo (void)
  885 +{
  886 + do_divduo();
  887 + RETURN();
  888 +}
  889 +#endif
  890 +
712 /* multiply high word */ 891 /* multiply high word */
713 -PPC_OP(mulhw) 892 +void OPPROTO op_mulhw (void)
714 { 893 {
715 - T0 = ((int64_t)Ts0 * (int64_t)Ts1) >> 32; 894 + T0 = ((int64_t)((int32_t)T0) * (int64_t)((int32_t)T1)) >> 32;
716 RETURN(); 895 RETURN();
717 } 896 }
718 897
  898 +#if defined(TARGET_PPC64)
  899 +void OPPROTO op_mulhd (void)
  900 +{
  901 + uint64_t tl, th;
  902 +
  903 + do_imul64(&tl, &th);
  904 + T0 = th;
  905 + RETURN();
  906 +}
  907 +#endif
  908 +
719 /* multiply high word unsigned */ 909 /* multiply high word unsigned */
720 -PPC_OP(mulhwu) 910 +void OPPROTO op_mulhwu (void)
721 { 911 {
722 - T0 = ((uint64_t)T0 * (uint64_t)T1) >> 32; 912 + T0 = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1) >> 32;
723 RETURN(); 913 RETURN();
724 } 914 }
725 915
  916 +#if defined(TARGET_PPC64)
  917 +void OPPROTO op_mulhdu (void)
  918 +{
  919 + uint64_t tl, th;
  920 +
  921 + do_mul64(&tl, &th);
  922 + T0 = th;
  923 + RETURN();
  924 +}
  925 +#endif
  926 +
726 /* multiply low immediate */ 927 /* multiply low immediate */
727 PPC_OP(mulli) 928 PPC_OP(mulli)
728 { 929 {
729 - T0 = (Ts0 * SPARAM(1)); 930 + T0 = ((int32_t)T0 * (int32_t)PARAM1);
730 RETURN(); 931 RETURN();
731 } 932 }
732 933
733 /* multiply low word */ 934 /* multiply low word */
734 PPC_OP(mullw) 935 PPC_OP(mullw)
735 { 936 {
  937 + T0 = (int32_t)(T0 * T1);
  938 + RETURN();
  939 +}
  940 +
  941 +#if defined(TARGET_PPC64)
  942 +void OPPROTO op_mulld (void)
  943 +{
736 T0 *= T1; 944 T0 *= T1;
737 RETURN(); 945 RETURN();
738 } 946 }
  947 +#endif
739 948
740 void OPPROTO op_mullwo (void) 949 void OPPROTO op_mullwo (void)
741 { 950 {
@@ -743,21 +952,47 @@ void OPPROTO op_mullwo (void) @@ -743,21 +952,47 @@ void OPPROTO op_mullwo (void)
743 RETURN(); 952 RETURN();
744 } 953 }
745 954
  955 +#if defined(TARGET_PPC64)
  956 +void OPPROTO op_mulldo (void)
  957 +{
  958 + do_mulldo();
  959 + RETURN();
  960 +}
  961 +#endif
  962 +
746 /* negate */ 963 /* negate */
747 -PPC_OP(neg) 964 +void OPPROTO op_neg (void)
748 { 965 {
749 - if (T0 != 0x80000000) {  
750 - T0 = -Ts0; 966 + if (likely(T0 != INT32_MIN)) {
  967 + T0 = -(int32_t)T0;
751 } 968 }
752 RETURN(); 969 RETURN();
753 } 970 }
754 971
  972 +#if defined(TARGET_PPC64)
  973 +void OPPROTO op_neg_64 (void)
  974 +{
  975 + if (likely(T0 != INT64_MIN)) {
  976 + T0 = -(int64_t)T0;
  977 + }
  978 + RETURN();
  979 +}
  980 +#endif
  981 +
755 void OPPROTO op_nego (void) 982 void OPPROTO op_nego (void)
756 { 983 {
757 do_nego(); 984 do_nego();
758 RETURN(); 985 RETURN();
759 } 986 }
760 987
  988 +#if defined(TARGET_PPC64)
  989 +void OPPROTO op_nego_64 (void)
  990 +{
  991 + do_nego_64();
  992 + RETURN();
  993 +}
  994 +#endif
  995 +
761 /* substract from */ 996 /* substract from */
762 PPC_OP(subf) 997 PPC_OP(subf)
763 { 998 {
@@ -765,29 +1000,54 @@ PPC_OP(subf) @@ -765,29 +1000,54 @@ PPC_OP(subf)
765 RETURN(); 1000 RETURN();
766 } 1001 }
767 1002
768 -void OPPROTO op_subfo (void) 1003 +void OPPROTO op_check_subfo (void)
  1004 +{
  1005 + if (likely(!(((uint32_t)(~T2) ^ (uint32_t)T1 ^ UINT32_MAX) &
  1006 + ((uint32_t)(~T2) ^ (uint32_t)T0) & (1UL << 31)))) {
  1007 + xer_ov = 0;
  1008 + } else {
  1009 + xer_so = 1;
  1010 + xer_ov = 1;
  1011 + }
  1012 + RETURN();
  1013 +}
  1014 +
  1015 +#if defined(TARGET_PPC64)
  1016 +void OPPROTO op_check_subfo_64 (void)
769 { 1017 {
770 - do_subfo(); 1018 + if (likely(!(((uint64_t)(~T2) ^ (uint64_t)T1 ^ UINT64_MAX) &
  1019 + ((uint64_t)(~T2) ^ (uint64_t)T0) & (1ULL << 63)))) {
  1020 + xer_ov = 0;
  1021 + } else {
  1022 + xer_so = 1;
  1023 + xer_ov = 1;
  1024 + }
771 RETURN(); 1025 RETURN();
772 } 1026 }
  1027 +#endif
773 1028
774 /* substract from carrying */ 1029 /* substract from carrying */
775 -PPC_OP(subfc) 1030 +void OPPROTO op_check_subfc (void)
776 { 1031 {
777 - T0 = T1 - T0;  
778 - if (T0 <= T1) {  
779 - xer_ca = 1;  
780 - } else { 1032 + if (likely((uint32_t)T0 > (uint32_t)T1)) {
781 xer_ca = 0; 1033 xer_ca = 0;
  1034 + } else {
  1035 + xer_ca = 1;
782 } 1036 }
783 RETURN(); 1037 RETURN();
784 } 1038 }
785 1039
786 -void OPPROTO op_subfco (void) 1040 +#if defined(TARGET_PPC64)
  1041 +void OPPROTO op_check_subfc_64 (void)
787 { 1042 {
788 - do_subfco(); 1043 + if (likely((uint64_t)T0 > (uint64_t)T1)) {
  1044 + xer_ca = 0;
  1045 + } else {
  1046 + xer_ca = 1;
  1047 + }
789 RETURN(); 1048 RETURN();
790 } 1049 }
  1050 +#endif
791 1051
792 /* substract from extended */ 1052 /* substract from extended */
793 void OPPROTO op_subfe (void) 1053 void OPPROTO op_subfe (void)
@@ -796,17 +1056,19 @@ void OPPROTO op_subfe (void) @@ -796,17 +1056,19 @@ void OPPROTO op_subfe (void)
796 RETURN(); 1056 RETURN();
797 } 1057 }
798 1058
799 -PPC_OP(subfeo) 1059 +#if defined(TARGET_PPC64)
  1060 +void OPPROTO op_subfe_64 (void)
800 { 1061 {
801 - do_subfeo(); 1062 + do_subfe_64();
802 RETURN(); 1063 RETURN();
803 } 1064 }
  1065 +#endif
804 1066
805 /* substract from immediate carrying */ 1067 /* substract from immediate carrying */
806 -PPC_OP(subfic) 1068 +void OPPROTO op_subfic (void)
807 { 1069 {
808 - T0 = PARAM(1) + ~T0 + 1;  
809 - if (T0 <= PARAM(1)) { 1070 + T0 = PARAM1 + ~T0 + 1;
  1071 + if ((uint32_t)T0 <= (uint32_t)PARAM1) {
810 xer_ca = 1; 1072 xer_ca = 1;
811 } else { 1073 } else {
812 xer_ca = 0; 1074 xer_ca = 0;
@@ -814,15 +1076,37 @@ PPC_OP(subfic) @@ -814,15 +1076,37 @@ PPC_OP(subfic)
814 RETURN(); 1076 RETURN();
815 } 1077 }
816 1078
  1079 +#if defined(TARGET_PPC64)
  1080 +void OPPROTO op_subfic_64 (void)
  1081 +{
  1082 + T0 = PARAM1 + ~T0 + 1;
  1083 + if ((uint64_t)T0 <= (uint64_t)PARAM1) {
  1084 + xer_ca = 1;
  1085 + } else {
  1086 + xer_ca = 0;
  1087 + }
  1088 + RETURN();
  1089 +}
  1090 +#endif
  1091 +
817 /* substract from minus one extended */ 1092 /* substract from minus one extended */
818 -PPC_OP(subfme) 1093 +void OPPROTO op_subfme (void)
819 { 1094 {
820 T0 = ~T0 + xer_ca - 1; 1095 T0 = ~T0 + xer_ca - 1;
  1096 + if (likely((uint32_t)T0 != (uint32_t)-1))
  1097 + xer_ca = 1;
  1098 + RETURN();
  1099 +}
821 1100
822 - if (T0 != -1) 1101 +#if defined(TARGET_PPC64)
  1102 +void OPPROTO op_subfme_64 (void)
  1103 +{
  1104 + T0 = ~T0 + xer_ca - 1;
  1105 + if (likely((uint64_t)T0 != (uint64_t)-1))
823 xer_ca = 1; 1106 xer_ca = 1;
824 RETURN(); 1107 RETURN();
825 } 1108 }
  1109 +#endif
826 1110
827 void OPPROTO op_subfmeo (void) 1111 void OPPROTO op_subfmeo (void)
828 { 1112 {
@@ -830,12 +1114,20 @@ void OPPROTO op_subfmeo (void) @@ -830,12 +1114,20 @@ void OPPROTO op_subfmeo (void)
830 RETURN(); 1114 RETURN();
831 } 1115 }
832 1116
  1117 +#if defined(TARGET_PPC64)
  1118 +void OPPROTO op_subfmeo_64 (void)
  1119 +{
  1120 + do_subfmeo_64();
  1121 + RETURN();
  1122 +}
  1123 +#endif
  1124 +
833 /* substract from zero extended */ 1125 /* substract from zero extended */
834 -PPC_OP(subfze) 1126 +void OPPROTO op_subfze (void)
835 { 1127 {
836 T1 = ~T0; 1128 T1 = ~T0;
837 T0 = T1 + xer_ca; 1129 T0 = T1 + xer_ca;
838 - if (T0 < T1) { 1130 + if ((uint32_t)T0 < (uint32_t)T1) {
839 xer_ca = 1; 1131 xer_ca = 1;
840 } else { 1132 } else {
841 xer_ca = 0; 1133 xer_ca = 0;
@@ -843,32 +1135,68 @@ PPC_OP(subfze) @@ -843,32 +1135,68 @@ PPC_OP(subfze)
843 RETURN(); 1135 RETURN();
844 } 1136 }
845 1137
  1138 +#if defined(TARGET_PPC64)
  1139 +void OPPROTO op_subfze_64 (void)
  1140 +{
  1141 + T1 = ~T0;
  1142 + T0 = T1 + xer_ca;
  1143 + if ((uint64_t)T0 < (uint64_t)T1) {
  1144 + xer_ca = 1;
  1145 + } else {
  1146 + xer_ca = 0;
  1147 + }
  1148 + RETURN();
  1149 +}
  1150 +#endif
  1151 +
846 void OPPROTO op_subfzeo (void) 1152 void OPPROTO op_subfzeo (void)
847 { 1153 {
848 do_subfzeo(); 1154 do_subfzeo();
849 RETURN(); 1155 RETURN();
850 } 1156 }
851 1157
  1158 +#if defined(TARGET_PPC64)
  1159 +void OPPROTO op_subfzeo_64 (void)
  1160 +{
  1161 + do_subfzeo_64();
  1162 + RETURN();
  1163 +}
  1164 +#endif
  1165 +
852 /*** Integer comparison ***/ 1166 /*** Integer comparison ***/
853 /* compare */ 1167 /* compare */
854 -PPC_OP(cmp) 1168 +void OPPROTO op_cmp (void)
  1169 +{
  1170 + if ((int32_t)T0 < (int32_t)T1) {
  1171 + T0 = 0x08;
  1172 + } else if ((int32_t)T0 > (int32_t)T1) {
  1173 + T0 = 0x04;
  1174 + } else {
  1175 + T0 = 0x02;
  1176 + }
  1177 + RETURN();
  1178 +}
  1179 +
  1180 +#if defined(TARGET_PPC64)
  1181 +void OPPROTO op_cmp_64 (void)
855 { 1182 {
856 - if (Ts0 < Ts1) { 1183 + if ((int64_t)T0 < (int64_t)T1) {
857 T0 = 0x08; 1184 T0 = 0x08;
858 - } else if (Ts0 > Ts1) { 1185 + } else if ((int64_t)T0 > (int64_t)T1) {
859 T0 = 0x04; 1186 T0 = 0x04;
860 } else { 1187 } else {
861 T0 = 0x02; 1188 T0 = 0x02;
862 } 1189 }
863 RETURN(); 1190 RETURN();
864 } 1191 }
  1192 +#endif
865 1193
866 /* compare immediate */ 1194 /* compare immediate */
867 -PPC_OP(cmpi) 1195 +void OPPROTO op_cmpi (void)
868 { 1196 {
869 - if (Ts0 < SPARAM(1)) { 1197 + if ((int32_t)T0 < (int32_t)PARAM1) {
870 T0 = 0x08; 1198 T0 = 0x08;
871 - } else if (Ts0 > SPARAM(1)) { 1199 + } else if ((int32_t)T0 > (int32_t)PARAM1) {
872 T0 = 0x04; 1200 T0 = 0x04;
873 } else { 1201 } else {
874 T0 = 0x02; 1202 T0 = 0x02;
@@ -876,12 +1204,26 @@ PPC_OP(cmpi) @@ -876,12 +1204,26 @@ PPC_OP(cmpi)
876 RETURN(); 1204 RETURN();
877 } 1205 }
878 1206
  1207 +#if defined(TARGET_PPC64)
  1208 +void OPPROTO op_cmpi_64 (void)
  1209 +{
  1210 + if ((int64_t)T0 < (int64_t)((int32_t)PARAM1)) {
  1211 + T0 = 0x08;
  1212 + } else if ((int64_t)T0 > (int64_t)((int32_t)PARAM1)) {
  1213 + T0 = 0x04;
  1214 + } else {
  1215 + T0 = 0x02;
  1216 + }
  1217 + RETURN();
  1218 +}
  1219 +#endif
  1220 +
879 /* compare logical */ 1221 /* compare logical */
880 -PPC_OP(cmpl) 1222 +void OPPROTO op_cmpl (void)
881 { 1223 {
882 - if (T0 < T1) { 1224 + if ((uint32_t)T0 < (uint32_t)T1) {
883 T0 = 0x08; 1225 T0 = 0x08;
884 - } else if (T0 > T1) { 1226 + } else if ((uint32_t)T0 > (uint32_t)T1) {
885 T0 = 0x04; 1227 T0 = 0x04;
886 } else { 1228 } else {
887 T0 = 0x02; 1229 T0 = 0x02;
@@ -889,18 +1231,69 @@ PPC_OP(cmpl) @@ -889,18 +1231,69 @@ PPC_OP(cmpl)
889 RETURN(); 1231 RETURN();
890 } 1232 }
891 1233
  1234 +#if defined(TARGET_PPC64)
  1235 +void OPPROTO op_cmpl_64 (void)
  1236 +{
  1237 + if ((uint64_t)T0 < (uint64_t)T1) {
  1238 + T0 = 0x08;
  1239 + } else if ((uint64_t)T0 > (uint64_t)T1) {
  1240 + T0 = 0x04;
  1241 + } else {
  1242 + T0 = 0x02;
  1243 + }
  1244 + RETURN();
  1245 +}
  1246 +#endif
  1247 +
892 /* compare logical immediate */ 1248 /* compare logical immediate */
893 -PPC_OP(cmpli) 1249 +void OPPROTO op_cmpli (void)
  1250 +{
  1251 + if ((uint32_t)T0 < (uint32_t)PARAM1) {
  1252 + T0 = 0x08;
  1253 + } else if ((uint32_t)T0 > (uint32_t)PARAM1) {
  1254 + T0 = 0x04;
  1255 + } else {
  1256 + T0 = 0x02;
  1257 + }
  1258 + RETURN();
  1259 +}
  1260 +
  1261 +#if defined(TARGET_PPC64)
  1262 +void OPPROTO op_cmpli_64 (void)
894 { 1263 {
895 - if (T0 < PARAM(1)) { 1264 + if ((uint64_t)T0 < (uint64_t)PARAM1) {
896 T0 = 0x08; 1265 T0 = 0x08;
897 - } else if (T0 > PARAM(1)) { 1266 + } else if ((uint64_t)T0 > (uint64_t)PARAM1) {
898 T0 = 0x04; 1267 T0 = 0x04;
899 } else { 1268 } else {
900 T0 = 0x02; 1269 T0 = 0x02;
901 } 1270 }
902 RETURN(); 1271 RETURN();
903 } 1272 }
  1273 +#endif
  1274 +
  1275 +void OPPROTO op_isel (void)
  1276 +{
  1277 + if (T0)
  1278 + T0 = T1;
  1279 + else
  1280 + T0 = T2;
  1281 + RETURN();
  1282 +}
  1283 +
  1284 +void OPPROTO op_popcntb (void)
  1285 +{
  1286 + do_popcntb();
  1287 + RETURN();
  1288 +}
  1289 +
  1290 +#if defined(TARGET_PPC64)
  1291 +void OPPROTO op_popcntb_64 (void)
  1292 +{
  1293 + do_popcntb_64();
  1294 + RETURN();
  1295 +}
  1296 +#endif
904 1297
905 /*** Integer logical ***/ 1298 /*** Integer logical ***/
906 /* and */ 1299 /* and */
@@ -963,6 +1356,80 @@ void OPPROTO op_cntlzw (void) @@ -963,6 +1356,80 @@ void OPPROTO op_cntlzw (void)
963 RETURN(); 1356 RETURN();
964 } 1357 }
965 1358
  1359 +#if defined(TARGET_PPC64)
  1360 +void OPPROTO op_cntlzd (void)
  1361 +{
  1362 +#if HOST_LONG_BITS == 64
  1363 + int cnt;
  1364 +
  1365 + cnt = 0;
  1366 + if (!(T0 & 0xFFFFFFFF00000000ULL)) {
  1367 + cnt += 32;
  1368 + T0 <<= 32;
  1369 + }
  1370 + if (!(T0 & 0xFFFF000000000000ULL)) {
  1371 + cnt += 16;
  1372 + T0 <<= 16;
  1373 + }
  1374 + if (!(T0 & 0xFF00000000000000ULL)) {
  1375 + cnt += 8;
  1376 + T0 <<= 8;
  1377 + }
  1378 + if (!(T0 & 0xF000000000000000ULL)) {
  1379 + cnt += 4;
  1380 + T0 <<= 4;
  1381 + }
  1382 + if (!(T0 & 0xC000000000000000ULL)) {
  1383 + cnt += 2;
  1384 + T0 <<= 2;
  1385 + }
  1386 + if (!(T0 & 0x8000000000000000ULL)) {
  1387 + cnt++;
  1388 + T0 <<= 1;
  1389 + }
  1390 + if (!(T0 & 0x8000000000000000ULL)) {
  1391 + cnt++;
  1392 + }
  1393 + T0 = cnt;
  1394 +#else
  1395 + uint32_t tmp;
  1396 +
  1397 + /* Make it easier on 32 bits host machines */
  1398 + if (!(T0 >> 32)) {
  1399 + tmp = T0;
  1400 + T0 = 32;
  1401 + } else {
  1402 + tmp = T0 >> 32;
  1403 + T0 = 0;
  1404 + }
  1405 + if (!(tmp & 0xFFFF0000UL)) {
  1406 + T0 += 16;
  1407 + tmp <<= 16;
  1408 + }
  1409 + if (!(tmp & 0xFF000000UL)) {
  1410 + T0 += 8;
  1411 + tmp <<= 8;
  1412 + }
  1413 + if (!(tmp & 0xF0000000UL)) {
  1414 + T0 += 4;
  1415 + tmp <<= 4;
  1416 + }
  1417 + if (!(tmp & 0xC0000000UL)) {
  1418 + T0 += 2;
  1419 + tmp <<= 2;
  1420 + }
  1421 + if (!(tmp & 0x80000000UL)) {
  1422 + T0++;
  1423 + tmp <<= 1;
  1424 + }
  1425 + if (!(tmp & 0x80000000UL)) {
  1426 + T0++;
  1427 + }
  1428 +#endif
  1429 + RETURN();
  1430 +}
  1431 +#endif
  1432 +
966 /* eqv */ 1433 /* eqv */
967 PPC_OP(eqv) 1434 PPC_OP(eqv)
968 { 1435 {
@@ -971,19 +1438,35 @@ PPC_OP(eqv) @@ -971,19 +1438,35 @@ PPC_OP(eqv)
971 } 1438 }
972 1439
973 /* extend sign byte */ 1440 /* extend sign byte */
974 -PPC_OP(extsb) 1441 +void OPPROTO op_extsb (void)
975 { 1442 {
976 - T0 = (int32_t)((int8_t)(Ts0)); 1443 +#if defined (TARGET_PPC64)
  1444 + T0 = (int64_t)((int8_t)T0);
  1445 +#else
  1446 + T0 = (int32_t)((int8_t)T0);
  1447 +#endif
977 RETURN(); 1448 RETURN();
978 } 1449 }
979 1450
980 /* extend sign half word */ 1451 /* extend sign half word */
981 -PPC_OP(extsh) 1452 +void OPPROTO op_extsh (void)
982 { 1453 {
983 - T0 = (int32_t)((int16_t)(Ts0)); 1454 +#if defined (TARGET_PPC64)
  1455 + T0 = (int64_t)((int16_t)T0);
  1456 +#else
  1457 + T0 = (int32_t)((int16_t)T0);
  1458 +#endif
984 RETURN(); 1459 RETURN();
985 } 1460 }
986 1461
  1462 +#if defined (TARGET_PPC64)
  1463 +void OPPROTO op_extsw (void)
  1464 +{
  1465 + T0 = (int64_t)((int32_t)T0);
  1466 + RETURN();
  1467 +}
  1468 +#endif
  1469 +
987 /* nand */ 1470 /* nand */
988 PPC_OP(nand) 1471 PPC_OP(nand)
989 { 1472 {
@@ -1048,15 +1531,27 @@ void OPPROTO op_rotli32_T0 (void) @@ -1048,15 +1531,27 @@ void OPPROTO op_rotli32_T0 (void)
1048 1531
1049 /*** Integer shift ***/ 1532 /*** Integer shift ***/
1050 /* shift left word */ 1533 /* shift left word */
1051 -PPC_OP(slw) 1534 +void OPPROTO op_slw (void)
1052 { 1535 {
1053 if (T1 & 0x20) { 1536 if (T1 & 0x20) {
1054 T0 = 0; 1537 T0 = 0;
1055 } else { 1538 } else {
  1539 + T0 = (uint32_t)(T0 << T1);
  1540 + }
  1541 + RETURN();
  1542 +}
  1543 +
  1544 +#if defined(TARGET_PPC64)
  1545 +void OPPROTO op_sld (void)
  1546 +{
  1547 + if (T1 & 0x40) {
  1548 + T0 = 0;
  1549 + } else {
1056 T0 = T0 << T1; 1550 T0 = T0 << T1;
1057 } 1551 }
1058 RETURN(); 1552 RETURN();
1059 } 1553 }
  1554 +#endif
1060 1555
1061 /* shift right algebraic word */ 1556 /* shift right algebraic word */
1062 void OPPROTO op_sraw (void) 1557 void OPPROTO op_sraw (void)
@@ -1065,12 +1560,21 @@ void OPPROTO op_sraw (void) @@ -1065,12 +1560,21 @@ void OPPROTO op_sraw (void)
1065 RETURN(); 1560 RETURN();
1066 } 1561 }
1067 1562
  1563 +#if defined(TARGET_PPC64)
  1564 +void OPPROTO op_srad (void)
  1565 +{
  1566 + do_srad();
  1567 + RETURN();
  1568 +}
  1569 +#endif
  1570 +
1068 /* shift right algebraic word immediate */ 1571 /* shift right algebraic word immediate */
1069 -PPC_OP(srawi) 1572 +void OPPROTO op_srawi (void)
1070 { 1573 {
1071 - T1 = T0;  
1072 - T0 = (Ts0 >> PARAM(1));  
1073 - if (Ts1 < 0 && (Ts1 & PARAM(2)) != 0) { 1574 + uint32_t mask = (uint32_t)PARAM2;
  1575 +
  1576 + T0 = (int32_t)T0 >> PARAM1;
  1577 + if ((int32_t)T1 < 0 && (T1 & mask) != 0) {
1074 xer_ca = 1; 1578 xer_ca = 1;
1075 } else { 1579 } else {
1076 xer_ca = 0; 1580 xer_ca = 0;
@@ -1078,16 +1582,43 @@ PPC_OP(srawi) @@ -1078,16 +1582,43 @@ PPC_OP(srawi)
1078 RETURN(); 1582 RETURN();
1079 } 1583 }
1080 1584
  1585 +#if defined(TARGET_PPC64)
  1586 +void OPPROTO op_sradi (void)
  1587 +{
  1588 + uint64_t mask = ((uint64_t)PARAM2 << 32) | (uint64_t)PARAM3;
  1589 +
  1590 + T0 = (int64_t)T0 >> PARAM1;
  1591 + if ((int64_t)T1 < 0 && ((uint64_t)T1 & mask) != 0) {
  1592 + xer_ca = 1;
  1593 + } else {
  1594 + xer_ca = 0;
  1595 + }
  1596 + RETURN();
  1597 +}
  1598 +#endif
  1599 +
1081 /* shift right word */ 1600 /* shift right word */
1082 -PPC_OP(srw) 1601 +void OPPROTO op_srw (void)
1083 { 1602 {
1084 if (T1 & 0x20) { 1603 if (T1 & 0x20) {
1085 T0 = 0; 1604 T0 = 0;
1086 } else { 1605 } else {
1087 - T0 = T0 >> T1; 1606 + T0 = (uint32_t)T0 >> T1;
  1607 + }
  1608 + RETURN();
  1609 +}
  1610 +
  1611 +#if defined(TARGET_PPC64)
  1612 +void OPPROTO op_srd (void)
  1613 +{
  1614 + if (T1 & 0x40) {
  1615 + T0 = 0;
  1616 + } else {
  1617 + T0 = (uint64_t)T0 >> T1;
1088 } 1618 }
1089 RETURN(); 1619 RETURN();
1090 } 1620 }
  1621 +#endif
1091 1622
1092 void OPPROTO op_sl_T0_T1 (void) 1623 void OPPROTO op_sl_T0_T1 (void)
1093 { 1624 {
@@ -1103,22 +1634,46 @@ void OPPROTO op_sli_T0 (void) @@ -1103,22 +1634,46 @@ void OPPROTO op_sli_T0 (void)
1103 1634
1104 void OPPROTO op_srl_T0_T1 (void) 1635 void OPPROTO op_srl_T0_T1 (void)
1105 { 1636 {
1106 - T0 = T0 >> T1; 1637 + T0 = (uint32_t)T0 >> T1;
  1638 + RETURN();
  1639 +}
  1640 +
  1641 +#if defined(TARGET_PPC64)
  1642 +void OPPROTO op_srl_T0_T1_64 (void)
  1643 +{
  1644 + T0 = (uint32_t)T0 >> T1;
1107 RETURN(); 1645 RETURN();
1108 } 1646 }
  1647 +#endif
1109 1648
1110 void OPPROTO op_srli_T0 (void) 1649 void OPPROTO op_srli_T0 (void)
1111 { 1650 {
1112 - T0 = T0 >> PARAM1; 1651 + T0 = (uint32_t)T0 >> PARAM1;
1113 RETURN(); 1652 RETURN();
1114 } 1653 }
1115 1654
  1655 +#if defined(TARGET_PPC64)
  1656 +void OPPROTO op_srli_T0_64 (void)
  1657 +{
  1658 + T0 = (uint64_t)T0 >> PARAM1;
  1659 + RETURN();
  1660 +}
  1661 +#endif
  1662 +
1116 void OPPROTO op_srli_T1 (void) 1663 void OPPROTO op_srli_T1 (void)
1117 { 1664 {
1118 - T1 = T1 >> PARAM1; 1665 + T1 = (uint32_t)T1 >> PARAM1;
1119 RETURN(); 1666 RETURN();
1120 } 1667 }
1121 1668
  1669 +#if defined(TARGET_PPC64)
  1670 +void OPPROTO op_srli_T1_64 (void)
  1671 +{
  1672 + T1 = (uint64_t)T1 >> PARAM1;
  1673 + RETURN();
  1674 +}
  1675 +#endif
  1676 +
1122 /*** Floating-Point arithmetic ***/ 1677 /*** Floating-Point arithmetic ***/
1123 /* fadd - fadd. */ 1678 /* fadd - fadd. */
1124 PPC_OP(fadd) 1679 PPC_OP(fadd)
@@ -1281,13 +1836,22 @@ PPC_OP(fneg) @@ -1281,13 +1836,22 @@ PPC_OP(fneg)
1281 #endif 1836 #endif
1282 1837
1283 /* Special op to check and maybe clear reservation */ 1838 /* Special op to check and maybe clear reservation */
1284 -PPC_OP(check_reservation) 1839 +void OPPROTO op_check_reservation (void)
1285 { 1840 {
1286 if ((uint32_t)env->reserve == (uint32_t)(T0 & ~0x00000003)) 1841 if ((uint32_t)env->reserve == (uint32_t)(T0 & ~0x00000003))
1287 env->reserve = -1; 1842 env->reserve = -1;
1288 RETURN(); 1843 RETURN();
1289 } 1844 }
1290 1845
  1846 +#if defined(TARGET_PPC64)
  1847 +void OPPROTO op_check_reservation_64 (void)
  1848 +{
  1849 + if ((uint64_t)env->reserve == (uint64_t)(T0 & ~0x00000003))
  1850 + env->reserve = -1;
  1851 + RETURN();
  1852 +}
  1853 +#endif
  1854 +
1291 /* Return from interrupt */ 1855 /* Return from interrupt */
1292 #if !defined(CONFIG_USER_ONLY) 1856 #if !defined(CONFIG_USER_ONLY)
1293 void OPPROTO op_rfi (void) 1857 void OPPROTO op_rfi (void)
@@ -1295,6 +1859,14 @@ void OPPROTO op_rfi (void) @@ -1295,6 +1859,14 @@ void OPPROTO op_rfi (void)
1295 do_rfi(); 1859 do_rfi();
1296 RETURN(); 1860 RETURN();
1297 } 1861 }
  1862 +
  1863 +#if defined(TARGET_PPC64)
  1864 +void OPPROTO op_rfi_32 (void)
  1865 +{
  1866 + do_rfi_32();
  1867 + RETURN();
  1868 +}
  1869 +#endif
1298 #endif 1870 #endif
1299 1871
1300 /* Trap word */ 1872 /* Trap word */
@@ -1304,13 +1876,29 @@ void OPPROTO op_tw (void) @@ -1304,13 +1876,29 @@ void OPPROTO op_tw (void)
1304 RETURN(); 1876 RETURN();
1305 } 1877 }
1306 1878
  1879 +#if defined(TARGET_PPC64)
  1880 +void OPPROTO op_td (void)
  1881 +{
  1882 + do_td(PARAM1);
  1883 + RETURN();
  1884 +}
  1885 +#endif
  1886 +
1307 /* Instruction cache block invalidate */ 1887 /* Instruction cache block invalidate */
1308 -PPC_OP(icbi) 1888 +void OPPROTO op_icbi (void)
1309 { 1889 {
1310 do_icbi(); 1890 do_icbi();
1311 RETURN(); 1891 RETURN();
1312 } 1892 }
1313 1893
  1894 +#if defined(TARGET_PPC64)
  1895 +void OPPROTO op_icbi_64 (void)
  1896 +{
  1897 + do_icbi_64();
  1898 + RETURN();
  1899 +}
  1900 +#endif
  1901 +
1314 #if !defined(CONFIG_USER_ONLY) 1902 #if !defined(CONFIG_USER_ONLY)
1315 /* tlbia */ 1903 /* tlbia */
1316 PPC_OP(tlbia) 1904 PPC_OP(tlbia)
@@ -1320,11 +1908,33 @@ PPC_OP(tlbia) @@ -1320,11 +1908,33 @@ PPC_OP(tlbia)
1320 } 1908 }
1321 1909
1322 /* tlbie */ 1910 /* tlbie */
1323 -PPC_OP(tlbie) 1911 +void OPPROTO op_tlbie (void)
1324 { 1912 {
1325 do_tlbie(); 1913 do_tlbie();
1326 RETURN(); 1914 RETURN();
1327 } 1915 }
  1916 +
  1917 +#if defined(TARGET_PPC64)
  1918 +void OPPROTO op_tlbie_64 (void)
  1919 +{
  1920 + do_tlbie_64();
  1921 + RETURN();
  1922 +}
  1923 +#endif
  1924 +
  1925 +#if defined(TARGET_PPC64)
  1926 +void OPPROTO op_slbia (void)
  1927 +{
  1928 + do_slbia();
  1929 + RETURN();
  1930 +}
  1931 +
  1932 +void OPPROTO op_slbie (void)
  1933 +{
  1934 + do_slbie();
  1935 + RETURN();
  1936 +}
  1937 +#endif
1328 #endif 1938 #endif
1329 1939
1330 /* PowerPC 602/603/755 software TLB load instructions */ 1940 /* PowerPC 602/603/755 software TLB load instructions */
@@ -1343,14 +1953,12 @@ void OPPROTO op_6xx_tlbli (void) @@ -1343,14 +1953,12 @@ void OPPROTO op_6xx_tlbli (void)
1343 #endif 1953 #endif
1344 1954
1345 /* 601 specific */ 1955 /* 601 specific */
1346 -uint32_t cpu_ppc601_load_rtcl (CPUState *env);  
1347 void OPPROTO op_load_601_rtcl (void) 1956 void OPPROTO op_load_601_rtcl (void)
1348 { 1957 {
1349 T0 = cpu_ppc601_load_rtcl(env); 1958 T0 = cpu_ppc601_load_rtcl(env);
1350 RETURN(); 1959 RETURN();
1351 } 1960 }
1352 1961
1353 -uint32_t cpu_ppc601_load_rtcu (CPUState *env);  
1354 void OPPROTO op_load_601_rtcu (void) 1962 void OPPROTO op_load_601_rtcu (void)
1355 { 1963 {
1356 T0 = cpu_ppc601_load_rtcu(env); 1964 T0 = cpu_ppc601_load_rtcu(env);
@@ -1358,14 +1966,12 @@ void OPPROTO op_load_601_rtcu (void) @@ -1358,14 +1966,12 @@ void OPPROTO op_load_601_rtcu (void)
1358 } 1966 }
1359 1967
1360 #if !defined(CONFIG_USER_ONLY) 1968 #if !defined(CONFIG_USER_ONLY)
1361 -void cpu_ppc601_store_rtcl (CPUState *env, uint32_t value);  
1362 void OPPROTO op_store_601_rtcl (void) 1969 void OPPROTO op_store_601_rtcl (void)
1363 { 1970 {
1364 cpu_ppc601_store_rtcl(env, T0); 1971 cpu_ppc601_store_rtcl(env, T0);
1365 RETURN(); 1972 RETURN();
1366 } 1973 }
1367 1974
1368 -void cpu_ppc601_store_rtcu (CPUState *env, uint32_t value);  
1369 void OPPROTO op_store_601_rtcu (void) 1975 void OPPROTO op_store_601_rtcu (void)
1370 { 1976 {
1371 cpu_ppc601_store_rtcu(env, T0); 1977 cpu_ppc601_store_rtcu(env, T0);
@@ -1449,7 +2055,7 @@ void OPPROTO op_POWER_divso (void) @@ -1449,7 +2055,7 @@ void OPPROTO op_POWER_divso (void)
1449 2055
1450 void OPPROTO op_POWER_doz (void) 2056 void OPPROTO op_POWER_doz (void)
1451 { 2057 {
1452 - if (Ts1 > Ts0) 2058 + if ((int32_t)T1 > (int32_t)T0)
1453 T0 = T1 - T0; 2059 T0 = T1 - T0;
1454 else 2060 else
1455 T0 = 0; 2061 T0 = 0;
@@ -1580,7 +2186,7 @@ void OPPROTO op_POWER_sraq (void) @@ -1580,7 +2186,7 @@ void OPPROTO op_POWER_sraq (void)
1580 if (T1 & 0x20UL) 2186 if (T1 & 0x20UL)
1581 T0 = -1L; 2187 T0 = -1L;
1582 else 2188 else
1583 - T0 = Ts0 >> T1; 2189 + T0 = (int32_t)T0 >> T1;
1584 RETURN(); 2190 RETURN();
1585 } 2191 }
1586 2192
@@ -1588,7 +2194,7 @@ void OPPROTO op_POWER_sre (void) @@ -1588,7 +2194,7 @@ void OPPROTO op_POWER_sre (void)
1588 { 2194 {
1589 T1 &= 0x1FUL; 2195 T1 &= 0x1FUL;
1590 env->spr[SPR_MQ] = rotl32(T0, 32 - T1); 2196 env->spr[SPR_MQ] = rotl32(T0, 32 - T1);
1591 - T0 = Ts0 >> T1; 2197 + T0 = (int32_t)T0 >> T1;
1592 RETURN(); 2198 RETURN();
1593 } 2199 }
1594 2200
@@ -1596,7 +2202,7 @@ void OPPROTO op_POWER_srea (void) @@ -1596,7 +2202,7 @@ void OPPROTO op_POWER_srea (void)
1596 { 2202 {
1597 T1 &= 0x1FUL; 2203 T1 &= 0x1FUL;
1598 env->spr[SPR_MQ] = T0 >> T1; 2204 env->spr[SPR_MQ] = T0 >> T1;
1599 - T0 = Ts0 >> T1; 2205 + T0 = (int32_t)T0 >> T1;
1600 RETURN(); 2206 RETURN();
1601 } 2207 }
1602 2208
@@ -1848,28 +2454,24 @@ void OPPROTO op_store_403_pb (void) @@ -1848,28 +2454,24 @@ void OPPROTO op_store_403_pb (void)
1848 RETURN(); 2454 RETURN();
1849 } 2455 }
1850 2456
1851 -target_ulong load_40x_pit (CPUState *env);  
1852 void OPPROTO op_load_40x_pit (void) 2457 void OPPROTO op_load_40x_pit (void)
1853 { 2458 {
1854 T0 = load_40x_pit(env); 2459 T0 = load_40x_pit(env);
1855 RETURN(); 2460 RETURN();
1856 } 2461 }
1857 2462
1858 -void store_40x_pit (CPUState *env, target_ulong val);  
1859 void OPPROTO op_store_40x_pit (void) 2463 void OPPROTO op_store_40x_pit (void)
1860 { 2464 {
1861 store_40x_pit(env, T0); 2465 store_40x_pit(env, T0);
1862 RETURN(); 2466 RETURN();
1863 } 2467 }
1864 2468
1865 -void store_booke_tcr (CPUState *env, target_ulong val);  
1866 void OPPROTO op_store_booke_tcr (void) 2469 void OPPROTO op_store_booke_tcr (void)
1867 { 2470 {
1868 store_booke_tcr(env, T0); 2471 store_booke_tcr(env, T0);
1869 RETURN(); 2472 RETURN();
1870 } 2473 }
1871 2474
1872 -void store_booke_tsr (CPUState *env, target_ulong val);  
1873 void OPPROTO op_store_booke_tsr (void) 2475 void OPPROTO op_store_booke_tsr (void)
1874 { 2476 {
1875 store_booke_tsr(env, T0); 2477 store_booke_tsr(env, T0);
target-ppc/op_helper.c
@@ -33,10 +33,6 @@ @@ -33,10 +33,6 @@
33 //#define DEBUG_SOFTWARE_TLB 33 //#define DEBUG_SOFTWARE_TLB
34 //#define FLUSH_ALL_TLBS 34 //#define FLUSH_ALL_TLBS
35 35
36 -#define Ts0 (long)((target_long)T0)  
37 -#define Ts1 (long)((target_long)T1)  
38 -#define Ts2 (long)((target_long)T2)  
39 -  
40 /*****************************************************************************/ 36 /*****************************************************************************/
41 /* Exceptions processing helpers */ 37 /* Exceptions processing helpers */
42 void cpu_loop_exit (void) 38 void cpu_loop_exit (void)
@@ -106,7 +102,7 @@ void do_store_xer (void) @@ -106,7 +102,7 @@ void do_store_xer (void)
106 xer_ov = (T0 >> XER_OV) & 0x01; 102 xer_ov = (T0 >> XER_OV) & 0x01;
107 xer_ca = (T0 >> XER_CA) & 0x01; 103 xer_ca = (T0 >> XER_CA) & 0x01;
108 xer_cmp = (T0 >> XER_CMP) & 0xFF; 104 xer_cmp = (T0 >> XER_CMP) & 0xFF;
109 - xer_bc = (T0 >> XER_BC) & 0x3F; 105 + xer_bc = (T0 >> XER_BC) & 0x7F;
110 } 106 }
111 107
112 void do_load_fpscr (void) 108 void do_load_fpscr (void)
@@ -122,7 +118,7 @@ void do_load_fpscr (void) @@ -122,7 +118,7 @@ void do_load_fpscr (void)
122 } u; 118 } u;
123 int i; 119 int i;
124 120
125 -#ifdef WORDS_BIGENDIAN 121 +#if defined(WORDS_BIGENDIAN)
126 #define WORD0 0 122 #define WORD0 0
127 #define WORD1 1 123 #define WORD1 1
128 #else 124 #else
@@ -182,68 +178,110 @@ void do_store_fpscr (uint32_t mask) @@ -182,68 +178,110 @@ void do_store_fpscr (uint32_t mask)
182 178
183 /*****************************************************************************/ 179 /*****************************************************************************/
184 /* Fixed point operations helpers */ 180 /* Fixed point operations helpers */
185 -void do_addo (void) 181 +#if defined(TARGET_PPC64)
  182 +static void add128 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
186 { 183 {
187 - T2 = T0;  
188 - T0 += T1;  
189 - if (likely(!((T2 ^ T1 ^ (-1)) & (T2 ^ T0) & (1 << 31)))) {  
190 - xer_ov = 0;  
191 - } else {  
192 - xer_so = 1;  
193 - xer_ov = 1;  
194 - } 184 + *plow += a;
  185 + /* carry test */
  186 + if (*plow < a)
  187 + (*phigh)++;
  188 + *phigh += b;
195 } 189 }
196 190
197 -void do_addco (void) 191 +static void neg128 (uint64_t *plow, uint64_t *phigh)
198 { 192 {
199 - T2 = T0;  
200 - T0 += T1;  
201 - if (likely(T0 >= T2)) {  
202 - xer_ca = 0;  
203 - } else {  
204 - xer_ca = 1;  
205 - }  
206 - if (likely(!((T2 ^ T1 ^ (-1)) & (T2 ^ T0) & (1 << 31)))) {  
207 - xer_ov = 0;  
208 - } else {  
209 - xer_so = 1;  
210 - xer_ov = 1; 193 + *plow = ~ *plow;
  194 + *phigh = ~ *phigh;
  195 + add128(plow, phigh, 1, 0);
  196 +}
  197 +
  198 +static void mul64 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
  199 +{
  200 + uint32_t a0, a1, b0, b1;
  201 + uint64_t v;
  202 +
  203 + a0 = a;
  204 + a1 = a >> 32;
  205 +
  206 + b0 = b;
  207 + b1 = b >> 32;
  208 +
  209 + v = (uint64_t)a0 * (uint64_t)b0;
  210 + *plow = v;
  211 + *phigh = 0;
  212 +
  213 + v = (uint64_t)a0 * (uint64_t)b1;
  214 + add128(plow, phigh, v << 32, v >> 32);
  215 +
  216 + v = (uint64_t)a1 * (uint64_t)b0;
  217 + add128(plow, phigh, v << 32, v >> 32);
  218 +
  219 + v = (uint64_t)a1 * (uint64_t)b1;
  220 + *phigh += v;
  221 +#if defined(DEBUG_MULDIV)
  222 + printf("mul: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n",
  223 + a, b, *phigh, *plow);
  224 +#endif
  225 +}
  226 +
  227 +void do_mul64 (uint64_t *plow, uint64_t *phigh)
  228 +{
  229 + mul64(plow, phigh, T0, T1);
  230 +}
  231 +
  232 +static void imul64(uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b)
  233 +{
  234 + int sa, sb;
  235 + sa = (a < 0);
  236 + if (sa)
  237 + a = -a;
  238 + sb = (b < 0);
  239 + if (sb)
  240 + b = -b;
  241 + mul64(plow, phigh, a, b);
  242 + if (sa ^ sb) {
  243 + neg128(plow, phigh);
211 } 244 }
212 } 245 }
213 246
  247 +void do_imul64 (uint64_t *plow, uint64_t *phigh)
  248 +{
  249 + imul64(plow, phigh, T0, T1);
  250 +}
  251 +#endif
  252 +
214 void do_adde (void) 253 void do_adde (void)
215 { 254 {
216 T2 = T0; 255 T2 = T0;
217 T0 += T1 + xer_ca; 256 T0 += T1 + xer_ca;
218 - if (likely(!(T0 < T2 || (xer_ca == 1 && T0 == T2)))) { 257 + if (likely(!((uint32_t)T0 < (uint32_t)T2 ||
  258 + (xer_ca == 1 && (uint32_t)T0 == (uint32_t)T2)))) {
219 xer_ca = 0; 259 xer_ca = 0;
220 } else { 260 } else {
221 xer_ca = 1; 261 xer_ca = 1;
222 } 262 }
223 } 263 }
224 264
225 -void do_addeo (void) 265 +#if defined(TARGET_PPC64)
  266 +void do_adde_64 (void)
226 { 267 {
227 T2 = T0; 268 T2 = T0;
228 T0 += T1 + xer_ca; 269 T0 += T1 + xer_ca;
229 - if (likely(!(T0 < T2 || (xer_ca == 1 && T0 == T2)))) { 270 + if (likely(!((uint64_t)T0 < (uint64_t)T2 ||
  271 + (xer_ca == 1 && (uint64_t)T0 == (uint64_t)T2)))) {
230 xer_ca = 0; 272 xer_ca = 0;
231 } else { 273 } else {
232 xer_ca = 1; 274 xer_ca = 1;
233 } 275 }
234 - if (likely(!((T2 ^ T1 ^ (-1)) & (T2 ^ T0) & (1 << 31)))) {  
235 - xer_ov = 0;  
236 - } else {  
237 - xer_so = 1;  
238 - xer_ov = 1;  
239 - }  
240 } 276 }
  277 +#endif
241 278
242 void do_addmeo (void) 279 void do_addmeo (void)
243 { 280 {
244 T1 = T0; 281 T1 = T0;
245 T0 += xer_ca + (-1); 282 T0 += xer_ca + (-1);
246 - if (likely(!(T1 & (T1 ^ T0) & (1 << 31)))) { 283 + if (likely(!((uint32_t)T1 &
  284 + ((uint32_t)T1 ^ (uint32_t)T0) & (1UL << 31)))) {
247 xer_ov = 0; 285 xer_ov = 0;
248 } else { 286 } else {
249 xer_so = 1; 287 xer_so = 1;
@@ -253,28 +291,29 @@ void do_addmeo (void) @@ -253,28 +291,29 @@ void do_addmeo (void)
253 xer_ca = 1; 291 xer_ca = 1;
254 } 292 }
255 293
256 -void do_addzeo (void) 294 +#if defined(TARGET_PPC64)
  295 +void do_addmeo_64 (void)
257 { 296 {
258 T1 = T0; 297 T1 = T0;
259 - T0 += xer_ca;  
260 - if (likely(!((T1 ^ (-1)) & (T1 ^ T0) & (1 << 31)))) { 298 + T0 += xer_ca + (-1);
  299 + if (likely(!((uint64_t)T1 &
  300 + ((uint64_t)T1 ^ (uint64_t)T0) & (1ULL << 63)))) {
261 xer_ov = 0; 301 xer_ov = 0;
262 } else { 302 } else {
263 xer_so = 1; 303 xer_so = 1;
264 xer_ov = 1; 304 xer_ov = 1;
265 } 305 }
266 - if (likely(T0 >= T1)) {  
267 - xer_ca = 0;  
268 - } else { 306 + if (likely(T1 != 0))
269 xer_ca = 1; 307 xer_ca = 1;
270 - }  
271 } 308 }
  309 +#endif
272 310
273 void do_divwo (void) 311 void do_divwo (void)
274 { 312 {
275 - if (likely(!((Ts0 == INT32_MIN && Ts1 == -1) || Ts1 == 0))) { 313 + if (likely(!(((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) ||
  314 + (int32_t)T1 == 0))) {
276 xer_ov = 0; 315 xer_ov = 0;
277 - T0 = (Ts0 / Ts1); 316 + T0 = (int32_t)T0 / (int32_t)T1;
278 } else { 317 } else {
279 xer_so = 1; 318 xer_so = 1;
280 xer_ov = 1; 319 xer_ov = 1;
@@ -282,6 +321,21 @@ void do_divwo (void) @@ -282,6 +321,21 @@ void do_divwo (void)
282 } 321 }
283 } 322 }
284 323
  324 +#if defined(TARGET_PPC64)
  325 +void do_divdo (void)
  326 +{
  327 + if (likely(!(((int64_t)T0 == INT64_MIN && (int64_t)T1 == -1ULL) ||
  328 + (int64_t)T1 == 0))) {
  329 + xer_ov = 0;
  330 + T0 = (int64_t)T0 / (int64_t)T1;
  331 + } else {
  332 + xer_so = 1;
  333 + xer_ov = 1;
  334 + T0 = (-1ULL) * ((uint64_t)T0 >> 63);
  335 + }
  336 +}
  337 +#endif
  338 +
285 void do_divwuo (void) 339 void do_divwuo (void)
286 { 340 {
287 if (likely((uint32_t)T1 != 0)) { 341 if (likely((uint32_t)T1 != 0)) {
@@ -294,9 +348,23 @@ void do_divwuo (void) @@ -294,9 +348,23 @@ void do_divwuo (void)
294 } 348 }
295 } 349 }
296 350
  351 +#if defined(TARGET_PPC64)
  352 +void do_divduo (void)
  353 +{
  354 + if (likely((uint64_t)T1 != 0)) {
  355 + xer_ov = 0;
  356 + T0 = (uint64_t)T0 / (uint64_t)T1;
  357 + } else {
  358 + xer_so = 1;
  359 + xer_ov = 1;
  360 + T0 = 0;
  361 + }
  362 +}
  363 +#endif
  364 +
297 void do_mullwo (void) 365 void do_mullwo (void)
298 { 366 {
299 - int64_t res = (int64_t)Ts0 * (int64_t)Ts1; 367 + int64_t res = (int64_t)T0 * (int64_t)T1;
300 368
301 if (likely((int32_t)res == res)) { 369 if (likely((int32_t)res == res)) {
302 xer_ov = 0; 370 xer_ov = 0;
@@ -307,112 +375,148 @@ void do_mullwo (void) @@ -307,112 +375,148 @@ void do_mullwo (void)
307 T0 = (int32_t)res; 375 T0 = (int32_t)res;
308 } 376 }
309 377
310 -void do_nego (void) 378 +#if defined(TARGET_PPC64)
  379 +void do_mulldo (void)
311 { 380 {
312 - if (likely(T0 != INT32_MIN)) { 381 + int64_t th;
  382 + uint64_t tl;
  383 +
  384 + do_imul64(&tl, &th);
  385 + if (likely(th == 0)) {
313 xer_ov = 0; 386 xer_ov = 0;
314 - T0 = -Ts0;  
315 } else { 387 } else {
316 xer_ov = 1; 388 xer_ov = 1;
317 xer_so = 1; 389 xer_so = 1;
318 } 390 }
  391 + T0 = (int64_t)tl;
319 } 392 }
  393 +#endif
320 394
321 -void do_subfo (void) 395 +void do_nego (void)
322 { 396 {
323 - T2 = T0;  
324 - T0 = T1 - T0;  
325 - if (likely(!(((~T2) ^ T1 ^ (-1)) & ((~T2) ^ T0) & (1 << 31)))) { 397 + if (likely((int32_t)T0 != INT32_MIN)) {
326 xer_ov = 0; 398 xer_ov = 0;
  399 + T0 = -(int32_t)T0;
327 } else { 400 } else {
328 - xer_so = 1;  
329 xer_ov = 1; 401 xer_ov = 1;
  402 + xer_so = 1;
330 } 403 }
331 - RETURN();  
332 } 404 }
333 405
334 -void do_subfco (void) 406 +#if defined(TARGET_PPC64)
  407 +void do_nego_64 (void)
335 { 408 {
336 - T2 = T0;  
337 - T0 = T1 - T0;  
338 - if (likely(T0 > T1)) {  
339 - xer_ca = 0;  
340 - } else {  
341 - xer_ca = 1;  
342 - }  
343 - if (likely(!(((~T2) ^ T1 ^ (-1)) & ((~T2) ^ T0) & (1 << 31)))) { 409 + if (likely((int64_t)T0 != INT64_MIN)) {
344 xer_ov = 0; 410 xer_ov = 0;
  411 + T0 = -(int64_t)T0;
345 } else { 412 } else {
346 - xer_so = 1;  
347 xer_ov = 1; 413 xer_ov = 1;
  414 + xer_so = 1;
348 } 415 }
349 } 416 }
  417 +#endif
350 418
351 void do_subfe (void) 419 void do_subfe (void)
352 { 420 {
353 T0 = T1 + ~T0 + xer_ca; 421 T0 = T1 + ~T0 + xer_ca;
354 - if (likely(T0 >= T1 && (xer_ca == 0 || T0 != T1))) { 422 + if (likely((uint32_t)T0 >= (uint32_t)T1 &&
  423 + (xer_ca == 0 || (uint32_t)T0 != (uint32_t)T1))) {
355 xer_ca = 0; 424 xer_ca = 0;
356 } else { 425 } else {
357 xer_ca = 1; 426 xer_ca = 1;
358 } 427 }
359 } 428 }
360 429
361 -void do_subfeo (void) 430 +#if defined(TARGET_PPC64)
  431 +void do_subfe_64 (void)
362 { 432 {
363 - T2 = T0;  
364 T0 = T1 + ~T0 + xer_ca; 433 T0 = T1 + ~T0 + xer_ca;
365 - if (likely(!((~T2 ^ T1 ^ (-1)) & (~T2 ^ T0) & (1 << 31)))) { 434 + if (likely((uint64_t)T0 >= (uint64_t)T1 &&
  435 + (xer_ca == 0 || (uint64_t)T0 != (uint64_t)T1))) {
  436 + xer_ca = 0;
  437 + } else {
  438 + xer_ca = 1;
  439 + }
  440 +}
  441 +#endif
  442 +
  443 +void do_subfmeo (void)
  444 +{
  445 + T1 = T0;
  446 + T0 = ~T0 + xer_ca - 1;
  447 + if (likely(!((uint32_t)~T1 & ((uint32_t)~T1 ^ (uint32_t)T0) &
  448 + (1UL << 31)))) {
366 xer_ov = 0; 449 xer_ov = 0;
367 } else { 450 } else {
368 xer_so = 1; 451 xer_so = 1;
369 xer_ov = 1; 452 xer_ov = 1;
370 } 453 }
371 - if (likely(T0 >= T1 && (xer_ca == 0 || T0 != T1))) {  
372 - xer_ca = 0;  
373 - } else { 454 + if (likely((uint32_t)T1 != UINT32_MAX))
374 xer_ca = 1; 455 xer_ca = 1;
375 - }  
376 } 456 }
377 457
378 -void do_subfmeo (void) 458 +#if defined(TARGET_PPC64)
  459 +void do_subfmeo_64 (void)
379 { 460 {
380 T1 = T0; 461 T1 = T0;
381 T0 = ~T0 + xer_ca - 1; 462 T0 = ~T0 + xer_ca - 1;
382 - if (likely(!(~T1 & (~T1 ^ T0) & (1 << 31)))) { 463 + if (likely(!((uint64_t)~T1 & ((uint64_t)~T1 ^ (uint64_t)T0) &
  464 + (1ULL << 63)))) {
383 xer_ov = 0; 465 xer_ov = 0;
384 } else { 466 } else {
385 xer_so = 1; 467 xer_so = 1;
386 xer_ov = 1; 468 xer_ov = 1;
387 } 469 }
388 - if (likely(T1 != -1)) 470 + if (likely((uint64_t)T1 != UINT64_MAX))
389 xer_ca = 1; 471 xer_ca = 1;
390 } 472 }
  473 +#endif
391 474
392 void do_subfzeo (void) 475 void do_subfzeo (void)
393 { 476 {
394 T1 = T0; 477 T1 = T0;
395 T0 = ~T0 + xer_ca; 478 T0 = ~T0 + xer_ca;
396 - if (likely(!((~T1 ^ (-1)) & ((~T1) ^ T0) & (1 << 31)))) { 479 + if (likely(!(((uint32_t)~T1 ^ UINT32_MAX) &
  480 + ((uint32_t)(~T1) ^ (uint32_t)T0) & (1UL << 31)))) {
397 xer_ov = 0; 481 xer_ov = 0;
398 } else { 482 } else {
399 xer_ov = 1; 483 xer_ov = 1;
400 xer_so = 1; 484 xer_so = 1;
401 } 485 }
402 - if (likely(T0 >= ~T1)) { 486 + if (likely((uint32_t)T0 >= (uint32_t)~T1)) {
403 xer_ca = 0; 487 xer_ca = 0;
404 } else { 488 } else {
405 xer_ca = 1; 489 xer_ca = 1;
406 } 490 }
407 } 491 }
408 492
  493 +#if defined(TARGET_PPC64)
  494 +void do_subfzeo_64 (void)
  495 +{
  496 + T1 = T0;
  497 + T0 = ~T0 + xer_ca;
  498 + if (likely(!(((uint64_t)~T1 ^ UINT64_MAX) &
  499 + ((uint64_t)(~T1) ^ (uint64_t)T0) & (1ULL << 63)))) {
  500 + xer_ov = 0;
  501 + } else {
  502 + xer_ov = 1;
  503 + xer_so = 1;
  504 + }
  505 + if (likely((uint64_t)T0 >= (uint64_t)~T1)) {
  506 + xer_ca = 0;
  507 + } else {
  508 + xer_ca = 1;
  509 + }
  510 +}
  511 +#endif
  512 +
409 /* shift right arithmetic helper */ 513 /* shift right arithmetic helper */
410 void do_sraw (void) 514 void do_sraw (void)
411 { 515 {
412 int32_t ret; 516 int32_t ret;
413 517
414 if (likely(!(T1 & 0x20UL))) { 518 if (likely(!(T1 & 0x20UL))) {
415 - if (likely(T1 != 0)) { 519 + if (likely((uint32_t)T1 != 0)) {
416 ret = (int32_t)T0 >> (T1 & 0x1fUL); 520 ret = (int32_t)T0 >> (T1 & 0x1fUL);
417 if (likely(ret >= 0 || ((int32_t)T0 & ((1 << T1) - 1)) == 0)) { 521 if (likely(ret >= 0 || ((int32_t)T0 & ((1 << T1) - 1)) == 0)) {
418 xer_ca = 0; 522 xer_ca = 0;
@@ -434,6 +538,69 @@ void do_sraw (void) @@ -434,6 +538,69 @@ void do_sraw (void)
434 T0 = ret; 538 T0 = ret;
435 } 539 }
436 540
  541 +#if defined(TARGET_PPC64)
  542 +void do_srad (void)
  543 +{
  544 + int64_t ret;
  545 +
  546 + if (likely(!(T1 & 0x40UL))) {
  547 + if (likely((uint64_t)T1 != 0)) {
  548 + ret = (int64_t)T0 >> (T1 & 0x3FUL);
  549 + if (likely(ret >= 0 || ((int64_t)T0 & ((1 << T1) - 1)) == 0)) {
  550 + xer_ca = 0;
  551 + } else {
  552 + xer_ca = 1;
  553 + }
  554 + } else {
  555 + ret = T0;
  556 + xer_ca = 0;
  557 + }
  558 + } else {
  559 + ret = (-1) * ((uint64_t)T0 >> 63);
  560 + if (likely(ret >= 0 || ((uint64_t)T0 & ~0x8000000000000000ULL) == 0)) {
  561 + xer_ca = 0;
  562 + } else {
  563 + xer_ca = 1;
  564 + }
  565 + }
  566 + T0 = ret;
  567 +}
  568 +#endif
  569 +
  570 +static inline int popcnt (uint32_t val)
  571 +{
  572 + int i;
  573 +
  574 + for (i = 0; val != 0;)
  575 + val = val ^ (val - 1);
  576 +
  577 + return i;
  578 +}
  579 +
  580 +void do_popcntb (void)
  581 +{
  582 + uint32_t ret;
  583 + int i;
  584 +
  585 + ret = 0;
  586 + for (i = 0; i < 32; i += 8)
  587 + ret |= popcnt((T0 >> i) & 0xFF) << i;
  588 + T0 = ret;
  589 +}
  590 +
  591 +#if defined(TARGET_PPC64)
  592 +void do_popcntb_64 (void)
  593 +{
  594 + uint64_t ret;
  595 + int i;
  596 +
  597 + ret = 0;
  598 + for (i = 0; i < 64; i += 8)
  599 + ret |= popcnt((T0 >> i) & 0xFF) << i;
  600 + T0 = ret;
  601 +}
  602 +#endif
  603 +
437 /*****************************************************************************/ 604 /*****************************************************************************/
438 /* Floating point operations helpers */ 605 /* Floating point operations helpers */
439 void do_fctiw (void) 606 void do_fctiw (void)
@@ -459,7 +626,7 @@ void do_fctiwz (void) @@ -459,7 +626,7 @@ void do_fctiwz (void)
459 } p; 626 } p;
460 627
461 /* XXX: higher bits are not supposed to be significant. 628 /* XXX: higher bits are not supposed to be significant.
462 - * to make tests easier, return the same as a real PowerPC 750 (aka G3) 629 + * to make tests easier, return the same as a real PowerPC 750 (aka G3)
463 */ 630 */
464 p.i = float64_to_int32_round_to_zero(FT0, &env->fp_status); 631 p.i = float64_to_int32_round_to_zero(FT0, &env->fp_status);
465 p.i |= 0xFFF80000ULL << 32; 632 p.i |= 0xFFF80000ULL << 32;
@@ -596,26 +763,51 @@ void do_fcmpo (void) @@ -596,26 +763,51 @@ void do_fcmpo (void)
596 #if !defined (CONFIG_USER_ONLY) 763 #if !defined (CONFIG_USER_ONLY)
597 void do_rfi (void) 764 void do_rfi (void)
598 { 765 {
599 - env->nip = env->spr[SPR_SRR0] & ~0x00000003;  
600 - T0 = env->spr[SPR_SRR1] & ~0xFFFF0000UL; 766 + env->nip = (target_ulong)(env->spr[SPR_SRR0] & ~0x00000003);
  767 + T0 = (target_ulong)(env->spr[SPR_SRR1] & ~0xFFFF0000UL);
601 do_store_msr(env, T0); 768 do_store_msr(env, T0);
602 #if defined (DEBUG_OP) 769 #if defined (DEBUG_OP)
603 dump_rfi(); 770 dump_rfi();
604 #endif 771 #endif
605 env->interrupt_request |= CPU_INTERRUPT_EXITTB; 772 env->interrupt_request |= CPU_INTERRUPT_EXITTB;
606 } 773 }
  774 +
  775 +#if defined(TARGET_PPC64)
  776 +void do_rfi_32 (void)
  777 +{
  778 + env->nip = (uint32_t)(env->spr[SPR_SRR0] & ~0x00000003);
  779 + T0 = (uint32_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL);
  780 + do_store_msr(env, T0);
  781 +#if defined (DEBUG_OP)
  782 + dump_rfi();
  783 +#endif
  784 + env->interrupt_request |= CPU_INTERRUPT_EXITTB;
  785 +}
  786 +#endif
607 #endif 787 #endif
608 788
609 void do_tw (int flags) 789 void do_tw (int flags)
610 { 790 {
611 - if (!likely(!((Ts0 < Ts1 && (flags & 0x10)) ||  
612 - (Ts0 > Ts1 && (flags & 0x08)) ||  
613 - (Ts0 == Ts1 && (flags & 0x04)) ||  
614 - (T0 < T1 && (flags & 0x02)) ||  
615 - (T0 > T1 && (flags & 0x01))))) 791 + if (!likely(!(((int32_t)T0 < (int32_t)T1 && (flags & 0x10)) ||
  792 + ((int32_t)T0 > (int32_t)T1 && (flags & 0x08)) ||
  793 + ((int32_t)T0 == (int32_t)T1 && (flags & 0x04)) ||
  794 + ((uint32_t)T0 < (uint32_t)T1 && (flags & 0x02)) ||
  795 + ((uint32_t)T0 > (uint32_t)T1 && (flags & 0x01)))))
616 do_raise_exception_err(EXCP_PROGRAM, EXCP_TRAP); 796 do_raise_exception_err(EXCP_PROGRAM, EXCP_TRAP);
617 } 797 }
618 798
  799 +#if defined(TARGET_PPC64)
  800 +void do_td (int flags)
  801 +{
  802 + if (!likely(!(((int64_t)T0 < (int64_t)T1 && (flags & 0x10)) ||
  803 + ((int64_t)T0 > (int64_t)T1 && (flags & 0x08)) ||
  804 + ((int64_t)T0 == (int64_t)T1 && (flags & 0x04)) ||
  805 + ((uint64_t)T0 < (uint64_t)T1 && (flags & 0x02)) ||
  806 + ((uint64_t)T0 > (uint64_t)T1 && (flags & 0x01)))))
  807 + do_raise_exception_err(EXCP_PROGRAM, EXCP_TRAP);
  808 +}
  809 +#endif
  810 +
619 /* Instruction cache invalidation helper */ 811 /* Instruction cache invalidation helper */
620 void do_icbi (void) 812 void do_icbi (void)
621 { 813 {
@@ -625,20 +817,31 @@ void do_icbi (void) @@ -625,20 +817,31 @@ void do_icbi (void)
625 * (not a fetch) by the MMU. To be sure it will be so, 817 * (not a fetch) by the MMU. To be sure it will be so,
626 * do the load "by hand". 818 * do the load "by hand".
627 */ 819 */
  820 + tmp = ldl_kernel((uint32_t)T0);
  821 + T0 &= ~(ICACHE_LINE_SIZE - 1);
  822 + tb_invalidate_page_range((uint32_t)T0, (uint32_t)(T0 + ICACHE_LINE_SIZE));
  823 +}
  824 +
628 #if defined(TARGET_PPC64) 825 #if defined(TARGET_PPC64)
629 - if (!msr_sf)  
630 - T0 &= 0xFFFFFFFFULL;  
631 -#endif  
632 - tmp = ldl_kernel(T0); 826 +void do_icbi_64 (void)
  827 +{
  828 + uint64_t tmp;
  829 + /* Invalidate one cache line :
  830 + * PowerPC specification says this is to be treated like a load
  831 + * (not a fetch) by the MMU. To be sure it will be so,
  832 + * do the load "by hand".
  833 + */
  834 + tmp = ldq_kernel((uint64_t)T0);
633 T0 &= ~(ICACHE_LINE_SIZE - 1); 835 T0 &= ~(ICACHE_LINE_SIZE - 1);
634 - tb_invalidate_page_range(T0, T0 + ICACHE_LINE_SIZE); 836 + tb_invalidate_page_range((uint64_t)T0, (uint64_t)(T0 + ICACHE_LINE_SIZE));
635 } 837 }
  838 +#endif
636 839
637 /*****************************************************************************/ 840 /*****************************************************************************/
638 /* PowerPC 601 specific instructions (POWER bridge) */ 841 /* PowerPC 601 specific instructions (POWER bridge) */
639 void do_POWER_abso (void) 842 void do_POWER_abso (void)
640 { 843 {
641 - if (T0 == INT32_MIN) { 844 + if ((uint32_t)T0 == INT32_MIN) {
642 T0 = INT32_MAX; 845 T0 = INT32_MAX;
643 xer_ov = 1; 846 xer_ov = 1;
644 xer_so = 1; 847 xer_so = 1;
@@ -679,13 +882,13 @@ void do_POWER_div (void) @@ -679,13 +882,13 @@ void do_POWER_div (void)
679 { 882 {
680 uint64_t tmp; 883 uint64_t tmp;
681 884
682 - if ((Ts0 == INT32_MIN && Ts1 == -1) || Ts1 == 0) { 885 + if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
683 T0 = (long)((-1) * (T0 >> 31)); 886 T0 = (long)((-1) * (T0 >> 31));
684 env->spr[SPR_MQ] = 0; 887 env->spr[SPR_MQ] = 0;
685 } else { 888 } else {
686 tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ]; 889 tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
687 env->spr[SPR_MQ] = tmp % T1; 890 env->spr[SPR_MQ] = tmp % T1;
688 - T0 = tmp / Ts1; 891 + T0 = tmp / (int32_t)T1;
689 } 892 }
690 } 893 }
691 894
@@ -693,7 +896,7 @@ void do_POWER_divo (void) @@ -693,7 +896,7 @@ void do_POWER_divo (void)
693 { 896 {
694 int64_t tmp; 897 int64_t tmp;
695 898
696 - if ((Ts0 == INT32_MIN && Ts1 == -1) || Ts1 == 0) { 899 + if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
697 T0 = (long)((-1) * (T0 >> 31)); 900 T0 = (long)((-1) * (T0 >> 31));
698 env->spr[SPR_MQ] = 0; 901 env->spr[SPR_MQ] = 0;
699 xer_ov = 1; 902 xer_ov = 1;
@@ -701,7 +904,7 @@ void do_POWER_divo (void) @@ -701,7 +904,7 @@ void do_POWER_divo (void)
701 } else { 904 } else {
702 tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ]; 905 tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
703 env->spr[SPR_MQ] = tmp % T1; 906 env->spr[SPR_MQ] = tmp % T1;
704 - tmp /= Ts1; 907 + tmp /= (int32_t)T1;
705 if (tmp > (int64_t)INT32_MAX || tmp < (int64_t)INT32_MIN) { 908 if (tmp > (int64_t)INT32_MAX || tmp < (int64_t)INT32_MIN) {
706 xer_ov = 1; 909 xer_ov = 1;
707 xer_so = 1; 910 xer_so = 1;
@@ -714,35 +917,36 @@ void do_POWER_divo (void) @@ -714,35 +917,36 @@ void do_POWER_divo (void)
714 917
715 void do_POWER_divs (void) 918 void do_POWER_divs (void)
716 { 919 {
717 - if ((Ts0 == INT32_MIN && Ts1 == -1) || Ts1 == 0) { 920 + if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
718 T0 = (long)((-1) * (T0 >> 31)); 921 T0 = (long)((-1) * (T0 >> 31));
719 env->spr[SPR_MQ] = 0; 922 env->spr[SPR_MQ] = 0;
720 } else { 923 } else {
721 env->spr[SPR_MQ] = T0 % T1; 924 env->spr[SPR_MQ] = T0 % T1;
722 - T0 = Ts0 / Ts1; 925 + T0 = (int32_t)T0 / (int32_t)T1;
723 } 926 }
724 } 927 }
725 928
726 void do_POWER_divso (void) 929 void do_POWER_divso (void)
727 { 930 {
728 - if ((Ts0 == INT32_MIN && Ts1 == -1) || Ts1 == 0) { 931 + if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
729 T0 = (long)((-1) * (T0 >> 31)); 932 T0 = (long)((-1) * (T0 >> 31));
730 env->spr[SPR_MQ] = 0; 933 env->spr[SPR_MQ] = 0;
731 xer_ov = 1; 934 xer_ov = 1;
732 xer_so = 1; 935 xer_so = 1;
733 } else { 936 } else {
734 - T0 = Ts0 / Ts1;  
735 - env->spr[SPR_MQ] = Ts0 % Ts1; 937 + T0 = (int32_t)T0 / (int32_t)T1;
  938 + env->spr[SPR_MQ] = (int32_t)T0 % (int32_t)T1;
736 xer_ov = 0; 939 xer_ov = 0;
737 } 940 }
738 } 941 }
739 942
740 void do_POWER_dozo (void) 943 void do_POWER_dozo (void)
741 { 944 {
742 - if (Ts1 > Ts0) { 945 + if ((int32_t)T1 > (int32_t)T0) {
743 T2 = T0; 946 T2 = T0;
744 T0 = T1 - T0; 947 T0 = T1 - T0;
745 - if (((~T2) ^ T1 ^ (-1)) & ((~T2) ^ T0) & (1 << 31)) { 948 + if (((uint32_t)(~T2) ^ (uint32_t)T1 ^ UINT32_MAX) &
  949 + ((uint32_t)(~T2) ^ (uint32_t)T0) & (1UL << 31)) {
746 xer_so = 1; 950 xer_so = 1;
747 xer_ov = 1; 951 xer_ov = 1;
748 } else { 952 } else {
@@ -758,12 +962,12 @@ void do_POWER_maskg (void) @@ -758,12 +962,12 @@ void do_POWER_maskg (void)
758 { 962 {
759 uint32_t ret; 963 uint32_t ret;
760 964
761 - if (T0 == T1 + 1) { 965 + if ((uint32_t)T0 == (uint32_t)(T1 + 1)) {
762 ret = -1; 966 ret = -1;
763 } else { 967 } else {
764 - ret = (((uint32_t)(-1)) >> (T0)) ^  
765 - (((uint32_t)(-1) >> (T1)) >> 1);  
766 - if (T0 > T1) 968 + ret = (((uint32_t)(-1)) >> ((uint32_t)T0)) ^
  969 + (((uint32_t)(-1) >> ((uint32_t)T1)) >> 1);
  970 + if ((uint32_t)T0 > (uint32_t)T1)
767 ret = ~ret; 971 ret = ~ret;
768 } 972 }
769 T0 = ret; 973 T0 = ret;
@@ -812,7 +1016,7 @@ void do_POWER_rfsvc (void) @@ -812,7 +1016,7 @@ void do_POWER_rfsvc (void)
812 /* PowerPC 601 BAT management helper */ 1016 /* PowerPC 601 BAT management helper */
813 void do_store_601_batu (int nr) 1017 void do_store_601_batu (int nr)
814 { 1018 {
815 - do_store_ibatu(env, nr, T0); 1019 + do_store_ibatu(env, nr, (uint32_t)T0);
816 env->DBAT[0][nr] = env->IBAT[0][nr]; 1020 env->DBAT[0][nr] = env->IBAT[0][nr];
817 env->DBAT[1][nr] = env->IBAT[1][nr]; 1021 env->DBAT[1][nr] = env->IBAT[1][nr];
818 } 1022 }
@@ -826,7 +1030,7 @@ void do_store_601_batu (int nr) @@ -826,7 +1030,7 @@ void do_store_601_batu (int nr)
826 void do_op_602_mfrom (void) 1030 void do_op_602_mfrom (void)
827 { 1031 {
828 if (likely(T0 < 602)) { 1032 if (likely(T0 < 602)) {
829 -#ifdef USE_MFROM_ROM_TABLE 1033 +#if defined(USE_MFROM_ROM_TABLE)
830 #include "mfrom_table.c" 1034 #include "mfrom_table.c"
831 T0 = mfrom_ROM_table[T0]; 1035 T0 = mfrom_ROM_table[T0];
832 #else 1036 #else
@@ -854,7 +1058,8 @@ void do_op_602_mfrom (void) @@ -854,7 +1058,8 @@ void do_op_602_mfrom (void)
854 /* Embedded PowerPC specific helpers */ 1058 /* Embedded PowerPC specific helpers */
855 void do_405_check_ov (void) 1059 void do_405_check_ov (void)
856 { 1060 {
857 - if (likely(((T1 ^ T2) >> 31) || !((T0 ^ T2) >> 31))) { 1061 + if (likely((((uint32_t)T1 ^ (uint32_t)T2) >> 31) ||
  1062 + !(((uint32_t)T0 ^ (uint32_t)T2) >> 31))) {
858 xer_ov = 0; 1063 xer_ov = 0;
859 } else { 1064 } else {
860 xer_ov = 1; 1065 xer_ov = 1;
@@ -864,7 +1069,8 @@ void do_405_check_ov (void) @@ -864,7 +1069,8 @@ void do_405_check_ov (void)
864 1069
865 void do_405_check_sat (void) 1070 void do_405_check_sat (void)
866 { 1071 {
867 - if (!likely(((T1 ^ T2) >> 31) || !((T0 ^ T2) >> 31))) { 1072 + if (!likely((((uint32_t)T1 ^ (uint32_t)T2) >> 31) ||
  1073 + !(((uint32_t)T0 ^ (uint32_t)T2) >> 31))) {
868 /* Saturate result */ 1074 /* Saturate result */
869 if (T2 >> 31) { 1075 if (T2 >> 31) {
870 T0 = INT32_MIN; 1076 T0 = INT32_MIN;
@@ -1010,6 +1216,7 @@ void do_tlbia (void) @@ -1010,6 +1216,7 @@ void do_tlbia (void)
1010 1216
1011 void do_tlbie (void) 1217 void do_tlbie (void)
1012 { 1218 {
  1219 + T0 = (uint32_t)T0;
1013 #if !defined(FLUSH_ALL_TLBS) 1220 #if !defined(FLUSH_ALL_TLBS)
1014 if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) { 1221 if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
1015 ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 0); 1222 ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 0);
@@ -1050,13 +1257,78 @@ void do_tlbie (void) @@ -1050,13 +1257,78 @@ void do_tlbie (void)
1050 #endif 1257 #endif
1051 } 1258 }
1052 1259
  1260 +#if defined(TARGET_PPC64)
  1261 +void do_tlbie_64 (void)
  1262 +{
  1263 + T0 = (uint64_t)T0;
  1264 +#if !defined(FLUSH_ALL_TLBS)
  1265 + if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
  1266 + ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 0);
  1267 + if (env->id_tlbs == 1)
  1268 + ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 1);
  1269 + } else if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_4xx)) {
  1270 + /* XXX: TODO */
  1271 +#if 0
  1272 + ppcbooke_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK,
  1273 + env->spr[SPR_BOOKE_PID]);
  1274 +#endif
  1275 + } else {
  1276 + /* tlbie invalidate TLBs for all segments
  1277 + * As we have 2^36 segments, invalidate all qemu TLBs
  1278 + */
  1279 +#if 0
  1280 + T0 &= TARGET_PAGE_MASK;
  1281 + T0 &= ~((target_ulong)-1 << 28);
  1282 + /* XXX: this case should be optimized,
  1283 + * giving a mask to tlb_flush_page
  1284 + */
  1285 + tlb_flush_page(env, T0 | (0x0 << 28));
  1286 + tlb_flush_page(env, T0 | (0x1 << 28));
  1287 + tlb_flush_page(env, T0 | (0x2 << 28));
  1288 + tlb_flush_page(env, T0 | (0x3 << 28));
  1289 + tlb_flush_page(env, T0 | (0x4 << 28));
  1290 + tlb_flush_page(env, T0 | (0x5 << 28));
  1291 + tlb_flush_page(env, T0 | (0x6 << 28));
  1292 + tlb_flush_page(env, T0 | (0x7 << 28));
  1293 + tlb_flush_page(env, T0 | (0x8 << 28));
  1294 + tlb_flush_page(env, T0 | (0x9 << 28));
  1295 + tlb_flush_page(env, T0 | (0xA << 28));
  1296 + tlb_flush_page(env, T0 | (0xB << 28));
  1297 + tlb_flush_page(env, T0 | (0xC << 28));
  1298 + tlb_flush_page(env, T0 | (0xD << 28));
  1299 + tlb_flush_page(env, T0 | (0xE << 28));
  1300 + tlb_flush_page(env, T0 | (0xF << 28));
  1301 +#else
  1302 + tlb_flush(env, 1);
  1303 +#endif
  1304 + }
  1305 +#else
  1306 + do_tlbia();
  1307 +#endif
  1308 +}
  1309 +#endif
  1310 +
  1311 +#if defined(TARGET_PPC64)
  1312 +void do_slbia (void)
  1313 +{
  1314 + /* XXX: TODO */
  1315 + tlb_flush(env, 1);
  1316 +}
  1317 +
  1318 +void do_slbie (void)
  1319 +{
  1320 + /* XXX: TODO */
  1321 + tlb_flush(env, 1);
  1322 +}
  1323 +#endif
  1324 +
1053 /* Software driven TLBs management */ 1325 /* Software driven TLBs management */
1054 /* PowerPC 602/603 software TLB load instructions helpers */ 1326 /* PowerPC 602/603 software TLB load instructions helpers */
1055 void do_load_6xx_tlb (int is_code) 1327 void do_load_6xx_tlb (int is_code)
1056 { 1328 {
1057 target_ulong RPN, CMP, EPN; 1329 target_ulong RPN, CMP, EPN;
1058 int way; 1330 int way;
1059 - 1331 +
1060 RPN = env->spr[SPR_RPA]; 1332 RPN = env->spr[SPR_RPA];
1061 if (is_code) { 1333 if (is_code) {
1062 CMP = env->spr[SPR_ICMP]; 1334 CMP = env->spr[SPR_ICMP];
@@ -1074,7 +1346,8 @@ void do_load_6xx_tlb (int is_code) @@ -1074,7 +1346,8 @@ void do_load_6xx_tlb (int is_code)
1074 } 1346 }
1075 #endif 1347 #endif
1076 /* Store this TLB */ 1348 /* Store this TLB */
1077 - ppc6xx_tlb_store(env, T0 & TARGET_PAGE_MASK, way, is_code, CMP, RPN); 1349 + ppc6xx_tlb_store(env, (uint32_t)(T0 & TARGET_PAGE_MASK),
  1350 + way, is_code, CMP, RPN);
1078 } 1351 }
1079 1352
1080 /* Helpers for 4xx TLB management */ 1353 /* Helpers for 4xx TLB management */
target-ppc/op_helper.h
@@ -35,6 +35,17 @@ void glue(do_POWER2_lfq_le, MEMSUFFIX) (void); @@ -35,6 +35,17 @@ void glue(do_POWER2_lfq_le, MEMSUFFIX) (void);
35 void glue(do_POWER2_stfq, MEMSUFFIX) (void); 35 void glue(do_POWER2_stfq, MEMSUFFIX) (void);
36 void glue(do_POWER2_stfq_le, MEMSUFFIX) (void); 36 void glue(do_POWER2_stfq_le, MEMSUFFIX) (void);
37 37
  38 +#if defined(TARGET_PPC64)
  39 +void glue(do_lsw_64, MEMSUFFIX) (int dst);
  40 +void glue(do_lsw_le_64, MEMSUFFIX) (int dst);
  41 +void glue(do_stsw_64, MEMSUFFIX) (int src);
  42 +void glue(do_stsw_le_64, MEMSUFFIX) (int src);
  43 +void glue(do_lmw_64, MEMSUFFIX) (int dst);
  44 +void glue(do_lmw_le_64, MEMSUFFIX) (int dst);
  45 +void glue(do_stmw_64, MEMSUFFIX) (int src);
  46 +void glue(do_stmw_le_64, MEMSUFFIX) (int src);
  47 +#endif
  48 +
38 #else 49 #else
39 50
40 /* Registers load and stores */ 51 /* Registers load and stores */
@@ -46,23 +57,34 @@ void do_load_fpscr (void); @@ -46,23 +57,34 @@ void do_load_fpscr (void);
46 void do_store_fpscr (uint32_t mask); 57 void do_store_fpscr (uint32_t mask);
47 58
48 /* Integer arithmetic helpers */ 59 /* Integer arithmetic helpers */
49 -void do_addo (void);  
50 -void do_addco (void);  
51 void do_adde (void); 60 void do_adde (void);
52 -void do_addeo (void);  
53 void do_addmeo (void); 61 void do_addmeo (void);
54 -void do_addzeo (void);  
55 void do_divwo (void); 62 void do_divwo (void);
56 void do_divwuo (void); 63 void do_divwuo (void);
57 void do_mullwo (void); 64 void do_mullwo (void);
58 void do_nego (void); 65 void do_nego (void);
59 -void do_subfo (void);  
60 -void do_subfco (void);  
61 void do_subfe (void); 66 void do_subfe (void);
62 -void do_subfeo (void);  
63 void do_subfmeo (void); 67 void do_subfmeo (void);
64 void do_subfzeo (void); 68 void do_subfzeo (void);
65 -void do_sraw(void); 69 +void do_sraw (void);
  70 +#if defined(TARGET_PPC64)
  71 +void do_adde_64 (void);
  72 +void do_addmeo_64 (void);
  73 +void do_imul64 (uint64_t *tl, uint64_t *th);
  74 +void do_mul64 (uint64_t *tl, uint64_t *th);
  75 +void do_divdo (void);
  76 +void do_divduo (void);
  77 +void do_mulldo (void);
  78 +void do_nego_64 (void);
  79 +void do_subfe_64 (void);
  80 +void do_subfmeo_64 (void);
  81 +void do_subfzeo_64 (void);
  82 +void do_srad (void);
  83 +#endif
  84 +void do_popcntb (void);
  85 +#if defined(TARGET_PPC64)
  86 +void do_popcntb_64 (void);
  87 +#endif
66 88
67 /* Floating-point arithmetic helpers */ 89 /* Floating-point arithmetic helpers */
68 void do_fsqrt (void); 90 void do_fsqrt (void);
@@ -77,13 +99,29 @@ void do_fcmpu (void); @@ -77,13 +99,29 @@ void do_fcmpu (void);
77 void do_fcmpo (void); 99 void do_fcmpo (void);
78 100
79 void do_tw (int flags); 101 void do_tw (int flags);
  102 +#if defined(TARGET_PPC64)
  103 +void do_td (int flags);
  104 +#endif
80 void do_icbi (void); 105 void do_icbi (void);
  106 +#if defined(TARGET_PPC64)
  107 +void do_icbi_64 (void);
  108 +#endif
81 109
82 #if !defined(CONFIG_USER_ONLY) 110 #if !defined(CONFIG_USER_ONLY)
83 void do_rfi (void); 111 void do_rfi (void);
  112 +#if defined(TARGET_PPC64)
  113 +void do_rfi_32 (void);
  114 +#endif
84 void do_tlbia (void); 115 void do_tlbia (void);
85 void do_tlbie (void); 116 void do_tlbie (void);
  117 +#if defined(TARGET_PPC64)
  118 +void do_tlbie_64 (void);
  119 +#endif
86 void do_load_6xx_tlb (int is_code); 120 void do_load_6xx_tlb (int is_code);
  121 +#if defined(TARGET_PPC64)
  122 +void do_slbia (void);
  123 +void do_slbie (void);
  124 +#endif
87 #endif 125 #endif
88 126
89 /* POWER / PowerPC 601 specific helpers */ 127 /* POWER / PowerPC 601 specific helpers */
target-ppc/op_helper_mem.h
1 /* 1 /*
2 * PowerPC emulation micro-operations helpers for qemu. 2 * PowerPC emulation micro-operations helpers for qemu.
3 - * 3 + *
4 * Copyright (c) 2003-2007 Jocelyn Mayer 4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
@@ -37,98 +37,210 @@ static inline void glue(st32r, MEMSUFFIX) (target_ulong EA, target_ulong data) @@ -37,98 +37,210 @@ static inline void glue(st32r, MEMSUFFIX) (target_ulong EA, target_ulong data)
37 void glue(do_lmw, MEMSUFFIX) (int dst) 37 void glue(do_lmw, MEMSUFFIX) (int dst)
38 { 38 {
39 for (; dst < 32; dst++, T0 += 4) { 39 for (; dst < 32; dst++, T0 += 4) {
40 - ugpr(dst) = glue(ldl, MEMSUFFIX)(T0); 40 + ugpr(dst) = glue(ldl, MEMSUFFIX)((uint32_t)T0);
  41 + }
  42 +}
  43 +
  44 +#if defined(TARGET_PPC64)
  45 +void glue(do_lmw_64, MEMSUFFIX) (int dst)
  46 +{
  47 + for (; dst < 32; dst++, T0 += 4) {
  48 + ugpr(dst) = glue(ldl, MEMSUFFIX)((uint64_t)T0);
41 } 49 }
42 } 50 }
  51 +#endif
43 52
44 void glue(do_stmw, MEMSUFFIX) (int src) 53 void glue(do_stmw, MEMSUFFIX) (int src)
45 { 54 {
46 for (; src < 32; src++, T0 += 4) { 55 for (; src < 32; src++, T0 += 4) {
47 - glue(stl, MEMSUFFIX)(T0, ugpr(src)); 56 + glue(stl, MEMSUFFIX)((uint32_t)T0, ugpr(src));
  57 + }
  58 +}
  59 +
  60 +#if defined(TARGET_PPC64)
  61 +void glue(do_stmw_64, MEMSUFFIX) (int src)
  62 +{
  63 + for (; src < 32; src++, T0 += 4) {
  64 + glue(stl, MEMSUFFIX)((uint64_t)T0, ugpr(src));
48 } 65 }
49 } 66 }
  67 +#endif
50 68
51 void glue(do_lmw_le, MEMSUFFIX) (int dst) 69 void glue(do_lmw_le, MEMSUFFIX) (int dst)
52 { 70 {
53 for (; dst < 32; dst++, T0 += 4) { 71 for (; dst < 32; dst++, T0 += 4) {
54 - ugpr(dst) = glue(ld32r, MEMSUFFIX)(T0); 72 + ugpr(dst) = glue(ld32r, MEMSUFFIX)((uint32_t)T0);
  73 + }
  74 +}
  75 +
  76 +#if defined(TARGET_PPC64)
  77 +void glue(do_lmw_le_64, MEMSUFFIX) (int dst)
  78 +{
  79 + for (; dst < 32; dst++, T0 += 4) {
  80 + ugpr(dst) = glue(ld32r, MEMSUFFIX)((uint64_t)T0);
55 } 81 }
56 } 82 }
  83 +#endif
57 84
58 void glue(do_stmw_le, MEMSUFFIX) (int src) 85 void glue(do_stmw_le, MEMSUFFIX) (int src)
59 { 86 {
60 for (; src < 32; src++, T0 += 4) { 87 for (; src < 32; src++, T0 += 4) {
61 - glue(st32r, MEMSUFFIX)(T0, ugpr(src)); 88 + glue(st32r, MEMSUFFIX)((uint32_t)T0, ugpr(src));
62 } 89 }
63 } 90 }
64 91
  92 +#if defined(TARGET_PPC64)
  93 +void glue(do_stmw_le_64, MEMSUFFIX) (int src)
  94 +{
  95 + for (; src < 32; src++, T0 += 4) {
  96 + glue(st32r, MEMSUFFIX)((uint64_t)T0, ugpr(src));
  97 + }
  98 +}
  99 +#endif
  100 +
65 void glue(do_lsw, MEMSUFFIX) (int dst) 101 void glue(do_lsw, MEMSUFFIX) (int dst)
66 { 102 {
67 uint32_t tmp; 103 uint32_t tmp;
68 int sh; 104 int sh;
69 105
70 for (; T1 > 3; T1 -= 4, T0 += 4) { 106 for (; T1 > 3; T1 -= 4, T0 += 4) {
71 - ugpr(dst++) = glue(ldl, MEMSUFFIX)(T0); 107 + ugpr(dst++) = glue(ldl, MEMSUFFIX)((uint32_t)T0);
72 if (unlikely(dst == 32)) 108 if (unlikely(dst == 32))
73 dst = 0; 109 dst = 0;
74 } 110 }
75 if (unlikely(T1 != 0)) { 111 if (unlikely(T1 != 0)) {
76 tmp = 0; 112 tmp = 0;
77 for (sh = 24; T1 > 0; T1--, T0++, sh -= 8) { 113 for (sh = 24; T1 > 0; T1--, T0++, sh -= 8) {
78 - tmp |= glue(ldub, MEMSUFFIX)(T0) << sh; 114 + tmp |= glue(ldub, MEMSUFFIX)((uint32_t)T0) << sh;
79 } 115 }
80 ugpr(dst) = tmp; 116 ugpr(dst) = tmp;
81 } 117 }
82 } 118 }
83 119
  120 +#if defined(TARGET_PPC64)
  121 +void glue(do_lsw_64, MEMSUFFIX) (int dst)
  122 +{
  123 + uint32_t tmp;
  124 + int sh;
  125 +
  126 + for (; T1 > 3; T1 -= 4, T0 += 4) {
  127 + ugpr(dst++) = glue(ldl, MEMSUFFIX)((uint64_t)T0);
  128 + if (unlikely(dst == 32))
  129 + dst = 0;
  130 + }
  131 + if (unlikely(T1 != 0)) {
  132 + tmp = 0;
  133 + for (sh = 24; T1 > 0; T1--, T0++, sh -= 8) {
  134 + tmp |= glue(ldub, MEMSUFFIX)((uint64_t)T0) << sh;
  135 + }
  136 + ugpr(dst) = tmp;
  137 + }
  138 +}
  139 +#endif
  140 +
84 void glue(do_stsw, MEMSUFFIX) (int src) 141 void glue(do_stsw, MEMSUFFIX) (int src)
85 { 142 {
86 int sh; 143 int sh;
87 144
88 for (; T1 > 3; T1 -= 4, T0 += 4) { 145 for (; T1 > 3; T1 -= 4, T0 += 4) {
89 - glue(stl, MEMSUFFIX)(T0, ugpr(src++)); 146 + glue(stl, MEMSUFFIX)((uint32_t)T0, ugpr(src++));
90 if (unlikely(src == 32)) 147 if (unlikely(src == 32))
91 src = 0; 148 src = 0;
92 } 149 }
93 if (unlikely(T1 != 0)) { 150 if (unlikely(T1 != 0)) {
94 for (sh = 24; T1 > 0; T1--, T0++, sh -= 8) 151 for (sh = 24; T1 > 0; T1--, T0++, sh -= 8)
95 - glue(stb, MEMSUFFIX)(T0, (ugpr(src) >> sh) & 0xFF); 152 + glue(stb, MEMSUFFIX)((uint32_t)T0, (ugpr(src) >> sh) & 0xFF);
96 } 153 }
97 } 154 }
98 155
  156 +#if defined(TARGET_PPC64)
  157 +void glue(do_stsw_64, MEMSUFFIX) (int src)
  158 +{
  159 + int sh;
  160 +
  161 + for (; T1 > 3; T1 -= 4, T0 += 4) {
  162 + glue(stl, MEMSUFFIX)((uint64_t)T0, ugpr(src++));
  163 + if (unlikely(src == 32))
  164 + src = 0;
  165 + }
  166 + if (unlikely(T1 != 0)) {
  167 + for (sh = 24; T1 > 0; T1--, T0++, sh -= 8)
  168 + glue(stb, MEMSUFFIX)((uint64_t)T0, (ugpr(src) >> sh) & 0xFF);
  169 + }
  170 +}
  171 +#endif
  172 +
99 void glue(do_lsw_le, MEMSUFFIX) (int dst) 173 void glue(do_lsw_le, MEMSUFFIX) (int dst)
100 { 174 {
101 uint32_t tmp; 175 uint32_t tmp;
102 int sh; 176 int sh;
103 177
104 for (; T1 > 3; T1 -= 4, T0 += 4) { 178 for (; T1 > 3; T1 -= 4, T0 += 4) {
105 - ugpr(dst++) = glue(ld32r, MEMSUFFIX)(T0); 179 + ugpr(dst++) = glue(ld32r, MEMSUFFIX)((uint32_t)T0);
  180 + if (unlikely(dst == 32))
  181 + dst = 0;
  182 + }
  183 + if (unlikely(T1 != 0)) {
  184 + tmp = 0;
  185 + for (sh = 0; T1 > 0; T1--, T0++, sh += 8) {
  186 + tmp |= glue(ldub, MEMSUFFIX)((uint32_t)T0) << sh;
  187 + }
  188 + ugpr(dst) = tmp;
  189 + }
  190 +}
  191 +
  192 +#if defined(TARGET_PPC64)
  193 +void glue(do_lsw_le_64, MEMSUFFIX) (int dst)
  194 +{
  195 + uint32_t tmp;
  196 + int sh;
  197 +
  198 + for (; T1 > 3; T1 -= 4, T0 += 4) {
  199 + ugpr(dst++) = glue(ld32r, MEMSUFFIX)((uint64_t)T0);
106 if (unlikely(dst == 32)) 200 if (unlikely(dst == 32))
107 dst = 0; 201 dst = 0;
108 } 202 }
109 if (unlikely(T1 != 0)) { 203 if (unlikely(T1 != 0)) {
110 tmp = 0; 204 tmp = 0;
111 for (sh = 0; T1 > 0; T1--, T0++, sh += 8) { 205 for (sh = 0; T1 > 0; T1--, T0++, sh += 8) {
112 - tmp |= glue(ldub, MEMSUFFIX)(T0) << sh; 206 + tmp |= glue(ldub, MEMSUFFIX)((uint64_t)T0) << sh;
113 } 207 }
114 ugpr(dst) = tmp; 208 ugpr(dst) = tmp;
115 } 209 }
116 } 210 }
  211 +#endif
117 212
118 void glue(do_stsw_le, MEMSUFFIX) (int src) 213 void glue(do_stsw_le, MEMSUFFIX) (int src)
119 { 214 {
120 int sh; 215 int sh;
121 216
122 for (; T1 > 3; T1 -= 4, T0 += 4) { 217 for (; T1 > 3; T1 -= 4, T0 += 4) {
123 - glue(st32r, MEMSUFFIX)(T0, ugpr(src++)); 218 + glue(st32r, MEMSUFFIX)((uint32_t)T0, ugpr(src++));
  219 + if (unlikely(src == 32))
  220 + src = 0;
  221 + }
  222 + if (unlikely(T1 != 0)) {
  223 + for (sh = 0; T1 > 0; T1--, T0++, sh += 8)
  224 + glue(stb, MEMSUFFIX)((uint32_t)T0, (ugpr(src) >> sh) & 0xFF);
  225 + }
  226 +}
  227 +
  228 +#if defined(TARGET_PPC64)
  229 +void glue(do_stsw_le_64, MEMSUFFIX) (int src)
  230 +{
  231 + int sh;
  232 +
  233 + for (; T1 > 3; T1 -= 4, T0 += 4) {
  234 + glue(st32r, MEMSUFFIX)((uint64_t)T0, ugpr(src++));
124 if (unlikely(src == 32)) 235 if (unlikely(src == 32))
125 src = 0; 236 src = 0;
126 } 237 }
127 if (unlikely(T1 != 0)) { 238 if (unlikely(T1 != 0)) {
128 for (sh = 0; T1 > 0; T1--, T0++, sh += 8) 239 for (sh = 0; T1 > 0; T1--, T0++, sh += 8)
129 - glue(stb, MEMSUFFIX)(T0, (ugpr(src) >> sh) & 0xFF); 240 + glue(stb, MEMSUFFIX)((uint64_t)T0, (ugpr(src) >> sh) & 0xFF);
130 } 241 }
131 } 242 }
  243 +#endif
132 244
133 /* PPC 601 specific instructions (POWER bridge) */ 245 /* PPC 601 specific instructions (POWER bridge) */
134 // XXX: to be tested 246 // XXX: to be tested
@@ -139,7 +251,7 @@ void glue(do_POWER_lscbx, MEMSUFFIX) (int dest, int ra, int rb) @@ -139,7 +251,7 @@ void glue(do_POWER_lscbx, MEMSUFFIX) (int dest, int ra, int rb)
139 d = 24; 251 d = 24;
140 reg = dest; 252 reg = dest;
141 for (i = 0; i < T1; i++) { 253 for (i = 0; i < T1; i++) {
142 - c = glue(ldub, MEMSUFFIX)(T0++); 254 + c = glue(ldub, MEMSUFFIX)((uint32_t)T0++);
143 /* ra (if not 0) and rb are never modified */ 255 /* ra (if not 0) and rb are never modified */
144 if (likely(reg != rb && (ra == 0 || reg != ra))) { 256 if (likely(reg != rb && (ra == 0 || reg != ra))) {
145 ugpr(reg) = (ugpr(reg) & ~(0xFF << d)) | (c << d); 257 ugpr(reg) = (ugpr(reg) & ~(0xFF << d)) | (c << d);
@@ -160,8 +272,8 @@ void glue(do_POWER_lscbx, MEMSUFFIX) (int dest, int ra, int rb) @@ -160,8 +272,8 @@ void glue(do_POWER_lscbx, MEMSUFFIX) (int dest, int ra, int rb)
160 /* XXX: TAGs are not managed */ 272 /* XXX: TAGs are not managed */
161 void glue(do_POWER2_lfq, MEMSUFFIX) (void) 273 void glue(do_POWER2_lfq, MEMSUFFIX) (void)
162 { 274 {
163 - FT0 = glue(ldfq, MEMSUFFIX)(T0);  
164 - FT1 = glue(ldfq, MEMSUFFIX)(T0 + 4); 275 + FT0 = glue(ldfq, MEMSUFFIX)((uint32_t)T0);
  276 + FT1 = glue(ldfq, MEMSUFFIX)((uint32_t)(T0 + 4));
165 } 277 }
166 278
167 static inline double glue(ldfqr, MEMSUFFIX) (target_ulong EA) 279 static inline double glue(ldfqr, MEMSUFFIX) (target_ulong EA)
@@ -186,14 +298,14 @@ static inline double glue(ldfqr, MEMSUFFIX) (target_ulong EA) @@ -186,14 +298,14 @@ static inline double glue(ldfqr, MEMSUFFIX) (target_ulong EA)
186 298
187 void glue(do_POWER2_lfq_le, MEMSUFFIX) (void) 299 void glue(do_POWER2_lfq_le, MEMSUFFIX) (void)
188 { 300 {
189 - FT0 = glue(ldfqr, MEMSUFFIX)(T0 + 4);  
190 - FT1 = glue(ldfqr, MEMSUFFIX)(T0); 301 + FT0 = glue(ldfqr, MEMSUFFIX)((uint32_t)(T0 + 4));
  302 + FT1 = glue(ldfqr, MEMSUFFIX)((uint32_t)T0);
191 } 303 }
192 304
193 void glue(do_POWER2_stfq, MEMSUFFIX) (void) 305 void glue(do_POWER2_stfq, MEMSUFFIX) (void)
194 { 306 {
195 - glue(stfq, MEMSUFFIX)(T0, FT0);  
196 - glue(stfq, MEMSUFFIX)(T0 + 4, FT1); 307 + glue(stfq, MEMSUFFIX)((uint32_t)T0, FT0);
  308 + glue(stfq, MEMSUFFIX)((uint32_t)(T0 + 4), FT1);
197 } 309 }
198 310
199 static inline void glue(stfqr, MEMSUFFIX) (target_ulong EA, double d) 311 static inline void glue(stfqr, MEMSUFFIX) (target_ulong EA, double d)
@@ -217,8 +329,8 @@ static inline void glue(stfqr, MEMSUFFIX) (target_ulong EA, double d) @@ -217,8 +329,8 @@ static inline void glue(stfqr, MEMSUFFIX) (target_ulong EA, double d)
217 329
218 void glue(do_POWER2_stfq_le, MEMSUFFIX) (void) 330 void glue(do_POWER2_stfq_le, MEMSUFFIX) (void)
219 { 331 {
220 - glue(stfqr, MEMSUFFIX)(T0 + 4, FT0);  
221 - glue(stfqr, MEMSUFFIX)(T0, FT1); 332 + glue(stfqr, MEMSUFFIX)((uint32_t)(T0 + 4), FT0);
  333 + glue(stfqr, MEMSUFFIX)((uint32_t)T0, FT1);
222 } 334 }
223 335
224 #undef MEMSUFFIX 336 #undef MEMSUFFIX
target-ppc/op_mem.h
@@ -37,6 +37,33 @@ static inline uint32_t glue(ld32r, MEMSUFFIX) (target_ulong EA) @@ -37,6 +37,33 @@ static inline uint32_t glue(ld32r, MEMSUFFIX) (target_ulong EA)
37 ((tmp & 0x0000FF00) << 8) | ((tmp & 0x000000FF) << 24); 37 ((tmp & 0x0000FF00) << 8) | ((tmp & 0x000000FF) << 24);
38 } 38 }
39 39
  40 +#if defined(TARGET_PPC64)
  41 +static inline int64_t glue(ldsl, MEMSUFFIX) (target_ulong EA)
  42 +{
  43 + return (int32_t)glue(ldl, MEMSUFFIX)(EA);
  44 +}
  45 +
  46 +static inline uint64_t glue(ld64r, MEMSUFFIX) (target_ulong EA)
  47 +{
  48 + uint64_t tmp = glue(ldq, MEMSUFFIX)(EA);
  49 + return ((tmp & 0xFF00000000000000ULL) >> 56) |
  50 + ((tmp & 0x00FF000000000000ULL) >> 40) |
  51 + ((tmp & 0x0000FF0000000000ULL) >> 24) |
  52 + ((tmp & 0x000000FF00000000ULL) >> 8) |
  53 + ((tmp & 0x00000000FF000000ULL) << 8) |
  54 + ((tmp & 0x0000000000FF0000ULL) << 24) |
  55 + ((tmp & 0x000000000000FF00ULL) << 40) |
  56 + ((tmp & 0x00000000000000FFULL) << 54);
  57 +}
  58 +
  59 +static inline int64_t glue(ld32rs, MEMSUFFIX) (target_ulong EA)
  60 +{
  61 + uint32_t tmp = glue(ldl, MEMSUFFIX)(EA);
  62 + return (int32_t)((tmp & 0xFF000000) >> 24) | ((tmp & 0x00FF0000) >> 8) |
  63 + ((tmp & 0x0000FF00) << 8) | ((tmp & 0x000000FF) << 24);
  64 +}
  65 +#endif
  66 +
40 static inline void glue(st16r, MEMSUFFIX) (target_ulong EA, uint16_t data) 67 static inline void glue(st16r, MEMSUFFIX) (target_ulong EA, uint16_t data)
41 { 68 {
42 uint16_t tmp = ((data & 0xFF00) >> 8) | ((data & 0x00FF) << 8); 69 uint16_t tmp = ((data & 0xFF00) >> 8) | ((data & 0x00FF) << 8);
@@ -50,140 +77,328 @@ static inline void glue(st32r, MEMSUFFIX) (target_ulong EA, uint32_t data) @@ -50,140 +77,328 @@ static inline void glue(st32r, MEMSUFFIX) (target_ulong EA, uint32_t data)
50 glue(stl, MEMSUFFIX)(EA, tmp); 77 glue(stl, MEMSUFFIX)(EA, tmp);
51 } 78 }
52 79
  80 +#if defined(TARGET_PPC64)
  81 +static inline void glue(st64r, MEMSUFFIX) (target_ulong EA, uint64_t data)
  82 +{
  83 + uint64_t tmp = ((data & 0xFF00000000000000ULL) >> 56) |
  84 + ((data & 0x00FF000000000000ULL) >> 40) |
  85 + ((data & 0x0000FF0000000000ULL) >> 24) |
  86 + ((data & 0x000000FF00000000ULL) >> 8) |
  87 + ((data & 0x00000000FF000000ULL) << 8) |
  88 + ((data & 0x0000000000FF0000ULL) << 24) |
  89 + ((data & 0x000000000000FF00ULL) << 40) |
  90 + ((data & 0x00000000000000FFULL) << 56);
  91 + glue(stq, MEMSUFFIX)(EA, tmp);
  92 +}
  93 +#endif
  94 +
53 /*** Integer load ***/ 95 /*** Integer load ***/
54 #define PPC_LD_OP(name, op) \ 96 #define PPC_LD_OP(name, op) \
55 -PPC_OP(glue(glue(l, name), MEMSUFFIX)) \ 97 +void OPPROTO glue(glue(op_l, name), MEMSUFFIX) (void) \
56 { \ 98 { \
57 - T1 = glue(op, MEMSUFFIX)(T0); \ 99 + T1 = glue(op, MEMSUFFIX)((uint32_t)T0); \
58 RETURN(); \ 100 RETURN(); \
59 } 101 }
60 102
  103 +#if defined(TARGET_PPC64)
  104 +#define PPC_LD_OP_64(name, op) \
  105 +void OPPROTO glue(glue(glue(op_l, name), _64), MEMSUFFIX) (void) \
  106 +{ \
  107 + T1 = glue(op, MEMSUFFIX)((uint64_t)T0); \
  108 + RETURN(); \
  109 +}
  110 +#endif
  111 +
61 #define PPC_ST_OP(name, op) \ 112 #define PPC_ST_OP(name, op) \
62 -PPC_OP(glue(glue(st, name), MEMSUFFIX)) \ 113 +void OPPROTO glue(glue(op_st, name), MEMSUFFIX) (void) \
63 { \ 114 { \
64 - glue(op, MEMSUFFIX)(T0, T1); \ 115 + glue(op, MEMSUFFIX)((uint32_t)T0, T1); \
65 RETURN(); \ 116 RETURN(); \
66 } 117 }
67 118
  119 +#if defined(TARGET_PPC64)
  120 +#define PPC_ST_OP_64(name, op) \
  121 +void OPPROTO glue(glue(glue(op_st, name), _64), MEMSUFFIX) (void) \
  122 +{ \
  123 + glue(op, MEMSUFFIX)((uint64_t)T0, T1); \
  124 + RETURN(); \
  125 +}
  126 +#endif
  127 +
68 PPC_LD_OP(bz, ldub); 128 PPC_LD_OP(bz, ldub);
69 PPC_LD_OP(ha, ldsw); 129 PPC_LD_OP(ha, ldsw);
70 PPC_LD_OP(hz, lduw); 130 PPC_LD_OP(hz, lduw);
71 PPC_LD_OP(wz, ldl); 131 PPC_LD_OP(wz, ldl);
  132 +#if defined(TARGET_PPC64)
  133 +PPC_LD_OP(d, ldq);
  134 +PPC_LD_OP(wa, ldsl);
  135 +PPC_LD_OP_64(d, ldq);
  136 +PPC_LD_OP_64(wa, ldsl);
  137 +PPC_LD_OP_64(bz, ldub);
  138 +PPC_LD_OP_64(ha, ldsw);
  139 +PPC_LD_OP_64(hz, lduw);
  140 +PPC_LD_OP_64(wz, ldl);
  141 +#endif
72 142
73 PPC_LD_OP(ha_le, ld16rs); 143 PPC_LD_OP(ha_le, ld16rs);
74 PPC_LD_OP(hz_le, ld16r); 144 PPC_LD_OP(hz_le, ld16r);
75 PPC_LD_OP(wz_le, ld32r); 145 PPC_LD_OP(wz_le, ld32r);
  146 +#if defined(TARGET_PPC64)
  147 +PPC_LD_OP(d_le, ld64r);
  148 +PPC_LD_OP(wa_le, ld32rs);
  149 +PPC_LD_OP_64(d_le, ld64r);
  150 +PPC_LD_OP_64(wa_le, ld32rs);
  151 +PPC_LD_OP_64(ha_le, ld16rs);
  152 +PPC_LD_OP_64(hz_le, ld16r);
  153 +PPC_LD_OP_64(wz_le, ld32r);
  154 +#endif
76 155
77 /*** Integer store ***/ 156 /*** Integer store ***/
78 PPC_ST_OP(b, stb); 157 PPC_ST_OP(b, stb);
79 PPC_ST_OP(h, stw); 158 PPC_ST_OP(h, stw);
80 PPC_ST_OP(w, stl); 159 PPC_ST_OP(w, stl);
  160 +#if defined(TARGET_PPC64)
  161 +PPC_ST_OP(d, stq);
  162 +PPC_ST_OP_64(d, stq);
  163 +PPC_ST_OP_64(b, stb);
  164 +PPC_ST_OP_64(h, stw);
  165 +PPC_ST_OP_64(w, stl);
  166 +#endif
81 167
82 PPC_ST_OP(h_le, st16r); 168 PPC_ST_OP(h_le, st16r);
83 PPC_ST_OP(w_le, st32r); 169 PPC_ST_OP(w_le, st32r);
  170 +#if defined(TARGET_PPC64)
  171 +PPC_ST_OP(d_le, st64r);
  172 +PPC_ST_OP_64(d_le, st64r);
  173 +PPC_ST_OP_64(h_le, st16r);
  174 +PPC_ST_OP_64(w_le, st32r);
  175 +#endif
84 176
85 /*** Integer load and store with byte reverse ***/ 177 /*** Integer load and store with byte reverse ***/
86 PPC_LD_OP(hbr, ld16r); 178 PPC_LD_OP(hbr, ld16r);
87 PPC_LD_OP(wbr, ld32r); 179 PPC_LD_OP(wbr, ld32r);
88 PPC_ST_OP(hbr, st16r); 180 PPC_ST_OP(hbr, st16r);
89 PPC_ST_OP(wbr, st32r); 181 PPC_ST_OP(wbr, st32r);
  182 +#if defined(TARGET_PPC64)
  183 +PPC_LD_OP_64(hbr, ld16r);
  184 +PPC_LD_OP_64(wbr, ld32r);
  185 +PPC_ST_OP_64(hbr, st16r);
  186 +PPC_ST_OP_64(wbr, st32r);
  187 +#endif
90 188
91 PPC_LD_OP(hbr_le, lduw); 189 PPC_LD_OP(hbr_le, lduw);
92 PPC_LD_OP(wbr_le, ldl); 190 PPC_LD_OP(wbr_le, ldl);
93 PPC_ST_OP(hbr_le, stw); 191 PPC_ST_OP(hbr_le, stw);
94 PPC_ST_OP(wbr_le, stl); 192 PPC_ST_OP(wbr_le, stl);
  193 +#if defined(TARGET_PPC64)
  194 +PPC_LD_OP_64(hbr_le, lduw);
  195 +PPC_LD_OP_64(wbr_le, ldl);
  196 +PPC_ST_OP_64(hbr_le, stw);
  197 +PPC_ST_OP_64(wbr_le, stl);
  198 +#endif
95 199
96 /*** Integer load and store multiple ***/ 200 /*** Integer load and store multiple ***/
97 -PPC_OP(glue(lmw, MEMSUFFIX)) 201 +void OPPROTO glue(op_lmw, MEMSUFFIX) (void)
98 { 202 {
99 glue(do_lmw, MEMSUFFIX)(PARAM1); 203 glue(do_lmw, MEMSUFFIX)(PARAM1);
100 RETURN(); 204 RETURN();
101 } 205 }
102 206
103 -PPC_OP(glue(lmw_le, MEMSUFFIX)) 207 +#if defined(TARGET_PPC64)
  208 +void OPPROTO glue(op_lmw_64, MEMSUFFIX) (void)
  209 +{
  210 + glue(do_lmw_64, MEMSUFFIX)(PARAM1);
  211 + RETURN();
  212 +}
  213 +#endif
  214 +
  215 +void OPPROTO glue(op_lmw_le, MEMSUFFIX) (void)
104 { 216 {
105 glue(do_lmw_le, MEMSUFFIX)(PARAM1); 217 glue(do_lmw_le, MEMSUFFIX)(PARAM1);
106 RETURN(); 218 RETURN();
107 } 219 }
108 220
109 -PPC_OP(glue(stmw, MEMSUFFIX)) 221 +#if defined(TARGET_PPC64)
  222 +void OPPROTO glue(op_lmw_le_64, MEMSUFFIX) (void)
  223 +{
  224 + glue(do_lmw_le_64, MEMSUFFIX)(PARAM1);
  225 + RETURN();
  226 +}
  227 +#endif
  228 +
  229 +void OPPROTO glue(op_stmw, MEMSUFFIX) (void)
110 { 230 {
111 glue(do_stmw, MEMSUFFIX)(PARAM1); 231 glue(do_stmw, MEMSUFFIX)(PARAM1);
112 RETURN(); 232 RETURN();
113 } 233 }
114 234
115 -PPC_OP(glue(stmw_le, MEMSUFFIX)) 235 +#if defined(TARGET_PPC64)
  236 +void OPPROTO glue(op_stmw_64, MEMSUFFIX) (void)
  237 +{
  238 + glue(do_stmw_64, MEMSUFFIX)(PARAM1);
  239 + RETURN();
  240 +}
  241 +#endif
  242 +
  243 +void OPPROTO glue(op_stmw_le, MEMSUFFIX) (void)
116 { 244 {
117 glue(do_stmw_le, MEMSUFFIX)(PARAM1); 245 glue(do_stmw_le, MEMSUFFIX)(PARAM1);
118 RETURN(); 246 RETURN();
119 } 247 }
120 248
  249 +#if defined(TARGET_PPC64)
  250 +void OPPROTO glue(op_stmw_le_64, MEMSUFFIX) (void)
  251 +{
  252 + glue(do_stmw_le_64, MEMSUFFIX)(PARAM1);
  253 + RETURN();
  254 +}
  255 +#endif
  256 +
121 /*** Integer load and store strings ***/ 257 /*** Integer load and store strings ***/
122 -PPC_OP(glue(lswi, MEMSUFFIX)) 258 +void OPPROTO glue(op_lswi, MEMSUFFIX) (void)
  259 +{
  260 + glue(do_lsw, MEMSUFFIX)(PARAM1);
  261 + RETURN();
  262 +}
  263 +
  264 +#if defined(TARGET_PPC64)
  265 +void OPPROTO glue(op_lswi_64, MEMSUFFIX) (void)
123 { 266 {
124 - glue(do_lsw, MEMSUFFIX)(PARAM(1)); 267 + glue(do_lsw_64, MEMSUFFIX)(PARAM1);
125 RETURN(); 268 RETURN();
126 } 269 }
  270 +#endif
127 271
128 -PPC_OP(glue(lswi_le, MEMSUFFIX)) 272 +void OPPROTO glue(op_lswi_le, MEMSUFFIX) (void)
129 { 273 {
130 - glue(do_lsw_le, MEMSUFFIX)(PARAM(1)); 274 + glue(do_lsw_le, MEMSUFFIX)(PARAM1);
131 RETURN(); 275 RETURN();
132 } 276 }
133 277
  278 +#if defined(TARGET_PPC64)
  279 +void OPPROTO glue(op_lswi_le_64, MEMSUFFIX) (void)
  280 +{
  281 + glue(do_lsw_le_64, MEMSUFFIX)(PARAM1);
  282 + RETURN();
  283 +}
  284 +#endif
  285 +
134 /* PPC32 specification says we must generate an exception if 286 /* PPC32 specification says we must generate an exception if
135 * rA is in the range of registers to be loaded. 287 * rA is in the range of registers to be loaded.
136 * In an other hand, IBM says this is valid, but rA won't be loaded. 288 * In an other hand, IBM says this is valid, but rA won't be loaded.
137 * For now, I'll follow the spec... 289 * For now, I'll follow the spec...
138 */ 290 */
139 -PPC_OP(glue(lswx, MEMSUFFIX)) 291 +void OPPROTO glue(op_lswx, MEMSUFFIX) (void)
  292 +{
  293 + /* Note: T1 comes from xer_bc then no cast is needed */
  294 + if (likely(T1 != 0)) {
  295 + if (unlikely((PARAM1 < PARAM2 && (PARAM1 + T1) > PARAM2) ||
  296 + (PARAM1 < PARAM3 && (PARAM1 + T1) > PARAM3))) {
  297 + do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_LSWX);
  298 + } else {
  299 + glue(do_lsw, MEMSUFFIX)(PARAM1);
  300 + }
  301 + }
  302 + RETURN();
  303 +}
  304 +
  305 +#if defined(TARGET_PPC64)
  306 +void OPPROTO glue(op_lswx_64, MEMSUFFIX) (void)
  307 +{
  308 + /* Note: T1 comes from xer_bc then no cast is needed */
  309 + if (likely(T1 != 0)) {
  310 + if (unlikely((PARAM1 < PARAM2 && (PARAM1 + T1) > PARAM2) ||
  311 + (PARAM1 < PARAM3 && (PARAM1 + T1) > PARAM3))) {
  312 + do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_LSWX);
  313 + } else {
  314 + glue(do_lsw_64, MEMSUFFIX)(PARAM1);
  315 + }
  316 + }
  317 + RETURN();
  318 +}
  319 +#endif
  320 +
  321 +void OPPROTO glue(op_lswx_le, MEMSUFFIX) (void)
140 { 322 {
141 - if (unlikely(T1 > 0)) { 323 + /* Note: T1 comes from xer_bc then no cast is needed */
  324 + if (likely(T1 != 0)) {
142 if (unlikely((PARAM1 < PARAM2 && (PARAM1 + T1) > PARAM2) || 325 if (unlikely((PARAM1 < PARAM2 && (PARAM1 + T1) > PARAM2) ||
143 (PARAM1 < PARAM3 && (PARAM1 + T1) > PARAM3))) { 326 (PARAM1 < PARAM3 && (PARAM1 + T1) > PARAM3))) {
144 do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_LSWX); 327 do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_LSWX);
145 } else { 328 } else {
146 - glue(do_lsw, MEMSUFFIX)(PARAM(1)); 329 + glue(do_lsw_le, MEMSUFFIX)(PARAM1);
147 } 330 }
148 } 331 }
149 RETURN(); 332 RETURN();
150 } 333 }
151 334
152 -PPC_OP(glue(lswx_le, MEMSUFFIX)) 335 +#if defined(TARGET_PPC64)
  336 +void OPPROTO glue(op_lswx_le_64, MEMSUFFIX) (void)
153 { 337 {
154 - if (unlikely(T1 > 0)) { 338 + /* Note: T1 comes from xer_bc then no cast is needed */
  339 + if (likely(T1 != 0)) {
155 if (unlikely((PARAM1 < PARAM2 && (PARAM1 + T1) > PARAM2) || 340 if (unlikely((PARAM1 < PARAM2 && (PARAM1 + T1) > PARAM2) ||
156 (PARAM1 < PARAM3 && (PARAM1 + T1) > PARAM3))) { 341 (PARAM1 < PARAM3 && (PARAM1 + T1) > PARAM3))) {
157 do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_LSWX); 342 do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_LSWX);
158 } else { 343 } else {
159 - glue(do_lsw_le, MEMSUFFIX)(PARAM(1)); 344 + glue(do_lsw_le_64, MEMSUFFIX)(PARAM1);
160 } 345 }
161 } 346 }
162 RETURN(); 347 RETURN();
163 } 348 }
  349 +#endif
  350 +
  351 +void OPPROTO glue(op_stsw, MEMSUFFIX) (void)
  352 +{
  353 + glue(do_stsw, MEMSUFFIX)(PARAM1);
  354 + RETURN();
  355 +}
  356 +
  357 +#if defined(TARGET_PPC64)
  358 +void OPPROTO glue(op_stsw_64, MEMSUFFIX) (void)
  359 +{
  360 + glue(do_stsw_64, MEMSUFFIX)(PARAM1);
  361 + RETURN();
  362 +}
  363 +#endif
164 364
165 -PPC_OP(glue(stsw, MEMSUFFIX)) 365 +void OPPROTO glue(op_stsw_le, MEMSUFFIX) (void)
166 { 366 {
167 - glue(do_stsw, MEMSUFFIX)(PARAM(1)); 367 + glue(do_stsw_le, MEMSUFFIX)(PARAM1);
168 RETURN(); 368 RETURN();
169 } 369 }
170 370
171 -PPC_OP(glue(stsw_le, MEMSUFFIX)) 371 +#if defined(TARGET_PPC64)
  372 +void OPPROTO glue(op_stsw_le_64, MEMSUFFIX) (void)
172 { 373 {
173 - glue(do_stsw_le, MEMSUFFIX)(PARAM(1)); 374 + glue(do_stsw_le_64, MEMSUFFIX)(PARAM1);
174 RETURN(); 375 RETURN();
175 } 376 }
  377 +#endif
176 378
177 /*** Floating-point store ***/ 379 /*** Floating-point store ***/
178 #define PPC_STF_OP(name, op) \ 380 #define PPC_STF_OP(name, op) \
179 -PPC_OP(glue(glue(st, name), MEMSUFFIX)) \ 381 +void OPPROTO glue(glue(op_st, name), MEMSUFFIX) (void) \
  382 +{ \
  383 + glue(op, MEMSUFFIX)((uint32_t)T0, FT0); \
  384 + RETURN(); \
  385 +}
  386 +
  387 +#if defined(TARGET_PPC64)
  388 +#define PPC_STF_OP_64(name, op) \
  389 +void OPPROTO glue(glue(glue(op_st, name), _64), MEMSUFFIX) (void) \
180 { \ 390 { \
181 - glue(op, MEMSUFFIX)(T0, FT0); \ 391 + glue(op, MEMSUFFIX)((uint64_t)T0, FT0); \
182 RETURN(); \ 392 RETURN(); \
183 } 393 }
  394 +#endif
184 395
185 PPC_STF_OP(fd, stfq); 396 PPC_STF_OP(fd, stfq);
186 PPC_STF_OP(fs, stfl); 397 PPC_STF_OP(fs, stfl);
  398 +#if defined(TARGET_PPC64)
  399 +PPC_STF_OP_64(fd, stfq);
  400 +PPC_STF_OP_64(fs, stfl);
  401 +#endif
187 402
188 static inline void glue(stfqr, MEMSUFFIX) (target_ulong EA, double d) 403 static inline void glue(stfqr, MEMSUFFIX) (target_ulong EA, double d)
189 { 404 {
@@ -221,17 +436,34 @@ static inline void glue(stflr, MEMSUFFIX) (target_ulong EA, float f) @@ -221,17 +436,34 @@ static inline void glue(stflr, MEMSUFFIX) (target_ulong EA, float f)
221 436
222 PPC_STF_OP(fd_le, stfqr); 437 PPC_STF_OP(fd_le, stfqr);
223 PPC_STF_OP(fs_le, stflr); 438 PPC_STF_OP(fs_le, stflr);
  439 +#if defined(TARGET_PPC64)
  440 +PPC_STF_OP_64(fd_le, stfqr);
  441 +PPC_STF_OP_64(fs_le, stflr);
  442 +#endif
224 443
225 /*** Floating-point load ***/ 444 /*** Floating-point load ***/
226 #define PPC_LDF_OP(name, op) \ 445 #define PPC_LDF_OP(name, op) \
227 -PPC_OP(glue(glue(l, name), MEMSUFFIX)) \ 446 +void OPPROTO glue(glue(op_l, name), MEMSUFFIX) (void) \
  447 +{ \
  448 + FT0 = glue(op, MEMSUFFIX)((uint32_t)T0); \
  449 + RETURN(); \
  450 +}
  451 +
  452 +#if defined(TARGET_PPC64)
  453 +#define PPC_LDF_OP_64(name, op) \
  454 +void OPPROTO glue(glue(glue(op_l, name), _64), MEMSUFFIX) (void) \
228 { \ 455 { \
229 - FT0 = glue(op, MEMSUFFIX)(T0); \ 456 + FT0 = glue(op, MEMSUFFIX)((uint64_t)T0); \
230 RETURN(); \ 457 RETURN(); \
231 } 458 }
  459 +#endif
232 460
233 PPC_LDF_OP(fd, ldfq); 461 PPC_LDF_OP(fd, ldfq);
234 PPC_LDF_OP(fs, ldfl); 462 PPC_LDF_OP(fs, ldfl);
  463 +#if defined(TARGET_PPC64)
  464 +PPC_LDF_OP_64(fd, ldfq);
  465 +PPC_LDF_OP_64(fs, ldfl);
  466 +#endif
235 467
236 static inline double glue(ldfqr, MEMSUFFIX) (target_ulong EA) 468 static inline double glue(ldfqr, MEMSUFFIX) (target_ulong EA)
237 { 469 {
@@ -271,40 +503,142 @@ static inline float glue(ldflr, MEMSUFFIX) (target_ulong EA) @@ -271,40 +503,142 @@ static inline float glue(ldflr, MEMSUFFIX) (target_ulong EA)
271 503
272 PPC_LDF_OP(fd_le, ldfqr); 504 PPC_LDF_OP(fd_le, ldfqr);
273 PPC_LDF_OP(fs_le, ldflr); 505 PPC_LDF_OP(fs_le, ldflr);
  506 +#if defined(TARGET_PPC64)
  507 +PPC_LDF_OP_64(fd_le, ldfqr);
  508 +PPC_LDF_OP_64(fs_le, ldflr);
  509 +#endif
274 510
275 /* Load and set reservation */ 511 /* Load and set reservation */
276 -PPC_OP(glue(lwarx, MEMSUFFIX)) 512 +void OPPROTO glue(op_lwarx, MEMSUFFIX) (void)
  513 +{
  514 + if (unlikely(T0 & 0x03)) {
  515 + do_raise_exception(EXCP_ALIGN);
  516 + } else {
  517 + T1 = glue(ldl, MEMSUFFIX)((uint32_t)T0);
  518 + regs->reserve = (uint32_t)T0;
  519 + }
  520 + RETURN();
  521 +}
  522 +
  523 +#if defined(TARGET_PPC64)
  524 +void OPPROTO glue(op_lwarx_64, MEMSUFFIX) (void)
  525 +{
  526 + if (unlikely(T0 & 0x03)) {
  527 + do_raise_exception(EXCP_ALIGN);
  528 + } else {
  529 + T1 = glue(ldl, MEMSUFFIX)((uint64_t)T0);
  530 + regs->reserve = (uint64_t)T0;
  531 + }
  532 + RETURN();
  533 +}
  534 +
  535 +void OPPROTO glue(op_ldarx_64, MEMSUFFIX) (void)
  536 +{
  537 + if (unlikely(T0 & 0x03)) {
  538 + do_raise_exception(EXCP_ALIGN);
  539 + } else {
  540 + T1 = glue(ldq, MEMSUFFIX)((uint64_t)T0);
  541 + regs->reserve = (uint64_t)T0;
  542 + }
  543 + RETURN();
  544 +}
  545 +#endif
  546 +
  547 +void OPPROTO glue(op_lwarx_le, MEMSUFFIX) (void)
  548 +{
  549 + if (unlikely(T0 & 0x03)) {
  550 + do_raise_exception(EXCP_ALIGN);
  551 + } else {
  552 + T1 = glue(ld32r, MEMSUFFIX)((uint32_t)T0);
  553 + regs->reserve = (uint32_t)T0;
  554 + }
  555 + RETURN();
  556 +}
  557 +
  558 +#if defined(TARGET_PPC64)
  559 +void OPPROTO glue(op_lwarx_le_64, MEMSUFFIX) (void)
277 { 560 {
278 if (unlikely(T0 & 0x03)) { 561 if (unlikely(T0 & 0x03)) {
279 do_raise_exception(EXCP_ALIGN); 562 do_raise_exception(EXCP_ALIGN);
280 } else { 563 } else {
281 - T1 = glue(ldl, MEMSUFFIX)(T0);  
282 - regs->reserve = T0; 564 + T1 = glue(ld32r, MEMSUFFIX)((uint64_t)T0);
  565 + regs->reserve = (uint64_t)T0;
283 } 566 }
284 RETURN(); 567 RETURN();
285 } 568 }
286 569
287 -PPC_OP(glue(lwarx_le, MEMSUFFIX)) 570 +void OPPROTO glue(op_ldarx_le_64, MEMSUFFIX) (void)
288 { 571 {
289 if (unlikely(T0 & 0x03)) { 572 if (unlikely(T0 & 0x03)) {
290 do_raise_exception(EXCP_ALIGN); 573 do_raise_exception(EXCP_ALIGN);
291 } else { 574 } else {
292 - T1 = glue(ld32r, MEMSUFFIX)(T0);  
293 - regs->reserve = T0; 575 + T1 = glue(ld64r, MEMSUFFIX)((uint64_t)T0);
  576 + regs->reserve = (uint64_t)T0;
294 } 577 }
295 RETURN(); 578 RETURN();
296 } 579 }
  580 +#endif
297 581
298 /* Store with reservation */ 582 /* Store with reservation */
299 -PPC_OP(glue(stwcx, MEMSUFFIX)) 583 +void OPPROTO glue(op_stwcx, MEMSUFFIX) (void)
  584 +{
  585 + if (unlikely(T0 & 0x03)) {
  586 + do_raise_exception(EXCP_ALIGN);
  587 + } else {
  588 + if (unlikely(regs->reserve != (uint32_t)T0)) {
  589 + env->crf[0] = xer_ov;
  590 + } else {
  591 + glue(stl, MEMSUFFIX)((uint32_t)T0, T1);
  592 + env->crf[0] = xer_ov | 0x02;
  593 + }
  594 + }
  595 + regs->reserve = -1;
  596 + RETURN();
  597 +}
  598 +
  599 +#if defined(TARGET_PPC64)
  600 +void OPPROTO glue(op_stwcx_64, MEMSUFFIX) (void)
  601 +{
  602 + if (unlikely(T0 & 0x03)) {
  603 + do_raise_exception(EXCP_ALIGN);
  604 + } else {
  605 + if (unlikely(regs->reserve != (uint64_t)T0)) {
  606 + env->crf[0] = xer_ov;
  607 + } else {
  608 + glue(stl, MEMSUFFIX)((uint64_t)T0, T1);
  609 + env->crf[0] = xer_ov | 0x02;
  610 + }
  611 + }
  612 + regs->reserve = -1;
  613 + RETURN();
  614 +}
  615 +
  616 +void OPPROTO glue(op_stdcx_64, MEMSUFFIX) (void)
300 { 617 {
301 if (unlikely(T0 & 0x03)) { 618 if (unlikely(T0 & 0x03)) {
302 do_raise_exception(EXCP_ALIGN); 619 do_raise_exception(EXCP_ALIGN);
303 } else { 620 } else {
304 - if (unlikely(regs->reserve != T0)) { 621 + if (unlikely(regs->reserve != (uint64_t)T0)) {
305 env->crf[0] = xer_ov; 622 env->crf[0] = xer_ov;
306 } else { 623 } else {
307 - glue(stl, MEMSUFFIX)(T0, T1); 624 + glue(stq, MEMSUFFIX)((uint64_t)T0, T1);
  625 + env->crf[0] = xer_ov | 0x02;
  626 + }
  627 + }
  628 + regs->reserve = -1;
  629 + RETURN();
  630 +}
  631 +#endif
  632 +
  633 +void OPPROTO glue(op_stwcx_le, MEMSUFFIX) (void)
  634 +{
  635 + if (unlikely(T0 & 0x03)) {
  636 + do_raise_exception(EXCP_ALIGN);
  637 + } else {
  638 + if (unlikely(regs->reserve != (uint32_t)T0)) {
  639 + env->crf[0] = xer_ov;
  640 + } else {
  641 + glue(st32r, MEMSUFFIX)((uint32_t)T0, T1);
308 env->crf[0] = xer_ov | 0x02; 642 env->crf[0] = xer_ov | 0x02;
309 } 643 }
310 } 644 }
@@ -312,15 +646,16 @@ PPC_OP(glue(stwcx, MEMSUFFIX)) @@ -312,15 +646,16 @@ PPC_OP(glue(stwcx, MEMSUFFIX))
312 RETURN(); 646 RETURN();
313 } 647 }
314 648
315 -PPC_OP(glue(stwcx_le, MEMSUFFIX)) 649 +#if defined(TARGET_PPC64)
  650 +void OPPROTO glue(op_stwcx_le_64, MEMSUFFIX) (void)
316 { 651 {
317 if (unlikely(T0 & 0x03)) { 652 if (unlikely(T0 & 0x03)) {
318 do_raise_exception(EXCP_ALIGN); 653 do_raise_exception(EXCP_ALIGN);
319 } else { 654 } else {
320 - if (unlikely(regs->reserve != T0)) { 655 + if (unlikely(regs->reserve != (uint64_t)T0)) {
321 env->crf[0] = xer_ov; 656 env->crf[0] = xer_ov;
322 } else { 657 } else {
323 - glue(st32r, MEMSUFFIX)(T0, T1); 658 + glue(st32r, MEMSUFFIX)((uint64_t)T0, T1);
324 env->crf[0] = xer_ov | 0x02; 659 env->crf[0] = xer_ov | 0x02;
325 } 660 }
326 } 661 }
@@ -328,61 +663,136 @@ PPC_OP(glue(stwcx_le, MEMSUFFIX)) @@ -328,61 +663,136 @@ PPC_OP(glue(stwcx_le, MEMSUFFIX))
328 RETURN(); 663 RETURN();
329 } 664 }
330 665
331 -PPC_OP(glue(dcbz, MEMSUFFIX)) 666 +void OPPROTO glue(op_stdcx_le_64, MEMSUFFIX) (void)
  667 +{
  668 + if (unlikely(T0 & 0x03)) {
  669 + do_raise_exception(EXCP_ALIGN);
  670 + } else {
  671 + if (unlikely(regs->reserve != (uint64_t)T0)) {
  672 + env->crf[0] = xer_ov;
  673 + } else {
  674 + glue(st64r, MEMSUFFIX)((uint64_t)T0, T1);
  675 + env->crf[0] = xer_ov | 0x02;
  676 + }
  677 + }
  678 + regs->reserve = -1;
  679 + RETURN();
  680 +}
  681 +#endif
  682 +
  683 +void OPPROTO glue(op_dcbz, MEMSUFFIX) (void)
  684 +{
  685 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x00), 0);
  686 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x04), 0);
  687 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x08), 0);
  688 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x0C), 0);
  689 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x10), 0);
  690 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x14), 0);
  691 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x18), 0);
  692 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x1C), 0);
  693 +#if DCACHE_LINE_SIZE == 64
  694 + /* XXX: cache line size should be 64 for POWER & PowerPC 601 */
  695 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x20UL), 0);
  696 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x24UL), 0);
  697 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x28UL), 0);
  698 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x2CUL), 0);
  699 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x30UL), 0);
  700 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x34UL), 0);
  701 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x38UL), 0);
  702 + glue(stl, MEMSUFFIX)((uint32_t)(T0 + 0x3CUL), 0);
  703 +#endif
  704 + RETURN();
  705 +}
  706 +
  707 +#if defined(TARGET_PPC64)
  708 +void OPPROTO glue(op_dcbz_64, MEMSUFFIX) (void)
332 { 709 {
333 - glue(stl, MEMSUFFIX)(T0 + 0x00, 0);  
334 - glue(stl, MEMSUFFIX)(T0 + 0x04, 0);  
335 - glue(stl, MEMSUFFIX)(T0 + 0x08, 0);  
336 - glue(stl, MEMSUFFIX)(T0 + 0x0C, 0);  
337 - glue(stl, MEMSUFFIX)(T0 + 0x10, 0);  
338 - glue(stl, MEMSUFFIX)(T0 + 0x14, 0);  
339 - glue(stl, MEMSUFFIX)(T0 + 0x18, 0);  
340 - glue(stl, MEMSUFFIX)(T0 + 0x1C, 0); 710 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x00), 0);
  711 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x04), 0);
  712 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x08), 0);
  713 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x0C), 0);
  714 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x10), 0);
  715 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x14), 0);
  716 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x18), 0);
  717 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x1C), 0);
341 #if DCACHE_LINE_SIZE == 64 718 #if DCACHE_LINE_SIZE == 64
342 /* XXX: cache line size should be 64 for POWER & PowerPC 601 */ 719 /* XXX: cache line size should be 64 for POWER & PowerPC 601 */
343 - glue(stl, MEMSUFFIX)(T0 + 0x20UL, 0);  
344 - glue(stl, MEMSUFFIX)(T0 + 0x24UL, 0);  
345 - glue(stl, MEMSUFFIX)(T0 + 0x28UL, 0);  
346 - glue(stl, MEMSUFFIX)(T0 + 0x2CUL, 0);  
347 - glue(stl, MEMSUFFIX)(T0 + 0x30UL, 0);  
348 - glue(stl, MEMSUFFIX)(T0 + 0x34UL, 0);  
349 - glue(stl, MEMSUFFIX)(T0 + 0x38UL, 0);  
350 - glue(stl, MEMSUFFIX)(T0 + 0x3CUL, 0); 720 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x20UL), 0);
  721 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x24UL), 0);
  722 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x28UL), 0);
  723 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x2CUL), 0);
  724 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x30UL), 0);
  725 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x34UL), 0);
  726 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x38UL), 0);
  727 + glue(stl, MEMSUFFIX)((uint64_t)(T0 + 0x3CUL), 0);
351 #endif 728 #endif
352 RETURN(); 729 RETURN();
353 } 730 }
  731 +#endif
354 732
355 /* External access */ 733 /* External access */
356 -PPC_OP(glue(eciwx, MEMSUFFIX)) 734 +void OPPROTO glue(op_eciwx, MEMSUFFIX) (void)
  735 +{
  736 + T1 = glue(ldl, MEMSUFFIX)((uint32_t)T0);
  737 + RETURN();
  738 +}
  739 +
  740 +#if defined(TARGET_PPC64)
  741 +void OPPROTO glue(op_eciwx_64, MEMSUFFIX) (void)
  742 +{
  743 + T1 = glue(ldl, MEMSUFFIX)((uint64_t)T0);
  744 + RETURN();
  745 +}
  746 +#endif
  747 +
  748 +void OPPROTO glue(op_ecowx, MEMSUFFIX) (void)
  749 +{
  750 + glue(stl, MEMSUFFIX)((uint32_t)T0, T1);
  751 + RETURN();
  752 +}
  753 +
  754 +#if defined(TARGET_PPC64)
  755 +void OPPROTO glue(op_ecowx_64, MEMSUFFIX) (void)
357 { 756 {
358 - T1 = glue(ldl, MEMSUFFIX)(T0); 757 + glue(stl, MEMSUFFIX)((uint64_t)T0, T1);
359 RETURN(); 758 RETURN();
360 } 759 }
  760 +#endif
361 761
362 -PPC_OP(glue(ecowx, MEMSUFFIX)) 762 +void OPPROTO glue(op_eciwx_le, MEMSUFFIX) (void)
363 { 763 {
364 - glue(stl, MEMSUFFIX)(T0, T1); 764 + T1 = glue(ld32r, MEMSUFFIX)((uint32_t)T0);
365 RETURN(); 765 RETURN();
366 } 766 }
367 767
368 -PPC_OP(glue(eciwx_le, MEMSUFFIX)) 768 +#if defined(TARGET_PPC64)
  769 +void OPPROTO glue(op_eciwx_le_64, MEMSUFFIX) (void)
369 { 770 {
370 - T1 = glue(ld32r, MEMSUFFIX)(T0); 771 + T1 = glue(ld32r, MEMSUFFIX)((uint64_t)T0);
371 RETURN(); 772 RETURN();
372 } 773 }
  774 +#endif
373 775
374 -PPC_OP(glue(ecowx_le, MEMSUFFIX)) 776 +void OPPROTO glue(op_ecowx_le, MEMSUFFIX) (void)
375 { 777 {
376 - glue(st32r, MEMSUFFIX)(T0, T1); 778 + glue(st32r, MEMSUFFIX)((uint32_t)T0, T1);
377 RETURN(); 779 RETURN();
378 } 780 }
379 781
  782 +#if defined(TARGET_PPC64)
  783 +void OPPROTO glue(op_ecowx_le_64, MEMSUFFIX) (void)
  784 +{
  785 + glue(st32r, MEMSUFFIX)((uint64_t)T0, T1);
  786 + RETURN();
  787 +}
  788 +#endif
  789 +
380 /* XXX: those micro-ops need tests ! */ 790 /* XXX: those micro-ops need tests ! */
381 /* PowerPC 601 specific instructions (POWER bridge) */ 791 /* PowerPC 601 specific instructions (POWER bridge) */
382 void OPPROTO glue(op_POWER_lscbx, MEMSUFFIX) (void) 792 void OPPROTO glue(op_POWER_lscbx, MEMSUFFIX) (void)
383 { 793 {
384 /* When byte count is 0, do nothing */ 794 /* When byte count is 0, do nothing */
385 - if (likely(T1 > 0)) { 795 + if (likely(T1 != 0)) {
386 glue(do_POWER_lscbx, MEMSUFFIX)(PARAM1, PARAM2, PARAM3); 796 glue(do_POWER_lscbx, MEMSUFFIX)(PARAM1, PARAM2, PARAM3);
387 } 797 }
388 RETURN(); 798 RETURN();
target-ppc/translate.c
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 //#define PPC_DEBUG_DISAS 31 //#define PPC_DEBUG_DISAS
32 //#define DO_PPC_STATISTICS 32 //#define DO_PPC_STATISTICS
33 33
34 -#ifdef USE_DIRECT_JUMP 34 +#if defined(USE_DIRECT_JUMP)
35 #define TBPARAM(x) 35 #define TBPARAM(x)
36 #else 36 #else
37 #define TBPARAM(x) (long)(x) 37 #define TBPARAM(x) (long)(x)
@@ -49,7 +49,27 @@ static uint32_t *gen_opparam_ptr; @@ -49,7 +49,27 @@ static uint32_t *gen_opparam_ptr;
49 49
50 #include "gen-op.h" 50 #include "gen-op.h"
51 51
52 -#define GEN8(func, NAME) \ 52 +static inline void gen_set_T0 (target_ulong val)
  53 +{
  54 +#if defined(TARGET_PPC64)
  55 + if (val >> 32)
  56 + gen_op_set_T0_64(val >> 32, val);
  57 + else
  58 +#endif
  59 + gen_op_set_T0(val);
  60 +}
  61 +
  62 +static inline void gen_set_T1 (target_ulong val)
  63 +{
  64 +#if defined(TARGET_PPC64)
  65 + if (val >> 32)
  66 + gen_op_set_T1_64(val >> 32, val);
  67 + else
  68 +#endif
  69 + gen_op_set_T1(val);
  70 +}
  71 +
  72 +#define GEN8(func, NAME) \
53 static GenOpFunc *NAME ## _table [8] = { \ 73 static GenOpFunc *NAME ## _table [8] = { \
54 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \ 74 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
55 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \ 75 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
@@ -71,7 +91,7 @@ static inline void func(int n) \ @@ -71,7 +91,7 @@ static inline void func(int n) \
71 NAME ## _table[n](); \ 91 NAME ## _table[n](); \
72 } 92 }
73 93
74 -#define GEN32(func, NAME) \ 94 +#define GEN32(func, NAME) \
75 static GenOpFunc *NAME ## _table [32] = { \ 95 static GenOpFunc *NAME ## _table [32] = { \
76 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \ 96 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
77 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \ 97 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
@@ -136,6 +156,9 @@ typedef struct DisasContext { @@ -136,6 +156,9 @@ typedef struct DisasContext {
136 #if !defined(CONFIG_USER_ONLY) 156 #if !defined(CONFIG_USER_ONLY)
137 int supervisor; 157 int supervisor;
138 #endif 158 #endif
  159 +#if defined(TARGET_PPC64)
  160 + int sf_mode;
  161 +#endif
139 int fpu_enabled; 162 int fpu_enabled;
140 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */ 163 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
141 int singlestep_enabled; 164 int singlestep_enabled;
@@ -156,14 +179,29 @@ struct opc_handler_t { @@ -156,14 +179,29 @@ struct opc_handler_t {
156 179
157 static inline void gen_set_Rc0 (DisasContext *ctx) 180 static inline void gen_set_Rc0 (DisasContext *ctx)
158 { 181 {
159 - gen_op_cmpi(0); 182 +#if defined(TARGET_PPC64)
  183 + if (ctx->sf_mode)
  184 + gen_op_cmpi_64(0);
  185 + else
  186 +#endif
  187 + gen_op_cmpi(0);
160 gen_op_set_Rc0(); 188 gen_op_set_Rc0();
161 } 189 }
162 190
  191 +static inline void gen_update_nip (DisasContext *ctx, target_ulong nip)
  192 +{
  193 +#if defined(TARGET_PPC64)
  194 + if (ctx->sf_mode)
  195 + gen_op_update_nip_64(nip >> 32, nip);
  196 + else
  197 +#endif
  198 + gen_op_update_nip(nip);
  199 +}
  200 +
163 #define RET_EXCP(ctx, excp, error) \ 201 #define RET_EXCP(ctx, excp, error) \
164 do { \ 202 do { \
165 if ((ctx)->exception == EXCP_NONE) { \ 203 if ((ctx)->exception == EXCP_NONE) { \
166 - gen_op_update_nip((ctx)->nip); \ 204 + gen_update_nip(ctx, (ctx)->nip); \
167 } \ 205 } \
168 gen_op_raise_exception_err((excp), (error)); \ 206 gen_op_raise_exception_err((excp), (error)); \
169 ctx->exception = (excp); \ 207 ctx->exception = (excp); \
@@ -181,7 +219,7 @@ RET_EXCP((ctx), EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_REG) @@ -181,7 +219,7 @@ RET_EXCP((ctx), EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_REG)
181 /* Stop translation */ 219 /* Stop translation */
182 static inline void RET_STOP (DisasContext *ctx) 220 static inline void RET_STOP (DisasContext *ctx)
183 { 221 {
184 - gen_op_update_nip((ctx)->nip); 222 + gen_update_nip(ctx, ctx->nip);
185 ctx->exception = EXCP_MTMSR; 223 ctx->exception = EXCP_MTMSR;
186 } 224 }
187 225
@@ -209,13 +247,13 @@ typedef struct opcode_t { @@ -209,13 +247,13 @@ typedef struct opcode_t {
209 247
210 /*** Instruction decoding ***/ 248 /*** Instruction decoding ***/
211 #define EXTRACT_HELPER(name, shift, nb) \ 249 #define EXTRACT_HELPER(name, shift, nb) \
212 -static inline target_ulong name (uint32_t opcode) \ 250 +static inline uint32_t name (uint32_t opcode) \
213 { \ 251 { \
214 return (opcode >> (shift)) & ((1 << (nb)) - 1); \ 252 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
215 } 253 }
216 254
217 #define EXTRACT_SHELPER(name, shift, nb) \ 255 #define EXTRACT_SHELPER(name, shift, nb) \
218 -static inline target_long name (uint32_t opcode) \ 256 +static inline int32_t name (uint32_t opcode) \
219 { \ 257 { \
220 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \ 258 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
221 } 259 }
@@ -329,10 +367,10 @@ static inline target_ulong MASK (uint32_t start, uint32_t end) @@ -329,10 +367,10 @@ static inline target_ulong MASK (uint32_t start, uint32_t end)
329 #define OPC_ALIGN 4 367 #define OPC_ALIGN 4
330 #endif 368 #endif
331 #if defined(__APPLE__) 369 #if defined(__APPLE__)
332 -#define OPCODES_SECTION \ 370 +#define OPCODES_SECTION \
333 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) )) 371 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
334 #else 372 #else
335 -#define OPCODES_SECTION \ 373 +#define OPCODES_SECTION \
336 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) )) 374 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
337 #endif 375 #endif
338 376
@@ -397,8 +435,8 @@ static opc_handler_t invalid_handler = { @@ -397,8 +435,8 @@ static opc_handler_t invalid_handler = {
397 }; 435 };
398 436
399 /*** Integer arithmetic ***/ 437 /*** Integer arithmetic ***/
400 -#define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval) \  
401 -GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \ 438 +#define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
  439 +GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
402 { \ 440 { \
403 gen_op_load_gpr_T0(rA(ctx->opcode)); \ 441 gen_op_load_gpr_T0(rA(ctx->opcode)); \
404 gen_op_load_gpr_T1(rB(ctx->opcode)); \ 442 gen_op_load_gpr_T1(rB(ctx->opcode)); \
@@ -408,8 +446,8 @@ GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \ @@ -408,8 +446,8 @@ GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \
408 gen_set_Rc0(ctx); \ 446 gen_set_Rc0(ctx); \
409 } 447 }
410 448
411 -#define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval) \  
412 -GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \ 449 +#define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
  450 +GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
413 { \ 451 { \
414 gen_op_load_gpr_T0(rA(ctx->opcode)); \ 452 gen_op_load_gpr_T0(rA(ctx->opcode)); \
415 gen_op_load_gpr_T1(rB(ctx->opcode)); \ 453 gen_op_load_gpr_T1(rB(ctx->opcode)); \
@@ -419,8 +457,8 @@ GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \ @@ -419,8 +457,8 @@ GEN_HANDLER(name, opc1, opc2, opc3, inval, PPC_INTEGER) \
419 gen_set_Rc0(ctx); \ 457 gen_set_Rc0(ctx); \
420 } 458 }
421 459
422 -#define __GEN_INT_ARITH1(name, opc1, opc2, opc3) \  
423 -GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \ 460 +#define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
  461 +GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
424 { \ 462 { \
425 gen_op_load_gpr_T0(rA(ctx->opcode)); \ 463 gen_op_load_gpr_T0(rA(ctx->opcode)); \
426 gen_op_##name(); \ 464 gen_op_##name(); \
@@ -428,8 +466,8 @@ GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \ @@ -428,8 +466,8 @@ GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \
428 if (unlikely(Rc(ctx->opcode) != 0)) \ 466 if (unlikely(Rc(ctx->opcode) != 0)) \
429 gen_set_Rc0(ctx); \ 467 gen_set_Rc0(ctx); \
430 } 468 }
431 -#define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3) \  
432 -GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \ 469 +#define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
  470 +GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
433 { \ 471 { \
434 gen_op_load_gpr_T0(rA(ctx->opcode)); \ 472 gen_op_load_gpr_T0(rA(ctx->opcode)); \
435 gen_op_##name(); \ 473 gen_op_##name(); \
@@ -439,51 +477,277 @@ GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \ @@ -439,51 +477,277 @@ GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, PPC_INTEGER) \
439 } 477 }
440 478
441 /* Two operands arithmetic functions */ 479 /* Two operands arithmetic functions */
442 -#define GEN_INT_ARITH2(name, opc1, opc2, opc3) \  
443 -__GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000) \  
444 -__GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000) 480 +#define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
  481 +__GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
  482 +__GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
  483 +
  484 +/* Two operands arithmetic functions with no overflow allowed */
  485 +#define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
  486 +__GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
  487 +
  488 +/* One operand arithmetic functions */
  489 +#define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
  490 +__GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
  491 +__GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type)
  492 +
  493 +#if defined(TARGET_PPC64)
  494 +#define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
  495 +GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
  496 +{ \
  497 + gen_op_load_gpr_T0(rA(ctx->opcode)); \
  498 + gen_op_load_gpr_T1(rB(ctx->opcode)); \
  499 + if (ctx->sf_mode) \
  500 + gen_op_##name##_64(); \
  501 + else \
  502 + gen_op_##name(); \
  503 + gen_op_store_T0_gpr(rD(ctx->opcode)); \
  504 + if (unlikely(Rc(ctx->opcode) != 0)) \
  505 + gen_set_Rc0(ctx); \
  506 +}
  507 +
  508 +#define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
  509 +GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
  510 +{ \
  511 + gen_op_load_gpr_T0(rA(ctx->opcode)); \
  512 + gen_op_load_gpr_T1(rB(ctx->opcode)); \
  513 + if (ctx->sf_mode) \
  514 + gen_op_##name##_64(); \
  515 + else \
  516 + gen_op_##name(); \
  517 + gen_op_store_T0_gpr(rD(ctx->opcode)); \
  518 + if (unlikely(Rc(ctx->opcode) != 0)) \
  519 + gen_set_Rc0(ctx); \
  520 +}
  521 +
  522 +#define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
  523 +GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
  524 +{ \
  525 + gen_op_load_gpr_T0(rA(ctx->opcode)); \
  526 + if (ctx->sf_mode) \
  527 + gen_op_##name##_64(); \
  528 + else \
  529 + gen_op_##name(); \
  530 + gen_op_store_T0_gpr(rD(ctx->opcode)); \
  531 + if (unlikely(Rc(ctx->opcode) != 0)) \
  532 + gen_set_Rc0(ctx); \
  533 +}
  534 +#define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
  535 +GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
  536 +{ \
  537 + gen_op_load_gpr_T0(rA(ctx->opcode)); \
  538 + if (ctx->sf_mode) \
  539 + gen_op_##name##_64(); \
  540 + else \
  541 + gen_op_##name(); \
  542 + gen_op_store_T0_gpr(rD(ctx->opcode)); \
  543 + if (unlikely(Rc(ctx->opcode) != 0)) \
  544 + gen_set_Rc0(ctx); \
  545 +}
  546 +
  547 +/* Two operands arithmetic functions */
  548 +#define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
  549 +__GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
  550 +__GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
445 551
446 /* Two operands arithmetic functions with no overflow allowed */ 552 /* Two operands arithmetic functions with no overflow allowed */
447 -#define GEN_INT_ARITHN(name, opc1, opc2, opc3) \  
448 -__GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400) 553 +#define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
  554 +__GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
449 555
450 /* One operand arithmetic functions */ 556 /* One operand arithmetic functions */
451 -#define GEN_INT_ARITH1(name, opc1, opc2, opc3) \  
452 -__GEN_INT_ARITH1(name, opc1, opc2, opc3) \  
453 -__GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10) 557 +#define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
  558 +__GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
  559 +__GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type)
  560 +#else
  561 +#define GEN_INT_ARITH2_64 GEN_INT_ARITH2
  562 +#define GEN_INT_ARITHN_64 GEN_INT_ARITHN
  563 +#define GEN_INT_ARITH1_64 GEN_INT_ARITH1
  564 +#endif
454 565
455 /* add add. addo addo. */ 566 /* add add. addo addo. */
456 -GEN_INT_ARITH2 (add, 0x1F, 0x0A, 0x08); 567 +static inline void gen_op_addo (void)
  568 +{
  569 + gen_op_move_T2_T0();
  570 + gen_op_add();
  571 + gen_op_check_addo();
  572 +}
  573 +#if defined(TARGET_PPC64)
  574 +#define gen_op_add_64 gen_op_add
  575 +static inline void gen_op_addo_64 (void)
  576 +{
  577 + gen_op_move_T2_T0();
  578 + gen_op_add();
  579 + gen_op_check_addo_64();
  580 +}
  581 +#endif
  582 +GEN_INT_ARITH2_64 (add, 0x1F, 0x0A, 0x08, PPC_INTEGER);
457 /* addc addc. addco addco. */ 583 /* addc addc. addco addco. */
458 -GEN_INT_ARITH2 (addc, 0x1F, 0x0A, 0x00); 584 +static inline void gen_op_addc (void)
  585 +{
  586 + gen_op_move_T2_T0();
  587 + gen_op_add();
  588 + gen_op_check_addc();
  589 +}
  590 +static inline void gen_op_addco (void)
  591 +{
  592 + gen_op_move_T2_T0();
  593 + gen_op_add();
  594 + gen_op_check_addc();
  595 + gen_op_check_addo();
  596 +}
  597 +#if defined(TARGET_PPC64)
  598 +static inline void gen_op_addc_64 (void)
  599 +{
  600 + gen_op_move_T2_T0();
  601 + gen_op_add();
  602 + gen_op_check_addc_64();
  603 +}
  604 +static inline void gen_op_addco_64 (void)
  605 +{
  606 + gen_op_move_T2_T0();
  607 + gen_op_add();
  608 + gen_op_check_addc_64();
  609 + gen_op_check_addo_64();
  610 +}
  611 +#endif
  612 +GEN_INT_ARITH2_64 (addc, 0x1F, 0x0A, 0x00, PPC_INTEGER);
459 /* adde adde. addeo addeo. */ 613 /* adde adde. addeo addeo. */
460 -GEN_INT_ARITH2 (adde, 0x1F, 0x0A, 0x04); 614 +static inline void gen_op_addeo (void)
  615 +{
  616 + gen_op_move_T2_T0();
  617 + gen_op_adde();
  618 + gen_op_check_addo();
  619 +}
  620 +#if defined(TARGET_PPC64)
  621 +static inline void gen_op_addeo_64 (void)
  622 +{
  623 + gen_op_move_T2_T0();
  624 + gen_op_adde_64();
  625 + gen_op_check_addo_64();
  626 +}
  627 +#endif
  628 +GEN_INT_ARITH2_64 (adde, 0x1F, 0x0A, 0x04, PPC_INTEGER);
461 /* addme addme. addmeo addmeo. */ 629 /* addme addme. addmeo addmeo. */
462 -GEN_INT_ARITH1 (addme, 0x1F, 0x0A, 0x07); 630 +static inline void gen_op_addme (void)
  631 +{
  632 + gen_op_move_T1_T0();
  633 + gen_op_add_me();
  634 +}
  635 +#if defined(TARGET_PPC64)
  636 +static inline void gen_op_addme_64 (void)
  637 +{
  638 + gen_op_move_T1_T0();
  639 + gen_op_add_me_64();
  640 +}
  641 +#endif
  642 +GEN_INT_ARITH1_64 (addme, 0x1F, 0x0A, 0x07, PPC_INTEGER);
463 /* addze addze. addzeo addzeo. */ 643 /* addze addze. addzeo addzeo. */
464 -GEN_INT_ARITH1 (addze, 0x1F, 0x0A, 0x06); 644 +static inline void gen_op_addze (void)
  645 +{
  646 + gen_op_move_T2_T0();
  647 + gen_op_add_ze();
  648 + gen_op_check_addc();
  649 +}
  650 +static inline void gen_op_addzeo (void)
  651 +{
  652 + gen_op_move_T2_T0();
  653 + gen_op_add_ze();
  654 + gen_op_check_addc();
  655 + gen_op_check_addo();
  656 +}
  657 +#if defined(TARGET_PPC64)
  658 +static inline void gen_op_addze_64 (void)
  659 +{
  660 + gen_op_move_T2_T0();
  661 + gen_op_add_ze();
  662 + gen_op_check_addc_64();
  663 +}
  664 +static inline void gen_op_addzeo_64 (void)
  665 +{
  666 + gen_op_move_T2_T0();
  667 + gen_op_add_ze();
  668 + gen_op_check_addc_64();
  669 + gen_op_check_addo_64();
  670 +}
  671 +#endif
  672 +GEN_INT_ARITH1_64 (addze, 0x1F, 0x0A, 0x06, PPC_INTEGER);
465 /* divw divw. divwo divwo. */ 673 /* divw divw. divwo divwo. */
466 -GEN_INT_ARITH2 (divw, 0x1F, 0x0B, 0x0F); 674 +GEN_INT_ARITH2 (divw, 0x1F, 0x0B, 0x0F, PPC_INTEGER);
467 /* divwu divwu. divwuo divwuo. */ 675 /* divwu divwu. divwuo divwuo. */
468 -GEN_INT_ARITH2 (divwu, 0x1F, 0x0B, 0x0E); 676 +GEN_INT_ARITH2 (divwu, 0x1F, 0x0B, 0x0E, PPC_INTEGER);
469 /* mulhw mulhw. */ 677 /* mulhw mulhw. */
470 -GEN_INT_ARITHN (mulhw, 0x1F, 0x0B, 0x02); 678 +GEN_INT_ARITHN (mulhw, 0x1F, 0x0B, 0x02, PPC_INTEGER);
471 /* mulhwu mulhwu. */ 679 /* mulhwu mulhwu. */
472 -GEN_INT_ARITHN (mulhwu, 0x1F, 0x0B, 0x00); 680 +GEN_INT_ARITHN (mulhwu, 0x1F, 0x0B, 0x00, PPC_INTEGER);
473 /* mullw mullw. mullwo mullwo. */ 681 /* mullw mullw. mullwo mullwo. */
474 -GEN_INT_ARITH2 (mullw, 0x1F, 0x0B, 0x07); 682 +GEN_INT_ARITH2 (mullw, 0x1F, 0x0B, 0x07, PPC_INTEGER);
475 /* neg neg. nego nego. */ 683 /* neg neg. nego nego. */
476 -GEN_INT_ARITH1 (neg, 0x1F, 0x08, 0x03); 684 +GEN_INT_ARITH1_64 (neg, 0x1F, 0x08, 0x03, PPC_INTEGER);
477 /* subf subf. subfo subfo. */ 685 /* subf subf. subfo subfo. */
478 -GEN_INT_ARITH2 (subf, 0x1F, 0x08, 0x01); 686 +static inline void gen_op_subfo (void)
  687 +{
  688 + gen_op_move_T2_T0();
  689 + gen_op_subf();
  690 + gen_op_check_subfo();
  691 +}
  692 +#if defined(TARGET_PPC64)
  693 +#define gen_op_subf_64 gen_op_subf
  694 +static inline void gen_op_subfo_64 (void)
  695 +{
  696 + gen_op_move_T2_T0();
  697 + gen_op_subf();
  698 + gen_op_check_subfo_64();
  699 +}
  700 +#endif
  701 +GEN_INT_ARITH2_64 (subf, 0x1F, 0x08, 0x01, PPC_INTEGER);
479 /* subfc subfc. subfco subfco. */ 702 /* subfc subfc. subfco subfco. */
480 -GEN_INT_ARITH2 (subfc, 0x1F, 0x08, 0x00); 703 +static inline void gen_op_subfc (void)
  704 +{
  705 + gen_op_subf();
  706 + gen_op_check_subfc();
  707 +}
  708 +static inline void gen_op_subfco (void)
  709 +{
  710 + gen_op_move_T2_T0();
  711 + gen_op_subf();
  712 + gen_op_check_subfc();
  713 + gen_op_check_subfo();
  714 +}
  715 +#if defined(TARGET_PPC64)
  716 +static inline void gen_op_subfc_64 (void)
  717 +{
  718 + gen_op_subf();
  719 + gen_op_check_subfc_64();
  720 +}
  721 +static inline void gen_op_subfco_64 (void)
  722 +{
  723 + gen_op_move_T2_T0();
  724 + gen_op_subf();
  725 + gen_op_check_subfc_64();
  726 + gen_op_check_subfo_64();
  727 +}
  728 +#endif
  729 +GEN_INT_ARITH2_64 (subfc, 0x1F, 0x08, 0x00, PPC_INTEGER);
481 /* subfe subfe. subfeo subfeo. */ 730 /* subfe subfe. subfeo subfeo. */
482 -GEN_INT_ARITH2 (subfe, 0x1F, 0x08, 0x04); 731 +static inline void gen_op_subfeo (void)
  732 +{
  733 + gen_op_move_T2_T0();
  734 + gen_op_subfe();
  735 + gen_op_check_subfo();
  736 +}
  737 +#if defined(TARGET_PPC64)
  738 +#define gen_op_subfe_64 gen_op_subfe
  739 +static inline void gen_op_subfeo_64 (void)
  740 +{
  741 + gen_op_move_T2_T0();
  742 + gen_op_subfe_64();
  743 + gen_op_check_subfo_64();
  744 +}
  745 +#endif
  746 +GEN_INT_ARITH2_64 (subfe, 0x1F, 0x08, 0x04, PPC_INTEGER);
483 /* subfme subfme. subfmeo subfmeo. */ 747 /* subfme subfme. subfmeo subfmeo. */
484 -GEN_INT_ARITH1 (subfme, 0x1F, 0x08, 0x07); 748 +GEN_INT_ARITH1_64 (subfme, 0x1F, 0x08, 0x07, PPC_INTEGER);
485 /* subfze subfze. subfzeo subfzeo. */ 749 /* subfze subfze. subfzeo subfzeo. */
486 -GEN_INT_ARITH1 (subfze, 0x1F, 0x08, 0x06); 750 +GEN_INT_ARITH1_64 (subfze, 0x1F, 0x08, 0x06, PPC_INTEGER);
487 /* addi */ 751 /* addi */
488 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) 752 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
489 { 753 {
@@ -491,7 +755,7 @@ GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -491,7 +755,7 @@ GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
491 755
492 if (rA(ctx->opcode) == 0) { 756 if (rA(ctx->opcode) == 0) {
493 /* li case */ 757 /* li case */
494 - gen_op_set_T0(simm); 758 + gen_set_T0(simm);
495 } else { 759 } else {
496 gen_op_load_gpr_T0(rA(ctx->opcode)); 760 gen_op_load_gpr_T0(rA(ctx->opcode));
497 if (likely(simm != 0)) 761 if (likely(simm != 0))
@@ -505,8 +769,16 @@ GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -505,8 +769,16 @@ GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
505 target_long simm = SIMM(ctx->opcode); 769 target_long simm = SIMM(ctx->opcode);
506 770
507 gen_op_load_gpr_T0(rA(ctx->opcode)); 771 gen_op_load_gpr_T0(rA(ctx->opcode));
508 - if (likely(simm != 0))  
509 - gen_op_addic(SIMM(ctx->opcode)); 772 + if (likely(simm != 0)) {
  773 + gen_op_move_T2_T0();
  774 + gen_op_addi(simm);
  775 +#if defined(TARGET_PPC64)
  776 + if (ctx->sf_mode)
  777 + gen_op_check_addc_64();
  778 + else
  779 +#endif
  780 + gen_op_check_addc();
  781 + }
510 gen_op_store_T0_gpr(rD(ctx->opcode)); 782 gen_op_store_T0_gpr(rD(ctx->opcode));
511 } 783 }
512 /* addic. */ 784 /* addic. */
@@ -515,8 +787,16 @@ GEN_HANDLER(addic_, 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -515,8 +787,16 @@ GEN_HANDLER(addic_, 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
515 target_long simm = SIMM(ctx->opcode); 787 target_long simm = SIMM(ctx->opcode);
516 788
517 gen_op_load_gpr_T0(rA(ctx->opcode)); 789 gen_op_load_gpr_T0(rA(ctx->opcode));
518 - if (likely(simm != 0))  
519 - gen_op_addic(SIMM(ctx->opcode)); 790 + if (likely(simm != 0)) {
  791 + gen_op_move_T2_T0();
  792 + gen_op_addi(simm);
  793 +#if defined(TARGET_PPC64)
  794 + if (ctx->sf_mode)
  795 + gen_op_check_addc_64();
  796 + else
  797 +#endif
  798 + gen_op_check_addc();
  799 + }
520 gen_op_store_T0_gpr(rD(ctx->opcode)); 800 gen_op_store_T0_gpr(rD(ctx->opcode));
521 gen_set_Rc0(ctx); 801 gen_set_Rc0(ctx);
522 } 802 }
@@ -527,7 +807,7 @@ GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -527,7 +807,7 @@ GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
527 807
528 if (rA(ctx->opcode) == 0) { 808 if (rA(ctx->opcode) == 0) {
529 /* lis case */ 809 /* lis case */
530 - gen_op_set_T0(simm << 16); 810 + gen_set_T0(simm << 16);
531 } else { 811 } else {
532 gen_op_load_gpr_T0(rA(ctx->opcode)); 812 gen_op_load_gpr_T0(rA(ctx->opcode));
533 if (likely(simm != 0)) 813 if (likely(simm != 0))
@@ -546,42 +826,103 @@ GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -546,42 +826,103 @@ GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
546 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) 826 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
547 { 827 {
548 gen_op_load_gpr_T0(rA(ctx->opcode)); 828 gen_op_load_gpr_T0(rA(ctx->opcode));
549 - gen_op_subfic(SIMM(ctx->opcode)); 829 +#if defined(TARGET_PPC64)
  830 + if (ctx->sf_mode)
  831 + gen_op_subfic_64(SIMM(ctx->opcode));
  832 + else
  833 +#endif
  834 + gen_op_subfic(SIMM(ctx->opcode));
550 gen_op_store_T0_gpr(rD(ctx->opcode)); 835 gen_op_store_T0_gpr(rD(ctx->opcode));
551 } 836 }
552 837
  838 +#if defined(TARGET_PPC64)
  839 +/* mulhd mulhd. */
  840 +GEN_INT_ARITHN (mulhd, 0x1F, 0x09, 0x02, PPC_INTEGER);
  841 +/* mulhdu mulhdu. */
  842 +GEN_INT_ARITHN (mulhdu, 0x1F, 0x09, 0x00, PPC_INTEGER);
  843 +/* mulld mulld. mulldo mulldo. */
  844 +GEN_INT_ARITH2 (mulld, 0x1F, 0x09, 0x07, PPC_INTEGER);
  845 +/* divd divd. divdo divdo. */
  846 +GEN_INT_ARITH2 (divd, 0x1F, 0x09, 0x0F, PPC_INTEGER);
  847 +/* divdu divdu. divduo divduo. */
  848 +GEN_INT_ARITH2 (divdu, 0x1F, 0x09, 0x0E, PPC_INTEGER);
  849 +#endif
  850 +
553 /*** Integer comparison ***/ 851 /*** Integer comparison ***/
554 -#define GEN_CMP(name, opc) \  
555 -GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, PPC_INTEGER) \ 852 +#if defined(TARGET_PPC64)
  853 +#define GEN_CMP(name, opc, type) \
  854 +GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
  855 +{ \
  856 + gen_op_load_gpr_T0(rA(ctx->opcode)); \
  857 + gen_op_load_gpr_T1(rB(ctx->opcode)); \
  858 + if (ctx->sf_mode) \
  859 + gen_op_##name##_64(); \
  860 + else \
  861 + gen_op_##name(); \
  862 + gen_op_store_T0_crf(crfD(ctx->opcode)); \
  863 +}
  864 +#else
  865 +#define GEN_CMP(name, opc, type) \
  866 +GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
556 { \ 867 { \
557 gen_op_load_gpr_T0(rA(ctx->opcode)); \ 868 gen_op_load_gpr_T0(rA(ctx->opcode)); \
558 gen_op_load_gpr_T1(rB(ctx->opcode)); \ 869 gen_op_load_gpr_T1(rB(ctx->opcode)); \
559 gen_op_##name(); \ 870 gen_op_##name(); \
560 gen_op_store_T0_crf(crfD(ctx->opcode)); \ 871 gen_op_store_T0_crf(crfD(ctx->opcode)); \
561 } 872 }
  873 +#endif
562 874
563 /* cmp */ 875 /* cmp */
564 -GEN_CMP(cmp, 0x00); 876 +GEN_CMP(cmp, 0x00, PPC_INTEGER);
565 /* cmpi */ 877 /* cmpi */
566 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER) 878 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
567 { 879 {
568 gen_op_load_gpr_T0(rA(ctx->opcode)); 880 gen_op_load_gpr_T0(rA(ctx->opcode));
569 - gen_op_cmpi(SIMM(ctx->opcode)); 881 +#if defined(TARGET_PPC64)
  882 + if (ctx->sf_mode)
  883 + gen_op_cmpi_64(SIMM(ctx->opcode));
  884 + else
  885 +#endif
  886 + gen_op_cmpi(SIMM(ctx->opcode));
570 gen_op_store_T0_crf(crfD(ctx->opcode)); 887 gen_op_store_T0_crf(crfD(ctx->opcode));
571 } 888 }
572 /* cmpl */ 889 /* cmpl */
573 -GEN_CMP(cmpl, 0x01); 890 +GEN_CMP(cmpl, 0x01, PPC_INTEGER);
574 /* cmpli */ 891 /* cmpli */
575 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER) 892 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
576 { 893 {
577 gen_op_load_gpr_T0(rA(ctx->opcode)); 894 gen_op_load_gpr_T0(rA(ctx->opcode));
578 - gen_op_cmpli(UIMM(ctx->opcode)); 895 +#if defined(TARGET_PPC64)
  896 + if (ctx->sf_mode)
  897 + gen_op_cmpli_64(UIMM(ctx->opcode));
  898 + else
  899 +#endif
  900 + gen_op_cmpli(UIMM(ctx->opcode));
579 gen_op_store_T0_crf(crfD(ctx->opcode)); 901 gen_op_store_T0_crf(crfD(ctx->opcode));
580 } 902 }
581 903
  904 +/* isel (PowerPC 2.03 specification) */
  905 +GEN_HANDLER(isel, 0x1F, 0x0F, 0x00, 0x00000001, PPC_203)
  906 +{
  907 + uint32_t bi = rC(ctx->opcode);
  908 + uint32_t mask;
  909 +
  910 + if (rA(ctx->opcode) == 0) {
  911 + gen_set_T0(0);
  912 + } else {
  913 + gen_op_load_gpr_T1(rA(ctx->opcode));
  914 + }
  915 + gen_op_load_gpr_T2(rB(ctx->opcode));
  916 + mask = 1 << (3 - (bi & 0x03));
  917 + gen_op_load_crf_T0(bi >> 2);
  918 + gen_op_test_true(mask);
  919 + gen_op_isel();
  920 + gen_op_store_T0_gpr(rD(ctx->opcode));
  921 +}
  922 +
582 /*** Integer logical ***/ 923 /*** Integer logical ***/
583 -#define __GEN_LOGICAL2(name, opc2, opc3) \  
584 -GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, PPC_INTEGER) \ 924 +#define __GEN_LOGICAL2(name, opc2, opc3, type) \
  925 +GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \
585 { \ 926 { \
586 gen_op_load_gpr_T0(rS(ctx->opcode)); \ 927 gen_op_load_gpr_T0(rS(ctx->opcode)); \
587 gen_op_load_gpr_T1(rB(ctx->opcode)); \ 928 gen_op_load_gpr_T1(rB(ctx->opcode)); \
@@ -590,11 +931,11 @@ GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, PPC_INTEGER) \ @@ -590,11 +931,11 @@ GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, PPC_INTEGER) \
590 if (unlikely(Rc(ctx->opcode) != 0)) \ 931 if (unlikely(Rc(ctx->opcode) != 0)) \
591 gen_set_Rc0(ctx); \ 932 gen_set_Rc0(ctx); \
592 } 933 }
593 -#define GEN_LOGICAL2(name, opc) \  
594 -__GEN_LOGICAL2(name, 0x1C, opc) 934 +#define GEN_LOGICAL2(name, opc, type) \
  935 +__GEN_LOGICAL2(name, 0x1C, opc, type)
595 936
596 -#define GEN_LOGICAL1(name, opc) \  
597 -GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, PPC_INTEGER) \ 937 +#define GEN_LOGICAL1(name, opc, type) \
  938 +GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
598 { \ 939 { \
599 gen_op_load_gpr_T0(rS(ctx->opcode)); \ 940 gen_op_load_gpr_T0(rS(ctx->opcode)); \
600 gen_op_##name(); \ 941 gen_op_##name(); \
@@ -604,9 +945,9 @@ GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, PPC_INTEGER) \ @@ -604,9 +945,9 @@ GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, PPC_INTEGER) \
604 } 945 }
605 946
606 /* and & and. */ 947 /* and & and. */
607 -GEN_LOGICAL2(and, 0x00); 948 +GEN_LOGICAL2(and, 0x00, PPC_INTEGER);
608 /* andc & andc. */ 949 /* andc & andc. */
609 -GEN_LOGICAL2(andc, 0x01); 950 +GEN_LOGICAL2(andc, 0x01, PPC_INTEGER);
610 /* andi. */ 951 /* andi. */
611 GEN_HANDLER(andi_, 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) 952 GEN_HANDLER(andi_, 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
612 { 953 {
@@ -625,17 +966,17 @@ GEN_HANDLER(andis_, 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -625,17 +966,17 @@ GEN_HANDLER(andis_, 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
625 } 966 }
626 967
627 /* cntlzw */ 968 /* cntlzw */
628 -GEN_LOGICAL1(cntlzw, 0x00); 969 +GEN_LOGICAL1(cntlzw, 0x00, PPC_INTEGER);
629 /* eqv & eqv. */ 970 /* eqv & eqv. */
630 -GEN_LOGICAL2(eqv, 0x08); 971 +GEN_LOGICAL2(eqv, 0x08, PPC_INTEGER);
631 /* extsb & extsb. */ 972 /* extsb & extsb. */
632 -GEN_LOGICAL1(extsb, 0x1D); 973 +GEN_LOGICAL1(extsb, 0x1D, PPC_INTEGER);
633 /* extsh & extsh. */ 974 /* extsh & extsh. */
634 -GEN_LOGICAL1(extsh, 0x1C); 975 +GEN_LOGICAL1(extsh, 0x1C, PPC_INTEGER);
635 /* nand & nand. */ 976 /* nand & nand. */
636 -GEN_LOGICAL2(nand, 0x0E); 977 +GEN_LOGICAL2(nand, 0x0E, PPC_INTEGER);
637 /* nor & nor. */ 978 /* nor & nor. */
638 -GEN_LOGICAL2(nor, 0x03); 979 +GEN_LOGICAL2(nor, 0x03, PPC_INTEGER);
639 980
640 /* or & or. */ 981 /* or & or. */
641 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER) 982 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
@@ -662,7 +1003,7 @@ GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER) @@ -662,7 +1003,7 @@ GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
662 } 1003 }
663 1004
664 /* orc & orc. */ 1005 /* orc & orc. */
665 -GEN_LOGICAL2(orc, 0x0C); 1006 +GEN_LOGICAL2(orc, 0x0C, PPC_INTEGER);
666 /* xor & xor. */ 1007 /* xor & xor. */
667 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER) 1008 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER)
668 { 1009 {
@@ -737,6 +1078,26 @@ GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -737,6 +1078,26 @@ GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
737 gen_op_store_T0_gpr(rA(ctx->opcode)); 1078 gen_op_store_T0_gpr(rA(ctx->opcode));
738 } 1079 }
739 1080
  1081 +/* popcntb : PowerPC 2.03 specification */
  1082 +GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_203)
  1083 +{
  1084 + gen_op_load_gpr_T0(rS(ctx->opcode));
  1085 +#if defined(TARGET_PPC64)
  1086 + if (ctx->sf_mode)
  1087 + gen_op_popcntb_64();
  1088 + else
  1089 +#endif
  1090 + gen_op_popcntb();
  1091 + gen_op_store_T0_gpr(rA(ctx->opcode));
  1092 +}
  1093 +
  1094 +#if defined(TARGET_PPC64)
  1095 +/* extsw & extsw. */
  1096 +GEN_LOGICAL1(extsw, 0x1E, PPC_64B);
  1097 +/* cntlzd */
  1098 +GEN_LOGICAL1(cntlzd, 0x01, PPC_64B);
  1099 +#endif
  1100 +
740 /*** Integer rotate ***/ 1101 /*** Integer rotate ***/
741 /* rlwimi & rlwimi. */ 1102 /* rlwimi & rlwimi. */
742 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) 1103 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
@@ -838,23 +1199,161 @@ GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -838,23 +1199,161 @@ GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
838 gen_set_Rc0(ctx); 1199 gen_set_Rc0(ctx);
839 } 1200 }
840 1201
  1202 +#if defined(TARGET_PPC64)
  1203 +#define GEN_PPC64_R2(name, opc1, opc2) \
  1204 +GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
  1205 +{ \
  1206 + gen_##name(ctx, 0); \
  1207 +} \
  1208 +GEN_HANDLER(name##1, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \
  1209 +{ \
  1210 + gen_##name(ctx, 1); \
  1211 +}
  1212 +#define GEN_PPC64_R4(name, opc1, opc2) \
  1213 +GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
  1214 +{ \
  1215 + gen_##name(ctx, 0, 0); \
  1216 +} \
  1217 +GEN_HANDLER(name##1, opc1, opc2 | 0x01, 0xFF, 0x00000000, PPC_64B) \
  1218 +{ \
  1219 + gen_##name(ctx, 0, 1); \
  1220 +} \
  1221 +GEN_HANDLER(name##2, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \
  1222 +{ \
  1223 + gen_##name(ctx, 1, 0); \
  1224 +} \
  1225 +GEN_HANDLER(name##3, opc1, opc2 | 0x11, 0xFF, 0x00000000, PPC_64B) \
  1226 +{ \
  1227 + gen_##name(ctx, 1, 1); \
  1228 +}
  1229 +/* rldicl - rldicl. */
  1230 +static inline void gen_rldicl (DisasContext *ctx, int mbn, int shn)
  1231 +{
  1232 + int sh, mb;
  1233 +
  1234 + sh = SH(ctx->opcode) | (1 << shn);
  1235 + mb = (MB(ctx->opcode) << 1) | mbn;
  1236 + /* XXX: TODO */
  1237 + RET_INVAL(ctx);
  1238 +}
  1239 +GEN_PPC64_R4(rldicl, 0x1E, 0x00)
  1240 +/* rldicr - rldicr. */
  1241 +static inline void gen_rldicr (DisasContext *ctx, int men, int shn)
  1242 +{
  1243 + int sh, me;
  1244 +
  1245 + sh = SH(ctx->opcode) | (1 << shn);
  1246 + me = (MB(ctx->opcode) << 1) | men;
  1247 + /* XXX: TODO */
  1248 + RET_INVAL(ctx);
  1249 +}
  1250 +GEN_PPC64_R4(rldicr, 0x1E, 0x02)
  1251 +/* rldic - rldic. */
  1252 +static inline void gen_rldic (DisasContext *ctx, int mbn, int shn)
  1253 +{
  1254 + int sh, mb;
  1255 +
  1256 + sh = SH(ctx->opcode) | (1 << shn);
  1257 + mb = (MB(ctx->opcode) << 1) | mbn;
  1258 + /* XXX: TODO */
  1259 + RET_INVAL(ctx);
  1260 +}
  1261 +GEN_PPC64_R4(rldic, 0x1E, 0x04)
  1262 +/* rldcl - rldcl. */
  1263 +static inline void gen_rldcl (DisasContext *ctx, int mbn)
  1264 +{
  1265 + int mb;
  1266 +
  1267 + mb = (MB(ctx->opcode) << 1) | mbn;
  1268 + /* XXX: TODO */
  1269 + RET_INVAL(ctx);
  1270 +}
  1271 +GEN_PPC64_R2(rldcl, 0x1E, 0x08)
  1272 +/* rldcr - rldcr. */
  1273 +static inline void gen_rldcr (DisasContext *ctx, int men)
  1274 +{
  1275 + int me;
  1276 +
  1277 + me = (MB(ctx->opcode) << 1) | men;
  1278 + /* XXX: TODO */
  1279 + RET_INVAL(ctx);
  1280 +}
  1281 +GEN_PPC64_R2(rldcr, 0x1E, 0x09)
  1282 +/* rldimi - rldimi. */
  1283 +static inline void gen_rldimi (DisasContext *ctx, int mbn, int shn)
  1284 +{
  1285 + int sh, mb;
  1286 +
  1287 + sh = SH(ctx->opcode) | (1 << shn);
  1288 + mb = (MB(ctx->opcode) << 1) | mbn;
  1289 + /* XXX: TODO */
  1290 + RET_INVAL(ctx);
  1291 +}
  1292 +GEN_PPC64_R4(rldimi, 0x1E, 0x06)
  1293 +#endif
  1294 +
841 /*** Integer shift ***/ 1295 /*** Integer shift ***/
842 /* slw & slw. */ 1296 /* slw & slw. */
843 -__GEN_LOGICAL2(slw, 0x18, 0x00); 1297 +__GEN_LOGICAL2(slw, 0x18, 0x00, PPC_INTEGER);
844 /* sraw & sraw. */ 1298 /* sraw & sraw. */
845 -__GEN_LOGICAL2(sraw, 0x18, 0x18); 1299 +__GEN_LOGICAL2(sraw, 0x18, 0x18, PPC_INTEGER);
846 /* srawi & srawi. */ 1300 /* srawi & srawi. */
847 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER) 1301 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
848 { 1302 {
  1303 + int mb, me;
849 gen_op_load_gpr_T0(rS(ctx->opcode)); 1304 gen_op_load_gpr_T0(rS(ctx->opcode));
850 - if (SH(ctx->opcode) != 0)  
851 - gen_op_srawi(SH(ctx->opcode), MASK(32 - SH(ctx->opcode), 31)); 1305 + if (SH(ctx->opcode) != 0) {
  1306 + gen_op_move_T1_T0();
  1307 + mb = 32 - SH(ctx->opcode);
  1308 + me = 31;
  1309 +#if defined(TARGET_PPC64)
  1310 + mb += 32;
  1311 + me += 32;
  1312 +#endif
  1313 + gen_op_srawi(SH(ctx->opcode), MASK(mb, me));
  1314 + }
852 gen_op_store_T0_gpr(rA(ctx->opcode)); 1315 gen_op_store_T0_gpr(rA(ctx->opcode));
853 if (unlikely(Rc(ctx->opcode) != 0)) 1316 if (unlikely(Rc(ctx->opcode) != 0))
854 gen_set_Rc0(ctx); 1317 gen_set_Rc0(ctx);
855 } 1318 }
856 /* srw & srw. */ 1319 /* srw & srw. */
857 -__GEN_LOGICAL2(srw, 0x18, 0x10); 1320 +__GEN_LOGICAL2(srw, 0x18, 0x10, PPC_INTEGER);
  1321 +
  1322 +#if defined(TARGET_PPC64)
  1323 +/* sld & sld. */
  1324 +__GEN_LOGICAL2(sld, 0x1B, 0x00, PPC_64B);
  1325 +/* srad & srad. */
  1326 +__GEN_LOGICAL2(srad, 0x1A, 0x18, PPC_64B);
  1327 +/* sradi & sradi. */
  1328 +static inline void gen_sradi (DisasContext *ctx, int n)
  1329 +{
  1330 + uint64_t mask;
  1331 + int sh, mb, me;
  1332 +
  1333 + gen_op_load_gpr_T0(rS(ctx->opcode));
  1334 + sh = SH(ctx->opcode) + (n << 5);
  1335 + if (sh != 0) {
  1336 + gen_op_move_T1_T0();
  1337 + mb = 64 - SH(ctx->opcode);
  1338 + me = 63;
  1339 + mask = MASK(mb, me);
  1340 + gen_op_sradi(sh, mask >> 32, mask);
  1341 + }
  1342 + gen_op_store_T0_gpr(rA(ctx->opcode));
  1343 + if (unlikely(Rc(ctx->opcode) != 0))
  1344 + gen_set_Rc0(ctx);
  1345 +}
  1346 +GEN_HANDLER(sradi0, 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B)
  1347 +{
  1348 + gen_sradi(ctx, 0);
  1349 +}
  1350 +GEN_HANDLER(sradi1, 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B)
  1351 +{
  1352 + gen_sradi(ctx, 1);
  1353 +}
  1354 +/* srd & srd. */
  1355 +__GEN_LOGICAL2(srd, 0x1B, 0x10, PPC_64B);
  1356 +#endif
858 1357
859 /*** Floating-Point arithmetic ***/ 1358 /*** Floating-Point arithmetic ***/
860 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat) \ 1359 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat) \
@@ -1165,7 +1664,7 @@ static inline void gen_addr_imm_index (DisasContext *ctx) @@ -1165,7 +1664,7 @@ static inline void gen_addr_imm_index (DisasContext *ctx)
1165 target_long simm = SIMM(ctx->opcode); 1664 target_long simm = SIMM(ctx->opcode);
1166 1665
1167 if (rA(ctx->opcode) == 0) { 1666 if (rA(ctx->opcode) == 0) {
1168 - gen_op_set_T0(simm); 1667 + gen_set_T0(simm);
1169 } else { 1668 } else {
1170 gen_op_load_gpr_T0(rA(ctx->opcode)); 1669 gen_op_load_gpr_T0(rA(ctx->opcode));
1171 if (likely(simm != 0)) 1670 if (likely(simm != 0))
@@ -1196,26 +1695,51 @@ static inline void gen_addr_register (DisasContext *ctx) @@ -1196,26 +1695,51 @@ static inline void gen_addr_register (DisasContext *ctx)
1196 /*** Integer load ***/ 1695 /*** Integer load ***/
1197 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])() 1696 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
1198 #if defined(CONFIG_USER_ONLY) 1697 #if defined(CONFIG_USER_ONLY)
  1698 +#if defined(TARGET_PPC64)
1199 #define OP_LD_TABLE(width) \ 1699 #define OP_LD_TABLE(width) \
1200 static GenOpFunc *gen_op_l##width[] = { \ 1700 static GenOpFunc *gen_op_l##width[] = { \
1201 &gen_op_l##width##_raw, \ 1701 &gen_op_l##width##_raw, \
1202 &gen_op_l##width##_le_raw, \ 1702 &gen_op_l##width##_le_raw, \
  1703 + &gen_op_l##width##_64_raw, \
  1704 + &gen_op_l##width##_le_64_raw, \
1203 }; 1705 };
1204 #define OP_ST_TABLE(width) \ 1706 #define OP_ST_TABLE(width) \
1205 static GenOpFunc *gen_op_st##width[] = { \ 1707 static GenOpFunc *gen_op_st##width[] = { \
1206 &gen_op_st##width##_raw, \ 1708 &gen_op_st##width##_raw, \
1207 &gen_op_st##width##_le_raw, \ 1709 &gen_op_st##width##_le_raw, \
  1710 + &gen_op_st##width##_64_raw, \
  1711 + &gen_op_st##width##_le_64_raw, \
1208 }; 1712 };
1209 /* Byte access routine are endian safe */ 1713 /* Byte access routine are endian safe */
  1714 +#define gen_op_stb_le_64_raw gen_op_stb_64_raw
  1715 +#define gen_op_lbz_le_64_raw gen_op_lbz_64_raw
  1716 +#else
  1717 +#define OP_LD_TABLE(width) \
  1718 +static GenOpFunc *gen_op_l##width[] = { \
  1719 + &gen_op_l##width##_raw, \
  1720 + &gen_op_l##width##_le_raw, \
  1721 +};
  1722 +#define OP_ST_TABLE(width) \
  1723 +static GenOpFunc *gen_op_st##width[] = { \
  1724 + &gen_op_st##width##_raw, \
  1725 + &gen_op_st##width##_le_raw, \
  1726 +};
  1727 +#endif
  1728 +/* Byte access routine are endian safe */
1210 #define gen_op_stb_le_raw gen_op_stb_raw 1729 #define gen_op_stb_le_raw gen_op_stb_raw
1211 #define gen_op_lbz_le_raw gen_op_lbz_raw 1730 #define gen_op_lbz_le_raw gen_op_lbz_raw
1212 #else 1731 #else
  1732 +#if defined(TARGET_PPC64)
1213 #define OP_LD_TABLE(width) \ 1733 #define OP_LD_TABLE(width) \
1214 static GenOpFunc *gen_op_l##width[] = { \ 1734 static GenOpFunc *gen_op_l##width[] = { \
1215 &gen_op_l##width##_user, \ 1735 &gen_op_l##width##_user, \
1216 &gen_op_l##width##_le_user, \ 1736 &gen_op_l##width##_le_user, \
1217 &gen_op_l##width##_kernel, \ 1737 &gen_op_l##width##_kernel, \
1218 &gen_op_l##width##_le_kernel, \ 1738 &gen_op_l##width##_le_kernel, \
  1739 + &gen_op_l##width##_64_user, \
  1740 + &gen_op_l##width##_le_64_user, \
  1741 + &gen_op_l##width##_64_kernel, \
  1742 + &gen_op_l##width##_le_64_kernel, \
1219 }; 1743 };
1220 #define OP_ST_TABLE(width) \ 1744 #define OP_ST_TABLE(width) \
1221 static GenOpFunc *gen_op_st##width[] = { \ 1745 static GenOpFunc *gen_op_st##width[] = { \
@@ -1223,24 +1747,49 @@ static GenOpFunc *gen_op_st##width[] = { \ @@ -1223,24 +1747,49 @@ static GenOpFunc *gen_op_st##width[] = { \
1223 &gen_op_st##width##_le_user, \ 1747 &gen_op_st##width##_le_user, \
1224 &gen_op_st##width##_kernel, \ 1748 &gen_op_st##width##_kernel, \
1225 &gen_op_st##width##_le_kernel, \ 1749 &gen_op_st##width##_le_kernel, \
  1750 + &gen_op_st##width##_64_user, \
  1751 + &gen_op_st##width##_le_64_user, \
  1752 + &gen_op_st##width##_64_kernel, \
  1753 + &gen_op_st##width##_le_64_kernel, \
1226 }; 1754 };
1227 /* Byte access routine are endian safe */ 1755 /* Byte access routine are endian safe */
  1756 +#define gen_op_stb_le_64_user gen_op_stb_64_user
  1757 +#define gen_op_lbz_le_64_user gen_op_lbz_64_user
  1758 +#define gen_op_stb_le_64_kernel gen_op_stb_64_kernel
  1759 +#define gen_op_lbz_le_64_kernel gen_op_lbz_64_kernel
  1760 +#else
  1761 +#define OP_LD_TABLE(width) \
  1762 +static GenOpFunc *gen_op_l##width[] = { \
  1763 + &gen_op_l##width##_user, \
  1764 + &gen_op_l##width##_le_user, \
  1765 + &gen_op_l##width##_kernel, \
  1766 + &gen_op_l##width##_le_kernel, \
  1767 +};
  1768 +#define OP_ST_TABLE(width) \
  1769 +static GenOpFunc *gen_op_st##width[] = { \
  1770 + &gen_op_st##width##_user, \
  1771 + &gen_op_st##width##_le_user, \
  1772 + &gen_op_st##width##_kernel, \
  1773 + &gen_op_st##width##_le_kernel, \
  1774 +};
  1775 +#endif
  1776 +/* Byte access routine are endian safe */
1228 #define gen_op_stb_le_user gen_op_stb_user 1777 #define gen_op_stb_le_user gen_op_stb_user
1229 #define gen_op_lbz_le_user gen_op_lbz_user 1778 #define gen_op_lbz_le_user gen_op_lbz_user
1230 #define gen_op_stb_le_kernel gen_op_stb_kernel 1779 #define gen_op_stb_le_kernel gen_op_stb_kernel
1231 #define gen_op_lbz_le_kernel gen_op_lbz_kernel 1780 #define gen_op_lbz_le_kernel gen_op_lbz_kernel
1232 #endif 1781 #endif
1233 1782
1234 -#define GEN_LD(width, opc) \  
1235 -GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \ 1783 +#define GEN_LD(width, opc, type) \
  1784 +GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
1236 { \ 1785 { \
1237 gen_addr_imm_index(ctx); \ 1786 gen_addr_imm_index(ctx); \
1238 op_ldst(l##width); \ 1787 op_ldst(l##width); \
1239 gen_op_store_T1_gpr(rD(ctx->opcode)); \ 1788 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1240 } 1789 }
1241 1790
1242 -#define GEN_LDU(width, opc) \  
1243 -GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \ 1791 +#define GEN_LDU(width, opc, type) \
  1792 +GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
1244 { \ 1793 { \
1245 if (unlikely(rA(ctx->opcode) == 0 || \ 1794 if (unlikely(rA(ctx->opcode) == 0 || \
1246 rA(ctx->opcode) == rD(ctx->opcode))) { \ 1795 rA(ctx->opcode) == rD(ctx->opcode))) { \
@@ -1253,8 +1802,8 @@ GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \ @@ -1253,8 +1802,8 @@ GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1253 gen_op_store_T0_gpr(rA(ctx->opcode)); \ 1802 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1254 } 1803 }
1255 1804
1256 -#define GEN_LDUX(width, opc) \  
1257 -GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \ 1805 +#define GEN_LDUX(width, opc2, opc3, type) \
  1806 +GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
1258 { \ 1807 { \
1259 if (unlikely(rA(ctx->opcode) == 0 || \ 1808 if (unlikely(rA(ctx->opcode) == 0 || \
1260 rA(ctx->opcode) == rD(ctx->opcode))) { \ 1809 rA(ctx->opcode) == rD(ctx->opcode))) { \
@@ -1267,41 +1816,74 @@ GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \ @@ -1267,41 +1816,74 @@ GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1267 gen_op_store_T0_gpr(rA(ctx->opcode)); \ 1816 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1268 } 1817 }
1269 1818
1270 -#define GEN_LDX(width, opc2, opc3) \  
1271 -GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \ 1819 +#define GEN_LDX(width, opc2, opc3, type) \
  1820 +GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
1272 { \ 1821 { \
1273 gen_addr_reg_index(ctx); \ 1822 gen_addr_reg_index(ctx); \
1274 op_ldst(l##width); \ 1823 op_ldst(l##width); \
1275 gen_op_store_T1_gpr(rD(ctx->opcode)); \ 1824 gen_op_store_T1_gpr(rD(ctx->opcode)); \
1276 } 1825 }
1277 1826
1278 -#define GEN_LDS(width, op) \ 1827 +#define GEN_LDS(width, op, type) \
1279 OP_LD_TABLE(width); \ 1828 OP_LD_TABLE(width); \
1280 -GEN_LD(width, op | 0x20); \  
1281 -GEN_LDU(width, op | 0x21); \  
1282 -GEN_LDUX(width, op | 0x01); \  
1283 -GEN_LDX(width, 0x17, op | 0x00) 1829 +GEN_LD(width, op | 0x20, type); \
  1830 +GEN_LDU(width, op | 0x21, type); \
  1831 +GEN_LDUX(width, 0x17, op | 0x01, type); \
  1832 +GEN_LDX(width, 0x17, op | 0x00, type)
1284 1833
1285 /* lbz lbzu lbzux lbzx */ 1834 /* lbz lbzu lbzux lbzx */
1286 -GEN_LDS(bz, 0x02); 1835 +GEN_LDS(bz, 0x02, PPC_INTEGER);
1287 /* lha lhau lhaux lhax */ 1836 /* lha lhau lhaux lhax */
1288 -GEN_LDS(ha, 0x0A); 1837 +GEN_LDS(ha, 0x0A, PPC_INTEGER);
1289 /* lhz lhzu lhzux lhzx */ 1838 /* lhz lhzu lhzux lhzx */
1290 -GEN_LDS(hz, 0x08); 1839 +GEN_LDS(hz, 0x08, PPC_INTEGER);
1291 /* lwz lwzu lwzux lwzx */ 1840 /* lwz lwzu lwzux lwzx */
1292 -GEN_LDS(wz, 0x00); 1841 +GEN_LDS(wz, 0x00, PPC_INTEGER);
  1842 +#if defined(TARGET_PPC64)
  1843 +OP_LD_TABLE(wa);
  1844 +OP_LD_TABLE(d);
  1845 +/* lwaux */
  1846 +GEN_LDUX(wa, 0x15, 0x0B, PPC_64B);
  1847 +/* lwax */
  1848 +GEN_LDX(wa, 0x15, 0x0A, PPC_64B);
  1849 +/* ldux */
  1850 +GEN_LDUX(d, 0x15, 0x01, PPC_64B);
  1851 +/* ldx */
  1852 +GEN_LDX(d, 0x15, 0x00, PPC_64B);
  1853 +GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
  1854 +{
  1855 + if (Rc(ctx->opcode)) {
  1856 + if (unlikely(rA(ctx->opcode) == 0 ||
  1857 + rA(ctx->opcode) == rD(ctx->opcode))) {
  1858 + RET_INVAL(ctx);
  1859 + return;
  1860 + }
  1861 + }
  1862 + gen_addr_imm_index(ctx);
  1863 + if (ctx->opcode & 0x02) {
  1864 + /* lwa (lwau is undefined) */
  1865 + op_ldst(lwa);
  1866 + } else {
  1867 + /* ld - ldu */
  1868 + op_ldst(ld);
  1869 + }
  1870 + gen_op_store_T1_gpr(rD(ctx->opcode));
  1871 + if (Rc(ctx->opcode))
  1872 + gen_op_store_T0_gpr(rA(ctx->opcode));
  1873 +}
  1874 +#endif
1293 1875
1294 /*** Integer store ***/ 1876 /*** Integer store ***/
1295 -#define GEN_ST(width, opc) \  
1296 -GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \ 1877 +#define GEN_ST(width, opc, type) \
  1878 +GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
1297 { \ 1879 { \
1298 gen_addr_imm_index(ctx); \ 1880 gen_addr_imm_index(ctx); \
1299 gen_op_load_gpr_T1(rS(ctx->opcode)); \ 1881 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1300 op_ldst(st##width); \ 1882 op_ldst(st##width); \
1301 } 1883 }
1302 1884
1303 -#define GEN_STU(width, opc) \  
1304 -GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \ 1885 +#define GEN_STU(width, opc, type) \
  1886 +GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
1305 { \ 1887 { \
1306 if (unlikely(rA(ctx->opcode) == 0)) { \ 1888 if (unlikely(rA(ctx->opcode) == 0)) { \
1307 RET_INVAL(ctx); \ 1889 RET_INVAL(ctx); \
@@ -1313,8 +1895,8 @@ GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \ @@ -1313,8 +1895,8 @@ GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) \
1313 gen_op_store_T0_gpr(rA(ctx->opcode)); \ 1895 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1314 } 1896 }
1315 1897
1316 -#define GEN_STUX(width, opc) \  
1317 -GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \ 1898 +#define GEN_STUX(width, opc2, opc3, type) \
  1899 +GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
1318 { \ 1900 { \
1319 if (unlikely(rA(ctx->opcode) == 0)) { \ 1901 if (unlikely(rA(ctx->opcode) == 0)) { \
1320 RET_INVAL(ctx); \ 1902 RET_INVAL(ctx); \
@@ -1326,44 +1908,97 @@ GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \ @@ -1326,44 +1908,97 @@ GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, PPC_INTEGER) \
1326 gen_op_store_T0_gpr(rA(ctx->opcode)); \ 1908 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1327 } 1909 }
1328 1910
1329 -#define GEN_STX(width, opc2, opc3) \  
1330 -GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, PPC_INTEGER) \ 1911 +#define GEN_STX(width, opc2, opc3, type) \
  1912 +GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
1331 { \ 1913 { \
1332 gen_addr_reg_index(ctx); \ 1914 gen_addr_reg_index(ctx); \
1333 gen_op_load_gpr_T1(rS(ctx->opcode)); \ 1915 gen_op_load_gpr_T1(rS(ctx->opcode)); \
1334 op_ldst(st##width); \ 1916 op_ldst(st##width); \
1335 } 1917 }
1336 1918
1337 -#define GEN_STS(width, op) \ 1919 +#define GEN_STS(width, op, type) \
1338 OP_ST_TABLE(width); \ 1920 OP_ST_TABLE(width); \
1339 -GEN_ST(width, op | 0x20); \  
1340 -GEN_STU(width, op | 0x21); \  
1341 -GEN_STUX(width, op | 0x01); \  
1342 -GEN_STX(width, 0x17, op | 0x00) 1921 +GEN_ST(width, op | 0x20, type); \
  1922 +GEN_STU(width, op | 0x21, type); \
  1923 +GEN_STUX(width, 0x17, op | 0x01, type); \
  1924 +GEN_STX(width, 0x17, op | 0x00, type)
1343 1925
1344 /* stb stbu stbux stbx */ 1926 /* stb stbu stbux stbx */
1345 -GEN_STS(b, 0x06); 1927 +GEN_STS(b, 0x06, PPC_INTEGER);
1346 /* sth sthu sthux sthx */ 1928 /* sth sthu sthux sthx */
1347 -GEN_STS(h, 0x0C); 1929 +GEN_STS(h, 0x0C, PPC_INTEGER);
1348 /* stw stwu stwux stwx */ 1930 /* stw stwu stwux stwx */
1349 -GEN_STS(w, 0x04);  
1350 - 1931 +GEN_STS(w, 0x04, PPC_INTEGER);
  1932 +#if defined(TARGET_PPC64)
  1933 +OP_ST_TABLE(d);
  1934 +GEN_STUX(d, 0x15, 0x01, PPC_64B);
  1935 +GEN_STX(d, 0x15, 0x00, PPC_64B);
  1936 +GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000002, PPC_64B)
  1937 +{
  1938 + if (Rc(ctx->opcode)) {
  1939 + if (unlikely(rA(ctx->opcode) == 0)) {
  1940 + RET_INVAL(ctx);
  1941 + return;
  1942 + }
  1943 + }
  1944 + gen_addr_imm_index(ctx);
  1945 + gen_op_load_gpr_T1(rS(ctx->opcode));
  1946 + op_ldst(std);
  1947 + if (Rc(ctx->opcode))
  1948 + gen_op_store_T0_gpr(rA(ctx->opcode));
  1949 +}
  1950 +#endif
1351 /*** Integer load and store with byte reverse ***/ 1951 /*** Integer load and store with byte reverse ***/
1352 /* lhbrx */ 1952 /* lhbrx */
1353 OP_LD_TABLE(hbr); 1953 OP_LD_TABLE(hbr);
1354 -GEN_LDX(hbr, 0x16, 0x18); 1954 +GEN_LDX(hbr, 0x16, 0x18, PPC_INTEGER);
1355 /* lwbrx */ 1955 /* lwbrx */
1356 OP_LD_TABLE(wbr); 1956 OP_LD_TABLE(wbr);
1357 -GEN_LDX(wbr, 0x16, 0x10); 1957 +GEN_LDX(wbr, 0x16, 0x10, PPC_INTEGER);
1358 /* sthbrx */ 1958 /* sthbrx */
1359 OP_ST_TABLE(hbr); 1959 OP_ST_TABLE(hbr);
1360 -GEN_STX(hbr, 0x16, 0x1C); 1960 +GEN_STX(hbr, 0x16, 0x1C, PPC_INTEGER);
1361 /* stwbrx */ 1961 /* stwbrx */
1362 OP_ST_TABLE(wbr); 1962 OP_ST_TABLE(wbr);
1363 -GEN_STX(wbr, 0x16, 0x14); 1963 +GEN_STX(wbr, 0x16, 0x14, PPC_INTEGER);
1364 1964
1365 /*** Integer load and store multiple ***/ 1965 /*** Integer load and store multiple ***/
1366 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg) 1966 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
  1967 +#if defined(TARGET_PPC64)
  1968 +#if defined(CONFIG_USER_ONLY)
  1969 +static GenOpFunc1 *gen_op_lmw[] = {
  1970 + &gen_op_lmw_raw,
  1971 + &gen_op_lmw_le_raw,
  1972 + &gen_op_lmw_64_raw,
  1973 + &gen_op_lmw_le_64_raw,
  1974 +};
  1975 +static GenOpFunc1 *gen_op_stmw[] = {
  1976 + &gen_op_stmw_64_raw,
  1977 + &gen_op_stmw_le_64_raw,
  1978 +};
  1979 +#else
  1980 +static GenOpFunc1 *gen_op_lmw[] = {
  1981 + &gen_op_lmw_user,
  1982 + &gen_op_lmw_le_user,
  1983 + &gen_op_lmw_kernel,
  1984 + &gen_op_lmw_le_kernel,
  1985 + &gen_op_lmw_64_user,
  1986 + &gen_op_lmw_le_64_user,
  1987 + &gen_op_lmw_64_kernel,
  1988 + &gen_op_lmw_le_64_kernel,
  1989 +};
  1990 +static GenOpFunc1 *gen_op_stmw[] = {
  1991 + &gen_op_stmw_user,
  1992 + &gen_op_stmw_le_user,
  1993 + &gen_op_stmw_kernel,
  1994 + &gen_op_stmw_le_kernel,
  1995 + &gen_op_stmw_64_user,
  1996 + &gen_op_stmw_le_64_user,
  1997 + &gen_op_stmw_64_kernel,
  1998 + &gen_op_stmw_le_64_kernel,
  1999 +};
  2000 +#endif
  2001 +#else
1367 #if defined(CONFIG_USER_ONLY) 2002 #if defined(CONFIG_USER_ONLY)
1368 static GenOpFunc1 *gen_op_lmw[] = { 2003 static GenOpFunc1 *gen_op_lmw[] = {
1369 &gen_op_lmw_raw, 2004 &gen_op_lmw_raw,
@@ -1387,12 +2022,13 @@ static GenOpFunc1 *gen_op_stmw[] = { @@ -1387,12 +2022,13 @@ static GenOpFunc1 *gen_op_stmw[] = {
1387 &gen_op_stmw_le_kernel, 2022 &gen_op_stmw_le_kernel,
1388 }; 2023 };
1389 #endif 2024 #endif
  2025 +#endif
1390 2026
1391 /* lmw */ 2027 /* lmw */
1392 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) 2028 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1393 { 2029 {
1394 /* NIP cannot be restored if the memory exception comes from an helper */ 2030 /* NIP cannot be restored if the memory exception comes from an helper */
1395 - gen_op_update_nip(ctx->nip - 4); 2031 + gen_update_nip(ctx, ctx->nip - 4);
1396 gen_addr_imm_index(ctx); 2032 gen_addr_imm_index(ctx);
1397 op_ldstm(lmw, rD(ctx->opcode)); 2033 op_ldstm(lmw, rD(ctx->opcode));
1398 } 2034 }
@@ -1401,7 +2037,7 @@ GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -1401,7 +2037,7 @@ GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1401 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) 2037 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1402 { 2038 {
1403 /* NIP cannot be restored if the memory exception comes from an helper */ 2039 /* NIP cannot be restored if the memory exception comes from an helper */
1404 - gen_op_update_nip(ctx->nip - 4); 2040 + gen_update_nip(ctx, ctx->nip - 4);
1405 gen_addr_imm_index(ctx); 2041 gen_addr_imm_index(ctx);
1406 op_ldstm(stmw, rS(ctx->opcode)); 2042 op_ldstm(stmw, rS(ctx->opcode));
1407 } 2043 }
@@ -1409,6 +2045,59 @@ GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) @@ -1409,6 +2045,59 @@ GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1409 /*** Integer load and store strings ***/ 2045 /*** Integer load and store strings ***/
1410 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start) 2046 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
1411 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb) 2047 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
  2048 +#if defined(TARGET_PPC64)
  2049 +#if defined(CONFIG_USER_ONLY)
  2050 +static GenOpFunc1 *gen_op_lswi[] = {
  2051 + &gen_op_lswi_raw,
  2052 + &gen_op_lswi_le_raw,
  2053 + &gen_op_lswi_64_raw,
  2054 + &gen_op_lswi_le_64_raw,
  2055 +};
  2056 +static GenOpFunc3 *gen_op_lswx[] = {
  2057 + &gen_op_lswx_raw,
  2058 + &gen_op_lswx_le_raw,
  2059 + &gen_op_lswx_64_raw,
  2060 + &gen_op_lswx_le_64_raw,
  2061 +};
  2062 +static GenOpFunc1 *gen_op_stsw[] = {
  2063 + &gen_op_stsw_raw,
  2064 + &gen_op_stsw_le_raw,
  2065 + &gen_op_stsw_64_raw,
  2066 + &gen_op_stsw_le_64_raw,
  2067 +};
  2068 +#else
  2069 +static GenOpFunc1 *gen_op_lswi[] = {
  2070 + &gen_op_lswi_user,
  2071 + &gen_op_lswi_le_user,
  2072 + &gen_op_lswi_kernel,
  2073 + &gen_op_lswi_le_kernel,
  2074 + &gen_op_lswi_64_user,
  2075 + &gen_op_lswi_le_64_user,
  2076 + &gen_op_lswi_64_kernel,
  2077 + &gen_op_lswi_le_64_kernel,
  2078 +};
  2079 +static GenOpFunc3 *gen_op_lswx[] = {
  2080 + &gen_op_lswx_user,
  2081 + &gen_op_lswx_le_user,
  2082 + &gen_op_lswx_kernel,
  2083 + &gen_op_lswx_le_kernel,
  2084 + &gen_op_lswx_64_user,
  2085 + &gen_op_lswx_le_64_user,
  2086 + &gen_op_lswx_64_kernel,
  2087 + &gen_op_lswx_le_64_kernel,
  2088 +};
  2089 +static GenOpFunc1 *gen_op_stsw[] = {
  2090 + &gen_op_stsw_user,
  2091 + &gen_op_stsw_le_user,
  2092 + &gen_op_stsw_kernel,
  2093 + &gen_op_stsw_le_kernel,
  2094 + &gen_op_stsw_64_user,
  2095 + &gen_op_stsw_le_64_user,
  2096 + &gen_op_stsw_64_kernel,
  2097 + &gen_op_stsw_le_64_kernel,
  2098 +};
  2099 +#endif
  2100 +#else
1412 #if defined(CONFIG_USER_ONLY) 2101 #if defined(CONFIG_USER_ONLY)
1413 static GenOpFunc1 *gen_op_lswi[] = { 2102 static GenOpFunc1 *gen_op_lswi[] = {
1414 &gen_op_lswi_raw, 2103 &gen_op_lswi_raw,
@@ -1442,6 +2131,7 @@ static GenOpFunc1 *gen_op_stsw[] = { @@ -1442,6 +2131,7 @@ static GenOpFunc1 *gen_op_stsw[] = {
1442 &gen_op_stsw_le_kernel, 2131 &gen_op_stsw_le_kernel,
1443 }; 2132 };
1444 #endif 2133 #endif
  2134 +#endif
1445 2135
1446 /* lswi */ 2136 /* lswi */
1447 /* PowerPC32 specification says we must generate an exception if 2137 /* PowerPC32 specification says we must generate an exception if
@@ -1466,7 +2156,7 @@ GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_INTEGER) @@ -1466,7 +2156,7 @@ GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_INTEGER)
1466 return; 2156 return;
1467 } 2157 }
1468 /* NIP cannot be restored if the memory exception comes from an helper */ 2158 /* NIP cannot be restored if the memory exception comes from an helper */
1469 - gen_op_update_nip(ctx->nip - 4); 2159 + gen_update_nip(ctx, ctx->nip - 4);
1470 gen_addr_register(ctx); 2160 gen_addr_register(ctx);
1471 gen_op_set_T1(nb); 2161 gen_op_set_T1(nb);
1472 op_ldsts(lswi, start); 2162 op_ldsts(lswi, start);
@@ -1479,7 +2169,7 @@ GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_INTEGER) @@ -1479,7 +2169,7 @@ GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_INTEGER)
1479 int rb = rB(ctx->opcode); 2169 int rb = rB(ctx->opcode);
1480 2170
1481 /* NIP cannot be restored if the memory exception comes from an helper */ 2171 /* NIP cannot be restored if the memory exception comes from an helper */
1482 - gen_op_update_nip(ctx->nip - 4); 2172 + gen_update_nip(ctx, ctx->nip - 4);
1483 gen_addr_reg_index(ctx); 2173 gen_addr_reg_index(ctx);
1484 if (ra == 0) { 2174 if (ra == 0) {
1485 ra = rb; 2175 ra = rb;
@@ -1494,7 +2184,7 @@ GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER) @@ -1494,7 +2184,7 @@ GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER)
1494 int nb = NB(ctx->opcode); 2184 int nb = NB(ctx->opcode);
1495 2185
1496 /* NIP cannot be restored if the memory exception comes from an helper */ 2186 /* NIP cannot be restored if the memory exception comes from an helper */
1497 - gen_op_update_nip(ctx->nip - 4); 2187 + gen_update_nip(ctx, ctx->nip - 4);
1498 gen_addr_register(ctx); 2188 gen_addr_register(ctx);
1499 if (nb == 0) 2189 if (nb == 0)
1500 nb = 32; 2190 nb = 32;
@@ -1506,7 +2196,7 @@ GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER) @@ -1506,7 +2196,7 @@ GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER)
1506 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_INTEGER) 2196 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_INTEGER)
1507 { 2197 {
1508 /* NIP cannot be restored if the memory exception comes from an helper */ 2198 /* NIP cannot be restored if the memory exception comes from an helper */
1509 - gen_op_update_nip(ctx->nip - 4); 2199 + gen_update_nip(ctx, ctx->nip - 4);
1510 gen_addr_reg_index(ctx); 2200 gen_addr_reg_index(ctx);
1511 gen_op_load_xer_bc(); 2201 gen_op_load_xer_bc();
1512 op_ldsts(stsw, rS(ctx->opcode)); 2202 op_ldsts(stsw, rS(ctx->opcode));
@@ -1525,14 +2215,19 @@ GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FF0801, PPC_MEM) @@ -1525,14 +2215,19 @@ GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FF0801, PPC_MEM)
1525 2215
1526 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])() 2216 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
1527 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])() 2217 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
  2218 +#if defined(TARGET_PPC64)
1528 #if defined(CONFIG_USER_ONLY) 2219 #if defined(CONFIG_USER_ONLY)
1529 static GenOpFunc *gen_op_lwarx[] = { 2220 static GenOpFunc *gen_op_lwarx[] = {
1530 &gen_op_lwarx_raw, 2221 &gen_op_lwarx_raw,
1531 &gen_op_lwarx_le_raw, 2222 &gen_op_lwarx_le_raw,
  2223 + &gen_op_lwarx_64_raw,
  2224 + &gen_op_lwarx_le_64_raw,
1532 }; 2225 };
1533 static GenOpFunc *gen_op_stwcx[] = { 2226 static GenOpFunc *gen_op_stwcx[] = {
1534 &gen_op_stwcx_raw, 2227 &gen_op_stwcx_raw,
1535 &gen_op_stwcx_le_raw, 2228 &gen_op_stwcx_le_raw,
  2229 + &gen_op_stwcx_64_raw,
  2230 + &gen_op_stwcx_le_64_raw,
1536 }; 2231 };
1537 #else 2232 #else
1538 static GenOpFunc *gen_op_lwarx[] = { 2233 static GenOpFunc *gen_op_lwarx[] = {
@@ -1540,14 +2235,47 @@ static GenOpFunc *gen_op_lwarx[] = { @@ -1540,14 +2235,47 @@ static GenOpFunc *gen_op_lwarx[] = {
1540 &gen_op_lwarx_le_user, 2235 &gen_op_lwarx_le_user,
1541 &gen_op_lwarx_kernel, 2236 &gen_op_lwarx_kernel,
1542 &gen_op_lwarx_le_kernel, 2237 &gen_op_lwarx_le_kernel,
  2238 + &gen_op_lwarx_64_user,
  2239 + &gen_op_lwarx_le_64_user,
  2240 + &gen_op_lwarx_64_kernel,
  2241 + &gen_op_lwarx_le_64_kernel,
1543 }; 2242 };
1544 static GenOpFunc *gen_op_stwcx[] = { 2243 static GenOpFunc *gen_op_stwcx[] = {
1545 &gen_op_stwcx_user, 2244 &gen_op_stwcx_user,
1546 &gen_op_stwcx_le_user, 2245 &gen_op_stwcx_le_user,
1547 &gen_op_stwcx_kernel, 2246 &gen_op_stwcx_kernel,
1548 &gen_op_stwcx_le_kernel, 2247 &gen_op_stwcx_le_kernel,
  2248 + &gen_op_stwcx_64_user,
  2249 + &gen_op_stwcx_le_64_user,
  2250 + &gen_op_stwcx_64_kernel,
  2251 + &gen_op_stwcx_le_64_kernel,
1549 }; 2252 };
1550 #endif 2253 #endif
  2254 +#else
  2255 +#if defined(CONFIG_USER_ONLY)
  2256 +static GenOpFunc *gen_op_lwarx[] = {
  2257 + &gen_op_lwarx_raw,
  2258 + &gen_op_lwarx_le_raw,
  2259 +};
  2260 +static GenOpFunc *gen_op_stwcx[] = {
  2261 + &gen_op_stwcx_raw,
  2262 + &gen_op_stwcx_le_raw,
  2263 +};
  2264 +#else
  2265 +static GenOpFunc *gen_op_lwarx[] = {
  2266 + &gen_op_lwarx_user,
  2267 + &gen_op_lwarx_le_user,
  2268 + &gen_op_lwarx_kernel,
  2269 + &gen_op_lwarx_le_kernel,
  2270 +};
  2271 +static GenOpFunc *gen_op_stwcx[] = {
  2272 + &gen_op_stwcx_user,
  2273 + &gen_op_stwcx_le_user,
  2274 + &gen_op_stwcx_kernel,
  2275 + &gen_op_stwcx_le_kernel,
  2276 +};
  2277 +#endif
  2278 +#endif
1551 2279
1552 /* lwarx */ 2280 /* lwarx */
1553 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES) 2281 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES)
@@ -1736,15 +2464,25 @@ static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) @@ -1736,15 +2464,25 @@ static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
1736 gen_op_goto_tb0(TBPARAM(tb)); 2464 gen_op_goto_tb0(TBPARAM(tb));
1737 else 2465 else
1738 gen_op_goto_tb1(TBPARAM(tb)); 2466 gen_op_goto_tb1(TBPARAM(tb));
1739 - gen_op_set_T1(dest);  
1740 - gen_op_b_T1(); 2467 + gen_set_T1(dest);
  2468 +#if defined(TARGET_PPC64)
  2469 + if (ctx->sf_mode)
  2470 + gen_op_b_T1_64();
  2471 + else
  2472 +#endif
  2473 + gen_op_b_T1();
1741 gen_op_set_T0((long)tb + n); 2474 gen_op_set_T0((long)tb + n);
1742 if (ctx->singlestep_enabled) 2475 if (ctx->singlestep_enabled)
1743 gen_op_debug(); 2476 gen_op_debug();
1744 gen_op_exit_tb(); 2477 gen_op_exit_tb();
1745 } else { 2478 } else {
1746 - gen_op_set_T1(dest);  
1747 - gen_op_b_T1(); 2479 + gen_set_T1(dest);
  2480 +#if defined(TARGET_PPC64)
  2481 + if (ctx->sf_mode)
  2482 + gen_op_b_T1_64();
  2483 + else
  2484 +#endif
  2485 + gen_op_b_T1();
1748 gen_op_reset_T0(); 2486 gen_op_reset_T0();
1749 if (ctx->singlestep_enabled) 2487 if (ctx->singlestep_enabled)
1750 gen_op_debug(); 2488 gen_op_debug();
@@ -1759,16 +2497,22 @@ GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW) @@ -1759,16 +2497,22 @@ GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1759 2497
1760 /* sign extend LI */ 2498 /* sign extend LI */
1761 #if defined(TARGET_PPC64) 2499 #if defined(TARGET_PPC64)
1762 - li = ((target_long)LI(ctx->opcode) << 38) >> 38;  
1763 -#else  
1764 - li = ((target_long)LI(ctx->opcode) << 6) >> 6; 2500 + if (ctx->sf_mode)
  2501 + li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
  2502 + else
1765 #endif 2503 #endif
  2504 + li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
1766 if (likely(AA(ctx->opcode) == 0)) 2505 if (likely(AA(ctx->opcode) == 0))
1767 target = ctx->nip + li - 4; 2506 target = ctx->nip + li - 4;
1768 else 2507 else
1769 target = li; 2508 target = li;
1770 if (LK(ctx->opcode)) { 2509 if (LK(ctx->opcode)) {
1771 - gen_op_setlr(ctx->nip); 2510 +#if defined(TARGET_PPC64)
  2511 + if (ctx->sf_mode)
  2512 + gen_op_setlr_64(ctx->nip >> 32, ctx->nip);
  2513 + else
  2514 +#endif
  2515 + gen_op_setlr(ctx->nip);
1772 } 2516 }
1773 gen_goto_tb(ctx, 0, target); 2517 gen_goto_tb(ctx, 0, target);
1774 ctx->exception = EXCP_BRANCH; 2518 ctx->exception = EXCP_BRANCH;
@@ -1778,16 +2522,16 @@ GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW) @@ -1778,16 +2522,16 @@ GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1778 #define BCOND_LR 1 2522 #define BCOND_LR 1
1779 #define BCOND_CTR 2 2523 #define BCOND_CTR 2
1780 2524
1781 -static inline void gen_bcond(DisasContext *ctx, int type)  
1782 -{ 2525 +static inline void gen_bcond(DisasContext *ctx, int type)
  2526 +{
1783 target_ulong target = 0; 2527 target_ulong target = 0;
1784 target_ulong li; 2528 target_ulong li;
1785 - uint32_t bo = BO(ctx->opcode);  
1786 - uint32_t bi = BI(ctx->opcode);  
1787 - uint32_t mask; 2529 + uint32_t bo = BO(ctx->opcode);
  2530 + uint32_t bi = BI(ctx->opcode);
  2531 + uint32_t mask;
1788 2532
1789 if ((bo & 0x4) == 0) 2533 if ((bo & 0x4) == 0)
1790 - gen_op_dec_ctr(); 2534 + gen_op_dec_ctr();
1791 switch(type) { 2535 switch(type) {
1792 case BCOND_IM: 2536 case BCOND_IM:
1793 li = (target_long)((int16_t)(BD(ctx->opcode))); 2537 li = (target_long)((int16_t)(BD(ctx->opcode)));
@@ -1805,62 +2549,102 @@ static inline void gen_bcond(DisasContext *ctx, int type) @@ -1805,62 +2549,102 @@ static inline void gen_bcond(DisasContext *ctx, int type)
1805 gen_op_movl_T1_lr(); 2549 gen_op_movl_T1_lr();
1806 break; 2550 break;
1807 } 2551 }
1808 - if (LK(ctx->opcode)) {  
1809 - gen_op_setlr(ctx->nip); 2552 + if (LK(ctx->opcode)) {
  2553 +#if defined(TARGET_PPC64)
  2554 + if (ctx->sf_mode)
  2555 + gen_op_setlr_64(ctx->nip >> 32, ctx->nip);
  2556 + else
  2557 +#endif
  2558 + gen_op_setlr(ctx->nip);
1810 } 2559 }
1811 if (bo & 0x10) { 2560 if (bo & 0x10) {
1812 - /* No CR condition */  
1813 - switch (bo & 0x6) {  
1814 - case 0:  
1815 - gen_op_test_ctr(); 2561 + /* No CR condition */
  2562 + switch (bo & 0x6) {
  2563 + case 0:
  2564 +#if defined(TARGET_PPC64)
  2565 + if (ctx->sf_mode)
  2566 + gen_op_test_ctr_64();
  2567 + else
  2568 +#endif
  2569 + gen_op_test_ctr();
  2570 + break;
  2571 + case 2:
  2572 +#if defined(TARGET_PPC64)
  2573 + if (ctx->sf_mode)
  2574 + gen_op_test_ctrz_64();
  2575 + else
  2576 +#endif
  2577 + gen_op_test_ctrz();
1816 break; 2578 break;
1817 - case 2:  
1818 - gen_op_test_ctrz();  
1819 - break;  
1820 default: 2579 default:
1821 - case 4:  
1822 - case 6: 2580 + case 4:
  2581 + case 6:
1823 if (type == BCOND_IM) { 2582 if (type == BCOND_IM) {
1824 gen_goto_tb(ctx, 0, target); 2583 gen_goto_tb(ctx, 0, target);
1825 } else { 2584 } else {
1826 - gen_op_b_T1(); 2585 +#if defined(TARGET_PPC64)
  2586 + if (ctx->sf_mode)
  2587 + gen_op_b_T1_64();
  2588 + else
  2589 +#endif
  2590 + gen_op_b_T1();
1827 gen_op_reset_T0(); 2591 gen_op_reset_T0();
1828 } 2592 }
1829 goto no_test; 2593 goto no_test;
1830 } 2594 }
1831 - } else {  
1832 - mask = 1 << (3 - (bi & 0x03));  
1833 - gen_op_load_crf_T0(bi >> 2);  
1834 - if (bo & 0x8) {  
1835 - switch (bo & 0x6) {  
1836 - case 0:  
1837 - gen_op_test_ctr_true(mask);  
1838 - break;  
1839 - case 2:  
1840 - gen_op_test_ctrz_true(mask);  
1841 - break;  
1842 - default:  
1843 - case 4:  
1844 - case 6: 2595 + } else {
  2596 + mask = 1 << (3 - (bi & 0x03));
  2597 + gen_op_load_crf_T0(bi >> 2);
  2598 + if (bo & 0x8) {
  2599 + switch (bo & 0x6) {
  2600 + case 0:
  2601 +#if defined(TARGET_PPC64)
  2602 + if (ctx->sf_mode)
  2603 + gen_op_test_ctr_true_64(mask);
  2604 + else
  2605 +#endif
  2606 + gen_op_test_ctr_true(mask);
  2607 + break;
  2608 + case 2:
  2609 +#if defined(TARGET_PPC64)
  2610 + if (ctx->sf_mode)
  2611 + gen_op_test_ctrz_true_64(mask);
  2612 + else
  2613 +#endif
  2614 + gen_op_test_ctrz_true(mask);
  2615 + break;
  2616 + default:
  2617 + case 4:
  2618 + case 6:
1845 gen_op_test_true(mask); 2619 gen_op_test_true(mask);
1846 - break;  
1847 - }  
1848 - } else {  
1849 - switch (bo & 0x6) {  
1850 - case 0:  
1851 - gen_op_test_ctr_false(mask);  
1852 - break;  
1853 - case 2:  
1854 - gen_op_test_ctrz_false(mask);  
1855 - break; 2620 + break;
  2621 + }
  2622 + } else {
  2623 + switch (bo & 0x6) {
  2624 + case 0:
  2625 +#if defined(TARGET_PPC64)
  2626 + if (ctx->sf_mode)
  2627 + gen_op_test_ctr_false_64(mask);
  2628 + else
  2629 +#endif
  2630 + gen_op_test_ctr_false(mask);
  2631 + break;
  2632 + case 2:
  2633 +#if defined(TARGET_PPC64)
  2634 + if (ctx->sf_mode)
  2635 + gen_op_test_ctrz_false_64(mask);
  2636 + else
  2637 +#endif
  2638 + gen_op_test_ctrz_false(mask);
  2639 + break;
1856 default: 2640 default:
1857 - case 4:  
1858 - case 6: 2641 + case 4:
  2642 + case 6:
1859 gen_op_test_false(mask); 2643 gen_op_test_false(mask);
1860 - break;  
1861 - }  
1862 - }  
1863 - } 2644 + break;
  2645 + }
  2646 + }
  2647 + }
1864 if (type == BCOND_IM) { 2648 if (type == BCOND_IM) {
1865 int l1 = gen_new_label(); 2649 int l1 = gen_new_label();
1866 gen_op_jz_T0(l1); 2650 gen_op_jz_T0(l1);
@@ -1868,28 +2652,33 @@ static inline void gen_bcond(DisasContext *ctx, int type) @@ -1868,28 +2652,33 @@ static inline void gen_bcond(DisasContext *ctx, int type)
1868 gen_set_label(l1); 2652 gen_set_label(l1);
1869 gen_goto_tb(ctx, 1, ctx->nip); 2653 gen_goto_tb(ctx, 1, ctx->nip);
1870 } else { 2654 } else {
1871 - gen_op_btest_T1(ctx->nip); 2655 +#if defined(TARGET_PPC64)
  2656 + if (ctx->sf_mode)
  2657 + gen_op_btest_T1_64(ctx->nip >> 32, ctx->nip);
  2658 + else
  2659 +#endif
  2660 + gen_op_btest_T1(ctx->nip);
1872 gen_op_reset_T0(); 2661 gen_op_reset_T0();
1873 } 2662 }
1874 no_test: 2663 no_test:
1875 if (ctx->singlestep_enabled) 2664 if (ctx->singlestep_enabled)
1876 gen_op_debug(); 2665 gen_op_debug();
1877 gen_op_exit_tb(); 2666 gen_op_exit_tb();
1878 - ctx->exception = EXCP_BRANCH; 2667 + ctx->exception = EXCP_BRANCH;
1879 } 2668 }
1880 2669
1881 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW) 2670 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1882 -{ 2671 +{
1883 gen_bcond(ctx, BCOND_IM); 2672 gen_bcond(ctx, BCOND_IM);
1884 } 2673 }
1885 2674
1886 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW) 2675 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
1887 -{ 2676 +{
1888 gen_bcond(ctx, BCOND_CTR); 2677 gen_bcond(ctx, BCOND_CTR);
1889 } 2678 }
1890 2679
1891 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW) 2680 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
1892 -{ 2681 +{
1893 gen_bcond(ctx, BCOND_LR); 2682 gen_bcond(ctx, BCOND_LR);
1894 } 2683 }
1895 2684
@@ -1943,7 +2732,12 @@ GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW) @@ -1943,7 +2732,12 @@ GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
1943 RET_PRIVOPC(ctx); 2732 RET_PRIVOPC(ctx);
1944 return; 2733 return;
1945 } 2734 }
1946 - gen_op_rfi(); 2735 +#if defined(TARGET_PPC64)
  2736 + if (!ctx->sf_mode)
  2737 + gen_op_rfi_32();
  2738 + else
  2739 +#endif
  2740 + gen_op_rfi();
1947 RET_CHG_FLOW(ctx); 2741 RET_CHG_FLOW(ctx);
1948 #endif 2742 #endif
1949 } 2743 }
@@ -1965,7 +2759,7 @@ GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW) @@ -1965,7 +2759,7 @@ GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW)
1965 gen_op_load_gpr_T0(rA(ctx->opcode)); 2759 gen_op_load_gpr_T0(rA(ctx->opcode));
1966 gen_op_load_gpr_T1(rB(ctx->opcode)); 2760 gen_op_load_gpr_T1(rB(ctx->opcode));
1967 /* Update the nip since this might generate a trap exception */ 2761 /* Update the nip since this might generate a trap exception */
1968 - gen_op_update_nip(ctx->nip); 2762 + gen_update_nip(ctx, ctx->nip);
1969 gen_op_tw(TO(ctx->opcode)); 2763 gen_op_tw(TO(ctx->opcode));
1970 } 2764 }
1971 2765
@@ -1973,10 +2767,34 @@ GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW) @@ -1973,10 +2767,34 @@ GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW)
1973 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW) 2767 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
1974 { 2768 {
1975 gen_op_load_gpr_T0(rA(ctx->opcode)); 2769 gen_op_load_gpr_T0(rA(ctx->opcode));
1976 - gen_op_set_T1(SIMM(ctx->opcode)); 2770 + gen_set_T1(SIMM(ctx->opcode));
  2771 + /* Update the nip since this might generate a trap exception */
  2772 + gen_update_nip(ctx, ctx->nip);
1977 gen_op_tw(TO(ctx->opcode)); 2773 gen_op_tw(TO(ctx->opcode));
1978 } 2774 }
1979 2775
  2776 +#if defined(TARGET_PPC64)
  2777 +/* td */
  2778 +GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B)
  2779 +{
  2780 + gen_op_load_gpr_T0(rA(ctx->opcode));
  2781 + gen_op_load_gpr_T1(rB(ctx->opcode));
  2782 + /* Update the nip since this might generate a trap exception */
  2783 + gen_update_nip(ctx, ctx->nip);
  2784 + gen_op_td(TO(ctx->opcode));
  2785 +}
  2786 +
  2787 +/* tdi */
  2788 +GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B)
  2789 +{
  2790 + gen_op_load_gpr_T0(rA(ctx->opcode));
  2791 + gen_set_T1(SIMM(ctx->opcode));
  2792 + /* Update the nip since this might generate a trap exception */
  2793 + gen_update_nip(ctx, ctx->nip);
  2794 + gen_op_td(TO(ctx->opcode));
  2795 +}
  2796 +#endif
  2797 +
1980 /*** Processor control ***/ 2798 /*** Processor control ***/
1981 /* mcrxr */ 2799 /* mcrxr */
1982 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC) 2800 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
@@ -1989,7 +2807,6 @@ GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC) @@ -1989,7 +2807,6 @@ GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
1989 /* mfcr */ 2807 /* mfcr */
1990 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC) 2808 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
1991 { 2809 {
1992 -#if 0 // XXX: to be tested  
1993 uint32_t crm, crn; 2810 uint32_t crm, crn;
1994 2811
1995 if (likely(ctx->opcode & 0x00100000)) { 2812 if (likely(ctx->opcode & 0x00100000)) {
@@ -1998,11 +2815,9 @@ GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC) @@ -1998,11 +2815,9 @@ GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
1998 crn = ffs(crm); 2815 crn = ffs(crm);
1999 gen_op_load_cro(7 - crn); 2816 gen_op_load_cro(7 - crn);
2000 } 2817 }
2001 - } else  
2002 -#endif  
2003 - {  
2004 - gen_op_load_cr();  
2005 - } 2818 + } else {
  2819 + gen_op_load_cr();
  2820 + }
2006 gen_op_store_T0_gpr(rD(ctx->opcode)); 2821 gen_op_store_T0_gpr(rD(ctx->opcode));
2007 } 2822 }
2008 2823
@@ -2106,9 +2921,14 @@ GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC) @@ -2106,9 +2921,14 @@ GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
2106 RET_PRIVREG(ctx); 2921 RET_PRIVREG(ctx);
2107 return; 2922 return;
2108 } 2923 }
2109 - gen_op_update_nip((ctx)->nip); 2924 + gen_update_nip(ctx, ctx->nip);
2110 gen_op_load_gpr_T0(rS(ctx->opcode)); 2925 gen_op_load_gpr_T0(rS(ctx->opcode));
2111 - gen_op_store_msr(); 2926 +#if defined(TARGET_PPC64)
  2927 + if (!ctx->sf_mode)
  2928 + gen_op_store_msr_32();
  2929 + else
  2930 +#endif
  2931 + gen_op_store_msr();
2112 /* Must stop the translation as machine state (may have) changed */ 2932 /* Must stop the translation as machine state (may have) changed */
2113 RET_CHG_FLOW(ctx); 2933 RET_CHG_FLOW(ctx);
2114 #endif 2934 #endif
@@ -2205,6 +3025,27 @@ GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x03E00001, PPC_CACHE) @@ -2205,6 +3025,27 @@ GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x03E00001, PPC_CACHE)
2205 3025
2206 /* dcbz */ 3026 /* dcbz */
2207 #define op_dcbz() (*gen_op_dcbz[ctx->mem_idx])() 3027 #define op_dcbz() (*gen_op_dcbz[ctx->mem_idx])()
  3028 +#if defined(TARGET_PPC64)
  3029 +#if defined(CONFIG_USER_ONLY)
  3030 +static GenOpFunc *gen_op_dcbz[] = {
  3031 + &gen_op_dcbz_raw,
  3032 + &gen_op_dcbz_raw,
  3033 + &gen_op_dcbz_64_raw,
  3034 + &gen_op_dcbz_64_raw,
  3035 +};
  3036 +#else
  3037 +static GenOpFunc *gen_op_dcbz[] = {
  3038 + &gen_op_dcbz_user,
  3039 + &gen_op_dcbz_user,
  3040 + &gen_op_dcbz_kernel,
  3041 + &gen_op_dcbz_kernel,
  3042 + &gen_op_dcbz_64_user,
  3043 + &gen_op_dcbz_64_user,
  3044 + &gen_op_dcbz_64_kernel,
  3045 + &gen_op_dcbz_64_kernel,
  3046 +};
  3047 +#endif
  3048 +#else
2208 #if defined(CONFIG_USER_ONLY) 3049 #if defined(CONFIG_USER_ONLY)
2209 static GenOpFunc *gen_op_dcbz[] = { 3050 static GenOpFunc *gen_op_dcbz[] = {
2210 &gen_op_dcbz_raw, 3051 &gen_op_dcbz_raw,
@@ -2218,6 +3059,7 @@ static GenOpFunc *gen_op_dcbz[] = { @@ -2218,6 +3059,7 @@ static GenOpFunc *gen_op_dcbz[] = {
2218 &gen_op_dcbz_kernel, 3059 &gen_op_dcbz_kernel,
2219 }; 3060 };
2220 #endif 3061 #endif
  3062 +#endif
2221 3063
2222 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE) 3064 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE)
2223 { 3065 {
@@ -2230,9 +3072,14 @@ GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE) @@ -2230,9 +3072,14 @@ GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE)
2230 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE) 3072 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE)
2231 { 3073 {
2232 /* NIP cannot be restored if the memory exception comes from an helper */ 3074 /* NIP cannot be restored if the memory exception comes from an helper */
2233 - gen_op_update_nip(ctx->nip - 4); 3075 + gen_update_nip(ctx, ctx->nip - 4);
2234 gen_addr_reg_index(ctx); 3076 gen_addr_reg_index(ctx);
2235 - gen_op_icbi(); 3077 +#if defined(TARGET_PPC64)
  3078 + if (ctx->sf_mode)
  3079 + gen_op_icbi_64();
  3080 + else
  3081 +#endif
  3082 + gen_op_icbi();
2236 RET_STOP(ctx); 3083 RET_STOP(ctx);
2237 } 3084 }
2238 3085
@@ -2342,7 +3189,12 @@ GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE) @@ -2342,7 +3189,12 @@ GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
2342 return; 3189 return;
2343 } 3190 }
2344 gen_op_load_gpr_T0(rB(ctx->opcode)); 3191 gen_op_load_gpr_T0(rB(ctx->opcode));
2345 - gen_op_tlbie(); 3192 +#if defined(TARGET_PPC64)
  3193 + if (ctx->sf_mode)
  3194 + gen_op_tlbie_64();
  3195 + else
  3196 +#endif
  3197 + gen_op_tlbie();
2346 RET_STOP(ctx); 3198 RET_STOP(ctx);
2347 #endif 3199 #endif
2348 } 3200 }
@@ -2368,14 +3220,19 @@ GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC) @@ -2368,14 +3220,19 @@ GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
2368 /* Optional: */ 3220 /* Optional: */
2369 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])() 3221 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
2370 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])() 3222 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
  3223 +#if defined(TARGET_PPC64)
2371 #if defined(CONFIG_USER_ONLY) 3224 #if defined(CONFIG_USER_ONLY)
2372 static GenOpFunc *gen_op_eciwx[] = { 3225 static GenOpFunc *gen_op_eciwx[] = {
2373 &gen_op_eciwx_raw, 3226 &gen_op_eciwx_raw,
2374 &gen_op_eciwx_le_raw, 3227 &gen_op_eciwx_le_raw,
  3228 + &gen_op_eciwx_64_raw,
  3229 + &gen_op_eciwx_le_64_raw,
2375 }; 3230 };
2376 static GenOpFunc *gen_op_ecowx[] = { 3231 static GenOpFunc *gen_op_ecowx[] = {
2377 &gen_op_ecowx_raw, 3232 &gen_op_ecowx_raw,
2378 &gen_op_ecowx_le_raw, 3233 &gen_op_ecowx_le_raw,
  3234 + &gen_op_ecowx_64_raw,
  3235 + &gen_op_ecowx_le_64_raw,
2379 }; 3236 };
2380 #else 3237 #else
2381 static GenOpFunc *gen_op_eciwx[] = { 3238 static GenOpFunc *gen_op_eciwx[] = {
@@ -2383,14 +3240,47 @@ static GenOpFunc *gen_op_eciwx[] = { @@ -2383,14 +3240,47 @@ static GenOpFunc *gen_op_eciwx[] = {
2383 &gen_op_eciwx_le_user, 3240 &gen_op_eciwx_le_user,
2384 &gen_op_eciwx_kernel, 3241 &gen_op_eciwx_kernel,
2385 &gen_op_eciwx_le_kernel, 3242 &gen_op_eciwx_le_kernel,
  3243 + &gen_op_eciwx_64_user,
  3244 + &gen_op_eciwx_le_64_user,
  3245 + &gen_op_eciwx_64_kernel,
  3246 + &gen_op_eciwx_le_64_kernel,
2386 }; 3247 };
2387 static GenOpFunc *gen_op_ecowx[] = { 3248 static GenOpFunc *gen_op_ecowx[] = {
2388 &gen_op_ecowx_user, 3249 &gen_op_ecowx_user,
2389 &gen_op_ecowx_le_user, 3250 &gen_op_ecowx_le_user,
2390 &gen_op_ecowx_kernel, 3251 &gen_op_ecowx_kernel,
2391 &gen_op_ecowx_le_kernel, 3252 &gen_op_ecowx_le_kernel,
  3253 + &gen_op_ecowx_64_user,
  3254 + &gen_op_ecowx_le_64_user,
  3255 + &gen_op_ecowx_64_kernel,
  3256 + &gen_op_ecowx_le_64_kernel,
2392 }; 3257 };
2393 #endif 3258 #endif
  3259 +#else
  3260 +#if defined(CONFIG_USER_ONLY)
  3261 +static GenOpFunc *gen_op_eciwx[] = {
  3262 + &gen_op_eciwx_raw,
  3263 + &gen_op_eciwx_le_raw,
  3264 +};
  3265 +static GenOpFunc *gen_op_ecowx[] = {
  3266 + &gen_op_ecowx_raw,
  3267 + &gen_op_ecowx_le_raw,
  3268 +};
  3269 +#else
  3270 +static GenOpFunc *gen_op_eciwx[] = {
  3271 + &gen_op_eciwx_user,
  3272 + &gen_op_eciwx_le_user,
  3273 + &gen_op_eciwx_kernel,
  3274 + &gen_op_eciwx_le_kernel,
  3275 +};
  3276 +static GenOpFunc *gen_op_ecowx[] = {
  3277 + &gen_op_ecowx_user,
  3278 + &gen_op_ecowx_le_user,
  3279 + &gen_op_ecowx_kernel,
  3280 + &gen_op_ecowx_le_kernel,
  3281 +};
  3282 +#endif
  3283 +#endif
2394 3284
2395 /* eciwx */ 3285 /* eciwx */
2396 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN) 3286 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN)
@@ -2542,7 +3432,7 @@ GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR) @@ -2542,7 +3432,7 @@ GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR)
2542 ra = rb; 3432 ra = rb;
2543 } 3433 }
2544 /* NIP cannot be restored if the memory exception comes from an helper */ 3434 /* NIP cannot be restored if the memory exception comes from an helper */
2545 - gen_op_update_nip(ctx->nip - 4); 3435 + gen_update_nip(ctx, ctx->nip - 4);
2546 gen_op_load_xer_bc(); 3436 gen_op_load_xer_bc();
2547 gen_op_load_xer_cmp(); 3437 gen_op_load_xer_cmp();
2548 op_POWER_lscbx(rD(ctx->opcode), ra, rb); 3438 op_POWER_lscbx(rD(ctx->opcode), ra, rb);
@@ -2710,7 +3600,7 @@ GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR) @@ -2710,7 +3600,7 @@ GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR)
2710 gen_set_Rc0(ctx); 3600 gen_set_Rc0(ctx);
2711 } 3601 }
2712 3602
2713 -/* sraiq -sraiq. */ 3603 +/* sraiq - sraiq. */
2714 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR) 3604 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR)
2715 { 3605 {
2716 gen_op_load_gpr_T0(rS(ctx->opcode)); 3606 gen_op_load_gpr_T0(rS(ctx->opcode));
@@ -2984,7 +3874,7 @@ static GenOpFunc *gen_op_POWER2_stfq[] = { @@ -2984,7 +3874,7 @@ static GenOpFunc *gen_op_POWER2_stfq[] = {
2984 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2) 3874 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
2985 { 3875 {
2986 /* NIP cannot be restored if the memory exception comes from an helper */ 3876 /* NIP cannot be restored if the memory exception comes from an helper */
2987 - gen_op_update_nip(ctx->nip - 4); 3877 + gen_update_nip(ctx, ctx->nip - 4);
2988 gen_addr_imm_index(ctx); 3878 gen_addr_imm_index(ctx);
2989 op_POWER2_lfq(); 3879 op_POWER2_lfq();
2990 gen_op_store_FT0_fpr(rD(ctx->opcode)); 3880 gen_op_store_FT0_fpr(rD(ctx->opcode));
@@ -2997,7 +3887,7 @@ GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2) @@ -2997,7 +3887,7 @@ GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
2997 int ra = rA(ctx->opcode); 3887 int ra = rA(ctx->opcode);
2998 3888
2999 /* NIP cannot be restored if the memory exception comes from an helper */ 3889 /* NIP cannot be restored if the memory exception comes from an helper */
3000 - gen_op_update_nip(ctx->nip - 4); 3890 + gen_update_nip(ctx, ctx->nip - 4);
3001 gen_addr_imm_index(ctx); 3891 gen_addr_imm_index(ctx);
3002 op_POWER2_lfq(); 3892 op_POWER2_lfq();
3003 gen_op_store_FT0_fpr(rD(ctx->opcode)); 3893 gen_op_store_FT0_fpr(rD(ctx->opcode));
@@ -3012,7 +3902,7 @@ GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2) @@ -3012,7 +3902,7 @@ GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2)
3012 int ra = rA(ctx->opcode); 3902 int ra = rA(ctx->opcode);
3013 3903
3014 /* NIP cannot be restored if the memory exception comes from an helper */ 3904 /* NIP cannot be restored if the memory exception comes from an helper */
3015 - gen_op_update_nip(ctx->nip - 4); 3905 + gen_update_nip(ctx, ctx->nip - 4);
3016 gen_addr_reg_index(ctx); 3906 gen_addr_reg_index(ctx);
3017 op_POWER2_lfq(); 3907 op_POWER2_lfq();
3018 gen_op_store_FT0_fpr(rD(ctx->opcode)); 3908 gen_op_store_FT0_fpr(rD(ctx->opcode));
@@ -3025,7 +3915,7 @@ GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2) @@ -3025,7 +3915,7 @@ GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2)
3025 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2) 3915 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2)
3026 { 3916 {
3027 /* NIP cannot be restored if the memory exception comes from an helper */ 3917 /* NIP cannot be restored if the memory exception comes from an helper */
3028 - gen_op_update_nip(ctx->nip - 4); 3918 + gen_update_nip(ctx, ctx->nip - 4);
3029 gen_addr_reg_index(ctx); 3919 gen_addr_reg_index(ctx);
3030 op_POWER2_lfq(); 3920 op_POWER2_lfq();
3031 gen_op_store_FT0_fpr(rD(ctx->opcode)); 3921 gen_op_store_FT0_fpr(rD(ctx->opcode));
@@ -3036,7 +3926,7 @@ GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2) @@ -3036,7 +3926,7 @@ GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2)
3036 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2) 3926 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
3037 { 3927 {
3038 /* NIP cannot be restored if the memory exception comes from an helper */ 3928 /* NIP cannot be restored if the memory exception comes from an helper */
3039 - gen_op_update_nip(ctx->nip - 4); 3929 + gen_update_nip(ctx, ctx->nip - 4);
3040 gen_addr_imm_index(ctx); 3930 gen_addr_imm_index(ctx);
3041 gen_op_load_fpr_FT0(rS(ctx->opcode)); 3931 gen_op_load_fpr_FT0(rS(ctx->opcode));
3042 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1); 3932 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
@@ -3049,7 +3939,7 @@ GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2) @@ -3049,7 +3939,7 @@ GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
3049 int ra = rA(ctx->opcode); 3939 int ra = rA(ctx->opcode);
3050 3940
3051 /* NIP cannot be restored if the memory exception comes from an helper */ 3941 /* NIP cannot be restored if the memory exception comes from an helper */
3052 - gen_op_update_nip(ctx->nip - 4); 3942 + gen_update_nip(ctx, ctx->nip - 4);
3053 gen_addr_imm_index(ctx); 3943 gen_addr_imm_index(ctx);
3054 gen_op_load_fpr_FT0(rS(ctx->opcode)); 3944 gen_op_load_fpr_FT0(rS(ctx->opcode));
3055 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1); 3945 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
@@ -3064,7 +3954,7 @@ GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2) @@ -3064,7 +3954,7 @@ GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2)
3064 int ra = rA(ctx->opcode); 3954 int ra = rA(ctx->opcode);
3065 3955
3066 /* NIP cannot be restored if the memory exception comes from an helper */ 3956 /* NIP cannot be restored if the memory exception comes from an helper */
3067 - gen_op_update_nip(ctx->nip - 4); 3957 + gen_update_nip(ctx, ctx->nip - 4);
3068 gen_addr_reg_index(ctx); 3958 gen_addr_reg_index(ctx);
3069 gen_op_load_fpr_FT0(rS(ctx->opcode)); 3959 gen_op_load_fpr_FT0(rS(ctx->opcode));
3070 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1); 3960 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
@@ -3077,7 +3967,7 @@ GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2) @@ -3077,7 +3967,7 @@ GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2)
3077 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2) 3967 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2)
3078 { 3968 {
3079 /* NIP cannot be restored if the memory exception comes from an helper */ 3969 /* NIP cannot be restored if the memory exception comes from an helper */
3080 - gen_op_update_nip(ctx->nip - 4); 3970 + gen_update_nip(ctx, ctx->nip - 4);
3081 gen_addr_reg_index(ctx); 3971 gen_addr_reg_index(ctx);
3082 gen_op_load_fpr_FT0(rS(ctx->opcode)); 3972 gen_op_load_fpr_FT0(rS(ctx->opcode));
3083 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1); 3973 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
@@ -3102,7 +3992,12 @@ GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_BOOKE) @@ -3102,7 +3992,12 @@ GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_BOOKE)
3102 } 3992 }
3103 gen_addr_reg_index(ctx); 3993 gen_addr_reg_index(ctx);
3104 /* Use the same micro-ops as for tlbie */ 3994 /* Use the same micro-ops as for tlbie */
3105 - gen_op_tlbie(); 3995 +#if defined(TARGET_PPC64)
  3996 + if (ctx->sf_mode)
  3997 + gen_op_tlbie_64();
  3998 + else
  3999 +#endif
  4000 + gen_op_tlbie();
3106 RET_STOP(ctx); 4001 RET_STOP(ctx);
3107 #endif 4002 #endif
3108 } 4003 }
@@ -3398,6 +4293,7 @@ GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_EMB_COMMON) @@ -3398,6 +4293,7 @@ GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_EMB_COMMON)
3398 #endif 4293 #endif
3399 } 4294 }
3400 4295
  4296 +/* TLB management - PowerPC 405 implementation */
3401 /* tlbre */ 4297 /* tlbre */
3402 GEN_HANDLER(tlbre, 0x1F, 0x12, 0x1D, 0x00000001, PPC_EMB_COMMON) 4298 GEN_HANDLER(tlbre, 0x1F, 0x12, 0x1D, 0x00000001, PPC_EMB_COMMON)
3403 { 4299 {
@@ -3426,7 +4322,7 @@ GEN_HANDLER(tlbre, 0x1F, 0x12, 0x1D, 0x00000001, PPC_EMB_COMMON) @@ -3426,7 +4322,7 @@ GEN_HANDLER(tlbre, 0x1F, 0x12, 0x1D, 0x00000001, PPC_EMB_COMMON)
3426 #endif 4322 #endif
3427 } 4323 }
3428 4324
3429 -/* tlbsx - tlbsx. */ /* Named tlbs in BookE */ 4325 +/* tlbsx - tlbsx. */
3430 GEN_HANDLER(tlbsx, 0x1F, 0x12, 0x1C, 0x00000000, PPC_EMB_COMMON) 4326 GEN_HANDLER(tlbsx, 0x1F, 0x12, 0x1C, 0x00000000, PPC_EMB_COMMON)
3431 { 4327 {
3432 #if defined(CONFIG_USER_ONLY) 4328 #if defined(CONFIG_USER_ONLY)
@@ -3446,7 +4342,7 @@ GEN_HANDLER(tlbsx, 0x1F, 0x12, 0x1C, 0x00000000, PPC_EMB_COMMON) @@ -3446,7 +4342,7 @@ GEN_HANDLER(tlbsx, 0x1F, 0x12, 0x1C, 0x00000000, PPC_EMB_COMMON)
3446 } 4342 }
3447 4343
3448 /* tlbwe */ 4344 /* tlbwe */
3449 -GEN_HANDLER(tlbwe, 0x1F, 0x12, 0x1E, 0x00000001, PPC_EMB_COMMON) 4345 +GEN_HANDLER(tlbwe, 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_SPEC)
3450 { 4346 {
3451 #if defined(CONFIG_USER_ONLY) 4347 #if defined(CONFIG_USER_ONLY)
3452 RET_PRIVOPC(ctx); 4348 RET_PRIVOPC(ctx);
@@ -3575,16 +4471,21 @@ void cpu_dump_state(CPUState *env, FILE *f, @@ -3575,16 +4471,21 @@ void cpu_dump_state(CPUState *env, FILE *f,
3575 4471
3576 cpu_fprintf(f, "NIP " REGX " LR " REGX " CTR " REGX "\n", 4472 cpu_fprintf(f, "NIP " REGX " LR " REGX " CTR " REGX "\n",
3577 env->nip, env->lr, env->ctr); 4473 env->nip, env->lr, env->ctr);
3578 - cpu_fprintf(f, "MSR " REGX FILL " XER %08x TB %08x %08x " 4474 + cpu_fprintf(f, "MSR " REGX FILL " XER %08x "
  4475 +#if !defined(NO_TIMER_DUMP)
  4476 + "TB %08x %08x "
3579 #if !defined(CONFIG_USER_ONLY) 4477 #if !defined(CONFIG_USER_ONLY)
3580 "DECR %08x" 4478 "DECR %08x"
3581 #endif 4479 #endif
  4480 +#endif
3582 "\n", 4481 "\n",
3583 - do_load_msr(env), load_xer(env), cpu_ppc_load_tbu(env),  
3584 - cpu_ppc_load_tbl(env) 4482 + do_load_msr(env), load_xer(env)
  4483 +#if !defined(NO_TIMER_DUMP)
  4484 + , cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
3585 #if !defined(CONFIG_USER_ONLY) 4485 #if !defined(CONFIG_USER_ONLY)
3586 , cpu_ppc_load_decr(env) 4486 , cpu_ppc_load_decr(env)
3587 #endif 4487 #endif
  4488 +#endif
3588 ); 4489 );
3589 for (i = 0; i < 32; i++) { 4490 for (i = 0; i < 32; i++) {
3590 if ((i & (RGPL - 1)) == 0) 4491 if ((i & (RGPL - 1)) == 0)
@@ -3619,7 +4520,6 @@ void cpu_dump_state(CPUState *env, FILE *f, @@ -3619,7 +4520,6 @@ void cpu_dump_state(CPUState *env, FILE *f,
3619 "SDR1 " REGX "\n", 4520 "SDR1 " REGX "\n",
3620 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1); 4521 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);
3621 4522
3622 -#undef REGX  
3623 #undef RGPL 4523 #undef RGPL
3624 #undef RFPL 4524 #undef RFPL
3625 #undef FILL 4525 #undef FILL
@@ -3693,9 +4593,18 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb, @@ -3693,9 +4593,18 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
3693 ctx.spr_cb = env->spr_cb; 4593 ctx.spr_cb = env->spr_cb;
3694 #if defined(CONFIG_USER_ONLY) 4594 #if defined(CONFIG_USER_ONLY)
3695 ctx.mem_idx = msr_le; 4595 ctx.mem_idx = msr_le;
  4596 +#if defined(TARGET_PPC64)
  4597 + ctx.mem_idx |= msr_sf << 1;
  4598 +#endif
3696 #else 4599 #else
3697 ctx.supervisor = 1 - msr_pr; 4600 ctx.supervisor = 1 - msr_pr;
3698 ctx.mem_idx = ((1 - msr_pr) << 1) | msr_le; 4601 ctx.mem_idx = ((1 - msr_pr) << 1) | msr_le;
  4602 +#if defined(TARGET_PPC64)
  4603 + ctx.mem_idx |= msr_sf << 2;
  4604 +#endif
  4605 +#endif
  4606 +#if defined(TARGET_PPC64)
  4607 + ctx.sf_mode = msr_sf;
3699 #endif 4608 #endif
3700 ctx.fpu_enabled = msr_fp; 4609 ctx.fpu_enabled = msr_fp;
3701 ctx.singlestep_enabled = env->singlestep_enabled; 4610 ctx.singlestep_enabled = env->singlestep_enabled;
@@ -3708,7 +4617,7 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb, @@ -3708,7 +4617,7 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
3708 if (unlikely(env->nb_breakpoints > 0)) { 4617 if (unlikely(env->nb_breakpoints > 0)) {
3709 for (j = 0; j < env->nb_breakpoints; j++) { 4618 for (j = 0; j < env->nb_breakpoints; j++) {
3710 if (env->breakpoints[j] == ctx.nip) { 4619 if (env->breakpoints[j] == ctx.nip) {
3711 - gen_op_update_nip(ctx.nip); 4620 + gen_update_nip(&ctx, ctx.nip);
3712 gen_op_debug(); 4621 gen_op_debug();
3713 break; 4622 break;
3714 } 4623 }
@@ -3760,12 +4669,12 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb, @@ -3760,12 +4669,12 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
3760 if (unlikely(handler->handler == &gen_invalid)) { 4669 if (unlikely(handler->handler == &gen_invalid)) {
3761 if (loglevel > 0) { 4670 if (loglevel > 0) {
3762 fprintf(logfile, "invalid/unsupported opcode: " 4671 fprintf(logfile, "invalid/unsupported opcode: "
3763 - "%02x - %02x - %02x (%08x) 0x%08x %d\n", 4672 + "%02x - %02x - %02x (%08x) 0x" REGX " %d\n",
3764 opc1(ctx.opcode), opc2(ctx.opcode), 4673 opc1(ctx.opcode), opc2(ctx.opcode),
3765 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir); 4674 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
3766 } else { 4675 } else {
3767 printf("invalid/unsupported opcode: " 4676 printf("invalid/unsupported opcode: "
3768 - "%02x - %02x - %02x (%08x) 0x%08x %d\n", 4677 + "%02x - %02x - %02x (%08x) 0x" REGX " %d\n",
3769 opc1(ctx.opcode), opc2(ctx.opcode), 4678 opc1(ctx.opcode), opc2(ctx.opcode),
3770 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir); 4679 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
3771 } 4680 }
@@ -3773,13 +4682,13 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb, @@ -3773,13 +4682,13 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
3773 if (unlikely((ctx.opcode & handler->inval) != 0)) { 4682 if (unlikely((ctx.opcode & handler->inval) != 0)) {
3774 if (loglevel > 0) { 4683 if (loglevel > 0) {
3775 fprintf(logfile, "invalid bits: %08x for opcode: " 4684 fprintf(logfile, "invalid bits: %08x for opcode: "
3776 - "%02x -%02x - %02x (0x%08x) (0x%08x)\n", 4685 + "%02x -%02x - %02x (%08x) " REGX "\n",
3777 ctx.opcode & handler->inval, opc1(ctx.opcode), 4686 ctx.opcode & handler->inval, opc1(ctx.opcode),
3778 opc2(ctx.opcode), opc3(ctx.opcode), 4687 opc2(ctx.opcode), opc3(ctx.opcode),
3779 ctx.opcode, ctx.nip - 4); 4688 ctx.opcode, ctx.nip - 4);
3780 } else { 4689 } else {
3781 printf("invalid bits: %08x for opcode: " 4690 printf("invalid bits: %08x for opcode: "
3782 - "%02x -%02x - %02x (0x%08x) (0x%08x)\n", 4691 + "%02x -%02x - %02x (%08x) " REGX "\n",
3783 ctx.opcode & handler->inval, opc1(ctx.opcode), 4692 ctx.opcode & handler->inval, opc1(ctx.opcode),
3784 opc2(ctx.opcode), opc3(ctx.opcode), 4693 opc2(ctx.opcode), opc3(ctx.opcode),
3785 ctx.opcode, ctx.nip - 4); 4694 ctx.opcode, ctx.nip - 4);
@@ -3835,7 +4744,7 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb, @@ -3835,7 +4744,7 @@ int gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
3835 } else { 4744 } else {
3836 tb->size = ctx.nip - pc_start; 4745 tb->size = ctx.nip - pc_start;
3837 } 4746 }
3838 -#ifdef DEBUG_DISAS 4747 +#if defined(DEBUG_DISAS)
3839 if (loglevel & CPU_LOG_TB_CPU) { 4748 if (loglevel & CPU_LOG_TB_CPU) {
3840 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception); 4749 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
3841 cpu_dump_state(env, logfile, fprintf, 0); 4750 cpu_dump_state(env, logfile, fprintf, 0);