@@ -26,7 +26,9 @@ int DoesQualifyForLocalDisassembly(const uint8_t *data, bool bigendian)
2626 uint32_t tmp = 0 ;
2727
2828 if (bigendian == true )
29+ {
2930 insword = bswap32 (insword);
31+ }
3032
3133 // 111111xxx00xxxxxxxxxx00001000000 <- fcmpo
3234 tmp = insword & 0xFC6007FF ;
@@ -41,17 +43,78 @@ int DoesQualifyForLocalDisassembly(const uint8_t *data, bool bigendian)
4143
4244void ppc_fcmpo (uint32_t insword, decomp_result *res)
4345{
46+ unsigned regtmp = 0 ;
47+
4448 // 111111AAA00BBBBBCCCCC00001000000 "fcmpo crA,fB,fC"
45- res->detail .ppc .operands [0 ].reg = (ppc_reg)(PPC_REG_CR0 + (insword >> 23 ) & 7 );
49+ regtmp = PPC_REG_CR0 + ((insword >> 23 ) & 7 );
50+ res->detail .ppc .operands [0 ].reg = (ppc_reg)(regtmp);
4651 res->detail .ppc .operands [0 ].type = PPC_OP_REG;
47- res->detail .ppc .operands [1 ].reg = (ppc_reg)(PPC_REG_F0 + (insword >> 16 ) & 31 );
52+
53+ regtmp = PPC_REG_F0 + ((insword >> 16 ) & 31 );
54+ res->detail .ppc .operands [1 ].reg = (ppc_reg)(regtmp);
4855 res->detail .ppc .operands [1 ].type = PPC_OP_REG;
49- res->detail .ppc .operands [2 ].reg = (ppc_reg)(PPC_REG_F0 + (insword >> 11 ) & 31 );
56+
57+ regtmp = PPC_REG_F0 + ((insword >> 11 ) & 31 );
58+ res->detail .ppc .operands [2 ].reg = (ppc_reg)(regtmp);
5059 res->detail .ppc .operands [2 ].type = PPC_OP_REG;
5160
61+
62+ #ifdef FORCE_TEST
63+ SStream ss;
64+ struct cs_struct * handle = 0 ;
65+ struct MCInst tempmc = {0 };
66+ char * first_space = 0 ;
67+
68+ // SStream_Init(&ss);
69+ ss.index = 0 ;
70+ ss.buffer [0 ] = ' \0 ' ;
71+ regtmp = PPC_REG_CR0 + ((insword >> 23 ) & 7 );
72+ tempmc.Operands [0 ].MachineOperandType = MCOperand::kRegister ;
73+ tempmc.Operands [0 ].Kind = 1 ;
74+ tempmc.Operands [0 ].RegVal = regtmp;
75+ regtmp = PPC_REG_F0 + ((insword >> 16 ) & 31 );
76+ tempmc.Operands [1 ].MachineOperandType = MCOperand::kRegister ;
77+ tempmc.Operands [1 ].Kind = 1 ;
78+ tempmc.Operands [1 ].RegVal = regtmp;
79+ regtmp = PPC_REG_F0 + ((insword >> 11 ) & 31 );
80+ tempmc.Operands [2 ].Kind = 1 ;
81+ tempmc.Operands [2 ].MachineOperandType = MCOperand::kRegister ;
82+ tempmc.Operands [2 ].RegVal = regtmp;
83+
84+ // temporarily set this so that print processing succeeds
85+ res->insn .id = PPC_INS_FCMPU;
86+
87+ if (handle_big != 0 )
88+ {
89+ handle = (struct cs_struct *)handle_big;
90+ }
91+ else if (handle_lil != 0 )
92+ {
93+ handle = (struct cs_struct *)handle_lil;
94+ }
95+
96+ #define PPC_FCMPUS 804
97+
98+ tempmc.csh = handle;
99+ tempmc.Opcode = PPC_FCMPUS;
100+ tempmc.flat_insn = &res->insn ;
101+ tempmc.flat_insn ->detail = &res->detail ;
102+
103+ if (handle != 0 )
104+ {
105+ handle->printer (&tempmc, &ss, handle->printer_info );
106+ }
107+
108+ // replace the 'fcmpu' with 'fcmpo'
109+ first_space = strchr (ss.buffer , ' ' );
110+ strncpy (res->insn .op_str , first_space + 1 , sizeof (res->insn .op_str ));
111+ #endif
112+
113+ strncpy (res->insn .mnemonic , " fcmpo" , sizeof (res->insn .mnemonic ));
114+
115+ // reset this to the target value
52116 res->insn .id = PPC_INS_BN_FCMPO;
53117 res->detail .ppc .op_count = 3 ;
54- strncpy (res->insn .mnemonic , " fcmpo" , sizeof (res->insn .mnemonic ));
55118}
56119
57120void ppc_xxpermr (uint32_t insword, decomp_result *res)
@@ -76,10 +139,13 @@ void ppc_xxpermr(uint32_t insword, decomp_result *res)
76139bool PerformLocalDisassembly (const uint8_t *data, uint64_t addr, size_t &len, decomp_result* res, bool bigendian)
77140{
78141 uint32_t local_op = 0 ;
79- uint32_t insword = 0 ;
142+ uint32_t insword = *( uint32_t *)data ;
80143
81144 if (bigendian == true )
145+ {
82146 insword = bswap32 (insword);
147+ }
148+
83149 local_op = DoesQualifyForLocalDisassembly (data, bigendian);
84150
85151 switch (local_op)
0 commit comments