cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
cerion | d0eae2d | 2005-12-23 11:43:01 +0000 | [diff] [blame] | 4 | /*--- This file (guest-ppc/toIR.c) is ---*/ |
sewardj | dbcfae7 | 2005-08-02 11:14:04 +0000 | [diff] [blame] | 5 | /*--- Copyright (C) OpenWorks LLP. All rights reserved. ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 6 | /*--- ---*/ |
| 7 | /*--------------------------------------------------------------------*/ |
| 8 | |
| 9 | /* |
| 10 | This file is part of LibVEX, a library for dynamic binary |
| 11 | instrumentation and translation. |
| 12 | |
sewardj | a33e9a4 | 2006-06-05 23:13:19 +0000 | [diff] [blame] | 13 | Copyright (C) 2004-2006 OpenWorks LLP. All rights reserved. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 14 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 15 | This library is made available under a dual licensing scheme. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 16 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 17 | If you link LibVEX against other code all of which is itself |
| 18 | licensed under the GNU General Public License, version 2 dated June |
| 19 | 1991 ("GPL v2"), then you may use LibVEX under the terms of the GPL |
| 20 | v2, as appearing in the file LICENSE.GPL. If the file LICENSE.GPL |
| 21 | is missing, you can obtain a copy of the GPL v2 from the Free |
| 22 | Software Foundation Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 23 | 02110-1301, USA. |
| 24 | |
| 25 | For any other uses of LibVEX, you must first obtain a commercial |
| 26 | license from OpenWorks LLP. Please contact info@open-works.co.uk |
| 27 | for information about commercial licensing. |
| 28 | |
| 29 | This software is provided by OpenWorks LLP "as is" and any express |
| 30 | or implied warranties, including, but not limited to, the implied |
| 31 | warranties of merchantability and fitness for a particular purpose |
| 32 | are disclaimed. In no event shall OpenWorks LLP be liable for any |
| 33 | direct, indirect, incidental, special, exemplary, or consequential |
| 34 | damages (including, but not limited to, procurement of substitute |
| 35 | goods or services; loss of use, data, or profits; or business |
| 36 | interruption) however caused and on any theory of liability, |
| 37 | whether in contract, strict liability, or tort (including |
| 38 | negligence or otherwise) arising in any way out of the use of this |
| 39 | software, even if advised of the possibility of such damage. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 40 | |
| 41 | Neither the names of the U.S. Department of Energy nor the |
| 42 | University of California nor the names of its contributors may be |
| 43 | used to endorse or promote products derived from this software |
| 44 | without prior written permission. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 45 | */ |
| 46 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 47 | /* TODO 18/Nov/05: |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 48 | |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 49 | Spot rld... cases which are simply left/right shifts and emit |
| 50 | Shl64/Shr64 accordingly. |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 51 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 52 | Altivec |
| 53 | - datastream insns |
| 54 | - lvxl,stvxl: load/store with 'least recently used' hint |
| 55 | - vexptefp, vlogefp |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 56 | |
| 57 | LIMITATIONS: |
| 58 | |
| 59 | Various, including: |
| 60 | |
| 61 | - Some invalid forms of lswi and lswx are accepted when they should |
| 62 | not be. |
| 63 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 64 | - Floating Point: |
| 65 | - All exceptions disabled in FPSCR |
| 66 | - condition codes not set in FPSCR |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 67 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 68 | - Altivec floating point: |
| 69 | - vmaddfp, vnmsubfp |
| 70 | Because we're using Java/IEEE mode (FPSCR[NJ]), rather than the |
| 71 | system default of Non-Java mode, we get some small errors |
| 72 | (lowest bit only). |
| 73 | This is because Non-Java mode brutally hacks denormalised results |
| 74 | to zero, whereas we keep maximum accuracy. However, using |
| 75 | Non-Java mode would give us more inaccuracy, as our intermediate |
| 76 | results would then be zeroed, too. |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 77 | |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 78 | - AbiHints for the stack red zone are only emitted for |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 79 | unconditional calls and returns (bl, blr). They should also be |
| 80 | emitted for conditional calls and returns, but we don't have a |
| 81 | way to express that right now. Ah well. |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 82 | */ |
| 83 | |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 84 | /* "Special" instructions. |
| 85 | |
sewardj | 09e88d1 | 2006-01-27 16:05:49 +0000 | [diff] [blame] | 86 | This instruction decoder can decode four special instructions |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 87 | which mean nothing natively (are no-ops as far as regs/mem are |
| 88 | concerned) but have meaning for supporting Valgrind. A special |
sewardj | 1eb7e6b | 2006-01-12 21:13:14 +0000 | [diff] [blame] | 89 | instruction is flagged by a 16-byte preamble: |
| 90 | |
| 91 | 32-bit mode: 54001800 54006800 5400E800 54009800 |
| 92 | (rlwinm 0,0,3,0,0; rlwinm 0,0,13,0,0; |
| 93 | rlwinm 0,0,29,0,0; rlwinm 0,0,19,0,0) |
| 94 | |
| 95 | 64-bit mode: 78001800 78006800 7800E802 78009802 |
| 96 | (rotldi 0,0,3; rotldi 0,0,13; |
| 97 | rotldi 0,0,61; rotldi 0,0,51) |
| 98 | |
| 99 | Following that, one of the following 3 are allowed |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 100 | (standard interpretation in parentheses): |
| 101 | |
| 102 | 7C210B78 (or 1,1,1) %R3 = client_request ( %R4 ) |
| 103 | 7C421378 (or 2,2,2) %R3 = guest_NRADDR |
| 104 | 7C631B78 (or 3,3,3) branch-and-link-to-noredir %R11 |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 105 | 7C842378 (or 4,4,4) %R3 = guest_NRADDR_GPR2 |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 106 | |
| 107 | Any other bytes following the 16-byte preamble are illegal and |
| 108 | constitute a failure in instruction decoding. This all assumes |
| 109 | that the preamble will never occur except in specific code |
| 110 | fragments designed for Valgrind to catch. |
| 111 | */ |
| 112 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 113 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 114 | /* Translates PPC32/64 code to IR. */ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 115 | |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 116 | /* References |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 117 | |
| 118 | #define PPC32 |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 119 | "PowerPC Microprocessor Family: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 120 | The Programming Environments Manual for 32-Bit Microprocessors" |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 121 | 02/21/2000 |
| 122 | http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF778525699600719DF2 |
| 123 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 124 | #define PPC64 |
| 125 | "PowerPC Microprocessor Family: |
| 126 | Programming Environments Manual for 64-Bit Microprocessors" |
| 127 | 06/10/2003 |
| 128 | http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/F7E732FF811F783187256FDD004D3797 |
| 129 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 130 | #define AV |
| 131 | "PowerPC Microprocessor Family: |
| 132 | AltiVec(TM) Technology Programming Environments Manual" |
| 133 | 07/10/2003 |
| 134 | http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/FBFA164F824370F987256D6A006F424D |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 135 | */ |
| 136 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 137 | #include "libvex_basictypes.h" |
| 138 | #include "libvex_ir.h" |
| 139 | #include "libvex.h" |
cerion | 1515db9 | 2005-01-25 17:21:23 +0000 | [diff] [blame] | 140 | #include "libvex_guest_ppc32.h" |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 141 | #include "libvex_guest_ppc64.h" |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 142 | |
| 143 | #include "main/vex_util.h" |
| 144 | #include "main/vex_globals.h" |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 145 | #include "guest-generic/bb_to_IR.h" |
cerion | d0eae2d | 2005-12-23 11:43:01 +0000 | [diff] [blame] | 146 | #include "guest-ppc/gdefs.h" |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 147 | |
| 148 | |
| 149 | /*------------------------------------------------------------*/ |
| 150 | /*--- Globals ---*/ |
| 151 | /*------------------------------------------------------------*/ |
| 152 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 153 | /* These are set at the start of the translation of an insn, right |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 154 | down in disInstr_PPC, so that we don't have to pass them around |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 155 | endlessly. They are all constant during the translation of any |
| 156 | given insn. */ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 157 | |
cerion | ed623db | 2005-06-20 12:42:04 +0000 | [diff] [blame] | 158 | /* We need to know this to do sub-register accesses correctly. */ |
cerion | ed623db | 2005-06-20 12:42:04 +0000 | [diff] [blame] | 159 | static Bool host_is_bigendian; |
| 160 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 161 | /* Pointer to the guest code area. */ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 162 | static UChar* guest_code; |
| 163 | |
| 164 | /* The guest address corresponding to guest_code[0]. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 165 | static Addr64 guest_CIA_bbstart; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 166 | |
sewardj | 01a9e80 | 2005-02-01 20:46:00 +0000 | [diff] [blame] | 167 | /* The guest address for the instruction currently being |
| 168 | translated. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 169 | static Addr64 guest_CIA_curr_instr; |
sewardj | 01a9e80 | 2005-02-01 20:46:00 +0000 | [diff] [blame] | 170 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 171 | /* The IRBB* into which we're generating code. */ |
| 172 | static IRBB* irbb; |
| 173 | |
sewardj | 5df65bb | 2005-11-29 14:47:04 +0000 | [diff] [blame] | 174 | /* Is our guest binary 32 or 64bit? Set at each call to |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 175 | disInstr_PPC below. */ |
sewardj | 5df65bb | 2005-11-29 14:47:04 +0000 | [diff] [blame] | 176 | static Bool mode64 = False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 177 | |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 178 | // Given a pointer to a function as obtained by "& functionname" in C, |
| 179 | // produce a pointer to the actual entry point for the function. For |
| 180 | // most platforms it's the identity function. Unfortunately, on |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 181 | // ppc64-linux it isn't (sigh) and ditto for ppc32-aix5 and |
| 182 | // ppc64-aix5. |
| 183 | static void* fnptr_to_fnentry( VexMiscInfo* vmi, void* f ) |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 184 | { |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 185 | if (vmi->host_ppc_calls_use_fndescrs) { |
| 186 | /* f is a pointer to a 3-word function descriptor, of which the |
| 187 | first word is the entry address. */ |
| 188 | /* note, this is correct even with cross-jitting, since this is |
| 189 | purely a host issue, not a guest one. */ |
| 190 | HWord* fdescr = (HWord*)f; |
| 191 | return (void*)(fdescr[0]); |
| 192 | } else { |
| 193 | /* Simple; "& f" points directly at the code for f. */ |
| 194 | return f; |
| 195 | } |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 196 | } |
| 197 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 198 | |
| 199 | /*------------------------------------------------------------*/ |
| 200 | /*--- Debugging output ---*/ |
| 201 | /*------------------------------------------------------------*/ |
| 202 | |
| 203 | #define DIP(format, args...) \ |
| 204 | if (vex_traceflags & VEX_TRACE_FE) \ |
| 205 | vex_printf(format, ## args) |
| 206 | |
| 207 | #define DIS(buf, format, args...) \ |
| 208 | if (vex_traceflags & VEX_TRACE_FE) \ |
| 209 | vex_sprintf(buf, format, ## args) |
| 210 | |
| 211 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 212 | /*------------------------------------------------------------*/ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 213 | /*--- Offsets of various parts of the ppc32/64 guest state ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 214 | /*------------------------------------------------------------*/ |
| 215 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 216 | #define offsetofPPCGuestState(_x) \ |
| 217 | (mode64 ? offsetof(VexGuestPPC64State, _x) : \ |
| 218 | offsetof(VexGuestPPC32State, _x)) |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 219 | |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 220 | #define OFFB_CIA offsetofPPCGuestState(guest_CIA) |
| 221 | #define OFFB_CIA_AT_SC offsetofPPCGuestState(guest_CIA_AT_SC) |
| 222 | #define OFFB_SPRG3_RO offsetofPPCGuestState(guest_SPRG3_RO) |
| 223 | #define OFFB_LR offsetofPPCGuestState(guest_LR) |
| 224 | #define OFFB_CTR offsetofPPCGuestState(guest_CTR) |
| 225 | #define OFFB_XER_SO offsetofPPCGuestState(guest_XER_SO) |
| 226 | #define OFFB_XER_OV offsetofPPCGuestState(guest_XER_OV) |
| 227 | #define OFFB_XER_CA offsetofPPCGuestState(guest_XER_CA) |
| 228 | #define OFFB_XER_BC offsetofPPCGuestState(guest_XER_BC) |
| 229 | #define OFFB_FPROUND offsetofPPCGuestState(guest_FPROUND) |
| 230 | #define OFFB_VRSAVE offsetofPPCGuestState(guest_VRSAVE) |
| 231 | #define OFFB_VSCR offsetofPPCGuestState(guest_VSCR) |
| 232 | #define OFFB_EMWARN offsetofPPCGuestState(guest_EMWARN) |
| 233 | #define OFFB_TISTART offsetofPPCGuestState(guest_TISTART) |
| 234 | #define OFFB_TILEN offsetofPPCGuestState(guest_TILEN) |
| 235 | #define OFFB_RESVN offsetofPPCGuestState(guest_RESVN) |
| 236 | #define OFFB_NRADDR offsetofPPCGuestState(guest_NRADDR) |
| 237 | #define OFFB_NRADDR_GPR2 offsetofPPCGuestState(guest_NRADDR_GPR2) |
sewardj | 5ff11dd | 2006-01-20 14:19:25 +0000 | [diff] [blame] | 238 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 239 | |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 240 | /*------------------------------------------------------------*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 241 | /*--- Extract instruction fields --- */ |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 242 | /*------------------------------------------------------------*/ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 243 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 244 | /* Extract field from insn, given idx (zero = lsb) and field length */ |
| 245 | #define IFIELD( insn, idx, len ) ((insn >> idx) & ((1<<len)-1)) |
| 246 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 247 | /* Extract primary opcode, instr[31:26] */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 248 | static UChar ifieldOPC( UInt instr ) { |
| 249 | return toUChar( IFIELD( instr, 26, 6 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 250 | } |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 251 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 252 | /* Extract 10-bit secondary opcode, instr[10:1] */ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 253 | static UInt ifieldOPClo10 ( UInt instr) { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 254 | return IFIELD( instr, 1, 10 ); |
| 255 | } |
| 256 | |
| 257 | /* Extract 9-bit secondary opcode, instr[9:1] */ |
| 258 | static UInt ifieldOPClo9 ( UInt instr) { |
| 259 | return IFIELD( instr, 1, 9 ); |
| 260 | } |
| 261 | |
| 262 | /* Extract 5-bit secondary opcode, instr[5:1] */ |
| 263 | static UInt ifieldOPClo5 ( UInt instr) { |
| 264 | return IFIELD( instr, 1, 5 ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 265 | } |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 266 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 267 | /* Extract RD (destination register) field, instr[25:21] */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 268 | static UChar ifieldRegDS( UInt instr ) { |
| 269 | return toUChar( IFIELD( instr, 21, 5 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 270 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 271 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 272 | /* Extract RA (1st source register) field, instr[20:16] */ |
| 273 | static UChar ifieldRegA ( UInt instr ) { |
| 274 | return toUChar( IFIELD( instr, 16, 5 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 275 | } |
| 276 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 277 | /* Extract RB (2nd source register) field, instr[15:11] */ |
| 278 | static UChar ifieldRegB ( UInt instr ) { |
| 279 | return toUChar( IFIELD( instr, 11, 5 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 280 | } |
| 281 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 282 | /* Extract RC (3rd source register) field, instr[10:6] */ |
| 283 | static UChar ifieldRegC ( UInt instr ) { |
| 284 | return toUChar( IFIELD( instr, 6, 5 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 285 | } |
| 286 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 287 | /* Extract 2nd lowest bit, instr[1] */ |
| 288 | static UChar ifieldBIT10 ( UInt instr ) { |
| 289 | return toUChar( IFIELD( instr, 10, 1 ) ); |
| 290 | } |
| 291 | |
| 292 | /* Extract 2nd lowest bit, instr[1] */ |
| 293 | static UChar ifieldBIT1 ( UInt instr ) { |
| 294 | return toUChar( IFIELD( instr, 1, 1 ) ); |
| 295 | } |
| 296 | |
| 297 | /* Extract lowest bit, instr[0] */ |
| 298 | static UChar ifieldBIT0 ( UInt instr ) { |
| 299 | return toUChar( instr & 0x1 ); |
| 300 | } |
| 301 | |
| 302 | /* Extract unsigned bottom half, instr[15:0] */ |
| 303 | static UInt ifieldUIMM16 ( UInt instr ) { |
| 304 | return instr & 0xFFFF; |
| 305 | } |
| 306 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 307 | /* Extract unsigned bottom 26 bits, instr[25:0] */ |
| 308 | static UInt ifieldUIMM26 ( UInt instr ) { |
| 309 | return instr & 0x3FFFFFF; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 310 | } |
| 311 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 312 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 313 | /*------------------------------------------------------------*/ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 314 | /*--- Guest-state identifiers ---*/ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 315 | /*------------------------------------------------------------*/ |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 316 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 317 | typedef enum { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 318 | PPC_GST_CIA, // Current Instruction Address |
| 319 | PPC_GST_LR, // Link Register |
| 320 | PPC_GST_CTR, // Count Register |
| 321 | PPC_GST_XER, // Overflow, carry flags, byte count |
| 322 | PPC_GST_CR, // Condition Register |
| 323 | PPC_GST_FPSCR, // Floating Point Status/Control Register |
| 324 | PPC_GST_VRSAVE, // Vector Save/Restore Register |
| 325 | PPC_GST_VSCR, // Vector Status and Control Register |
| 326 | PPC_GST_EMWARN, // Emulation warnings |
| 327 | PPC_GST_TISTART,// For icbi: start of area to invalidate |
| 328 | PPC_GST_TILEN, // For icbi: length of area to invalidate |
| 329 | PPC_GST_RESVN, // For lwarx/stwcx. |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 330 | PPC_GST_CIA_AT_SC, // the CIA of the most recently executed SC insn |
| 331 | PPC_GST_SPRG3_RO, // SPRG3 |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 332 | PPC_GST_MAX |
| 333 | } PPC_GST; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 334 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 335 | #define MASK_FPSCR_RN 0x3 |
| 336 | #define MASK_VSCR_VALID 0x00010001 |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 337 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 338 | |
| 339 | /*------------------------------------------------------------*/ |
| 340 | /*--- FP Helpers ---*/ |
| 341 | /*------------------------------------------------------------*/ |
| 342 | |
sewardj | 2ead522 | 2005-11-23 03:53:45 +0000 | [diff] [blame] | 343 | /* Produce the 32-bit pattern corresponding to the supplied |
| 344 | float. */ |
| 345 | static UInt float_to_bits ( Float f ) |
| 346 | { |
| 347 | union { UInt i; Float f; } u; |
| 348 | vassert(4 == sizeof(UInt)); |
| 349 | vassert(4 == sizeof(Float)); |
| 350 | vassert(4 == sizeof(u)); |
| 351 | u.f = f; |
| 352 | return u.i; |
| 353 | } |
| 354 | |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 355 | |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 356 | /*------------------------------------------------------------*/ |
| 357 | /*--- Misc Helpers ---*/ |
| 358 | /*------------------------------------------------------------*/ |
| 359 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 360 | /* Generate mask with 1's from 'begin' through 'end', |
| 361 | wrapping if begin > end. |
| 362 | begin->end works from right to left, 0=lsb |
| 363 | */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 364 | static UInt MASK32( UInt begin, UInt end ) |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 365 | { |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 366 | UInt m1, m2, mask; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 367 | vassert(begin < 32); |
| 368 | vassert(end < 32); |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 369 | m1 = ((UInt)(-1)) << begin; |
| 370 | m2 = ((UInt)(-1)) << end << 1; |
| 371 | mask = m1 ^ m2; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 372 | if (begin > end) mask = ~mask; // wrap mask |
| 373 | return mask; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 374 | } |
| 375 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 376 | /* ditto for 64bit mask */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 377 | static ULong MASK64( UInt begin, UInt end ) |
| 378 | { |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 379 | ULong m1, m2, mask; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 380 | vassert(begin < 64); |
| 381 | vassert(end < 64); |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 382 | m1 = ((ULong)(-1)) << begin; |
| 383 | m2 = ((ULong)(-1)) << end << 1; |
| 384 | mask = m1 ^ m2; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 385 | if (begin > end) mask = ~mask; // wrap mask |
| 386 | return mask; |
| 387 | } |
| 388 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 389 | static Addr64 nextInsnAddr( void ) |
| 390 | { |
| 391 | return guest_CIA_curr_instr + 4; |
| 392 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 393 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 394 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 395 | /*------------------------------------------------------------*/ |
| 396 | /*--- Helper bits and pieces for deconstructing the ---*/ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 397 | /*--- ppc32/64 insn stream. ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 398 | /*------------------------------------------------------------*/ |
| 399 | |
| 400 | /* Add a statement to the list held by "irbb". */ |
| 401 | static void stmt ( IRStmt* st ) |
| 402 | { |
| 403 | addStmtToIRBB( irbb, st ); |
| 404 | } |
| 405 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 406 | /* Generate a new temporary of the given type. */ |
| 407 | static IRTemp newTemp ( IRType ty ) |
| 408 | { |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 409 | vassert(isPlausibleIRType(ty)); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 410 | return newIRTemp( irbb->tyenv, ty ); |
| 411 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 412 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 413 | /* Various simple conversions */ |
| 414 | |
| 415 | static UChar extend_s_5to8 ( UChar x ) |
| 416 | { |
| 417 | return toUChar((((Int)x) << 27) >> 27); |
| 418 | } |
| 419 | |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 420 | static UInt extend_s_8to32( UChar x ) |
| 421 | { |
| 422 | return (UInt)((((Int)x) << 24) >> 24); |
| 423 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 424 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 425 | static UInt extend_s_16to32 ( UInt x ) |
| 426 | { |
| 427 | return (UInt)((((Int)x) << 16) >> 16); |
| 428 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 429 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 430 | static ULong extend_s_16to64 ( UInt x ) |
| 431 | { |
| 432 | return (ULong)((((Long)x) << 48) >> 48); |
| 433 | } |
| 434 | |
| 435 | static ULong extend_s_26to64 ( UInt x ) |
| 436 | { |
| 437 | return (ULong)((((Long)x) << 38) >> 38); |
| 438 | } |
| 439 | |
| 440 | static ULong extend_s_32to64 ( UInt x ) |
| 441 | { |
| 442 | return (ULong)((((Long)x) << 32) >> 32); |
| 443 | } |
| 444 | |
sewardj | 684aa95 | 2005-01-30 12:52:14 +0000 | [diff] [blame] | 445 | /* Do a big-endian load of a 32-bit word, regardless of the endianness |
| 446 | of the underlying host. */ |
cerion | cf00446 | 2005-01-31 15:24:55 +0000 | [diff] [blame] | 447 | static UInt getUIntBigendianly ( UChar* p ) |
sewardj | 684aa95 | 2005-01-30 12:52:14 +0000 | [diff] [blame] | 448 | { |
cerion | cf00446 | 2005-01-31 15:24:55 +0000 | [diff] [blame] | 449 | UInt w = 0; |
sewardj | 684aa95 | 2005-01-30 12:52:14 +0000 | [diff] [blame] | 450 | w = (w << 8) | p[0]; |
| 451 | w = (w << 8) | p[1]; |
| 452 | w = (w << 8) | p[2]; |
| 453 | w = (w << 8) | p[3]; |
| 454 | return w; |
| 455 | } |
| 456 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 457 | |
| 458 | /*------------------------------------------------------------*/ |
| 459 | /*--- Helpers for constructing IR. ---*/ |
| 460 | /*------------------------------------------------------------*/ |
| 461 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 462 | static void assign ( IRTemp dst, IRExpr* e ) |
| 463 | { |
| 464 | stmt( IRStmt_Tmp(dst, e) ); |
| 465 | } |
| 466 | |
cerion | ae69462 | 2005-01-28 17:52:47 +0000 | [diff] [blame] | 467 | static void storeBE ( IRExpr* addr, IRExpr* data ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 468 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 469 | vassert(typeOfIRExpr(irbb->tyenv, addr) == Ity_I32 || |
| 470 | typeOfIRExpr(irbb->tyenv, addr) == Ity_I64); |
sewardj | af1ceca | 2005-06-30 23:31:27 +0000 | [diff] [blame] | 471 | stmt( IRStmt_Store(Iend_BE,addr,data) ); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static IRExpr* unop ( IROp op, IRExpr* a ) |
| 475 | { |
| 476 | return IRExpr_Unop(op, a); |
| 477 | } |
| 478 | |
| 479 | static IRExpr* binop ( IROp op, IRExpr* a1, IRExpr* a2 ) |
| 480 | { |
| 481 | return IRExpr_Binop(op, a1, a2); |
| 482 | } |
| 483 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 484 | static IRExpr* triop ( IROp op, IRExpr* a1, IRExpr* a2, IRExpr* a3 ) |
| 485 | { |
| 486 | return IRExpr_Triop(op, a1, a2, a3); |
| 487 | } |
| 488 | |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 489 | static IRExpr* qop ( IROp op, IRExpr* a1, IRExpr* a2, |
| 490 | IRExpr* a3, IRExpr* a4 ) |
| 491 | { |
| 492 | return IRExpr_Qop(op, a1, a2, a3, a4); |
| 493 | } |
| 494 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 495 | static IRExpr* mkexpr ( IRTemp tmp ) |
| 496 | { |
| 497 | return IRExpr_Tmp(tmp); |
| 498 | } |
| 499 | |
sewardj | 684c037 | 2005-02-07 02:33:58 +0000 | [diff] [blame] | 500 | static IRExpr* mkU8 ( UChar i ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 501 | { |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 502 | return IRExpr_Const(IRConst_U8(i)); |
| 503 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 504 | |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 505 | static IRExpr* mkU16 ( UInt i ) |
| 506 | { |
| 507 | return IRExpr_Const(IRConst_U16(i)); |
| 508 | } |
| 509 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 510 | static IRExpr* mkU32 ( UInt i ) |
| 511 | { |
| 512 | return IRExpr_Const(IRConst_U32(i)); |
| 513 | } |
| 514 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 515 | static IRExpr* mkU64 ( ULong i ) |
| 516 | { |
| 517 | return IRExpr_Const(IRConst_U64(i)); |
| 518 | } |
| 519 | |
cerion | ae69462 | 2005-01-28 17:52:47 +0000 | [diff] [blame] | 520 | static IRExpr* loadBE ( IRType ty, IRExpr* data ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 521 | { |
sewardj | af1ceca | 2005-06-30 23:31:27 +0000 | [diff] [blame] | 522 | return IRExpr_Load(Iend_BE,ty,data); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 523 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 524 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 525 | static IRExpr* mkOR1 ( IRExpr* arg1, IRExpr* arg2 ) |
| 526 | { |
| 527 | vassert(typeOfIRExpr(irbb->tyenv, arg1) == Ity_I1); |
| 528 | vassert(typeOfIRExpr(irbb->tyenv, arg2) == Ity_I1); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 529 | return unop(Iop_32to1, binop(Iop_Or32, unop(Iop_1Uto32, arg1), |
| 530 | unop(Iop_1Uto32, arg2))); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | static IRExpr* mkAND1 ( IRExpr* arg1, IRExpr* arg2 ) |
| 534 | { |
| 535 | vassert(typeOfIRExpr(irbb->tyenv, arg1) == Ity_I1); |
| 536 | vassert(typeOfIRExpr(irbb->tyenv, arg2) == Ity_I1); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 537 | return unop(Iop_32to1, binop(Iop_And32, unop(Iop_1Uto32, arg1), |
| 538 | unop(Iop_1Uto32, arg2))); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 539 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 540 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 541 | /* expand V128_8Ux16 to 2x V128_16Ux8's */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 542 | static void expand8Ux16( IRExpr* vIn, |
| 543 | /*OUTs*/ IRTemp* vEvn, IRTemp* vOdd ) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 544 | { |
| 545 | IRTemp ones8x16 = newTemp(Ity_V128); |
| 546 | |
| 547 | vassert(typeOfIRExpr(irbb->tyenv, vIn) == Ity_V128); |
| 548 | vassert(vEvn && *vEvn == IRTemp_INVALID); |
| 549 | vassert(vOdd && *vOdd == IRTemp_INVALID); |
| 550 | *vEvn = newTemp(Ity_V128); |
| 551 | *vOdd = newTemp(Ity_V128); |
| 552 | |
| 553 | assign( ones8x16, unop(Iop_Dup8x16, mkU8(0x1)) ); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 554 | assign( *vOdd, binop(Iop_MullEven8Ux16, mkexpr(ones8x16), vIn) ); |
| 555 | assign( *vEvn, binop(Iop_MullEven8Ux16, mkexpr(ones8x16), |
| 556 | binop(Iop_ShrV128, vIn, mkU8(8))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* expand V128_8Sx16 to 2x V128_16Sx8's */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 560 | static void expand8Sx16( IRExpr* vIn, |
| 561 | /*OUTs*/ IRTemp* vEvn, IRTemp* vOdd ) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 562 | { |
| 563 | IRTemp ones8x16 = newTemp(Ity_V128); |
| 564 | |
| 565 | vassert(typeOfIRExpr(irbb->tyenv, vIn) == Ity_V128); |
| 566 | vassert(vEvn && *vEvn == IRTemp_INVALID); |
| 567 | vassert(vOdd && *vOdd == IRTemp_INVALID); |
| 568 | *vEvn = newTemp(Ity_V128); |
| 569 | *vOdd = newTemp(Ity_V128); |
| 570 | |
| 571 | assign( ones8x16, unop(Iop_Dup8x16, mkU8(0x1)) ); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 572 | assign( *vOdd, binop(Iop_MullEven8Sx16, mkexpr(ones8x16), vIn) ); |
| 573 | assign( *vEvn, binop(Iop_MullEven8Sx16, mkexpr(ones8x16), |
| 574 | binop(Iop_ShrV128, vIn, mkU8(8))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /* expand V128_16Uto8 to 2x V128_32Ux4's */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 578 | static void expand16Ux8( IRExpr* vIn, |
| 579 | /*OUTs*/ IRTemp* vEvn, IRTemp* vOdd ) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 580 | { |
| 581 | IRTemp ones16x8 = newTemp(Ity_V128); |
| 582 | |
| 583 | vassert(typeOfIRExpr(irbb->tyenv, vIn) == Ity_V128); |
| 584 | vassert(vEvn && *vEvn == IRTemp_INVALID); |
| 585 | vassert(vOdd && *vOdd == IRTemp_INVALID); |
| 586 | *vEvn = newTemp(Ity_V128); |
| 587 | *vOdd = newTemp(Ity_V128); |
| 588 | |
| 589 | assign( ones16x8, unop(Iop_Dup16x8, mkU16(0x1)) ); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 590 | assign( *vOdd, binop(Iop_MullEven16Ux8, mkexpr(ones16x8), vIn) ); |
| 591 | assign( *vEvn, binop(Iop_MullEven16Ux8, mkexpr(ones16x8), |
| 592 | binop(Iop_ShrV128, vIn, mkU8(16))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /* expand V128_16Sto8 to 2x V128_32Sx4's */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 596 | static void expand16Sx8( IRExpr* vIn, |
| 597 | /*OUTs*/ IRTemp* vEvn, IRTemp* vOdd ) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 598 | { |
| 599 | IRTemp ones16x8 = newTemp(Ity_V128); |
| 600 | |
| 601 | vassert(typeOfIRExpr(irbb->tyenv, vIn) == Ity_V128); |
| 602 | vassert(vEvn && *vEvn == IRTemp_INVALID); |
| 603 | vassert(vOdd && *vOdd == IRTemp_INVALID); |
| 604 | *vEvn = newTemp(Ity_V128); |
| 605 | *vOdd = newTemp(Ity_V128); |
| 606 | |
| 607 | assign( ones16x8, unop(Iop_Dup16x8, mkU16(0x1)) ); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 608 | assign( *vOdd, binop(Iop_MullEven16Sx8, mkexpr(ones16x8), vIn) ); |
| 609 | assign( *vEvn, binop(Iop_MullEven16Sx8, mkexpr(ones16x8), |
| 610 | binop(Iop_ShrV128, vIn, mkU8(16))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /* break V128 to 4xI32's, then sign-extend to I64's */ |
| 614 | static void breakV128to4x64S( IRExpr* t128, |
| 615 | /*OUTs*/ |
| 616 | IRTemp* t3, IRTemp* t2, |
| 617 | IRTemp* t1, IRTemp* t0 ) |
| 618 | { |
| 619 | IRTemp hi64 = newTemp(Ity_I64); |
| 620 | IRTemp lo64 = newTemp(Ity_I64); |
| 621 | |
| 622 | vassert(typeOfIRExpr(irbb->tyenv, t128) == Ity_V128); |
| 623 | vassert(t0 && *t0 == IRTemp_INVALID); |
| 624 | vassert(t1 && *t1 == IRTemp_INVALID); |
| 625 | vassert(t2 && *t2 == IRTemp_INVALID); |
| 626 | vassert(t3 && *t3 == IRTemp_INVALID); |
| 627 | *t0 = newTemp(Ity_I64); |
| 628 | *t1 = newTemp(Ity_I64); |
| 629 | *t2 = newTemp(Ity_I64); |
| 630 | *t3 = newTemp(Ity_I64); |
| 631 | |
| 632 | assign( hi64, unop(Iop_V128HIto64, t128) ); |
| 633 | assign( lo64, unop(Iop_V128to64, t128) ); |
| 634 | assign( *t3, unop(Iop_32Sto64, unop(Iop_64HIto32, mkexpr(hi64))) ); |
| 635 | assign( *t2, unop(Iop_32Sto64, unop(Iop_64to32, mkexpr(hi64))) ); |
| 636 | assign( *t1, unop(Iop_32Sto64, unop(Iop_64HIto32, mkexpr(lo64))) ); |
| 637 | assign( *t0, unop(Iop_32Sto64, unop(Iop_64to32, mkexpr(lo64))) ); |
| 638 | } |
| 639 | |
| 640 | /* break V128 to 4xI32's, then zero-extend to I64's */ |
| 641 | static void breakV128to4x64U ( IRExpr* t128, |
| 642 | /*OUTs*/ |
| 643 | IRTemp* t3, IRTemp* t2, |
| 644 | IRTemp* t1, IRTemp* t0 ) |
| 645 | { |
| 646 | IRTemp hi64 = newTemp(Ity_I64); |
| 647 | IRTemp lo64 = newTemp(Ity_I64); |
| 648 | |
| 649 | vassert(typeOfIRExpr(irbb->tyenv, t128) == Ity_V128); |
| 650 | vassert(t0 && *t0 == IRTemp_INVALID); |
| 651 | vassert(t1 && *t1 == IRTemp_INVALID); |
| 652 | vassert(t2 && *t2 == IRTemp_INVALID); |
| 653 | vassert(t3 && *t3 == IRTemp_INVALID); |
| 654 | *t0 = newTemp(Ity_I64); |
| 655 | *t1 = newTemp(Ity_I64); |
| 656 | *t2 = newTemp(Ity_I64); |
| 657 | *t3 = newTemp(Ity_I64); |
| 658 | |
| 659 | assign( hi64, unop(Iop_V128HIto64, t128) ); |
| 660 | assign( lo64, unop(Iop_V128to64, t128) ); |
| 661 | assign( *t3, unop(Iop_32Uto64, unop(Iop_64HIto32, mkexpr(hi64))) ); |
| 662 | assign( *t2, unop(Iop_32Uto64, unop(Iop_64to32, mkexpr(hi64))) ); |
| 663 | assign( *t1, unop(Iop_32Uto64, unop(Iop_64HIto32, mkexpr(lo64))) ); |
| 664 | assign( *t0, unop(Iop_32Uto64, unop(Iop_64to32, mkexpr(lo64))) ); |
| 665 | } |
| 666 | |
| 667 | /* Signed saturating narrow 64S to 32 */ |
| 668 | static IRExpr* mkQNarrow64Sto32 ( IRExpr* t64 ) |
| 669 | { |
| 670 | IRTemp hi32 = newTemp(Ity_I32); |
| 671 | IRTemp lo32 = newTemp(Ity_I32); |
| 672 | |
| 673 | vassert(typeOfIRExpr(irbb->tyenv, t64) == Ity_I64); |
| 674 | |
| 675 | assign( hi32, unop(Iop_64HIto32, t64)); |
| 676 | assign( lo32, unop(Iop_64to32, t64)); |
| 677 | |
| 678 | return IRExpr_Mux0X( |
| 679 | /* if (hi32 == (lo32 >>s 31)) */ |
| 680 | unop(Iop_1Uto8, |
| 681 | binop(Iop_CmpEQ32, mkexpr(hi32), |
| 682 | binop( Iop_Sar32, mkexpr(lo32), mkU8(31)))), |
| 683 | /* else: sign dep saturate: 1->0x80000000, 0->0x7FFFFFFF */ |
| 684 | binop(Iop_Add32, mkU32(0x7FFFFFFF), |
| 685 | binop(Iop_Shr32, mkexpr(hi32), mkU8(31))), |
| 686 | /* then: within signed-32 range: lo half good enough */ |
| 687 | mkexpr(lo32) ); |
| 688 | } |
| 689 | |
| 690 | /* Unsigned saturating narrow 64S to 32 */ |
| 691 | static IRExpr* mkQNarrow64Uto32 ( IRExpr* t64 ) |
| 692 | { |
| 693 | IRTemp hi32 = newTemp(Ity_I32); |
| 694 | IRTemp lo32 = newTemp(Ity_I32); |
| 695 | |
| 696 | vassert(typeOfIRExpr(irbb->tyenv, t64) == Ity_I64); |
| 697 | |
| 698 | assign( hi32, unop(Iop_64HIto32, t64)); |
| 699 | assign( lo32, unop(Iop_64to32, t64)); |
| 700 | |
| 701 | return IRExpr_Mux0X( |
| 702 | /* if (top 32 bits of t64 are 0) */ |
| 703 | unop(Iop_1Uto8, binop(Iop_CmpEQ32, mkexpr(hi32), mkU32(0))), |
| 704 | /* else: positive saturate -> 0xFFFFFFFF */ |
| 705 | mkU32(0xFFFFFFFF), |
| 706 | /* then: within unsigned-32 range: lo half good enough */ |
| 707 | mkexpr(lo32) ); |
| 708 | } |
| 709 | |
| 710 | /* Signed saturate narrow 64->32, combining to V128 */ |
| 711 | static IRExpr* mkV128from4x64S ( IRExpr* t3, IRExpr* t2, |
| 712 | IRExpr* t1, IRExpr* t0 ) |
| 713 | { |
| 714 | vassert(typeOfIRExpr(irbb->tyenv, t3) == Ity_I64); |
| 715 | vassert(typeOfIRExpr(irbb->tyenv, t2) == Ity_I64); |
| 716 | vassert(typeOfIRExpr(irbb->tyenv, t1) == Ity_I64); |
| 717 | vassert(typeOfIRExpr(irbb->tyenv, t0) == Ity_I64); |
| 718 | return binop(Iop_64HLtoV128, |
| 719 | binop(Iop_32HLto64, |
| 720 | mkQNarrow64Sto32( t3 ), |
| 721 | mkQNarrow64Sto32( t2 )), |
| 722 | binop(Iop_32HLto64, |
| 723 | mkQNarrow64Sto32( t1 ), |
| 724 | mkQNarrow64Sto32( t0 ))); |
| 725 | } |
| 726 | |
| 727 | /* Unsigned saturate narrow 64->32, combining to V128 */ |
| 728 | static IRExpr* mkV128from4x64U ( IRExpr* t3, IRExpr* t2, |
| 729 | IRExpr* t1, IRExpr* t0 ) |
| 730 | { |
| 731 | vassert(typeOfIRExpr(irbb->tyenv, t3) == Ity_I64); |
| 732 | vassert(typeOfIRExpr(irbb->tyenv, t2) == Ity_I64); |
| 733 | vassert(typeOfIRExpr(irbb->tyenv, t1) == Ity_I64); |
| 734 | vassert(typeOfIRExpr(irbb->tyenv, t0) == Ity_I64); |
| 735 | return binop(Iop_64HLtoV128, |
| 736 | binop(Iop_32HLto64, |
| 737 | mkQNarrow64Uto32( t3 ), |
| 738 | mkQNarrow64Uto32( t2 )), |
| 739 | binop(Iop_32HLto64, |
| 740 | mkQNarrow64Uto32( t1 ), |
| 741 | mkQNarrow64Uto32( t0 ))); |
| 742 | } |
| 743 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 744 | /* Simulate irops Iop_MullOdd*, since we don't have them */ |
| 745 | #define MK_Iop_MullOdd8Ux16( expr_vA, expr_vB ) \ |
| 746 | binop(Iop_MullEven8Ux16, \ |
| 747 | binop(Iop_ShrV128, expr_vA, mkU8(8)), \ |
| 748 | binop(Iop_ShrV128, expr_vB, mkU8(8))) |
| 749 | |
| 750 | #define MK_Iop_MullOdd8Sx16( expr_vA, expr_vB ) \ |
| 751 | binop(Iop_MullEven8Sx16, \ |
| 752 | binop(Iop_ShrV128, expr_vA, mkU8(8)), \ |
| 753 | binop(Iop_ShrV128, expr_vB, mkU8(8))) |
| 754 | |
| 755 | #define MK_Iop_MullOdd16Ux8( expr_vA, expr_vB ) \ |
| 756 | binop(Iop_MullEven16Ux8, \ |
| 757 | binop(Iop_ShrV128, expr_vA, mkU8(16)), \ |
| 758 | binop(Iop_ShrV128, expr_vB, mkU8(16))) |
| 759 | |
| 760 | #define MK_Iop_MullOdd16Sx8( expr_vA, expr_vB ) \ |
| 761 | binop(Iop_MullEven16Sx8, \ |
| 762 | binop(Iop_ShrV128, expr_vA, mkU8(16)), \ |
| 763 | binop(Iop_ShrV128, expr_vB, mkU8(16))) |
| 764 | |
cerion | 59b2c31 | 2005-12-17 11:28:53 +0000 | [diff] [blame] | 765 | static IRExpr* /* :: Ity_I64 */ mk64lo32Sto64 ( IRExpr* src ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 766 | { |
| 767 | vassert(typeOfIRExpr(irbb->tyenv, src) == Ity_I64); |
| 768 | return unop(Iop_32Sto64, unop(Iop_64to32, src)); |
| 769 | } |
| 770 | |
cerion | 59b2c31 | 2005-12-17 11:28:53 +0000 | [diff] [blame] | 771 | static IRExpr* /* :: Ity_I64 */ mk64lo32Uto64 ( IRExpr* src ) |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 772 | { |
| 773 | vassert(typeOfIRExpr(irbb->tyenv, src) == Ity_I64); |
| 774 | return unop(Iop_32Uto64, unop(Iop_64to32, src)); |
| 775 | } |
| 776 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 777 | static IROp mkSzOp ( IRType ty, IROp op8 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 778 | { |
| 779 | Int adj; |
| 780 | vassert(ty == Ity_I8 || ty == Ity_I16 || |
| 781 | ty == Ity_I32 || ty == Ity_I64); |
| 782 | vassert(op8 == Iop_Add8 || op8 == Iop_Sub8 || op8 == Iop_Mul8 || |
| 783 | op8 == Iop_Or8 || op8 == Iop_And8 || op8 == Iop_Xor8 || |
| 784 | op8 == Iop_Shl8 || op8 == Iop_Shr8 || op8 == Iop_Sar8 || |
| 785 | op8 == Iop_CmpEQ8 || op8 == Iop_CmpNE8 || |
| 786 | op8 == Iop_Not8 || op8 == Iop_Neg8 ); |
| 787 | adj = ty==Ity_I8 ? 0 : (ty==Ity_I16 ? 1 : (ty==Ity_I32 ? 2 : 3)); |
| 788 | return adj + op8; |
| 789 | } |
| 790 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 791 | /* Make sure we get valid 32 and 64bit addresses */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 792 | static Addr64 mkSzAddr ( IRType ty, Addr64 addr ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 793 | { |
| 794 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 795 | return ( ty == Ity_I64 ? |
| 796 | (Addr64)addr : |
| 797 | (Addr64)extend_s_32to64( toUInt(addr) ) ); |
| 798 | } |
| 799 | |
| 800 | /* sz, ULong -> IRExpr */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 801 | static IRExpr* mkSzImm ( IRType ty, ULong imm64 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 802 | { |
| 803 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 804 | return ty == Ity_I64 ? mkU64(imm64) : mkU32((UInt)imm64); |
| 805 | } |
| 806 | |
| 807 | /* sz, ULong -> IRConst */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 808 | static IRConst* mkSzConst ( IRType ty, ULong imm64 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 809 | { |
| 810 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 811 | return ( ty == Ity_I64 ? |
| 812 | IRConst_U64(imm64) : |
| 813 | IRConst_U32((UInt)imm64) ); |
| 814 | } |
| 815 | |
| 816 | /* Sign extend imm16 -> IRExpr* */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 817 | static IRExpr* mkSzExtendS16 ( IRType ty, UInt imm16 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 818 | { |
| 819 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 820 | return ( ty == Ity_I64 ? |
| 821 | mkU64(extend_s_16to64(imm16)) : |
| 822 | mkU32(extend_s_16to32(imm16)) ); |
| 823 | } |
| 824 | |
| 825 | /* Sign extend imm32 -> IRExpr* */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 826 | static IRExpr* mkSzExtendS32 ( IRType ty, UInt imm32 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 827 | { |
| 828 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 829 | return ( ty == Ity_I64 ? |
| 830 | mkU64(extend_s_32to64(imm32)) : |
| 831 | mkU32(imm32) ); |
| 832 | } |
| 833 | |
| 834 | /* IR narrows I32/I64 -> I8/I16/I32 */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 835 | static IRExpr* mkSzNarrow8 ( IRType ty, IRExpr* src ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 836 | { |
| 837 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 838 | return ty == Ity_I64 ? unop(Iop_64to8, src) : unop(Iop_32to8, src); |
| 839 | } |
| 840 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 841 | static IRExpr* mkSzNarrow16 ( IRType ty, IRExpr* src ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 842 | { |
| 843 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 844 | return ty == Ity_I64 ? unop(Iop_64to16, src) : unop(Iop_32to16, src); |
| 845 | } |
| 846 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 847 | static IRExpr* mkSzNarrow32 ( IRType ty, IRExpr* src ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 848 | { |
| 849 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 850 | return ty == Ity_I64 ? unop(Iop_64to32, src) : src; |
| 851 | } |
| 852 | |
| 853 | /* Signed/Unsigned IR widens I8/I16/I32 -> I32/I64 */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 854 | static IRExpr* mkSzWiden8 ( IRType ty, IRExpr* src, Bool sined ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 855 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 856 | IROp op; |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 857 | vassert(ty == Ity_I32 || ty == Ity_I64); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 858 | if (sined) op = (ty==Ity_I32) ? Iop_8Sto32 : Iop_8Sto64; |
| 859 | else op = (ty==Ity_I32) ? Iop_8Uto32 : Iop_8Uto64; |
| 860 | return unop(op, src); |
| 861 | } |
| 862 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 863 | static IRExpr* mkSzWiden16 ( IRType ty, IRExpr* src, Bool sined ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 864 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 865 | IROp op; |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 866 | vassert(ty == Ity_I32 || ty == Ity_I64); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 867 | if (sined) op = (ty==Ity_I32) ? Iop_16Sto32 : Iop_16Sto64; |
| 868 | else op = (ty==Ity_I32) ? Iop_16Uto32 : Iop_16Uto64; |
| 869 | return unop(op, src); |
| 870 | } |
| 871 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 872 | static IRExpr* mkSzWiden32 ( IRType ty, IRExpr* src, Bool sined ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 873 | { |
| 874 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 875 | if (ty == Ity_I32) |
| 876 | return src; |
| 877 | return (sined) ? unop(Iop_32Sto64, src) : unop(Iop_32Uto64, src); |
| 878 | } |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 879 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 880 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 881 | static Int integerGuestRegOffset ( UInt archreg ) |
cerion | 45b70ff | 2005-01-31 17:03:25 +0000 | [diff] [blame] | 882 | { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 883 | vassert(archreg < 32); |
| 884 | |
| 885 | // jrs: probably not necessary; only matters if we reference sub-parts |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 886 | // of the ppc registers, but that isn't the case |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 887 | // later: this might affect Altivec though? |
| 888 | vassert(host_is_bigendian); |
| 889 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 890 | switch (archreg) { |
| 891 | case 0: return offsetofPPCGuestState(guest_GPR0); |
| 892 | case 1: return offsetofPPCGuestState(guest_GPR1); |
| 893 | case 2: return offsetofPPCGuestState(guest_GPR2); |
| 894 | case 3: return offsetofPPCGuestState(guest_GPR3); |
| 895 | case 4: return offsetofPPCGuestState(guest_GPR4); |
| 896 | case 5: return offsetofPPCGuestState(guest_GPR5); |
| 897 | case 6: return offsetofPPCGuestState(guest_GPR6); |
| 898 | case 7: return offsetofPPCGuestState(guest_GPR7); |
| 899 | case 8: return offsetofPPCGuestState(guest_GPR8); |
| 900 | case 9: return offsetofPPCGuestState(guest_GPR9); |
| 901 | case 10: return offsetofPPCGuestState(guest_GPR10); |
| 902 | case 11: return offsetofPPCGuestState(guest_GPR11); |
| 903 | case 12: return offsetofPPCGuestState(guest_GPR12); |
| 904 | case 13: return offsetofPPCGuestState(guest_GPR13); |
| 905 | case 14: return offsetofPPCGuestState(guest_GPR14); |
| 906 | case 15: return offsetofPPCGuestState(guest_GPR15); |
| 907 | case 16: return offsetofPPCGuestState(guest_GPR16); |
| 908 | case 17: return offsetofPPCGuestState(guest_GPR17); |
| 909 | case 18: return offsetofPPCGuestState(guest_GPR18); |
| 910 | case 19: return offsetofPPCGuestState(guest_GPR19); |
| 911 | case 20: return offsetofPPCGuestState(guest_GPR20); |
| 912 | case 21: return offsetofPPCGuestState(guest_GPR21); |
| 913 | case 22: return offsetofPPCGuestState(guest_GPR22); |
| 914 | case 23: return offsetofPPCGuestState(guest_GPR23); |
| 915 | case 24: return offsetofPPCGuestState(guest_GPR24); |
| 916 | case 25: return offsetofPPCGuestState(guest_GPR25); |
| 917 | case 26: return offsetofPPCGuestState(guest_GPR26); |
| 918 | case 27: return offsetofPPCGuestState(guest_GPR27); |
| 919 | case 28: return offsetofPPCGuestState(guest_GPR28); |
| 920 | case 29: return offsetofPPCGuestState(guest_GPR29); |
| 921 | case 30: return offsetofPPCGuestState(guest_GPR30); |
| 922 | case 31: return offsetofPPCGuestState(guest_GPR31); |
| 923 | default: break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 924 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 925 | vpanic("integerGuestRegOffset(ppc,be)"); /*notreached*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static IRExpr* getIReg ( UInt archreg ) |
| 929 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 930 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 931 | vassert(archreg < 32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 932 | return IRExpr_Get( integerGuestRegOffset(archreg), ty ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /* Ditto, but write to a reg instead. */ |
| 936 | static void putIReg ( UInt archreg, IRExpr* e ) |
| 937 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 938 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 939 | vassert(archreg < 32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 940 | vassert(typeOfIRExpr(irbb->tyenv, e) == ty ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 941 | stmt( IRStmt_Put(integerGuestRegOffset(archreg), e) ); |
| 942 | } |
| 943 | |
| 944 | |
| 945 | static Int floatGuestRegOffset ( UInt archreg ) |
| 946 | { |
| 947 | vassert(archreg < 32); |
| 948 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 949 | switch (archreg) { |
| 950 | case 0: return offsetofPPCGuestState(guest_FPR0); |
| 951 | case 1: return offsetofPPCGuestState(guest_FPR1); |
| 952 | case 2: return offsetofPPCGuestState(guest_FPR2); |
| 953 | case 3: return offsetofPPCGuestState(guest_FPR3); |
| 954 | case 4: return offsetofPPCGuestState(guest_FPR4); |
| 955 | case 5: return offsetofPPCGuestState(guest_FPR5); |
| 956 | case 6: return offsetofPPCGuestState(guest_FPR6); |
| 957 | case 7: return offsetofPPCGuestState(guest_FPR7); |
| 958 | case 8: return offsetofPPCGuestState(guest_FPR8); |
| 959 | case 9: return offsetofPPCGuestState(guest_FPR9); |
| 960 | case 10: return offsetofPPCGuestState(guest_FPR10); |
| 961 | case 11: return offsetofPPCGuestState(guest_FPR11); |
| 962 | case 12: return offsetofPPCGuestState(guest_FPR12); |
| 963 | case 13: return offsetofPPCGuestState(guest_FPR13); |
| 964 | case 14: return offsetofPPCGuestState(guest_FPR14); |
| 965 | case 15: return offsetofPPCGuestState(guest_FPR15); |
| 966 | case 16: return offsetofPPCGuestState(guest_FPR16); |
| 967 | case 17: return offsetofPPCGuestState(guest_FPR17); |
| 968 | case 18: return offsetofPPCGuestState(guest_FPR18); |
| 969 | case 19: return offsetofPPCGuestState(guest_FPR19); |
| 970 | case 20: return offsetofPPCGuestState(guest_FPR20); |
| 971 | case 21: return offsetofPPCGuestState(guest_FPR21); |
| 972 | case 22: return offsetofPPCGuestState(guest_FPR22); |
| 973 | case 23: return offsetofPPCGuestState(guest_FPR23); |
| 974 | case 24: return offsetofPPCGuestState(guest_FPR24); |
| 975 | case 25: return offsetofPPCGuestState(guest_FPR25); |
| 976 | case 26: return offsetofPPCGuestState(guest_FPR26); |
| 977 | case 27: return offsetofPPCGuestState(guest_FPR27); |
| 978 | case 28: return offsetofPPCGuestState(guest_FPR28); |
| 979 | case 29: return offsetofPPCGuestState(guest_FPR29); |
| 980 | case 30: return offsetofPPCGuestState(guest_FPR30); |
| 981 | case 31: return offsetofPPCGuestState(guest_FPR31); |
| 982 | default: break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 983 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 984 | vpanic("floatGuestRegOffset(ppc)"); /*notreached*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | static IRExpr* getFReg ( UInt archreg ) |
| 988 | { |
| 989 | vassert(archreg < 32); |
| 990 | return IRExpr_Get( floatGuestRegOffset(archreg), Ity_F64 ); |
| 991 | } |
| 992 | |
| 993 | /* Ditto, but write to a reg instead. */ |
| 994 | static void putFReg ( UInt archreg, IRExpr* e ) |
| 995 | { |
| 996 | vassert(archreg < 32); |
| 997 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_F64); |
| 998 | stmt( IRStmt_Put(floatGuestRegOffset(archreg), e) ); |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | static Int vectorGuestRegOffset ( UInt archreg ) |
| 1003 | { |
| 1004 | vassert(archreg < 32); |
| 1005 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1006 | switch (archreg) { |
| 1007 | case 0: return offsetofPPCGuestState(guest_VR0); |
| 1008 | case 1: return offsetofPPCGuestState(guest_VR1); |
| 1009 | case 2: return offsetofPPCGuestState(guest_VR2); |
| 1010 | case 3: return offsetofPPCGuestState(guest_VR3); |
| 1011 | case 4: return offsetofPPCGuestState(guest_VR4); |
| 1012 | case 5: return offsetofPPCGuestState(guest_VR5); |
| 1013 | case 6: return offsetofPPCGuestState(guest_VR6); |
| 1014 | case 7: return offsetofPPCGuestState(guest_VR7); |
| 1015 | case 8: return offsetofPPCGuestState(guest_VR8); |
| 1016 | case 9: return offsetofPPCGuestState(guest_VR9); |
| 1017 | case 10: return offsetofPPCGuestState(guest_VR10); |
| 1018 | case 11: return offsetofPPCGuestState(guest_VR11); |
| 1019 | case 12: return offsetofPPCGuestState(guest_VR12); |
| 1020 | case 13: return offsetofPPCGuestState(guest_VR13); |
| 1021 | case 14: return offsetofPPCGuestState(guest_VR14); |
| 1022 | case 15: return offsetofPPCGuestState(guest_VR15); |
| 1023 | case 16: return offsetofPPCGuestState(guest_VR16); |
| 1024 | case 17: return offsetofPPCGuestState(guest_VR17); |
| 1025 | case 18: return offsetofPPCGuestState(guest_VR18); |
| 1026 | case 19: return offsetofPPCGuestState(guest_VR19); |
| 1027 | case 20: return offsetofPPCGuestState(guest_VR20); |
| 1028 | case 21: return offsetofPPCGuestState(guest_VR21); |
| 1029 | case 22: return offsetofPPCGuestState(guest_VR22); |
| 1030 | case 23: return offsetofPPCGuestState(guest_VR23); |
| 1031 | case 24: return offsetofPPCGuestState(guest_VR24); |
| 1032 | case 25: return offsetofPPCGuestState(guest_VR25); |
| 1033 | case 26: return offsetofPPCGuestState(guest_VR26); |
| 1034 | case 27: return offsetofPPCGuestState(guest_VR27); |
| 1035 | case 28: return offsetofPPCGuestState(guest_VR28); |
| 1036 | case 29: return offsetofPPCGuestState(guest_VR29); |
| 1037 | case 30: return offsetofPPCGuestState(guest_VR30); |
| 1038 | case 31: return offsetofPPCGuestState(guest_VR31); |
| 1039 | default: break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1040 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1041 | vpanic("vextorGuestRegOffset(ppc)"); /*notreached*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | static IRExpr* getVReg ( UInt archreg ) |
| 1045 | { |
| 1046 | vassert(archreg < 32); |
| 1047 | return IRExpr_Get( vectorGuestRegOffset(archreg), Ity_V128 ); |
| 1048 | } |
| 1049 | |
| 1050 | /* Ditto, but write to a reg instead. */ |
| 1051 | static void putVReg ( UInt archreg, IRExpr* e ) |
| 1052 | { |
| 1053 | vassert(archreg < 32); |
| 1054 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_V128); |
| 1055 | stmt( IRStmt_Put(vectorGuestRegOffset(archreg), e) ); |
| 1056 | } |
| 1057 | |
| 1058 | static Int guestCR321offset ( UInt cr ) |
| 1059 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1060 | switch (cr) { |
| 1061 | case 0: return offsetofPPCGuestState(guest_CR0_321 ); |
| 1062 | case 1: return offsetofPPCGuestState(guest_CR1_321 ); |
| 1063 | case 2: return offsetofPPCGuestState(guest_CR2_321 ); |
| 1064 | case 3: return offsetofPPCGuestState(guest_CR3_321 ); |
| 1065 | case 4: return offsetofPPCGuestState(guest_CR4_321 ); |
| 1066 | case 5: return offsetofPPCGuestState(guest_CR5_321 ); |
| 1067 | case 6: return offsetofPPCGuestState(guest_CR6_321 ); |
| 1068 | case 7: return offsetofPPCGuestState(guest_CR7_321 ); |
| 1069 | default: vpanic("guestCR321offset(ppc)"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | static Int guestCR0offset ( UInt cr ) |
| 1074 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1075 | switch (cr) { |
| 1076 | case 0: return offsetofPPCGuestState(guest_CR0_0 ); |
| 1077 | case 1: return offsetofPPCGuestState(guest_CR1_0 ); |
| 1078 | case 2: return offsetofPPCGuestState(guest_CR2_0 ); |
| 1079 | case 3: return offsetofPPCGuestState(guest_CR3_0 ); |
| 1080 | case 4: return offsetofPPCGuestState(guest_CR4_0 ); |
| 1081 | case 5: return offsetofPPCGuestState(guest_CR5_0 ); |
| 1082 | case 6: return offsetofPPCGuestState(guest_CR6_0 ); |
| 1083 | case 7: return offsetofPPCGuestState(guest_CR7_0 ); |
| 1084 | default: vpanic("guestCR3offset(ppc)"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1085 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 1088 | // ROTL(src32/64, rot_amt5/6) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1089 | static IRExpr* /* :: Ity_I32/64 */ ROTL ( IRExpr* src, |
| 1090 | IRExpr* rot_amt ) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1091 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1092 | IRExpr *mask, *rot; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1093 | vassert(typeOfIRExpr(irbb->tyenv,rot_amt) == Ity_I8); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1094 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1095 | if (typeOfIRExpr(irbb->tyenv,src) == Ity_I64) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1096 | // rot = (src << rot_amt) | (src >> (64-rot_amt)) |
| 1097 | mask = binop(Iop_And8, rot_amt, mkU8(63)); |
| 1098 | rot = binop(Iop_Or64, |
| 1099 | binop(Iop_Shl64, src, mask), |
| 1100 | binop(Iop_Shr64, src, binop(Iop_Sub8, mkU8(64), mask))); |
| 1101 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1102 | // rot = (src << rot_amt) | (src >> (32-rot_amt)) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1103 | mask = binop(Iop_And8, rot_amt, mkU8(31)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1104 | rot = binop(Iop_Or32, |
| 1105 | binop(Iop_Shl32, src, mask), |
| 1106 | binop(Iop_Shr32, src, binop(Iop_Sub8, mkU8(32), mask))); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1107 | } |
sewardj | c965953 | 2005-07-21 21:33:57 +0000 | [diff] [blame] | 1108 | /* Note: the MuxOX is not merely an optimisation; it's needed |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1109 | because otherwise the Shr is a shift by the word size when |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1110 | mask denotes zero. For rotates by immediates, a lot of |
sewardj | c965953 | 2005-07-21 21:33:57 +0000 | [diff] [blame] | 1111 | this junk gets folded out. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1112 | return IRExpr_Mux0X( mask, /* zero rotate */ src, |
| 1113 | /* non-zero rotate */ rot ); |
cerion | 45b70ff | 2005-01-31 17:03:25 +0000 | [diff] [blame] | 1114 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1115 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1116 | #if 0 |
| 1117 | /* ROTL32_64(src64, rot_amt5) |
| 1118 | Weirdo 32bit rotl on ppc64: |
| 1119 | rot32 = ROTL(src_lo32,y); |
| 1120 | return (rot32|rot32); |
| 1121 | */ |
| 1122 | static IRExpr* /* :: Ity_I64 */ ROTL32_64 ( IRExpr* src64, |
| 1123 | IRExpr* rot_amt ) |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1124 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1125 | IRExpr *mask, *rot32; |
| 1126 | vassert(mode64); // used only in 64bit mode |
| 1127 | vassert(typeOfIRExpr(irbb->tyenv,src64) == Ity_I64); |
| 1128 | vassert(typeOfIRExpr(irbb->tyenv,rot_amt) == Ity_I8); |
| 1129 | |
| 1130 | mask = binop(Iop_And8, rot_amt, mkU8(31)); |
| 1131 | rot32 = ROTL( unop(Iop_64to32, src64), rot_amt ); |
| 1132 | |
| 1133 | return binop(Iop_Or64, |
| 1134 | binop(Iop_Shl64, unop(Iop_32Uto64, rot32), mkU8(32)), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1135 | unop(Iop_32Uto64, rot32)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1136 | } |
| 1137 | #endif |
| 1138 | |
| 1139 | |
| 1140 | /* Standard effective address calc: (rA + rB) */ |
| 1141 | static IRExpr* ea_rA_idxd ( UInt rA, UInt rB ) |
| 1142 | { |
| 1143 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1144 | vassert(rA < 32); |
| 1145 | vassert(rB < 32); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1146 | return binop(mkSzOp(ty, Iop_Add8), getIReg(rA), getIReg(rB)); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1149 | /* Standard effective address calc: (rA + simm) */ |
| 1150 | static IRExpr* ea_rA_simm ( UInt rA, UInt simm16 ) |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1151 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1152 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1153 | vassert(rA < 32); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1154 | return binop(mkSzOp(ty, Iop_Add8), getIReg(rA), |
| 1155 | mkSzExtendS16(ty, simm16)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | /* Standard effective address calc: (rA|0) */ |
| 1159 | static IRExpr* ea_rAor0 ( UInt rA ) |
| 1160 | { |
| 1161 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1162 | vassert(rA < 32); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1163 | if (rA == 0) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1164 | return mkSzImm(ty, 0); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1165 | } else { |
| 1166 | return getIReg(rA); |
| 1167 | } |
| 1168 | } |
| 1169 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1170 | /* Standard effective address calc: (rA|0) + rB */ |
| 1171 | static IRExpr* ea_rAor0_idxd ( UInt rA, UInt rB ) |
| 1172 | { |
| 1173 | vassert(rA < 32); |
| 1174 | vassert(rB < 32); |
| 1175 | return (rA == 0) ? getIReg(rB) : ea_rA_idxd( rA, rB ); |
| 1176 | } |
| 1177 | |
| 1178 | /* Standard effective address calc: (rA|0) + simm16 */ |
| 1179 | static IRExpr* ea_rAor0_simm ( UInt rA, UInt simm16 ) |
| 1180 | { |
| 1181 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1182 | vassert(rA < 32); |
| 1183 | if (rA == 0) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1184 | return mkSzExtendS16(ty, simm16); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1185 | } else { |
| 1186 | return ea_rA_simm( rA, simm16 ); |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | |
| 1191 | /* Align effective address */ |
| 1192 | static IRExpr* addr_align( IRExpr* addr, UChar align ) |
| 1193 | { |
| 1194 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1195 | Long mask; |
| 1196 | switch (align) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1197 | case 1: return addr; // byte aligned |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1198 | case 2: mask = ((Long)-1) << 1; break; // half-word aligned |
| 1199 | case 4: mask = ((Long)-1) << 2; break; // word aligned |
| 1200 | case 16: mask = ((Long)-1) << 4; break; // quad-word aligned |
| 1201 | default: |
| 1202 | vex_printf("addr_align: align = %u\n", align); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1203 | vpanic("addr_align(ppc)"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | vassert(typeOfIRExpr(irbb->tyenv,addr) == ty); |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 1207 | return binop( mkSzOp(ty, Iop_And8), addr, mkSzImm(ty, mask) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1210 | |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 1211 | /* Generate AbiHints which mark points at which the ELF or PowerOpen |
| 1212 | ABIs say that the stack red zone (viz, -N(r1) .. -1(r1), for some |
| 1213 | N) becomes undefined. That is at function calls and returns. ELF |
| 1214 | ppc32 doesn't have this "feature" (how fortunate for it). |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 1215 | */ |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 1216 | static void make_redzone_AbiHint ( VexMiscInfo* vmi, HChar* who ) |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 1217 | { |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 1218 | Int szB = vmi->guest_stack_redzone_size; |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 1219 | if (0) vex_printf("AbiHint: %s\n", who); |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 1220 | vassert(szB >= 0); |
| 1221 | if (szB > 0) { |
| 1222 | if (mode64) |
| 1223 | stmt( IRStmt_AbiHint( |
| 1224 | binop(Iop_Sub64, getIReg(1), mkU64(szB)), |
| 1225 | szB |
| 1226 | )); |
| 1227 | else |
| 1228 | stmt( IRStmt_AbiHint( |
| 1229 | binop(Iop_Sub32, getIReg(1), mkU32(szB)), |
| 1230 | szB |
| 1231 | )); |
| 1232 | } |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1236 | /*------------------------------------------------------------*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1237 | /*--- Helpers for condition codes. ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1238 | /*------------------------------------------------------------*/ |
| 1239 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1240 | /* Condition register layout. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1241 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1242 | In the hardware, CR is laid out like this. The leftmost end is the |
| 1243 | most significant bit in the register; however the IBM documentation |
| 1244 | numbers the bits backwards for some reason. |
| 1245 | |
| 1246 | CR0 CR1 .......... CR6 CR7 |
| 1247 | 0 .. 3 ....................... 28 .. 31 (IBM bit numbering) |
| 1248 | 31 28 3 0 (normal bit numbering) |
| 1249 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1250 | Each CR field is 4 bits: [<,>,==,SO] |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1251 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1252 | Hence in IBM's notation, BI=0 is CR7[SO], BI=1 is CR7[==], etc. |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1253 | |
| 1254 | Indexing from BI to guest state: |
| 1255 | |
| 1256 | let n = BI / 4 |
| 1257 | off = BI % 4 |
| 1258 | this references CR n: |
| 1259 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1260 | off==0 -> guest_CRn_321 >> 3 |
| 1261 | off==1 -> guest_CRn_321 >> 2 |
| 1262 | off==2 -> guest_CRn_321 >> 1 |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1263 | off==3 -> guest_CRn_SO |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1264 | |
| 1265 | Bear in mind the only significant bit in guest_CRn_SO is bit 0 |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1266 | (normal notation) and in guest_CRn_321 the significant bits are |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1267 | 3, 2 and 1 (normal notation). |
| 1268 | */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1269 | |
| 1270 | static void putCR321 ( UInt cr, IRExpr* e ) |
| 1271 | { |
| 1272 | vassert(cr < 8); |
| 1273 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
| 1274 | stmt( IRStmt_Put(guestCR321offset(cr), e) ); |
| 1275 | } |
| 1276 | |
| 1277 | static void putCR0 ( UInt cr, IRExpr* e ) |
| 1278 | { |
| 1279 | vassert(cr < 8); |
| 1280 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
| 1281 | stmt( IRStmt_Put(guestCR0offset(cr), e) ); |
| 1282 | } |
| 1283 | |
| 1284 | static IRExpr* /* :: Ity_I8 */ getCR0 ( UInt cr ) |
| 1285 | { |
| 1286 | vassert(cr < 8); |
| 1287 | return IRExpr_Get(guestCR0offset(cr), Ity_I8); |
| 1288 | } |
| 1289 | |
| 1290 | static IRExpr* /* :: Ity_I8 */ getCR321 ( UInt cr ) |
| 1291 | { |
| 1292 | vassert(cr < 8); |
| 1293 | return IRExpr_Get(guestCR321offset(cr), Ity_I8); |
| 1294 | } |
| 1295 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1296 | /* Fetch the specified CR bit (as per IBM/hardware notation) and |
| 1297 | return it at the bottom of an I32; the top 31 bits are guaranteed |
| 1298 | to be zero. */ |
| 1299 | static IRExpr* /* :: Ity_I32 */ getCRbit ( UInt bi ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1300 | { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1301 | UInt n = bi / 4; |
| 1302 | UInt off = bi % 4; |
| 1303 | vassert(bi < 32); |
| 1304 | if (off == 3) { |
| 1305 | /* Fetch the SO bit for this CR field */ |
| 1306 | /* Note: And32 is redundant paranoia iff guest state only has 0 |
| 1307 | or 1 in that slot. */ |
| 1308 | return binop(Iop_And32, unop(Iop_8Uto32, getCR0(n)), mkU32(1)); |
| 1309 | } else { |
| 1310 | /* Fetch the <, > or == bit for this CR field */ |
| 1311 | return binop( Iop_And32, |
| 1312 | binop( Iop_Shr32, |
| 1313 | unop(Iop_8Uto32, getCR321(n)), |
sewardj | c7cd214 | 2005-09-09 22:31:49 +0000 | [diff] [blame] | 1314 | mkU8(toUChar(3-off)) ), |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1315 | mkU32(1) ); |
| 1316 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1319 | /* Dually, write the least significant bit of BIT to the specified CR |
| 1320 | bit. Indexing as per getCRbit. */ |
| 1321 | static void putCRbit ( UInt bi, IRExpr* bit ) |
| 1322 | { |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 1323 | UInt n, off; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1324 | IRExpr* safe; |
| 1325 | vassert(typeOfIRExpr(irbb->tyenv,bit) == Ity_I32); |
| 1326 | safe = binop(Iop_And32, bit, mkU32(1)); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 1327 | n = bi / 4; |
| 1328 | off = bi % 4; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1329 | vassert(bi < 32); |
| 1330 | if (off == 3) { |
| 1331 | /* This is the SO bit for this CR field */ |
| 1332 | putCR0(n, unop(Iop_32to8, safe)); |
| 1333 | } else { |
| 1334 | off = 3 - off; |
| 1335 | vassert(off == 1 || off == 2 || off == 3); |
| 1336 | putCR321( |
| 1337 | n, |
| 1338 | unop( Iop_32to8, |
| 1339 | binop( Iop_Or32, |
| 1340 | /* old value with field masked out */ |
| 1341 | binop(Iop_And32, unop(Iop_8Uto32, getCR321(n)), |
| 1342 | mkU32(~(1 << off))), |
| 1343 | /* new value in the right place */ |
sewardj | c7cd214 | 2005-09-09 22:31:49 +0000 | [diff] [blame] | 1344 | binop(Iop_Shl32, safe, mkU8(toUChar(off))) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1345 | ) |
| 1346 | ) |
| 1347 | ); |
| 1348 | } |
| 1349 | } |
| 1350 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1351 | /* Fetch the specified CR bit (as per IBM/hardware notation) and |
| 1352 | return it somewhere in an I32; it does not matter where, but |
| 1353 | whichever bit it is, all other bits are guaranteed to be zero. In |
| 1354 | other words, the I32-typed expression will be zero if the bit is |
| 1355 | zero and nonzero if the bit is 1. Write into *where the index |
| 1356 | of where the bit will be. */ |
| 1357 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1358 | static |
| 1359 | IRExpr* /* :: Ity_I32 */ getCRbit_anywhere ( UInt bi, Int* where ) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1360 | { |
| 1361 | UInt n = bi / 4; |
| 1362 | UInt off = bi % 4; |
| 1363 | vassert(bi < 32); |
| 1364 | if (off == 3) { |
| 1365 | /* Fetch the SO bit for this CR field */ |
| 1366 | /* Note: And32 is redundant paranoia iff guest state only has 0 |
| 1367 | or 1 in that slot. */ |
| 1368 | *where = 0; |
| 1369 | return binop(Iop_And32, unop(Iop_8Uto32, getCR0(n)), mkU32(1)); |
| 1370 | } else { |
| 1371 | /* Fetch the <, > or == bit for this CR field */ |
| 1372 | *where = 3-off; |
| 1373 | return binop( Iop_And32, |
| 1374 | unop(Iop_8Uto32, getCR321(n)), |
| 1375 | mkU32(1 << (3-off)) ); |
| 1376 | } |
| 1377 | } |
| 1378 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1379 | /* Set the CR0 flags following an arithmetic operation. |
| 1380 | (Condition Register CR0 Field Definition, PPC32 p60) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1381 | */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1382 | static IRExpr* getXER_SO ( void ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1383 | static void set_CR0 ( IRExpr* result ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1384 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1385 | vassert(typeOfIRExpr(irbb->tyenv,result) == Ity_I32 || |
| 1386 | typeOfIRExpr(irbb->tyenv,result) == Ity_I64); |
| 1387 | if (mode64) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1388 | putCR321( 0, unop(Iop_64to8, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1389 | binop(Iop_CmpORD64S, result, mkU64(0))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1390 | } else { |
| 1391 | putCR321( 0, unop(Iop_32to8, |
| 1392 | binop(Iop_CmpORD32S, result, mkU32(0))) ); |
| 1393 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1394 | putCR0( 0, getXER_SO() ); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1395 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1396 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1397 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1398 | /* Set the CR6 flags following an AltiVec compare operation. */ |
| 1399 | static void set_AV_CR6 ( IRExpr* result, Bool test_all_ones ) |
| 1400 | { |
| 1401 | /* CR6[0:3] = {all_ones, 0, all_zeros, 0} |
| 1402 | all_ones = (v[0] && v[1] && v[2] && v[3]) |
| 1403 | all_zeros = ~(v[0] || v[1] || v[2] || v[3]) |
| 1404 | */ |
| 1405 | IRTemp v0 = newTemp(Ity_V128); |
| 1406 | IRTemp v1 = newTemp(Ity_V128); |
| 1407 | IRTemp v2 = newTemp(Ity_V128); |
| 1408 | IRTemp v3 = newTemp(Ity_V128); |
| 1409 | IRTemp rOnes = newTemp(Ity_I8); |
| 1410 | IRTemp rZeros = newTemp(Ity_I8); |
| 1411 | |
| 1412 | vassert(typeOfIRExpr(irbb->tyenv,result) == Ity_V128); |
| 1413 | |
| 1414 | assign( v0, result ); |
| 1415 | assign( v1, binop(Iop_ShrV128, result, mkU8(32)) ); |
| 1416 | assign( v2, binop(Iop_ShrV128, result, mkU8(64)) ); |
| 1417 | assign( v3, binop(Iop_ShrV128, result, mkU8(96)) ); |
| 1418 | |
| 1419 | assign( rZeros, unop(Iop_1Uto8, |
| 1420 | binop(Iop_CmpEQ32, mkU32(0xFFFFFFFF), |
| 1421 | unop(Iop_Not32, |
| 1422 | unop(Iop_V128to32, |
| 1423 | binop(Iop_OrV128, |
| 1424 | binop(Iop_OrV128, mkexpr(v0), mkexpr(v1)), |
| 1425 | binop(Iop_OrV128, mkexpr(v2), mkexpr(v3)))) |
| 1426 | ))) ); |
| 1427 | |
| 1428 | if (test_all_ones) { |
| 1429 | assign( rOnes, unop(Iop_1Uto8, |
| 1430 | binop(Iop_CmpEQ32, mkU32(0xFFFFFFFF), |
| 1431 | unop(Iop_V128to32, |
| 1432 | binop(Iop_AndV128, |
| 1433 | binop(Iop_AndV128, mkexpr(v0), mkexpr(v1)), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1434 | binop(Iop_AndV128, mkexpr(v2), mkexpr(v3))) |
| 1435 | ))) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1436 | putCR321( 6, binop(Iop_Or8, |
| 1437 | binop(Iop_Shl8, mkexpr(rOnes), mkU8(3)), |
| 1438 | binop(Iop_Shl8, mkexpr(rZeros), mkU8(1))) ); |
| 1439 | } else { |
| 1440 | putCR321( 6, binop(Iop_Shl8, mkexpr(rZeros), mkU8(1)) ); |
| 1441 | } |
| 1442 | putCR0( 6, mkU8(0) ); |
| 1443 | } |
| 1444 | |
| 1445 | |
| 1446 | |
| 1447 | /*------------------------------------------------------------*/ |
| 1448 | /*--- Helpers for XER flags. ---*/ |
| 1449 | /*------------------------------------------------------------*/ |
| 1450 | |
| 1451 | static void putXER_SO ( IRExpr* e ) |
| 1452 | { |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 1453 | IRExpr* so; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1454 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 1455 | so = binop(Iop_And8, e, mkU8(1)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1456 | stmt( IRStmt_Put( OFFB_XER_SO, so ) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | static void putXER_OV ( IRExpr* e ) |
| 1460 | { |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 1461 | IRExpr* ov; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1462 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 1463 | ov = binop(Iop_And8, e, mkU8(1)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1464 | stmt( IRStmt_Put( OFFB_XER_OV, ov ) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | static void putXER_CA ( IRExpr* e ) |
| 1468 | { |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 1469 | IRExpr* ca; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1470 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 1471 | ca = binop(Iop_And8, e, mkU8(1)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1472 | stmt( IRStmt_Put( OFFB_XER_CA, ca ) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | static void putXER_BC ( IRExpr* e ) |
| 1476 | { |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 1477 | IRExpr* bc; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1478 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
sewardj | 6332740 | 2006-01-25 03:26:27 +0000 | [diff] [blame] | 1479 | bc = binop(Iop_And8, e, mkU8(0x7F)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1480 | stmt( IRStmt_Put( OFFB_XER_BC, bc ) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | static IRExpr* /* :: Ity_I8 */ getXER_SO ( void ) |
| 1484 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1485 | return IRExpr_Get( OFFB_XER_SO, Ity_I8 ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | static IRExpr* /* :: Ity_I32 */ getXER_SO32 ( void ) |
| 1489 | { |
| 1490 | return binop( Iop_And32, unop(Iop_8Uto32, getXER_SO()), mkU32(1) ); |
| 1491 | } |
| 1492 | |
| 1493 | static IRExpr* /* :: Ity_I8 */ getXER_OV ( void ) |
| 1494 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1495 | return IRExpr_Get( OFFB_XER_OV, Ity_I8 ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | static IRExpr* /* :: Ity_I32 */ getXER_OV32 ( void ) |
| 1499 | { |
| 1500 | return binop( Iop_And32, unop(Iop_8Uto32, getXER_OV()), mkU32(1) ); |
| 1501 | } |
| 1502 | |
| 1503 | static IRExpr* /* :: Ity_I32 */ getXER_CA32 ( void ) |
| 1504 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1505 | IRExpr* ca = IRExpr_Get( OFFB_XER_CA, Ity_I8 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1506 | return binop( Iop_And32, unop(Iop_8Uto32, ca ), mkU32(1) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | static IRExpr* /* :: Ity_I8 */ getXER_BC ( void ) |
| 1510 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1511 | return IRExpr_Get( OFFB_XER_BC, Ity_I8 ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | static IRExpr* /* :: Ity_I32 */ getXER_BC32 ( void ) |
| 1515 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1516 | IRExpr* bc = IRExpr_Get( OFFB_XER_BC, Ity_I8 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1517 | return binop( Iop_And32, unop(Iop_8Uto32, bc), mkU32(0x7F) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1521 | /* RES is the result of doing OP on ARGL and ARGR. Set %XER.OV and |
| 1522 | %XER.SO accordingly. */ |
| 1523 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1524 | static void set_XER_OV_32( UInt op, IRExpr* res, |
| 1525 | IRExpr* argL, IRExpr* argR ) |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1526 | { |
| 1527 | IRTemp t64; |
| 1528 | IRExpr* xer_ov; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1529 | vassert(op < PPCG_FLAG_OP_NUMBER); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1530 | vassert(typeOfIRExpr(irbb->tyenv,res) == Ity_I32); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1531 | vassert(typeOfIRExpr(irbb->tyenv,argL) == Ity_I32); |
| 1532 | vassert(typeOfIRExpr(irbb->tyenv,argR) == Ity_I32); |
| 1533 | |
| 1534 | # define INT32_MIN 0x80000000 |
| 1535 | |
| 1536 | # define XOR2(_aa,_bb) \ |
| 1537 | binop(Iop_Xor32,(_aa),(_bb)) |
| 1538 | |
| 1539 | # define XOR3(_cc,_dd,_ee) \ |
| 1540 | binop(Iop_Xor32,binop(Iop_Xor32,(_cc),(_dd)),(_ee)) |
| 1541 | |
| 1542 | # define AND3(_ff,_gg,_hh) \ |
| 1543 | binop(Iop_And32,binop(Iop_And32,(_ff),(_gg)),(_hh)) |
| 1544 | |
| 1545 | #define NOT(_jj) \ |
| 1546 | unop(Iop_Not32, (_jj)) |
| 1547 | |
| 1548 | switch (op) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1549 | case /* 0 */ PPCG_FLAG_OP_ADD: |
| 1550 | case /* 1 */ PPCG_FLAG_OP_ADDE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1551 | /* (argL^argR^-1) & (argL^res) & (1<<31) ?1:0 */ |
| 1552 | // i.e. ((both_same_sign) & (sign_changed) & (sign_mask)) |
| 1553 | xer_ov |
| 1554 | = AND3( XOR3(argL,argR,mkU32(-1)), |
| 1555 | XOR2(argL,res), |
| 1556 | mkU32(INT32_MIN) ); |
| 1557 | /* xer_ov can only be 0 or 1<<31 */ |
| 1558 | xer_ov |
| 1559 | = binop(Iop_Shr32, xer_ov, mkU8(31) ); |
| 1560 | break; |
| 1561 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1562 | case /* 2 */ PPCG_FLAG_OP_DIVW: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1563 | /* (argL == INT32_MIN && argR == -1) || argR == 0 */ |
| 1564 | xer_ov |
| 1565 | = mkOR1( |
| 1566 | mkAND1( |
| 1567 | binop(Iop_CmpEQ32, argL, mkU32(INT32_MIN)), |
| 1568 | binop(Iop_CmpEQ32, argR, mkU32(-1)) |
| 1569 | ), |
| 1570 | binop(Iop_CmpEQ32, argR, mkU32(0) ) |
| 1571 | ); |
| 1572 | xer_ov |
| 1573 | = unop(Iop_1Uto32, xer_ov); |
| 1574 | break; |
| 1575 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1576 | case /* 3 */ PPCG_FLAG_OP_DIVWU: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1577 | /* argR == 0 */ |
| 1578 | xer_ov |
| 1579 | = unop(Iop_1Uto32, binop(Iop_CmpEQ32, argR, mkU32(0))); |
| 1580 | break; |
| 1581 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1582 | case /* 4 */ PPCG_FLAG_OP_MULLW: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1583 | /* OV true if result can't be represented in 32 bits |
| 1584 | i.e sHi != sign extension of sLo */ |
| 1585 | t64 = newTemp(Ity_I64); |
| 1586 | assign( t64, binop(Iop_MullS32, argL, argR) ); |
| 1587 | xer_ov |
| 1588 | = binop( Iop_CmpNE32, |
| 1589 | unop(Iop_64HIto32, mkexpr(t64)), |
| 1590 | binop( Iop_Sar32, |
| 1591 | unop(Iop_64to32, mkexpr(t64)), |
| 1592 | mkU8(31)) |
| 1593 | ); |
| 1594 | xer_ov |
| 1595 | = unop(Iop_1Uto32, xer_ov); |
| 1596 | break; |
| 1597 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1598 | case /* 5 */ PPCG_FLAG_OP_NEG: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1599 | /* argL == INT32_MIN */ |
| 1600 | xer_ov |
| 1601 | = unop( Iop_1Uto32, |
| 1602 | binop(Iop_CmpEQ32, argL, mkU32(INT32_MIN)) ); |
| 1603 | break; |
| 1604 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1605 | case /* 6 */ PPCG_FLAG_OP_SUBF: |
| 1606 | case /* 7 */ PPCG_FLAG_OP_SUBFC: |
| 1607 | case /* 8 */ PPCG_FLAG_OP_SUBFE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1608 | /* ((~argL)^argR^-1) & ((~argL)^res) & (1<<31) ?1:0; */ |
| 1609 | xer_ov |
| 1610 | = AND3( XOR3(NOT(argL),argR,mkU32(-1)), |
| 1611 | XOR2(NOT(argL),res), |
| 1612 | mkU32(INT32_MIN) ); |
| 1613 | /* xer_ov can only be 0 or 1<<31 */ |
| 1614 | xer_ov |
| 1615 | = binop(Iop_Shr32, xer_ov, mkU8(31) ); |
| 1616 | break; |
| 1617 | |
| 1618 | default: |
| 1619 | vex_printf("set_XER_OV: op = %u\n", op); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1620 | vpanic("set_XER_OV(ppc)"); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1621 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1622 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1623 | /* xer_ov MUST denote either 0 or 1, no other value allowed */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1624 | putXER_OV( unop(Iop_32to8, xer_ov) ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1625 | |
| 1626 | /* Update the summary overflow */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1627 | putXER_SO( binop(Iop_Or8, getXER_SO(), getXER_OV()) ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1628 | |
| 1629 | # undef INT32_MIN |
| 1630 | # undef AND3 |
| 1631 | # undef XOR3 |
| 1632 | # undef XOR2 |
| 1633 | # undef NOT |
| 1634 | } |
| 1635 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1636 | static void set_XER_OV_64( UInt op, IRExpr* res, |
| 1637 | IRExpr* argL, IRExpr* argR ) |
| 1638 | { |
| 1639 | IRExpr* xer_ov; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1640 | vassert(op < PPCG_FLAG_OP_NUMBER); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1641 | vassert(typeOfIRExpr(irbb->tyenv,res) == Ity_I64); |
| 1642 | vassert(typeOfIRExpr(irbb->tyenv,argL) == Ity_I64); |
| 1643 | vassert(typeOfIRExpr(irbb->tyenv,argR) == Ity_I64); |
| 1644 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1645 | # define INT64_MIN 0x8000000000000000ULL |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1646 | |
| 1647 | # define XOR2(_aa,_bb) \ |
| 1648 | binop(Iop_Xor64,(_aa),(_bb)) |
| 1649 | |
| 1650 | # define XOR3(_cc,_dd,_ee) \ |
| 1651 | binop(Iop_Xor64,binop(Iop_Xor64,(_cc),(_dd)),(_ee)) |
| 1652 | |
| 1653 | # define AND3(_ff,_gg,_hh) \ |
| 1654 | binop(Iop_And64,binop(Iop_And64,(_ff),(_gg)),(_hh)) |
| 1655 | |
| 1656 | #define NOT(_jj) \ |
| 1657 | unop(Iop_Not64, (_jj)) |
| 1658 | |
| 1659 | switch (op) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1660 | case /* 0 */ PPCG_FLAG_OP_ADD: |
| 1661 | case /* 1 */ PPCG_FLAG_OP_ADDE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1662 | /* (argL^argR^-1) & (argL^res) & (1<<63) ? 1:0 */ |
| 1663 | // i.e. ((both_same_sign) & (sign_changed) & (sign_mask)) |
| 1664 | xer_ov |
| 1665 | = AND3( XOR3(argL,argR,mkU64(-1)), |
| 1666 | XOR2(argL,res), |
| 1667 | mkU64(INT64_MIN) ); |
| 1668 | /* xer_ov can only be 0 or 1<<63 */ |
| 1669 | xer_ov |
| 1670 | = unop(Iop_64to1, binop(Iop_Shr64, xer_ov, mkU8(63))); |
| 1671 | break; |
| 1672 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1673 | case /* 2 */ PPCG_FLAG_OP_DIVW: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1674 | /* (argL == INT64_MIN && argR == -1) || argR == 0 */ |
| 1675 | xer_ov |
| 1676 | = mkOR1( |
| 1677 | mkAND1( |
| 1678 | binop(Iop_CmpEQ64, argL, mkU64(INT64_MIN)), |
| 1679 | binop(Iop_CmpEQ64, argR, mkU64(-1)) |
| 1680 | ), |
| 1681 | binop(Iop_CmpEQ64, argR, mkU64(0) ) |
| 1682 | ); |
| 1683 | break; |
| 1684 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1685 | case /* 3 */ PPCG_FLAG_OP_DIVWU: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1686 | /* argR == 0 */ |
| 1687 | xer_ov |
| 1688 | = binop(Iop_CmpEQ64, argR, mkU64(0)); |
| 1689 | break; |
| 1690 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1691 | case /* 4 */ PPCG_FLAG_OP_MULLW: { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1692 | /* OV true if result can't be represented in 64 bits |
| 1693 | i.e sHi != sign extension of sLo */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1694 | xer_ov |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 1695 | = binop( Iop_CmpNE32, |
| 1696 | unop(Iop_64HIto32, res), |
| 1697 | binop( Iop_Sar32, |
| 1698 | unop(Iop_64to32, res), |
| 1699 | mkU8(31)) |
| 1700 | ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1701 | break; |
| 1702 | } |
| 1703 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1704 | case /* 5 */ PPCG_FLAG_OP_NEG: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1705 | /* argL == INT64_MIN */ |
| 1706 | xer_ov |
| 1707 | = binop(Iop_CmpEQ64, argL, mkU64(INT64_MIN)); |
| 1708 | break; |
| 1709 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1710 | case /* 6 */ PPCG_FLAG_OP_SUBF: |
| 1711 | case /* 7 */ PPCG_FLAG_OP_SUBFC: |
| 1712 | case /* 8 */ PPCG_FLAG_OP_SUBFE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1713 | /* ((~argL)^argR^-1) & ((~argL)^res) & (1<<63) ?1:0; */ |
| 1714 | xer_ov |
| 1715 | = AND3( XOR3(NOT(argL),argR,mkU64(-1)), |
| 1716 | XOR2(NOT(argL),res), |
| 1717 | mkU64(INT64_MIN) ); |
| 1718 | /* xer_ov can only be 0 or 1<<63 */ |
| 1719 | xer_ov |
| 1720 | = unop(Iop_64to1, binop(Iop_Shr64, xer_ov, mkU8(63))); |
| 1721 | break; |
| 1722 | |
| 1723 | default: |
| 1724 | vex_printf("set_XER_OV: op = %u\n", op); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1725 | vpanic("set_XER_OV(ppc64)"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | /* xer_ov MUST denote either 0 or 1, no other value allowed */ |
| 1729 | putXER_OV( unop(Iop_1Uto8, xer_ov) ); |
| 1730 | |
| 1731 | /* Update the summary overflow */ |
| 1732 | putXER_SO( binop(Iop_Or8, getXER_SO(), getXER_OV()) ); |
| 1733 | |
| 1734 | # undef INT64_MIN |
| 1735 | # undef AND3 |
| 1736 | # undef XOR3 |
| 1737 | # undef XOR2 |
| 1738 | # undef NOT |
| 1739 | } |
| 1740 | |
| 1741 | static void set_XER_OV ( IRType ty, UInt op, IRExpr* res, |
| 1742 | IRExpr* argL, IRExpr* argR ) |
| 1743 | { |
| 1744 | if (ty == Ity_I32) |
| 1745 | set_XER_OV_32( op, res, argL, argR ); |
| 1746 | else |
| 1747 | set_XER_OV_64( op, res, argL, argR ); |
| 1748 | } |
| 1749 | |
| 1750 | |
| 1751 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1752 | /* RES is the result of doing OP on ARGL and ARGR with the old %XER.CA |
| 1753 | value being OLDCA. Set %XER.CA accordingly. */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 1754 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1755 | static void set_XER_CA_32 ( UInt op, IRExpr* res, |
| 1756 | IRExpr* argL, IRExpr* argR, IRExpr* oldca ) |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 1757 | { |
sewardj | 9a036bf | 2005-03-14 18:19:08 +0000 | [diff] [blame] | 1758 | IRExpr* xer_ca; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1759 | vassert(op < PPCG_FLAG_OP_NUMBER); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1760 | vassert(typeOfIRExpr(irbb->tyenv,res) == Ity_I32); |
| 1761 | vassert(typeOfIRExpr(irbb->tyenv,argL) == Ity_I32); |
| 1762 | vassert(typeOfIRExpr(irbb->tyenv,argR) == Ity_I32); |
| 1763 | vassert(typeOfIRExpr(irbb->tyenv,oldca) == Ity_I32); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 1764 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1765 | /* Incoming oldca is assumed to hold the values 0 or 1 only. This |
| 1766 | seems reasonable given that it's always generated by |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1767 | getXER_CA32(), which masks it accordingly. In any case it being |
cerion | 7594920 | 2005-12-24 13:14:11 +0000 | [diff] [blame] | 1768 | 0 or 1 is an invariant of the ppc guest state representation; |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1769 | if it has any other value, that invariant has been violated. */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 1770 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1771 | switch (op) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1772 | case /* 0 */ PPCG_FLAG_OP_ADD: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1773 | /* res <u argL */ |
| 1774 | xer_ca |
| 1775 | = unop(Iop_1Uto32, binop(Iop_CmpLT32U, res, argL)); |
| 1776 | break; |
| 1777 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1778 | case /* 1 */ PPCG_FLAG_OP_ADDE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1779 | /* res <u argL || (old_ca==1 && res==argL) */ |
| 1780 | xer_ca |
| 1781 | = mkOR1( |
| 1782 | binop(Iop_CmpLT32U, res, argL), |
| 1783 | mkAND1( |
| 1784 | binop(Iop_CmpEQ32, oldca, mkU32(1)), |
| 1785 | binop(Iop_CmpEQ32, res, argL) |
| 1786 | ) |
| 1787 | ); |
| 1788 | xer_ca |
| 1789 | = unop(Iop_1Uto32, xer_ca); |
| 1790 | break; |
| 1791 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1792 | case /* 8 */ PPCG_FLAG_OP_SUBFE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1793 | /* res <u argR || (old_ca==1 && res==argR) */ |
| 1794 | xer_ca |
| 1795 | = mkOR1( |
| 1796 | binop(Iop_CmpLT32U, res, argR), |
| 1797 | mkAND1( |
| 1798 | binop(Iop_CmpEQ32, oldca, mkU32(1)), |
| 1799 | binop(Iop_CmpEQ32, res, argR) |
| 1800 | ) |
| 1801 | ); |
| 1802 | xer_ca |
| 1803 | = unop(Iop_1Uto32, xer_ca); |
| 1804 | break; |
| 1805 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1806 | case /* 7 */ PPCG_FLAG_OP_SUBFC: |
| 1807 | case /* 9 */ PPCG_FLAG_OP_SUBFI: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1808 | /* res <=u argR */ |
| 1809 | xer_ca |
| 1810 | = unop(Iop_1Uto32, binop(Iop_CmpLE32U, res, argR)); |
| 1811 | break; |
| 1812 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1813 | case /* 10 */ PPCG_FLAG_OP_SRAW: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1814 | /* The shift amount is guaranteed to be in 0 .. 63 inclusive. |
| 1815 | If it is <= 31, behave like SRAWI; else XER.CA is the sign |
| 1816 | bit of argL. */ |
| 1817 | /* This term valid for shift amount < 32 only */ |
| 1818 | xer_ca |
| 1819 | = binop( |
| 1820 | Iop_And32, |
| 1821 | binop(Iop_Sar32, argL, mkU8(31)), |
| 1822 | binop( Iop_And32, |
| 1823 | argL, |
| 1824 | binop( Iop_Sub32, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1825 | binop(Iop_Shl32, mkU32(1), |
| 1826 | unop(Iop_32to8,argR)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1827 | mkU32(1) ) |
| 1828 | ) |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1829 | ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1830 | xer_ca |
| 1831 | = IRExpr_Mux0X( |
| 1832 | /* shift amt > 31 ? */ |
| 1833 | unop(Iop_1Uto8, binop(Iop_CmpLT32U, mkU32(31), argR)), |
| 1834 | /* no -- be like srawi */ |
| 1835 | unop(Iop_1Uto32, binop(Iop_CmpNE32, xer_ca, mkU32(0))), |
| 1836 | /* yes -- get sign bit of argL */ |
| 1837 | binop(Iop_Shr32, argL, mkU8(31)) |
| 1838 | ); |
| 1839 | break; |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1840 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1841 | case /* 11 */ PPCG_FLAG_OP_SRAWI: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1842 | /* xer_ca is 1 iff src was negative and bits_shifted_out != |
| 1843 | 0. Since the shift amount is known to be in the range |
| 1844 | 0 .. 31 inclusive the following seems viable: |
| 1845 | xer.ca == 1 iff the following is nonzero: |
| 1846 | (argL >>s 31) -- either all 0s or all 1s |
| 1847 | & (argL & (1<<argR)-1) -- the stuff shifted out */ |
| 1848 | xer_ca |
| 1849 | = binop( |
| 1850 | Iop_And32, |
| 1851 | binop(Iop_Sar32, argL, mkU8(31)), |
| 1852 | binop( Iop_And32, |
| 1853 | argL, |
| 1854 | binop( Iop_Sub32, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1855 | binop(Iop_Shl32, mkU32(1), |
| 1856 | unop(Iop_32to8,argR)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1857 | mkU32(1) ) |
| 1858 | ) |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1859 | ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1860 | xer_ca |
| 1861 | = unop(Iop_1Uto32, binop(Iop_CmpNE32, xer_ca, mkU32(0))); |
| 1862 | break; |
| 1863 | |
| 1864 | default: |
| 1865 | vex_printf("set_XER_CA: op = %u\n", op); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1866 | vpanic("set_XER_CA(ppc)"); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | /* xer_ca MUST denote either 0 or 1, no other value allowed */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1870 | putXER_CA( unop(Iop_32to8, xer_ca) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1873 | static void set_XER_CA_64 ( UInt op, IRExpr* res, |
| 1874 | IRExpr* argL, IRExpr* argR, IRExpr* oldca ) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 1875 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1876 | IRExpr* xer_ca; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1877 | vassert(op < PPCG_FLAG_OP_NUMBER); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1878 | vassert(typeOfIRExpr(irbb->tyenv,res) == Ity_I64); |
| 1879 | vassert(typeOfIRExpr(irbb->tyenv,argL) == Ity_I64); |
| 1880 | vassert(typeOfIRExpr(irbb->tyenv,argR) == Ity_I64); |
| 1881 | vassert(typeOfIRExpr(irbb->tyenv,oldca) == Ity_I64); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 1882 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1883 | /* Incoming oldca is assumed to hold the values 0 or 1 only. This |
| 1884 | seems reasonable given that it's always generated by |
| 1885 | getXER_CA32(), which masks it accordingly. In any case it being |
cerion | 7594920 | 2005-12-24 13:14:11 +0000 | [diff] [blame] | 1886 | 0 or 1 is an invariant of the ppc guest state representation; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1887 | if it has any other value, that invariant has been violated. */ |
| 1888 | |
| 1889 | switch (op) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1890 | case /* 0 */ PPCG_FLAG_OP_ADD: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1891 | /* res <u argL */ |
| 1892 | xer_ca |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1893 | = unop(Iop_1Uto32, binop(Iop_CmpLT64U, res, argL)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1894 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 1895 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1896 | case /* 1 */ PPCG_FLAG_OP_ADDE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1897 | /* res <u argL || (old_ca==1 && res==argL) */ |
| 1898 | xer_ca |
| 1899 | = mkOR1( |
| 1900 | binop(Iop_CmpLT64U, res, argL), |
| 1901 | mkAND1( |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1902 | binop(Iop_CmpEQ64, oldca, mkU64(1)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1903 | binop(Iop_CmpEQ64, res, argL) |
| 1904 | ) |
| 1905 | ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1906 | xer_ca |
| 1907 | = unop(Iop_1Uto32, xer_ca); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1908 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1909 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1910 | case /* 8 */ PPCG_FLAG_OP_SUBFE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1911 | /* res <u argR || (old_ca==1 && res==argR) */ |
| 1912 | xer_ca |
| 1913 | = mkOR1( |
| 1914 | binop(Iop_CmpLT64U, res, argR), |
| 1915 | mkAND1( |
| 1916 | binop(Iop_CmpEQ64, oldca, mkU64(1)), |
| 1917 | binop(Iop_CmpEQ64, res, argR) |
| 1918 | ) |
| 1919 | ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1920 | xer_ca |
| 1921 | = unop(Iop_1Uto32, xer_ca); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1922 | break; |
| 1923 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1924 | case /* 7 */ PPCG_FLAG_OP_SUBFC: |
| 1925 | case /* 9 */ PPCG_FLAG_OP_SUBFI: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1926 | /* res <=u argR */ |
| 1927 | xer_ca |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1928 | = unop(Iop_1Uto32, binop(Iop_CmpLE64U, res, argR)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | |
| 1931 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1932 | case /* 10 */ PPCG_FLAG_OP_SRAW: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1933 | /* The shift amount is guaranteed to be in 0 .. 31 inclusive. |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1934 | If it is <= 31, behave like SRAWI; else XER.CA is the sign |
| 1935 | bit of argL. */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1936 | /* This term valid for shift amount < 31 only */ |
| 1937 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1938 | xer_ca |
| 1939 | = binop( |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1940 | Iop_And64, |
| 1941 | binop(Iop_Sar64, argL, mkU8(31)), |
| 1942 | binop( Iop_And64, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1943 | argL, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1944 | binop( Iop_Sub64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1945 | binop(Iop_Shl64, mkU64(1), |
| 1946 | unop(Iop_64to8,argR)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1947 | mkU64(1) ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1948 | ) |
| 1949 | ); |
| 1950 | xer_ca |
| 1951 | = IRExpr_Mux0X( |
| 1952 | /* shift amt > 31 ? */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1953 | unop(Iop_1Uto8, binop(Iop_CmpLT64U, mkU64(31), argR)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1954 | /* no -- be like srawi */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1955 | unop(Iop_1Uto32, binop(Iop_CmpNE64, xer_ca, mkU64(0))), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1956 | /* yes -- get sign bit of argL */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1957 | unop(Iop_64to32, binop(Iop_Shr64, argL, mkU8(63))) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1958 | ); |
| 1959 | break; |
| 1960 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1961 | case /* 11 */ PPCG_FLAG_OP_SRAWI: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1962 | /* xer_ca is 1 iff src was negative and bits_shifted_out != 0. |
| 1963 | Since the shift amount is known to be in the range 0 .. 31 |
| 1964 | inclusive the following seems viable: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1965 | xer.ca == 1 iff the following is nonzero: |
| 1966 | (argL >>s 31) -- either all 0s or all 1s |
| 1967 | & (argL & (1<<argR)-1) -- the stuff shifted out */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1968 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1969 | xer_ca |
| 1970 | = binop( |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1971 | Iop_And64, |
| 1972 | binop(Iop_Sar64, argL, mkU8(31)), |
| 1973 | binop( Iop_And64, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1974 | argL, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1975 | binop( Iop_Sub64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1976 | binop(Iop_Shl64, mkU64(1), |
| 1977 | unop(Iop_64to8,argR)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1978 | mkU64(1) ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1979 | ) |
| 1980 | ); |
| 1981 | xer_ca |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1982 | = unop(Iop_1Uto32, binop(Iop_CmpNE64, xer_ca, mkU64(0))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1983 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1984 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1985 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1986 | case /* 12 */ PPCG_FLAG_OP_SRAD: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1987 | /* The shift amount is guaranteed to be in 0 .. 63 inclusive. |
| 1988 | If it is <= 63, behave like SRADI; else XER.CA is the sign |
| 1989 | bit of argL. */ |
| 1990 | /* This term valid for shift amount < 63 only */ |
| 1991 | |
| 1992 | xer_ca |
| 1993 | = binop( |
| 1994 | Iop_And64, |
| 1995 | binop(Iop_Sar64, argL, mkU8(63)), |
| 1996 | binop( Iop_And64, |
| 1997 | argL, |
| 1998 | binop( Iop_Sub64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1999 | binop(Iop_Shl64, mkU64(1), |
| 2000 | unop(Iop_64to8,argR)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2001 | mkU64(1) ) |
| 2002 | ) |
| 2003 | ); |
| 2004 | xer_ca |
| 2005 | = IRExpr_Mux0X( |
| 2006 | /* shift amt > 63 ? */ |
| 2007 | unop(Iop_1Uto8, binop(Iop_CmpLT64U, mkU64(63), argR)), |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2008 | /* no -- be like sradi */ |
| 2009 | unop(Iop_1Uto32, binop(Iop_CmpNE64, xer_ca, mkU64(0))), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2010 | /* yes -- get sign bit of argL */ |
| 2011 | unop(Iop_64to32, binop(Iop_Shr64, argL, mkU8(63))) |
| 2012 | ); |
| 2013 | break; |
| 2014 | |
| 2015 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2016 | case /* 13 */ PPCG_FLAG_OP_SRADI: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2017 | /* xer_ca is 1 iff src was negative and bits_shifted_out != 0. |
| 2018 | Since the shift amount is known to be in the range 0 .. 63 |
| 2019 | inclusive, the following seems viable: |
| 2020 | xer.ca == 1 iff the following is nonzero: |
| 2021 | (argL >>s 63) -- either all 0s or all 1s |
| 2022 | & (argL & (1<<argR)-1) -- the stuff shifted out */ |
| 2023 | |
| 2024 | xer_ca |
| 2025 | = binop( |
| 2026 | Iop_And64, |
| 2027 | binop(Iop_Sar64, argL, mkU8(63)), |
| 2028 | binop( Iop_And64, |
| 2029 | argL, |
| 2030 | binop( Iop_Sub64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2031 | binop(Iop_Shl64, mkU64(1), |
| 2032 | unop(Iop_64to8,argR)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2033 | mkU64(1) ) |
| 2034 | ) |
| 2035 | ); |
| 2036 | xer_ca |
| 2037 | = unop(Iop_1Uto32, binop(Iop_CmpNE64, xer_ca, mkU64(0))); |
| 2038 | break; |
| 2039 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2040 | default: |
| 2041 | vex_printf("set_XER_CA: op = %u\n", op); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2042 | vpanic("set_XER_CA(ppc64)"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2045 | /* xer_ca MUST denote either 0 or 1, no other value allowed */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2046 | putXER_CA( unop(Iop_32to8, xer_ca) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2049 | static void set_XER_CA ( IRType ty, UInt op, IRExpr* res, |
| 2050 | IRExpr* argL, IRExpr* argR, IRExpr* oldca ) |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2051 | { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2052 | if (ty == Ity_I32) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2053 | set_XER_CA_32( op, res, argL, argR, oldca ); |
| 2054 | else |
| 2055 | set_XER_CA_64( op, res, argL, argR, oldca ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2058 | |
| 2059 | |
| 2060 | /*------------------------------------------------------------*/ |
| 2061 | /*--- Read/write to guest-state --- */ |
| 2062 | /*------------------------------------------------------------*/ |
| 2063 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2064 | static IRExpr* /* :: Ity_I32/64 */ getGST ( PPC_GST reg ) |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2065 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2066 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2067 | switch (reg) { |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 2068 | case PPC_GST_SPRG3_RO: |
| 2069 | return IRExpr_Get( OFFB_SPRG3_RO, ty ); |
| 2070 | |
| 2071 | case PPC_GST_CIA: |
| 2072 | return IRExpr_Get( OFFB_CIA, ty ); |
| 2073 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2074 | case PPC_GST_LR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2075 | return IRExpr_Get( OFFB_LR, ty ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2076 | |
| 2077 | case PPC_GST_CTR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2078 | return IRExpr_Get( OFFB_CTR, ty ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2079 | |
| 2080 | case PPC_GST_VRSAVE: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2081 | return IRExpr_Get( OFFB_VRSAVE, Ity_I32 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2082 | |
| 2083 | case PPC_GST_VSCR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2084 | return binop(Iop_And32, IRExpr_Get( OFFB_VSCR,Ity_I32 ), |
| 2085 | mkU32(MASK_VSCR_VALID)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2086 | |
| 2087 | case PPC_GST_CR: { |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2088 | /* Synthesise the entire CR into a single word. Expensive. */ |
| 2089 | # define FIELD(_n) \ |
| 2090 | binop(Iop_Shl32, \ |
| 2091 | unop(Iop_8Uto32, \ |
| 2092 | binop(Iop_Or8, \ |
| 2093 | binop(Iop_And8, getCR321(_n), mkU8(7<<1)), \ |
| 2094 | binop(Iop_And8, getCR0(_n), mkU8(1)) \ |
| 2095 | ) \ |
| 2096 | ), \ |
| 2097 | mkU8(4 * (7-(_n))) \ |
| 2098 | ) |
| 2099 | return binop(Iop_Or32, |
| 2100 | binop(Iop_Or32, |
| 2101 | binop(Iop_Or32, FIELD(0), FIELD(1)), |
| 2102 | binop(Iop_Or32, FIELD(2), FIELD(3)) |
| 2103 | ), |
| 2104 | binop(Iop_Or32, |
| 2105 | binop(Iop_Or32, FIELD(4), FIELD(5)), |
| 2106 | binop(Iop_Or32, FIELD(6), FIELD(7)) |
| 2107 | ) |
| 2108 | ); |
| 2109 | # undef FIELD |
| 2110 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2111 | |
| 2112 | case PPC_GST_XER: |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2113 | return binop(Iop_Or32, |
| 2114 | binop(Iop_Or32, |
| 2115 | binop( Iop_Shl32, getXER_SO32(), mkU8(31)), |
| 2116 | binop( Iop_Shl32, getXER_OV32(), mkU8(30))), |
| 2117 | binop(Iop_Or32, |
| 2118 | binop( Iop_Shl32, getXER_CA32(), mkU8(29)), |
| 2119 | getXER_BC32())); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2120 | |
| 2121 | case PPC_GST_RESVN: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2122 | return IRExpr_Get( OFFB_RESVN, ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2123 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2124 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2125 | vex_printf("getGST(ppc): reg = %u", reg); |
| 2126 | vpanic("getGST(ppc)"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | /* Get a masked word from the given reg */ |
| 2131 | static IRExpr* /* ::Ity_I32 */ getGST_masked ( PPC_GST reg, UInt mask ) |
| 2132 | { |
| 2133 | IRTemp val = newTemp(Ity_I32); |
| 2134 | vassert( reg < PPC_GST_MAX ); |
| 2135 | |
| 2136 | switch (reg) { |
| 2137 | |
| 2138 | case PPC_GST_FPSCR: { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2139 | /* Vex-generated code expects the FPSCR to be set as follows: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2140 | all exceptions masked, round-to-nearest. |
| 2141 | This corresponds to a FPSCR value of 0x0. */ |
| 2142 | |
| 2143 | /* We're only keeping track of the rounding mode, |
| 2144 | so if the mask isn't asking for this, just return 0x0 */ |
| 2145 | if (mask & 0x3) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2146 | assign( val, IRExpr_Get( OFFB_FPROUND, Ity_I32 ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2147 | } else { |
| 2148 | assign( val, mkU32(0x0) ); |
| 2149 | } |
| 2150 | break; |
| 2151 | } |
| 2152 | |
| 2153 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2154 | vex_printf("getGST_masked(ppc): reg = %u", reg); |
| 2155 | vpanic("getGST_masked(ppc)"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | if (mask != 0xFFFFFFFF) { |
| 2159 | return binop(Iop_And32, mkexpr(val), mkU32(mask)); |
| 2160 | } else { |
| 2161 | return mkexpr(val); |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | /* Fetch the specified REG[FLD] nibble (as per IBM/hardware notation) |
| 2166 | and return it at the bottom of an I32; the top 27 bits are |
| 2167 | guaranteed to be zero. */ |
| 2168 | static IRExpr* /* ::Ity_I32 */ getGST_field ( PPC_GST reg, UInt fld ) |
| 2169 | { |
| 2170 | UInt shft, mask; |
| 2171 | |
| 2172 | vassert( fld < 8 ); |
| 2173 | vassert( reg < PPC_GST_MAX ); |
| 2174 | |
| 2175 | shft = 4*(7-fld); |
| 2176 | mask = 0xF<<shft; |
| 2177 | |
| 2178 | switch (reg) { |
| 2179 | case PPC_GST_XER: |
| 2180 | vassert(fld ==7); |
| 2181 | return binop(Iop_Or32, |
| 2182 | binop(Iop_Or32, |
| 2183 | binop(Iop_Shl32, getXER_SO32(), mkU8(3)), |
| 2184 | binop(Iop_Shl32, getXER_OV32(), mkU8(2))), |
| 2185 | binop( Iop_Shl32, getXER_CA32(), mkU8(1))); |
| 2186 | break; |
| 2187 | |
| 2188 | default: |
| 2189 | if (shft == 0) |
| 2190 | return getGST_masked( reg, mask ); |
| 2191 | else |
| 2192 | return binop(Iop_Shr32, |
| 2193 | getGST_masked( reg, mask ), |
| 2194 | mkU8(toUChar( shft ))); |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | static void putGST ( PPC_GST reg, IRExpr* src ) |
| 2199 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2200 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 2201 | IRType ty_src = typeOfIRExpr(irbb->tyenv,src ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2202 | vassert( reg < PPC_GST_MAX ); |
| 2203 | switch (reg) { |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 2204 | case PPC_GST_CIA_AT_SC: |
| 2205 | vassert( ty_src == ty ); |
| 2206 | stmt( IRStmt_Put( OFFB_CIA_AT_SC, src ) ); |
| 2207 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2208 | case PPC_GST_CIA: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2209 | vassert( ty_src == ty ); |
| 2210 | stmt( IRStmt_Put( OFFB_CIA, src ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2211 | break; |
| 2212 | case PPC_GST_LR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2213 | vassert( ty_src == ty ); |
| 2214 | stmt( IRStmt_Put( OFFB_LR, src ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2215 | break; |
| 2216 | case PPC_GST_CTR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2217 | vassert( ty_src == ty ); |
| 2218 | stmt( IRStmt_Put( OFFB_CTR, src ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2219 | break; |
| 2220 | case PPC_GST_VRSAVE: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2221 | vassert( ty_src == Ity_I32 ); |
| 2222 | stmt( IRStmt_Put( OFFB_VRSAVE,src)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2223 | break; |
| 2224 | case PPC_GST_VSCR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2225 | vassert( ty_src == Ity_I32 ); |
| 2226 | stmt( IRStmt_Put( OFFB_VSCR, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2227 | binop(Iop_And32, src, |
| 2228 | mkU32(MASK_VSCR_VALID)) ) ); |
| 2229 | break; |
| 2230 | case PPC_GST_XER: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2231 | vassert( ty_src == Ity_I32 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2232 | putXER_SO( unop(Iop_32to8, binop(Iop_Shr32, src, mkU8(31))) ); |
| 2233 | putXER_OV( unop(Iop_32to8, binop(Iop_Shr32, src, mkU8(30))) ); |
| 2234 | putXER_CA( unop(Iop_32to8, binop(Iop_Shr32, src, mkU8(29))) ); |
| 2235 | putXER_BC( unop(Iop_32to8, src) ); |
| 2236 | break; |
| 2237 | |
| 2238 | case PPC_GST_EMWARN: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2239 | vassert( ty_src == Ity_I32 ); |
| 2240 | stmt( IRStmt_Put( OFFB_EMWARN,src) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2241 | break; |
| 2242 | |
| 2243 | case PPC_GST_TISTART: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2244 | vassert( ty_src == ty ); |
| 2245 | stmt( IRStmt_Put( OFFB_TISTART, src) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2246 | break; |
| 2247 | |
| 2248 | case PPC_GST_TILEN: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2249 | vassert( ty_src == ty ); |
| 2250 | stmt( IRStmt_Put( OFFB_TILEN, src) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2251 | break; |
| 2252 | |
| 2253 | case PPC_GST_RESVN: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2254 | vassert( ty_src == ty ); |
| 2255 | stmt( IRStmt_Put( OFFB_RESVN, src) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2256 | break; |
| 2257 | |
| 2258 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2259 | vex_printf("putGST(ppc): reg = %u", reg); |
| 2260 | vpanic("putGST(ppc)"); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2261 | } |
| 2262 | } |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2263 | |
| 2264 | /* Write masked src to the given reg */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2265 | static void putGST_masked ( PPC_GST reg, IRExpr* src, UInt mask ) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2266 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2267 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 2268 | vassert( reg < PPC_GST_MAX ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2269 | vassert( typeOfIRExpr(irbb->tyenv,src ) == Ity_I32 ); |
| 2270 | |
| 2271 | switch (reg) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2272 | case PPC_GST_FPSCR: { |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2273 | /* Allow writes to Rounding Mode */ |
| 2274 | if (mask & 0x3) { |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 2275 | /* construct new fpround from new and old values as per mask: |
| 2276 | new fpround = (src & (3 & mask)) | (fpround & (3 & ~mask)) */ |
| 2277 | stmt( |
| 2278 | IRStmt_Put( |
| 2279 | OFFB_FPROUND, |
| 2280 | binop( |
| 2281 | Iop_Or32, |
| 2282 | binop(Iop_And32, src, mkU32(3 & mask)), |
| 2283 | binop( |
| 2284 | Iop_And32, |
| 2285 | IRExpr_Get(OFFB_FPROUND,Ity_I32), |
| 2286 | mkU32(3 & ~mask) |
| 2287 | ) |
| 2288 | ) |
| 2289 | ) |
| 2290 | ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2293 | /* Give EmWarn for attempted writes to: |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2294 | - Exception Controls |
| 2295 | - Non-IEEE Mode |
| 2296 | */ |
| 2297 | if (mask & 0xFC) { // Exception Control, Non-IEE mode |
sewardj | 5ff11dd | 2006-01-20 14:19:25 +0000 | [diff] [blame] | 2298 | VexEmWarn ew = EmWarn_PPCexns; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2299 | |
| 2300 | /* If any of the src::exception_control bits are actually set, |
| 2301 | side-exit to the next insn, reporting the warning, |
| 2302 | so that Valgrind's dispatcher sees the warning. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2303 | putGST( PPC_GST_EMWARN, mkU32(ew) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2304 | stmt( |
| 2305 | IRStmt_Exit( |
| 2306 | binop(Iop_CmpNE32, mkU32(ew), mkU32(EmWarn_NONE)), |
| 2307 | Ijk_EmWarn, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2308 | mkSzConst( ty, nextInsnAddr()) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2311 | /* Ignore all other writes */ |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2312 | break; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2313 | } |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2314 | |
| 2315 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2316 | vex_printf("putGST_masked(ppc): reg = %u", reg); |
| 2317 | vpanic("putGST_masked(ppc)"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2318 | } |
| 2319 | } |
| 2320 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2321 | /* Write the least significant nibble of src to the specified |
| 2322 | REG[FLD] (as per IBM/hardware notation). */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2323 | static void putGST_field ( PPC_GST reg, IRExpr* src, UInt fld ) |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2324 | { |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 2325 | UInt shft, mask; |
| 2326 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2327 | vassert( typeOfIRExpr(irbb->tyenv,src ) == Ity_I32 ); |
| 2328 | vassert( fld < 8 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2329 | vassert( reg < PPC_GST_MAX ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2330 | |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 2331 | shft = 4*(7-fld); |
| 2332 | mask = 0xF<<shft; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2333 | |
| 2334 | switch (reg) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2335 | case PPC_GST_CR: |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2336 | putCR0 (fld, binop(Iop_And8, mkU8(1 ), unop(Iop_32to8, src))); |
| 2337 | putCR321(fld, binop(Iop_And8, mkU8(7<<1), unop(Iop_32to8, src))); |
| 2338 | break; |
| 2339 | |
| 2340 | default: |
| 2341 | if (shft == 0) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2342 | putGST_masked( reg, src, mask ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2343 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2344 | putGST_masked( reg, |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2345 | binop(Iop_Shl32, src, mkU8(toUChar(shft))), |
| 2346 | mask ); |
| 2347 | } |
| 2348 | } |
| 2349 | } |
cerion | 62bec57 | 2005-02-01 21:29:39 +0000 | [diff] [blame] | 2350 | |
cerion | 7622226 | 2005-02-05 13:45:57 +0000 | [diff] [blame] | 2351 | |
| 2352 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2353 | /*------------------------------------------------------------*/ |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 2354 | /*--- Integer Instruction Translation --- */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2355 | /*------------------------------------------------------------*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 2356 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2357 | /* |
| 2358 | Integer Arithmetic Instructions |
| 2359 | */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 2360 | static Bool dis_int_arith ( UInt theInstr ) |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2361 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2362 | /* D-Form, XO-Form */ |
| 2363 | UChar opc1 = ifieldOPC(theInstr); |
| 2364 | UChar rD_addr = ifieldRegDS(theInstr); |
| 2365 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2366 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2367 | UChar rB_addr = ifieldRegB(theInstr); |
| 2368 | UChar flag_OE = ifieldBIT10(theInstr); |
| 2369 | UInt opc2 = ifieldOPClo9(theInstr); |
| 2370 | UChar flag_rC = ifieldBIT0(theInstr); |
| 2371 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2372 | Long simm16 = extend_s_16to64(uimm16); |
| 2373 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 2374 | IRTemp rA = newTemp(ty); |
| 2375 | IRTemp rB = newTemp(ty); |
| 2376 | IRTemp rD = newTemp(ty); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2377 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2378 | Bool do_rc = False; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2379 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2380 | assign( rA, getIReg(rA_addr) ); |
| 2381 | assign( rB, getIReg(rB_addr) ); // XO-Form: rD, rA, rB |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2382 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2383 | switch (opc1) { |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2384 | /* D-Form */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2385 | case 0x0C: // addic (Add Immediate Carrying, PPC32 p351 |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2386 | DIP("addic r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2387 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2388 | mkSzExtendS16(ty, uimm16) ) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2389 | set_XER_CA( ty, PPCG_FLAG_OP_ADD, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2390 | mkexpr(rD), mkexpr(rA), mkSzExtendS16(ty, uimm16), |
| 2391 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 2392 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2393 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2394 | case 0x0D: // addic. (Add Immediate Carrying and Record, PPC32 p352) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2395 | DIP("addic. r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2396 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2397 | mkSzExtendS16(ty, uimm16) ) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2398 | set_XER_CA( ty, PPCG_FLAG_OP_ADD, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2399 | mkexpr(rD), mkexpr(rA), mkSzExtendS16(ty, uimm16), |
| 2400 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2401 | do_rc = True; // Always record to CR |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2402 | flag_rC = 1; |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 2403 | break; |
| 2404 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2405 | case 0x0E: // addi (Add Immediate, PPC32 p350) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2406 | // li rD,val == addi rD,0,val |
| 2407 | // la disp(rA) == addi rD,rA,disp |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2408 | if ( rA_addr == 0 ) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2409 | DIP("li r%u,%d\n", rD_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2410 | assign( rD, mkSzExtendS16(ty, uimm16) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2411 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2412 | DIP("addi r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2413 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2414 | mkSzExtendS16(ty, uimm16) ) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2415 | } |
| 2416 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2417 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2418 | case 0x0F: // addis (Add Immediate Shifted, PPC32 p353) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2419 | // lis rD,val == addis rD,0,val |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2420 | if ( rA_addr == 0 ) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2421 | DIP("lis r%u,%d\n", rD_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2422 | assign( rD, mkSzExtendS32(ty, uimm16 << 16) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2423 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2424 | DIP("addis r%u,r%u,0x%x\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2425 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2426 | mkSzExtendS32(ty, uimm16 << 16) ) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2427 | } |
| 2428 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2429 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2430 | case 0x07: // mulli (Multiply Low Immediate, PPC32 p490) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2431 | DIP("mulli r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
| 2432 | if (mode64) |
| 2433 | assign( rD, unop(Iop_128to64, |
| 2434 | binop(Iop_MullS64, mkexpr(rA), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2435 | mkSzExtendS16(ty, uimm16))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2436 | else |
| 2437 | assign( rD, unop(Iop_64to32, |
| 2438 | binop(Iop_MullS32, mkexpr(rA), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2439 | mkSzExtendS16(ty, uimm16))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2440 | break; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 2441 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2442 | case 0x08: // subfic (Subtract from Immediate Carrying, PPC32 p540) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2443 | DIP("subfic r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2444 | // rD = simm16 - rA |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2445 | assign( rD, binop( mkSzOp(ty, Iop_Sub8), |
| 2446 | mkSzExtendS16(ty, uimm16), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2447 | mkexpr(rA)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2448 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFI, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2449 | mkexpr(rD), mkexpr(rA), mkSzExtendS16(ty, uimm16), |
| 2450 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2451 | break; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 2452 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2453 | /* XO-Form */ |
| 2454 | case 0x1F: |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2455 | do_rc = True; // All below record to CR |
| 2456 | |
| 2457 | switch (opc2) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2458 | case 0x10A: // add (Add, PPC32 p347) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2459 | DIP("add%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2460 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2461 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2462 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2463 | mkexpr(rA), mkexpr(rB) ) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2464 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2465 | set_XER_OV( ty, PPCG_FLAG_OP_ADD, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2466 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2467 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2468 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2469 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2470 | case 0x00A: // addc (Add Carrying, PPC32 p348) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2471 | DIP("addc%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2472 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2473 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2474 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2475 | mkexpr(rA), mkexpr(rB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2476 | set_XER_CA( ty, PPCG_FLAG_OP_ADD, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2477 | mkexpr(rD), mkexpr(rA), mkexpr(rB), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2478 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2479 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2480 | set_XER_OV( ty, PPCG_FLAG_OP_ADD, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2481 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2482 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2483 | break; |
| 2484 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2485 | case 0x08A: { // adde (Add Extended, PPC32 p349) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2486 | IRTemp old_xer_ca = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2487 | DIP("adde%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2488 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2489 | rD_addr, rA_addr, rB_addr); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2490 | // rD = rA + rB + XER[CA] |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2491 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2492 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2493 | binop( mkSzOp(ty, Iop_Add8), |
| 2494 | mkexpr(rB), mkexpr(old_xer_ca))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2495 | set_XER_CA( ty, PPCG_FLAG_OP_ADDE, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2496 | mkexpr(rD), mkexpr(rA), mkexpr(rB), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2497 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2498 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2499 | set_XER_OV( ty, PPCG_FLAG_OP_ADDE, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2500 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2501 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2502 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2505 | case 0x0EA: { // addme (Add to Minus One Extended, PPC32 p354) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2506 | IRTemp old_xer_ca = newTemp(ty); |
| 2507 | IRExpr *min_one; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2508 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2509 | vex_printf("dis_int_arith(ppc)(addme,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2510 | return False; |
| 2511 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2512 | DIP("addme%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2513 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2514 | rD_addr, rA_addr, rB_addr); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2515 | // rD = rA + (-1) + XER[CA] |
| 2516 | // => Just another form of adde |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2517 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2518 | min_one = mkSzImm(ty, (Long)-1); |
| 2519 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2520 | binop( mkSzOp(ty, Iop_Add8), |
| 2521 | min_one, mkexpr(old_xer_ca)) )); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2522 | set_XER_CA( ty, PPCG_FLAG_OP_ADDE, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2523 | mkexpr(rD), mkexpr(rA), min_one, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2524 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2525 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2526 | set_XER_OV( ty, PPCG_FLAG_OP_ADDE, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2527 | mkexpr(rD), mkexpr(rA), min_one ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2528 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2529 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | case 0x0CA: { // addze (Add to Zero Extended, PPC32 p355) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2533 | IRTemp old_xer_ca = newTemp(ty); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2534 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2535 | vex_printf("dis_int_arith(ppc)(addze,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2536 | return False; |
| 2537 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2538 | DIP("addze%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2539 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2540 | rD_addr, rA_addr, rB_addr); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2541 | // rD = rA + (0) + XER[CA] |
| 2542 | // => Just another form of adde |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2543 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2544 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2545 | mkexpr(rA), mkexpr(old_xer_ca)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2546 | set_XER_CA( ty, PPCG_FLAG_OP_ADDE, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2547 | mkexpr(rD), mkexpr(rA), mkSzImm(ty, 0), |
| 2548 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2549 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2550 | set_XER_OV( ty, PPCG_FLAG_OP_ADDE, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2551 | mkexpr(rD), mkexpr(rA), mkSzImm(ty, 0) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2552 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2553 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2554 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2555 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2556 | case 0x1EB: // divw (Divide Word, PPC32 p388) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2557 | DIP("divw%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2558 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2559 | rD_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2560 | if (mode64) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2561 | /* Note: |
| 2562 | XER settings are mode independent, and reflect the |
| 2563 | overflow of the low-order 32bit result |
| 2564 | CR0[LT|GT|EQ] are undefined if flag_rC && mode64 |
| 2565 | */ |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2566 | /* rD[hi32] are undefined: setting them to sign of lo32 |
| 2567 | - makes set_CR0 happy */ |
| 2568 | IRExpr* dividend = mk64lo32Sto64( mkexpr(rA) ); |
| 2569 | IRExpr* divisor = mk64lo32Sto64( mkexpr(rB) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2570 | assign( rD, mk64lo32Uto64( binop(Iop_DivS64, dividend, |
| 2571 | divisor) ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2572 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2573 | set_XER_OV( ty, PPCG_FLAG_OP_DIVW, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2574 | mkexpr(rD), dividend, divisor ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2575 | } |
| 2576 | } else { |
| 2577 | assign( rD, binop(Iop_DivS32, mkexpr(rA), mkexpr(rB)) ); |
| 2578 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2579 | set_XER_OV( ty, PPCG_FLAG_OP_DIVW, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2580 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2581 | } |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2582 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2583 | /* Note: |
| 2584 | if (0x8000_0000 / -1) or (x / 0) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2585 | => rD=undef, if(flag_rC) CR7=undef, if(flag_OE) XER_OV=1 |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2586 | => But _no_ exception raised. */ |
| 2587 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2588 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2589 | case 0x1CB: // divwu (Divide Word Unsigned, PPC32 p389) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2590 | DIP("divwu%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2591 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2592 | rD_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2593 | if (mode64) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2594 | /* Note: |
| 2595 | XER settings are mode independent, and reflect the |
| 2596 | overflow of the low-order 32bit result |
| 2597 | CR0[LT|GT|EQ] are undefined if flag_rC && mode64 |
| 2598 | */ |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2599 | IRExpr* dividend = mk64lo32Uto64( mkexpr(rA) ); |
| 2600 | IRExpr* divisor = mk64lo32Uto64( mkexpr(rB) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2601 | assign( rD, mk64lo32Uto64( binop(Iop_DivU64, dividend, |
| 2602 | divisor) ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2603 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2604 | set_XER_OV( ty, PPCG_FLAG_OP_DIVWU, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2605 | mkexpr(rD), dividend, divisor ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2606 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2607 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2608 | assign( rD, binop(Iop_DivU32, mkexpr(rA), mkexpr(rB)) ); |
| 2609 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2610 | set_XER_OV( ty, PPCG_FLAG_OP_DIVWU, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2611 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2612 | } |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2613 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2614 | /* Note: ditto comment divw, for (x / 0) */ |
| 2615 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2616 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2617 | case 0x04B: // mulhw (Multiply High Word, PPC32 p488) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2618 | if (flag_OE != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2619 | vex_printf("dis_int_arith(ppc)(mulhw,flag_OE)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2620 | return False; |
| 2621 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2622 | DIP("mulhw%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2623 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2624 | if (mode64) { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2625 | /* rD[hi32] are undefined: setting them to sign of lo32 |
| 2626 | - makes set_CR0 happy */ |
| 2627 | assign( rD, binop(Iop_Sar64, |
| 2628 | binop(Iop_Mul64, |
| 2629 | mk64lo32Sto64( mkexpr(rA) ), |
| 2630 | mk64lo32Sto64( mkexpr(rB) )), |
| 2631 | mkU8(32)) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2632 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2633 | assign( rD, unop(Iop_64HIto32, |
| 2634 | binop(Iop_MullS32, |
| 2635 | mkexpr(rA), mkexpr(rB))) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2636 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2637 | break; |
cerion | c19d5e1 | 2005-02-01 15:56:25 +0000 | [diff] [blame] | 2638 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2639 | case 0x00B: // mulhwu (Multiply High Word Unsigned, PPC32 p489) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2640 | if (flag_OE != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2641 | vex_printf("dis_int_arith(ppc)(mulhwu,flag_OE)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2642 | return False; |
| 2643 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2644 | DIP("mulhwu%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2645 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2646 | if (mode64) { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2647 | /* rD[hi32] are undefined: setting them to sign of lo32 |
| 2648 | - makes set_CR0 happy */ |
| 2649 | assign( rD, binop(Iop_Sar64, |
| 2650 | binop(Iop_Mul64, |
| 2651 | mk64lo32Uto64( mkexpr(rA) ), |
| 2652 | mk64lo32Uto64( mkexpr(rB) ) ), |
| 2653 | mkU8(32)) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2654 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2655 | assign( rD, unop(Iop_64HIto32, |
| 2656 | binop(Iop_MullU32, |
| 2657 | mkexpr(rA), mkexpr(rB))) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2658 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2659 | break; |
| 2660 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2661 | case 0x0EB: // mullw (Multiply Low Word, PPC32 p491) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2662 | DIP("mullw%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2663 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2664 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2665 | if (mode64) { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2666 | /* rD[hi32] are undefined: setting them to sign of lo32 |
| 2667 | - set_XER_OV() and set_CR0() depend on this */ |
| 2668 | IRExpr *a = unop(Iop_64to32, mkexpr(rA) ); |
| 2669 | IRExpr *b = unop(Iop_64to32, mkexpr(rB) ); |
| 2670 | assign( rD, binop(Iop_MullS32, a, b) ); |
| 2671 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2672 | set_XER_OV( ty, PPCG_FLAG_OP_MULLW, |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2673 | mkexpr(rD), |
| 2674 | unop(Iop_32Uto64, a), unop(Iop_32Uto64, b) ); |
| 2675 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2676 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2677 | assign( rD, unop(Iop_64to32, |
| 2678 | binop(Iop_MullU32, |
| 2679 | mkexpr(rA), mkexpr(rB))) ); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2680 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2681 | set_XER_OV( ty, PPCG_FLAG_OP_MULLW, |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2682 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2683 | } |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2684 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2685 | break; |
cerion | c19d5e1 | 2005-02-01 15:56:25 +0000 | [diff] [blame] | 2686 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2687 | case 0x068: // neg (Negate, PPC32 p493) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2688 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2689 | vex_printf("dis_int_arith(ppc)(neg,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2690 | return False; |
| 2691 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2692 | DIP("neg%s%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2693 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2694 | rD_addr, rA_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2695 | // rD = (~rA) + 1 |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2696 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2697 | unop( mkSzOp(ty, Iop_Not8), mkexpr(rA) ), |
| 2698 | mkSzImm(ty, 1)) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2699 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2700 | set_XER_OV( ty, PPCG_FLAG_OP_NEG, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2701 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2702 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2703 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2704 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2705 | case 0x028: // subf (Subtract From, PPC32 p537) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2706 | DIP("subf%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2707 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2708 | rD_addr, rA_addr, rB_addr); |
cerion | 0190847 | 2005-02-25 16:43:08 +0000 | [diff] [blame] | 2709 | // rD = rB - rA |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2710 | assign( rD, binop( mkSzOp(ty, Iop_Sub8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2711 | mkexpr(rB), mkexpr(rA)) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2712 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2713 | set_XER_OV( ty, PPCG_FLAG_OP_SUBF, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2714 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2715 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2716 | break; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 2717 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2718 | case 0x008: // subfc (Subtract from Carrying, PPC32 p538) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2719 | DIP("subfc%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2720 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2721 | rD_addr, rA_addr, rB_addr); |
cerion | 0190847 | 2005-02-25 16:43:08 +0000 | [diff] [blame] | 2722 | // rD = rB - rA |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2723 | assign( rD, binop( mkSzOp(ty, Iop_Sub8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2724 | mkexpr(rB), mkexpr(rA)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2725 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFC, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2726 | mkexpr(rD), mkexpr(rA), mkexpr(rB), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2727 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2728 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2729 | set_XER_OV( ty, PPCG_FLAG_OP_SUBFC, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2730 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2731 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2732 | break; |
| 2733 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2734 | case 0x088: {// subfe (Subtract from Extended, PPC32 p539) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2735 | IRTemp old_xer_ca = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2736 | DIP("subfe%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2737 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2738 | rD_addr, rA_addr, rB_addr); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2739 | // rD = (log not)rA + rB + XER[CA] |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2740 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2741 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2742 | unop( mkSzOp(ty, Iop_Not8), mkexpr(rA)), |
| 2743 | binop( mkSzOp(ty, Iop_Add8), |
| 2744 | mkexpr(rB), mkexpr(old_xer_ca))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2745 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFE, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2746 | mkexpr(rD), mkexpr(rA), mkexpr(rB), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2747 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2748 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2749 | set_XER_OV( ty, PPCG_FLAG_OP_SUBFE, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2750 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2751 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2752 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2755 | case 0x0E8: { // subfme (Subtract from -1 Extended, PPC32 p541) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2756 | IRTemp old_xer_ca = newTemp(ty); |
| 2757 | IRExpr *min_one; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2758 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2759 | vex_printf("dis_int_arith(ppc)(subfme,rB_addr)\n"); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 2760 | return False; |
| 2761 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2762 | DIP("subfme%s%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2763 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2764 | rD_addr, rA_addr); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 2765 | // rD = (log not)rA + (-1) + XER[CA] |
| 2766 | // => Just another form of subfe |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2767 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2768 | min_one = mkSzImm(ty, (Long)-1); |
| 2769 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2770 | unop( mkSzOp(ty, Iop_Not8), mkexpr(rA)), |
| 2771 | binop( mkSzOp(ty, Iop_Add8), |
| 2772 | min_one, mkexpr(old_xer_ca))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2773 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFE, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2774 | mkexpr(rD), mkexpr(rA), min_one, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2775 | mkexpr(old_xer_ca) ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 2776 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2777 | set_XER_OV( ty, PPCG_FLAG_OP_SUBFE, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2778 | mkexpr(rD), mkexpr(rA), min_one ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 2779 | } |
| 2780 | break; |
| 2781 | } |
| 2782 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2783 | case 0x0C8: { // subfze (Subtract from Zero Extended, PPC32 p542) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2784 | IRTemp old_xer_ca = newTemp(ty); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2785 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2786 | vex_printf("dis_int_arith(ppc)(subfze,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2787 | return False; |
| 2788 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2789 | DIP("subfze%s%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2790 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2791 | rD_addr, rA_addr); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2792 | // rD = (log not)rA + (0) + XER[CA] |
| 2793 | // => Just another form of subfe |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2794 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2795 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2796 | unop( mkSzOp(ty, Iop_Not8), |
| 2797 | mkexpr(rA)), mkexpr(old_xer_ca)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2798 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFE, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2799 | mkexpr(rD), mkexpr(rA), mkSzImm(ty, 0), |
| 2800 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2801 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2802 | set_XER_OV( ty, PPCG_FLAG_OP_SUBFE, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2803 | mkexpr(rD), mkexpr(rA), mkSzImm(ty, 0) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2804 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2805 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2806 | } |
cerion | ae69462 | 2005-01-28 17:52:47 +0000 | [diff] [blame] | 2807 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2808 | |
| 2809 | /* 64bit Arithmetic */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2810 | case 0x49: // mulhd (Multiply High DWord, PPC64 p539) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2811 | if (flag_OE != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2812 | vex_printf("dis_int_arith(ppc)(mulhd,flagOE)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2813 | return False; |
| 2814 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2815 | DIP("mulhd%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2816 | rD_addr, rA_addr, rB_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2817 | assign( rD, unop(Iop_128HIto64, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2818 | binop(Iop_MullS64, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2819 | mkexpr(rA), mkexpr(rB))) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2820 | |
| 2821 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2822 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2823 | case 0x9: // mulhdu (Multiply High DWord Unsigned, PPC64 p540) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2824 | if (flag_OE != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2825 | vex_printf("dis_int_arith(ppc)(mulhdu,flagOE)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2826 | return False; |
| 2827 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2828 | DIP("mulhdu%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2829 | rD_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2830 | assign( rD, unop(Iop_128HIto64, |
| 2831 | binop(Iop_MullU64, |
| 2832 | mkexpr(rA), mkexpr(rB))) ); |
| 2833 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2834 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2835 | case 0xE9: // mulld (Multiply Low DWord, PPC64 p543) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2836 | DIP("mulld%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2837 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2838 | rD_addr, rA_addr, rB_addr); |
| 2839 | assign( rD, binop(Iop_Mul64, mkexpr(rA), mkexpr(rB)) ); |
| 2840 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2841 | set_XER_OV( ty, PPCG_FLAG_OP_MULLW, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2842 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2843 | } |
| 2844 | break; |
| 2845 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2846 | case 0x1E9: // divd (Divide DWord, PPC64 p419) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2847 | DIP("divd%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2848 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2849 | rD_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2850 | assign( rD, binop(Iop_DivS64, mkexpr(rA), mkexpr(rB)) ); |
| 2851 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2852 | set_XER_OV( ty, PPCG_FLAG_OP_DIVW, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2853 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2854 | } |
| 2855 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2856 | /* Note: |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2857 | if (0x8000_0000_0000_0000 / -1) or (x / 0) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2858 | => rD=undef, if(flag_rC) CR7=undef, if(flag_OE) XER_OV=1 |
| 2859 | => But _no_ exception raised. */ |
| 2860 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2861 | case 0x1C9: // divdu (Divide DWord Unsigned, PPC64 p420) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2862 | DIP("divdu%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2863 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2864 | rD_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2865 | assign( rD, binop(Iop_DivU64, mkexpr(rA), mkexpr(rB)) ); |
| 2866 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2867 | set_XER_OV( ty, PPCG_FLAG_OP_DIVWU, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2868 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2869 | } |
| 2870 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2871 | /* Note: ditto comment divd, for (x / 0) */ |
| 2872 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2873 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2874 | vex_printf("dis_int_arith(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2875 | return False; |
| 2876 | } |
| 2877 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2878 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2879 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2880 | vex_printf("dis_int_arith(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2881 | return False; |
| 2882 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2883 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2884 | putIReg( rD_addr, mkexpr(rD) ); |
| 2885 | |
| 2886 | if (do_rc && flag_rC) { |
| 2887 | set_CR0( mkexpr(rD) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2888 | } |
| 2889 | return True; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | |
| 2893 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 2894 | /* |
| 2895 | Integer Compare Instructions |
| 2896 | */ |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2897 | static Bool dis_int_cmp ( UInt theInstr ) |
| 2898 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2899 | /* D-Form, X-Form */ |
| 2900 | UChar opc1 = ifieldOPC(theInstr); |
| 2901 | UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 2902 | UChar b22 = toUChar( IFIELD( theInstr, 22, 1 ) ); |
| 2903 | UChar flag_L = toUChar( IFIELD( theInstr, 21, 1 ) ); |
| 2904 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2905 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2906 | UChar rB_addr = ifieldRegB(theInstr); |
| 2907 | UInt opc2 = ifieldOPClo10(theInstr); |
| 2908 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2909 | |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2910 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 2911 | IRExpr *a = getIReg(rA_addr); |
| 2912 | IRExpr *b; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2913 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2914 | if (!mode64 && flag_L==1) { // L==1 invalid for 32 bit. |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2915 | vex_printf("dis_int_cmp(ppc)(flag_L)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2916 | return False; |
| 2917 | } |
| 2918 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2919 | if (b22 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2920 | vex_printf("dis_int_cmp(ppc)(b22)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2921 | return False; |
| 2922 | } |
| 2923 | |
| 2924 | switch (opc1) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2925 | case 0x0B: // cmpi (Compare Immediate, PPC32 p368) |
| 2926 | DIP("cmpi cr%u,%u,r%u,%d\n", crfD, flag_L, rA_addr, |
| 2927 | (Int)extend_s_16to32(uimm16)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2928 | b = mkSzExtendS16( ty, uimm16 ); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2929 | if (flag_L == 1) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2930 | putCR321(crfD, unop(Iop_64to8, binop(Iop_CmpORD64S, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2931 | } else { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2932 | a = mkSzNarrow32( ty, a ); |
| 2933 | b = mkSzNarrow32( ty, b ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2934 | putCR321(crfD, unop(Iop_32to8, binop(Iop_CmpORD32S, a, b))); |
| 2935 | } |
| 2936 | putCR0( crfD, getXER_SO() ); |
| 2937 | break; |
| 2938 | |
| 2939 | case 0x0A: // cmpli (Compare Logical Immediate, PPC32 p370) |
| 2940 | DIP("cmpli cr%u,%u,r%u,0x%x\n", crfD, flag_L, rA_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2941 | b = mkSzImm( ty, uimm16 ); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2942 | if (flag_L == 1) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2943 | putCR321(crfD, unop(Iop_64to8, binop(Iop_CmpORD64U, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2944 | } else { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2945 | a = mkSzNarrow32( ty, a ); |
| 2946 | b = mkSzNarrow32( ty, b ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2947 | putCR321(crfD, unop(Iop_32to8, binop(Iop_CmpORD32U, a, b))); |
| 2948 | } |
| 2949 | putCR0( crfD, getXER_SO() ); |
| 2950 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2951 | |
| 2952 | /* X Form */ |
| 2953 | case 0x1F: |
| 2954 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2955 | vex_printf("dis_int_cmp(ppc)(0x1F,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2956 | return False; |
| 2957 | } |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2958 | b = getIReg(rB_addr); |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2959 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2960 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2961 | case 0x000: // cmp (Compare, PPC32 p367) |
| 2962 | DIP("cmp cr%u,%u,r%u,r%u\n", crfD, flag_L, rA_addr, rB_addr); |
sewardj | a9cb67b | 2006-08-19 18:31:53 +0000 | [diff] [blame] | 2963 | /* Comparing a reg with itself produces a result which |
| 2964 | doesn't depend on the contents of the reg. Therefore |
| 2965 | remove the false dependency, which has been known to cause |
| 2966 | memcheck to produce false errors. */ |
sewardj | 9195aa1 | 2006-08-19 22:18:53 +0000 | [diff] [blame] | 2967 | if (rA_addr == rB_addr) |
| 2968 | a = b = typeOfIRExpr(irbb->tyenv,a) == Ity_I64 |
| 2969 | ? mkU64(0) : mkU32(0); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2970 | if (flag_L == 1) { |
| 2971 | putCR321(crfD, unop(Iop_64to8, binop(Iop_CmpORD64S, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2972 | } else { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2973 | a = mkSzNarrow32( ty, a ); |
| 2974 | b = mkSzNarrow32( ty, b ); |
| 2975 | putCR321(crfD, unop(Iop_32to8,binop(Iop_CmpORD32S, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2976 | } |
| 2977 | putCR0( crfD, getXER_SO() ); |
| 2978 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2979 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2980 | case 0x020: // cmpl (Compare Logical, PPC32 p369) |
| 2981 | DIP("cmpl cr%u,%u,r%u,r%u\n", crfD, flag_L, rA_addr, rB_addr); |
sewardj | a9cb67b | 2006-08-19 18:31:53 +0000 | [diff] [blame] | 2982 | /* Comparing a reg with itself produces a result which |
| 2983 | doesn't depend on the contents of the reg. Therefore |
| 2984 | remove the false dependency, which has been known to cause |
| 2985 | memcheck to produce false errors. */ |
sewardj | 9195aa1 | 2006-08-19 22:18:53 +0000 | [diff] [blame] | 2986 | if (rA_addr == rB_addr) |
| 2987 | a = b = typeOfIRExpr(irbb->tyenv,a) == Ity_I64 |
| 2988 | ? mkU64(0) : mkU32(0); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2989 | if (flag_L == 1) { |
| 2990 | putCR321(crfD, unop(Iop_64to8, binop(Iop_CmpORD64U, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2991 | } else { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2992 | a = mkSzNarrow32( ty, a ); |
| 2993 | b = mkSzNarrow32( ty, b ); |
| 2994 | putCR321(crfD, unop(Iop_32to8, binop(Iop_CmpORD32U, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2995 | } |
| 2996 | putCR0( crfD, getXER_SO() ); |
| 2997 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2998 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2999 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3000 | vex_printf("dis_int_cmp(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3001 | return False; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3002 | } |
| 3003 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3004 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3005 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3006 | vex_printf("dis_int_cmp(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3007 | return False; |
| 3008 | } |
| 3009 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3010 | return True; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 3014 | /* |
| 3015 | Integer Logical Instructions |
| 3016 | */ |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3017 | static Bool dis_int_logic ( UInt theInstr ) |
| 3018 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3019 | /* D-Form, X-Form */ |
| 3020 | UChar opc1 = ifieldOPC(theInstr); |
| 3021 | UChar rS_addr = ifieldRegDS(theInstr); |
| 3022 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3023 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3024 | UChar rB_addr = ifieldRegB(theInstr); |
| 3025 | UInt opc2 = ifieldOPClo10(theInstr); |
| 3026 | UChar flag_rC = ifieldBIT0(theInstr); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3027 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3028 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 3029 | IRTemp rS = newTemp(ty); |
| 3030 | IRTemp rA = newTemp(ty); |
| 3031 | IRTemp rB = newTemp(ty); |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3032 | IRExpr* irx; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3033 | Bool do_rc = False; |
| 3034 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3035 | assign( rS, getIReg(rS_addr) ); |
| 3036 | assign( rB, getIReg(rB_addr) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3037 | |
| 3038 | switch (opc1) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3039 | case 0x1C: // andi. (AND Immediate, PPC32 p358) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3040 | DIP("andi. r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3041 | assign( rA, binop( mkSzOp(ty, Iop_And8), mkexpr(rS), |
| 3042 | mkSzImm(ty, uimm16)) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 3043 | do_rc = True; // Always record to CR |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3044 | flag_rC = 1; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3045 | break; |
| 3046 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3047 | case 0x1D: // andis. (AND Immediate Shifted, PPC32 p359) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3048 | DIP("andis r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3049 | assign( rA, binop( mkSzOp(ty, Iop_And8), mkexpr(rS), |
| 3050 | mkSzImm(ty, uimm16 << 16)) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 3051 | do_rc = True; // Always record to CR |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3052 | flag_rC = 1; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3053 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3054 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3055 | case 0x18: // ori (OR Immediate, PPC32 p497) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3056 | DIP("ori r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3057 | assign( rA, binop( mkSzOp(ty, Iop_Or8), mkexpr(rS), |
| 3058 | mkSzImm(ty, uimm16)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3059 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3060 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3061 | case 0x19: // oris (OR Immediate Shifted, PPC32 p498) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3062 | DIP("oris r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3063 | assign( rA, binop( mkSzOp(ty, Iop_Or8), mkexpr(rS), |
| 3064 | mkSzImm(ty, uimm16 << 16)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3065 | break; |
cerion | aabdfbf | 2005-01-29 12:56:15 +0000 | [diff] [blame] | 3066 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3067 | case 0x1A: // xori (XOR Immediate, PPC32 p550) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3068 | DIP("xori r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3069 | assign( rA, binop( mkSzOp(ty, Iop_Xor8), mkexpr(rS), |
| 3070 | mkSzImm(ty, uimm16)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3071 | break; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 3072 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3073 | case 0x1B: // xoris (XOR Immediate Shifted, PPC32 p551) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3074 | DIP("xoris r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3075 | assign( rA, binop( mkSzOp(ty, Iop_Xor8), mkexpr(rS), |
| 3076 | mkSzImm(ty, uimm16 << 16)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3077 | break; |
cerion | aabdfbf | 2005-01-29 12:56:15 +0000 | [diff] [blame] | 3078 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3079 | /* X Form */ |
| 3080 | case 0x1F: |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 3081 | do_rc = True; // All below record to CR |
| 3082 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3083 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3084 | case 0x01C: // and (AND, PPC32 p356) |
| 3085 | DIP("and%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3086 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3087 | assign(rA, binop( mkSzOp(ty, Iop_And8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3088 | mkexpr(rS), mkexpr(rB))); |
| 3089 | break; |
| 3090 | |
| 3091 | case 0x03C: // andc (AND with Complement, PPC32 p357) |
| 3092 | DIP("andc%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3093 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3094 | assign(rA, binop( mkSzOp(ty, Iop_And8), mkexpr(rS), |
| 3095 | unop( mkSzOp(ty, Iop_Not8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3096 | mkexpr(rB)))); |
| 3097 | break; |
| 3098 | |
| 3099 | case 0x01A: { // cntlzw (Count Leading Zeros Word, PPC32 p371) |
| 3100 | IRExpr* lo32; |
| 3101 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3102 | vex_printf("dis_int_logic(ppc)(cntlzw,rB_addr)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3103 | return False; |
| 3104 | } |
| 3105 | DIP("cntlzw%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3106 | flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3107 | |
| 3108 | // mode64: count in low word only |
| 3109 | lo32 = mode64 ? unop(Iop_64to32, mkexpr(rS)) : mkexpr(rS); |
| 3110 | |
| 3111 | // Iop_Clz32 undefined for arg==0, so deal with that case: |
| 3112 | irx = binop(Iop_CmpNE32, lo32, mkU32(0)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3113 | assign(rA, mkSzWiden32(ty, |
| 3114 | IRExpr_Mux0X( unop(Iop_1Uto8, irx), |
| 3115 | mkU32(32), |
| 3116 | unop(Iop_Clz32, lo32)), |
| 3117 | False)); |
| 3118 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3119 | // TODO: alternatively: assign(rA, verbose_Clz32(rS)); |
| 3120 | break; |
| 3121 | } |
| 3122 | |
| 3123 | case 0x11C: // eqv (Equivalent, PPC32 p396) |
| 3124 | DIP("eqv%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3125 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3126 | assign( rA, unop( mkSzOp(ty, Iop_Not8), |
| 3127 | binop( mkSzOp(ty, Iop_Xor8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3128 | mkexpr(rS), mkexpr(rB))) ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 3129 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3130 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3131 | case 0x3BA: // extsb (Extend Sign Byte, PPC32 p397 |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3132 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3133 | vex_printf("dis_int_logic(ppc)(extsb,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3134 | return False; |
| 3135 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3136 | DIP("extsb%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3137 | flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3138 | if (mode64) |
| 3139 | assign( rA, unop(Iop_8Sto64, unop(Iop_64to8, mkexpr(rS))) ); |
| 3140 | else |
| 3141 | assign( rA, unop(Iop_8Sto32, unop(Iop_32to8, mkexpr(rS))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3142 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3143 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3144 | case 0x39A: // extsh (Extend Sign Half Word, PPC32 p398) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3145 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3146 | vex_printf("dis_int_logic(ppc)(extsh,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3147 | return False; |
| 3148 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3149 | DIP("extsh%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3150 | flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3151 | if (mode64) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3152 | assign( rA, unop(Iop_16Sto64, |
| 3153 | unop(Iop_64to16, mkexpr(rS))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3154 | else |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3155 | assign( rA, unop(Iop_16Sto32, |
| 3156 | unop(Iop_32to16, mkexpr(rS))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3157 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3158 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3159 | case 0x1DC: // nand (NAND, PPC32 p492) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3160 | DIP("nand%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3161 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3162 | assign( rA, unop( mkSzOp(ty, Iop_Not8), |
| 3163 | binop( mkSzOp(ty, Iop_And8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3164 | mkexpr(rS), mkexpr(rB))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3165 | break; |
| 3166 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3167 | case 0x07C: // nor (NOR, PPC32 p494) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3168 | DIP("nor%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3169 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3170 | assign( rA, unop( mkSzOp(ty, Iop_Not8), |
| 3171 | binop( mkSzOp(ty, Iop_Or8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3172 | mkexpr(rS), mkexpr(rB))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3173 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3174 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3175 | case 0x1BC: // or (OR, PPC32 p495) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3176 | if ((!flag_rC) && rS_addr == rB_addr) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3177 | DIP("mr r%u,r%u\n", rA_addr, rS_addr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3178 | assign( rA, mkexpr(rS) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 3179 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3180 | DIP("or%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3181 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3182 | assign( rA, binop( mkSzOp(ty, Iop_Or8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3183 | mkexpr(rS), mkexpr(rB)) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 3184 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3185 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3186 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3187 | case 0x19C: // orc (OR with Complement, PPC32 p496) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3188 | DIP("orc%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3189 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3190 | assign( rA, binop( mkSzOp(ty, Iop_Or8), mkexpr(rS), |
| 3191 | unop(mkSzOp(ty, Iop_Not8), mkexpr(rB)))); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3192 | break; |
| 3193 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3194 | case 0x13C: // xor (XOR, PPC32 p549) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3195 | DIP("xor%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3196 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3197 | assign( rA, binop( mkSzOp(ty, Iop_Xor8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3198 | mkexpr(rS), mkexpr(rB)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3199 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3200 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3201 | |
| 3202 | /* 64bit Integer Logical Instructions */ |
| 3203 | case 0x3DA: // extsw (Extend Sign Word, PPC64 p430) |
| 3204 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3205 | vex_printf("dis_int_logic(ppc)(extsw,rB_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3206 | return False; |
| 3207 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3208 | DIP("extsw%s r%u,r%u\n", flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3209 | assign(rA, unop(Iop_32Sto64, unop(Iop_64to32, mkexpr(rS)))); |
| 3210 | break; |
| 3211 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3212 | case 0x03A: // cntlzd (Count Leading Zeros DWord, PPC64 p401) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3213 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3214 | vex_printf("dis_int_logic(ppc)(cntlzd,rB_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3215 | return False; |
| 3216 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3217 | DIP("cntlzd%s r%u,r%u\n", |
| 3218 | flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3219 | // Iop_Clz64 undefined for arg==0, so deal with that case: |
| 3220 | irx = binop(Iop_CmpNE64, mkexpr(rS), mkU64(0)); |
| 3221 | assign(rA, IRExpr_Mux0X( unop(Iop_1Uto8, irx), |
| 3222 | mkU64(64), |
| 3223 | unop(Iop_Clz64, mkexpr(rS)) )); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3224 | // TODO: alternatively: assign(rA, verbose_Clz64(rS)); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3225 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3226 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3227 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3228 | vex_printf("dis_int_logic(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3229 | return False; |
| 3230 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3231 | break; |
| 3232 | |
| 3233 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3234 | vex_printf("dis_int_logic(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3235 | return False; |
| 3236 | } |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 3237 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3238 | putIReg( rA_addr, mkexpr(rA) ); |
| 3239 | |
| 3240 | if (do_rc && flag_rC) { |
| 3241 | set_CR0( mkexpr(rA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3242 | } |
| 3243 | return True; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | |
| 3247 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 3248 | /* |
| 3249 | Integer Rotate Instructions |
| 3250 | */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3251 | static Bool dis_int_rot ( UInt theInstr ) |
| 3252 | { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3253 | /* M-Form, MDS-Form */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3254 | UChar opc1 = ifieldOPC(theInstr); |
| 3255 | UChar rS_addr = ifieldRegDS(theInstr); |
| 3256 | UChar rA_addr = ifieldRegA(theInstr); |
| 3257 | UChar rB_addr = ifieldRegB(theInstr); |
| 3258 | UChar sh_imm = rB_addr; |
| 3259 | UChar MaskBeg = toUChar( IFIELD( theInstr, 6, 5 ) ); |
| 3260 | UChar MaskEnd = toUChar( IFIELD( theInstr, 1, 5 ) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3261 | UChar msk_imm = toUChar( IFIELD( theInstr, 5, 6 ) ); |
| 3262 | UChar opc2 = toUChar( IFIELD( theInstr, 2, 3 ) ); |
| 3263 | UChar b1 = ifieldBIT1(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3264 | UChar flag_rC = ifieldBIT0(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3265 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3266 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 3267 | IRTemp rS = newTemp(ty); |
| 3268 | IRTemp rA = newTemp(ty); |
| 3269 | IRTemp rB = newTemp(ty); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3270 | IRTemp rot = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3271 | IRExpr *r; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3272 | UInt mask32; |
| 3273 | ULong mask64; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3274 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3275 | assign( rS, getIReg(rS_addr) ); |
| 3276 | assign( rB, getIReg(rB_addr) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3277 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3278 | switch (opc1) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3279 | case 0x14: { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3280 | // rlwimi (Rotate Left Word Imm then Mask Insert, PPC32 p500) |
| 3281 | DIP("rlwimi%s r%u,r%u,%d,%d,%d\n", flag_rC ? ".":"", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3282 | rA_addr, rS_addr, sh_imm, MaskBeg, MaskEnd); |
| 3283 | if (mode64) { |
| 3284 | // tmp32 = (ROTL(rS_Lo32, Imm) |
| 3285 | // rA = ((tmp32 || tmp32) & mask64) | (rA & ~mask64) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3286 | mask64 = MASK64(31-MaskEnd, 31-MaskBeg); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3287 | r = ROTL( unop(Iop_64to32, mkexpr(rS) ), mkU8(sh_imm) ); |
| 3288 | r = unop(Iop_32Uto64, r); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3289 | assign( rot, binop(Iop_Or64, r, |
| 3290 | binop(Iop_Shl64, r, mkU8(32))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3291 | assign( rA, |
| 3292 | binop(Iop_Or64, |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3293 | binop(Iop_And64, mkexpr(rot), mkU64(mask64)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3294 | binop(Iop_And64, getIReg(rA_addr), mkU64(~mask64))) ); |
sewardj | 26b3320 | 2005-10-07 09:45:16 +0000 | [diff] [blame] | 3295 | } |
| 3296 | else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3297 | // rA = (ROTL(rS, Imm) & mask) | (rA & ~mask); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3298 | mask32 = MASK32(31-MaskEnd, 31-MaskBeg); |
| 3299 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3300 | assign( rA, |
| 3301 | binop(Iop_Or32, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3302 | binop(Iop_And32, mkU32(mask32), r), |
| 3303 | binop(Iop_And32, getIReg(rA_addr), mkU32(~mask32))) ); |
sewardj | 26b3320 | 2005-10-07 09:45:16 +0000 | [diff] [blame] | 3304 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3305 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3306 | } |
cerion | 45b70ff | 2005-01-31 17:03:25 +0000 | [diff] [blame] | 3307 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3308 | case 0x15: { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3309 | // rlwinm (Rotate Left Word Imm then AND with Mask, PPC32 p501) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3310 | vassert(MaskBeg < 32); |
| 3311 | vassert(MaskEnd < 32); |
| 3312 | vassert(sh_imm < 32); |
| 3313 | |
| 3314 | if (mode64) { |
sewardj | ef4433b | 2006-10-19 03:01:09 +0000 | [diff] [blame] | 3315 | IRTemp rTmp = newTemp(Ity_I64); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3316 | mask64 = MASK64(31-MaskEnd, 31-MaskBeg); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3317 | DIP("rlwinm%s r%u,r%u,%d,%d,%d\n", flag_rC ? ".":"", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3318 | rA_addr, rS_addr, sh_imm, MaskBeg, MaskEnd); |
| 3319 | // tmp32 = (ROTL(rS_Lo32, Imm) |
| 3320 | // rA = ((tmp32 || tmp32) & mask64) |
| 3321 | r = ROTL( unop(Iop_64to32, mkexpr(rS) ), mkU8(sh_imm) ); |
| 3322 | r = unop(Iop_32Uto64, r); |
sewardj | ef4433b | 2006-10-19 03:01:09 +0000 | [diff] [blame] | 3323 | assign( rTmp, r ); |
| 3324 | r = NULL; |
| 3325 | assign( rot, binop(Iop_Or64, mkexpr(rTmp), |
| 3326 | binop(Iop_Shl64, mkexpr(rTmp), mkU8(32))) ); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3327 | assign( rA, binop(Iop_And64, mkexpr(rot), mkU64(mask64)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3328 | } |
| 3329 | else { |
| 3330 | if (MaskBeg == 0 && sh_imm+MaskEnd == 31) { |
| 3331 | /* Special-case the ,n,0,31-n form as that is just n-bit |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3332 | shift left, PPC32 p501 */ |
| 3333 | DIP("slwi%s r%u,r%u,%d\n", flag_rC ? ".":"", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3334 | rA_addr, rS_addr, sh_imm); |
| 3335 | assign( rA, binop(Iop_Shl32, mkexpr(rS), mkU8(sh_imm)) ); |
| 3336 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3337 | else if (MaskEnd == 31 && sh_imm+MaskBeg == 32) { |
| 3338 | /* Special-case the ,32-n,n,31 form as that is just n-bit |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3339 | unsigned shift right, PPC32 p501 */ |
| 3340 | DIP("srwi%s r%u,r%u,%d\n", flag_rC ? ".":"", |
sewardj | ee4a859 | 2006-10-19 00:15:25 +0000 | [diff] [blame] | 3341 | rA_addr, rS_addr, MaskBeg); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3342 | assign( rA, binop(Iop_Shr32, mkexpr(rS), mkU8(MaskBeg)) ); |
| 3343 | } |
| 3344 | else { |
| 3345 | /* General case. */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3346 | mask32 = MASK32(31-MaskEnd, 31-MaskBeg); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3347 | DIP("rlwinm%s r%u,r%u,%d,%d,%d\n", flag_rC ? ".":"", |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3348 | rA_addr, rS_addr, sh_imm, MaskBeg, MaskEnd); |
| 3349 | // rA = ROTL(rS, Imm) & mask |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3350 | assign( rA, binop(Iop_And32, |
| 3351 | ROTL(mkexpr(rS), mkU8(sh_imm)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3352 | mkU32(mask32)) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3353 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3354 | } |
sewardj | c965953 | 2005-07-21 21:33:57 +0000 | [diff] [blame] | 3355 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | case 0x17: { |
| 3359 | // rlwnm (Rotate Left Word then AND with Mask, PPC32 p503 |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3360 | DIP("rlwnm%s r%u,r%u,r%u,%d,%d\n", flag_rC ? ".":"", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3361 | rA_addr, rS_addr, rB_addr, MaskBeg, MaskEnd); |
| 3362 | if (mode64) { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3363 | mask64 = MASK64(31-MaskEnd, 31-MaskBeg); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3364 | /* weird insn alert! |
| 3365 | tmp32 = (ROTL(rS_Lo32, rB[0-4]) |
| 3366 | rA = ((tmp32 || tmp32) & mask64) |
| 3367 | */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3368 | // note, ROTL does the masking, so we don't do it here |
| 3369 | r = ROTL( unop(Iop_64to32, mkexpr(rS)), |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3370 | unop(Iop_64to8, mkexpr(rB)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3371 | r = unop(Iop_32Uto64, r); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3372 | assign(rot, binop(Iop_Or64, r, binop(Iop_Shl64, r, mkU8(32)))); |
| 3373 | assign( rA, binop(Iop_And64, mkexpr(rot), mkU64(mask64)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3374 | } else { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3375 | mask32 = MASK32(31-MaskEnd, 31-MaskBeg); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3376 | // rA = ROTL(rS, rB[0-4]) & mask |
| 3377 | // note, ROTL does the masking, so we don't do it here |
| 3378 | assign( rA, binop(Iop_And32, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3379 | ROTL(mkexpr(rS), |
| 3380 | unop(Iop_32to8, mkexpr(rB))), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3381 | mkU32(mask32)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3382 | } |
| 3383 | break; |
| 3384 | } |
cerion | 45b70ff | 2005-01-31 17:03:25 +0000 | [diff] [blame] | 3385 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3386 | /* 64bit Integer Rotates */ |
| 3387 | case 0x1E: { |
| 3388 | msk_imm = ((msk_imm & 1) << 5) | (msk_imm >> 1); |
| 3389 | sh_imm |= b1 << 5; |
| 3390 | |
| 3391 | vassert( msk_imm < 64 ); |
| 3392 | vassert( sh_imm < 64 ); |
| 3393 | |
| 3394 | switch (opc2) { |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3395 | case 0x4: { |
| 3396 | /* r = ROTL64( rS, rB_lo6) */ |
| 3397 | r = ROTL( mkexpr(rS), unop(Iop_64to8, mkexpr(rB)) ); |
| 3398 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3399 | if (b1 == 0) { // rldcl (Rotl DWord, Clear Left, PPC64 p555) |
| 3400 | DIP("rldcl%s r%u,r%u,r%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3401 | rA_addr, rS_addr, rB_addr, msk_imm); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3402 | // note, ROTL does the masking, so we don't do it here |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3403 | mask64 = MASK64(0, 63-msk_imm); |
| 3404 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3405 | break; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3406 | } else { // rldcr (Rotl DWord, Clear Right, PPC64 p556) |
| 3407 | DIP("rldcr%s r%u,r%u,r%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3408 | rA_addr, rS_addr, rB_addr, msk_imm); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3409 | mask64 = MASK64(63-msk_imm, 63); |
| 3410 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3411 | break; |
| 3412 | } |
| 3413 | break; |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3414 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3415 | case 0x2: // rldic (Rotl DWord Imm, Clear, PPC64 p557) |
| 3416 | DIP("rldic%s r%u,r%u,%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3417 | rA_addr, rS_addr, sh_imm, msk_imm); |
| 3418 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
| 3419 | mask64 = MASK64(sh_imm, 63-msk_imm); |
| 3420 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3421 | break; |
| 3422 | // later: deal with special case: (msk_imm==0) => SHL(sh_imm) |
| 3423 | /* |
| 3424 | Hmm... looks like this'll do the job more simply: |
| 3425 | r = SHL(rS, sh_imm) |
| 3426 | m = ~(1 << (63-msk_imm)) |
| 3427 | assign(rA, r & m); |
| 3428 | */ |
| 3429 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3430 | case 0x0: // rldicl (Rotl DWord Imm, Clear Left, PPC64 p558) |
sewardj | ee4a859 | 2006-10-19 00:15:25 +0000 | [diff] [blame] | 3431 | if (mode64 |
| 3432 | && sh_imm + msk_imm == 64 && msk_imm >= 1 && msk_imm <= 63) { |
| 3433 | /* special-case the ,64-n,n form as that is just |
| 3434 | unsigned shift-right by n */ |
| 3435 | DIP("srdi%s r%u,r%u,%u\n", |
| 3436 | flag_rC ? ".":"", rA_addr, rS_addr, msk_imm); |
| 3437 | assign( rA, binop(Iop_Shr64, mkexpr(rS), mkU8(msk_imm)) ); |
| 3438 | } else { |
| 3439 | DIP("rldicl%s r%u,r%u,%u,%u\n", flag_rC ? ".":"", |
| 3440 | rA_addr, rS_addr, sh_imm, msk_imm); |
| 3441 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
| 3442 | mask64 = MASK64(0, 63-msk_imm); |
| 3443 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3444 | } |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3445 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3446 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3447 | case 0x1: // rldicr (Rotl DWord Imm, Clear Right, PPC64 p559) |
sewardj | ee4a859 | 2006-10-19 00:15:25 +0000 | [diff] [blame] | 3448 | if (mode64 |
| 3449 | && sh_imm + msk_imm == 63 && sh_imm >= 1 && sh_imm <= 63) { |
| 3450 | /* special-case the ,n,63-n form as that is just |
| 3451 | shift-left by n */ |
| 3452 | DIP("sldi%s r%u,r%u,%u\n", |
| 3453 | flag_rC ? ".":"", rA_addr, rS_addr, sh_imm); |
| 3454 | assign( rA, binop(Iop_Shl64, mkexpr(rS), mkU8(sh_imm)) ); |
| 3455 | } else { |
| 3456 | DIP("rldicr%s r%u,r%u,%u,%u\n", flag_rC ? ".":"", |
| 3457 | rA_addr, rS_addr, sh_imm, msk_imm); |
| 3458 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
| 3459 | mask64 = MASK64(63-msk_imm, 63); |
| 3460 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3461 | } |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3462 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3463 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3464 | case 0x3: { // rldimi (Rotl DWord Imm, Mask Insert, PPC64 p560) |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3465 | IRTemp rA_orig = newTemp(ty); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3466 | DIP("rldimi%s r%u,r%u,%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3467 | rA_addr, rS_addr, sh_imm, msk_imm); |
| 3468 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
| 3469 | mask64 = MASK64(sh_imm, 63-msk_imm); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3470 | assign( rA_orig, getIReg(rA_addr) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3471 | assign( rA, binop(Iop_Or64, |
| 3472 | binop(Iop_And64, mkU64(mask64), r), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3473 | binop(Iop_And64, mkU64(~mask64), |
| 3474 | mkexpr(rA_orig))) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3475 | break; |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3476 | } |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3477 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3478 | vex_printf("dis_int_rot(ppc)(opc2)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3479 | return False; |
| 3480 | } |
| 3481 | break; |
| 3482 | } |
| 3483 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3484 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3485 | vex_printf("dis_int_rot(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3486 | return False; |
| 3487 | } |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3488 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3489 | putIReg( rA_addr, mkexpr(rA) ); |
| 3490 | |
| 3491 | if (flag_rC) { |
| 3492 | set_CR0( mkexpr(rA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3493 | } |
| 3494 | return True; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 3498 | /* |
| 3499 | Integer Load Instructions |
| 3500 | */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3501 | static Bool dis_int_load ( UInt theInstr ) |
| 3502 | { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3503 | /* D-Form, X-Form, DS-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3504 | UChar opc1 = ifieldOPC(theInstr); |
| 3505 | UChar rD_addr = ifieldRegDS(theInstr); |
| 3506 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3507 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3508 | UChar rB_addr = ifieldRegB(theInstr); |
| 3509 | UInt opc2 = ifieldOPClo10(theInstr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3510 | UChar b1 = ifieldBIT1(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3511 | UChar b0 = ifieldBIT0(theInstr); |
| 3512 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3513 | Int simm16 = extend_s_16to32(uimm16); |
| 3514 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3515 | IRTemp EA = newTemp(ty); |
| 3516 | IRExpr* val; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3517 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3518 | switch (opc1) { |
| 3519 | case 0x1F: // register offset |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3520 | assign( EA, ea_rAor0_idxd( rA_addr, rB_addr ) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3521 | break; |
| 3522 | case 0x3A: // immediate offset: 64bit |
| 3523 | simm16 = simm16 & 0xFFFFFFFC; |
| 3524 | default: // immediate offset |
| 3525 | assign( EA, ea_rAor0_simm( rA_addr, simm16 ) ); |
| 3526 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3527 | } |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3528 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3529 | switch (opc1) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3530 | case 0x22: // lbz (Load B & Zero, PPC32 p433) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3531 | DIP("lbz r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3532 | val = loadBE(Ity_I8, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3533 | putIReg( rD_addr, mkSzWiden8(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3534 | break; |
| 3535 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3536 | case 0x23: // lbzu (Load B & Zero, Update, PPC32 p434) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3537 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3538 | vex_printf("dis_int_load(ppc)(lbzu,rA_addr|rD_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3539 | return False; |
| 3540 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3541 | DIP("lbzu r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3542 | val = loadBE(Ity_I8, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3543 | putIReg( rD_addr, mkSzWiden8(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3544 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3545 | break; |
| 3546 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3547 | case 0x2A: // lha (Load HW Alg, PPC32 p445) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3548 | DIP("lha r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3549 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3550 | putIReg( rD_addr, mkSzWiden16(ty, val, True) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3551 | break; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3552 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3553 | case 0x2B: // lhau (Load HW Alg, Update, PPC32 p446) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3554 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3555 | vex_printf("dis_int_load(ppc)(lhau,rA_addr|rD_addr)\n"); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3556 | return False; |
| 3557 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3558 | DIP("lhau r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3559 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3560 | putIReg( rD_addr, mkSzWiden16(ty, val, True) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3561 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3562 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3563 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3564 | case 0x28: // lhz (Load HW & Zero, PPC32 p450) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3565 | DIP("lhz r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3566 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3567 | putIReg( rD_addr, mkSzWiden16(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3568 | break; |
| 3569 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3570 | case 0x29: // lhzu (Load HW & and Zero, Update, PPC32 p451) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3571 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3572 | vex_printf("dis_int_load(ppc)(lhzu,rA_addr|rD_addr)\n"); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 3573 | return False; |
| 3574 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3575 | DIP("lhzu r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3576 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3577 | putIReg( rD_addr, mkSzWiden16(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3578 | putIReg( rA_addr, mkexpr(EA) ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 3579 | break; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3580 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3581 | case 0x20: // lwz (Load W & Zero, PPC32 p460) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3582 | DIP("lwz r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3583 | val = loadBE(Ity_I32, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3584 | putIReg( rD_addr, mkSzWiden32(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3585 | break; |
| 3586 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3587 | case 0x21: // lwzu (Load W & Zero, Update, PPC32 p461)) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3588 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3589 | vex_printf("dis_int_load(ppc)(lwzu,rA_addr|rD_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3590 | return False; |
| 3591 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3592 | DIP("lwzu r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3593 | val = loadBE(Ity_I32, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3594 | putIReg( rD_addr, mkSzWiden32(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3595 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3596 | break; |
| 3597 | |
| 3598 | /* X Form */ |
| 3599 | case 0x1F: |
| 3600 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3601 | vex_printf("dis_int_load(ppc)(Ox1F,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3602 | return False; |
| 3603 | } |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3604 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3605 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3606 | case 0x077: // lbzux (Load B & Zero, Update Indexed, PPC32 p435) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3607 | DIP("lbzux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3608 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3609 | vex_printf("dis_int_load(ppc)(lwzux,rA_addr|rD_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3610 | return False; |
| 3611 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3612 | val = loadBE(Ity_I8, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3613 | putIReg( rD_addr, mkSzWiden8(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3614 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3615 | break; |
| 3616 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3617 | case 0x057: // lbzx (Load B & Zero, Indexed, PPC32 p436) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3618 | DIP("lbzx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3619 | val = loadBE(Ity_I8, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3620 | putIReg( rD_addr, mkSzWiden8(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3621 | break; |
| 3622 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3623 | case 0x177: // lhaux (Load HW Alg, Update Indexed, PPC32 p447) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3624 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3625 | vex_printf("dis_int_load(ppc)(lhaux,rA_addr|rD_addr)\n"); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3626 | return False; |
| 3627 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3628 | DIP("lhaux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3629 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3630 | putIReg( rD_addr, mkSzWiden16(ty, val, True) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3631 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3632 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3633 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3634 | case 0x157: // lhax (Load HW Alg, Indexed, PPC32 p448) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3635 | DIP("lhax r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3636 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3637 | putIReg( rD_addr, mkSzWiden16(ty, val, True) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3638 | break; |
| 3639 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3640 | case 0x137: // lhzux (Load HW & Zero, Update Indexed, PPC32 p452) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3641 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3642 | vex_printf("dis_int_load(ppc)(lhzux,rA_addr|rD_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3643 | return False; |
| 3644 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3645 | DIP("lhzux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3646 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3647 | putIReg( rD_addr, mkSzWiden16(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3648 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3649 | break; |
| 3650 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3651 | case 0x117: // lhzx (Load HW & Zero, Indexed, PPC32 p453) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3652 | DIP("lhzx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3653 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3654 | putIReg( rD_addr, mkSzWiden16(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3655 | break; |
cerion | 44997f2 | 2005-01-31 18:45:59 +0000 | [diff] [blame] | 3656 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3657 | case 0x037: // lwzux (Load W & Zero, Update Indexed, PPC32 p462) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3658 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3659 | vex_printf("dis_int_load(ppc)(lwzux,rA_addr|rD_addr)\n"); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3660 | return False; |
| 3661 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3662 | DIP("lwzux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3663 | val = loadBE(Ity_I32, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3664 | putIReg( rD_addr, mkSzWiden32(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3665 | putIReg( rA_addr, mkexpr(EA) ); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3666 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3667 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3668 | case 0x017: // lwzx (Load W & Zero, Indexed, PPC32 p463) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3669 | DIP("lwzx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3670 | val = loadBE(Ity_I32, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3671 | putIReg( rD_addr, mkSzWiden32(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3672 | break; |
cerion | 44997f2 | 2005-01-31 18:45:59 +0000 | [diff] [blame] | 3673 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3674 | |
| 3675 | /* 64bit Loads */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3676 | case 0x035: // ldux (Load DWord, Update Indexed, PPC64 p475) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3677 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3678 | vex_printf("dis_int_load(ppc)(ldux,rA_addr|rD_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3679 | return False; |
| 3680 | } |
| 3681 | DIP("ldux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3682 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 3683 | putIReg( rA_addr, mkexpr(EA) ); |
| 3684 | break; |
| 3685 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3686 | case 0x015: // ldx (Load DWord, Indexed, PPC64 p476) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3687 | DIP("ldx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3688 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 3689 | break; |
| 3690 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3691 | case 0x175: // lwaux (Load W Alg, Update Indexed, PPC64 p501) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3692 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3693 | vex_printf("dis_int_load(ppc)(lwaux,rA_addr|rD_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3694 | return False; |
| 3695 | } |
| 3696 | DIP("lwaux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3697 | putIReg( rD_addr, |
| 3698 | unop(Iop_32Sto64, loadBE(Ity_I32, mkexpr(EA))) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3699 | putIReg( rA_addr, mkexpr(EA) ); |
| 3700 | break; |
| 3701 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3702 | case 0x155: // lwax (Load W Alg, Indexed, PPC64 p502) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3703 | DIP("lwax r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3704 | putIReg( rD_addr, |
| 3705 | unop(Iop_32Sto64, loadBE(Ity_I32, mkexpr(EA))) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3706 | break; |
| 3707 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3708 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3709 | vex_printf("dis_int_load(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3710 | return False; |
| 3711 | } |
| 3712 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3713 | |
| 3714 | /* DS Form - 64bit Loads */ |
| 3715 | case 0x3A: |
| 3716 | switch (b1<<1 | b0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3717 | case 0x0: // ld (Load DWord, PPC64 p472) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3718 | DIP("ld r%u,%d(r%u)\n", rD_addr, simm16, rA_addr); |
| 3719 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 3720 | break; |
| 3721 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3722 | case 0x1: // ldu (Load DWord, Update, PPC64 p474) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3723 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3724 | vex_printf("dis_int_load(ppc)(ldu,rA_addr|rD_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3725 | return False; |
| 3726 | } |
| 3727 | DIP("ldu r%u,%d(r%u)\n", rD_addr, simm16, rA_addr); |
| 3728 | simm16 = simm16 & ~0x3; |
| 3729 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 3730 | putIReg( rA_addr, mkexpr(EA) ); |
| 3731 | break; |
| 3732 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3733 | case 0x2: // lwa (Load Word Alg, PPC64 p499) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3734 | DIP("lwa r%u,%d(r%u)\n", rD_addr, simm16, rA_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3735 | putIReg( rD_addr, |
| 3736 | unop(Iop_32Sto64, loadBE(Ity_I32, mkexpr(EA))) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3737 | break; |
| 3738 | |
| 3739 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3740 | vex_printf("dis_int_load(ppc)(0x3A, opc2)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3741 | return False; |
| 3742 | } |
| 3743 | break; |
| 3744 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3745 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3746 | vex_printf("dis_int_load(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3747 | return False; |
| 3748 | } |
| 3749 | return True; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | |
| 3753 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 3754 | /* |
| 3755 | Integer Store Instructions |
| 3756 | */ |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 3757 | static Bool dis_int_store ( UInt theInstr, VexMiscInfo* vmi ) |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3758 | { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3759 | /* D-Form, X-Form, DS-Form */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3760 | UChar opc1 = ifieldOPC(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3761 | UInt rS_addr = ifieldRegDS(theInstr); |
| 3762 | UInt rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3763 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3764 | UInt rB_addr = ifieldRegB(theInstr); |
| 3765 | UInt opc2 = ifieldOPClo10(theInstr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3766 | UChar b1 = ifieldBIT1(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3767 | UChar b0 = ifieldBIT0(theInstr); |
| 3768 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3769 | Int simm16 = extend_s_16to32(uimm16); |
| 3770 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 3771 | IRTemp rS = newTemp(ty); |
| 3772 | IRTemp rB = newTemp(ty); |
| 3773 | IRTemp EA = newTemp(ty); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3774 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3775 | assign( rB, getIReg(rB_addr) ); |
| 3776 | assign( rS, getIReg(rS_addr) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3777 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3778 | switch (opc1) { |
| 3779 | case 0x1F: // register offset |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3780 | assign( EA, ea_rAor0_idxd( rA_addr, rB_addr ) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3781 | break; |
| 3782 | case 0x3E: // immediate offset: 64bit |
| 3783 | simm16 = simm16 & 0xFFFFFFFC; |
| 3784 | default: // immediate offset |
| 3785 | assign( EA, ea_rAor0_simm( rA_addr, simm16 ) ); |
| 3786 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3789 | switch (opc1) { |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 3790 | case 0x26: // stb (Store B, PPC32 p509) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3791 | DIP("stb r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3792 | storeBE( mkexpr(EA), mkSzNarrow8(ty, mkexpr(rS)) ); |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 3793 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 3794 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3795 | case 0x27: // stbu (Store B, Update, PPC32 p510) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3796 | if (rA_addr == 0 ) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3797 | vex_printf("dis_int_store(ppc)(stbu,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3798 | return False; |
| 3799 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3800 | DIP("stbu r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3801 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3802 | storeBE( mkexpr(EA), mkSzNarrow8(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3803 | break; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3804 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3805 | case 0x2C: // sth (Store HW, PPC32 p522) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3806 | DIP("sth r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3807 | storeBE( mkexpr(EA), mkSzNarrow16(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3808 | break; |
| 3809 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3810 | case 0x2D: // sthu (Store HW, Update, PPC32 p524) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3811 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3812 | vex_printf("dis_int_store(ppc)(sthu,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3813 | return False; |
| 3814 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3815 | DIP("sthu r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3816 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3817 | storeBE( mkexpr(EA), mkSzNarrow16(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3818 | break; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3819 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3820 | case 0x24: // stw (Store W, PPC32 p530) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3821 | DIP("stw r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3822 | storeBE( mkexpr(EA), mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3823 | break; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3824 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3825 | case 0x25: // stwu (Store W, Update, PPC32 p534) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3826 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3827 | vex_printf("dis_int_store(ppc)(stwu,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3828 | return False; |
| 3829 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3830 | DIP("stwu r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3831 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3832 | storeBE( mkexpr(EA), mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3833 | break; |
| 3834 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3835 | /* X Form : all these use EA_indexed */ |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3836 | case 0x1F: |
| 3837 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3838 | vex_printf("dis_int_store(ppc)(0x1F,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3839 | return False; |
| 3840 | } |
cerion | 44997f2 | 2005-01-31 18:45:59 +0000 | [diff] [blame] | 3841 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3842 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3843 | case 0x0F7: // stbux (Store B, Update Indexed, PPC32 p511) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3844 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3845 | vex_printf("dis_int_store(ppc)(stbux,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3846 | return False; |
| 3847 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3848 | DIP("stbux r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3849 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3850 | storeBE( mkexpr(EA), mkSzNarrow8(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3851 | break; |
| 3852 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3853 | case 0x0D7: // stbx (Store B Indexed, PPC32 p512) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3854 | DIP("stbx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3855 | storeBE( mkexpr(EA), mkSzNarrow8(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3856 | break; |
| 3857 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3858 | case 0x1B7: // sthux (Store HW, Update Indexed, PPC32 p525) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3859 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3860 | vex_printf("dis_int_store(ppc)(sthux,rA_addr)\n"); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3861 | return False; |
| 3862 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3863 | DIP("sthux r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3864 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3865 | storeBE( mkexpr(EA), mkSzNarrow16(ty, mkexpr(rS)) ); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3866 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3867 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3868 | case 0x197: // sthx (Store HW Indexed, PPC32 p526) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3869 | DIP("sthx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3870 | storeBE( mkexpr(EA), mkSzNarrow16(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3871 | break; |
| 3872 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3873 | case 0x0B7: // stwux (Store W, Update Indexed, PPC32 p535) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3874 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3875 | vex_printf("dis_int_store(ppc)(stwux,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3876 | return False; |
| 3877 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3878 | DIP("stwux r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3879 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3880 | storeBE( mkexpr(EA), mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3881 | break; |
cerion | 44997f2 | 2005-01-31 18:45:59 +0000 | [diff] [blame] | 3882 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3883 | case 0x097: // stwx (Store W Indexed, PPC32 p536) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3884 | DIP("stwx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3885 | storeBE( mkexpr(EA), mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3886 | break; |
| 3887 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3888 | |
| 3889 | /* 64bit Stores */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3890 | case 0x0B5: // stdux (Store DWord, Update Indexed, PPC64 p584) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3891 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3892 | vex_printf("dis_int_store(ppc)(stdux,rA_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3893 | return False; |
| 3894 | } |
| 3895 | DIP("stdux r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
| 3896 | putIReg( rA_addr, mkexpr(EA) ); |
| 3897 | storeBE( mkexpr(EA), mkexpr(rS) ); |
| 3898 | break; |
| 3899 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3900 | case 0x095: // stdx (Store DWord Indexed, PPC64 p585) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3901 | DIP("stdx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
| 3902 | storeBE( mkexpr(EA), mkexpr(rS) ); |
| 3903 | break; |
| 3904 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3905 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3906 | vex_printf("dis_int_store(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3907 | return False; |
| 3908 | } |
| 3909 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3910 | |
| 3911 | /* DS Form - 64bit Stores */ |
| 3912 | case 0x3E: |
| 3913 | switch (b1<<1 | b0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3914 | case 0x0: // std (Store DWord, PPC64 p580) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3915 | DIP("std r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
| 3916 | storeBE( mkexpr(EA), mkexpr(rS) ); |
| 3917 | break; |
| 3918 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3919 | case 0x1: // stdu (Store DWord, Update, PPC64 p583) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3920 | DIP("stdu r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
| 3921 | putIReg( rA_addr, mkexpr(EA) ); |
| 3922 | storeBE( mkexpr(EA), mkexpr(rS) ); |
| 3923 | break; |
| 3924 | |
| 3925 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3926 | vex_printf("dis_int_load(ppc)(0x3A, opc2)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3927 | return False; |
| 3928 | } |
| 3929 | break; |
| 3930 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3931 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3932 | vex_printf("dis_int_store(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3933 | return False; |
| 3934 | } |
| 3935 | return True; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | |
| 3939 | |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3940 | /* |
| 3941 | Integer Load/Store Multiple Instructions |
| 3942 | */ |
| 3943 | static Bool dis_int_ldst_mult ( UInt theInstr ) |
| 3944 | { |
| 3945 | /* D-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3946 | UChar opc1 = ifieldOPC(theInstr); |
| 3947 | UChar rD_addr = ifieldRegDS(theInstr); |
| 3948 | UChar rS_addr = rD_addr; |
| 3949 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3950 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3951 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3952 | Int simm16 = extend_s_16to32(uimm16); |
| 3953 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 3954 | IRTemp EA = newTemp(ty); |
| 3955 | UInt r = 0; |
| 3956 | UInt ea_off = 0; |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3957 | IRExpr* irx_addr; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3958 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3959 | assign( EA, ea_rAor0_simm( rA_addr, simm16 ) ); |
| 3960 | |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3961 | switch (opc1) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3962 | case 0x2E: // lmw (Load Multiple Word, PPC32 p454) |
| 3963 | if (rA_addr >= rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3964 | vex_printf("dis_int_ldst_mult(ppc)(lmw,rA_addr)\n"); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3965 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3966 | } |
| 3967 | DIP("lmw r%u,%d(r%u)\n", rD_addr, simm16, rA_addr); |
| 3968 | for (r = rD_addr; r <= 31; r++) { |
| 3969 | irx_addr = binop(Iop_Add32, mkexpr(EA), mkU32(ea_off)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3970 | putIReg( r, mkSzWiden32(ty, loadBE(Ity_I32, irx_addr ), |
| 3971 | False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3972 | ea_off += 4; |
| 3973 | } |
| 3974 | break; |
| 3975 | |
| 3976 | case 0x2F: // stmw (Store Multiple Word, PPC32 p527) |
| 3977 | DIP("stmw r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
| 3978 | for (r = rS_addr; r <= 31; r++) { |
| 3979 | irx_addr = binop(Iop_Add32, mkexpr(EA), mkU32(ea_off)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3980 | storeBE( irx_addr, mkSzNarrow32(ty, getIReg(r)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3981 | ea_off += 4; |
| 3982 | } |
| 3983 | break; |
| 3984 | |
| 3985 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3986 | vex_printf("dis_int_ldst_mult(ppc)(opc1)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3987 | return False; |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3988 | } |
| 3989 | return True; |
| 3990 | } |
| 3991 | |
| 3992 | |
| 3993 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3994 | /* |
| 3995 | Integer Load/Store String Instructions |
| 3996 | */ |
| 3997 | static |
| 3998 | void generate_lsw_sequence ( IRTemp tNBytes, // # bytes, :: Ity_I32 |
| 3999 | IRTemp EA, // EA |
| 4000 | Int rD, // first dst register |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4001 | Int maxBytes ) // 32 or 128 |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4002 | { |
| 4003 | Int i, shift = 24; |
| 4004 | IRExpr* e_nbytes = mkexpr(tNBytes); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4005 | IRExpr* e_EA = mkexpr(EA); |
| 4006 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4007 | |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4008 | vassert(rD >= 0 && rD < 32); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4009 | rD--; if (rD < 0) rD = 31; |
| 4010 | |
| 4011 | for (i = 0; i < maxBytes; i++) { |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4012 | /* if (nBytes < (i+1)) goto NIA; */ |
| 4013 | stmt( IRStmt_Exit( binop(Iop_CmpLT32U, e_nbytes, mkU32(i+1)), |
| 4014 | Ijk_Boring, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4015 | mkSzConst( ty, nextInsnAddr()) )); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4016 | /* when crossing into a new dest register, set it to zero. */ |
| 4017 | if ((i % 4) == 0) { |
| 4018 | rD++; if (rD == 32) rD = 0; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4019 | putIReg(rD, mkSzImm(ty, 0)); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4020 | shift = 24; |
| 4021 | } |
| 4022 | /* rD |= (8Uto32(*(EA+i))) << shift */ |
| 4023 | vassert(shift == 0 || shift == 8 || shift == 16 || shift == 24); |
sewardj | 2ef8a37 | 2006-01-28 17:07:19 +0000 | [diff] [blame] | 4024 | putIReg( |
| 4025 | rD, |
| 4026 | mkSzWiden32( |
| 4027 | ty, |
| 4028 | binop( |
| 4029 | Iop_Or32, |
| 4030 | mkSzNarrow32(ty, getIReg(rD)), |
| 4031 | binop( |
| 4032 | Iop_Shl32, |
| 4033 | unop( |
| 4034 | Iop_8Uto32, |
| 4035 | loadBE(Ity_I8, |
| 4036 | binop(mkSzOp(ty,Iop_Add8), e_EA, mkSzImm(ty,i))) |
| 4037 | ), |
| 4038 | mkU8(toUChar(shift)) |
| 4039 | ) |
| 4040 | ), |
| 4041 | /*Signed*/False |
| 4042 | ) |
| 4043 | ); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4044 | shift -= 8; |
| 4045 | } |
| 4046 | } |
| 4047 | |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4048 | static |
| 4049 | void generate_stsw_sequence ( IRTemp tNBytes, // # bytes, :: Ity_I32 |
| 4050 | IRTemp EA, // EA |
| 4051 | Int rS, // first src register |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4052 | Int maxBytes ) // 32 or 128 |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4053 | { |
| 4054 | Int i, shift = 24; |
| 4055 | IRExpr* e_nbytes = mkexpr(tNBytes); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4056 | IRExpr* e_EA = mkexpr(EA); |
| 4057 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4058 | |
| 4059 | vassert(rS >= 0 && rS < 32); |
| 4060 | rS--; if (rS < 0) rS = 31; |
| 4061 | |
| 4062 | for (i = 0; i < maxBytes; i++) { |
| 4063 | /* if (nBytes < (i+1)) goto NIA; */ |
| 4064 | stmt( IRStmt_Exit( binop(Iop_CmpLT32U, e_nbytes, mkU32(i+1)), |
| 4065 | Ijk_Boring, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4066 | mkSzConst( ty, nextInsnAddr() ) )); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4067 | /* check for crossing into a new src register. */ |
| 4068 | if ((i % 4) == 0) { |
| 4069 | rS++; if (rS == 32) rS = 0; |
| 4070 | shift = 24; |
| 4071 | } |
| 4072 | /* *(EA+i) = 32to8(rS >> shift) */ |
| 4073 | vassert(shift == 0 || shift == 8 || shift == 16 || shift == 24); |
| 4074 | storeBE( |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4075 | binop(mkSzOp(ty,Iop_Add8), e_EA, mkSzImm(ty,i)), |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4076 | unop(Iop_32to8, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4077 | binop(Iop_Shr32, |
| 4078 | mkSzNarrow32(ty, getIReg(rS)), |
| 4079 | mkU8(toUChar(shift)))) |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4080 | ); |
| 4081 | shift -= 8; |
| 4082 | } |
| 4083 | } |
| 4084 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4085 | static Bool dis_int_ldst_str ( UInt theInstr, /*OUT*/Bool* stopHere ) |
| 4086 | { |
| 4087 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4088 | UChar opc1 = ifieldOPC(theInstr); |
| 4089 | UChar rD_addr = ifieldRegDS(theInstr); |
| 4090 | UChar rS_addr = rD_addr; |
| 4091 | UChar rA_addr = ifieldRegA(theInstr); |
| 4092 | UChar rB_addr = ifieldRegB(theInstr); |
| 4093 | UChar NumBytes = rB_addr; |
| 4094 | UInt opc2 = ifieldOPClo10(theInstr); |
| 4095 | UChar b0 = ifieldBIT0(theInstr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4096 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4097 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 4098 | IRTemp t_EA = newTemp(ty); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4099 | IRTemp t_nbytes = IRTemp_INVALID; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4100 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4101 | *stopHere = False; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4102 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4103 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4104 | vex_printf("dis_int_ldst_str(ppc)(opc1)\n"); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4105 | return False; |
| 4106 | } |
| 4107 | |
| 4108 | switch (opc2) { |
| 4109 | case 0x255: // lswi (Load String Word Immediate, PPC32 p455) |
| 4110 | /* NB: does not reject the case where RA is in the range of |
| 4111 | registers to be loaded. It should. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4112 | DIP("lswi r%u,r%u,%d\n", rD_addr, rA_addr, NumBytes); |
| 4113 | assign( t_EA, ea_rAor0(rA_addr) ); |
sewardj | 2ef8a37 | 2006-01-28 17:07:19 +0000 | [diff] [blame] | 4114 | if (NumBytes == 8 && !mode64) { |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4115 | /* Special case hack */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4116 | /* rD = Mem[EA]; (rD+1)%32 = Mem[EA+4] */ |
| 4117 | putIReg( rD_addr, |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4118 | loadBE(Ity_I32, mkexpr(t_EA)) ); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4119 | putIReg( (rD_addr+1) % 32, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4120 | loadBE(Ity_I32, |
| 4121 | binop(Iop_Add32, mkexpr(t_EA), mkU32(4))) ); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4122 | } else { |
| 4123 | t_nbytes = newTemp(Ity_I32); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4124 | assign( t_nbytes, mkU32(NumBytes==0 ? 32 : NumBytes) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4125 | generate_lsw_sequence( t_nbytes, t_EA, rD_addr, 32 ); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4126 | *stopHere = True; |
| 4127 | } |
| 4128 | return True; |
| 4129 | |
| 4130 | case 0x215: // lswx (Load String Word Indexed, PPC32 p456) |
| 4131 | /* NB: does not reject the case where RA is in the range of |
| 4132 | registers to be loaded. It should. Although considering |
| 4133 | that that can only be detected at run time, it's not easy to |
| 4134 | do so. */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4135 | if (rD_addr == rA_addr || rD_addr == rB_addr) |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4136 | return False; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4137 | if (rD_addr == 0 && rA_addr == 0) |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4138 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4139 | DIP("lswx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4140 | t_nbytes = newTemp(Ity_I32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4141 | assign( t_EA, ea_rAor0_idxd(rA_addr,rB_addr) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4142 | assign( t_nbytes, unop( Iop_8Uto32, getXER_BC() ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4143 | generate_lsw_sequence( t_nbytes, t_EA, rD_addr, 128 ); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4144 | *stopHere = True; |
| 4145 | return True; |
| 4146 | |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4147 | case 0x2D5: // stswi (Store String Word Immediate, PPC32 p528) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4148 | DIP("stswi r%u,r%u,%d\n", rS_addr, rA_addr, NumBytes); |
| 4149 | assign( t_EA, ea_rAor0(rA_addr) ); |
sewardj | 2ef8a37 | 2006-01-28 17:07:19 +0000 | [diff] [blame] | 4150 | if (NumBytes == 8 && !mode64) { |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4151 | /* Special case hack */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4152 | /* Mem[EA] = rD; Mem[EA+4] = (rD+1)%32 */ |
| 4153 | storeBE( mkexpr(t_EA), |
| 4154 | getIReg(rD_addr) ); |
| 4155 | storeBE( binop(Iop_Add32, mkexpr(t_EA), mkU32(4)), |
| 4156 | getIReg((rD_addr+1) % 32) ); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4157 | } else { |
| 4158 | t_nbytes = newTemp(Ity_I32); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4159 | assign( t_nbytes, mkU32(NumBytes==0 ? 32 : NumBytes) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4160 | generate_stsw_sequence( t_nbytes, t_EA, rD_addr, 32 ); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4161 | *stopHere = True; |
| 4162 | } |
| 4163 | return True; |
| 4164 | |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4165 | case 0x295: // stswx (Store String Word Indexed, PPC32 p529) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4166 | DIP("stswx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4167 | t_nbytes = newTemp(Ity_I32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4168 | assign( t_EA, ea_rAor0_idxd(rA_addr,rB_addr) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4169 | assign( t_nbytes, unop( Iop_8Uto32, getXER_BC() ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4170 | generate_stsw_sequence( t_nbytes, t_EA, rS_addr, 128 ); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4171 | *stopHere = True; |
| 4172 | return True; |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4173 | |
| 4174 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4175 | vex_printf("dis_int_ldst_str(ppc)(opc2)\n"); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4176 | return False; |
| 4177 | } |
| 4178 | return True; |
| 4179 | } |
| 4180 | |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 4181 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4182 | /* ------------------------------------------------------------------ |
| 4183 | Integer Branch Instructions |
| 4184 | ------------------------------------------------------------------ */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 4185 | |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4186 | /* |
| 4187 | Branch helper function |
| 4188 | ok = BO[2] | ((CTR[0] != 0) ^ BO[1]) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4189 | Returns an I32 which is 0x00000000 if the ctr condition failed |
| 4190 | and 0xFFFFFFFF otherwise. |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4191 | */ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4192 | static IRExpr* /* :: Ity_I32 */ branch_ctr_ok( UInt BO ) |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4193 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4194 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4195 | IRTemp ok = newTemp(Ity_I32); |
cerion | ed623db | 2005-06-20 12:42:04 +0000 | [diff] [blame] | 4196 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4197 | if ((BO >> 2) & 1) { // independent of ctr |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4198 | assign( ok, mkU32(0xFFFFFFFF) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4199 | } else { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4200 | if ((BO >> 1) & 1) { // ctr == 0 ? |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4201 | assign( ok, unop( Iop_1Sto32, |
cerion | 4e2c2b3 | 2006-01-02 13:35:51 +0000 | [diff] [blame] | 4202 | binop( mkSzOp(ty, Iop_CmpEQ8), |
| 4203 | getGST( PPC_GST_CTR ), |
| 4204 | mkSzImm(ty,0))) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4205 | } else { // ctr != 0 ? |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4206 | assign( ok, unop( Iop_1Sto32, |
cerion | 4e2c2b3 | 2006-01-02 13:35:51 +0000 | [diff] [blame] | 4207 | binop( mkSzOp(ty, Iop_CmpNE8), |
| 4208 | getGST( PPC_GST_CTR ), |
| 4209 | mkSzImm(ty,0))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4210 | } |
| 4211 | } |
| 4212 | return mkexpr(ok); |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4213 | } |
| 4214 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4215 | |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4216 | /* |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4217 | Branch helper function cond_ok = BO[4] | (CR[BI] == BO[3]) |
| 4218 | Returns an I32 which is either 0 if the condition failed or |
| 4219 | some arbitrary nonzero value otherwise. */ |
| 4220 | |
| 4221 | static IRExpr* /* :: Ity_I32 */ branch_cond_ok( UInt BO, UInt BI ) |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4222 | { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4223 | Int where; |
| 4224 | IRTemp res = newTemp(Ity_I32); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4225 | IRTemp cr_bi = newTemp(Ity_I32); |
| 4226 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4227 | if ((BO >> 4) & 1) { |
| 4228 | assign( res, mkU32(1) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4229 | } else { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4230 | // ok = (CR[BI] == BO[3]) Note, the following relies on |
| 4231 | // getCRbit_anywhere returning a value which |
| 4232 | // is either zero or has exactly 1 bit set. |
| 4233 | assign( cr_bi, getCRbit_anywhere( BI, &where ) ); |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4234 | |
| 4235 | if ((BO >> 3) & 1) { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4236 | /* We can use cr_bi as-is. */ |
| 4237 | assign( res, mkexpr(cr_bi) ); |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4238 | } else { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4239 | /* We have to invert the sense of the information held in |
| 4240 | cr_bi. For that we need to know which bit |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4241 | getCRbit_anywhere regards as significant. */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4242 | assign( res, binop(Iop_Xor32, mkexpr(cr_bi), |
| 4243 | mkU32(1<<where)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4244 | } |
| 4245 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4246 | return mkexpr(res); |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4250 | /* |
| 4251 | Integer Branch Instructions |
| 4252 | */ |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4253 | static Bool dis_branch ( UInt theInstr, |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 4254 | VexMiscInfo* vmi, |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4255 | /*OUT*/DisResult* dres, |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 4256 | Bool (*resteerOkFn)(void*,Addr64), |
| 4257 | void* callback_opaque ) |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 4258 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4259 | UChar opc1 = ifieldOPC(theInstr); |
| 4260 | UChar BO = ifieldRegDS(theInstr); |
| 4261 | UChar BI = ifieldRegA(theInstr); |
| 4262 | UInt BD_u16 = ifieldUIMM16(theInstr) & 0xFFFFFFFC; /* mask off */ |
| 4263 | UChar b11to15 = ifieldRegB(theInstr); |
| 4264 | UInt opc2 = ifieldOPClo10(theInstr); |
| 4265 | UInt LI_u26 = ifieldUIMM26(theInstr) & 0xFFFFFFFC; /* mask off */ |
| 4266 | UChar flag_AA = ifieldBIT1(theInstr); |
| 4267 | UChar flag_LK = ifieldBIT0(theInstr); |
| 4268 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4269 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4270 | Addr64 tgt = 0; |
| 4271 | Int BD = extend_s_16to32(BD_u16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4272 | IRTemp do_branch = newTemp(Ity_I32); |
| 4273 | IRTemp ctr_ok = newTemp(Ity_I32); |
| 4274 | IRTemp cond_ok = newTemp(Ity_I32); |
| 4275 | IRExpr* e_nia = mkSzImm(ty, nextInsnAddr()); |
| 4276 | IRConst* c_nia = mkSzConst(ty, nextInsnAddr()); |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4277 | IRTemp lr_old = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4278 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4279 | /* Hack to pass through code that just wants to read the PC */ |
| 4280 | if (theInstr == 0x429F0005) { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4281 | DIP("bcl 0x%x, 0x%x (a.k.a mr lr,cia+4)\n", BO, BI); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4282 | putGST( PPC_GST_LR, e_nia ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4283 | return True; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4284 | } |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4285 | |
| 4286 | /* The default what-next. Individual cases can override it. */ |
| 4287 | dres->whatNext = Dis_StopHere; |
| 4288 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4289 | switch (opc1) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4290 | case 0x12: // b (Branch, PPC32 p360) |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 4291 | if (flag_AA) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4292 | tgt = mkSzAddr( ty, extend_s_26to64(LI_u26) ); |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 4293 | } else { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4294 | tgt = mkSzAddr( ty, guest_CIA_curr_instr + |
| 4295 | (Long)extend_s_26to64(LI_u26) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4296 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4297 | if (mode64) { |
| 4298 | DIP("b%s%s 0x%llx\n", |
| 4299 | flag_LK ? "l" : "", flag_AA ? "a" : "", tgt); |
| 4300 | } else { |
| 4301 | DIP("b%s%s 0x%x\n", |
| 4302 | flag_LK ? "l" : "", flag_AA ? "a" : "", (Addr32)tgt); |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 4305 | if (flag_LK) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4306 | putGST( PPC_GST_LR, e_nia ); |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 4307 | if (vmi->guest_ppc_zap_RZ_at_bl |
| 4308 | && vmi->guest_ppc_zap_RZ_at_bl( (ULong)tgt) ) |
| 4309 | make_redzone_AbiHint( vmi, |
| 4310 | "branch-and-link (unconditional call)" ); |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 4311 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4312 | |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 4313 | if (resteerOkFn( callback_opaque, tgt )) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4314 | dres->whatNext = Dis_Resteer; |
| 4315 | dres->continueAt = tgt; |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4316 | } else { |
| 4317 | irbb->jumpkind = flag_LK ? Ijk_Call : Ijk_Boring; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4318 | irbb->next = mkSzImm(ty, tgt); |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4319 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4320 | break; |
| 4321 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4322 | case 0x10: // bc (Branch Conditional, PPC32 p361) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4323 | DIP("bc%s%s 0x%x, 0x%x, 0x%x\n", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4324 | flag_LK ? "l" : "", flag_AA ? "a" : "", BO, BI, BD); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4325 | |
| 4326 | if (!(BO & 0x4)) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4327 | putGST( PPC_GST_CTR, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4328 | binop(mkSzOp(ty, Iop_Sub8), |
| 4329 | getGST( PPC_GST_CTR ), mkSzImm(ty, 1)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4330 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4331 | |
| 4332 | /* This is a bit subtle. ctr_ok is either all 0s or all 1s. |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4333 | cond_ok is either zero or nonzero, since that's the cheapest |
| 4334 | way to compute it. Anding them together gives a value which |
| 4335 | is either zero or non zero and so that's what we must test |
| 4336 | for in the IRStmt_Exit. */ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4337 | assign( ctr_ok, branch_ctr_ok( BO ) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4338 | assign( cond_ok, branch_cond_ok( BO, BI ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4339 | assign( do_branch, |
| 4340 | binop(Iop_And32, mkexpr(cond_ok), mkexpr(ctr_ok)) ); |
| 4341 | |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 4342 | if (flag_AA) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4343 | tgt = mkSzAddr(ty, extend_s_16to64(BD_u16)); |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 4344 | } else { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4345 | tgt = mkSzAddr(ty, guest_CIA_curr_instr + |
| 4346 | (Long)extend_s_16to64(BD_u16)); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4347 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4348 | if (flag_LK) |
| 4349 | putGST( PPC_GST_LR, e_nia ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4350 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4351 | stmt( IRStmt_Exit( |
| 4352 | binop(Iop_CmpNE32, mkexpr(do_branch), mkU32(0)), |
| 4353 | flag_LK ? Ijk_Call : Ijk_Boring, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4354 | mkSzConst(ty, tgt) ) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4355 | |
| 4356 | irbb->jumpkind = Ijk_Boring; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4357 | irbb->next = e_nia; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4358 | break; |
| 4359 | |
| 4360 | case 0x13: |
sewardj | 6be6723 | 2006-01-24 19:00:05 +0000 | [diff] [blame] | 4361 | /* For bclr and bcctr, it appears that the lowest two bits of |
| 4362 | b11to15 are a branch hint, and so we only need to ensure it's |
| 4363 | of the form 000XX. */ |
| 4364 | if ((b11to15 & ~3) != 0) { |
| 4365 | vex_printf("dis_int_branch(ppc)(0x13,b11to15)(%d)\n", (Int)b11to15); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4366 | return False; |
| 4367 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 4368 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4369 | switch (opc2) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4370 | case 0x210: // bcctr (Branch Cond. to Count Register, PPC32 p363) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4371 | if ((BO & 0x4) == 0) { // "decr and test CTR" option invalid |
| 4372 | vex_printf("dis_int_branch(ppc)(bcctr,BO)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4373 | return False; |
| 4374 | } |
cerion | a31e8b5 | 2005-02-21 16:30:45 +0000 | [diff] [blame] | 4375 | DIP("bcctr%s 0x%x, 0x%x\n", flag_LK ? "l" : "", BO, BI); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4376 | |
| 4377 | assign( cond_ok, branch_cond_ok( BO, BI ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4378 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4379 | assign( lr_old, addr_align( getGST( PPC_GST_CTR ), 4 )); |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4380 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4381 | if (flag_LK) |
| 4382 | putGST( PPC_GST_LR, e_nia ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4383 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4384 | stmt( IRStmt_Exit( |
| 4385 | binop(Iop_CmpEQ32, mkexpr(cond_ok), mkU32(0)), |
| 4386 | Ijk_Boring, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4387 | c_nia )); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4388 | |
| 4389 | irbb->jumpkind = flag_LK ? Ijk_Call : Ijk_Boring; |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4390 | irbb->next = mkexpr(lr_old); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4391 | break; |
| 4392 | |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 4393 | case 0x010: { // bclr (Branch Cond. to Link Register, PPC32 p365) |
| 4394 | Bool vanilla_return = False; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4395 | if ((BO & 0x14 /* 1z1zz */) == 0x14 && flag_LK == 0) { |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 4396 | DIP("blr\n"); |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 4397 | vanilla_return = True; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4398 | } else { |
| 4399 | DIP("bclr%s 0x%x, 0x%x\n", flag_LK ? "l" : "", BO, BI); |
| 4400 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 4401 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4402 | if (!(BO & 0x4)) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4403 | putGST( PPC_GST_CTR, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4404 | binop(mkSzOp(ty, Iop_Sub8), |
| 4405 | getGST( PPC_GST_CTR ), mkSzImm(ty, 1)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4406 | } |
| 4407 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4408 | /* See comments above for 'bc' about this */ |
| 4409 | assign( ctr_ok, branch_ctr_ok( BO ) ); |
| 4410 | assign( cond_ok, branch_cond_ok( BO, BI ) ); |
| 4411 | assign( do_branch, |
| 4412 | binop(Iop_And32, mkexpr(cond_ok), mkexpr(ctr_ok)) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4413 | |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4414 | assign( lr_old, addr_align( getGST( PPC_GST_LR ), 4 )); |
| 4415 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4416 | if (flag_LK) |
| 4417 | putGST( PPC_GST_LR, e_nia ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4418 | |
| 4419 | stmt( IRStmt_Exit( |
| 4420 | binop(Iop_CmpEQ32, mkexpr(do_branch), mkU32(0)), |
| 4421 | Ijk_Boring, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4422 | c_nia )); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4423 | |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 4424 | if (vanilla_return && vmi->guest_ppc_zap_RZ_at_blr) |
| 4425 | make_redzone_AbiHint( vmi, "branch-to-lr (unconditional return)" ); |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 4426 | |
sewardj | d37be03 | 2005-11-12 12:56:31 +0000 | [diff] [blame] | 4427 | /* blrl is pretty strange; it's like a return that sets the |
| 4428 | return address of its caller to the insn following this |
| 4429 | one. Mark it as a return. */ |
| 4430 | irbb->jumpkind = Ijk_Ret; /* was flag_LK ? Ijk_Call : Ijk_Ret; */ |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4431 | irbb->next = mkexpr(lr_old); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4432 | break; |
sewardj | cf8986c | 2006-01-18 04:14:52 +0000 | [diff] [blame] | 4433 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4434 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4435 | vex_printf("dis_int_branch(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4436 | return False; |
| 4437 | } |
| 4438 | break; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4439 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4440 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4441 | vex_printf("dis_int_branch(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4442 | return False; |
| 4443 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4444 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4445 | return True; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | |
| 4449 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4450 | /* |
| 4451 | Condition Register Logical Instructions |
| 4452 | */ |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4453 | static Bool dis_cond_logic ( UInt theInstr ) |
| 4454 | { |
| 4455 | /* XL-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4456 | UChar opc1 = ifieldOPC(theInstr); |
| 4457 | UChar crbD_addr = ifieldRegDS(theInstr); |
| 4458 | UChar crfD_addr = toUChar( IFIELD(theInstr, 23, 3) ); |
| 4459 | UChar crbA_addr = ifieldRegA(theInstr); |
| 4460 | UChar crfS_addr = toUChar( IFIELD(theInstr, 18, 3) ); |
| 4461 | UChar crbB_addr = ifieldRegB(theInstr); |
| 4462 | UInt opc2 = ifieldOPClo10(theInstr); |
| 4463 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4464 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4465 | IRTemp crbD = newTemp(Ity_I32); |
| 4466 | IRTemp crbA = newTemp(Ity_I32); |
| 4467 | IRTemp crbB = newTemp(Ity_I32); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4468 | |
| 4469 | if (opc1 != 19 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4470 | vex_printf("dis_cond_logic(ppc)(opc1)\n"); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4471 | return False; |
| 4472 | } |
| 4473 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4474 | if (opc2 == 0) { // mcrf (Move Cond Reg Field, PPC32 p464) |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4475 | if (((crbD_addr & 0x3) != 0) || |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4476 | ((crbA_addr & 0x3) != 0) || (crbB_addr != 0)) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4477 | vex_printf("dis_cond_logic(ppc)(crbD|crbA|crbB != 0)\n"); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4478 | return False; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4479 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4480 | DIP("mcrf cr%u,cr%u\n", crfD_addr, crfS_addr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4481 | putCR0( crfD_addr, getCR0( crfS_addr) ); |
| 4482 | putCR321( crfD_addr, getCR321(crfS_addr) ); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4483 | } else { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4484 | assign( crbA, getCRbit(crbA_addr) ); |
cerion | a50fde5 | 2005-07-01 21:16:10 +0000 | [diff] [blame] | 4485 | if (crbA_addr == crbB_addr) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4486 | crbB = crbA; |
cerion | a50fde5 | 2005-07-01 21:16:10 +0000 | [diff] [blame] | 4487 | else |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4488 | assign( crbB, getCRbit(crbB_addr) ); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4489 | |
| 4490 | switch (opc2) { |
sewardj | 7c2dc71 | 2005-09-08 17:33:27 +0000 | [diff] [blame] | 4491 | case 0x101: // crand (Cond Reg AND, PPC32 p372) |
| 4492 | DIP("crand crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4493 | assign( crbD, binop(Iop_And32, mkexpr(crbA), mkexpr(crbB)) ); |
| 4494 | break; |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4495 | case 0x081: // crandc (Cond Reg AND w. Complement, PPC32 p373) |
| 4496 | DIP("crandc crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4497 | assign( crbD, binop(Iop_And32, |
| 4498 | mkexpr(crbA), |
| 4499 | unop(Iop_Not32, mkexpr(crbB))) ); |
| 4500 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 4501 | case 0x121: // creqv (Cond Reg Equivalent, PPC32 p374) |
| 4502 | DIP("creqv crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4503 | assign( crbD, unop(Iop_Not32, |
| 4504 | binop(Iop_Xor32, mkexpr(crbA), mkexpr(crbB))) ); |
| 4505 | break; |
sewardj | 7c2dc71 | 2005-09-08 17:33:27 +0000 | [diff] [blame] | 4506 | case 0x0E1: // crnand (Cond Reg NAND, PPC32 p375) |
| 4507 | DIP("crnand crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4508 | assign( crbD, unop(Iop_Not32, |
| 4509 | binop(Iop_And32, mkexpr(crbA), mkexpr(crbB))) ); |
| 4510 | break; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4511 | case 0x021: // crnor (Cond Reg NOR, PPC32 p376) |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4512 | DIP("crnor crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4513 | assign( crbD, unop(Iop_Not32, |
| 4514 | binop(Iop_Or32, mkexpr(crbA), mkexpr(crbB))) ); |
| 4515 | break; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4516 | case 0x1C1: // cror (Cond Reg OR, PPC32 p377) |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4517 | DIP("cror crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4518 | assign( crbD, binop(Iop_Or32, mkexpr(crbA), mkexpr(crbB)) ); |
| 4519 | break; |
sewardj | 7c2dc71 | 2005-09-08 17:33:27 +0000 | [diff] [blame] | 4520 | case 0x1A1: // crorc (Cond Reg OR w. Complement, PPC32 p378) |
| 4521 | DIP("crorc crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4522 | assign( crbD, binop(Iop_Or32, |
| 4523 | mkexpr(crbA), |
| 4524 | unop(Iop_Not32, mkexpr(crbB))) ); |
| 4525 | break; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4526 | case 0x0C1: // crxor (Cond Reg XOR, PPC32 p379) |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4527 | DIP("crxor crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4528 | assign( crbD, binop(Iop_Xor32, mkexpr(crbA), mkexpr(crbB)) ); |
| 4529 | break; |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4530 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4531 | vex_printf("dis_cond_logic(ppc)(opc2)\n"); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4532 | return False; |
| 4533 | } |
| 4534 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4535 | putCRbit( crbD_addr, mkexpr(crbD) ); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4536 | } |
| 4537 | return True; |
| 4538 | } |
| 4539 | |
| 4540 | |
sewardj | 334870d | 2006-02-07 16:42:39 +0000 | [diff] [blame] | 4541 | /* |
| 4542 | Trap instructions |
| 4543 | */ |
| 4544 | |
| 4545 | /* Do the code generation for a trap. Returned Bool is true iff |
| 4546 | this is an unconditional trap. */ |
sewardj | 2d19fe3 | 2006-02-07 20:55:08 +0000 | [diff] [blame] | 4547 | static Bool do_trap ( Bool is_twi, UChar TO, |
sewardj | 334870d | 2006-02-07 16:42:39 +0000 | [diff] [blame] | 4548 | IRExpr* argL0, ULong argR0, Addr64 cia ) |
| 4549 | { |
| 4550 | IRTemp argL, argR; |
| 4551 | IRExpr *argLe, *argRe, *cond, *tmp; |
| 4552 | |
sewardj | 2d19fe3 | 2006-02-07 20:55:08 +0000 | [diff] [blame] | 4553 | IROp opAND = is_twi ? Iop_And32 : Iop_And64; |
| 4554 | IROp opOR = is_twi ? Iop_Or32 : Iop_Or64; |
| 4555 | IROp opCMPORDS = is_twi ? Iop_CmpORD32S : Iop_CmpORD64S; |
| 4556 | IROp opCMPORDU = is_twi ? Iop_CmpORD32U : Iop_CmpORD64U; |
| 4557 | IROp opCMPNE = is_twi ? Iop_CmpNE32 : Iop_CmpNE64; |
| 4558 | IROp opCMPEQ = is_twi ? Iop_CmpEQ32 : Iop_CmpEQ64; |
| 4559 | IRExpr* const0 = is_twi ? mkU32(0) : mkU64(0); |
| 4560 | IRExpr* const2 = is_twi ? mkU32(2) : mkU64(2); |
| 4561 | IRExpr* const4 = is_twi ? mkU32(4) : mkU64(4); |
| 4562 | IRExpr* const8 = is_twi ? mkU32(8) : mkU64(8); |
sewardj | 334870d | 2006-02-07 16:42:39 +0000 | [diff] [blame] | 4563 | |
| 4564 | const UChar b11100 = 0x1C; |
| 4565 | const UChar b00111 = 0x07; |
| 4566 | |
| 4567 | if ((TO & b11100) == b11100 || (TO & b00111) == b00111) { |
| 4568 | /* Unconditional trap. Just do the exit without |
| 4569 | testing the arguments. */ |
| 4570 | stmt( IRStmt_Exit( |
| 4571 | binop(opCMPEQ, const0, const0), |
| 4572 | Ijk_Trap, |
| 4573 | mode64 ? IRConst_U64(cia) : IRConst_U32((UInt)cia) |
| 4574 | )); |
| 4575 | return True; /* unconditional trap */ |
| 4576 | } |
| 4577 | |
sewardj | 2d19fe3 | 2006-02-07 20:55:08 +0000 | [diff] [blame] | 4578 | if (is_twi) { |
| 4579 | argL = newTemp(Ity_I32); |
| 4580 | argR = newTemp(Ity_I32); |
| 4581 | assign( argL, mode64 ? mkSzNarrow32(Ity_I64,argL0) |
| 4582 | : argL0 ); |
sewardj | 334870d | 2006-02-07 16:42:39 +0000 | [diff] [blame] | 4583 | assign( argR, mkU32( (UInt)argR0 )); |
| 4584 | } else { |
| 4585 | vassert(mode64); |
sewardj | 2d19fe3 | 2006-02-07 20:55:08 +0000 | [diff] [blame] | 4586 | argL = newTemp(Ity_I64); |
| 4587 | argR = newTemp(Ity_I64); |
sewardj | 334870d | 2006-02-07 16:42:39 +0000 | [diff] [blame] | 4588 | assign( argL, argL0 ); |
| 4589 | assign( argR, mkU64( argR0 )); |
| 4590 | } |
| 4591 | argLe = mkexpr(argL); |
| 4592 | argRe = mkexpr(argR); |
| 4593 | cond = const0; |
| 4594 | if (TO & 16) { // L <s R |
| 4595 | tmp = binop(opAND, binop(opCMPORDS, argLe, argRe), const8); |
| 4596 | cond = binop(opOR, tmp, cond); |
| 4597 | } |
| 4598 | if (TO & 8) { // L >s R |
| 4599 | tmp = binop(opAND, binop(opCMPORDS, argLe, argRe), const4); |
| 4600 | cond = binop(opOR, tmp, cond); |
| 4601 | } |
| 4602 | if (TO & 4) { // L == R |
| 4603 | tmp = binop(opAND, binop(opCMPORDS, argLe, argRe), const2); |
| 4604 | cond = binop(opOR, tmp, cond); |
| 4605 | } |
| 4606 | if (TO & 2) { // L <u R |
| 4607 | tmp = binop(opAND, binop(opCMPORDU, argLe, argRe), const8); |
| 4608 | cond = binop(opOR, tmp, cond); |
| 4609 | } |
| 4610 | if (TO & 1) { // L >u R |
| 4611 | tmp = binop(opAND, binop(opCMPORDU, argLe, argRe), const4); |
| 4612 | cond = binop(opOR, tmp, cond); |
| 4613 | } |
| 4614 | stmt( IRStmt_Exit( |
| 4615 | binop(opCMPNE, cond, const0), |
| 4616 | Ijk_Trap, |
| 4617 | mode64 ? IRConst_U64(cia) : IRConst_U32((UInt)cia) |
| 4618 | )); |
| 4619 | return False; /* not an unconditional trap */ |
| 4620 | } |
| 4621 | |
| 4622 | static Bool dis_trapi ( UInt theInstr, |
| 4623 | /*OUT*/DisResult* dres ) |
| 4624 | { |
| 4625 | /* D-Form */ |
| 4626 | UChar opc1 = ifieldOPC(theInstr); |
| 4627 | UChar TO = ifieldRegDS(theInstr); |
| 4628 | UChar rA_addr = ifieldRegA(theInstr); |
| 4629 | UInt uimm16 = ifieldUIMM16(theInstr); |
| 4630 | ULong simm16 = extend_s_16to64(uimm16); |
| 4631 | Addr64 cia = guest_CIA_curr_instr; |
| 4632 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 4633 | Bool uncond = False; |
| 4634 | |
| 4635 | switch (opc1) { |
| 4636 | case 0x03: // twi (Trap Word Immediate, PPC32 p548) |
sewardj | 2d19fe3 | 2006-02-07 20:55:08 +0000 | [diff] [blame] | 4637 | uncond = do_trap( True/*is_twi*/, TO, getIReg(rA_addr), simm16, cia ); |
sewardj | 334870d | 2006-02-07 16:42:39 +0000 | [diff] [blame] | 4638 | if (TO == 4) { |
| 4639 | DIP("tweqi r%u,%d\n", (UInt)rA_addr, (Int)simm16); |
| 4640 | } else { |
| 4641 | DIP("tw%di r%u,%d\n", (Int)TO, (UInt)rA_addr, (Int)simm16); |
| 4642 | } |
| 4643 | break; |
| 4644 | case 0x02: // tdi |
| 4645 | if (!mode64) |
| 4646 | return False; |
sewardj | 2d19fe3 | 2006-02-07 20:55:08 +0000 | [diff] [blame] | 4647 | uncond = do_trap( False/*!is_twi*/, TO, getIReg(rA_addr), simm16, cia ); |
| 4648 | if (TO == 4) { |
| 4649 | DIP("tdeqi r%u,%d\n", (UInt)rA_addr, (Int)simm16); |
| 4650 | } else { |
| 4651 | DIP("td%di r%u,%d\n", (Int)TO, (UInt)rA_addr, (Int)simm16); |
| 4652 | } |
sewardj | 334870d | 2006-02-07 16:42:39 +0000 | [diff] [blame] | 4653 | break; |
| 4654 | default: |
| 4655 | return False; |
| 4656 | } |
| 4657 | |
| 4658 | if (uncond) { |
| 4659 | /* If the trap shows signs of being unconditional, don't |
| 4660 | continue decoding past it. */ |
| 4661 | irbb->next = mkSzImm( ty, nextInsnAddr() ); |
| 4662 | irbb->jumpkind = Ijk_Boring; |
| 4663 | dres->whatNext = Dis_StopHere; |
| 4664 | } |
| 4665 | |
| 4666 | return True; |
| 4667 | } |
| 4668 | |
| 4669 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4670 | /* |
| 4671 | System Linkage Instructions |
| 4672 | */ |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 4673 | static Bool dis_syslink ( UInt theInstr, |
| 4674 | VexMiscInfo* miscinfo, DisResult* dres ) |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4675 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4676 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 4677 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4678 | if (theInstr != 0x44000002) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4679 | vex_printf("dis_syslink(ppc)(theInstr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4680 | return False; |
| 4681 | } |
cerion | e1d857b | 2005-02-04 18:29:05 +0000 | [diff] [blame] | 4682 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4683 | // sc (System Call, PPC32 p504) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4684 | DIP("sc\n"); |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 4685 | |
| 4686 | /* Copy CIA into the CIA_AT_SC pseudo-register, so that on AIX |
| 4687 | Valgrind can back the guest up to this instruction if it needs |
| 4688 | to restart the syscall. */ |
| 4689 | putGST( PPC_GST_CIA_AT_SC, getGST( PPC_GST_CIA ) ); |
| 4690 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4691 | /* It's important that all ArchRegs carry their up-to-date value |
| 4692 | at this point. So we declare an end-of-block here, which |
| 4693 | forces any TempRegs caching ArchRegs to be flushed. */ |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 4694 | /* At this point, AIX's behaviour differs from Linux's: AIX resumes |
| 4695 | after the syscall at %lr, whereas Linux does the obvious thing |
| 4696 | and resumes at the next instruction. Hence we need to encode |
| 4697 | that into the generated IR. */ |
| 4698 | irbb->next = miscinfo->guest_ppc_sc_continues_at_LR |
| 4699 | ? /*AIXishly*/getGST( PPC_GST_LR ) |
| 4700 | : /*Linuxfully*/mkSzImm( ty, nextInsnAddr() ); |
sewardj | 4fa325a | 2005-11-03 13:27:24 +0000 | [diff] [blame] | 4701 | irbb->jumpkind = Ijk_Sys_syscall; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4702 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 4703 | dres->whatNext = Dis_StopHere; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4704 | return True; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4705 | } |
| 4706 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4707 | |
| 4708 | /* |
| 4709 | Memory Synchronization Instructions |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4710 | |
| 4711 | Note on Reservations: |
| 4712 | We rely on the assumption that V will in fact only allow one thread at |
| 4713 | once to run. In effect, a thread can make a reservation, but we don't |
| 4714 | check any stores it does. Instead, the reservation is cancelled when |
| 4715 | the scheduler switches to another thread (run_thread_for_a_while()). |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4716 | */ |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4717 | static Bool dis_memsync ( UInt theInstr ) |
| 4718 | { |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4719 | /* X-Form, XL-Form */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4720 | UChar opc1 = ifieldOPC(theInstr); |
| 4721 | UInt b11to25 = IFIELD(theInstr, 11, 15); |
cerion | e43bc88 | 2006-01-05 13:11:59 +0000 | [diff] [blame] | 4722 | UChar flag_L = ifieldRegDS(theInstr); |
| 4723 | UInt b11to20 = IFIELD(theInstr, 11, 10); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4724 | UChar rD_addr = ifieldRegDS(theInstr); |
| 4725 | UChar rS_addr = rD_addr; |
| 4726 | UChar rA_addr = ifieldRegA(theInstr); |
| 4727 | UChar rB_addr = ifieldRegB(theInstr); |
| 4728 | UInt opc2 = ifieldOPClo10(theInstr); |
| 4729 | UChar b0 = ifieldBIT0(theInstr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4730 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4731 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 4732 | IRTemp EA = newTemp(ty); |
| 4733 | IRTemp rS = newTemp(ty); |
| 4734 | |
| 4735 | assign( EA, ea_rAor0_idxd( rA_addr, rB_addr ) ); |
| 4736 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4737 | switch (opc1) { |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 4738 | /* XL-Form */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4739 | case 0x13: // isync (Instruction Synchronize, PPC32 p432) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4740 | if (opc2 != 0x096) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4741 | vex_printf("dis_memsync(ppc)(0x13,opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4742 | return False; |
| 4743 | } |
| 4744 | if (b11to25 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4745 | vex_printf("dis_memsync(ppc)(0x13,b11to25|b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4746 | return False; |
| 4747 | } |
| 4748 | DIP("isync\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4749 | stmt( IRStmt_MFence() ); |
| 4750 | break; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4751 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4752 | /* X-Form */ |
| 4753 | case 0x1F: |
| 4754 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4755 | case 0x356: // eieio (Enforce In-Order Exec of I/O, PPC32 p394) |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4756 | if (b11to25 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4757 | vex_printf("dis_memsync(ppc)(eiei0,b11to25|b0)\n"); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4758 | return False; |
| 4759 | } |
| 4760 | DIP("eieio\n"); |
| 4761 | /* Insert a memory fence, just to be on the safe side. */ |
| 4762 | stmt( IRStmt_MFence() ); |
| 4763 | break; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4764 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4765 | case 0x014: // lwarx (Load Word and Reserve Indexed, PPC32 p458) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4766 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4767 | vex_printf("dis_memsync(ppc)(lwarx,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4768 | return False; |
| 4769 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4770 | DIP("lwarx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4771 | putIReg( rD_addr, mkSzWiden32(ty, loadBE(Ity_I32, mkexpr(EA)), |
| 4772 | False) ); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4773 | /* Take a reservation */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4774 | putGST( PPC_GST_RESVN, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4775 | break; |
| 4776 | |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4777 | case 0x096: { |
| 4778 | // stwcx. (Store Word Conditional Indexed, PPC32 p532) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4779 | IRTemp resaddr = newTemp(ty); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4780 | if (b0 != 1) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4781 | vex_printf("dis_memsync(ppc)(stwcx.,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4782 | return False; |
| 4783 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4784 | DIP("stwcx. r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4785 | assign( rS, getIReg(rS_addr) ); |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 4786 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4787 | /* First set up as if the reservation failed */ |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4788 | // Set CR0[LT GT EQ S0] = 0b000 || XER[SO] |
| 4789 | putCR321(0, mkU8(0<<1)); |
| 4790 | putCR0(0, getXER_SO()); |
| 4791 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4792 | /* Get the reservation address into a temporary, then |
| 4793 | clear it. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4794 | assign( resaddr, getGST(PPC_GST_RESVN) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4795 | putGST( PPC_GST_RESVN, mkSzImm(ty, 0) ); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4796 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4797 | /* Skip the rest if the reservation really did fail. */ |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4798 | stmt( IRStmt_Exit( |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4799 | ( mode64 ? |
| 4800 | binop(Iop_CmpNE64, mkexpr(resaddr), mkexpr(EA)) : |
| 4801 | binop(Iop_CmpNE32, mkexpr(resaddr), mkexpr(EA)) ), |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4802 | Ijk_Boring, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4803 | mkSzConst( ty, nextInsnAddr()) )); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4804 | |
| 4805 | /* Note for mode64: |
| 4806 | If resaddr != lwarx_resaddr, CR0[EQ] is undefined, and |
| 4807 | whether rS is stored is dependent on that value. */ |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4808 | |
cerion | 4e2c2b3 | 2006-01-02 13:35:51 +0000 | [diff] [blame] | 4809 | /* Success? Do the (32bit) store */ |
| 4810 | storeBE( mkexpr(EA), mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4811 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4812 | // Set CR0[LT GT EQ S0] = 0b001 || XER[SO] |
| 4813 | putCR321(0, mkU8(1<<1)); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4814 | break; |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4815 | } |
| 4816 | |
sewardj | b029a61 | 2005-12-30 15:04:29 +0000 | [diff] [blame] | 4817 | case 0x256: // sync (Synchronize, PPC32 p543), |
cerion | e43bc88 | 2006-01-05 13:11:59 +0000 | [diff] [blame] | 4818 | // also lwsync (L==1), ptesync (L==2) |
sewardj | b029a61 | 2005-12-30 15:04:29 +0000 | [diff] [blame] | 4819 | /* http://sources.redhat.com/ml/binutils/2000-12/msg00311.html |
| 4820 | |
| 4821 | The PowerPC architecture used in IBM chips has expanded |
| 4822 | the sync instruction into two variants: lightweight sync |
| 4823 | and heavyweight sync. The original sync instruction is |
| 4824 | the new heavyweight sync and lightweight sync is a strict |
| 4825 | subset of the heavyweight sync functionality. This allows |
| 4826 | the programmer to specify a less expensive operation on |
| 4827 | high-end systems when the full sync functionality is not |
| 4828 | necessary. |
| 4829 | |
| 4830 | The basic "sync" mnemonic now utilizes an operand. "sync" |
| 4831 | without an operand now becomes a extended mnemonic for |
| 4832 | heavyweight sync. Processors without the lwsync |
| 4833 | instruction will not decode the L field and will perform a |
| 4834 | heavyweight sync. Everything is backward compatible. |
| 4835 | |
| 4836 | sync = sync 0 |
| 4837 | lwsync = sync 1 |
cerion | e43bc88 | 2006-01-05 13:11:59 +0000 | [diff] [blame] | 4838 | ptesync = sync 2 *** TODO - not implemented *** |
cerion | 4e2c2b3 | 2006-01-02 13:35:51 +0000 | [diff] [blame] | 4839 | */ |
cerion | e43bc88 | 2006-01-05 13:11:59 +0000 | [diff] [blame] | 4840 | if (b11to20 != 0 || b0 != 0) { |
| 4841 | vex_printf("dis_memsync(ppc)(sync/lwsync,b11to20|b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4842 | return False; |
| 4843 | } |
cerion | e43bc88 | 2006-01-05 13:11:59 +0000 | [diff] [blame] | 4844 | if (flag_L != 0/*sync*/ && flag_L != 1/*lwsync*/) { |
| 4845 | vex_printf("dis_memsync(ppc)(sync/lwsync,flag_L)\n"); |
| 4846 | return False; |
| 4847 | } |
| 4848 | DIP("%ssync\n", flag_L == 1 ? "lw" : ""); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4849 | /* Insert a memory fence. It's sometimes important that these |
| 4850 | are carried through to the generated code. */ |
| 4851 | stmt( IRStmt_MFence() ); |
| 4852 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4853 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4854 | /* 64bit Memsync */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4855 | case 0x054: // ldarx (Load DWord and Reserve Indexed, PPC64 p473) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4856 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4857 | vex_printf("dis_memsync(ppc)(ldarx,b0)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4858 | return False; |
| 4859 | } |
| 4860 | DIP("ldarx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4861 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 4862 | // Take a reservation |
| 4863 | putGST( PPC_GST_RESVN, mkexpr(EA) ); |
| 4864 | break; |
| 4865 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4866 | case 0x0D6: { // stdcx. (Store DWord Condition Indexd, PPC64 p581) |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4867 | IRTemp resaddr = newTemp(ty); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4868 | if (b0 != 1) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4869 | vex_printf("dis_memsync(ppc)(stdcx.,b0)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4870 | return False; |
| 4871 | } |
| 4872 | DIP("stdcx. r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4873 | assign( rS, getIReg(rS_addr) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4874 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4875 | // First set up as if the reservation failed |
| 4876 | // Set CR0[LT GT EQ S0] = 0b000 || XER[SO] |
| 4877 | putCR321(0, mkU8(0<<1)); |
| 4878 | putCR0(0, getXER_SO()); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4879 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4880 | // Get the reservation address into a temporary, then clear it. |
| 4881 | assign( resaddr, getGST(PPC_GST_RESVN) ); |
| 4882 | putGST( PPC_GST_RESVN, mkSzImm(ty, 0) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4883 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4884 | // Skip the rest if the reservation really did fail. |
| 4885 | stmt( IRStmt_Exit( binop(Iop_CmpNE64, mkexpr(resaddr), |
| 4886 | mkexpr(EA)), |
| 4887 | Ijk_Boring, |
| 4888 | IRConst_U64(nextInsnAddr())) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4889 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4890 | // Success? Do the store |
| 4891 | storeBE( mkexpr(EA), mkexpr(rS) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4892 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4893 | // Set CR0[LT GT EQ S0] = 0b001 || XER[SO] |
| 4894 | putCR321(0, mkU8(1<<1)); |
| 4895 | break; |
| 4896 | } |
| 4897 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4898 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4899 | vex_printf("dis_memsync(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4900 | return False; |
| 4901 | } |
| 4902 | break; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4903 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4904 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4905 | vex_printf("dis_memsync(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4906 | return False; |
| 4907 | } |
| 4908 | return True; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4909 | } |
| 4910 | |
| 4911 | |
| 4912 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4913 | /* |
| 4914 | Integer Shift Instructions |
| 4915 | */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 4916 | static Bool dis_int_shift ( UInt theInstr ) |
| 4917 | { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4918 | /* X-Form, XS-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4919 | UChar opc1 = ifieldOPC(theInstr); |
| 4920 | UChar rS_addr = ifieldRegDS(theInstr); |
| 4921 | UChar rA_addr = ifieldRegA(theInstr); |
| 4922 | UChar rB_addr = ifieldRegB(theInstr); |
| 4923 | UChar sh_imm = rB_addr; |
| 4924 | UInt opc2 = ifieldOPClo10(theInstr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4925 | UChar b1 = ifieldBIT1(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4926 | UChar flag_rC = ifieldBIT0(theInstr); |
| 4927 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4928 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 4929 | IRTemp rA = newTemp(ty); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4930 | IRTemp rS = newTemp(ty); |
| 4931 | IRTemp rB = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4932 | IRTemp outofrange = newTemp(Ity_I8); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4933 | IRTemp rS_lo32 = newTemp(Ity_I32); |
| 4934 | IRTemp rB_lo32 = newTemp(Ity_I32); |
| 4935 | IRExpr* e_tmp; |
| 4936 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4937 | assign( rS, getIReg(rS_addr) ); |
| 4938 | assign( rB, getIReg(rB_addr) ); |
| 4939 | assign( rS_lo32, mkSzNarrow32(ty, mkexpr(rS)) ); |
| 4940 | assign( rB_lo32, mkSzNarrow32(ty, mkexpr(rB)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4941 | |
| 4942 | if (opc1 == 0x1F) { |
| 4943 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4944 | case 0x018: { // slw (Shift Left Word, PPC32 p505) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4945 | DIP("slw%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4946 | rA_addr, rS_addr, rB_addr); |
| 4947 | /* rA = rS << rB */ |
| 4948 | /* ppc32 semantics are: |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 4949 | slw(x,y) = (x << (y & 31)) -- primary result |
| 4950 | & ~((y << 26) >>s 31) -- make result 0 |
| 4951 | for y in 32 .. 63 |
| 4952 | */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4953 | e_tmp = |
| 4954 | binop( Iop_And32, |
| 4955 | binop( Iop_Shl32, |
| 4956 | mkexpr(rS_lo32), |
| 4957 | unop( Iop_32to8, |
| 4958 | binop(Iop_And32, |
| 4959 | mkexpr(rB_lo32), mkU32(31)))), |
| 4960 | unop( Iop_Not32, |
| 4961 | binop( Iop_Sar32, |
| 4962 | binop(Iop_Shl32, mkexpr(rB_lo32), mkU8(26)), |
| 4963 | mkU8(31))) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4964 | assign( rA, mkSzWiden32(ty, e_tmp, /* Signed */False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4965 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4966 | } |
| 4967 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4968 | case 0x318: { // sraw (Shift Right Alg Word, PPC32 p506) |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4969 | IRTemp sh_amt = newTemp(Ity_I32); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4970 | DIP("sraw%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4971 | rA_addr, rS_addr, rB_addr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4972 | /* JRS: my reading of the (poorly worded) PPC32 doc p506 is: |
| 4973 | amt = rB & 63 |
| 4974 | rA = Sar32( rS, amt > 31 ? 31 : amt ) |
| 4975 | XER.CA = amt > 31 ? sign-of-rS : (computation as per srawi) |
| 4976 | */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4977 | assign( sh_amt, binop(Iop_And32, mkU32(0x3F), |
| 4978 | mkexpr(rB_lo32)) ); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4979 | assign( outofrange, |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 4980 | unop( Iop_1Uto8, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4981 | binop(Iop_CmpLT32U, mkU32(31), |
| 4982 | mkexpr(sh_amt)) )); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4983 | e_tmp = binop( Iop_Sar32, |
| 4984 | mkexpr(rS_lo32), |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 4985 | unop( Iop_32to8, |
| 4986 | IRExpr_Mux0X( mkexpr(outofrange), |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4987 | mkexpr(sh_amt), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4988 | mkU32(31)) ) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4989 | assign( rA, mkSzWiden32(ty, e_tmp, /* Signed */True) ); |
| 4990 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4991 | set_XER_CA( ty, PPCG_FLAG_OP_SRAW, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4992 | mkexpr(rA), |
| 4993 | mkSzWiden32(ty, mkexpr(rS_lo32), True), |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4994 | mkSzWiden32(ty, mkexpr(sh_amt), True ), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4995 | mkSzWiden32(ty, getXER_CA32(), True) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4996 | break; |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4997 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4998 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4999 | case 0x338: // srawi (Shift Right Alg Word Immediate, PPC32 p507) |
| 5000 | DIP("srawi%s r%u,r%u,%d\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5001 | rA_addr, rS_addr, sh_imm); |
| 5002 | vassert(sh_imm < 32); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5003 | if (mode64) { |
| 5004 | assign( rA, binop(Iop_Sar64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5005 | binop(Iop_Shl64, getIReg(rS_addr), |
| 5006 | mkU8(32)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5007 | mkU8(32 + sh_imm)) ); |
| 5008 | } else { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5009 | assign( rA, binop(Iop_Sar32, mkexpr(rS_lo32), |
| 5010 | mkU8(sh_imm)) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5011 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5012 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5013 | set_XER_CA( ty, PPCG_FLAG_OP_SRAWI, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5014 | mkexpr(rA), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5015 | mkSzWiden32(ty, mkexpr(rS_lo32), /* Syned */True), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5016 | mkSzImm(ty, sh_imm), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5017 | mkSzWiden32(ty, getXER_CA32(), /* Syned */False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5018 | break; |
| 5019 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5020 | case 0x218: // srw (Shift Right Word, PPC32 p508) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5021 | DIP("srw%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5022 | rA_addr, rS_addr, rB_addr); |
| 5023 | /* rA = rS >>u rB */ |
| 5024 | /* ppc32 semantics are: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5025 | srw(x,y) = (x >>u (y & 31)) -- primary result |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 5026 | & ~((y << 26) >>s 31) -- make result 0 |
| 5027 | for y in 32 .. 63 |
| 5028 | */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5029 | e_tmp = |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 5030 | binop( |
| 5031 | Iop_And32, |
| 5032 | binop( Iop_Shr32, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5033 | mkexpr(rS_lo32), |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 5034 | unop( Iop_32to8, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5035 | binop(Iop_And32, mkexpr(rB_lo32), |
| 5036 | mkU32(31)))), |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 5037 | unop( Iop_Not32, |
| 5038 | binop( Iop_Sar32, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5039 | binop(Iop_Shl32, mkexpr(rB_lo32), |
| 5040 | mkU8(26)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5041 | mkU8(31)))); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5042 | assign( rA, mkSzWiden32(ty, e_tmp, /* Signed */False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5043 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5044 | |
| 5045 | |
| 5046 | /* 64bit Shifts */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5047 | case 0x01B: // sld (Shift Left DWord, PPC64 p568) |
| 5048 | DIP("sld%s r%u,r%u,r%u\n", |
| 5049 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5050 | /* rA = rS << rB */ |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5051 | /* ppc64 semantics are: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5052 | slw(x,y) = (x << (y & 63)) -- primary result |
| 5053 | & ~((y << 57) >>s 63) -- make result 0 |
| 5054 | for y in 64 .. |
| 5055 | */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5056 | assign( rA, |
| 5057 | binop( |
| 5058 | Iop_And64, |
| 5059 | binop( Iop_Shl64, |
| 5060 | mkexpr(rS), |
| 5061 | unop( Iop_64to8, |
| 5062 | binop(Iop_And64, mkexpr(rB), mkU64(63)))), |
| 5063 | unop( Iop_Not64, |
| 5064 | binop( Iop_Sar64, |
| 5065 | binop(Iop_Shl64, mkexpr(rB), mkU8(57)), |
| 5066 | mkU8(63)))) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5067 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5068 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5069 | case 0x31A: { // srad (Shift Right Alg DWord, PPC64 p570) |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5070 | IRTemp sh_amt = newTemp(Ity_I64); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5071 | DIP("srad%s r%u,r%u,r%u\n", |
| 5072 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5073 | /* amt = rB & 127 |
| 5074 | rA = Sar64( rS, amt > 63 ? 63 : amt ) |
| 5075 | XER.CA = amt > 63 ? sign-of-rS : (computation as per srawi) |
| 5076 | */ |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5077 | assign( sh_amt, binop(Iop_And64, mkU64(0x7F), mkexpr(rB)) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5078 | assign( outofrange, |
| 5079 | unop( Iop_1Uto8, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5080 | binop(Iop_CmpLT64U, mkU64(63), |
| 5081 | mkexpr(sh_amt)) )); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5082 | assign( rA, |
| 5083 | binop( Iop_Sar64, |
| 5084 | mkexpr(rS), |
| 5085 | unop( Iop_64to8, |
| 5086 | IRExpr_Mux0X( mkexpr(outofrange), |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5087 | mkexpr(sh_amt), |
| 5088 | mkU64(63)) )) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5089 | ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5090 | set_XER_CA( ty, PPCG_FLAG_OP_SRAD, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5091 | mkexpr(rA), mkexpr(rS), mkexpr(sh_amt), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5092 | mkSzWiden32(ty, getXER_CA32(), /* Syned */False) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5093 | break; |
| 5094 | } |
| 5095 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5096 | case 0x33A: case 0x33B: // sradi (Shr Alg DWord Imm, PPC64 p571) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5097 | sh_imm |= b1<<5; |
| 5098 | vassert(sh_imm < 64); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5099 | DIP("sradi%s r%u,r%u,%u\n", |
| 5100 | flag_rC ? ".":"", rA_addr, rS_addr, sh_imm); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5101 | assign( rA, binop(Iop_Sar64, getIReg(rS_addr), mkU8(sh_imm)) ); |
| 5102 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5103 | set_XER_CA( ty, PPCG_FLAG_OP_SRADI, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5104 | mkexpr(rA), |
| 5105 | getIReg(rS_addr), |
| 5106 | mkU64(sh_imm), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5107 | mkSzWiden32(ty, getXER_CA32(), /* Syned */False) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5108 | break; |
| 5109 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5110 | case 0x21B: // srd (Shift Right DWord, PPC64 p574) |
| 5111 | DIP("srd%s r%u,r%u,r%u\n", |
| 5112 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5113 | /* rA = rS >>u rB */ |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5114 | /* ppc semantics are: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5115 | srw(x,y) = (x >>u (y & 63)) -- primary result |
| 5116 | & ~((y << 57) >>s 63) -- make result 0 |
| 5117 | for y in 64 .. 127 |
| 5118 | */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5119 | assign( rA, |
| 5120 | binop( |
| 5121 | Iop_And64, |
| 5122 | binop( Iop_Shr64, |
| 5123 | mkexpr(rS), |
| 5124 | unop( Iop_64to8, |
| 5125 | binop(Iop_And64, mkexpr(rB), mkU64(63)))), |
| 5126 | unop( Iop_Not64, |
| 5127 | binop( Iop_Sar64, |
| 5128 | binop(Iop_Shl64, mkexpr(rB), mkU8(57)), |
| 5129 | mkU8(63)))) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5130 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5131 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5132 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5133 | vex_printf("dis_int_shift(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5134 | return False; |
| 5135 | } |
| 5136 | } else { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5137 | vex_printf("dis_int_shift(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5138 | return False; |
| 5139 | } |
cerion | 0d330c5 | 2005-02-28 16:43:16 +0000 | [diff] [blame] | 5140 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5141 | putIReg( rA_addr, mkexpr(rA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5142 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5143 | if (flag_rC) { |
| 5144 | set_CR0( mkexpr(rA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5145 | } |
| 5146 | return True; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 5147 | } |
| 5148 | |
| 5149 | |
| 5150 | |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 5151 | /* |
| 5152 | Integer Load/Store Reverse Instructions |
| 5153 | */ |
sewardj | 40d8c09 | 2006-05-05 13:26:14 +0000 | [diff] [blame] | 5154 | /* Generates code to swap the byte order in an Ity_I32. */ |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 5155 | static IRExpr* /* :: Ity_I32 */ gen_byterev32 ( IRTemp t ) |
| 5156 | { |
| 5157 | vassert(typeOfIRTemp(irbb->tyenv, t) == Ity_I32); |
| 5158 | return |
| 5159 | binop(Iop_Or32, |
| 5160 | binop(Iop_Shl32, mkexpr(t), mkU8(24)), |
| 5161 | binop(Iop_Or32, |
| 5162 | binop(Iop_And32, binop(Iop_Shl32, mkexpr(t), mkU8(8)), |
| 5163 | mkU32(0x00FF0000)), |
| 5164 | binop(Iop_Or32, |
| 5165 | binop(Iop_And32, binop(Iop_Shr32, mkexpr(t), mkU8(8)), |
| 5166 | mkU32(0x0000FF00)), |
| 5167 | binop(Iop_And32, binop(Iop_Shr32, mkexpr(t), mkU8(24)), |
| 5168 | mkU32(0x000000FF) ) |
| 5169 | ))); |
| 5170 | } |
| 5171 | |
sewardj | 40d8c09 | 2006-05-05 13:26:14 +0000 | [diff] [blame] | 5172 | /* Generates code to swap the byte order in the lower half of an Ity_I32, |
| 5173 | and zeroes the upper half. */ |
| 5174 | static IRExpr* /* :: Ity_I32 */ gen_byterev16 ( IRTemp t ) |
| 5175 | { |
| 5176 | vassert(typeOfIRTemp(irbb->tyenv, t) == Ity_I32); |
| 5177 | return |
| 5178 | binop(Iop_Or32, |
| 5179 | binop(Iop_And32, binop(Iop_Shl32, mkexpr(t), mkU8(8)), |
| 5180 | mkU32(0x0000FF00)), |
| 5181 | binop(Iop_And32, binop(Iop_Shr32, mkexpr(t), mkU8(8)), |
| 5182 | mkU32(0x000000FF)) |
| 5183 | ); |
| 5184 | } |
| 5185 | |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 5186 | static Bool dis_int_ldst_rev ( UInt theInstr ) |
| 5187 | { |
| 5188 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5189 | UChar opc1 = ifieldOPC(theInstr); |
| 5190 | UChar rD_addr = ifieldRegDS(theInstr); |
| 5191 | UChar rS_addr = rD_addr; |
| 5192 | UChar rA_addr = ifieldRegA(theInstr); |
| 5193 | UChar rB_addr = ifieldRegB(theInstr); |
| 5194 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5195 | UChar b0 = ifieldBIT0(theInstr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5196 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5197 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 5198 | IRTemp EA = newTemp(ty); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5199 | IRTemp w1 = newTemp(Ity_I32); |
| 5200 | IRTemp w2 = newTemp(Ity_I32); |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 5201 | |
| 5202 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5203 | vex_printf("dis_int_ldst_rev(ppc)(opc1|b0)\n"); |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 5204 | return False; |
| 5205 | } |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 5206 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5207 | assign( EA, ea_rAor0_idxd( rA_addr, rB_addr ) ); |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 5208 | |
| 5209 | switch (opc2) { |
sewardj | 40d8c09 | 2006-05-05 13:26:14 +0000 | [diff] [blame] | 5210 | |
| 5211 | case 0x316: // lhbrx (Load Halfword Byte-Reverse Indexed, PPC32 p449) |
| 5212 | DIP("lhbrx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 5213 | assign( w1, unop(Iop_16Uto32, loadBE(Ity_I16, mkexpr(EA))) ); |
| 5214 | assign( w2, gen_byterev16(w1) ); |
| 5215 | putIReg( rD_addr, mkSzWiden32(ty, mkexpr(w2), |
| 5216 | /* Signed */False) ); |
| 5217 | break; |
| 5218 | |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 5219 | case 0x216: // lwbrx (Load Word Byte-Reverse Indexed, PPC32 p459) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5220 | DIP("lwbrx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 5221 | assign( w1, loadBE(Ity_I32, mkexpr(EA)) ); |
| 5222 | assign( w2, gen_byterev32(w1) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5223 | putIReg( rD_addr, mkSzWiden32(ty, mkexpr(w2), |
| 5224 | /* Signed */False) ); |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 5225 | break; |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 5226 | |
sewardj | 413a468 | 2006-05-05 13:44:17 +0000 | [diff] [blame] | 5227 | case 0x396: // sthbrx (Store Half Word Byte-Reverse Indexed, PPC32 p523) |
| 5228 | DIP("sthbrx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
| 5229 | assign( w1, mkSzNarrow32(ty, getIReg(rS_addr)) ); |
| 5230 | storeBE( mkexpr(EA), unop(Iop_32to16, gen_byterev16(w1)) ); |
| 5231 | break; |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 5232 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5233 | case 0x296: // stwbrx (Store Word Byte-Reverse Indxd, PPC32 p531) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5234 | DIP("stwbrx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5235 | assign( w1, mkSzNarrow32(ty, getIReg(rS_addr)) ); |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 5236 | storeBE( mkexpr(EA), gen_byterev32(w1) ); |
| 5237 | break; |
| 5238 | |
| 5239 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5240 | vex_printf("dis_int_ldst_rev(ppc)(opc2)\n"); |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 5241 | return False; |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 5242 | } |
| 5243 | return True; |
| 5244 | } |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 5245 | |
| 5246 | |
| 5247 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5248 | /* |
| 5249 | Processor Control Instructions |
| 5250 | */ |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 5251 | static Bool dis_proc_ctl ( VexMiscInfo* vmi, UInt theInstr ) |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5252 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5253 | UChar opc1 = ifieldOPC(theInstr); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5254 | |
| 5255 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5256 | UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 5257 | UChar b21to22 = toUChar( IFIELD( theInstr, 21, 2 ) ); |
| 5258 | UChar rD_addr = ifieldRegDS(theInstr); |
| 5259 | UInt b11to20 = IFIELD( theInstr, 11, 10 ); |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5260 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5261 | /* XFX-Form */ |
| 5262 | UChar rS_addr = rD_addr; |
| 5263 | UInt SPR = b11to20; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5264 | UInt TBR = b11to20; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5265 | UChar b20 = toUChar( IFIELD( theInstr, 20, 1 ) ); |
| 5266 | UInt CRM = IFIELD( theInstr, 12, 8 ); |
| 5267 | UChar b11 = toUChar( IFIELD( theInstr, 11, 1 ) ); |
| 5268 | |
| 5269 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5270 | UChar b0 = ifieldBIT0(theInstr); |
| 5271 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5272 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5273 | IRTemp rS = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5274 | assign( rS, getIReg(rS_addr) ); |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 5275 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5276 | /* Reorder SPR field as per PPC32 p470 */ |
| 5277 | SPR = ((SPR & 0x1F) << 5) | ((SPR >> 5) & 0x1F); |
sewardj | 73a9197 | 2005-09-06 10:25:46 +0000 | [diff] [blame] | 5278 | /* Reorder TBR field as per PPC32 p475 */ |
| 5279 | TBR = ((TBR & 31) << 5) | ((TBR >> 5) & 31); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5280 | |
| 5281 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5282 | vex_printf("dis_proc_ctl(ppc)(opc1|b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5283 | return False; |
| 5284 | } |
| 5285 | |
| 5286 | switch (opc2) { |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 5287 | /* X-Form */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5288 | case 0x200: { // mcrxr (Move to Cond Register from XER, PPC32 p466) |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 5289 | if (b21to22 != 0 || b11to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5290 | vex_printf("dis_proc_ctl(ppc)(mcrxr,b21to22|b11to20)\n"); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 5291 | return False; |
| 5292 | } |
| 5293 | DIP("mcrxr crf%d\n", crfD); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5294 | /* Move XER[0-3] (the top 4 bits of XER) to CR[crfD] */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5295 | putGST_field( PPC_GST_CR, |
| 5296 | getGST_field( PPC_GST_XER, 7 ), |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5297 | crfD ); |
sewardj | 55ccc3e | 2005-09-09 19:45:02 +0000 | [diff] [blame] | 5298 | |
| 5299 | // Clear XER[0-3] |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5300 | putXER_SO( mkU8(0) ); |
| 5301 | putXER_OV( mkU8(0) ); |
| 5302 | putXER_CA( mkU8(0) ); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 5303 | break; |
sewardj | 55ccc3e | 2005-09-09 19:45:02 +0000 | [diff] [blame] | 5304 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5305 | |
sewardj | 72aefb2 | 2006-03-01 18:58:39 +0000 | [diff] [blame] | 5306 | case 0x013: |
| 5307 | // b11to20==0: mfcr (Move from Cond Register, PPC32 p467) |
| 5308 | // b20==1 & b11==0: mfocrf (Move from One CR Field) |
| 5309 | // However it seems that the 'mfcr' behaviour is an acceptable |
| 5310 | // implementation of mfocr (from the 2.02 arch spec) |
| 5311 | if (b11to20 == 0) { |
| 5312 | DIP("mfcr r%u\n", rD_addr); |
| 5313 | putIReg( rD_addr, mkSzWiden32(ty, getGST( PPC_GST_CR ), |
| 5314 | /* Signed */False) ); |
| 5315 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5316 | } |
sewardj | 72aefb2 | 2006-03-01 18:58:39 +0000 | [diff] [blame] | 5317 | if (b20 == 1 && b11 == 0) { |
| 5318 | DIP("mfocrf r%u,%u\n", rD_addr, CRM); |
| 5319 | putIReg( rD_addr, mkSzWiden32(ty, getGST( PPC_GST_CR ), |
| 5320 | /* Signed */False) ); |
| 5321 | break; |
| 5322 | } |
| 5323 | /* not decodable */ |
| 5324 | return False; |
| 5325 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5326 | /* XFX-Form */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5327 | case 0x153: // mfspr (Move from Special-Purpose Register, PPC32 p470) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5328 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5329 | switch (SPR) { // Choose a register... |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5330 | case 0x1: |
| 5331 | DIP("mfxer r%u\n", rD_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5332 | putIReg( rD_addr, mkSzWiden32(ty, getGST( PPC_GST_XER ), |
| 5333 | /* Signed */False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5334 | break; |
| 5335 | case 0x8: |
| 5336 | DIP("mflr r%u\n", rD_addr); |
| 5337 | putIReg( rD_addr, getGST( PPC_GST_LR ) ); |
| 5338 | break; |
| 5339 | case 0x9: |
| 5340 | DIP("mfctr r%u\n", rD_addr); |
| 5341 | putIReg( rD_addr, getGST( PPC_GST_CTR ) ); |
| 5342 | break; |
| 5343 | case 0x100: |
| 5344 | DIP("mfvrsave r%u\n", rD_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5345 | putIReg( rD_addr, mkSzWiden32(ty, getGST( PPC_GST_VRSAVE ), |
| 5346 | /* Signed */False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5347 | break; |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 5348 | |
| 5349 | case 0x103: |
| 5350 | DIP("mfspr r%u, SPRG3(readonly)\n", rD_addr); |
| 5351 | putIReg( rD_addr, getGST( PPC_GST_SPRG3_RO ) ); |
| 5352 | break; |
| 5353 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5354 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5355 | vex_printf("dis_proc_ctl(ppc)(mfspr,SPR)(0x%x)\n", SPR); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5356 | return False; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5357 | } |
| 5358 | break; |
| 5359 | |
sewardj | 73a9197 | 2005-09-06 10:25:46 +0000 | [diff] [blame] | 5360 | case 0x173: { // mftb (Move from Time Base, PPC32 p475) |
| 5361 | IRTemp val = newTemp(Ity_I64); |
| 5362 | IRExpr** args = mkIRExprVec_0(); |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 5363 | IRDirty* d = unsafeIRDirty_1_N( |
| 5364 | val, |
| 5365 | 0/*regparms*/, |
| 5366 | "ppcg_dirtyhelper_MFTB", |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 5367 | fnptr_to_fnentry(vmi, &ppcg_dirtyhelper_MFTB), |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 5368 | args ); |
sewardj | 73a9197 | 2005-09-06 10:25:46 +0000 | [diff] [blame] | 5369 | /* execute the dirty call, dumping the result in val. */ |
| 5370 | stmt( IRStmt_Dirty(d) ); |
| 5371 | |
| 5372 | switch (TBR) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5373 | case 269: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5374 | DIP("mftbu r%u", rD_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5375 | putIReg( rD_addr, |
| 5376 | mkSzWiden32(ty, unop(Iop_64HIto32, mkexpr(val)), |
| 5377 | /* Signed */False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5378 | break; |
| 5379 | case 268: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5380 | DIP("mftb r%u", rD_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5381 | putIReg( rD_addr, (mode64) ? mkexpr(val) : |
| 5382 | unop(Iop_64to32, mkexpr(val)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5383 | break; |
| 5384 | default: |
| 5385 | return False; /* illegal instruction */ |
sewardj | 73a9197 | 2005-09-06 10:25:46 +0000 | [diff] [blame] | 5386 | } |
| 5387 | break; |
| 5388 | } |
| 5389 | |
sewardj | 72aefb2 | 2006-03-01 18:58:39 +0000 | [diff] [blame] | 5390 | case 0x090: { |
| 5391 | // b20==0: mtcrf (Move to Cond Register Fields, PPC32 p477) |
| 5392 | // b20==1: mtocrf (Move to One Cond Reg Field) |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5393 | Int cr; |
| 5394 | UChar shft; |
sewardj | 72aefb2 | 2006-03-01 18:58:39 +0000 | [diff] [blame] | 5395 | if (b11 != 0) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5396 | return False; |
sewardj | 72aefb2 | 2006-03-01 18:58:39 +0000 | [diff] [blame] | 5397 | if (b20 == 1) { |
| 5398 | /* ppc64 v2.02 spec says mtocrf gives undefined outcome if > |
| 5399 | 1 field is written. It seems more robust to decline to |
| 5400 | decode the insn if so. */ |
| 5401 | switch (CRM) { |
| 5402 | case 0x01: case 0x02: case 0x04: case 0x08: |
| 5403 | case 0x10: case 0x20: case 0x40: case 0x80: |
| 5404 | break; |
| 5405 | default: |
| 5406 | return False; |
| 5407 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5408 | } |
sewardj | 72aefb2 | 2006-03-01 18:58:39 +0000 | [diff] [blame] | 5409 | DIP("%s 0x%x,r%u\n", b20==1 ? "mtocrf" : "mtcrf", |
| 5410 | CRM, rS_addr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5411 | /* Write to each field specified by CRM */ |
| 5412 | for (cr = 0; cr < 8; cr++) { |
| 5413 | if ((CRM & (1 << (7-cr))) == 0) |
| 5414 | continue; |
| 5415 | shft = 4*(7-cr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5416 | putGST_field( PPC_GST_CR, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5417 | binop(Iop_Shr32, |
| 5418 | mkSzNarrow32(ty, mkexpr(rS)), |
| 5419 | mkU8(shft)), cr ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5420 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5421 | break; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5422 | } |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5423 | |
| 5424 | case 0x1D3: // mtspr (Move to Special-Purpose Register, PPC32 p483) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5425 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5426 | switch (SPR) { // Choose a register... |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5427 | case 0x1: |
| 5428 | DIP("mtxer r%u\n", rS_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5429 | putGST( PPC_GST_XER, mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5430 | break; |
| 5431 | case 0x8: |
| 5432 | DIP("mtlr r%u\n", rS_addr); |
| 5433 | putGST( PPC_GST_LR, mkexpr(rS) ); |
| 5434 | break; |
| 5435 | case 0x9: |
| 5436 | DIP("mtctr r%u\n", rS_addr); |
| 5437 | putGST( PPC_GST_CTR, mkexpr(rS) ); |
| 5438 | break; |
| 5439 | case 0x100: |
| 5440 | DIP("mtvrsave r%u\n", rS_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5441 | putGST( PPC_GST_VRSAVE, mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5442 | break; |
| 5443 | |
| 5444 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5445 | vex_printf("dis_proc_ctl(ppc)(mtspr,SPR)(%u)\n", SPR); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5446 | return False; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5447 | } |
| 5448 | break; |
| 5449 | |
| 5450 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5451 | vex_printf("dis_proc_ctl(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5452 | return False; |
| 5453 | } |
| 5454 | return True; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5455 | } |
| 5456 | |
| 5457 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5458 | /* |
| 5459 | Cache Management Instructions |
| 5460 | */ |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5461 | static Bool dis_cache_manage ( UInt theInstr, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 5462 | DisResult* dres, |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5463 | VexArchInfo* guest_archinfo ) |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5464 | { |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5465 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5466 | UChar opc1 = ifieldOPC(theInstr); |
| 5467 | UChar b21to25 = ifieldRegDS(theInstr); |
| 5468 | UChar rA_addr = ifieldRegA(theInstr); |
| 5469 | UChar rB_addr = ifieldRegB(theInstr); |
| 5470 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5471 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5472 | UInt lineszB = guest_archinfo->ppc_cache_line_szB; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5473 | |
| 5474 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5475 | |
sewardj | 6be6723 | 2006-01-24 19:00:05 +0000 | [diff] [blame] | 5476 | /* For dcbt, the lowest two bits of b21to25 encode an |
| 5477 | access-direction hint (TH field) which we ignore. Well, that's |
| 5478 | what the PowerPC documentation says. In fact xlc -O4 on POWER5 |
| 5479 | seems to generate values of 8 and 10 for b21to25. */ |
| 5480 | if (opc1 == 0x1F && opc2 == 0x116) { |
| 5481 | /* b21to25 &= ~3; */ /* if the docs were true */ |
| 5482 | b21to25 = 0; /* blunt instrument */ |
| 5483 | } |
| 5484 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5485 | if (opc1 != 0x1F || b21to25 != 0 || b0 != 0) { |
sewardj | 6be6723 | 2006-01-24 19:00:05 +0000 | [diff] [blame] | 5486 | if (0) vex_printf("dis_cache_manage %d %d %d\n", |
| 5487 | (Int)opc1, (Int)b21to25, (Int)b0); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5488 | vex_printf("dis_cache_manage(ppc)(opc1|b21to25|b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5489 | return False; |
| 5490 | } |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5491 | |
| 5492 | /* stay sane .. */ |
| 5493 | vassert(lineszB == 32 || lineszB == 128); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5494 | |
| 5495 | switch (opc2) { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5496 | //zz case 0x2F6: // dcba (Data Cache Block Allocate, PPC32 p380) |
| 5497 | //zz vassert(0); /* AWAITING TEST CASE */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5498 | //zz DIP("dcba r%u,r%u\n", rA_addr, rB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5499 | //zz if (0) vex_printf("vex ppc->IR: kludged dcba\n"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5500 | //zz break; |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 5501 | |
| 5502 | case 0x056: // dcbf (Data Cache Block Flush, PPC32 p382) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5503 | DIP("dcbf r%u,r%u\n", rA_addr, rB_addr); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 5504 | /* nop as far as vex is concerned */ |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 5505 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5506 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5507 | case 0x036: // dcbst (Data Cache Block Store, PPC32 p384) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5508 | DIP("dcbst r%u,r%u\n", rA_addr, rB_addr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5509 | /* nop as far as vex is concerned */ |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5510 | break; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5511 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5512 | case 0x116: // dcbt (Data Cache Block Touch, PPC32 p385) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5513 | DIP("dcbt r%u,r%u\n", rA_addr, rB_addr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5514 | /* nop as far as vex is concerned */ |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5515 | break; |
| 5516 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5517 | case 0x0F6: // dcbtst (Data Cache Block Touch for Store, PPC32 p386) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5518 | DIP("dcbtst r%u,r%u\n", rA_addr, rB_addr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5519 | /* nop as far as vex is concerned */ |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5520 | break; |
| 5521 | |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5522 | case 0x3F6: { // dcbz (Data Cache Block Clear to Zero, PPC32 p387) |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5523 | /* Clear all bytes in cache block at (rA|0) + rB. */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5524 | IRTemp EA = newTemp(ty); |
| 5525 | IRTemp addr = newTemp(ty); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5526 | IRExpr* irx_addr; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5527 | UInt i; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5528 | DIP("dcbz r%u,r%u\n", rA_addr, rB_addr); |
sewardj | cb1f68e | 2005-12-30 03:39:14 +0000 | [diff] [blame] | 5529 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5530 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5531 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5532 | if (mode64) { |
| 5533 | /* Round EA down to the start of the containing block. */ |
| 5534 | assign( addr, binop( Iop_And64, |
| 5535 | mkexpr(EA), |
| 5536 | mkU64( ~((ULong)lineszB-1) )) ); |
| 5537 | |
| 5538 | for (i = 0; i < lineszB / 8; i++) { |
| 5539 | irx_addr = binop( Iop_Add64, mkexpr(addr), mkU64(i*8) ); |
| 5540 | storeBE( irx_addr, mkU64(0) ); |
| 5541 | } |
| 5542 | } else { |
| 5543 | /* Round EA down to the start of the containing block. */ |
| 5544 | assign( addr, binop( Iop_And32, |
| 5545 | mkexpr(EA), |
| 5546 | mkU32( ~(lineszB-1) )) ); |
| 5547 | |
| 5548 | for (i = 0; i < lineszB / 4; i++) { |
| 5549 | irx_addr = binop( Iop_Add32, mkexpr(addr), mkU32(i*4) ); |
| 5550 | storeBE( irx_addr, mkU32(0) ); |
| 5551 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5552 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5553 | break; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5554 | } |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5555 | |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5556 | case 0x3D6: { |
| 5557 | // icbi (Instruction Cache Block Invalidate, PPC32 p431) |
| 5558 | /* Invalidate all translations containing code from the cache |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5559 | block at (rA|0) + rB. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5560 | IRTemp EA = newTemp(ty); |
| 5561 | IRTemp addr = newTemp(ty); |
| 5562 | DIP("icbi r%u,r%u\n", rA_addr, rB_addr); |
| 5563 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5564 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5565 | /* Round EA down to the start of the containing block. */ |
| 5566 | assign( addr, binop( mkSzOp(ty, Iop_And8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5567 | mkexpr(EA), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5568 | mkSzImm(ty, ~(((ULong)lineszB)-1) )) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5569 | putGST( PPC_GST_TISTART, mkexpr(addr) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5570 | putGST( PPC_GST_TILEN, mkSzImm(ty, lineszB) ); |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5571 | |
sewardj | a8078f6 | 2005-03-15 18:27:40 +0000 | [diff] [blame] | 5572 | /* be paranoid ... */ |
| 5573 | stmt( IRStmt_MFence() ); |
| 5574 | |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5575 | irbb->jumpkind = Ijk_TInval; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5576 | irbb->next = mkSzImm(ty, nextInsnAddr()); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 5577 | dres->whatNext = Dis_StopHere; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5578 | break; |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5579 | } |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5580 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5581 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5582 | vex_printf("dis_cache_manage(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5583 | return False; |
| 5584 | } |
| 5585 | return True; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5589 | /*------------------------------------------------------------*/ |
| 5590 | /*--- Floating Point Helpers ---*/ |
| 5591 | /*------------------------------------------------------------*/ |
| 5592 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5593 | /* --------- Synthesise a 2-bit FPU rounding mode. --------- */ |
| 5594 | /* Produces a value in 0 .. 3, which is encoded as per the type |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5595 | IRRoundingMode. PPCRoundingMode encoding is different to |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5596 | IRRoundingMode, so need to map it. |
| 5597 | */ |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5598 | static IRExpr* /* :: Ity_I32 */ get_IR_roundingmode ( void ) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5599 | { |
| 5600 | /* |
| 5601 | rounding mode | PPC | IR |
| 5602 | ------------------------ |
| 5603 | to nearest | 00 | 00 |
| 5604 | to zero | 01 | 11 |
| 5605 | to +infinity | 10 | 10 |
| 5606 | to -infinity | 11 | 01 |
| 5607 | */ |
| 5608 | IRTemp rm_PPC32 = newTemp(Ity_I32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5609 | assign( rm_PPC32, getGST_masked( PPC_GST_FPSCR, MASK_FPSCR_RN ) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5610 | |
| 5611 | // rm_IR = XOR( rm_PPC32, (rm_PPC32 << 1) & 2) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5612 | return binop( Iop_Xor32, |
| 5613 | mkexpr(rm_PPC32), |
| 5614 | binop( Iop_And32, |
| 5615 | binop(Iop_Shl32, mkexpr(rm_PPC32), mkU8(1)), |
| 5616 | mkU32(2) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5617 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5618 | |
| 5619 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5620 | /*------------------------------------------------------------*/ |
| 5621 | /*--- Floating Point Instruction Translation ---*/ |
| 5622 | /*------------------------------------------------------------*/ |
| 5623 | |
| 5624 | /* |
| 5625 | Floating Point Load Instructions |
| 5626 | */ |
| 5627 | static Bool dis_fp_load ( UInt theInstr ) |
| 5628 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5629 | /* X-Form, D-Form */ |
| 5630 | UChar opc1 = ifieldOPC(theInstr); |
| 5631 | UChar frD_addr = ifieldRegDS(theInstr); |
| 5632 | UChar rA_addr = ifieldRegA(theInstr); |
| 5633 | UChar rB_addr = ifieldRegB(theInstr); |
| 5634 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5635 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5636 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5637 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5638 | Int simm16 = extend_s_16to32(uimm16); |
| 5639 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 5640 | IRTemp EA = newTemp(ty); |
| 5641 | IRTemp rA = newTemp(ty); |
| 5642 | IRTemp rB = newTemp(ty); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5643 | |
| 5644 | assign( rA, getIReg(rA_addr) ); |
| 5645 | assign( rB, getIReg(rB_addr) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5646 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5647 | /* These are completely straightforward from a rounding and status |
| 5648 | bits perspective: no rounding involved and no funny status or CR |
| 5649 | bits affected. */ |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5650 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5651 | switch (opc1) { |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5652 | case 0x30: // lfs (Load Float Single, PPC32 p441) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5653 | DIP("lfs fr%u,%d(r%u)\n", frD_addr, simm16, rA_addr); |
| 5654 | assign( EA, ea_rAor0_simm(rA_addr, simm16) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5655 | putFReg( frD_addr, |
| 5656 | unop(Iop_F32toF64, loadBE(Ity_F32, mkexpr(EA))) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5657 | break; |
| 5658 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5659 | case 0x31: // lfsu (Load Float Single, Update, PPC32 p442) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5660 | if (rA_addr == 0) |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5661 | return False; |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5662 | DIP("lfsu fr%u,%d(r%u)\n", frD_addr, simm16, rA_addr); |
| 5663 | assign( EA, ea_rA_simm(rA_addr, simm16) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5664 | putFReg( frD_addr, |
| 5665 | unop(Iop_F32toF64, loadBE(Ity_F32, mkexpr(EA))) ); |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5666 | putIReg( rA_addr, mkexpr(EA) ); |
| 5667 | break; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5668 | |
| 5669 | case 0x32: // lfd (Load Float Double, PPC32 p437) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5670 | DIP("lfd fr%u,%d(r%u)\n", frD_addr, simm16, rA_addr); |
| 5671 | assign( EA, ea_rAor0_simm(rA_addr, simm16) ); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5672 | putFReg( frD_addr, loadBE(Ity_F64, mkexpr(EA)) ); |
| 5673 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5674 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5675 | case 0x33: // lfdu (Load Float Double, Update, PPC32 p438) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5676 | if (rA_addr == 0) |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 5677 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5678 | DIP("lfdu fr%u,%d(r%u)\n", frD_addr, simm16, rA_addr); |
| 5679 | assign( EA, ea_rA_simm(rA_addr, simm16) ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 5680 | putFReg( frD_addr, loadBE(Ity_F64, mkexpr(EA)) ); |
| 5681 | putIReg( rA_addr, mkexpr(EA) ); |
| 5682 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5683 | |
| 5684 | case 0x1F: |
| 5685 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5686 | vex_printf("dis_fp_load(ppc)(instr,b0)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5687 | return False; |
| 5688 | } |
| 5689 | |
| 5690 | switch(opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5691 | case 0x217: // lfsx (Load Float Single Indexed, PPC32 p444) |
| 5692 | DIP("lfsx fr%u,r%u,r%u\n", frD_addr, rA_addr, rB_addr); |
| 5693 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 5694 | putFReg( frD_addr, unop( Iop_F32toF64, |
| 5695 | loadBE(Ity_F32, mkexpr(EA))) ); |
| 5696 | break; |
| 5697 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5698 | case 0x237: // lfsux (Load Float Single, Update Indxd, PPC32 p443) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5699 | if (rA_addr == 0) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5700 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5701 | DIP("lfsux fr%u,r%u,r%u\n", frD_addr, rA_addr, rB_addr); |
| 5702 | assign( EA, ea_rA_idxd(rA_addr, rB_addr) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5703 | putFReg( frD_addr, |
| 5704 | unop(Iop_F32toF64, loadBE(Ity_F32, mkexpr(EA))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5705 | putIReg( rA_addr, mkexpr(EA) ); |
| 5706 | break; |
| 5707 | |
| 5708 | case 0x257: // lfdx (Load Float Double Indexed, PPC32 p440) |
| 5709 | DIP("lfdx fr%u,r%u,r%u\n", frD_addr, rA_addr, rB_addr); |
| 5710 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 5711 | putFReg( frD_addr, loadBE(Ity_F64, mkexpr(EA)) ); |
| 5712 | break; |
| 5713 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5714 | case 0x277: // lfdux (Load Float Double, Update Indxd, PPC32 p439) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5715 | if (rA_addr == 0) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5716 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5717 | DIP("lfdux fr%u,r%u,r%u\n", frD_addr, rA_addr, rB_addr); |
| 5718 | assign( EA, ea_rA_idxd(rA_addr, rB_addr) ); |
| 5719 | putFReg( frD_addr, loadBE(Ity_F64, mkexpr(EA)) ); |
| 5720 | putIReg( rA_addr, mkexpr(EA) ); |
| 5721 | break; |
| 5722 | |
| 5723 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5724 | vex_printf("dis_fp_load(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5725 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5726 | } |
| 5727 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5728 | |
| 5729 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5730 | vex_printf("dis_fp_load(ppc)(opc1)\n"); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5731 | return False; |
| 5732 | } |
| 5733 | return True; |
| 5734 | } |
| 5735 | |
| 5736 | |
| 5737 | |
| 5738 | /* |
| 5739 | Floating Point Store Instructions |
| 5740 | */ |
| 5741 | static Bool dis_fp_store ( UInt theInstr ) |
| 5742 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5743 | /* X-Form, D-Form */ |
| 5744 | UChar opc1 = ifieldOPC(theInstr); |
| 5745 | UChar frS_addr = ifieldRegDS(theInstr); |
| 5746 | UChar rA_addr = ifieldRegA(theInstr); |
| 5747 | UChar rB_addr = ifieldRegB(theInstr); |
| 5748 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5749 | UChar b0 = ifieldBIT0(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5750 | Int uimm16 = ifieldUIMM16(theInstr); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5751 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5752 | Int simm16 = extend_s_16to32(uimm16); |
| 5753 | IRTemp frS = newTemp(Ity_F64); |
| 5754 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 5755 | IRTemp EA = newTemp(ty); |
| 5756 | IRTemp rA = newTemp(ty); |
| 5757 | IRTemp rB = newTemp(ty); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5758 | |
| 5759 | assign( frS, getFReg(frS_addr) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5760 | assign( rA, getIReg(rA_addr) ); |
| 5761 | assign( rB, getIReg(rB_addr) ); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5762 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5763 | /* These are straightforward from a status bits perspective: no |
| 5764 | funny status or CR bits affected. For single precision stores, |
| 5765 | the values are truncated and denormalised (not rounded) to turn |
| 5766 | them into single precision values. */ |
| 5767 | |
| 5768 | switch (opc1) { |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5769 | |
| 5770 | case 0x34: // stfs (Store Float Single, PPC32 p518) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5771 | DIP("stfs fr%u,%d(r%u)\n", frS_addr, simm16, rA_addr); |
| 5772 | assign( EA, ea_rAor0_simm(rA_addr, simm16) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5773 | /* Use Iop_TruncF64asF32 to truncate and possible denormalise |
| 5774 | the value to be stored in the correct way, without any |
| 5775 | rounding. */ |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5776 | storeBE( mkexpr(EA), |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5777 | unop(Iop_TruncF64asF32, mkexpr(frS)) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5778 | break; |
| 5779 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5780 | case 0x35: // stfsu (Store Float Single, Update, PPC32 p519) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5781 | if (rA_addr == 0) |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5782 | return False; |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5783 | DIP("stfsu fr%u,%d(r%u)\n", frS_addr, simm16, rA_addr); |
| 5784 | assign( EA, ea_rA_simm(rA_addr, simm16) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5785 | /* See comment for stfs */ |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5786 | storeBE( mkexpr(EA), |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5787 | unop(Iop_TruncF64asF32, mkexpr(frS)) ); |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5788 | putIReg( rA_addr, mkexpr(EA) ); |
| 5789 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5790 | |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5791 | case 0x36: // stfd (Store Float Double, PPC32 p513) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5792 | DIP("stfd fr%u,%d(r%u)\n", frS_addr, simm16, rA_addr); |
| 5793 | assign( EA, ea_rAor0_simm(rA_addr, simm16) ); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5794 | storeBE( mkexpr(EA), mkexpr(frS) ); |
| 5795 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5796 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5797 | case 0x37: // stfdu (Store Float Double, Update, PPC32 p514) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5798 | if (rA_addr == 0) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5799 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5800 | DIP("stfdu fr%u,%d(r%u)\n", frS_addr, simm16, rA_addr); |
| 5801 | assign( EA, ea_rA_simm(rA_addr, simm16) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5802 | storeBE( mkexpr(EA), mkexpr(frS) ); |
| 5803 | putIReg( rA_addr, mkexpr(EA) ); |
| 5804 | break; |
| 5805 | |
| 5806 | case 0x1F: |
| 5807 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5808 | vex_printf("dis_fp_store(ppc)(instr,b0)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5809 | return False; |
| 5810 | } |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5811 | switch(opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5812 | case 0x297: // stfsx (Store Float Single Indexed, PPC32 p521) |
| 5813 | DIP("stfsx fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5814 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5815 | /* See note for stfs */ |
| 5816 | storeBE( mkexpr(EA), |
| 5817 | unop(Iop_TruncF64asF32, mkexpr(frS)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5818 | break; |
| 5819 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5820 | case 0x2B7: // stfsux (Store Float Sgl, Update Indxd, PPC32 p520) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5821 | if (rA_addr == 0) |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5822 | return False; |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5823 | DIP("stfsux fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5824 | assign( EA, ea_rA_idxd(rA_addr, rB_addr) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5825 | /* See note for stfs */ |
| 5826 | storeBE( mkexpr(EA), |
| 5827 | unop(Iop_TruncF64asF32, mkexpr(frS)) ); |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5828 | putIReg( rA_addr, mkexpr(EA) ); |
| 5829 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5830 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5831 | case 0x2D7: // stfdx (Store Float Double Indexed, PPC32 p516) |
| 5832 | DIP("stfdx fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5833 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 5834 | storeBE( mkexpr(EA), mkexpr(frS) ); |
| 5835 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5836 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5837 | case 0x2F7: // stfdux (Store Float Dbl, Update Indxd, PPC32 p515) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5838 | if (rA_addr == 0) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5839 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5840 | DIP("stfdux fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5841 | assign( EA, ea_rA_idxd(rA_addr, rB_addr) ); |
| 5842 | storeBE( mkexpr(EA), mkexpr(frS) ); |
| 5843 | putIReg( rA_addr, mkexpr(EA) ); |
| 5844 | break; |
sewardj | 5f63c0c | 2005-09-09 10:36:55 +0000 | [diff] [blame] | 5845 | |
sewardj | 09e88d1 | 2006-01-27 16:05:49 +0000 | [diff] [blame] | 5846 | case 0x3D7: // stfiwx (Store Float as Int, Indexed, PPC32 p517) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 5847 | // NOTE: POWERPC OPTIONAL, "Graphics Group" (PPC32_GX) |
sewardj | 09e88d1 | 2006-01-27 16:05:49 +0000 | [diff] [blame] | 5848 | DIP("stfiwx fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5849 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 5850 | storeBE( mkexpr(EA), |
| 5851 | unop(Iop_64to32, unop(Iop_ReinterpF64asI64, mkexpr(frS))) ); |
| 5852 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5853 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5854 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5855 | vex_printf("dis_fp_store(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5856 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5857 | } |
| 5858 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5859 | |
| 5860 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5861 | vex_printf("dis_fp_store(ppc)(opc1)\n"); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5862 | return False; |
| 5863 | } |
| 5864 | return True; |
| 5865 | } |
| 5866 | |
| 5867 | |
| 5868 | |
| 5869 | /* |
| 5870 | Floating Point Arith Instructions |
| 5871 | */ |
| 5872 | static Bool dis_fp_arith ( UInt theInstr ) |
| 5873 | { |
| 5874 | /* A-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5875 | UChar opc1 = ifieldOPC(theInstr); |
| 5876 | UChar frD_addr = ifieldRegDS(theInstr); |
| 5877 | UChar frA_addr = ifieldRegA(theInstr); |
| 5878 | UChar frB_addr = ifieldRegB(theInstr); |
| 5879 | UChar frC_addr = ifieldRegC(theInstr); |
| 5880 | UChar opc2 = ifieldOPClo5(theInstr); |
| 5881 | UChar flag_rC = ifieldBIT0(theInstr); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5882 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5883 | IRTemp frD = newTemp(Ity_F64); |
| 5884 | IRTemp frA = newTemp(Ity_F64); |
| 5885 | IRTemp frB = newTemp(Ity_F64); |
| 5886 | IRTemp frC = newTemp(Ity_F64); |
| 5887 | IRExpr* rm = get_IR_roundingmode(); |
| 5888 | |
| 5889 | /* By default, we will examine the results of the operation and set |
| 5890 | fpscr[FPRF] accordingly. */ |
| 5891 | Bool set_FPRF = True; |
| 5892 | |
| 5893 | /* By default, if flag_RC is set, we will clear cr1 after the |
| 5894 | operation. In reality we should set cr1 to indicate the |
| 5895 | exception status of the operation, but since we're not |
| 5896 | simulating exceptions, the exception status will appear to be |
| 5897 | zero. Hence cr1 should be cleared if this is a . form insn. */ |
| 5898 | Bool clear_CR1 = True; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5899 | |
| 5900 | assign( frA, getFReg(frA_addr)); |
| 5901 | assign( frB, getFReg(frB_addr)); |
| 5902 | assign( frC, getFReg(frC_addr)); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5903 | |
| 5904 | switch (opc1) { |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5905 | case 0x3B: |
| 5906 | switch (opc2) { |
| 5907 | case 0x12: // fdivs (Floating Divide Single, PPC32 p407) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5908 | if (frC_addr != 0) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5909 | return False; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5910 | DIP("fdivs%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5911 | frD_addr, frA_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5912 | assign( frD, triop( Iop_DivF64r32, |
| 5913 | rm, mkexpr(frA), mkexpr(frB) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5914 | break; |
| 5915 | |
| 5916 | case 0x14: // fsubs (Floating Subtract Single, PPC32 p430) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5917 | if (frC_addr != 0) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5918 | return False; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5919 | DIP("fsubs%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5920 | frD_addr, frA_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5921 | assign( frD, triop( Iop_SubF64r32, |
| 5922 | rm, mkexpr(frA), mkexpr(frB) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5923 | break; |
| 5924 | |
| 5925 | case 0x15: // fadds (Floating Add Single, PPC32 p401) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5926 | if (frC_addr != 0) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5927 | return False; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5928 | DIP("fadds%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5929 | frD_addr, frA_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5930 | assign( frD, triop( Iop_AddF64r32, |
| 5931 | rm, mkexpr(frA), mkexpr(frB) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5932 | break; |
| 5933 | |
sewardj | 870c84b | 2006-01-24 03:33:43 +0000 | [diff] [blame] | 5934 | case 0x16: // fsqrts (Floating SqRt (Single-Precision), PPC32 p428) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 5935 | // NOTE: POWERPC OPTIONAL, "General-Purpose Group" (PPC32_FX) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5936 | if (frA_addr != 0 || frC_addr != 0) |
sewardj | 870c84b | 2006-01-24 03:33:43 +0000 | [diff] [blame] | 5937 | return False; |
sewardj | 870c84b | 2006-01-24 03:33:43 +0000 | [diff] [blame] | 5938 | DIP("fsqrts%s fr%u,fr%u\n", flag_rC ? ".":"", |
| 5939 | frD_addr, frB_addr); |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 5940 | // however illogically, on ppc970 this insn behaves identically |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5941 | // to fsqrt (double-precision). So use SqrtF64, not SqrtF64r32. |
| 5942 | assign( frD, binop( Iop_SqrtF64, rm, mkexpr(frB) )); |
sewardj | 870c84b | 2006-01-24 03:33:43 +0000 | [diff] [blame] | 5943 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5944 | |
sewardj | baf971a | 2006-01-27 15:09:35 +0000 | [diff] [blame] | 5945 | case 0x18: // fres (Floating Reciprocal Estimate Single, PPC32 p421) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 5946 | // NOTE: POWERPC OPTIONAL, "Graphics Group" (PPC32_GX) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5947 | if (frA_addr != 0 || frC_addr != 0) |
sewardj | baf971a | 2006-01-27 15:09:35 +0000 | [diff] [blame] | 5948 | return False; |
sewardj | baf971a | 2006-01-27 15:09:35 +0000 | [diff] [blame] | 5949 | DIP("fres%s fr%u,fr%u\n", flag_rC ? ".":"", |
| 5950 | frD_addr, frB_addr); |
sewardj | 157b19b | 2006-01-31 16:32:25 +0000 | [diff] [blame] | 5951 | { IRExpr* ieee_one |
| 5952 | = IRExpr_Const(IRConst_F64i(0x3ff0000000000000ULL)); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5953 | assign( frD, triop( Iop_DivF64r32, |
| 5954 | rm, |
| 5955 | ieee_one, mkexpr(frB) )); |
sewardj | 157b19b | 2006-01-31 16:32:25 +0000 | [diff] [blame] | 5956 | } |
sewardj | baf971a | 2006-01-27 15:09:35 +0000 | [diff] [blame] | 5957 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5958 | |
| 5959 | case 0x19: // fmuls (Floating Multiply Single, PPC32 p414) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5960 | if (frB_addr != 0) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5961 | return False; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5962 | DIP("fmuls%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5963 | frD_addr, frA_addr, frC_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5964 | assign( frD, triop( Iop_MulF64r32, |
| 5965 | rm, mkexpr(frA), mkexpr(frC) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5966 | break; |
| 5967 | |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 5968 | case 0x1A: // frsqrtes (Floating Recip SqRt Est Single) |
| 5969 | // NOTE: POWERPC OPTIONAL, "Graphics Group" (PPC32_GX) |
| 5970 | // Undocumented instruction? |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5971 | if (frA_addr != 0 || frC_addr != 0) |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 5972 | return False; |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 5973 | DIP("frsqrtes%s fr%u,fr%u\n", flag_rC ? ".":"", |
| 5974 | frD_addr, frB_addr); |
| 5975 | assign( frD, unop(Iop_Est5FRSqrt, mkexpr(frB)) ); |
| 5976 | break; |
| 5977 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5978 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5979 | vex_printf("dis_fp_arith(ppc)(3B: opc2)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5980 | return False; |
| 5981 | } |
| 5982 | break; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5983 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5984 | case 0x3F: |
| 5985 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5986 | case 0x12: // fdiv (Floating Div (Double-Precision), PPC32 p406) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5987 | if (frC_addr != 0) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5988 | return False; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5989 | DIP("fdiv%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5990 | frD_addr, frA_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5991 | assign( frD, triop(Iop_DivF64, rm, mkexpr(frA), mkexpr(frB)) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5992 | break; |
| 5993 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5994 | case 0x14: // fsub (Floating Sub (Double-Precision), PPC32 p429) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5995 | if (frC_addr != 0) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5996 | return False; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5997 | DIP("fsub%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5998 | frD_addr, frA_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 5999 | assign( frD, triop(Iop_SubF64, rm, mkexpr(frA), mkexpr(frB)) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6000 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 6001 | |
| 6002 | case 0x15: // fadd (Floating Add (Double-Precision), PPC32 p400) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6003 | if (frC_addr != 0) |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 6004 | return False; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6005 | DIP("fadd%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 6006 | frD_addr, frA_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6007 | assign( frD, triop(Iop_AddF64, rm, mkexpr(frA), mkexpr(frB)) ); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 6008 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 6009 | |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 6010 | case 0x16: // fsqrt (Floating SqRt (Double-Precision), PPC32 p427) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 6011 | // NOTE: POWERPC OPTIONAL, "General-Purpose Group" (PPC32_FX) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6012 | if (frA_addr != 0 || frC_addr != 0) |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 6013 | return False; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6014 | DIP("fsqrt%s fr%u,fr%u\n", flag_rC ? ".":"", |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 6015 | frD_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6016 | assign( frD, binop(Iop_SqrtF64, rm, mkexpr(frB)) ); |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 6017 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6018 | |
| 6019 | case 0x17: { // fsel (Floating Select, PPC32 p426) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 6020 | // NOTE: POWERPC OPTIONAL, "Graphics Group" (PPC32_GX) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6021 | IRTemp cc = newTemp(Ity_I32); |
| 6022 | IRTemp cc_b0 = newTemp(Ity_I32); |
| 6023 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6024 | DIP("fsel%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6025 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 6026 | |
| 6027 | // cc: UN == 0x41, LT == 0x01, GT == 0x00, EQ == 0x40 |
| 6028 | // => GT|EQ == (cc & 0x1 == 0) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6029 | assign( cc, binop(Iop_CmpF64, mkexpr(frA), |
| 6030 | IRExpr_Const(IRConst_F64(0))) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6031 | assign( cc_b0, binop(Iop_And32, mkexpr(cc), mkU32(1)) ); |
| 6032 | |
| 6033 | // frD = (frA >= 0.0) ? frC : frB |
| 6034 | // = (cc_b0 == 0) ? frC : frB |
| 6035 | assign( frD, |
| 6036 | IRExpr_Mux0X( |
| 6037 | unop(Iop_1Uto8, |
| 6038 | binop(Iop_CmpEQ32, mkexpr(cc_b0), mkU32(0))), |
| 6039 | mkexpr(frB), |
| 6040 | mkexpr(frC) )); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6041 | |
| 6042 | /* One of the rare ones which don't mess with FPRF */ |
| 6043 | set_FPRF = False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6044 | break; |
| 6045 | } |
| 6046 | |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 6047 | case 0x18: // fre (Floating Reciprocal Estimate) |
| 6048 | // NOTE: POWERPC OPTIONAL, "Graphics Group" (PPC32_GX) |
| 6049 | // Note: unclear whether this insn really exists or not |
| 6050 | // ppc970 doesn't have it, but POWER5 does |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6051 | if (frA_addr != 0 || frC_addr != 0) |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 6052 | return False; |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 6053 | DIP("fre%s fr%u,fr%u\n", flag_rC ? ".":"", |
| 6054 | frD_addr, frB_addr); |
sewardj | 157b19b | 2006-01-31 16:32:25 +0000 | [diff] [blame] | 6055 | { IRExpr* ieee_one |
| 6056 | = IRExpr_Const(IRConst_F64i(0x3ff0000000000000ULL)); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6057 | assign( frD, triop( Iop_DivF64, |
sewardj | 56de421 | 2006-02-06 22:19:17 +0000 | [diff] [blame] | 6058 | rm, |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6059 | ieee_one, mkexpr(frB) )); |
sewardj | 157b19b | 2006-01-31 16:32:25 +0000 | [diff] [blame] | 6060 | } |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 6061 | break; |
| 6062 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6063 | case 0x19: // fmul (Floating Mult (Double Precision), PPC32 p413) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6064 | if (frB_addr != 0) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6065 | vex_printf("dis_fp_arith(ppc)(instr,fmul)\n"); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6066 | DIP("fmul%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6067 | frD_addr, frA_addr, frC_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6068 | assign( frD, triop(Iop_MulF64, rm, mkexpr(frA), mkexpr(frC)) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6069 | break; |
| 6070 | |
sewardj | baf971a | 2006-01-27 15:09:35 +0000 | [diff] [blame] | 6071 | case 0x1A: // frsqrte (Floating Recip SqRt Est., PPC32 p424) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 6072 | // NOTE: POWERPC OPTIONAL, "Graphics Group" (PPC32_GX) |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6073 | if (frA_addr != 0 || frC_addr != 0) |
sewardj | baf971a | 2006-01-27 15:09:35 +0000 | [diff] [blame] | 6074 | return False; |
sewardj | baf971a | 2006-01-27 15:09:35 +0000 | [diff] [blame] | 6075 | DIP("frsqrte%s fr%u,fr%u\n", flag_rC ? ".":"", |
| 6076 | frD_addr, frB_addr); |
| 6077 | assign( frD, unop(Iop_Est5FRSqrt, mkexpr(frB)) ); |
| 6078 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 6079 | |
| 6080 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6081 | vex_printf("dis_fp_arith(ppc)(3F: opc2)\n"); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 6082 | return False; |
| 6083 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 6084 | break; |
| 6085 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 6086 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6087 | vex_printf("dis_fp_arith(ppc)(opc1)\n"); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 6088 | return False; |
| 6089 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 6090 | |
| 6091 | putFReg( frD_addr, mkexpr(frD) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6092 | |
| 6093 | if (set_FPRF) { |
| 6094 | // XXX XXX XXX FIXME |
| 6095 | // set FPRF from frD |
| 6096 | } |
| 6097 | |
| 6098 | if (flag_rC && clear_CR1) { |
| 6099 | putCR321( 1, mkU8(0) ); |
| 6100 | putCR0( 1, mkU8(0) ); |
| 6101 | } |
| 6102 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 6103 | return True; |
| 6104 | } |
| 6105 | |
| 6106 | |
| 6107 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6108 | /* |
| 6109 | Floating Point Mult-Add Instructions |
| 6110 | */ |
| 6111 | static Bool dis_fp_multadd ( UInt theInstr ) |
| 6112 | { |
| 6113 | /* A-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6114 | UChar opc1 = ifieldOPC(theInstr); |
| 6115 | UChar frD_addr = ifieldRegDS(theInstr); |
| 6116 | UChar frA_addr = ifieldRegA(theInstr); |
| 6117 | UChar frB_addr = ifieldRegB(theInstr); |
| 6118 | UChar frC_addr = ifieldRegC(theInstr); |
| 6119 | UChar opc2 = ifieldOPClo5(theInstr); |
| 6120 | UChar flag_rC = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6121 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6122 | IRTemp frD = newTemp(Ity_F64); |
| 6123 | IRTemp frA = newTemp(Ity_F64); |
| 6124 | IRTemp frB = newTemp(Ity_F64); |
| 6125 | IRTemp frC = newTemp(Ity_F64); |
| 6126 | IRTemp rmt = newTemp(Ity_I32); |
| 6127 | IRExpr* rm; |
| 6128 | |
| 6129 | /* By default, we will examine the results of the operation and set |
| 6130 | fpscr[FPRF] accordingly. */ |
| 6131 | Bool set_FPRF = True; |
| 6132 | |
| 6133 | /* By default, if flag_RC is set, we will clear cr1 after the |
| 6134 | operation. In reality we should set cr1 to indicate the |
| 6135 | exception status of the operation, but since we're not |
| 6136 | simulating exceptions, the exception status will appear to be |
| 6137 | zero. Hence cr1 should be cleared if this is a . form insn. */ |
| 6138 | Bool clear_CR1 = True; |
| 6139 | |
| 6140 | /* Bind the rounding mode expression to a temp; there's no |
| 6141 | point in creating gratuitous CSEs, as we know we'll need |
| 6142 | to use it twice. */ |
| 6143 | assign( rmt, get_IR_roundingmode() ); |
| 6144 | rm = mkexpr(rmt); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6145 | |
| 6146 | assign( frA, getFReg(frA_addr)); |
| 6147 | assign( frB, getFReg(frB_addr)); |
| 6148 | assign( frC, getFReg(frC_addr)); |
| 6149 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6150 | /* The rounding in this is all a bit dodgy. The idea is to only do |
| 6151 | one rounding. That clearly isn't achieveable without dedicated |
| 6152 | four-input IR primops, although in the single precision case we |
| 6153 | can sort-of simulate it by doing the inner multiply in double |
| 6154 | precision. |
| 6155 | |
| 6156 | In the negated cases, the negation happens after rounding. */ |
| 6157 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6158 | switch (opc1) { |
| 6159 | case 0x3B: |
| 6160 | switch (opc2) { |
| 6161 | case 0x1C: // fmsubs (Floating Mult-Subtr Single, PPC32 p412) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6162 | DIP("fmsubs%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6163 | frD_addr, frA_addr, frC_addr, frB_addr); |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 6164 | assign( frD, qop( Iop_MSubF64r32, rm, |
| 6165 | mkexpr(frA), mkexpr(frC), mkexpr(frB) )); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6166 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6167 | |
| 6168 | case 0x1D: // fmadds (Floating Mult-Add Single, PPC32 p409) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6169 | DIP("fmadds%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6170 | frD_addr, frA_addr, frC_addr, frB_addr); |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 6171 | assign( frD, qop( Iop_MAddF64r32, rm, |
| 6172 | mkexpr(frA), mkexpr(frC), mkexpr(frB) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6173 | break; |
| 6174 | |
| 6175 | case 0x1E: // fnmsubs (Float Neg Mult-Subtr Single, PPC32 p420) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6176 | DIP("fnmsubs%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6177 | frD_addr, frA_addr, frC_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6178 | assign( frD, unop( Iop_NegF64, |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 6179 | qop( Iop_MSubF64r32, rm, |
| 6180 | mkexpr(frA), mkexpr(frC), mkexpr(frB) ))); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6181 | break; |
| 6182 | |
| 6183 | case 0x1F: // fnmadds (Floating Negative Multiply-Add Single, PPC32 p418) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6184 | DIP("fnmadds%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6185 | frD_addr, frA_addr, frC_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6186 | assign( frD, unop( Iop_NegF64, |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 6187 | qop( Iop_MAddF64r32, rm, |
| 6188 | mkexpr(frA), mkexpr(frC), mkexpr(frB) ))); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6189 | break; |
| 6190 | |
| 6191 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6192 | vex_printf("dis_fp_multadd(ppc)(3B: opc2)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6193 | return False; |
| 6194 | } |
| 6195 | break; |
| 6196 | |
| 6197 | case 0x3F: |
| 6198 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6199 | case 0x1C: // fmsub (Float Mult-Sub (Dbl Precision), PPC32 p411) |
| 6200 | DIP("fmsub%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6201 | frD_addr, frA_addr, frC_addr, frB_addr); |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 6202 | assign( frD, qop( Iop_MSubF64, rm, |
| 6203 | mkexpr(frA), mkexpr(frC), mkexpr(frB) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6204 | break; |
| 6205 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6206 | case 0x1D: // fmadd (Float Mult-Add (Dbl Precision), PPC32 p408) |
| 6207 | DIP("fmadd%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6208 | frD_addr, frA_addr, frC_addr, frB_addr); |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 6209 | assign( frD, qop( Iop_MAddF64, rm, |
| 6210 | mkexpr(frA), mkexpr(frC), mkexpr(frB) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6211 | break; |
| 6212 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6213 | case 0x1E: // fnmsub (Float Neg Mult-Subtr (Dbl Precision), PPC32 p419) |
| 6214 | DIP("fnmsub%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6215 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 6216 | assign( frD, unop( Iop_NegF64, |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 6217 | qop( Iop_MSubF64, rm, |
| 6218 | mkexpr(frA), mkexpr(frC), mkexpr(frB) ))); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6219 | break; |
| 6220 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6221 | case 0x1F: // fnmadd (Float Neg Mult-Add (Dbl Precision), PPC32 p417) |
| 6222 | DIP("fnmadd%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6223 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 6224 | assign( frD, unop( Iop_NegF64, |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 6225 | qop( Iop_MAddF64, rm, |
| 6226 | mkexpr(frA), mkexpr(frC), mkexpr(frB) ))); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6227 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6228 | |
| 6229 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6230 | vex_printf("dis_fp_multadd(ppc)(3F: opc2)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6231 | return False; |
| 6232 | } |
| 6233 | break; |
| 6234 | |
| 6235 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6236 | vex_printf("dis_fp_multadd(ppc)(opc1)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6237 | return False; |
| 6238 | } |
| 6239 | |
| 6240 | putFReg( frD_addr, mkexpr(frD) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6241 | |
| 6242 | if (set_FPRF) { |
| 6243 | // XXX XXX XXX FIXME |
| 6244 | // set FPRF from frD |
| 6245 | } |
| 6246 | |
| 6247 | if (flag_rC && clear_CR1) { |
| 6248 | putCR321( 1, mkU8(0) ); |
| 6249 | putCR0( 1, mkU8(0) ); |
| 6250 | } |
| 6251 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6252 | return True; |
| 6253 | } |
| 6254 | |
| 6255 | |
| 6256 | |
| 6257 | /* |
| 6258 | Floating Point Compare Instructions |
| 6259 | */ |
| 6260 | static Bool dis_fp_cmp ( UInt theInstr ) |
| 6261 | { |
| 6262 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6263 | UChar opc1 = ifieldOPC(theInstr); |
| 6264 | UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 6265 | UChar b21to22 = toUChar( IFIELD( theInstr, 21, 2 ) ); |
| 6266 | UChar frA_addr = ifieldRegA(theInstr); |
| 6267 | UChar frB_addr = ifieldRegB(theInstr); |
| 6268 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6269 | UChar b0 = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6270 | |
| 6271 | IRTemp ccIR = newTemp(Ity_I32); |
| 6272 | IRTemp ccPPC32 = newTemp(Ity_I32); |
| 6273 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6274 | IRTemp frA = newTemp(Ity_F64); |
| 6275 | IRTemp frB = newTemp(Ity_F64); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6276 | |
| 6277 | if (opc1 != 0x3F || b21to22 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6278 | vex_printf("dis_fp_cmp(ppc)(instr)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6279 | return False; |
| 6280 | } |
| 6281 | |
| 6282 | assign( frA, getFReg(frA_addr)); |
| 6283 | assign( frB, getFReg(frB_addr)); |
| 6284 | |
| 6285 | assign( ccIR, binop(Iop_CmpF64, mkexpr(frA), mkexpr(frB)) ); |
| 6286 | |
| 6287 | /* Map compare result from IR to PPC32 */ |
| 6288 | /* |
| 6289 | FP cmp result | PPC | IR |
| 6290 | -------------------------- |
| 6291 | UN | 0x1 | 0x45 |
| 6292 | EQ | 0x2 | 0x40 |
| 6293 | GT | 0x4 | 0x00 |
| 6294 | LT | 0x8 | 0x01 |
| 6295 | */ |
| 6296 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6297 | // ccPPC32 = Shl(1, (~(ccIR>>5) & 2) |
| 6298 | // | ((ccIR ^ (ccIR>>6)) & 1) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6299 | assign( |
| 6300 | ccPPC32, |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6301 | binop( |
| 6302 | Iop_Shl32, |
| 6303 | mkU32(1), |
| 6304 | unop( |
| 6305 | Iop_32to8, |
| 6306 | binop( |
| 6307 | Iop_Or32, |
| 6308 | binop( |
| 6309 | Iop_And32, |
| 6310 | unop( |
| 6311 | Iop_Not32, |
| 6312 | binop(Iop_Shr32, mkexpr(ccIR), mkU8(5)) |
| 6313 | ), |
| 6314 | mkU32(2) |
| 6315 | ), |
| 6316 | binop( |
| 6317 | Iop_And32, |
| 6318 | binop( |
| 6319 | Iop_Xor32, |
| 6320 | mkexpr(ccIR), |
| 6321 | binop(Iop_Shr32, mkexpr(ccIR), mkU8(6)) |
| 6322 | ), |
| 6323 | mkU32(1) |
| 6324 | ) |
| 6325 | ) |
| 6326 | ) |
| 6327 | ) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6328 | ); |
| 6329 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6330 | putGST_field( PPC_GST_CR, mkexpr(ccPPC32), crfD ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6331 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 6332 | /* CAB: TODO?: Support writing cc to FPSCR->FPCC ? |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6333 | putGST_field( PPC_GST_FPSCR, mkexpr(ccPPC32), 4 ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 6334 | */ |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6335 | // XXX XXX XXX FIXME |
| 6336 | // Also write the result into FPRF (it's not entirely clear how) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6337 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 6338 | /* Note: Differences between fcmpu and fcmpo are only in exception |
| 6339 | flag settings, which aren't supported anyway. */ |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6340 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6341 | case 0x000: // fcmpu (Floating Compare Unordered, PPC32 p403) |
| 6342 | DIP("fcmpu crf%d,fr%u,fr%u\n", crfD, frA_addr, frB_addr); |
| 6343 | break; |
| 6344 | case 0x020: // fcmpo (Floating Compare Ordered, PPC32 p402) |
| 6345 | DIP("fcmpo crf%d,fr%u,fr%u\n", crfD, frA_addr, frB_addr); |
| 6346 | break; |
| 6347 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6348 | vex_printf("dis_fp_cmp(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6349 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6350 | } |
| 6351 | return True; |
| 6352 | } |
| 6353 | |
| 6354 | |
| 6355 | |
| 6356 | /* |
| 6357 | Floating Point Rounding/Conversion Instructions |
| 6358 | */ |
| 6359 | static Bool dis_fp_round ( UInt theInstr ) |
| 6360 | { |
| 6361 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6362 | UChar opc1 = ifieldOPC(theInstr); |
| 6363 | UChar frD_addr = ifieldRegDS(theInstr); |
| 6364 | UChar b16to20 = ifieldRegA(theInstr); |
| 6365 | UChar frB_addr = ifieldRegB(theInstr); |
| 6366 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6367 | UChar flag_rC = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6368 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6369 | IRTemp frD = newTemp(Ity_F64); |
| 6370 | IRTemp frB = newTemp(Ity_F64); |
| 6371 | IRTemp r_tmp32 = newTemp(Ity_I32); |
| 6372 | IRTemp r_tmp64 = newTemp(Ity_I64); |
| 6373 | IRExpr* rm = get_IR_roundingmode(); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6374 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6375 | /* By default, we will examine the results of the operation and set |
| 6376 | fpscr[FPRF] accordingly. */ |
| 6377 | Bool set_FPRF = True; |
| 6378 | |
| 6379 | /* By default, if flag_RC is set, we will clear cr1 after the |
| 6380 | operation. In reality we should set cr1 to indicate the |
| 6381 | exception status of the operation, but since we're not |
| 6382 | simulating exceptions, the exception status will appear to be |
| 6383 | zero. Hence cr1 should be cleared if this is a . form insn. */ |
| 6384 | Bool clear_CR1 = True; |
| 6385 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6386 | if (opc1 != 0x3F || b16to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6387 | vex_printf("dis_fp_round(ppc)(instr)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6388 | return False; |
| 6389 | } |
| 6390 | |
| 6391 | assign( frB, getFReg(frB_addr)); |
| 6392 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6393 | switch (opc2) { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 6394 | case 0x00C: // frsp (Float Round to Single, PPC32 p423) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6395 | DIP("frsp%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6396 | assign( frD, binop( Iop_RoundF64toF32, rm, mkexpr(frB) )); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6397 | break; |
| 6398 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 6399 | case 0x00E: // fctiw (Float Conv to Int, PPC32 p404) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6400 | DIP("fctiw%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
| 6401 | assign( r_tmp32, |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6402 | binop(Iop_F64toI32, rm, mkexpr(frB)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6403 | assign( frD, unop( Iop_ReinterpI64asF64, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 6404 | unop( Iop_32Uto64, mkexpr(r_tmp32)))); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6405 | /* FPRF is undefined after fctiw. Leave unchanged. */ |
| 6406 | set_FPRF = False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6407 | break; |
| 6408 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 6409 | case 0x00F: // fctiwz (Float Conv to Int, Round to Zero, PPC32 p405) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6410 | DIP("fctiwz%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6411 | assign( r_tmp32, |
| 6412 | binop(Iop_F64toI32, mkU32(Irrm_ZERO), mkexpr(frB) )); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6413 | assign( frD, unop( Iop_ReinterpI64asF64, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 6414 | unop( Iop_32Uto64, mkexpr(r_tmp32)))); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6415 | /* FPRF is undefined after fctiwz. Leave unchanged. */ |
| 6416 | set_FPRF = False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6417 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 6418 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6419 | case 0x32E: // fctid (Float Conv to Int DWord, PPC64 p437) |
| 6420 | DIP("fctid%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
| 6421 | assign( r_tmp64, |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6422 | binop(Iop_F64toI64, rm, mkexpr(frB)) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 6423 | assign( frD, unop( Iop_ReinterpI64asF64, mkexpr(r_tmp64)) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6424 | /* FPRF is undefined after fctid. Leave unchanged. */ |
| 6425 | set_FPRF = False; |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 6426 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 6427 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6428 | case 0x32F: // fctidz (Float Conv to Int DWord, Round to Zero, PPC64 p437) |
| 6429 | DIP("fctidz%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6430 | assign( r_tmp64, |
| 6431 | binop(Iop_F64toI64, mkU32(Irrm_ZERO), mkexpr(frB)) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 6432 | assign( frD, unop( Iop_ReinterpI64asF64, mkexpr(r_tmp64)) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6433 | /* FPRF is undefined after fctidz. Leave unchanged. */ |
| 6434 | set_FPRF = False; |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 6435 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 6436 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6437 | case 0x34E: // fcfid (Float Conv from Int DWord, PPC64 p434) |
| 6438 | DIP("fcfid%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 6439 | assign( r_tmp64, unop( Iop_ReinterpF64asI64, mkexpr(frB)) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6440 | assign( frD, |
| 6441 | binop(Iop_I64toF64, rm, mkexpr(r_tmp64)) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 6442 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 6443 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6444 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6445 | vex_printf("dis_fp_round(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6446 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6447 | } |
| 6448 | |
| 6449 | putFReg( frD_addr, mkexpr(frD) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6450 | |
| 6451 | if (set_FPRF) { |
| 6452 | // XXX XXX XXX FIXME |
| 6453 | // set FPRF from frD |
| 6454 | } |
| 6455 | |
| 6456 | if (flag_rC && clear_CR1) { |
| 6457 | putCR321( 1, mkU8(0) ); |
| 6458 | putCR0( 1, mkU8(0) ); |
| 6459 | } |
| 6460 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6461 | return True; |
| 6462 | } |
| 6463 | |
| 6464 | |
| 6465 | |
| 6466 | /* |
| 6467 | Floating Point Move Instructions |
| 6468 | */ |
| 6469 | static Bool dis_fp_move ( UInt theInstr ) |
| 6470 | { |
| 6471 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6472 | UChar opc1 = ifieldOPC(theInstr); |
| 6473 | UChar frD_addr = ifieldRegDS(theInstr); |
| 6474 | UChar b16to20 = ifieldRegA(theInstr); |
| 6475 | UChar frB_addr = ifieldRegB(theInstr); |
| 6476 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6477 | UChar flag_rC = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6478 | |
| 6479 | IRTemp frD = newTemp(Ity_F64); |
| 6480 | IRTemp frB = newTemp(Ity_F64); |
| 6481 | |
| 6482 | if (opc1 != 0x3F || b16to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6483 | vex_printf("dis_fp_move(ppc)(instr)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6484 | return False; |
| 6485 | } |
| 6486 | |
| 6487 | assign( frB, getFReg(frB_addr)); |
| 6488 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6489 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6490 | case 0x028: // fneg (Floating Negate, PPC32 p416) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6491 | DIP("fneg%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6492 | assign( frD, unop( Iop_NegF64, mkexpr(frB) )); |
| 6493 | break; |
| 6494 | |
| 6495 | case 0x048: // fmr (Floating Move Register, PPC32 p410) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6496 | DIP("fmr%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6497 | assign( frD, mkexpr(frB) ); |
| 6498 | break; |
| 6499 | |
| 6500 | case 0x088: // fnabs (Floating Negative Absolute Value, PPC32 p415) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6501 | DIP("fnabs%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6502 | assign( frD, unop( Iop_NegF64, unop( Iop_AbsF64, mkexpr(frB) ))); |
| 6503 | break; |
| 6504 | |
| 6505 | case 0x108: // fabs (Floating Absolute Value, PPC32 p399) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6506 | DIP("fabs%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6507 | assign( frD, unop( Iop_AbsF64, mkexpr(frB) )); |
| 6508 | break; |
| 6509 | |
| 6510 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6511 | vex_printf("dis_fp_move(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6512 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6513 | } |
| 6514 | |
| 6515 | putFReg( frD_addr, mkexpr(frD) ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 6516 | |
| 6517 | /* None of these change FPRF. cr1 is set in the usual way though, |
| 6518 | if flag_rC is set. */ |
| 6519 | |
| 6520 | if (flag_rC) { |
| 6521 | putCR321( 1, mkU8(0) ); |
| 6522 | putCR0( 1, mkU8(0) ); |
| 6523 | } |
| 6524 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6525 | return True; |
| 6526 | } |
| 6527 | |
| 6528 | |
| 6529 | |
| 6530 | /* |
| 6531 | Floating Point Status/Control Register Instructions |
| 6532 | */ |
| 6533 | static Bool dis_fp_scr ( UInt theInstr ) |
| 6534 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6535 | /* Many forms - see each switch case */ |
| 6536 | UChar opc1 = ifieldOPC(theInstr); |
| 6537 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6538 | UChar flag_rC = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6539 | |
| 6540 | if (opc1 != 0x3F) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6541 | vex_printf("dis_fp_scr(ppc)(instr)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6542 | return False; |
| 6543 | } |
| 6544 | |
| 6545 | switch (opc2) { |
cerion | 3ea49ee | 2006-01-04 10:53:00 +0000 | [diff] [blame] | 6546 | case 0x026: { // mtfsb1 (Move to FPSCR Bit 1, PPC32 p479) |
| 6547 | // Bit crbD of the FPSCR is set. |
| 6548 | UChar crbD = ifieldRegDS(theInstr); |
| 6549 | UInt b11to20 = IFIELD(theInstr, 11, 10); |
| 6550 | |
| 6551 | if (b11to20 != 0) { |
| 6552 | vex_printf("dis_fp_scr(ppc)(instr,mtfsb1)\n"); |
| 6553 | return False; |
| 6554 | } |
| 6555 | DIP("mtfsb1%s crb%d \n", flag_rC ? ".":"", crbD); |
| 6556 | putGST_masked( PPC_GST_FPSCR, mkU32(1<<(31-crbD)), 1<<(31-crbD) ); |
| 6557 | break; |
| 6558 | } |
| 6559 | |
sewardj | 496b88f | 2006-10-04 17:46:11 +0000 | [diff] [blame] | 6560 | case 0x040: { // mcrfs (Move to Condition Register from FPSCR, PPC32 p465) |
| 6561 | UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 6562 | UChar b21to22 = toUChar( IFIELD( theInstr, 21, 2 ) ); |
| 6563 | UChar crfS = toUChar( IFIELD( theInstr, 18, 3 ) ); |
| 6564 | UChar b11to17 = toUChar( IFIELD( theInstr, 11, 7 ) ); |
| 6565 | IRTemp tmp = newTemp(Ity_I32); |
| 6566 | IRExpr* fpscr_all; |
| 6567 | if (b21to22 != 0 || b11to17 != 0 || flag_rC != 0) { |
| 6568 | vex_printf("dis_fp_scr(ppc)(instr,mcrfs)\n"); |
| 6569 | return False; |
| 6570 | } |
| 6571 | DIP("mcrfs crf%d,crf%d\n", crfD, crfS); |
| 6572 | vassert(crfD < 8); |
| 6573 | vassert(crfS < 8); |
| 6574 | fpscr_all = getGST_masked( PPC_GST_FPSCR, MASK_FPSCR_RN ); |
| 6575 | assign( tmp, binop(Iop_And32, |
| 6576 | binop(Iop_Shr32,fpscr_all,mkU8(4 * (7-crfS))), |
| 6577 | mkU32(0xF)) ); |
| 6578 | putGST_field( PPC_GST_CR, mkexpr(tmp), crfD ); |
| 6579 | break; |
| 6580 | } |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6581 | |
| 6582 | case 0x046: { // mtfsb0 (Move to FPSCR Bit 0, PPC32 p478) |
| 6583 | // Bit crbD of the FPSCR is cleared. |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6584 | UChar crbD = ifieldRegDS(theInstr); |
| 6585 | UInt b11to20 = IFIELD(theInstr, 11, 10); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6586 | |
| 6587 | if (b11to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6588 | vex_printf("dis_fp_scr(ppc)(instr,mtfsb0)\n"); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6589 | return False; |
| 6590 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6591 | DIP("mtfsb0%s crb%d\n", flag_rC ? ".":"", crbD); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6592 | putGST_masked( PPC_GST_FPSCR, mkU32(0), 1<<(31-crbD) ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6593 | break; |
| 6594 | } |
| 6595 | |
| 6596 | case 0x086: { // mtfsfi (Move to FPSCR Field Immediate, PPC32 p481) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6597 | UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 6598 | UChar b16to22 = toUChar( IFIELD( theInstr, 16, 7 ) ); |
| 6599 | UChar IMM = toUChar( IFIELD( theInstr, 12, 4 ) ); |
| 6600 | UChar b11 = toUChar( IFIELD( theInstr, 11, 1 ) ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6601 | |
| 6602 | if (b16to22 != 0 || b11 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6603 | vex_printf("dis_fp_scr(ppc)(instr,mtfsfi)\n"); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6604 | return False; |
| 6605 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6606 | DIP("mtfsfi%s crf%d,%d\n", flag_rC ? ".":"", crfD, IMM); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6607 | putGST_field( PPC_GST_FPSCR, mkU32(IMM), crfD ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6608 | break; |
| 6609 | } |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6610 | |
| 6611 | case 0x247: { // mffs (Move from FPSCR, PPC32 p468) |
sewardj | 496b88f | 2006-10-04 17:46:11 +0000 | [diff] [blame] | 6612 | UChar frD_addr = ifieldRegDS(theInstr); |
| 6613 | UInt b11to20 = IFIELD(theInstr, 11, 10); |
| 6614 | IRExpr* fpscr_all = getGST_masked( PPC_GST_FPSCR, MASK_FPSCR_RN ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6615 | |
| 6616 | if (b11to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6617 | vex_printf("dis_fp_scr(ppc)(instr,mffs)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6618 | return False; |
| 6619 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6620 | DIP("mffs%s fr%u\n", flag_rC ? ".":"", frD_addr); |
| 6621 | putFReg( frD_addr, |
| 6622 | unop( Iop_ReinterpI64asF64, |
sewardj | 496b88f | 2006-10-04 17:46:11 +0000 | [diff] [blame] | 6623 | unop( Iop_32Uto64, fpscr_all ))); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6624 | break; |
| 6625 | } |
| 6626 | |
| 6627 | case 0x2C7: { // mtfsf (Move to FPSCR Fields, PPC32 p480) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6628 | UChar b25 = toUChar( IFIELD(theInstr, 25, 1) ); |
| 6629 | UChar FM = toUChar( IFIELD(theInstr, 17, 8) ); |
| 6630 | UChar b16 = toUChar( IFIELD(theInstr, 16, 1) ); |
| 6631 | UChar frB_addr = ifieldRegB(theInstr); |
| 6632 | IRTemp frB = newTemp(Ity_F64); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6633 | IRTemp rB_32 = newTemp(Ity_I32); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6634 | Int i, mask; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6635 | |
| 6636 | if (b25 != 0 || b16 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6637 | vex_printf("dis_fp_scr(ppc)(instr,mtfsf)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6638 | return False; |
| 6639 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6640 | DIP("mtfsf%s %d,fr%u\n", flag_rC ? ".":"", FM, frB_addr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6641 | assign( frB, getFReg(frB_addr)); |
| 6642 | assign( rB_32, unop( Iop_64to32, |
| 6643 | unop( Iop_ReinterpF64asI64, mkexpr(frB) ))); |
| 6644 | // Build 32bit mask from FM: |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6645 | mask = 0; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6646 | for (i=0; i<8; i++) { |
| 6647 | if ((FM & (1<<(7-i))) == 1) { |
| 6648 | mask |= 0xF << (7-i); |
| 6649 | } |
| 6650 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6651 | putGST_masked( PPC_GST_FPSCR, mkexpr(rB_32), mask ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6652 | break; |
| 6653 | } |
| 6654 | |
| 6655 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6656 | vex_printf("dis_fp_scr(ppc)(opc2)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6657 | return False; |
| 6658 | } |
| 6659 | return True; |
| 6660 | } |
| 6661 | |
| 6662 | |
| 6663 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6664 | /*------------------------------------------------------------*/ |
| 6665 | /*--- AltiVec Instruction Translation ---*/ |
| 6666 | /*------------------------------------------------------------*/ |
| 6667 | |
| 6668 | /* |
| 6669 | Altivec Cache Control Instructions (Data Streams) |
| 6670 | */ |
| 6671 | static Bool dis_av_datastream ( UInt theInstr ) |
| 6672 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6673 | /* X-Form */ |
| 6674 | UChar opc1 = ifieldOPC(theInstr); |
| 6675 | UChar flag_T = toUChar( IFIELD( theInstr, 25, 1 ) ); |
| 6676 | UChar flag_A = flag_T; |
| 6677 | UChar b23to24 = toUChar( IFIELD( theInstr, 23, 2 ) ); |
| 6678 | UChar STRM = toUChar( IFIELD( theInstr, 21, 2 ) ); |
| 6679 | UChar rA_addr = ifieldRegA(theInstr); |
| 6680 | UChar rB_addr = ifieldRegB(theInstr); |
| 6681 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6682 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6683 | |
| 6684 | if (opc1 != 0x1F || b23to24 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6685 | vex_printf("dis_av_datastream(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6686 | return False; |
| 6687 | } |
| 6688 | |
| 6689 | switch (opc2) { |
| 6690 | case 0x156: // dst (Data Stream Touch, AV p115) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6691 | DIP("dst%s r%u,r%u,%d\n", flag_T ? "t" : "", |
| 6692 | rA_addr, rB_addr, STRM); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6693 | DIP(" => not implemented\n"); |
| 6694 | return False; |
| 6695 | |
| 6696 | case 0x176: // dstst (Data Stream Touch for Store, AV p117) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6697 | DIP("dstst%s r%u,r%u,%d\n", flag_T ? "t" : "", |
| 6698 | rA_addr, rB_addr, STRM); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6699 | DIP(" => not implemented\n"); |
| 6700 | return False; |
| 6701 | |
| 6702 | case 0x336: // dss (Data Stream Stop, AV p114) |
| 6703 | if (rA_addr != 0 || rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6704 | vex_printf("dis_av_datastream(ppc)(opc2,dst)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6705 | return False; |
| 6706 | } |
| 6707 | if (flag_A == 0) { |
| 6708 | DIP("dss %d\n", STRM); |
| 6709 | DIP(" => not implemented\n"); |
| 6710 | } else { |
| 6711 | DIP("dssall\n"); |
| 6712 | DIP(" => not implemented\n"); |
| 6713 | } |
| 6714 | return False; |
| 6715 | |
| 6716 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6717 | vex_printf("dis_av_datastream(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6718 | return False; |
| 6719 | } |
| 6720 | return True; |
| 6721 | } |
| 6722 | |
| 6723 | /* |
| 6724 | AltiVec Processor Control Instructions |
| 6725 | */ |
| 6726 | static Bool dis_av_procctl ( UInt theInstr ) |
| 6727 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6728 | /* VX-Form */ |
| 6729 | UChar opc1 = ifieldOPC(theInstr); |
| 6730 | UChar vD_addr = ifieldRegDS(theInstr); |
| 6731 | UChar vA_addr = ifieldRegA(theInstr); |
| 6732 | UChar vB_addr = ifieldRegB(theInstr); |
| 6733 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6734 | |
| 6735 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6736 | vex_printf("dis_av_procctl(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6737 | return False; |
| 6738 | } |
| 6739 | |
| 6740 | switch (opc2) { |
| 6741 | case 0x604: // mfvscr (Move from VSCR, AV p129) |
| 6742 | if (vA_addr != 0 || vB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6743 | vex_printf("dis_av_procctl(ppc)(opc2,dst)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6744 | return False; |
| 6745 | } |
| 6746 | DIP("mfvscr v%d\n", vD_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6747 | putVReg( vD_addr, unop(Iop_32UtoV128, getGST( PPC_GST_VSCR )) ); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6748 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6749 | |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6750 | case 0x644: { // mtvscr (Move to VSCR, AV p130) |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 6751 | IRTemp vB = newTemp(Ity_V128); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6752 | if (vD_addr != 0 || vA_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6753 | vex_printf("dis_av_procctl(ppc)(opc2,dst)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6754 | return False; |
| 6755 | } |
| 6756 | DIP("mtvscr v%d\n", vB_addr); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6757 | assign( vB, getVReg(vB_addr)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6758 | putGST( PPC_GST_VSCR, unop(Iop_V128to32, mkexpr(vB)) ); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6759 | break; |
| 6760 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6761 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6762 | vex_printf("dis_av_procctl(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6763 | return False; |
| 6764 | } |
| 6765 | return True; |
| 6766 | } |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6767 | |
| 6768 | /* |
| 6769 | AltiVec Load Instructions |
| 6770 | */ |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 6771 | static Bool dis_av_load ( VexMiscInfo* vmi, UInt theInstr ) |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6772 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6773 | /* X-Form */ |
| 6774 | UChar opc1 = ifieldOPC(theInstr); |
| 6775 | UChar vD_addr = ifieldRegDS(theInstr); |
| 6776 | UChar rA_addr = ifieldRegA(theInstr); |
| 6777 | UChar rB_addr = ifieldRegB(theInstr); |
| 6778 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6779 | UChar b0 = ifieldBIT0(theInstr); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6780 | |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6781 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 6782 | IRTemp EA = newTemp(ty); |
| 6783 | IRTemp EA_align16 = newTemp(ty); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6784 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6785 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6786 | vex_printf("dis_av_load(ppc)(instr)\n"); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6787 | return False; |
| 6788 | } |
| 6789 | |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6790 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 6791 | assign( EA_align16, addr_align( mkexpr(EA), 16 ) ); |
cerion | a50fde5 | 2005-07-01 21:16:10 +0000 | [diff] [blame] | 6792 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6793 | switch (opc2) { |
| 6794 | |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6795 | case 0x006: { // lvsl (Load Vector for Shift Left, AV p123) |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6796 | IRDirty* d; |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6797 | UInt vD_off = vectorGuestRegOffset(vD_addr); |
| 6798 | IRExpr** args = mkIRExprVec_3( |
| 6799 | mkU32(vD_off), |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6800 | binop(Iop_And32, mkSzNarrow32(ty, mkexpr(EA)), |
| 6801 | mkU32(0xF)), |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6802 | mkU32(0)/*left*/ ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6803 | if (!mode64) { |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 6804 | d = unsafeIRDirty_0_N ( |
| 6805 | 0/*regparms*/, |
| 6806 | "ppc32g_dirtyhelper_LVS", |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 6807 | fnptr_to_fnentry(vmi, &ppc32g_dirtyhelper_LVS), |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 6808 | args ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6809 | } else { |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 6810 | d = unsafeIRDirty_0_N ( |
| 6811 | 0/*regparms*/, |
| 6812 | "ppc64g_dirtyhelper_LVS", |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 6813 | fnptr_to_fnentry(vmi, &ppc64g_dirtyhelper_LVS), |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 6814 | args ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6815 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6816 | DIP("lvsl v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6817 | /* declare guest state effects */ |
| 6818 | d->needsBBP = True; |
| 6819 | d->nFxState = 1; |
| 6820 | d->fxState[0].fx = Ifx_Write; |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6821 | d->fxState[0].offset = vD_off; |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6822 | d->fxState[0].size = sizeof(U128); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6823 | |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6824 | /* execute the dirty call, side-effecting guest state */ |
| 6825 | stmt( IRStmt_Dirty(d) ); |
| 6826 | break; |
| 6827 | } |
| 6828 | case 0x026: { // lvsr (Load Vector for Shift Right, AV p125) |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6829 | IRDirty* d; |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6830 | UInt vD_off = vectorGuestRegOffset(vD_addr); |
| 6831 | IRExpr** args = mkIRExprVec_3( |
| 6832 | mkU32(vD_off), |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6833 | binop(Iop_And32, mkSzNarrow32(ty, mkexpr(EA)), |
| 6834 | mkU32(0xF)), |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6835 | mkU32(1)/*right*/ ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6836 | if (!mode64) { |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 6837 | d = unsafeIRDirty_0_N ( |
| 6838 | 0/*regparms*/, |
| 6839 | "ppc32g_dirtyhelper_LVS", |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 6840 | fnptr_to_fnentry(vmi, &ppc32g_dirtyhelper_LVS), |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 6841 | args ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6842 | } else { |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 6843 | d = unsafeIRDirty_0_N ( |
| 6844 | 0/*regparms*/, |
| 6845 | "ppc64g_dirtyhelper_LVS", |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 6846 | fnptr_to_fnentry(vmi, &ppc64g_dirtyhelper_LVS), |
cerion | 4c4f5ef | 2006-01-02 14:41:50 +0000 | [diff] [blame] | 6847 | args ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6848 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6849 | DIP("lvsr v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6850 | /* declare guest state effects */ |
| 6851 | d->needsBBP = True; |
| 6852 | d->nFxState = 1; |
| 6853 | d->fxState[0].fx = Ifx_Write; |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6854 | d->fxState[0].offset = vD_off; |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6855 | d->fxState[0].size = sizeof(U128); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6856 | |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6857 | /* execute the dirty call, side-effecting guest state */ |
| 6858 | stmt( IRStmt_Dirty(d) ); |
| 6859 | break; |
| 6860 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6861 | case 0x007: // lvebx (Load Vector Element Byte Indexed, AV p119) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6862 | DIP("lvebx v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6863 | /* loads addressed byte into vector[EA[0:3] |
| 6864 | since all other destination bytes are undefined, |
| 6865 | can simply load entire vector from 16-aligned EA */ |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6866 | putVReg( vD_addr, loadBE(Ity_V128, mkexpr(EA_align16)) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6867 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6868 | |
| 6869 | case 0x027: // lvehx (Load Vector Element Half Word Indexed, AV p121) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6870 | DIP("lvehx v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6871 | /* see note for lvebx */ |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6872 | putVReg( vD_addr, loadBE(Ity_V128, mkexpr(EA_align16)) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6873 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6874 | |
| 6875 | case 0x047: // lvewx (Load Vector Element Word Indexed, AV p122) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6876 | DIP("lvewx v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6877 | /* see note for lvebx */ |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6878 | putVReg( vD_addr, loadBE(Ity_V128, mkexpr(EA_align16)) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6879 | break; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6880 | |
| 6881 | case 0x067: // lvx (Load Vector Indexed, AV p127) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6882 | DIP("lvx v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6883 | putVReg( vD_addr, loadBE(Ity_V128, mkexpr(EA_align16)) ); |
cerion | a50fde5 | 2005-07-01 21:16:10 +0000 | [diff] [blame] | 6884 | break; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6885 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6886 | case 0x167: // lvxl (Load Vector Indexed LRU, AV p128) |
| 6887 | // XXX: lvxl gives explicit control over cache block replacement |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6888 | DIP("lvxl v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6889 | DIP(" => not implemented\n"); |
| 6890 | return False; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6891 | |
| 6892 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6893 | vex_printf("dis_av_load(ppc)(opc2)\n"); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6894 | return False; |
| 6895 | } |
| 6896 | return True; |
| 6897 | } |
| 6898 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6899 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6900 | /* |
| 6901 | AltiVec Store Instructions |
| 6902 | */ |
| 6903 | static Bool dis_av_store ( UInt theInstr ) |
| 6904 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6905 | /* X-Form */ |
| 6906 | UChar opc1 = ifieldOPC(theInstr); |
| 6907 | UChar vS_addr = ifieldRegDS(theInstr); |
| 6908 | UChar rA_addr = ifieldRegA(theInstr); |
| 6909 | UChar rB_addr = ifieldRegB(theInstr); |
| 6910 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6911 | UChar b0 = ifieldBIT0(theInstr); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6912 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6913 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 6914 | IRTemp EA = newTemp(ty); |
cerion | dba87e2 | 2006-01-02 15:15:45 +0000 | [diff] [blame] | 6915 | IRTemp addr_aligned = newTemp(ty); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6916 | IRTemp vS = newTemp(Ity_V128); |
| 6917 | IRTemp eb = newTemp(Ity_I8); |
| 6918 | IRTemp idx = newTemp(Ity_I8); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6919 | |
| 6920 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6921 | vex_printf("dis_av_store(ppc)(instr)\n"); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6922 | return False; |
| 6923 | } |
| 6924 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6925 | assign( vS, getVReg(vS_addr)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6926 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6927 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6928 | switch (opc2) { |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6929 | case 0x087: { // stvebx (Store Vector Byte Indexed, AV p131) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6930 | DIP("stvebx v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6931 | assign( eb, binop(Iop_And8, mkU8(0xF), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6932 | unop(Iop_32to8, |
| 6933 | mkSzNarrow32(ty, mkexpr(EA)) )) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6934 | assign( idx, binop(Iop_Shl8, |
| 6935 | binop(Iop_Sub8, mkU8(15), mkexpr(eb)), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6936 | mkU8(3)) ); |
| 6937 | storeBE( mkexpr(EA), |
| 6938 | unop(Iop_32to8, unop(Iop_V128to32, |
| 6939 | binop(Iop_ShrV128, mkexpr(vS), mkexpr(idx)))) ); |
| 6940 | break; |
| 6941 | } |
| 6942 | case 0x0A7: { // stvehx (Store Vector Half Word Indexed, AV p132) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6943 | DIP("stvehx v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
cerion | dba87e2 | 2006-01-02 15:15:45 +0000 | [diff] [blame] | 6944 | assign( addr_aligned, addr_align(mkexpr(EA), 2) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6945 | assign( eb, binop(Iop_And8, mkU8(0xF), |
cerion | dba87e2 | 2006-01-02 15:15:45 +0000 | [diff] [blame] | 6946 | mkSzNarrow8(ty, mkexpr(addr_aligned) )) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6947 | assign( idx, binop(Iop_Shl8, |
| 6948 | binop(Iop_Sub8, mkU8(14), mkexpr(eb)), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6949 | mkU8(3)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6950 | storeBE( mkexpr(addr_aligned), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6951 | unop(Iop_32to16, unop(Iop_V128to32, |
| 6952 | binop(Iop_ShrV128, mkexpr(vS), mkexpr(idx)))) ); |
| 6953 | break; |
| 6954 | } |
| 6955 | case 0x0C7: { // stvewx (Store Vector Word Indexed, AV p133) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6956 | DIP("stvewx v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
cerion | dba87e2 | 2006-01-02 15:15:45 +0000 | [diff] [blame] | 6957 | assign( addr_aligned, addr_align(mkexpr(EA), 4) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6958 | assign( eb, binop(Iop_And8, mkU8(0xF), |
cerion | dba87e2 | 2006-01-02 15:15:45 +0000 | [diff] [blame] | 6959 | mkSzNarrow8(ty, mkexpr(addr_aligned) )) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6960 | assign( idx, binop(Iop_Shl8, |
| 6961 | binop(Iop_Sub8, mkU8(12), mkexpr(eb)), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6962 | mkU8(3)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6963 | storeBE( mkexpr(addr_aligned), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6964 | unop(Iop_V128to32, |
| 6965 | binop(Iop_ShrV128, mkexpr(vS), mkexpr(idx))) ); |
| 6966 | break; |
| 6967 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6968 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6969 | case 0x0E7: // stvx (Store Vector Indexed, AV p134) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6970 | DIP("stvx v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
| 6971 | storeBE( addr_align( mkexpr(EA), 16 ), mkexpr(vS) ); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6972 | break; |
| 6973 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6974 | case 0x1E7: // stvxl (Store Vector Indexed LRU, AV p135) |
| 6975 | // XXX: stvxl can give explicit control over cache block replacement |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6976 | DIP("stvxl v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6977 | DIP(" => not implemented\n"); |
| 6978 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6979 | // STORE(vS, 16, addr_align( mkexpr(EA), 16 )); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6980 | // break; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6981 | |
| 6982 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6983 | vex_printf("dis_av_store(ppc)(opc2)\n"); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6984 | return False; |
| 6985 | } |
| 6986 | return True; |
| 6987 | } |
| 6988 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6989 | /* |
| 6990 | AltiVec Arithmetic Instructions |
| 6991 | */ |
| 6992 | static Bool dis_av_arith ( UInt theInstr ) |
| 6993 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6994 | /* VX-Form */ |
| 6995 | UChar opc1 = ifieldOPC(theInstr); |
| 6996 | UChar vD_addr = ifieldRegDS(theInstr); |
| 6997 | UChar vA_addr = ifieldRegA(theInstr); |
| 6998 | UChar vB_addr = ifieldRegB(theInstr); |
| 6999 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7000 | |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 7001 | IRTemp vA = newTemp(Ity_V128); |
| 7002 | IRTemp vB = newTemp(Ity_V128); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7003 | IRTemp z3 = newTemp(Ity_I64); |
| 7004 | IRTemp z2 = newTemp(Ity_I64); |
| 7005 | IRTemp z1 = newTemp(Ity_I64); |
| 7006 | IRTemp z0 = newTemp(Ity_I64); |
| 7007 | IRTemp aEvn, aOdd; |
| 7008 | IRTemp a15, a14, a13, a12, a11, a10, a9, a8; |
| 7009 | IRTemp a7, a6, a5, a4, a3, a2, a1, a0; |
| 7010 | IRTemp b3, b2, b1, b0; |
| 7011 | |
| 7012 | aEvn = aOdd = IRTemp_INVALID; |
| 7013 | a15 = a14 = a13 = a12 = a11 = a10 = a9 = a8 = IRTemp_INVALID; |
| 7014 | a7 = a6 = a5 = a4 = a3 = a2 = a1 = a0 = IRTemp_INVALID; |
| 7015 | b3 = b2 = b1 = b0 = IRTemp_INVALID; |
| 7016 | |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 7017 | assign( vA, getVReg(vA_addr)); |
| 7018 | assign( vB, getVReg(vB_addr)); |
| 7019 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7020 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7021 | vex_printf("dis_av_arith(ppc)(opc1 != 0x4)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7022 | return False; |
| 7023 | } |
| 7024 | |
| 7025 | switch (opc2) { |
| 7026 | /* Add */ |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 7027 | case 0x180: { // vaddcuw (Add Carryout Unsigned Word, AV p136) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7028 | DIP("vaddcuw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7029 | /* unsigned_ov(x+y) = (y >u not(x)) */ |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 7030 | putVReg( vD_addr, binop(Iop_ShrN32x4, |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7031 | binop(Iop_CmpGT32Ux4, mkexpr(vB), |
| 7032 | unop(Iop_NotV128, mkexpr(vA))), |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 7033 | mkU8(31)) ); |
| 7034 | break; |
| 7035 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7036 | case 0x000: // vaddubm (Add Unsigned Byte Modulo, AV p141) |
| 7037 | DIP("vaddubm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7038 | putVReg( vD_addr, binop(Iop_Add8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7039 | break; |
| 7040 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7041 | case 0x040: // vadduhm (Add Unsigned Half Word Modulo, AV p143) |
| 7042 | DIP("vadduhm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7043 | putVReg( vD_addr, binop(Iop_Add16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7044 | break; |
| 7045 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7046 | case 0x080: // vadduwm (Add Unsigned Word Modulo, AV p145) |
| 7047 | DIP("vadduwm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7048 | putVReg( vD_addr, binop(Iop_Add32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7049 | break; |
| 7050 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7051 | case 0x200: // vaddubs (Add Unsigned Byte Saturate, AV p142) |
| 7052 | DIP("vaddubs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7053 | putVReg( vD_addr, binop(Iop_QAdd8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 7054 | // TODO: set VSCR[SAT], perhaps via new primop: Iop_SatOfQAdd8Ux16 |
| 7055 | break; |
| 7056 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7057 | case 0x240: // vadduhs (Add Unsigned Half Word Saturate, AV p144) |
| 7058 | DIP("vadduhs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7059 | putVReg( vD_addr, binop(Iop_QAdd16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 7060 | // TODO: set VSCR[SAT] |
| 7061 | break; |
| 7062 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7063 | case 0x280: // vadduws (Add Unsigned Word Saturate, AV p146) |
| 7064 | DIP("vadduws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7065 | putVReg( vD_addr, binop(Iop_QAdd32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 7066 | // TODO: set VSCR[SAT] |
| 7067 | break; |
| 7068 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7069 | case 0x300: // vaddsbs (Add Signed Byte Saturate, AV p138) |
| 7070 | DIP("vaddsbs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7071 | putVReg( vD_addr, binop(Iop_QAdd8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 7072 | // TODO: set VSCR[SAT] |
| 7073 | break; |
| 7074 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7075 | case 0x340: // vaddshs (Add Signed Half Word Saturate, AV p139) |
| 7076 | DIP("vaddshs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7077 | putVReg( vD_addr, binop(Iop_QAdd16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 7078 | // TODO: set VSCR[SAT] |
| 7079 | break; |
| 7080 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7081 | case 0x380: // vaddsws (Add Signed Word Saturate, AV p140) |
| 7082 | DIP("vaddsws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7083 | putVReg( vD_addr, binop(Iop_QAdd32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 7084 | // TODO: set VSCR[SAT] |
| 7085 | break; |
| 7086 | |
| 7087 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7088 | /* Subtract */ |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7089 | case 0x580: { // vsubcuw (Subtract Carryout Unsigned Word, AV p260) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7090 | DIP("vsubcuw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7091 | /* unsigned_ov(x-y) = (y >u x) */ |
| 7092 | putVReg( vD_addr, binop(Iop_ShrN32x4, |
| 7093 | unop(Iop_NotV128, |
| 7094 | binop(Iop_CmpGT32Ux4, mkexpr(vB), |
| 7095 | mkexpr(vA))), |
| 7096 | mkU8(31)) ); |
| 7097 | break; |
| 7098 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7099 | case 0x400: // vsububm (Subtract Unsigned Byte Modulo, AV p265) |
| 7100 | DIP("vsububm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7101 | putVReg( vD_addr, binop(Iop_Sub8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7102 | break; |
| 7103 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7104 | case 0x440: // vsubuhm (Subtract Unsigned Half Word Modulo, AV p267) |
| 7105 | DIP("vsubuhm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7106 | putVReg( vD_addr, binop(Iop_Sub16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7107 | break; |
| 7108 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7109 | case 0x480: // vsubuwm (Subtract Unsigned Word Modulo, AV p269) |
| 7110 | DIP("vsubuwm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7111 | putVReg( vD_addr, binop(Iop_Sub32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7112 | break; |
| 7113 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7114 | case 0x600: // vsububs (Subtract Unsigned Byte Saturate, AV p266) |
| 7115 | DIP("vsububs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7116 | putVReg( vD_addr, binop(Iop_QSub8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 7117 | // TODO: set VSCR[SAT] |
| 7118 | break; |
| 7119 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7120 | case 0x640: // vsubuhs (Subtract Unsigned HWord Saturate, AV p268) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7121 | DIP("vsubuhs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7122 | putVReg( vD_addr, binop(Iop_QSub16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 7123 | // TODO: set VSCR[SAT] |
| 7124 | break; |
| 7125 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7126 | case 0x680: // vsubuws (Subtract Unsigned Word Saturate, AV p270) |
| 7127 | DIP("vsubuws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7128 | putVReg( vD_addr, binop(Iop_QSub32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 7129 | // TODO: set VSCR[SAT] |
| 7130 | break; |
| 7131 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7132 | case 0x700: // vsubsbs (Subtract Signed Byte Saturate, AV p262) |
| 7133 | DIP("vsubsbs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7134 | putVReg( vD_addr, binop(Iop_QSub8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 7135 | // TODO: set VSCR[SAT] |
| 7136 | break; |
| 7137 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7138 | case 0x740: // vsubshs (Subtract Signed Half Word Saturate, AV p263) |
| 7139 | DIP("vsubshs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7140 | putVReg( vD_addr, binop(Iop_QSub16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 7141 | // TODO: set VSCR[SAT] |
| 7142 | break; |
| 7143 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7144 | case 0x780: // vsubsws (Subtract Signed Word Saturate, AV p264) |
| 7145 | DIP("vsubsws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7146 | putVReg( vD_addr, binop(Iop_QSub32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 7147 | // TODO: set VSCR[SAT] |
| 7148 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7149 | |
| 7150 | |
| 7151 | /* Maximum */ |
| 7152 | case 0x002: // vmaxub (Maximum Unsigned Byte, AV p182) |
| 7153 | DIP("vmaxub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7154 | putVReg( vD_addr, binop(Iop_Max8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 7155 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7156 | |
| 7157 | case 0x042: // vmaxuh (Maximum Unsigned Half Word, AV p183) |
| 7158 | DIP("vmaxuh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7159 | putVReg( vD_addr, binop(Iop_Max16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 7160 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7161 | |
| 7162 | case 0x082: // vmaxuw (Maximum Unsigned Word, AV p184) |
| 7163 | DIP("vmaxuw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7164 | putVReg( vD_addr, binop(Iop_Max32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 7165 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7166 | |
| 7167 | case 0x102: // vmaxsb (Maximum Signed Byte, AV p179) |
| 7168 | DIP("vmaxsb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7169 | putVReg( vD_addr, binop(Iop_Max8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 7170 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7171 | |
| 7172 | case 0x142: // vmaxsh (Maximum Signed Half Word, AV p180) |
| 7173 | DIP("vmaxsh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7174 | putVReg( vD_addr, binop(Iop_Max16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 7175 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7176 | |
| 7177 | case 0x182: // vmaxsw (Maximum Signed Word, AV p181) |
| 7178 | DIP("vmaxsw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7179 | putVReg( vD_addr, binop(Iop_Max32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 7180 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7181 | |
| 7182 | |
| 7183 | /* Minimum */ |
| 7184 | case 0x202: // vminub (Minimum Unsigned Byte, AV p191) |
| 7185 | DIP("vminub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7186 | putVReg( vD_addr, binop(Iop_Min8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 7187 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7188 | |
| 7189 | case 0x242: // vminuh (Minimum Unsigned Half Word, AV p192) |
| 7190 | DIP("vminuh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7191 | putVReg( vD_addr, binop(Iop_Min16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 7192 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7193 | |
| 7194 | case 0x282: // vminuw (Minimum Unsigned Word, AV p193) |
| 7195 | DIP("vminuw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7196 | putVReg( vD_addr, binop(Iop_Min32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 7197 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7198 | |
| 7199 | case 0x302: // vminsb (Minimum Signed Byte, AV p188) |
| 7200 | DIP("vminsb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7201 | putVReg( vD_addr, binop(Iop_Min8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 7202 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7203 | |
| 7204 | case 0x342: // vminsh (Minimum Signed Half Word, AV p189) |
| 7205 | DIP("vminsh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7206 | putVReg( vD_addr, binop(Iop_Min16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 7207 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7208 | |
| 7209 | case 0x382: // vminsw (Minimum Signed Word, AV p190) |
| 7210 | DIP("vminsw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7211 | putVReg( vD_addr, binop(Iop_Min32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 7212 | break; |
| 7213 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7214 | |
| 7215 | /* Average */ |
| 7216 | case 0x402: // vavgub (Average Unsigned Byte, AV p152) |
| 7217 | DIP("vavgub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7218 | putVReg( vD_addr, binop(Iop_Avg8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 7219 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7220 | |
| 7221 | case 0x442: // vavguh (Average Unsigned Half Word, AV p153) |
| 7222 | DIP("vavguh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7223 | putVReg( vD_addr, binop(Iop_Avg16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 7224 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7225 | |
| 7226 | case 0x482: // vavguw (Average Unsigned Word, AV p154) |
| 7227 | DIP("vavguw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7228 | putVReg( vD_addr, binop(Iop_Avg32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 7229 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7230 | |
| 7231 | case 0x502: // vavgsb (Average Signed Byte, AV p149) |
| 7232 | DIP("vavgsb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7233 | putVReg( vD_addr, binop(Iop_Avg8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 7234 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7235 | |
| 7236 | case 0x542: // vavgsh (Average Signed Half Word, AV p150) |
| 7237 | DIP("vavgsh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7238 | putVReg( vD_addr, binop(Iop_Avg16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 7239 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7240 | |
| 7241 | case 0x582: // vavgsw (Average Signed Word, AV p151) |
| 7242 | DIP("vavgsw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7243 | putVReg( vD_addr, binop(Iop_Avg32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 7244 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7245 | |
| 7246 | |
| 7247 | /* Multiply */ |
| 7248 | case 0x008: // vmuloub (Multiply Odd Unsigned Byte, AV p213) |
| 7249 | DIP("vmuloub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7250 | putVReg( vD_addr, |
| 7251 | binop(Iop_MullEven8Ux16, mkexpr(vA), mkexpr(vB))); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7252 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7253 | |
| 7254 | case 0x048: // vmulouh (Multiply Odd Unsigned Half Word, AV p214) |
| 7255 | DIP("vmulouh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7256 | putVReg( vD_addr, |
| 7257 | binop(Iop_MullEven16Ux8, mkexpr(vA), mkexpr(vB))); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7258 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7259 | |
| 7260 | case 0x108: // vmulosb (Multiply Odd Signed Byte, AV p211) |
| 7261 | DIP("vmulosb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7262 | putVReg( vD_addr, |
| 7263 | binop(Iop_MullEven8Sx16, mkexpr(vA), mkexpr(vB))); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7264 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7265 | |
| 7266 | case 0x148: // vmulosh (Multiply Odd Signed Half Word, AV p212) |
| 7267 | DIP("vmulosh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7268 | putVReg( vD_addr, |
| 7269 | binop(Iop_MullEven16Sx8, mkexpr(vA), mkexpr(vB))); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7270 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7271 | |
| 7272 | case 0x208: // vmuleub (Multiply Even Unsigned Byte, AV p209) |
| 7273 | DIP("vmuleub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7274 | putVReg( vD_addr, MK_Iop_MullOdd8Ux16( mkexpr(vA), mkexpr(vB) )); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7275 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7276 | |
| 7277 | case 0x248: // vmuleuh (Multiply Even Unsigned Half Word, AV p210) |
| 7278 | DIP("vmuleuh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7279 | putVReg( vD_addr, MK_Iop_MullOdd16Ux8( mkexpr(vA), mkexpr(vB) )); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7280 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7281 | |
| 7282 | case 0x308: // vmulesb (Multiply Even Signed Byte, AV p207) |
| 7283 | DIP("vmulesb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7284 | putVReg( vD_addr, MK_Iop_MullOdd8Sx16( mkexpr(vA), mkexpr(vB) )); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7285 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7286 | |
| 7287 | case 0x348: // vmulesh (Multiply Even Signed Half Word, AV p208) |
| 7288 | DIP("vmulesh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7289 | putVReg( vD_addr, MK_Iop_MullOdd16Sx8( mkexpr(vA), mkexpr(vB) )); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 7290 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7291 | |
| 7292 | |
| 7293 | /* Sum Across Partial */ |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7294 | case 0x608: { // vsum4ubs (Sum Partial (1/4) UB Saturate, AV p275) |
| 7295 | IRTemp aEE, aEO, aOE, aOO; |
| 7296 | aEE = aEO = aOE = aOO = IRTemp_INVALID; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7297 | DIP("vsum4ubs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7298 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7299 | /* vA: V128_8Ux16 -> 4 x V128_32Ux4, sign-extended */ |
| 7300 | expand8Ux16( mkexpr(vA), &aEvn, &aOdd ); // (15,13...),(14,12...) |
| 7301 | expand16Ux8( mkexpr(aEvn), &aEE, &aEO ); // (15,11...),(13, 9...) |
| 7302 | expand16Ux8( mkexpr(aOdd), &aOE, &aOO ); // (14,10...),(12, 8...) |
| 7303 | |
| 7304 | /* break V128 to 4xI32's, zero-extending to I64's */ |
| 7305 | breakV128to4x64U( mkexpr(aEE), &a15, &a11, &a7, &a3 ); |
| 7306 | breakV128to4x64U( mkexpr(aOE), &a14, &a10, &a6, &a2 ); |
| 7307 | breakV128to4x64U( mkexpr(aEO), &a13, &a9, &a5, &a1 ); |
| 7308 | breakV128to4x64U( mkexpr(aOO), &a12, &a8, &a4, &a0 ); |
| 7309 | breakV128to4x64U( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 7310 | |
| 7311 | /* add lanes */ |
| 7312 | assign( z3, binop(Iop_Add64, mkexpr(b3), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7313 | binop(Iop_Add64, |
| 7314 | binop(Iop_Add64, mkexpr(a15), mkexpr(a14)), |
| 7315 | binop(Iop_Add64, mkexpr(a13), mkexpr(a12)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7316 | assign( z2, binop(Iop_Add64, mkexpr(b2), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7317 | binop(Iop_Add64, |
| 7318 | binop(Iop_Add64, mkexpr(a11), mkexpr(a10)), |
| 7319 | binop(Iop_Add64, mkexpr(a9), mkexpr(a8)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7320 | assign( z1, binop(Iop_Add64, mkexpr(b1), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7321 | binop(Iop_Add64, |
| 7322 | binop(Iop_Add64, mkexpr(a7), mkexpr(a6)), |
| 7323 | binop(Iop_Add64, mkexpr(a5), mkexpr(a4)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7324 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7325 | binop(Iop_Add64, |
| 7326 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2)), |
| 7327 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7328 | |
| 7329 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 7330 | putVReg( vD_addr, mkV128from4x64U( mkexpr(z3), mkexpr(z2), |
| 7331 | mkexpr(z1), mkexpr(z0)) ); |
| 7332 | break; |
| 7333 | } |
| 7334 | case 0x708: { // vsum4sbs (Sum Partial (1/4) SB Saturate, AV p273) |
| 7335 | IRTemp aEE, aEO, aOE, aOO; |
| 7336 | aEE = aEO = aOE = aOO = IRTemp_INVALID; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7337 | DIP("vsum4sbs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7338 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7339 | /* vA: V128_8Sx16 -> 4 x V128_32Sx4, sign-extended */ |
| 7340 | expand8Sx16( mkexpr(vA), &aEvn, &aOdd ); // (15,13...),(14,12...) |
| 7341 | expand16Sx8( mkexpr(aEvn), &aEE, &aEO ); // (15,11...),(13, 9...) |
| 7342 | expand16Sx8( mkexpr(aOdd), &aOE, &aOO ); // (14,10...),(12, 8...) |
| 7343 | |
| 7344 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 7345 | breakV128to4x64S( mkexpr(aEE), &a15, &a11, &a7, &a3 ); |
| 7346 | breakV128to4x64S( mkexpr(aOE), &a14, &a10, &a6, &a2 ); |
| 7347 | breakV128to4x64S( mkexpr(aEO), &a13, &a9, &a5, &a1 ); |
| 7348 | breakV128to4x64S( mkexpr(aOO), &a12, &a8, &a4, &a0 ); |
| 7349 | breakV128to4x64S( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 7350 | |
| 7351 | /* add lanes */ |
| 7352 | assign( z3, binop(Iop_Add64, mkexpr(b3), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7353 | binop(Iop_Add64, |
| 7354 | binop(Iop_Add64, mkexpr(a15), mkexpr(a14)), |
| 7355 | binop(Iop_Add64, mkexpr(a13), mkexpr(a12)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7356 | assign( z2, binop(Iop_Add64, mkexpr(b2), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7357 | binop(Iop_Add64, |
| 7358 | binop(Iop_Add64, mkexpr(a11), mkexpr(a10)), |
| 7359 | binop(Iop_Add64, mkexpr(a9), mkexpr(a8)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7360 | assign( z1, binop(Iop_Add64, mkexpr(b1), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7361 | binop(Iop_Add64, |
| 7362 | binop(Iop_Add64, mkexpr(a7), mkexpr(a6)), |
| 7363 | binop(Iop_Add64, mkexpr(a5), mkexpr(a4)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7364 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7365 | binop(Iop_Add64, |
| 7366 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2)), |
| 7367 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7368 | |
| 7369 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 7370 | putVReg( vD_addr, mkV128from4x64S( mkexpr(z3), mkexpr(z2), |
| 7371 | mkexpr(z1), mkexpr(z0)) ); |
| 7372 | break; |
| 7373 | } |
| 7374 | case 0x648: { // vsum4shs (Sum Partial (1/4) SHW Saturate, AV p274) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7375 | DIP("vsum4shs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7376 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7377 | /* vA: V128_16Sx8 -> 2 x V128_32Sx4, sign-extended */ |
| 7378 | expand16Sx8( mkexpr(vA), &aEvn, &aOdd ); // (7,5...),(6,4...) |
| 7379 | |
| 7380 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 7381 | breakV128to4x64S( mkexpr(aEvn), &a7, &a5, &a3, &a1 ); |
| 7382 | breakV128to4x64S( mkexpr(aOdd), &a6, &a4, &a2, &a0 ); |
| 7383 | breakV128to4x64S( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 7384 | |
| 7385 | /* add lanes */ |
| 7386 | assign( z3, binop(Iop_Add64, mkexpr(b3), |
| 7387 | binop(Iop_Add64, mkexpr(a7), mkexpr(a6)))); |
| 7388 | assign( z2, binop(Iop_Add64, mkexpr(b2), |
| 7389 | binop(Iop_Add64, mkexpr(a5), mkexpr(a4)))); |
| 7390 | assign( z1, binop(Iop_Add64, mkexpr(b1), |
| 7391 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2)))); |
| 7392 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
| 7393 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0)))); |
| 7394 | |
| 7395 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 7396 | putVReg( vD_addr, mkV128from4x64S( mkexpr(z3), mkexpr(z2), |
| 7397 | mkexpr(z1), mkexpr(z0)) ); |
| 7398 | break; |
| 7399 | } |
| 7400 | case 0x688: { // vsum2sws (Sum Partial (1/2) SW Saturate, AV p272) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7401 | DIP("vsum2sws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7402 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7403 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 7404 | breakV128to4x64S( mkexpr(vA), &a3, &a2, &a1, &a0 ); |
| 7405 | breakV128to4x64S( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 7406 | |
| 7407 | /* add lanes */ |
| 7408 | assign( z2, binop(Iop_Add64, mkexpr(b2), |
| 7409 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2))) ); |
| 7410 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
| 7411 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0))) ); |
| 7412 | |
| 7413 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 7414 | putVReg( vD_addr, mkV128from4x64S( mkU64(0), mkexpr(z2), |
| 7415 | mkU64(0), mkexpr(z0)) ); |
| 7416 | break; |
| 7417 | } |
| 7418 | case 0x788: { // vsumsws (Sum SW Saturate, AV p271) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7419 | DIP("vsumsws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7420 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7421 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 7422 | breakV128to4x64S( mkexpr(vA), &a3, &a2, &a1, &a0 ); |
| 7423 | breakV128to4x64S( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 7424 | |
| 7425 | /* add lanes */ |
| 7426 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7427 | binop(Iop_Add64, |
| 7428 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2)), |
| 7429 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7430 | |
| 7431 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 7432 | putVReg( vD_addr, mkV128from4x64S( mkU64(0), mkU64(0), |
| 7433 | mkU64(0), mkexpr(z0)) ); |
| 7434 | break; |
| 7435 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7436 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7437 | vex_printf("dis_av_arith(ppc)(opc2=0x%x)\n", opc2); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7438 | return False; |
| 7439 | } |
| 7440 | return True; |
| 7441 | } |
| 7442 | |
| 7443 | /* |
| 7444 | AltiVec Logic Instructions |
| 7445 | */ |
| 7446 | static Bool dis_av_logic ( UInt theInstr ) |
| 7447 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7448 | /* VX-Form */ |
| 7449 | UChar opc1 = ifieldOPC(theInstr); |
| 7450 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7451 | UChar vA_addr = ifieldRegA(theInstr); |
| 7452 | UChar vB_addr = ifieldRegB(theInstr); |
| 7453 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7454 | |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 7455 | IRTemp vA = newTemp(Ity_V128); |
| 7456 | IRTemp vB = newTemp(Ity_V128); |
| 7457 | assign( vA, getVReg(vA_addr)); |
| 7458 | assign( vB, getVReg(vB_addr)); |
| 7459 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7460 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7461 | vex_printf("dis_av_logic(ppc)(opc1 != 0x4)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7462 | return False; |
| 7463 | } |
| 7464 | |
| 7465 | switch (opc2) { |
| 7466 | case 0x404: // vand (And, AV p147) |
| 7467 | DIP("vand v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 7468 | putVReg( vD_addr, binop(Iop_AndV128, mkexpr(vA), mkexpr(vB)) ); |
| 7469 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7470 | |
| 7471 | case 0x444: // vandc (And, AV p148) |
| 7472 | DIP("vandc v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 7473 | putVReg( vD_addr, binop(Iop_AndV128, mkexpr(vA), |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7474 | unop(Iop_NotV128, mkexpr(vB))) ); |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 7475 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7476 | |
| 7477 | case 0x484: // vor (Or, AV p217) |
| 7478 | DIP("vor v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 7479 | putVReg( vD_addr, binop(Iop_OrV128, mkexpr(vA), mkexpr(vB)) ); |
| 7480 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7481 | |
| 7482 | case 0x4C4: // vxor (Xor, AV p282) |
| 7483 | DIP("vxor v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 7484 | putVReg( vD_addr, binop(Iop_XorV128, mkexpr(vA), mkexpr(vB)) ); |
| 7485 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7486 | |
| 7487 | case 0x504: // vnor (Nor, AV p216) |
| 7488 | DIP("vnor v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 7489 | putVReg( vD_addr, |
| 7490 | unop(Iop_NotV128, binop(Iop_OrV128, mkexpr(vA), mkexpr(vB))) ); |
| 7491 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7492 | |
| 7493 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7494 | vex_printf("dis_av_logic(ppc)(opc2=0x%x)\n", opc2); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7495 | return False; |
| 7496 | } |
| 7497 | return True; |
| 7498 | } |
| 7499 | |
| 7500 | /* |
| 7501 | AltiVec Compare Instructions |
| 7502 | */ |
| 7503 | static Bool dis_av_cmp ( UInt theInstr ) |
| 7504 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7505 | /* VXR-Form */ |
| 7506 | UChar opc1 = ifieldOPC(theInstr); |
| 7507 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7508 | UChar vA_addr = ifieldRegA(theInstr); |
| 7509 | UChar vB_addr = ifieldRegB(theInstr); |
| 7510 | UChar flag_rC = ifieldBIT10(theInstr); |
| 7511 | UInt opc2 = IFIELD( theInstr, 0, 10 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7512 | |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7513 | IRTemp vA = newTemp(Ity_V128); |
| 7514 | IRTemp vB = newTemp(Ity_V128); |
| 7515 | IRTemp vD = newTemp(Ity_V128); |
| 7516 | assign( vA, getVReg(vA_addr)); |
| 7517 | assign( vB, getVReg(vB_addr)); |
| 7518 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7519 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7520 | vex_printf("dis_av_cmp(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7521 | return False; |
| 7522 | } |
| 7523 | |
| 7524 | switch (opc2) { |
| 7525 | case 0x006: // vcmpequb (Compare Equal-to Unsigned B, AV p160) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7526 | DIP("vcmpequb%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7527 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7528 | assign( vD, binop(Iop_CmpEQ8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7529 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7530 | |
| 7531 | case 0x046: // vcmpequh (Compare Equal-to Unsigned HW, AV p161) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7532 | DIP("vcmpequh%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7533 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7534 | assign( vD, binop(Iop_CmpEQ16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7535 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7536 | |
| 7537 | case 0x086: // vcmpequw (Compare Equal-to Unsigned W, AV p162) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7538 | DIP("vcmpequw%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7539 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7540 | assign( vD, binop(Iop_CmpEQ32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7541 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7542 | |
| 7543 | case 0x206: // vcmpgtub (Compare Greater-than Unsigned B, AV p168) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7544 | DIP("vcmpgtub%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7545 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7546 | assign( vD, binop(Iop_CmpGT8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 7547 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7548 | |
| 7549 | case 0x246: // vcmpgtuh (Compare Greater-than Unsigned HW, AV p169) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7550 | DIP("vcmpgtuh%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7551 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7552 | assign( vD, binop(Iop_CmpGT16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 7553 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7554 | |
| 7555 | case 0x286: // vcmpgtuw (Compare Greater-than Unsigned W, AV p170) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7556 | DIP("vcmpgtuw%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7557 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7558 | assign( vD, binop(Iop_CmpGT32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 7559 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7560 | |
| 7561 | case 0x306: // vcmpgtsb (Compare Greater-than Signed B, AV p165) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7562 | DIP("vcmpgtsb%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7563 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7564 | assign( vD, binop(Iop_CmpGT8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 7565 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7566 | |
| 7567 | case 0x346: // vcmpgtsh (Compare Greater-than Signed HW, AV p166) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7568 | DIP("vcmpgtsh%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7569 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7570 | assign( vD, binop(Iop_CmpGT16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 7571 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7572 | |
| 7573 | case 0x386: // vcmpgtsw (Compare Greater-than Signed W, AV p167) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7574 | DIP("vcmpgtsw%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7575 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7576 | assign( vD, binop(Iop_CmpGT32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 7577 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7578 | |
| 7579 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7580 | vex_printf("dis_av_cmp(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7581 | return False; |
| 7582 | } |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7583 | |
| 7584 | putVReg( vD_addr, mkexpr(vD) ); |
| 7585 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7586 | if (flag_rC) { |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 7587 | set_AV_CR6( mkexpr(vD), True ); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7588 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7589 | return True; |
| 7590 | } |
| 7591 | |
| 7592 | /* |
| 7593 | AltiVec Multiply-Sum Instructions |
| 7594 | */ |
| 7595 | static Bool dis_av_multarith ( UInt theInstr ) |
| 7596 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7597 | /* VA-Form */ |
| 7598 | UChar opc1 = ifieldOPC(theInstr); |
| 7599 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7600 | UChar vA_addr = ifieldRegA(theInstr); |
| 7601 | UChar vB_addr = ifieldRegB(theInstr); |
| 7602 | UChar vC_addr = ifieldRegC(theInstr); |
| 7603 | UChar opc2 = toUChar( IFIELD( theInstr, 0, 6 ) ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7604 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7605 | IRTemp vA = newTemp(Ity_V128); |
| 7606 | IRTemp vB = newTemp(Ity_V128); |
| 7607 | IRTemp vC = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7608 | IRTemp zeros = newTemp(Ity_V128); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7609 | IRTemp aLo = newTemp(Ity_V128); |
| 7610 | IRTemp bLo = newTemp(Ity_V128); |
| 7611 | IRTemp cLo = newTemp(Ity_V128); |
| 7612 | IRTemp zLo = newTemp(Ity_V128); |
| 7613 | IRTemp aHi = newTemp(Ity_V128); |
| 7614 | IRTemp bHi = newTemp(Ity_V128); |
| 7615 | IRTemp cHi = newTemp(Ity_V128); |
| 7616 | IRTemp zHi = newTemp(Ity_V128); |
| 7617 | IRTemp abEvn = newTemp(Ity_V128); |
| 7618 | IRTemp abOdd = newTemp(Ity_V128); |
| 7619 | IRTemp z3 = newTemp(Ity_I64); |
| 7620 | IRTemp z2 = newTemp(Ity_I64); |
| 7621 | IRTemp z1 = newTemp(Ity_I64); |
| 7622 | IRTemp z0 = newTemp(Ity_I64); |
| 7623 | IRTemp ab7, ab6, ab5, ab4, ab3, ab2, ab1, ab0; |
| 7624 | IRTemp c3, c2, c1, c0; |
| 7625 | |
| 7626 | ab7 = ab6 = ab5 = ab4 = ab3 = ab2 = ab1 = ab0 = IRTemp_INVALID; |
| 7627 | c3 = c2 = c1 = c0 = IRTemp_INVALID; |
| 7628 | |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7629 | assign( vA, getVReg(vA_addr)); |
| 7630 | assign( vB, getVReg(vB_addr)); |
| 7631 | assign( vC, getVReg(vC_addr)); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7632 | assign( zeros, unop(Iop_Dup32x4, mkU32(0)) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7633 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7634 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7635 | vex_printf("dis_av_multarith(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7636 | return False; |
| 7637 | } |
| 7638 | |
| 7639 | switch (opc2) { |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7640 | /* Multiply-Add */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7641 | case 0x20: { // vmhaddshs (Mult Hi, Add Signed HW Saturate, AV p185) |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7642 | IRTemp cSigns = newTemp(Ity_V128); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7643 | DIP("vmhaddshs v%d,v%d,v%d,v%d\n", |
| 7644 | vD_addr, vA_addr, vB_addr, vC_addr); |
| 7645 | assign(cSigns, binop(Iop_CmpGT16Sx8, mkexpr(zeros), mkexpr(vC))); |
| 7646 | assign(aLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vA))); |
| 7647 | assign(bLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vB))); |
| 7648 | assign(cLo, binop(Iop_InterleaveLO16x8, mkexpr(cSigns),mkexpr(vC))); |
| 7649 | assign(aHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vA))); |
| 7650 | assign(bHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vB))); |
| 7651 | assign(cHi, binop(Iop_InterleaveHI16x8, mkexpr(cSigns),mkexpr(vC))); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7652 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7653 | assign( zLo, binop(Iop_Add32x4, mkexpr(cLo), |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7654 | binop(Iop_SarN32x4, |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 7655 | binop(Iop_MullEven16Sx8, |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7656 | mkexpr(aLo), mkexpr(bLo)), |
| 7657 | mkU8(15))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7658 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7659 | assign( zHi, binop(Iop_Add32x4, mkexpr(cHi), |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7660 | binop(Iop_SarN32x4, |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 7661 | binop(Iop_MullEven16Sx8, |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7662 | mkexpr(aHi), mkexpr(bHi)), |
| 7663 | mkU8(15))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7664 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7665 | putVReg( vD_addr, |
| 7666 | binop(Iop_QNarrow32Sx4, mkexpr(zHi), mkexpr(zLo)) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7667 | break; |
| 7668 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7669 | case 0x21: { // vmhraddshs (Mult High Round, Add Signed HW Saturate, AV p186) |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7670 | IRTemp zKonst = newTemp(Ity_V128); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7671 | IRTemp cSigns = newTemp(Ity_V128); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7672 | DIP("vmhraddshs v%d,v%d,v%d,v%d\n", |
| 7673 | vD_addr, vA_addr, vB_addr, vC_addr); |
| 7674 | assign(cSigns, binop(Iop_CmpGT16Sx8, mkexpr(zeros), mkexpr(vC)) ); |
| 7675 | assign(aLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vA))); |
| 7676 | assign(bLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vB))); |
| 7677 | assign(cLo, binop(Iop_InterleaveLO16x8, mkexpr(cSigns),mkexpr(vC))); |
| 7678 | assign(aHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vA))); |
| 7679 | assign(bHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vB))); |
| 7680 | assign(cHi, binop(Iop_InterleaveHI16x8, mkexpr(cSigns),mkexpr(vC))); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7681 | |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7682 | /* shifting our const avoids store/load version of Dup */ |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7683 | assign( zKonst, binop(Iop_ShlN32x4, unop(Iop_Dup32x4, mkU32(0x1)), |
| 7684 | mkU8(14)) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7685 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7686 | assign( zLo, binop(Iop_Add32x4, mkexpr(cLo), |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7687 | binop(Iop_SarN32x4, |
| 7688 | binop(Iop_Add32x4, mkexpr(zKonst), |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 7689 | binop(Iop_MullEven16Sx8, |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7690 | mkexpr(aLo), mkexpr(bLo))), |
| 7691 | mkU8(15))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7692 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7693 | assign( zHi, binop(Iop_Add32x4, mkexpr(cHi), |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7694 | binop(Iop_SarN32x4, |
| 7695 | binop(Iop_Add32x4, mkexpr(zKonst), |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 7696 | binop(Iop_MullEven16Sx8, |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7697 | mkexpr(aHi), mkexpr(bHi))), |
| 7698 | mkU8(15))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7699 | |
| 7700 | putVReg( vD_addr, binop(Iop_QNarrow32Sx4, mkexpr(zHi), mkexpr(zLo)) ); |
| 7701 | break; |
| 7702 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7703 | case 0x22: { // vmladduhm (Mult Low, Add Unsigned HW Modulo, AV p194) |
| 7704 | DIP("vmladduhm v%d,v%d,v%d,v%d\n", |
| 7705 | vD_addr, vA_addr, vB_addr, vC_addr); |
| 7706 | assign(aLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vA))); |
| 7707 | assign(bLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vB))); |
| 7708 | assign(cLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vC))); |
| 7709 | assign(aHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vA))); |
| 7710 | assign(bHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vB))); |
| 7711 | assign(cHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vC))); |
| 7712 | assign(zLo, binop(Iop_Add32x4, |
| 7713 | binop(Iop_MullEven16Ux8, mkexpr(aLo), mkexpr(bLo)), |
| 7714 | mkexpr(cLo)) ); |
| 7715 | assign(zHi, binop(Iop_Add32x4, |
| 7716 | binop(Iop_MullEven16Ux8, mkexpr(aHi), mkexpr(bHi)), |
| 7717 | mkexpr(cHi))); |
| 7718 | putVReg(vD_addr, binop(Iop_Narrow32x4, mkexpr(zHi), mkexpr(zLo))); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7719 | break; |
| 7720 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7721 | |
| 7722 | |
| 7723 | /* Multiply-Sum */ |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7724 | case 0x24: { // vmsumubm (Multiply Sum Unsigned B Modulo, AV p204) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7725 | IRTemp abEE, abEO, abOE, abOO; |
| 7726 | abEE = abEO = abOE = abOO = IRTemp_INVALID; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7727 | DIP("vmsumubm v%d,v%d,v%d,v%d\n", |
| 7728 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7729 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7730 | /* multiply vA,vB (unsigned, widening) */ |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7731 | assign( abEvn, MK_Iop_MullOdd8Ux16( mkexpr(vA), mkexpr(vB) )); |
| 7732 | assign( abOdd, binop(Iop_MullEven8Ux16, mkexpr(vA), mkexpr(vB)) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7733 | |
| 7734 | /* evn,odd: V128_16Ux8 -> 2 x V128_32Ux4, zero-extended */ |
| 7735 | expand16Ux8( mkexpr(abEvn), &abEE, &abEO ); |
| 7736 | expand16Ux8( mkexpr(abOdd), &abOE, &abOO ); |
| 7737 | |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7738 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7739 | binop(Iop_Add32x4, mkexpr(vC), |
| 7740 | binop(Iop_Add32x4, |
| 7741 | binop(Iop_Add32x4, mkexpr(abEE), mkexpr(abEO)), |
| 7742 | binop(Iop_Add32x4, mkexpr(abOE), mkexpr(abOO)))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7743 | break; |
| 7744 | } |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7745 | case 0x25: { // vmsummbm (Multiply Sum Mixed-Sign B Modulo, AV p201) |
| 7746 | IRTemp aEvn, aOdd, bEvn, bOdd; |
| 7747 | IRTemp abEE = newTemp(Ity_V128); |
| 7748 | IRTemp abEO = newTemp(Ity_V128); |
| 7749 | IRTemp abOE = newTemp(Ity_V128); |
| 7750 | IRTemp abOO = newTemp(Ity_V128); |
| 7751 | aEvn = aOdd = bEvn = bOdd = IRTemp_INVALID; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7752 | DIP("vmsummbm v%d,v%d,v%d,v%d\n", |
| 7753 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7754 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7755 | /* sign-extend vA, zero-extend vB, for mixed-sign multiply |
| 7756 | (separating out adjacent lanes to different vectors) */ |
| 7757 | expand8Sx16( mkexpr(vA), &aEvn, &aOdd ); |
| 7758 | expand8Ux16( mkexpr(vB), &bEvn, &bOdd ); |
| 7759 | |
| 7760 | /* multiply vA, vB, again separating adjacent lanes */ |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7761 | assign( abEE, MK_Iop_MullOdd16Sx8( mkexpr(aEvn), mkexpr(bEvn) )); |
| 7762 | assign( abEO, binop(Iop_MullEven16Sx8, mkexpr(aEvn), mkexpr(bEvn)) ); |
| 7763 | assign( abOE, MK_Iop_MullOdd16Sx8( mkexpr(aOdd), mkexpr(bOdd) )); |
| 7764 | assign( abOO, binop(Iop_MullEven16Sx8, mkexpr(aOdd), mkexpr(bOdd)) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7765 | |
| 7766 | /* add results together, + vC */ |
| 7767 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7768 | binop(Iop_QAdd32Sx4, mkexpr(vC), |
| 7769 | binop(Iop_QAdd32Sx4, |
| 7770 | binop(Iop_QAdd32Sx4, mkexpr(abEE), mkexpr(abEO)), |
| 7771 | binop(Iop_QAdd32Sx4, mkexpr(abOE), mkexpr(abOO)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7772 | break; |
| 7773 | } |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7774 | case 0x26: { // vmsumuhm (Multiply Sum Unsigned HW Modulo, AV p205) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7775 | DIP("vmsumuhm v%d,v%d,v%d,v%d\n", |
| 7776 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7777 | assign( abEvn, MK_Iop_MullOdd16Ux8( mkexpr(vA), mkexpr(vB) )); |
| 7778 | assign( abOdd, binop(Iop_MullEven16Ux8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7779 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7780 | binop(Iop_Add32x4, mkexpr(vC), |
| 7781 | binop(Iop_Add32x4, mkexpr(abEvn), mkexpr(abOdd))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7782 | break; |
| 7783 | } |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7784 | case 0x27: { // vmsumuhs (Multiply Sum Unsigned HW Saturate, AV p206) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7785 | DIP("vmsumuhs v%d,v%d,v%d,v%d\n", |
| 7786 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7787 | /* widening multiply, separating lanes */ |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7788 | assign( abEvn, MK_Iop_MullOdd16Ux8(mkexpr(vA), mkexpr(vB) )); |
| 7789 | assign( abOdd, binop(Iop_MullEven16Ux8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7790 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7791 | /* break V128 to 4xI32's, zero-extending to I64's */ |
| 7792 | breakV128to4x64U( mkexpr(abEvn), &ab7, &ab5, &ab3, &ab1 ); |
| 7793 | breakV128to4x64U( mkexpr(abOdd), &ab6, &ab4, &ab2, &ab0 ); |
| 7794 | breakV128to4x64U( mkexpr(vC), &c3, &c2, &c1, &c0 ); |
| 7795 | |
| 7796 | /* add lanes */ |
| 7797 | assign( z3, binop(Iop_Add64, mkexpr(c3), |
| 7798 | binop(Iop_Add64, mkexpr(ab7), mkexpr(ab6)))); |
| 7799 | assign( z2, binop(Iop_Add64, mkexpr(c2), |
| 7800 | binop(Iop_Add64, mkexpr(ab5), mkexpr(ab4)))); |
| 7801 | assign( z1, binop(Iop_Add64, mkexpr(c1), |
| 7802 | binop(Iop_Add64, mkexpr(ab3), mkexpr(ab2)))); |
| 7803 | assign( z0, binop(Iop_Add64, mkexpr(c0), |
| 7804 | binop(Iop_Add64, mkexpr(ab1), mkexpr(ab0)))); |
| 7805 | |
| 7806 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 7807 | putVReg( vD_addr, mkV128from4x64U( mkexpr(z3), mkexpr(z2), |
| 7808 | mkexpr(z1), mkexpr(z0)) ); |
| 7809 | |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7810 | break; |
| 7811 | } |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7812 | case 0x28: { // vmsumshm (Multiply Sum Signed HW Modulo, AV p202) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7813 | DIP("vmsumshm v%d,v%d,v%d,v%d\n", |
| 7814 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7815 | assign( abEvn, MK_Iop_MullOdd16Sx8( mkexpr(vA), mkexpr(vB) )); |
| 7816 | assign( abOdd, binop(Iop_MullEven16Sx8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7817 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7818 | binop(Iop_Add32x4, mkexpr(vC), |
| 7819 | binop(Iop_Add32x4, mkexpr(abOdd), mkexpr(abEvn))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7820 | break; |
| 7821 | } |
| 7822 | case 0x29: { // vmsumshs (Multiply Sum Signed HW Saturate, AV p203) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7823 | DIP("vmsumshs v%d,v%d,v%d,v%d\n", |
| 7824 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7825 | /* widening multiply, separating lanes */ |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7826 | assign( abEvn, MK_Iop_MullOdd16Sx8( mkexpr(vA), mkexpr(vB) )); |
| 7827 | assign( abOdd, binop(Iop_MullEven16Sx8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7828 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7829 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 7830 | breakV128to4x64S( mkexpr(abEvn), &ab7, &ab5, &ab3, &ab1 ); |
| 7831 | breakV128to4x64S( mkexpr(abOdd), &ab6, &ab4, &ab2, &ab0 ); |
| 7832 | breakV128to4x64S( mkexpr(vC), &c3, &c2, &c1, &c0 ); |
| 7833 | |
| 7834 | /* add lanes */ |
| 7835 | assign( z3, binop(Iop_Add64, mkexpr(c3), |
| 7836 | binop(Iop_Add64, mkexpr(ab7), mkexpr(ab6)))); |
| 7837 | assign( z2, binop(Iop_Add64, mkexpr(c2), |
| 7838 | binop(Iop_Add64, mkexpr(ab5), mkexpr(ab4)))); |
| 7839 | assign( z1, binop(Iop_Add64, mkexpr(c1), |
| 7840 | binop(Iop_Add64, mkexpr(ab3), mkexpr(ab2)))); |
| 7841 | assign( z0, binop(Iop_Add64, mkexpr(c0), |
| 7842 | binop(Iop_Add64, mkexpr(ab1), mkexpr(ab0)))); |
| 7843 | |
| 7844 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 7845 | putVReg( vD_addr, mkV128from4x64S( mkexpr(z3), mkexpr(z2), |
| 7846 | mkexpr(z1), mkexpr(z0)) ); |
| 7847 | break; |
| 7848 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7849 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7850 | vex_printf("dis_av_multarith(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7851 | return False; |
| 7852 | } |
| 7853 | return True; |
| 7854 | } |
| 7855 | |
| 7856 | /* |
| 7857 | AltiVec Shift/Rotate Instructions |
| 7858 | */ |
| 7859 | static Bool dis_av_shift ( UInt theInstr ) |
| 7860 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7861 | /* VX-Form */ |
| 7862 | UChar opc1 = ifieldOPC(theInstr); |
| 7863 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7864 | UChar vA_addr = ifieldRegA(theInstr); |
| 7865 | UChar vB_addr = ifieldRegB(theInstr); |
| 7866 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7867 | |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7868 | IRTemp vA = newTemp(Ity_V128); |
| 7869 | IRTemp vB = newTemp(Ity_V128); |
| 7870 | assign( vA, getVReg(vA_addr)); |
| 7871 | assign( vB, getVReg(vB_addr)); |
| 7872 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7873 | if (opc1 != 0x4){ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7874 | vex_printf("dis_av_shift(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7875 | return False; |
| 7876 | } |
| 7877 | |
| 7878 | switch (opc2) { |
| 7879 | /* Rotate */ |
| 7880 | case 0x004: // vrlb (Rotate Left Integer B, AV p234) |
| 7881 | DIP("vrlb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 7882 | putVReg( vD_addr, binop(Iop_Rol8x16, mkexpr(vA), mkexpr(vB)) ); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7883 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7884 | |
| 7885 | case 0x044: // vrlh (Rotate Left Integer HW, AV p235) |
| 7886 | DIP("vrlh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 7887 | putVReg( vD_addr, binop(Iop_Rol16x8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7888 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7889 | |
| 7890 | case 0x084: // vrlw (Rotate Left Integer W, AV p236) |
| 7891 | DIP("vrlw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 7892 | putVReg( vD_addr, binop(Iop_Rol32x4, mkexpr(vA), mkexpr(vB)) ); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7893 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7894 | |
| 7895 | |
| 7896 | /* Shift Left */ |
| 7897 | case 0x104: // vslb (Shift Left Integer B, AV p240) |
| 7898 | DIP("vslb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7899 | putVReg( vD_addr, binop(Iop_Shl8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7900 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7901 | |
| 7902 | case 0x144: // vslh (Shift Left Integer HW, AV p242) |
| 7903 | DIP("vslh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7904 | putVReg( vD_addr, binop(Iop_Shl16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7905 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7906 | |
| 7907 | case 0x184: // vslw (Shift Left Integer W, AV p244) |
| 7908 | DIP("vslw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7909 | putVReg( vD_addr, binop(Iop_Shl32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7910 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7911 | |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7912 | case 0x1C4: { // vsl (Shift Left, AV p239) |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7913 | IRTemp sh = newTemp(Ity_I8); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7914 | DIP("vsl v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7915 | assign( sh, binop(Iop_And8, mkU8(0x7), |
| 7916 | unop(Iop_32to8, |
| 7917 | unop(Iop_V128to32, mkexpr(vB)))) ); |
| 7918 | putVReg( vD_addr, |
| 7919 | binop(Iop_ShlV128, mkexpr(vA), mkexpr(sh)) ); |
| 7920 | break; |
| 7921 | } |
| 7922 | case 0x40C: { // vslo (Shift Left by Octet, AV p243) |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7923 | IRTemp sh = newTemp(Ity_I8); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7924 | DIP("vslo v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7925 | assign( sh, binop(Iop_And8, mkU8(0x78), |
| 7926 | unop(Iop_32to8, |
| 7927 | unop(Iop_V128to32, mkexpr(vB)))) ); |
| 7928 | putVReg( vD_addr, |
| 7929 | binop(Iop_ShlV128, mkexpr(vA), mkexpr(sh)) ); |
| 7930 | break; |
| 7931 | } |
| 7932 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7933 | |
| 7934 | /* Shift Right */ |
| 7935 | case 0x204: // vsrb (Shift Right B, AV p256) |
| 7936 | DIP("vsrb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7937 | putVReg( vD_addr, binop(Iop_Shr8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7938 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7939 | |
| 7940 | case 0x244: // vsrh (Shift Right HW, AV p257) |
| 7941 | DIP("vsrh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7942 | putVReg( vD_addr, binop(Iop_Shr16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7943 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7944 | |
| 7945 | case 0x284: // vsrw (Shift Right W, AV p259) |
| 7946 | DIP("vsrw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7947 | putVReg( vD_addr, binop(Iop_Shr32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7948 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7949 | |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7950 | case 0x2C4: { // vsr (Shift Right, AV p251) |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7951 | IRTemp sh = newTemp(Ity_I8); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7952 | DIP("vsr v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7953 | assign( sh, binop(Iop_And8, mkU8(0x7), |
| 7954 | unop(Iop_32to8, |
| 7955 | unop(Iop_V128to32, mkexpr(vB)))) ); |
| 7956 | putVReg( vD_addr, |
| 7957 | binop(Iop_ShrV128, mkexpr(vA), mkexpr(sh)) ); |
| 7958 | break; |
| 7959 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7960 | case 0x304: // vsrab (Shift Right Alg B, AV p253) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7961 | DIP("vsrab v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7962 | putVReg( vD_addr, binop(Iop_Sar8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7963 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7964 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7965 | case 0x344: // vsrah (Shift Right Alg HW, AV p254) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7966 | DIP("vsrah v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7967 | putVReg( vD_addr, binop(Iop_Sar16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7968 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7969 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7970 | case 0x384: // vsraw (Shift Right Alg W, AV p255) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7971 | DIP("vsraw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7972 | putVReg( vD_addr, binop(Iop_Sar32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7973 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7974 | |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7975 | case 0x44C: { // vsro (Shift Right by Octet, AV p258) |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7976 | IRTemp sh = newTemp(Ity_I8); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7977 | DIP("vsro v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7978 | assign( sh, binop(Iop_And8, mkU8(0x78), |
| 7979 | unop(Iop_32to8, |
| 7980 | unop(Iop_V128to32, mkexpr(vB)))) ); |
| 7981 | putVReg( vD_addr, |
| 7982 | binop(Iop_ShrV128, mkexpr(vA), mkexpr(sh)) ); |
| 7983 | break; |
| 7984 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7985 | |
| 7986 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7987 | vex_printf("dis_av_shift(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7988 | return False; |
| 7989 | } |
| 7990 | return True; |
| 7991 | } |
| 7992 | |
| 7993 | /* |
| 7994 | AltiVec Permute Instructions |
| 7995 | */ |
| 7996 | static Bool dis_av_permute ( UInt theInstr ) |
| 7997 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7998 | /* VA-Form, VX-Form */ |
| 7999 | UChar opc1 = ifieldOPC(theInstr); |
| 8000 | UChar vD_addr = ifieldRegDS(theInstr); |
| 8001 | UChar vA_addr = ifieldRegA(theInstr); |
| 8002 | UChar UIMM_5 = vA_addr; |
| 8003 | UChar vB_addr = ifieldRegB(theInstr); |
| 8004 | UChar vC_addr = ifieldRegC(theInstr); |
| 8005 | UChar b10 = ifieldBIT10(theInstr); |
| 8006 | UChar SHB_uimm4 = toUChar( IFIELD( theInstr, 6, 4 ) ); |
| 8007 | UInt opc2 = toUChar( IFIELD( theInstr, 0, 6 ) ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8008 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8009 | UChar SIMM_8 = extend_s_5to8(UIMM_5); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8010 | |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 8011 | IRTemp vA = newTemp(Ity_V128); |
| 8012 | IRTemp vB = newTemp(Ity_V128); |
| 8013 | IRTemp vC = newTemp(Ity_V128); |
| 8014 | assign( vA, getVReg(vA_addr)); |
| 8015 | assign( vB, getVReg(vB_addr)); |
| 8016 | assign( vC, getVReg(vC_addr)); |
| 8017 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8018 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8019 | vex_printf("dis_av_permute(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8020 | return False; |
| 8021 | } |
| 8022 | |
| 8023 | switch (opc2) { |
| 8024 | case 0x2A: // vsel (Conditional Select, AV p238) |
| 8025 | DIP("vsel v%d,v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 8026 | /* vD = (vA & ~vC) | (vB & vC) */ |
| 8027 | putVReg( vD_addr, binop(Iop_OrV128, |
| 8028 | binop(Iop_AndV128, mkexpr(vA), unop(Iop_NotV128, mkexpr(vC))), |
| 8029 | binop(Iop_AndV128, mkexpr(vB), mkexpr(vC))) ); |
| 8030 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8031 | |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8032 | case 0x2B: { // vperm (Permute, AV p218) |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8033 | /* limited to two args for IR, so have to play games... */ |
sewardj | dc1f913 | 2005-10-22 12:49:49 +0000 | [diff] [blame] | 8034 | IRTemp a_perm = newTemp(Ity_V128); |
| 8035 | IRTemp b_perm = newTemp(Ity_V128); |
| 8036 | IRTemp mask = newTemp(Ity_V128); |
| 8037 | IRTemp vC_andF = newTemp(Ity_V128); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8038 | DIP("vperm v%d,v%d,v%d,v%d\n", |
| 8039 | vD_addr, vA_addr, vB_addr, vC_addr); |
sewardj | dc1f913 | 2005-10-22 12:49:49 +0000 | [diff] [blame] | 8040 | /* Limit the Perm8x16 steering values to 0 .. 15 as that is what |
| 8041 | IR specifies, and also to hide irrelevant bits from |
| 8042 | memcheck */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8043 | assign( vC_andF, |
| 8044 | binop(Iop_AndV128, mkexpr(vC), |
| 8045 | unop(Iop_Dup8x16, mkU8(0xF))) ); |
| 8046 | assign( a_perm, |
| 8047 | binop(Iop_Perm8x16, mkexpr(vA), mkexpr(vC_andF)) ); |
| 8048 | assign( b_perm, |
| 8049 | binop(Iop_Perm8x16, mkexpr(vB), mkexpr(vC_andF)) ); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8050 | // mask[i8] = (vC[i8]_4 == 1) ? 0xFF : 0x0 |
| 8051 | assign( mask, binop(Iop_SarN8x16, |
| 8052 | binop(Iop_ShlN8x16, mkexpr(vC), mkU8(3)), |
| 8053 | mkU8(7)) ); |
| 8054 | // dst = (a & ~mask) | (b & mask) |
| 8055 | putVReg( vD_addr, binop(Iop_OrV128, |
| 8056 | binop(Iop_AndV128, mkexpr(a_perm), |
| 8057 | unop(Iop_NotV128, mkexpr(mask))), |
| 8058 | binop(Iop_AndV128, mkexpr(b_perm), |
| 8059 | mkexpr(mask))) ); |
| 8060 | return True; |
| 8061 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8062 | case 0x2C: // vsldoi (Shift Left Double by Octet Imm, AV p241) |
| 8063 | if (b10 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8064 | vex_printf("dis_av_permute(ppc)(vsldoi)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8065 | return False; |
| 8066 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8067 | DIP("vsldoi v%d,v%d,v%d,%d\n", |
| 8068 | vD_addr, vA_addr, vB_addr, SHB_uimm4); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8069 | if (SHB_uimm4 == 0) |
| 8070 | putVReg( vD_addr, mkexpr(vA) ); |
| 8071 | else |
| 8072 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8073 | binop(Iop_OrV128, |
| 8074 | binop(Iop_ShlV128, mkexpr(vA), mkU8(SHB_uimm4*8)), |
| 8075 | binop(Iop_ShrV128, mkexpr(vB), mkU8((16-SHB_uimm4)*8))) ); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8076 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8077 | |
| 8078 | default: |
| 8079 | break; // Fall through... |
| 8080 | } |
| 8081 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8082 | opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8083 | switch (opc2) { |
| 8084 | |
| 8085 | /* Merge */ |
| 8086 | case 0x00C: // vmrghb (Merge High B, AV p195) |
| 8087 | DIP("vmrghb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8088 | putVReg( vD_addr, |
| 8089 | binop(Iop_InterleaveHI8x16, mkexpr(vA), mkexpr(vB)) ); |
| 8090 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8091 | |
| 8092 | case 0x04C: // vmrghh (Merge High HW, AV p196) |
| 8093 | DIP("vmrghh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8094 | putVReg( vD_addr, |
| 8095 | binop(Iop_InterleaveHI16x8, mkexpr(vA), mkexpr(vB)) ); |
| 8096 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8097 | |
| 8098 | case 0x08C: // vmrghw (Merge High W, AV p197) |
| 8099 | DIP("vmrghw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8100 | putVReg( vD_addr, |
| 8101 | binop(Iop_InterleaveHI32x4, mkexpr(vA), mkexpr(vB)) ); |
| 8102 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8103 | |
| 8104 | case 0x10C: // vmrglb (Merge Low B, AV p198) |
| 8105 | DIP("vmrglb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8106 | putVReg( vD_addr, |
| 8107 | binop(Iop_InterleaveLO8x16, mkexpr(vA), mkexpr(vB)) ); |
| 8108 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8109 | |
| 8110 | case 0x14C: // vmrglh (Merge Low HW, AV p199) |
| 8111 | DIP("vmrglh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8112 | putVReg( vD_addr, |
| 8113 | binop(Iop_InterleaveLO16x8, mkexpr(vA), mkexpr(vB)) ); |
| 8114 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8115 | |
| 8116 | case 0x18C: // vmrglw (Merge Low W, AV p200) |
| 8117 | DIP("vmrglw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8118 | putVReg( vD_addr, |
| 8119 | binop(Iop_InterleaveLO32x4, mkexpr(vA), mkexpr(vB)) ); |
| 8120 | break; |
| 8121 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8122 | |
| 8123 | /* Splat */ |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8124 | case 0x20C: { // vspltb (Splat Byte, AV p245) |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8125 | /* vD = Dup8x16( vB[UIMM_5] ) */ |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 8126 | UChar sh_uimm = (15 - (UIMM_5 & 15)) * 8; |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8127 | DIP("vspltb v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8128 | putVReg( vD_addr, unop(Iop_Dup8x16, |
| 8129 | unop(Iop_32to8, unop(Iop_V128to32, |
| 8130 | binop(Iop_ShrV128, mkexpr(vB), mkU8(sh_uimm))))) ); |
| 8131 | break; |
| 8132 | } |
| 8133 | case 0x24C: { // vsplth (Splat Half Word, AV p246) |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 8134 | UChar sh_uimm = (7 - (UIMM_5 & 7)) * 16; |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8135 | DIP("vsplth v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8136 | putVReg( vD_addr, unop(Iop_Dup16x8, |
| 8137 | unop(Iop_32to16, unop(Iop_V128to32, |
| 8138 | binop(Iop_ShrV128, mkexpr(vB), mkU8(sh_uimm))))) ); |
| 8139 | break; |
| 8140 | } |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 8141 | case 0x28C: { // vspltw (Splat Word, AV p250) |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 8142 | /* vD = Dup32x4( vB[UIMM_5] ) */ |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 8143 | UChar sh_uimm = (3 - (UIMM_5 & 3)) * 32; |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8144 | DIP("vspltw v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 8145 | putVReg( vD_addr, unop(Iop_Dup32x4, |
| 8146 | unop(Iop_V128to32, |
| 8147 | binop(Iop_ShrV128, mkexpr(vB), mkU8(sh_uimm)))) ); |
| 8148 | break; |
| 8149 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8150 | case 0x30C: // vspltisb (Splat Immediate Signed B, AV p247) |
| 8151 | DIP("vspltisb v%d,%d\n", vD_addr, (Char)SIMM_8); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8152 | putVReg( vD_addr, unop(Iop_Dup8x16, mkU8(SIMM_8)) ); |
| 8153 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8154 | |
| 8155 | case 0x34C: // vspltish (Splat Immediate Signed HW, AV p248) |
| 8156 | DIP("vspltish v%d,%d\n", vD_addr, (Char)SIMM_8); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8157 | putVReg( vD_addr, |
| 8158 | unop(Iop_Dup16x8, mkU16(extend_s_8to32(SIMM_8))) ); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8159 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8160 | |
| 8161 | case 0x38C: // vspltisw (Splat Immediate Signed W, AV p249) |
| 8162 | DIP("vspltisw v%d,%d\n", vD_addr, (Char)SIMM_8); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8163 | putVReg( vD_addr, |
| 8164 | unop(Iop_Dup32x4, mkU32(extend_s_8to32(SIMM_8))) ); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8165 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8166 | |
| 8167 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8168 | vex_printf("dis_av_permute(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8169 | return False; |
| 8170 | } |
| 8171 | return True; |
| 8172 | } |
| 8173 | |
| 8174 | /* |
| 8175 | AltiVec Pack/Unpack Instructions |
| 8176 | */ |
| 8177 | static Bool dis_av_pack ( UInt theInstr ) |
| 8178 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8179 | /* VX-Form */ |
| 8180 | UChar opc1 = ifieldOPC(theInstr); |
| 8181 | UChar vD_addr = ifieldRegDS(theInstr); |
| 8182 | UChar vA_addr = ifieldRegA(theInstr); |
| 8183 | UChar vB_addr = ifieldRegB(theInstr); |
| 8184 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8185 | |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8186 | IRTemp signs = IRTemp_INVALID; |
| 8187 | IRTemp zeros = IRTemp_INVALID; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8188 | IRTemp vA = newTemp(Ity_V128); |
| 8189 | IRTemp vB = newTemp(Ity_V128); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8190 | assign( vA, getVReg(vA_addr)); |
| 8191 | assign( vB, getVReg(vB_addr)); |
| 8192 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8193 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8194 | vex_printf("dis_av_pack(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8195 | return False; |
| 8196 | } |
| 8197 | |
| 8198 | switch (opc2) { |
| 8199 | /* Packing */ |
| 8200 | case 0x00E: // vpkuhum (Pack Unsigned HW Unsigned Modulo, AV p224) |
| 8201 | DIP("vpkuhum v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 8202 | putVReg( vD_addr, binop(Iop_Narrow16x8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8203 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8204 | |
| 8205 | case 0x04E: // vpkuwum (Pack Unsigned W Unsigned Modulo, AV p226) |
| 8206 | DIP("vpkuwum v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 8207 | putVReg( vD_addr, binop(Iop_Narrow32x4, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8208 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8209 | |
| 8210 | case 0x08E: // vpkuhus (Pack Unsigned HW Unsigned Saturate, AV p225) |
| 8211 | DIP("vpkuhus v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8212 | putVReg( vD_addr, |
| 8213 | binop(Iop_QNarrow16Ux8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8214 | // TODO: set VSCR[SAT] |
| 8215 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8216 | |
| 8217 | case 0x0CE: // vpkuwus (Pack Unsigned W Unsigned Saturate, AV p227) |
| 8218 | DIP("vpkuwus v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8219 | putVReg( vD_addr, |
| 8220 | binop(Iop_QNarrow32Ux4, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8221 | // TODO: set VSCR[SAT] |
| 8222 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8223 | |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8224 | case 0x10E: { // vpkshus (Pack Signed HW Unsigned Saturate, AV p221) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8225 | // This insn does a signed->unsigned saturating conversion. |
| 8226 | // Conversion done here, then uses unsigned->unsigned vpk insn: |
| 8227 | // => UnsignedSaturatingNarrow( x & ~ (x >>s 15) ) |
| 8228 | IRTemp vA_tmp = newTemp(Ity_V128); |
| 8229 | IRTemp vB_tmp = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8230 | DIP("vpkshus v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8231 | assign( vA_tmp, binop(Iop_AndV128, mkexpr(vA), |
| 8232 | unop(Iop_NotV128, |
| 8233 | binop(Iop_SarN16x8, |
| 8234 | mkexpr(vA), mkU8(15)))) ); |
| 8235 | assign( vB_tmp, binop(Iop_AndV128, mkexpr(vB), |
| 8236 | unop(Iop_NotV128, |
| 8237 | binop(Iop_SarN16x8, |
| 8238 | mkexpr(vB), mkU8(15)))) ); |
| 8239 | putVReg( vD_addr, binop(Iop_QNarrow16Ux8, |
| 8240 | mkexpr(vA_tmp), mkexpr(vB_tmp)) ); |
| 8241 | // TODO: set VSCR[SAT] |
| 8242 | return True; |
| 8243 | } |
| 8244 | case 0x14E: { // vpkswus (Pack Signed W Unsigned Saturate, AV p223) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8245 | // This insn does a signed->unsigned saturating conversion. |
| 8246 | // Conversion done here, then uses unsigned->unsigned vpk insn: |
| 8247 | // => UnsignedSaturatingNarrow( x & ~ (x >>s 31) ) |
| 8248 | IRTemp vA_tmp = newTemp(Ity_V128); |
| 8249 | IRTemp vB_tmp = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8250 | DIP("vpkswus v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8251 | assign( vA_tmp, binop(Iop_AndV128, mkexpr(vA), |
| 8252 | unop(Iop_NotV128, |
| 8253 | binop(Iop_SarN32x4, |
| 8254 | mkexpr(vA), mkU8(31)))) ); |
| 8255 | assign( vB_tmp, binop(Iop_AndV128, mkexpr(vB), |
| 8256 | unop(Iop_NotV128, |
| 8257 | binop(Iop_SarN32x4, |
| 8258 | mkexpr(vB), mkU8(31)))) ); |
| 8259 | putVReg( vD_addr, binop(Iop_QNarrow32Ux4, |
| 8260 | mkexpr(vA_tmp), mkexpr(vB_tmp)) ); |
| 8261 | // TODO: set VSCR[SAT] |
| 8262 | return True; |
| 8263 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8264 | case 0x18E: // vpkshss (Pack Signed HW Signed Saturate, AV p220) |
| 8265 | DIP("vpkshss v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8266 | putVReg( vD_addr, |
| 8267 | binop(Iop_QNarrow16Sx8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8268 | // TODO: set VSCR[SAT] |
| 8269 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8270 | |
| 8271 | case 0x1CE: // vpkswss (Pack Signed W Signed Saturate, AV p222) |
| 8272 | DIP("vpkswss v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8273 | putVReg( vD_addr, |
| 8274 | binop(Iop_QNarrow32Sx4, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8275 | // TODO: set VSCR[SAT] |
| 8276 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8277 | |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8278 | case 0x30E: { // vpkpx (Pack Pixel, AV p219) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8279 | /* CAB: Worth a new primop? */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8280 | /* Using shifts to compact pixel elements, then packing them */ |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8281 | IRTemp a1 = newTemp(Ity_V128); |
| 8282 | IRTemp a2 = newTemp(Ity_V128); |
| 8283 | IRTemp a3 = newTemp(Ity_V128); |
| 8284 | IRTemp a_tmp = newTemp(Ity_V128); |
| 8285 | IRTemp b1 = newTemp(Ity_V128); |
| 8286 | IRTemp b2 = newTemp(Ity_V128); |
| 8287 | IRTemp b3 = newTemp(Ity_V128); |
| 8288 | IRTemp b_tmp = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8289 | DIP("vpkpx v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8290 | assign( a1, binop(Iop_ShlN16x8, |
| 8291 | binop(Iop_ShrN32x4, mkexpr(vA), mkU8(19)), |
| 8292 | mkU8(10)) ); |
| 8293 | assign( a2, binop(Iop_ShlN16x8, |
| 8294 | binop(Iop_ShrN16x8, mkexpr(vA), mkU8(11)), |
| 8295 | mkU8(5)) ); |
| 8296 | assign( a3, binop(Iop_ShrN16x8, |
| 8297 | binop(Iop_ShlN16x8, mkexpr(vA), mkU8(8)), |
| 8298 | mkU8(11)) ); |
| 8299 | assign( a_tmp, binop(Iop_OrV128, mkexpr(a1), |
| 8300 | binop(Iop_OrV128, mkexpr(a2), mkexpr(a3))) ); |
| 8301 | |
| 8302 | assign( b1, binop(Iop_ShlN16x8, |
| 8303 | binop(Iop_ShrN32x4, mkexpr(vB), mkU8(19)), |
| 8304 | mkU8(10)) ); |
| 8305 | assign( b2, binop(Iop_ShlN16x8, |
| 8306 | binop(Iop_ShrN16x8, mkexpr(vB), mkU8(11)), |
| 8307 | mkU8(5)) ); |
| 8308 | assign( b3, binop(Iop_ShrN16x8, |
| 8309 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(8)), |
| 8310 | mkU8(11)) ); |
| 8311 | assign( b_tmp, binop(Iop_OrV128, mkexpr(b1), |
| 8312 | binop(Iop_OrV128, mkexpr(b2), mkexpr(b3))) ); |
| 8313 | |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 8314 | putVReg( vD_addr, binop(Iop_Narrow32x4, |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8315 | mkexpr(a_tmp), mkexpr(b_tmp)) ); |
| 8316 | return True; |
| 8317 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8318 | |
| 8319 | default: |
| 8320 | break; // Fall through... |
| 8321 | } |
| 8322 | |
| 8323 | |
| 8324 | if (vA_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8325 | vex_printf("dis_av_pack(ppc)(vA_addr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8326 | return False; |
| 8327 | } |
| 8328 | |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8329 | signs = newTemp(Ity_V128); |
| 8330 | zeros = newTemp(Ity_V128); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8331 | assign( zeros, unop(Iop_Dup32x4, mkU32(0)) ); |
| 8332 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8333 | switch (opc2) { |
| 8334 | /* Unpacking */ |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8335 | case 0x20E: { // vupkhsb (Unpack High Signed B, AV p277) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8336 | DIP("vupkhsb v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8337 | assign( signs, binop(Iop_CmpGT8Sx16, mkexpr(zeros), mkexpr(vB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8338 | putVReg( vD_addr, |
| 8339 | binop(Iop_InterleaveHI8x16, mkexpr(signs), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8340 | break; |
| 8341 | } |
| 8342 | case 0x24E: { // vupkhsh (Unpack High Signed HW, AV p278) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8343 | DIP("vupkhsh v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8344 | assign( signs, binop(Iop_CmpGT16Sx8, mkexpr(zeros), mkexpr(vB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8345 | putVReg( vD_addr, |
| 8346 | binop(Iop_InterleaveHI16x8, mkexpr(signs), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8347 | break; |
| 8348 | } |
| 8349 | case 0x28E: { // vupklsb (Unpack Low Signed B, AV p280) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8350 | DIP("vupklsb v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8351 | assign( signs, binop(Iop_CmpGT8Sx16, mkexpr(zeros), mkexpr(vB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8352 | putVReg( vD_addr, |
| 8353 | binop(Iop_InterleaveLO8x16, mkexpr(signs), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8354 | break; |
| 8355 | } |
| 8356 | case 0x2CE: { // vupklsh (Unpack Low Signed HW, AV p281) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8357 | DIP("vupklsh v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8358 | assign( signs, binop(Iop_CmpGT16Sx8, mkexpr(zeros), mkexpr(vB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8359 | putVReg( vD_addr, |
| 8360 | binop(Iop_InterleaveLO16x8, mkexpr(signs), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8361 | break; |
| 8362 | } |
| 8363 | case 0x34E: { // vupkhpx (Unpack High Pixel16, AV p276) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8364 | /* CAB: Worth a new primop? */ |
| 8365 | /* Using shifts to isolate pixel elements, then expanding them */ |
| 8366 | IRTemp z0 = newTemp(Ity_V128); |
| 8367 | IRTemp z1 = newTemp(Ity_V128); |
| 8368 | IRTemp z01 = newTemp(Ity_V128); |
| 8369 | IRTemp z2 = newTemp(Ity_V128); |
| 8370 | IRTemp z3 = newTemp(Ity_V128); |
| 8371 | IRTemp z23 = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8372 | DIP("vupkhpx v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8373 | assign( z0, binop(Iop_ShlN16x8, |
| 8374 | binop(Iop_SarN16x8, mkexpr(vB), mkU8(15)), |
| 8375 | mkU8(8)) ); |
| 8376 | assign( z1, binop(Iop_ShrN16x8, |
| 8377 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(1)), |
| 8378 | mkU8(11)) ); |
| 8379 | assign( z01, binop(Iop_InterleaveHI16x8, mkexpr(zeros), |
| 8380 | binop(Iop_OrV128, mkexpr(z0), mkexpr(z1))) ); |
| 8381 | assign( z2, binop(Iop_ShrN16x8, |
| 8382 | binop(Iop_ShlN16x8, |
| 8383 | binop(Iop_ShrN16x8, mkexpr(vB), mkU8(5)), |
| 8384 | mkU8(11)), |
| 8385 | mkU8(3)) ); |
| 8386 | assign( z3, binop(Iop_ShrN16x8, |
| 8387 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(11)), |
| 8388 | mkU8(11)) ); |
| 8389 | assign( z23, binop(Iop_InterleaveHI16x8, mkexpr(zeros), |
| 8390 | binop(Iop_OrV128, mkexpr(z2), mkexpr(z3))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8391 | putVReg( vD_addr, |
| 8392 | binop(Iop_OrV128, |
| 8393 | binop(Iop_ShlN32x4, mkexpr(z01), mkU8(16)), |
| 8394 | mkexpr(z23)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8395 | break; |
| 8396 | } |
| 8397 | case 0x3CE: { // vupklpx (Unpack Low Pixel16, AV p279) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8398 | /* identical to vupkhpx, except interleaving LO */ |
| 8399 | IRTemp z0 = newTemp(Ity_V128); |
| 8400 | IRTemp z1 = newTemp(Ity_V128); |
| 8401 | IRTemp z01 = newTemp(Ity_V128); |
| 8402 | IRTemp z2 = newTemp(Ity_V128); |
| 8403 | IRTemp z3 = newTemp(Ity_V128); |
| 8404 | IRTemp z23 = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 8405 | DIP("vupklpx v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8406 | assign( z0, binop(Iop_ShlN16x8, |
| 8407 | binop(Iop_SarN16x8, mkexpr(vB), mkU8(15)), |
| 8408 | mkU8(8)) ); |
| 8409 | assign( z1, binop(Iop_ShrN16x8, |
| 8410 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(1)), |
| 8411 | mkU8(11)) ); |
| 8412 | assign( z01, binop(Iop_InterleaveLO16x8, mkexpr(zeros), |
| 8413 | binop(Iop_OrV128, mkexpr(z0), mkexpr(z1))) ); |
| 8414 | assign( z2, binop(Iop_ShrN16x8, |
| 8415 | binop(Iop_ShlN16x8, |
| 8416 | binop(Iop_ShrN16x8, mkexpr(vB), mkU8(5)), |
| 8417 | mkU8(11)), |
| 8418 | mkU8(3)) ); |
| 8419 | assign( z3, binop(Iop_ShrN16x8, |
| 8420 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(11)), |
| 8421 | mkU8(11)) ); |
| 8422 | assign( z23, binop(Iop_InterleaveLO16x8, mkexpr(zeros), |
| 8423 | binop(Iop_OrV128, mkexpr(z2), mkexpr(z3))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8424 | putVReg( vD_addr, |
| 8425 | binop(Iop_OrV128, |
| 8426 | binop(Iop_ShlN32x4, mkexpr(z01), mkU8(16)), |
| 8427 | mkexpr(z23)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 8428 | break; |
| 8429 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8430 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8431 | vex_printf("dis_av_pack(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8432 | return False; |
| 8433 | } |
| 8434 | return True; |
| 8435 | } |
| 8436 | |
| 8437 | |
| 8438 | /* |
| 8439 | AltiVec Floating Point Arithmetic Instructions |
| 8440 | */ |
| 8441 | static Bool dis_av_fp_arith ( UInt theInstr ) |
| 8442 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8443 | /* VA-Form */ |
| 8444 | UChar opc1 = ifieldOPC(theInstr); |
| 8445 | UChar vD_addr = ifieldRegDS(theInstr); |
| 8446 | UChar vA_addr = ifieldRegA(theInstr); |
| 8447 | UChar vB_addr = ifieldRegB(theInstr); |
| 8448 | UChar vC_addr = ifieldRegC(theInstr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8449 | UInt opc2=0; |
| 8450 | |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8451 | IRTemp vA = newTemp(Ity_V128); |
| 8452 | IRTemp vB = newTemp(Ity_V128); |
| 8453 | IRTemp vC = newTemp(Ity_V128); |
| 8454 | assign( vA, getVReg(vA_addr)); |
| 8455 | assign( vB, getVReg(vB_addr)); |
| 8456 | assign( vC, getVReg(vC_addr)); |
| 8457 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8458 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8459 | vex_printf("dis_av_fp_arith(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8460 | return False; |
| 8461 | } |
| 8462 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8463 | opc2 = IFIELD( theInstr, 0, 6 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8464 | switch (opc2) { |
| 8465 | case 0x2E: // vmaddfp (Multiply Add FP, AV p177) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8466 | DIP("vmaddfp v%d,v%d,v%d,v%d\n", |
| 8467 | vD_addr, vA_addr, vC_addr, vB_addr); |
| 8468 | putVReg( vD_addr, |
| 8469 | binop(Iop_Add32Fx4, mkexpr(vB), |
| 8470 | binop(Iop_Mul32Fx4, mkexpr(vA), mkexpr(vC))) ); |
cerion | f3f173c | 2005-11-14 02:37:44 +0000 | [diff] [blame] | 8471 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8472 | |
cerion | f3f173c | 2005-11-14 02:37:44 +0000 | [diff] [blame] | 8473 | case 0x2F: { // vnmsubfp (Negative Multiply-Subtract FP, AV p215) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8474 | DIP("vnmsubfp v%d,v%d,v%d,v%d\n", |
| 8475 | vD_addr, vA_addr, vC_addr, vB_addr); |
| 8476 | putVReg( vD_addr, |
| 8477 | binop(Iop_Sub32Fx4, |
| 8478 | mkexpr(vB), |
| 8479 | binop(Iop_Mul32Fx4, mkexpr(vA), mkexpr(vC))) ); |
cerion | f3f173c | 2005-11-14 02:37:44 +0000 | [diff] [blame] | 8480 | return True; |
| 8481 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8482 | |
| 8483 | default: |
| 8484 | break; // Fall through... |
| 8485 | } |
| 8486 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8487 | opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8488 | switch (opc2) { |
| 8489 | case 0x00A: // vaddfp (Add FP, AV p137) |
| 8490 | DIP("vaddfp v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8491 | putVReg( vD_addr, binop(Iop_Add32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8492 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8493 | |
| 8494 | case 0x04A: // vsubfp (Subtract FP, AV p261) |
| 8495 | DIP("vsubfp v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8496 | putVReg( vD_addr, binop(Iop_Sub32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8497 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8498 | |
| 8499 | case 0x40A: // vmaxfp (Maximum FP, AV p178) |
| 8500 | DIP("vmaxfp v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8501 | putVReg( vD_addr, binop(Iop_Max32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8502 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8503 | |
| 8504 | case 0x44A: // vminfp (Minimum FP, AV p187) |
| 8505 | DIP("vminfp v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8506 | putVReg( vD_addr, binop(Iop_Min32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8507 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8508 | |
| 8509 | default: |
| 8510 | break; // Fall through... |
| 8511 | } |
| 8512 | |
| 8513 | |
| 8514 | if (vA_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8515 | vex_printf("dis_av_fp_arith(ppc)(vA_addr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8516 | return False; |
| 8517 | } |
| 8518 | |
| 8519 | switch (opc2) { |
| 8520 | case 0x10A: // vrefp (Reciprocal Esimate FP, AV p228) |
| 8521 | DIP("vrefp v%d,v%d\n", vD_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8522 | putVReg( vD_addr, unop(Iop_Recip32Fx4, mkexpr(vB)) ); |
| 8523 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8524 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8525 | case 0x14A: // vrsqrtefp (Reciprocal Sqrt Estimate FP, AV p237) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8526 | DIP("vrsqrtefp v%d,v%d\n", vD_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8527 | putVReg( vD_addr, unop(Iop_RSqrt32Fx4, mkexpr(vB)) ); |
| 8528 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8529 | |
| 8530 | case 0x18A: // vexptefp (2 Raised to the Exp Est FP, AV p173) |
| 8531 | DIP("vexptefp v%d,v%d\n", vD_addr, vB_addr); |
| 8532 | DIP(" => not implemented\n"); |
| 8533 | return False; |
| 8534 | |
| 8535 | case 0x1CA: // vlogefp (Log2 Estimate FP, AV p175) |
| 8536 | DIP("vlogefp v%d,v%d\n", vD_addr, vB_addr); |
| 8537 | DIP(" => not implemented\n"); |
| 8538 | return False; |
| 8539 | |
| 8540 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8541 | vex_printf("dis_av_fp_arith(ppc)(opc2=0x%x)\n",opc2); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8542 | return False; |
| 8543 | } |
| 8544 | return True; |
| 8545 | } |
| 8546 | |
| 8547 | /* |
| 8548 | AltiVec Floating Point Compare Instructions |
| 8549 | */ |
| 8550 | static Bool dis_av_fp_cmp ( UInt theInstr ) |
| 8551 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8552 | /* VXR-Form */ |
| 8553 | UChar opc1 = ifieldOPC(theInstr); |
| 8554 | UChar vD_addr = ifieldRegDS(theInstr); |
| 8555 | UChar vA_addr = ifieldRegA(theInstr); |
| 8556 | UChar vB_addr = ifieldRegB(theInstr); |
| 8557 | UChar flag_rC = ifieldBIT10(theInstr); |
| 8558 | UInt opc2 = IFIELD( theInstr, 0, 10 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8559 | |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8560 | Bool cmp_bounds = False; |
| 8561 | |
| 8562 | IRTemp vA = newTemp(Ity_V128); |
| 8563 | IRTemp vB = newTemp(Ity_V128); |
| 8564 | IRTemp vD = newTemp(Ity_V128); |
| 8565 | assign( vA, getVReg(vA_addr)); |
| 8566 | assign( vB, getVReg(vB_addr)); |
| 8567 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8568 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8569 | vex_printf("dis_av_fp_cmp(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8570 | return False; |
| 8571 | } |
| 8572 | |
| 8573 | switch (opc2) { |
| 8574 | case 0x0C6: // vcmpeqfp (Compare Equal-to FP, AV p159) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8575 | DIP("vcmpeqfp%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 8576 | vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8577 | assign( vD, binop(Iop_CmpEQ32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8578 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8579 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8580 | case 0x1C6: // vcmpgefp (Compare Greater-than-or-Equal-to, AV p163) |
| 8581 | DIP("vcmpgefp%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 8582 | vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8583 | assign( vD, binop(Iop_CmpGE32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8584 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8585 | |
| 8586 | case 0x2C6: // vcmpgtfp (Compare Greater-than FP, AV p164) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8587 | DIP("vcmpgtfp%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 8588 | vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8589 | assign( vD, binop(Iop_CmpGT32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8590 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8591 | |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8592 | case 0x3C6: { // vcmpbfp (Compare Bounds FP, AV p157) |
| 8593 | IRTemp gt = newTemp(Ity_V128); |
| 8594 | IRTemp lt = newTemp(Ity_V128); |
| 8595 | IRTemp zeros = newTemp(Ity_V128); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8596 | DIP("vcmpbfp%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 8597 | vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8598 | cmp_bounds = True; |
| 8599 | assign( zeros, unop(Iop_Dup32x4, mkU32(0)) ); |
| 8600 | |
| 8601 | /* Note: making use of fact that the ppc backend for compare insns |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8602 | return zero'd lanes if either of the corresponding arg lanes is |
| 8603 | a nan. |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8604 | |
| 8605 | Perhaps better to have an irop Iop_isNan32Fx4, but then we'd |
| 8606 | need this for the other compares too (vcmpeqfp etc)... |
| 8607 | Better still, tighten down the spec for compare irops. |
| 8608 | */ |
| 8609 | assign( gt, unop(Iop_NotV128, |
| 8610 | binop(Iop_CmpLE32Fx4, mkexpr(vA), mkexpr(vB))) ); |
| 8611 | assign( lt, unop(Iop_NotV128, |
| 8612 | binop(Iop_CmpGE32Fx4, mkexpr(vA), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8613 | binop(Iop_Sub32Fx4, mkexpr(zeros), |
| 8614 | mkexpr(vB)))) ); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8615 | |
| 8616 | // finally, just shift gt,lt to correct position |
| 8617 | assign( vD, binop(Iop_ShlN32x4, |
| 8618 | binop(Iop_OrV128, |
| 8619 | binop(Iop_AndV128, mkexpr(gt), |
| 8620 | unop(Iop_Dup32x4, mkU32(0x2))), |
| 8621 | binop(Iop_AndV128, mkexpr(lt), |
| 8622 | unop(Iop_Dup32x4, mkU32(0x1)))), |
| 8623 | mkU8(30)) ); |
| 8624 | break; |
| 8625 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8626 | |
| 8627 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8628 | vex_printf("dis_av_fp_cmp(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8629 | return False; |
| 8630 | } |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8631 | |
| 8632 | putVReg( vD_addr, mkexpr(vD) ); |
| 8633 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8634 | if (flag_rC) { |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8635 | set_AV_CR6( mkexpr(vD), !cmp_bounds ); |
| 8636 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8637 | return True; |
| 8638 | } |
| 8639 | |
| 8640 | /* |
| 8641 | AltiVec Floating Point Convert/Round Instructions |
| 8642 | */ |
| 8643 | static Bool dis_av_fp_convert ( UInt theInstr ) |
| 8644 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8645 | /* VX-Form */ |
| 8646 | UChar opc1 = ifieldOPC(theInstr); |
| 8647 | UChar vD_addr = ifieldRegDS(theInstr); |
| 8648 | UChar UIMM_5 = ifieldRegA(theInstr); |
| 8649 | UChar vB_addr = ifieldRegB(theInstr); |
| 8650 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8651 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8652 | IRTemp vB = newTemp(Ity_V128); |
| 8653 | IRTemp vScale = newTemp(Ity_V128); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8654 | IRTemp vInvScale = newTemp(Ity_V128); |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 8655 | |
| 8656 | float scale, inv_scale; |
| 8657 | |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8658 | assign( vB, getVReg(vB_addr)); |
| 8659 | |
| 8660 | /* scale = 2^UIMM, cast to float, reinterpreted as uint */ |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 8661 | scale = (float)( (unsigned int) 1<<UIMM_5 ); |
sewardj | 2ead522 | 2005-11-23 03:53:45 +0000 | [diff] [blame] | 8662 | assign( vScale, unop(Iop_Dup32x4, mkU32( float_to_bits(scale) )) ); |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 8663 | inv_scale = 1/scale; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8664 | assign( vInvScale, |
| 8665 | unop(Iop_Dup32x4, mkU32( float_to_bits(inv_scale) )) ); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8666 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8667 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8668 | vex_printf("dis_av_fp_convert(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8669 | return False; |
| 8670 | } |
| 8671 | |
| 8672 | switch (opc2) { |
| 8673 | case 0x30A: // vcfux (Convert from Unsigned Fixed-Point W, AV p156) |
| 8674 | DIP("vcfux v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8675 | putVReg( vD_addr, binop(Iop_Mul32Fx4, |
| 8676 | unop(Iop_I32UtoFx4, mkexpr(vB)), |
| 8677 | mkexpr(vInvScale)) ); |
| 8678 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8679 | |
| 8680 | case 0x34A: // vcfsx (Convert from Signed Fixed-Point W, AV p155) |
| 8681 | DIP("vcfsx v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8682 | |
| 8683 | putVReg( vD_addr, binop(Iop_Mul32Fx4, |
| 8684 | unop(Iop_I32StoFx4, mkexpr(vB)), |
| 8685 | mkexpr(vInvScale)) ); |
| 8686 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8687 | |
| 8688 | case 0x38A: // vctuxs (Convert to Unsigned Fixed-Point W Saturate, AV p172) |
| 8689 | DIP("vctuxs v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8690 | putVReg( vD_addr, |
| 8691 | unop(Iop_QFtoI32Ux4_RZ, |
| 8692 | binop(Iop_Mul32Fx4, mkexpr(vB), mkexpr(vScale))) ); |
| 8693 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8694 | |
| 8695 | case 0x3CA: // vctsxs (Convert to Signed Fixed-Point W Saturate, AV p171) |
| 8696 | DIP("vctsxs v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8697 | putVReg( vD_addr, |
| 8698 | unop(Iop_QFtoI32Sx4_RZ, |
| 8699 | binop(Iop_Mul32Fx4, mkexpr(vB), mkexpr(vScale))) ); |
| 8700 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8701 | |
| 8702 | default: |
| 8703 | break; // Fall through... |
| 8704 | } |
| 8705 | |
| 8706 | if (UIMM_5 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8707 | vex_printf("dis_av_fp_convert(ppc)(UIMM_5)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8708 | return False; |
| 8709 | } |
| 8710 | |
| 8711 | switch (opc2) { |
| 8712 | case 0x20A: // vrfin (Round to FP Integer Nearest, AV p231) |
| 8713 | DIP("vrfin v%d,v%d\n", vD_addr, vB_addr); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8714 | putVReg( vD_addr, unop(Iop_RoundF32x4_RN, mkexpr(vB)) ); |
| 8715 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8716 | |
| 8717 | case 0x24A: // vrfiz (Round to FP Integer toward zero, AV p233) |
| 8718 | DIP("vrfiz v%d,v%d\n", vD_addr, vB_addr); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8719 | putVReg( vD_addr, unop(Iop_RoundF32x4_RZ, mkexpr(vB)) ); |
| 8720 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8721 | |
| 8722 | case 0x28A: // vrfip (Round to FP Integer toward +inf, AV p232) |
| 8723 | DIP("vrfip v%d,v%d\n", vD_addr, vB_addr); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8724 | putVReg( vD_addr, unop(Iop_RoundF32x4_RP, mkexpr(vB)) ); |
| 8725 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8726 | |
| 8727 | case 0x2CA: // vrfim (Round to FP Integer toward -inf, AV p230) |
| 8728 | DIP("vrfim v%d,v%d\n", vD_addr, vB_addr); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8729 | putVReg( vD_addr, unop(Iop_RoundF32x4_RM, mkexpr(vB)) ); |
| 8730 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8731 | |
| 8732 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8733 | vex_printf("dis_av_fp_convert(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8734 | return False; |
| 8735 | } |
| 8736 | return True; |
| 8737 | } |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8738 | |
| 8739 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 8740 | |
| 8741 | |
| 8742 | |
| 8743 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8744 | /*------------------------------------------------------------*/ |
| 8745 | /*--- Disassemble a single instruction ---*/ |
| 8746 | /*------------------------------------------------------------*/ |
| 8747 | |
| 8748 | /* Disassemble a single instruction into IR. The instruction |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8749 | is located in host memory at &guest_code[delta]. */ |
| 8750 | |
| 8751 | static |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8752 | DisResult disInstr_PPC_WRK ( |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8753 | Bool put_IP, |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 8754 | Bool (*resteerOkFn) ( /*opaque*/void*, Addr64 ), |
| 8755 | void* callback_opaque, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8756 | Long delta64, |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 8757 | VexArchInfo* archinfo, |
| 8758 | VexMiscInfo* miscinfo |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8759 | ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8760 | { |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8761 | UChar opc1; |
| 8762 | UInt opc2; |
| 8763 | DisResult dres; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8764 | UInt theInstr; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8765 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 8766 | Bool allow_F = False; |
| 8767 | Bool allow_V = False; |
| 8768 | Bool allow_FX = False; |
| 8769 | Bool allow_GX = False; |
| 8770 | UInt hwcaps = archinfo->hwcaps; |
| 8771 | Long delta; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8772 | |
sewardj | 059601a | 2005-11-13 00:53:05 +0000 | [diff] [blame] | 8773 | /* What insn variants are we supporting today? */ |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 8774 | if (mode64) { |
| 8775 | allow_F = True; |
| 8776 | allow_V = (0 != (hwcaps & VEX_HWCAPS_PPC64_V)); |
| 8777 | allow_FX = (0 != (hwcaps & VEX_HWCAPS_PPC64_FX)); |
| 8778 | allow_GX = (0 != (hwcaps & VEX_HWCAPS_PPC64_GX)); |
| 8779 | } else { |
| 8780 | allow_F = (0 != (hwcaps & VEX_HWCAPS_PPC32_F)); |
| 8781 | allow_V = (0 != (hwcaps & VEX_HWCAPS_PPC32_V)); |
| 8782 | allow_FX = (0 != (hwcaps & VEX_HWCAPS_PPC32_FX)); |
| 8783 | allow_GX = (0 != (hwcaps & VEX_HWCAPS_PPC32_GX)); |
| 8784 | } |
sewardj | 059601a | 2005-11-13 00:53:05 +0000 | [diff] [blame] | 8785 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8786 | /* The running delta */ |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 8787 | delta = (Long)mkSzAddr(ty, (ULong)delta64); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8788 | |
| 8789 | /* Set result defaults. */ |
| 8790 | dres.whatNext = Dis_Continue; |
| 8791 | dres.len = 0; |
| 8792 | dres.continueAt = 0; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8793 | |
cerion | 1515db9 | 2005-01-25 17:21:23 +0000 | [diff] [blame] | 8794 | /* At least this is simple on PPC32: insns are all 4 bytes long, and |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8795 | 4-aligned. So just fish the whole thing out of memory right now |
| 8796 | and have done. */ |
cerion | cf00446 | 2005-01-31 15:24:55 +0000 | [diff] [blame] | 8797 | theInstr = getUIntBigendianly( (UChar*)(&guest_code[delta]) ); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8798 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 8799 | if (0) vex_printf("insn: 0x%x\n", theInstr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8800 | |
sewardj | 1eb7e6b | 2006-01-12 21:13:14 +0000 | [diff] [blame] | 8801 | DIP("\t0x%llx: ", (ULong)guest_CIA_curr_instr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8802 | |
| 8803 | /* We may be asked to update the guest CIA before going further. */ |
| 8804 | if (put_IP) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 8805 | putGST( PPC_GST_CIA, mkSzImm(ty, guest_CIA_curr_instr) ); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8806 | |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 8807 | /* Spot "Special" instructions (see comment at top of file). */ |
sewardj | 1eb7e6b | 2006-01-12 21:13:14 +0000 | [diff] [blame] | 8808 | { |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 8809 | UChar* code = (UChar*)(guest_code + delta); |
sewardj | 1eb7e6b | 2006-01-12 21:13:14 +0000 | [diff] [blame] | 8810 | /* Spot the 16-byte preamble: |
| 8811 | 32-bit mode: |
| 8812 | 54001800 rlwinm 0,0,3,0,0 |
| 8813 | 54006800 rlwinm 0,0,13,0,0 |
| 8814 | 5400E800 rlwinm 0,0,29,0,0 |
| 8815 | 54009800 rlwinm 0,0,19,0,0 |
| 8816 | 64-bit mode: |
| 8817 | 78001800 rotldi 0,0,3 |
| 8818 | 78006800 rotldi 0,0,13 |
| 8819 | 7800E802 rotldi 0,0,61 |
| 8820 | 78009802 rotldi 0,0,51 |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8821 | */ |
sewardj | 1eb7e6b | 2006-01-12 21:13:14 +0000 | [diff] [blame] | 8822 | UInt word1 = mode64 ? 0x78001800 : 0x54001800; |
| 8823 | UInt word2 = mode64 ? 0x78006800 : 0x54006800; |
| 8824 | UInt word3 = mode64 ? 0x7800E802 : 0x5400E800; |
| 8825 | UInt word4 = mode64 ? 0x78009802 : 0x54009800; |
| 8826 | if (getUIntBigendianly(code+ 0) == word1 && |
| 8827 | getUIntBigendianly(code+ 4) == word2 && |
| 8828 | getUIntBigendianly(code+ 8) == word3 && |
| 8829 | getUIntBigendianly(code+12) == word4) { |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 8830 | /* Got a "Special" instruction preamble. Which one is it? */ |
| 8831 | if (getUIntBigendianly(code+16) == 0x7C210B78 /* or 1,1,1 */) { |
| 8832 | /* %R3 = client_request ( %R4 ) */ |
| 8833 | DIP("r3 = client_request ( %%r4 )\n"); |
| 8834 | delta += 20; |
| 8835 | irbb->next = mkSzImm( ty, guest_CIA_bbstart + delta ); |
| 8836 | irbb->jumpkind = Ijk_ClientReq; |
| 8837 | dres.whatNext = Dis_StopHere; |
| 8838 | goto decode_success; |
| 8839 | } |
| 8840 | else |
| 8841 | if (getUIntBigendianly(code+16) == 0x7C421378 /* or 2,2,2 */) { |
| 8842 | /* %R3 = guest_NRADDR */ |
| 8843 | DIP("r3 = guest_NRADDR\n"); |
| 8844 | delta += 20; |
| 8845 | dres.len = 20; |
| 8846 | putIReg(3, IRExpr_Get( OFFB_NRADDR, ty )); |
| 8847 | goto decode_success; |
| 8848 | } |
| 8849 | else |
| 8850 | if (getUIntBigendianly(code+16) == 0x7C631B78 /* or 3,3,3 */) { |
| 8851 | /* branch-and-link-to-noredir %R11 */ |
| 8852 | DIP("branch-and-link-to-noredir r11\n"); |
| 8853 | delta += 20; |
sewardj | 1eb7e6b | 2006-01-12 21:13:14 +0000 | [diff] [blame] | 8854 | putGST( PPC_GST_LR, mkSzImm(ty, guest_CIA_bbstart + (Long)delta) ); |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 8855 | irbb->next = getIReg(11); |
| 8856 | irbb->jumpkind = Ijk_NoRedir; |
| 8857 | dres.whatNext = Dis_StopHere; |
| 8858 | goto decode_success; |
| 8859 | } |
sewardj | 5ff11dd | 2006-01-20 14:19:25 +0000 | [diff] [blame] | 8860 | else |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 8861 | if (getUIntBigendianly(code+16) == 0x7C842378 /* or 4,4,4 */) { |
sewardj | 5ff11dd | 2006-01-20 14:19:25 +0000 | [diff] [blame] | 8862 | /* %R3 = guest_NRADDR_GPR2 */ |
| 8863 | DIP("r3 = guest_NRADDR_GPR2\n"); |
| 8864 | delta += 20; |
| 8865 | dres.len = 20; |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 8866 | putIReg(3, IRExpr_Get( OFFB_NRADDR_GPR2, ty )); |
sewardj | 5ff11dd | 2006-01-20 14:19:25 +0000 | [diff] [blame] | 8867 | goto decode_success; |
| 8868 | } |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 8869 | /* We don't know what it is. Set opc1/opc2 so decode_failure |
| 8870 | can print the insn following the Special-insn preamble. */ |
| 8871 | theInstr = getUIntBigendianly(code+16); |
| 8872 | opc1 = ifieldOPC(theInstr); |
| 8873 | opc2 = ifieldOPClo10(theInstr); |
| 8874 | goto decode_failure; |
| 8875 | /*NOTREACHED*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8876 | } |
| 8877 | } |
| 8878 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8879 | opc1 = ifieldOPC(theInstr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8880 | opc2 = ifieldOPClo10(theInstr); |
cerion | 932ad94 | 2005-01-30 10:18:50 +0000 | [diff] [blame] | 8881 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 8882 | // Note: all 'reserved' bits must be cleared, else invalid |
| 8883 | switch (opc1) { |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8884 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8885 | /* Integer Arithmetic Instructions */ |
| 8886 | case 0x0C: case 0x0D: case 0x0E: // addic, addic., addi |
| 8887 | case 0x0F: case 0x07: case 0x08: // addis, mulli, subfic |
| 8888 | if (dis_int_arith( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8889 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8890 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8891 | /* Integer Compare Instructions */ |
| 8892 | case 0x0B: case 0x0A: // cmpi, cmpli |
| 8893 | if (dis_int_cmp( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8894 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8895 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8896 | /* Integer Logical Instructions */ |
| 8897 | case 0x1C: case 0x1D: case 0x18: // andi., andis., ori |
| 8898 | case 0x19: case 0x1A: case 0x1B: // oris, xori, xoris |
| 8899 | if (dis_int_logic( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8900 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8901 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8902 | /* Integer Rotate Instructions */ |
| 8903 | case 0x14: case 0x15: case 0x17: // rlwimi, rlwinm, rlwnm |
| 8904 | if (dis_int_rot( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8905 | goto decode_failure; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 8906 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8907 | /* 64bit Integer Rotate Instructions */ |
| 8908 | case 0x1E: // rldcl, rldcr, rldic, rldicl, rldicr, rldimi |
| 8909 | if (dis_int_rot( theInstr )) goto decode_success; |
| 8910 | goto decode_failure; |
| 8911 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8912 | /* Integer Load Instructions */ |
| 8913 | case 0x22: case 0x23: case 0x2A: // lbz, lbzu, lha |
| 8914 | case 0x2B: case 0x28: case 0x29: // lhau, lhz, lhzu |
| 8915 | case 0x20: case 0x21: // lwz, lwzu |
| 8916 | if (dis_int_load( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8917 | goto decode_failure; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 8918 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8919 | /* Integer Store Instructions */ |
| 8920 | case 0x26: case 0x27: case 0x2C: // stb, stbu, sth |
| 8921 | case 0x2D: case 0x24: case 0x25: // sthu, stw, stwu |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 8922 | if (dis_int_store( theInstr, miscinfo )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8923 | goto decode_failure; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 8924 | |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 8925 | /* Integer Load and Store Multiple Instructions */ |
| 8926 | case 0x2E: case 0x2F: // lmw, stmw |
| 8927 | if (dis_int_ldst_mult( theInstr )) goto decode_success; |
| 8928 | goto decode_failure; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 8929 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8930 | /* Branch Instructions */ |
| 8931 | case 0x12: case 0x10: // b, bc |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 8932 | if (dis_branch(theInstr, miscinfo, &dres, |
| 8933 | resteerOkFn, callback_opaque)) |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 8934 | goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8935 | goto decode_failure; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8936 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8937 | /* System Linkage Instructions */ |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 8938 | case 0x11: // sc |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 8939 | if (dis_syslink(theInstr, miscinfo, &dres)) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8940 | goto decode_failure; |
cerion | 26d07b2 | 2005-02-02 17:13:28 +0000 | [diff] [blame] | 8941 | |
sewardj | 334870d | 2006-02-07 16:42:39 +0000 | [diff] [blame] | 8942 | /* Trap Instructions */ |
| 8943 | case 0x02: case 0x03: // tdi, twi |
| 8944 | if (dis_trapi(theInstr, &dres)) goto decode_success; |
| 8945 | goto decode_failure; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 8946 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8947 | /* Floating Point Load Instructions */ |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 8948 | case 0x30: case 0x31: case 0x32: // lfs, lfsu, lfd |
| 8949 | case 0x33: // lfdu |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 8950 | if (!allow_F) goto decode_noF; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8951 | if (dis_fp_load( theInstr )) goto decode_success; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8952 | goto decode_failure; |
cerion | 995bc36 | 2005-02-03 11:03:31 +0000 | [diff] [blame] | 8953 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8954 | /* Floating Point Store Instructions */ |
| 8955 | case 0x34: case 0x35: case 0x36: // stfsx, stfsux, stfdx |
| 8956 | case 0x37: // stfdux |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 8957 | if (!allow_F) goto decode_noF; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8958 | if (dis_fp_store( theInstr )) goto decode_success; |
| 8959 | goto decode_failure; |
| 8960 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8961 | /* 64bit Integer Loads */ |
| 8962 | case 0x3A: // ld, ldu, lwa |
| 8963 | if (!mode64) goto decode_failure; |
| 8964 | if (dis_int_load( theInstr )) goto decode_success; |
| 8965 | goto decode_failure; |
| 8966 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8967 | case 0x3B: |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 8968 | if (!allow_F) goto decode_noF; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8969 | opc2 = IFIELD(theInstr, 1, 5); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8970 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8971 | /* Floating Point Arith Instructions */ |
| 8972 | case 0x12: case 0x14: case 0x15: // fdivs, fsubs, fadds |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 8973 | case 0x19: // fmuls |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8974 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 8975 | goto decode_failure; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 8976 | case 0x16: // fsqrts |
| 8977 | if (!allow_FX) goto decode_noFX; |
| 8978 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 8979 | goto decode_failure; |
| 8980 | case 0x18: // fres |
| 8981 | if (!allow_GX) goto decode_noGX; |
| 8982 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 8983 | goto decode_failure; |
| 8984 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8985 | /* Floating Point Mult-Add Instructions */ |
| 8986 | case 0x1C: case 0x1D: case 0x1E: // fmsubs, fmadds, fnmsubs |
| 8987 | case 0x1F: // fnmadds |
| 8988 | if (dis_fp_multadd(theInstr)) goto decode_success; |
| 8989 | goto decode_failure; |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 8990 | |
| 8991 | case 0x1A: // frsqrtes |
| 8992 | if (!allow_GX) goto decode_noGX; |
| 8993 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 8994 | goto decode_failure; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8995 | |
| 8996 | default: |
| 8997 | goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8998 | } |
| 8999 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 9000 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9001 | /* 64bit Integer Stores */ |
| 9002 | case 0x3E: // std, stdu |
| 9003 | if (!mode64) goto decode_failure; |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 9004 | if (dis_int_store( theInstr, miscinfo )) goto decode_success; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9005 | goto decode_failure; |
| 9006 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 9007 | case 0x3F: |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9008 | if (!allow_F) goto decode_noF; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 9009 | /* Instrs using opc[1:5] never overlap instrs using opc[1:10], |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 9010 | so we can simply fall through the first switch statement */ |
| 9011 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 9012 | opc2 = IFIELD(theInstr, 1, 5); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 9013 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9014 | /* Floating Point Arith Instructions */ |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9015 | case 0x12: case 0x14: case 0x15: // fdiv, fsub, fadd |
| 9016 | case 0x19: // fmul |
| 9017 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 9018 | goto decode_failure; |
| 9019 | case 0x16: // fsqrt |
| 9020 | if (!allow_FX) goto decode_noFX; |
| 9021 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 9022 | goto decode_failure; |
| 9023 | case 0x17: case 0x1A: // fsel, frsqrte |
| 9024 | if (!allow_GX) goto decode_noGX; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9025 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 9026 | goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 9027 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9028 | /* Floating Point Mult-Add Instructions */ |
| 9029 | case 0x1C: case 0x1D: case 0x1E: // fmsub, fmadd, fnmsub |
| 9030 | case 0x1F: // fnmadd |
| 9031 | if (dis_fp_multadd(theInstr)) goto decode_success; |
| 9032 | goto decode_failure; |
sewardj | 79fd33f | 2006-01-29 17:07:57 +0000 | [diff] [blame] | 9033 | |
| 9034 | case 0x18: // fre |
| 9035 | if (!allow_GX) goto decode_noGX; |
| 9036 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 9037 | goto decode_failure; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9038 | |
| 9039 | default: |
| 9040 | break; // Fall through |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 9041 | } |
| 9042 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 9043 | opc2 = IFIELD(theInstr, 1, 10); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 9044 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9045 | /* Floating Point Compare Instructions */ |
| 9046 | case 0x000: // fcmpu |
| 9047 | case 0x020: // fcmpo |
| 9048 | if (dis_fp_cmp(theInstr)) goto decode_success; |
| 9049 | goto decode_failure; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 9050 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9051 | /* Floating Point Rounding/Conversion Instructions */ |
| 9052 | case 0x00C: // frsp |
| 9053 | case 0x00E: // fctiw |
| 9054 | case 0x00F: // fctiwz |
sewardj | 6be6723 | 2006-01-24 19:00:05 +0000 | [diff] [blame] | 9055 | case 0x32E: // fctid |
| 9056 | case 0x32F: // fctidz |
| 9057 | case 0x34E: // fcfid |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9058 | if (dis_fp_round(theInstr)) goto decode_success; |
| 9059 | goto decode_failure; |
| 9060 | |
| 9061 | /* Floating Point Move Instructions */ |
| 9062 | case 0x028: // fneg |
| 9063 | case 0x048: // fmr |
| 9064 | case 0x088: // fnabs |
| 9065 | case 0x108: // fabs |
| 9066 | if (dis_fp_move( theInstr )) goto decode_success; |
| 9067 | goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 9068 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9069 | /* Floating Point Status/Control Register Instructions */ |
cerion | 3ea49ee | 2006-01-04 10:53:00 +0000 | [diff] [blame] | 9070 | case 0x026: // mtfsb1 |
sewardj | 496b88f | 2006-10-04 17:46:11 +0000 | [diff] [blame] | 9071 | case 0x040: // mcrfs |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9072 | case 0x046: // mtfsb0 |
| 9073 | case 0x086: // mtfsfi |
| 9074 | case 0x247: // mffs |
| 9075 | case 0x2C7: // mtfsf |
| 9076 | if (dis_fp_scr( theInstr )) goto decode_success; |
| 9077 | goto decode_failure; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9078 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9079 | default: |
| 9080 | goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 9081 | } |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 9082 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9083 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 9084 | case 0x13: |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9085 | switch (opc2) { |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 9086 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9087 | /* Condition Register Logical Instructions */ |
| 9088 | case 0x101: case 0x081: case 0x121: // crand, crandc, creqv |
| 9089 | case 0x0E1: case 0x021: case 0x1C1: // crnand, crnor, cror |
| 9090 | case 0x1A1: case 0x0C1: case 0x000: // crorc, crxor, mcrf |
| 9091 | if (dis_cond_logic( theInstr )) goto decode_success; |
| 9092 | goto decode_failure; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9093 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9094 | /* Branch Instructions */ |
| 9095 | case 0x210: case 0x010: // bcctr, bclr |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 9096 | if (dis_branch(theInstr, miscinfo, &dres, |
| 9097 | resteerOkFn, callback_opaque)) |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 9098 | goto decode_success; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9099 | goto decode_failure; |
| 9100 | |
| 9101 | /* Memory Synchronization Instructions */ |
| 9102 | case 0x096: // isync |
| 9103 | if (dis_memsync( theInstr )) goto decode_success; |
| 9104 | goto decode_failure; |
| 9105 | |
| 9106 | default: |
| 9107 | goto decode_failure; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9108 | } |
| 9109 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 9110 | |
| 9111 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9112 | case 0x1F: |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9113 | |
| 9114 | /* For arith instns, bit10 is the OE flag (overflow enable) */ |
| 9115 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 9116 | opc2 = IFIELD(theInstr, 1, 9); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9117 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9118 | /* Integer Arithmetic Instructions */ |
| 9119 | case 0x10A: case 0x00A: case 0x08A: // add, addc, adde |
| 9120 | case 0x0EA: case 0x0CA: case 0x1EB: // addme, addze, divw |
| 9121 | case 0x1CB: case 0x04B: case 0x00B: // divwu, mulhw, mulhwu |
| 9122 | case 0x0EB: case 0x068: case 0x028: // mullw, neg, subf |
| 9123 | case 0x008: case 0x088: case 0x0E8: // subfc, subfe, subfme |
| 9124 | case 0x0C8: // subfze |
| 9125 | if (dis_int_arith( theInstr )) goto decode_success; |
| 9126 | goto decode_failure; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9127 | |
| 9128 | /* 64bit Integer Arithmetic */ |
| 9129 | case 0x009: case 0x049: case 0x0E9: // mulhdu, mulhd, mulld |
| 9130 | case 0x1C9: case 0x1E9: // divdu, divd |
| 9131 | if (!mode64) goto decode_failure; |
| 9132 | if (dis_int_arith( theInstr )) goto decode_success; |
| 9133 | goto decode_failure; |
| 9134 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9135 | default: |
| 9136 | break; // Fall through... |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9137 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 9138 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9139 | /* All remaining opcodes use full 10 bits. */ |
| 9140 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 9141 | opc2 = IFIELD(theInstr, 1, 10); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9142 | switch (opc2) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9143 | /* Integer Compare Instructions */ |
| 9144 | case 0x000: case 0x020: // cmp, cmpl |
| 9145 | if (dis_int_cmp( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9146 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 9147 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9148 | /* Integer Logical Instructions */ |
| 9149 | case 0x01C: case 0x03C: case 0x01A: // and, andc, cntlzw |
| 9150 | case 0x11C: case 0x3BA: case 0x39A: // eqv, extsb, extsh |
| 9151 | case 0x1DC: case 0x07C: case 0x1BC: // nand, nor, or |
| 9152 | case 0x19C: case 0x13C: // orc, xor |
| 9153 | if (dis_int_logic( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9154 | goto decode_failure; |
cerion | 932ad94 | 2005-01-30 10:18:50 +0000 | [diff] [blame] | 9155 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9156 | /* 64bit Integer Logical Instructions */ |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 9157 | case 0x3DA: case 0x03A: // extsw, cntlzd |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9158 | if (!mode64) goto decode_failure; |
| 9159 | if (dis_int_logic( theInstr )) goto decode_success; |
| 9160 | goto decode_failure; |
| 9161 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9162 | /* Integer Shift Instructions */ |
| 9163 | case 0x018: case 0x318: case 0x338: // slw, sraw, srawi |
| 9164 | case 0x218: // srw |
| 9165 | if (dis_int_shift( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9166 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 9167 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9168 | /* 64bit Integer Shift Instructions */ |
| 9169 | case 0x01B: case 0x31A: // sld, srad |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 9170 | case 0x33A: case 0x33B: // sradi |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9171 | case 0x21B: // srd |
| 9172 | if (!mode64) goto decode_failure; |
| 9173 | if (dis_int_shift( theInstr )) goto decode_success; |
| 9174 | goto decode_failure; |
| 9175 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9176 | /* Integer Load Instructions */ |
| 9177 | case 0x057: case 0x077: case 0x157: // lbzx, lbzux, lhax |
| 9178 | case 0x177: case 0x117: case 0x137: // lhaux, lhzx, lhzux |
| 9179 | case 0x017: case 0x037: // lwzx, lwzux |
| 9180 | if (dis_int_load( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9181 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 9182 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9183 | /* 64bit Integer Load Instructions */ |
| 9184 | case 0x035: case 0x015: // ldux, ldx |
| 9185 | case 0x175: case 0x155: // lwaux, lwax |
| 9186 | if (!mode64) goto decode_failure; |
| 9187 | if (dis_int_load( theInstr )) goto decode_success; |
| 9188 | goto decode_failure; |
| 9189 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 9190 | /* Integer Store Instructions */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9191 | case 0x0F7: case 0x0D7: case 0x1B7: // stbux, stbx, sthux |
| 9192 | case 0x197: case 0x0B7: case 0x097: // sthx, stwux, stwx |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 9193 | if (dis_int_store( theInstr, miscinfo )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9194 | goto decode_failure; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 9195 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9196 | /* 64bit Integer Store Instructions */ |
| 9197 | case 0x0B5: case 0x095: // stdux, stdx |
| 9198 | if (!mode64) goto decode_failure; |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 9199 | if (dis_int_store( theInstr, miscinfo )) goto decode_success; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9200 | goto decode_failure; |
| 9201 | |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 9202 | /* Integer Load and Store with Byte Reverse Instructions */ |
| 9203 | case 0x316: case 0x216: case 0x396: // lhbrx, lwbrx, sthbrx |
| 9204 | case 0x296: // stwbrx |
| 9205 | if (dis_int_ldst_rev( theInstr )) goto decode_success; |
| 9206 | goto decode_failure; |
| 9207 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 9208 | /* Integer Load and Store String Instructions */ |
| 9209 | case 0x255: case 0x215: case 0x2D5: // lswi, lswx, stswi |
| 9210 | case 0x295: { // stswx |
| 9211 | Bool stopHere = False; |
| 9212 | Bool ok = dis_int_ldst_str( theInstr, &stopHere ); |
| 9213 | if (!ok) goto decode_failure; |
| 9214 | if (stopHere) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 9215 | irbb->next = mkSzImm(ty, nextInsnAddr()); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 9216 | irbb->jumpkind = Ijk_Boring; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9217 | dres.whatNext = Dis_StopHere; |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 9218 | } |
| 9219 | goto decode_success; |
| 9220 | } |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 9221 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9222 | /* Memory Synchronization Instructions */ |
| 9223 | case 0x356: case 0x014: case 0x096: // eieio, lwarx, stwcx. |
| 9224 | case 0x256: // sync |
| 9225 | if (dis_memsync( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9226 | goto decode_failure; |
| 9227 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9228 | /* 64bit Memory Synchronization Instructions */ |
| 9229 | case 0x054: case 0x0D6: // ldarx, stdcx. |
| 9230 | if (!mode64) goto decode_failure; |
| 9231 | if (dis_memsync( theInstr )) goto decode_success; |
| 9232 | goto decode_failure; |
| 9233 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9234 | /* Processor Control Instructions */ |
| 9235 | case 0x200: case 0x013: case 0x153: // mcrxr, mfcr, mfspr |
| 9236 | case 0x173: case 0x090: case 0x1D3: // mftb, mtcrf, mtspr |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 9237 | if (dis_proc_ctl( miscinfo, theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9238 | goto decode_failure; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 9239 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 9240 | /* Cache Management Instructions */ |
| 9241 | case 0x2F6: case 0x056: case 0x036: // dcba, dcbf, dcbst |
| 9242 | case 0x116: case 0x0F6: case 0x3F6: // dcbt, dcbtst, dcbz |
| 9243 | case 0x3D6: // icbi |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 9244 | if (dis_cache_manage( theInstr, &dres, archinfo )) |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 9245 | goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 9246 | goto decode_failure; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 9247 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 9248 | //zz /* External Control Instructions */ |
| 9249 | //zz case 0x136: case 0x1B6: // eciwx, ecowx |
| 9250 | //zz DIP("external control op => not implemented\n"); |
| 9251 | //zz goto decode_failure; |
| 9252 | //zz |
| 9253 | //zz /* Trap Instructions */ |
| 9254 | //zz case 0x004: // tw |
| 9255 | //zz DIP("trap op (tw) => not implemented\n"); |
| 9256 | //zz goto decode_failure; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 9257 | //zz case 0x044: // td |
| 9258 | //zz DIP("trap op (td) => not implemented\n"); |
| 9259 | //zz goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 9260 | |
| 9261 | /* Floating Point Load Instructions */ |
| 9262 | case 0x217: case 0x237: case 0x257: // lfsx, lfsux, lfdx |
| 9263 | case 0x277: // lfdux |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9264 | if (!allow_F) goto decode_noF; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 9265 | if (dis_fp_load( theInstr )) goto decode_success; |
| 9266 | goto decode_failure; |
| 9267 | |
| 9268 | /* Floating Point Store Instructions */ |
| 9269 | case 0x297: case 0x2B7: case 0x2D7: // stfs, stfsu, stfd |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9270 | case 0x2F7: // stfdu, stfiwx |
| 9271 | if (!allow_F) goto decode_noF; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 9272 | if (dis_fp_store( theInstr )) goto decode_success; |
| 9273 | goto decode_failure; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9274 | case 0x3D7: // stfiwx |
| 9275 | if (!allow_F) goto decode_noF; |
| 9276 | if (!allow_GX) goto decode_noGX; |
| 9277 | if (dis_fp_store( theInstr )) goto decode_success; |
| 9278 | goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 9279 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9280 | /* AltiVec instructions */ |
| 9281 | |
| 9282 | /* AV Cache Control - Data streams */ |
| 9283 | case 0x156: case 0x176: case 0x336: // dst, dstst, dss |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9284 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9285 | if (dis_av_datastream( theInstr )) goto decode_success; |
| 9286 | goto decode_failure; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 9287 | |
| 9288 | /* AV Load */ |
| 9289 | case 0x006: case 0x026: // lvsl, lvsr |
| 9290 | case 0x007: case 0x027: case 0x047: // lvebx, lvehx, lvewx |
| 9291 | case 0x067: case 0x167: // lvx, lvxl |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9292 | if (!allow_V) goto decode_noV; |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 9293 | if (dis_av_load( miscinfo, theInstr )) goto decode_success; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 9294 | goto decode_failure; |
| 9295 | |
| 9296 | /* AV Store */ |
| 9297 | case 0x087: case 0x0A7: case 0x0C7: // stvebx, stvehx, stvewx |
| 9298 | case 0x0E7: case 0x1E7: // stvx, stvxl |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9299 | if (!allow_V) goto decode_noV; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 9300 | if (dis_av_store( theInstr )) goto decode_success; |
| 9301 | goto decode_failure; |
| 9302 | |
| 9303 | default: |
| 9304 | goto decode_failure; |
| 9305 | } |
| 9306 | break; |
| 9307 | |
| 9308 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9309 | case 0x04: |
| 9310 | /* AltiVec instructions */ |
| 9311 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 9312 | opc2 = IFIELD(theInstr, 0, 6); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9313 | switch (opc2) { |
| 9314 | /* AV Mult-Add, Mult-Sum */ |
| 9315 | case 0x20: case 0x21: case 0x22: // vmhaddshs, vmhraddshs, vmladduhm |
| 9316 | case 0x24: case 0x25: case 0x26: // vmsumubm, vmsummbm, vmsumuhm |
| 9317 | case 0x27: case 0x28: case 0x29: // vmsumuhs, vmsumshm, vmsumshs |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9318 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9319 | if (dis_av_multarith( theInstr )) goto decode_success; |
| 9320 | goto decode_failure; |
| 9321 | |
| 9322 | /* AV Permutations */ |
| 9323 | case 0x2A: // vsel |
| 9324 | case 0x2B: // vperm |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9325 | case 0x2C: // vsldoi |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9326 | if (!allow_V) goto decode_noV; |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 9327 | if (dis_av_permute( theInstr )) goto decode_success; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9328 | goto decode_failure; |
| 9329 | |
| 9330 | /* AV Floating Point Mult-Add/Sub */ |
| 9331 | case 0x2E: case 0x2F: // vmaddfp, vnmsubfp |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9332 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9333 | if (dis_av_fp_arith( theInstr )) goto decode_success; |
| 9334 | goto decode_failure; |
| 9335 | |
| 9336 | default: |
| 9337 | break; // Fall through... |
| 9338 | } |
| 9339 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 9340 | opc2 = IFIELD(theInstr, 0, 11); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9341 | switch (opc2) { |
| 9342 | /* AV Arithmetic */ |
| 9343 | case 0x180: // vaddcuw |
| 9344 | case 0x000: case 0x040: case 0x080: // vaddubm, vadduhm, vadduwm |
| 9345 | case 0x200: case 0x240: case 0x280: // vaddubs, vadduhs, vadduws |
| 9346 | case 0x300: case 0x340: case 0x380: // vaddsbs, vaddshs, vaddsws |
| 9347 | case 0x580: // vsubcuw |
| 9348 | case 0x400: case 0x440: case 0x480: // vsububm, vsubuhm, vsubuwm |
| 9349 | case 0x600: case 0x640: case 0x680: // vsububs, vsubuhs, vsubuws |
| 9350 | case 0x700: case 0x740: case 0x780: // vsubsbs, vsubshs, vsubsws |
| 9351 | case 0x402: case 0x442: case 0x482: // vavgub, vavguh, vavguw |
| 9352 | case 0x502: case 0x542: case 0x582: // vavgsb, vavgsh, vavgsw |
| 9353 | case 0x002: case 0x042: case 0x082: // vmaxub, vmaxuh, vmaxuw |
| 9354 | case 0x102: case 0x142: case 0x182: // vmaxsb, vmaxsh, vmaxsw |
| 9355 | case 0x202: case 0x242: case 0x282: // vminub, vminuh, vminuw |
| 9356 | case 0x302: case 0x342: case 0x382: // vminsb, vminsh, vminsw |
| 9357 | case 0x008: case 0x048: // vmuloub, vmulouh |
| 9358 | case 0x108: case 0x148: // vmulosb, vmulosh |
| 9359 | case 0x208: case 0x248: // vmuleub, vmuleuh |
| 9360 | case 0x308: case 0x348: // vmulesb, vmulesh |
| 9361 | case 0x608: case 0x708: case 0x648: // vsum4ubs, vsum4sbs, vsum4shs |
| 9362 | case 0x688: case 0x788: // vsum2sws, vsumsws |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9363 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9364 | if (dis_av_arith( theInstr )) goto decode_success; |
| 9365 | goto decode_failure; |
| 9366 | |
| 9367 | /* AV Rotate, Shift */ |
| 9368 | case 0x004: case 0x044: case 0x084: // vrlb, vrlh, vrlw |
| 9369 | case 0x104: case 0x144: case 0x184: // vslb, vslh, vslw |
| 9370 | case 0x204: case 0x244: case 0x284: // vsrb, vsrh, vsrw |
| 9371 | case 0x304: case 0x344: case 0x384: // vsrab, vsrah, vsraw |
| 9372 | case 0x1C4: case 0x2C4: // vsl, vsr |
| 9373 | case 0x40C: case 0x44C: // vslo, vsro |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9374 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9375 | if (dis_av_shift( theInstr )) goto decode_success; |
| 9376 | goto decode_failure; |
| 9377 | |
| 9378 | /* AV Logic */ |
| 9379 | case 0x404: case 0x444: case 0x484: // vand, vandc, vor |
| 9380 | case 0x4C4: case 0x504: // vxor, vnor |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9381 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9382 | if (dis_av_logic( theInstr )) goto decode_success; |
| 9383 | goto decode_failure; |
| 9384 | |
| 9385 | /* AV Processor Control */ |
| 9386 | case 0x604: case 0x644: // mfvscr, mtvscr |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9387 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9388 | if (dis_av_procctl( theInstr )) goto decode_success; |
| 9389 | goto decode_failure; |
| 9390 | |
| 9391 | /* AV Floating Point Arithmetic */ |
| 9392 | case 0x00A: case 0x04A: // vaddfp, vsubfp |
| 9393 | case 0x10A: case 0x14A: case 0x18A: // vrefp, vrsqrtefp, vexptefp |
| 9394 | case 0x1CA: // vlogefp |
| 9395 | case 0x40A: case 0x44A: // vmaxfp, vminfp |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9396 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9397 | if (dis_av_fp_arith( theInstr )) goto decode_success; |
| 9398 | goto decode_failure; |
| 9399 | |
| 9400 | /* AV Floating Point Round/Convert */ |
| 9401 | case 0x20A: case 0x24A: case 0x28A: // vrfin, vrfiz, vrfip |
| 9402 | case 0x2CA: // vrfim |
| 9403 | case 0x30A: case 0x34A: case 0x38A: // vcfux, vcfsx, vctuxs |
| 9404 | case 0x3CA: // vctsxs |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9405 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9406 | if (dis_av_fp_convert( theInstr )) goto decode_success; |
| 9407 | goto decode_failure; |
| 9408 | |
| 9409 | /* AV Merge, Splat */ |
| 9410 | case 0x00C: case 0x04C: case 0x08C: // vmrghb, vmrghh, vmrghw |
| 9411 | case 0x10C: case 0x14C: case 0x18C: // vmrglb, vmrglh, vmrglw |
| 9412 | case 0x20C: case 0x24C: case 0x28C: // vspltb, vsplth, vspltw |
| 9413 | case 0x30C: case 0x34C: case 0x38C: // vspltisb, vspltish, vspltisw |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9414 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9415 | if (dis_av_permute( theInstr )) goto decode_success; |
| 9416 | goto decode_failure; |
| 9417 | |
| 9418 | /* AV Pack, Unpack */ |
| 9419 | case 0x00E: case 0x04E: case 0x08E: // vpkuhum, vpkuwum, vpkuhus |
| 9420 | case 0x0CE: // vpkuwus |
| 9421 | case 0x10E: case 0x14E: case 0x18E: // vpkshus, vpkswus, vpkshss |
| 9422 | case 0x1CE: // vpkswss |
| 9423 | case 0x20E: case 0x24E: case 0x28E: // vupkhsb, vupkhsh, vupklsb |
| 9424 | case 0x2CE: // vupklsh |
| 9425 | case 0x30E: case 0x34E: case 0x3CE: // vpkpx, vupkhpx, vupklpx |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9426 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9427 | if (dis_av_pack( theInstr )) goto decode_success; |
| 9428 | goto decode_failure; |
| 9429 | |
| 9430 | default: |
| 9431 | break; // Fall through... |
| 9432 | } |
| 9433 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 9434 | opc2 = IFIELD(theInstr, 0, 10); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9435 | switch (opc2) { |
| 9436 | |
| 9437 | /* AV Compare */ |
| 9438 | case 0x006: case 0x046: case 0x086: // vcmpequb, vcmpequh, vcmpequw |
| 9439 | case 0x206: case 0x246: case 0x286: // vcmpgtub, vcmpgtuh, vcmpgtuw |
| 9440 | case 0x306: case 0x346: case 0x386: // vcmpgtsb, vcmpgtsh, vcmpgtsw |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9441 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9442 | if (dis_av_cmp( theInstr )) goto decode_success; |
| 9443 | goto decode_failure; |
| 9444 | |
| 9445 | /* AV Floating Point Compare */ |
| 9446 | case 0x0C6: case 0x1C6: case 0x2C6: // vcmpeqfp, vcmpgefp, vcmpgtfp |
| 9447 | case 0x3C6: // vcmpbfp |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9448 | if (!allow_V) goto decode_noV; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 9449 | if (dis_av_fp_cmp( theInstr )) goto decode_success; |
| 9450 | goto decode_failure; |
| 9451 | |
| 9452 | default: |
| 9453 | goto decode_failure; |
| 9454 | } |
| 9455 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 9456 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9457 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 9458 | goto decode_failure; |
| 9459 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9460 | decode_noF: |
| 9461 | vassert(!allow_F); |
| 9462 | vex_printf("disInstr(ppc): declined to decode an FP insn.\n"); |
| 9463 | goto decode_failure; |
| 9464 | decode_noV: |
| 9465 | vassert(!allow_V); |
| 9466 | vex_printf("disInstr(ppc): declined to decode an AltiVec insn.\n"); |
| 9467 | goto decode_failure; |
| 9468 | decode_noFX: |
sewardj | 7c54586 | 2006-01-27 21:52:19 +0000 | [diff] [blame] | 9469 | vassert(!allow_FX); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9470 | vex_printf("disInstr(ppc): " |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 9471 | "declined to decode a GeneralPurpose-Optional insn.\n"); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9472 | goto decode_failure; |
| 9473 | decode_noGX: |
sewardj | 7c54586 | 2006-01-27 21:52:19 +0000 | [diff] [blame] | 9474 | vassert(!allow_GX); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9475 | vex_printf("disInstr(ppc): " |
| 9476 | "declined to decode a Graphics-Optional insn.\n"); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 9477 | goto decode_failure; |
| 9478 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9479 | decode_failure: |
| 9480 | /* All decode failures end up here. */ |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 9481 | opc2 = (theInstr) & 0x7FF; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 9482 | vex_printf("disInstr(ppc): unhandled instruction: " |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9483 | "0x%x\n", theInstr); |
sewardj | c7cd214 | 2005-09-09 22:31:49 +0000 | [diff] [blame] | 9484 | vex_printf(" primary %d(0x%x), secondary %u(0x%x)\n", |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 9485 | opc1, opc1, opc2, opc2); |
cerion | 995bc36 | 2005-02-03 11:03:31 +0000 | [diff] [blame] | 9486 | |
sewardj | 01a9e80 | 2005-02-01 20:46:00 +0000 | [diff] [blame] | 9487 | /* Tell the dispatcher that this insn cannot be decoded, and so has |
| 9488 | not been executed, and (is currently) the next to be executed. |
| 9489 | CIA should be up-to-date since it made so at the start of each |
| 9490 | insn, but nevertheless be paranoid and update it again right |
| 9491 | now. */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 9492 | putGST( PPC_GST_CIA, mkSzImm(ty, guest_CIA_curr_instr) ); |
| 9493 | irbb->next = mkSzImm(ty, guest_CIA_curr_instr); |
sewardj | 01a9e80 | 2005-02-01 20:46:00 +0000 | [diff] [blame] | 9494 | irbb->jumpkind = Ijk_NoDecode; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9495 | dres.whatNext = Dis_StopHere; |
| 9496 | dres.len = 0; |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 9497 | return dres; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9498 | |
| 9499 | } /* switch (opc) for the main (primary) opcode switch. */ |
| 9500 | |
| 9501 | decode_success: |
| 9502 | /* All decode successes end up here. */ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9503 | DIP("\n"); |
| 9504 | |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 9505 | if (dres.len == 0) { |
| 9506 | dres.len = 4; |
| 9507 | } else { |
| 9508 | vassert(dres.len == 20); |
| 9509 | } |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 9510 | return dres; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9511 | } |
| 9512 | |
| 9513 | #undef DIP |
| 9514 | #undef DIS |
| 9515 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 9516 | |
| 9517 | /*------------------------------------------------------------*/ |
| 9518 | /*--- Top-level fn ---*/ |
| 9519 | /*------------------------------------------------------------*/ |
| 9520 | |
| 9521 | /* Disassemble a single instruction into IR. The instruction |
| 9522 | is located in host memory at &guest_code[delta]. */ |
| 9523 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 9524 | DisResult disInstr_PPC ( IRBB* irbb_IN, |
| 9525 | Bool put_IP, |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 9526 | Bool (*resteerOkFn) ( void*, Addr64 ), |
| 9527 | void* callback_opaque, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 9528 | UChar* guest_code_IN, |
| 9529 | Long delta, |
| 9530 | Addr64 guest_IP, |
sewardj | a5f55da | 2006-04-30 23:37:32 +0000 | [diff] [blame] | 9531 | VexArch guest_arch, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 9532 | VexArchInfo* archinfo, |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 9533 | VexMiscInfo* miscinfo, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 9534 | Bool host_bigendian_IN ) |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 9535 | { |
sewardj | 5df65bb | 2005-11-29 14:47:04 +0000 | [diff] [blame] | 9536 | IRType ty; |
| 9537 | DisResult dres; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9538 | UInt mask32, mask64; |
| 9539 | UInt hwcaps_guest = archinfo->hwcaps; |
| 9540 | |
sewardj | a5f55da | 2006-04-30 23:37:32 +0000 | [diff] [blame] | 9541 | vassert(guest_arch == VexArchPPC32 || guest_arch == VexArchPPC64); |
sewardj | 5df65bb | 2005-11-29 14:47:04 +0000 | [diff] [blame] | 9542 | |
sewardj | a5f55da | 2006-04-30 23:37:32 +0000 | [diff] [blame] | 9543 | /* global -- ick */ |
| 9544 | mode64 = guest_arch == VexArchPPC64; |
| 9545 | ty = mode64 ? Ity_I64 : Ity_I32; |
| 9546 | |
| 9547 | /* do some sanity checks */ |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9548 | mask32 = VEX_HWCAPS_PPC32_F | VEX_HWCAPS_PPC32_V |
| 9549 | | VEX_HWCAPS_PPC32_FX | VEX_HWCAPS_PPC32_GX; |
| 9550 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 9551 | mask64 = VEX_HWCAPS_PPC64_V |
| 9552 | | VEX_HWCAPS_PPC64_FX | VEX_HWCAPS_PPC64_GX; |
| 9553 | |
sewardj | a5f55da | 2006-04-30 23:37:32 +0000 | [diff] [blame] | 9554 | if (mode64) { |
| 9555 | vassert((hwcaps_guest & mask32) == 0); |
| 9556 | } else { |
| 9557 | vassert((hwcaps_guest & mask64) == 0); |
| 9558 | } |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 9559 | |
| 9560 | /* Set globals (see top of this file) */ |
| 9561 | guest_code = guest_code_IN; |
| 9562 | irbb = irbb_IN; |
| 9563 | host_is_bigendian = host_bigendian_IN; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 9564 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 9565 | guest_CIA_curr_instr = mkSzAddr(ty, guest_IP); |
| 9566 | guest_CIA_bbstart = mkSzAddr(ty, guest_IP - delta); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 9567 | |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 9568 | dres = disInstr_PPC_WRK ( put_IP, resteerOkFn, callback_opaque, |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 9569 | delta, archinfo, miscinfo ); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 9570 | |
| 9571 | return dres; |
| 9572 | } |
| 9573 | |
| 9574 | |
sewardj | c808ef7 | 2005-08-18 11:50:43 +0000 | [diff] [blame] | 9575 | /*------------------------------------------------------------*/ |
| 9576 | /*--- Unused stuff ---*/ |
| 9577 | /*------------------------------------------------------------*/ |
| 9578 | |
| 9579 | ///* A potentially more memcheck-friendly implementation of Clz32, with |
| 9580 | // the boundary case Clz32(0) = 32, which is what ppc requires. */ |
| 9581 | // |
| 9582 | //static IRExpr* /* :: Ity_I32 */ verbose_Clz32 ( IRTemp arg ) |
| 9583 | //{ |
| 9584 | // /* Welcome ... to SSA R Us. */ |
| 9585 | // IRTemp n1 = newTemp(Ity_I32); |
| 9586 | // IRTemp n2 = newTemp(Ity_I32); |
| 9587 | // IRTemp n3 = newTemp(Ity_I32); |
| 9588 | // IRTemp n4 = newTemp(Ity_I32); |
| 9589 | // IRTemp n5 = newTemp(Ity_I32); |
| 9590 | // IRTemp n6 = newTemp(Ity_I32); |
| 9591 | // IRTemp n7 = newTemp(Ity_I32); |
| 9592 | // IRTemp n8 = newTemp(Ity_I32); |
| 9593 | // IRTemp n9 = newTemp(Ity_I32); |
| 9594 | // IRTemp n10 = newTemp(Ity_I32); |
| 9595 | // IRTemp n11 = newTemp(Ity_I32); |
| 9596 | // IRTemp n12 = newTemp(Ity_I32); |
| 9597 | // |
| 9598 | // /* First, propagate the most significant 1-bit into all lower |
| 9599 | // positions in the word. */ |
| 9600 | // /* unsigned int clz ( unsigned int n ) |
| 9601 | // { |
| 9602 | // n |= (n >> 1); |
| 9603 | // n |= (n >> 2); |
| 9604 | // n |= (n >> 4); |
| 9605 | // n |= (n >> 8); |
| 9606 | // n |= (n >> 16); |
| 9607 | // return bitcount(~n); |
| 9608 | // } |
| 9609 | // */ |
| 9610 | // assign(n1, mkexpr(arg)); |
| 9611 | // assign(n2, binop(Iop_Or32, mkexpr(n1), binop(Iop_Shr32, mkexpr(n1), mkU8(1)))); |
| 9612 | // assign(n3, binop(Iop_Or32, mkexpr(n2), binop(Iop_Shr32, mkexpr(n2), mkU8(2)))); |
| 9613 | // assign(n4, binop(Iop_Or32, mkexpr(n3), binop(Iop_Shr32, mkexpr(n3), mkU8(4)))); |
| 9614 | // assign(n5, binop(Iop_Or32, mkexpr(n4), binop(Iop_Shr32, mkexpr(n4), mkU8(8)))); |
| 9615 | // assign(n6, binop(Iop_Or32, mkexpr(n5), binop(Iop_Shr32, mkexpr(n5), mkU8(16)))); |
| 9616 | // /* This gives a word of the form 0---01---1. Now invert it, giving |
| 9617 | // a word of the form 1---10---0, then do a population-count idiom |
| 9618 | // (to count the 1s, which is the number of leading zeroes, or 32 |
| 9619 | // if the original word was 0. */ |
| 9620 | // assign(n7, unop(Iop_Not32, mkexpr(n6))); |
| 9621 | // |
| 9622 | // /* unsigned int bitcount ( unsigned int n ) |
| 9623 | // { |
| 9624 | // n = n - ((n >> 1) & 0x55555555); |
| 9625 | // n = (n & 0x33333333) + ((n >> 2) & 0x33333333); |
| 9626 | // n = (n + (n >> 4)) & 0x0F0F0F0F; |
| 9627 | // n = n + (n >> 8); |
| 9628 | // n = (n + (n >> 16)) & 0x3F; |
| 9629 | // return n; |
| 9630 | // } |
| 9631 | // */ |
| 9632 | // assign(n8, |
| 9633 | // binop(Iop_Sub32, |
| 9634 | // mkexpr(n7), |
| 9635 | // binop(Iop_And32, |
| 9636 | // binop(Iop_Shr32, mkexpr(n7), mkU8(1)), |
| 9637 | // mkU32(0x55555555)))); |
| 9638 | // assign(n9, |
| 9639 | // binop(Iop_Add32, |
| 9640 | // binop(Iop_And32, mkexpr(n8), mkU32(0x33333333)), |
| 9641 | // binop(Iop_And32, |
| 9642 | // binop(Iop_Shr32, mkexpr(n8), mkU8(2)), |
| 9643 | // mkU32(0x33333333)))); |
| 9644 | // assign(n10, |
| 9645 | // binop(Iop_And32, |
| 9646 | // binop(Iop_Add32, |
| 9647 | // mkexpr(n9), |
| 9648 | // binop(Iop_Shr32, mkexpr(n9), mkU8(4))), |
| 9649 | // mkU32(0x0F0F0F0F))); |
| 9650 | // assign(n11, |
| 9651 | // binop(Iop_Add32, |
| 9652 | // mkexpr(n10), |
| 9653 | // binop(Iop_Shr32, mkexpr(n10), mkU8(8)))); |
| 9654 | // assign(n12, |
| 9655 | // binop(Iop_Add32, |
| 9656 | // mkexpr(n11), |
| 9657 | // binop(Iop_Shr32, mkexpr(n11), mkU8(16)))); |
| 9658 | // return |
| 9659 | // binop(Iop_And32, mkexpr(n12), mkU32(0x3F)); |
| 9660 | //} |
| 9661 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9662 | /*--------------------------------------------------------------------*/ |
cerion | d0eae2d | 2005-12-23 11:43:01 +0000 | [diff] [blame] | 9663 | /*--- end guest-ppc/toIR.c ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9664 | /*--------------------------------------------------------------------*/ |