sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 3 | /*--- begin main_main.c ---*/ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 4 | /*---------------------------------------------------------------*/ |
| 5 | |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 6 | /* |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 9 | |
sewardj | 89ae847 | 2013-10-18 14:12:58 +0000 | [diff] [blame] | 10 | Copyright (C) 2004-2013 OpenWorks LLP |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 11 | info@open-works.net |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 12 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 17 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 26 | 02110-1301, USA. |
| 27 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 29 | |
| 30 | Neither the names of the U.S. Department of Energy nor the |
| 31 | University of California nor the names of its contributors may be |
| 32 | used to endorse or promote products derived from this software |
| 33 | without prior written permission. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 36 | #include "libvex.h" |
florian | 33b0243 | 2012-08-25 21:48:04 +0000 | [diff] [blame] | 37 | #include "libvex_emnote.h" |
sewardj | 81ec418 | 2004-10-25 23:15:52 +0000 | [diff] [blame] | 38 | #include "libvex_guest_x86.h" |
sewardj | 44d494d | 2005-01-20 20:26:33 +0000 | [diff] [blame] | 39 | #include "libvex_guest_amd64.h" |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 40 | #include "libvex_guest_arm.h" |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 41 | #include "libvex_guest_arm64.h" |
cerion | aabdfbf | 2005-01-29 12:56:15 +0000 | [diff] [blame] | 42 | #include "libvex_guest_ppc32.h" |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 43 | #include "libvex_guest_ppc64.h" |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 44 | #include "libvex_guest_s390x.h" |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 45 | #include "libvex_guest_mips32.h" |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 46 | #include "libvex_guest_mips64.h" |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 47 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 48 | #include "main_globals.h" |
| 49 | #include "main_util.h" |
| 50 | #include "host_generic_regs.h" |
| 51 | #include "ir_opt.h" |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 52 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 53 | #include "host_x86_defs.h" |
| 54 | #include "host_amd64_defs.h" |
| 55 | #include "host_ppc_defs.h" |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 56 | #include "host_arm_defs.h" |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 57 | #include "host_arm64_defs.h" |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 58 | #include "host_s390_defs.h" |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 59 | #include "host_mips_defs.h" |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 60 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 61 | #include "guest_generic_bb_to_IR.h" |
| 62 | #include "guest_x86_defs.h" |
| 63 | #include "guest_amd64_defs.h" |
| 64 | #include "guest_arm_defs.h" |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 65 | #include "guest_arm64_defs.h" |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 66 | #include "guest_ppc_defs.h" |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 67 | #include "guest_s390_defs.h" |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 68 | #include "guest_mips_defs.h" |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 69 | |
sewardj | 69d98e3 | 2010-06-18 08:17:41 +0000 | [diff] [blame] | 70 | #include "host_generic_simd128.h" |
| 71 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 72 | |
| 73 | /* This file contains the top level interface to the library. */ |
| 74 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 75 | /* --------- fwds ... --------- */ |
| 76 | |
| 77 | static Bool are_valid_hwcaps ( VexArch arch, UInt hwcaps ); |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 78 | static const HChar* show_hwcaps ( VexArch arch, UInt hwcaps ); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 79 | |
| 80 | |
sewardj | 8bde7f1 | 2013-04-11 13:57:43 +0000 | [diff] [blame] | 81 | /* --------- helpers --------- */ |
| 82 | |
| 83 | __attribute__((noinline)) |
| 84 | static UInt udiv32 ( UInt x, UInt y ) { return x/y; } |
| 85 | __attribute__((noinline)) |
| 86 | static Int sdiv32 ( Int x, Int y ) { return x/y; } |
| 87 | |
| 88 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 89 | /* --------- Initialise the library. --------- */ |
| 90 | |
| 91 | /* Exported to library client. */ |
| 92 | |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame] | 93 | void LibVEX_default_VexControl ( /*OUT*/ VexControl* vcon ) |
| 94 | { |
sewardj | 6590299 | 2014-05-03 21:20:56 +0000 | [diff] [blame] | 95 | vex_bzero(vcon, sizeof(*vcon)); |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame] | 96 | vcon->iropt_verbosity = 0; |
| 97 | vcon->iropt_level = 2; |
philippe | c8e2f98 | 2012-08-01 22:04:13 +0000 | [diff] [blame] | 98 | vcon->iropt_register_updates = VexRegUpdUnwindregsAtMemAccess; |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame] | 99 | vcon->iropt_unroll_thresh = 120; |
sewardj | 18b4bb7 | 2005-03-29 21:32:41 +0000 | [diff] [blame] | 100 | vcon->guest_max_insns = 60; |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame] | 101 | vcon->guest_chase_thresh = 10; |
sewardj | 984d9b1 | 2010-01-15 10:53:21 +0000 | [diff] [blame] | 102 | vcon->guest_chase_cond = False; |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
| 106 | /* Exported to library client. */ |
| 107 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 108 | void LibVEX_Init ( |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 109 | /* failure exit function */ |
sewardj | 2b51587 | 2004-07-05 20:50:45 +0000 | [diff] [blame] | 110 | __attribute__ ((noreturn)) |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 111 | void (*failure_exit) ( void ), |
| 112 | /* logging output function */ |
sewardj | d976362 | 2005-02-07 03:12:19 +0000 | [diff] [blame] | 113 | void (*log_bytes) ( HChar*, Int nbytes ), |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 114 | /* debug paranoia level */ |
| 115 | Int debuglevel, |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 116 | /* Are we supporting valgrind checking? */ |
| 117 | Bool valgrind_support, |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame] | 118 | /* Control ... */ |
| 119 | /*READONLY*/VexControl* vcon |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 120 | ) |
| 121 | { |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame] | 122 | /* First off, do enough minimal setup so that the following |
| 123 | assertions can fail in a sane fashion, if need be. */ |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 124 | vex_failure_exit = failure_exit; |
| 125 | vex_log_bytes = log_bytes; |
| 126 | |
| 127 | /* Now it's safe to check parameters for sanity. */ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 128 | vassert(!vex_initdone); |
| 129 | vassert(failure_exit); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 130 | vassert(log_bytes); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 131 | vassert(debuglevel >= 0); |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame] | 132 | |
| 133 | vassert(vcon->iropt_verbosity >= 0); |
| 134 | vassert(vcon->iropt_level >= 0); |
| 135 | vassert(vcon->iropt_level <= 2); |
| 136 | vassert(vcon->iropt_unroll_thresh >= 0); |
| 137 | vassert(vcon->iropt_unroll_thresh <= 400); |
| 138 | vassert(vcon->guest_max_insns >= 1); |
| 139 | vassert(vcon->guest_max_insns <= 100); |
| 140 | vassert(vcon->guest_chase_thresh >= 0); |
| 141 | vassert(vcon->guest_chase_thresh < vcon->guest_max_insns); |
sewardj | 984d9b1 | 2010-01-15 10:53:21 +0000 | [diff] [blame] | 142 | vassert(vcon->guest_chase_cond == True |
| 143 | || vcon->guest_chase_cond == False); |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 144 | |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 145 | /* Check that Vex has been built with sizes of basic types as |
| 146 | stated in priv/libvex_basictypes.h. Failure of any of these is |
| 147 | a serious configuration error and should be corrected |
| 148 | immediately. If any of these assertions fail you can fully |
| 149 | expect Vex not to work properly, if at all. */ |
| 150 | |
| 151 | vassert(1 == sizeof(UChar)); |
| 152 | vassert(1 == sizeof(Char)); |
| 153 | vassert(2 == sizeof(UShort)); |
| 154 | vassert(2 == sizeof(Short)); |
| 155 | vassert(4 == sizeof(UInt)); |
| 156 | vassert(4 == sizeof(Int)); |
| 157 | vassert(8 == sizeof(ULong)); |
| 158 | vassert(8 == sizeof(Long)); |
| 159 | vassert(4 == sizeof(Float)); |
| 160 | vassert(8 == sizeof(Double)); |
| 161 | vassert(1 == sizeof(Bool)); |
| 162 | vassert(4 == sizeof(Addr32)); |
| 163 | vassert(8 == sizeof(Addr64)); |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 164 | vassert(16 == sizeof(U128)); |
sewardj | 69d98e3 | 2010-06-18 08:17:41 +0000 | [diff] [blame] | 165 | vassert(16 == sizeof(V128)); |
sewardj | c9069f2 | 2012-06-01 16:09:50 +0000 | [diff] [blame] | 166 | vassert(32 == sizeof(U256)); |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 167 | |
| 168 | vassert(sizeof(void*) == 4 || sizeof(void*) == 8); |
| 169 | vassert(sizeof(void*) == sizeof(int*)); |
| 170 | vassert(sizeof(void*) == sizeof(HWord)); |
| 171 | |
sewardj | 97e8793 | 2005-02-07 00:00:50 +0000 | [diff] [blame] | 172 | vassert(VEX_HOST_WORDSIZE == sizeof(void*)); |
| 173 | vassert(VEX_HOST_WORDSIZE == sizeof(HWord)); |
| 174 | |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 175 | /* These take a lot of space, so make sure we don't have |
| 176 | any unnoticed size regressions. */ |
| 177 | if (VEX_HOST_WORDSIZE == 4) { |
florian | 420bfa9 | 2012-06-02 20:29:22 +0000 | [diff] [blame] | 178 | vassert(sizeof(IRExpr) == 16); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 179 | vassert(sizeof(IRStmt) == 20 /* x86 */ |
| 180 | || sizeof(IRStmt) == 24 /* arm */); |
| 181 | } else { |
florian | 420bfa9 | 2012-06-02 20:29:22 +0000 | [diff] [blame] | 182 | vassert(sizeof(IRExpr) == 32); |
florian | d6f38b3 | 2012-05-31 15:46:18 +0000 | [diff] [blame] | 183 | vassert(sizeof(IRStmt) == 32); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 184 | } |
| 185 | |
sewardj | 8bde7f1 | 2013-04-11 13:57:43 +0000 | [diff] [blame] | 186 | /* Check that signed integer division on the host rounds towards |
| 187 | zero. If not, h_calc_sdiv32_w_arm_semantics() won't work |
| 188 | correctly. */ |
| 189 | /* 100.0 / 7.0 == 14.2857 */ |
| 190 | vassert(udiv32(100, 7) == 14); |
| 191 | vassert(sdiv32(100, 7) == 14); |
| 192 | vassert(sdiv32(-100, 7) == -14); /* and not -15 */ |
| 193 | vassert(sdiv32(100, -7) == -14); /* ditto */ |
| 194 | vassert(sdiv32(-100, -7) == 14); /* not sure what this proves */ |
| 195 | |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 196 | /* Really start up .. */ |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 197 | vex_debuglevel = debuglevel; |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 198 | vex_valgrind_support = valgrind_support; |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame] | 199 | vex_control = *vcon; |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 200 | vex_initdone = True; |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 201 | vexSetAllocMode ( VexAllocModeTEMP ); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
| 205 | /* --------- Make a translation. --------- */ |
| 206 | |
| 207 | /* Exported to library client. */ |
| 208 | |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 209 | VexTranslateResult LibVEX_Translate ( VexTranslateArgs* vta ) |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 210 | { |
sewardj | 81bd550 | 2004-07-21 18:49:27 +0000 | [diff] [blame] | 211 | /* This the bundle of functions we need to do the back-end stuff |
| 212 | (insn selection, reg-alloc, assembly) whilst being insulated |
| 213 | from the target instruction set. */ |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 214 | HReg* available_real_regs; |
| 215 | Int n_available_real_regs; |
sewardj | fb7373a | 2007-08-25 21:29:03 +0000 | [diff] [blame] | 216 | Bool (*isMove) ( HInstr*, HReg*, HReg* ); |
| 217 | void (*getRegUsage) ( HRegUsage*, HInstr*, Bool ); |
| 218 | void (*mapRegs) ( HRegRemap*, HInstr*, Bool ); |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 219 | void (*genSpill) ( HInstr**, HInstr**, HReg, Int, Bool ); |
| 220 | void (*genReload) ( HInstr**, HInstr**, HReg, Int, Bool ); |
sewardj | fb7373a | 2007-08-25 21:29:03 +0000 | [diff] [blame] | 221 | HInstr* (*directReload) ( HInstr*, HReg, Short ); |
| 222 | void (*ppInstr) ( HInstr*, Bool ); |
| 223 | void (*ppReg) ( HReg ); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 224 | HInstrArray* (*iselSB) ( IRSB*, VexArch, VexArchInfo*, VexAbiInfo*, |
| 225 | Int, Int, Bool, Bool, Addr64 ); |
| 226 | Int (*emit) ( /*MB_MOD*/Bool*, |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 227 | UChar*, Int, HInstr*, Bool, VexEndness, |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 228 | void*, void*, void*, void* ); |
florian | 1ff4756 | 2012-10-21 02:09:51 +0000 | [diff] [blame] | 229 | IRExpr* (*specHelper) ( const HChar*, IRExpr**, IRStmt**, Int ); |
sewardj | 8d2291c | 2004-10-25 14:50:21 +0000 | [diff] [blame] | 230 | Bool (*preciseMemExnsFn) ( Int, Int ); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 231 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 232 | DisOneInstrFn disInstrFn; |
| 233 | |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 234 | VexGuestLayout* guest_layout; |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 235 | IRSB* irsb; |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 236 | HInstrArray* vcode; |
| 237 | HInstrArray* rcode; |
| 238 | Int i, j, k, out_used, guest_sizeB; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 239 | Int offB_CMSTART, offB_CMLEN, offB_GUEST_IP, szB_GUEST_IP; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 240 | Int offB_HOST_EvC_COUNTER, offB_HOST_EvC_FAILADDR; |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 241 | UChar insn_bytes[128]; |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 242 | IRType guest_word_type; |
| 243 | IRType host_word_type; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 244 | Bool mode64, chainingAllowed; |
| 245 | Addr64 max_ga; |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 246 | |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 247 | guest_layout = NULL; |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 248 | available_real_regs = NULL; |
| 249 | n_available_real_regs = 0; |
| 250 | isMove = NULL; |
| 251 | getRegUsage = NULL; |
| 252 | mapRegs = NULL; |
| 253 | genSpill = NULL; |
| 254 | genReload = NULL; |
sewardj | fb7373a | 2007-08-25 21:29:03 +0000 | [diff] [blame] | 255 | directReload = NULL; |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 256 | ppInstr = NULL; |
| 257 | ppReg = NULL; |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 258 | iselSB = NULL; |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 259 | emit = NULL; |
sewardj | 84ff065 | 2004-08-23 16:16:08 +0000 | [diff] [blame] | 260 | specHelper = NULL; |
sewardj | 8d2291c | 2004-10-25 14:50:21 +0000 | [diff] [blame] | 261 | preciseMemExnsFn = NULL; |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 262 | disInstrFn = NULL; |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 263 | guest_word_type = Ity_INVALID; |
| 264 | host_word_type = Ity_INVALID; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 265 | offB_CMSTART = 0; |
| 266 | offB_CMLEN = 0; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 267 | offB_GUEST_IP = 0; |
| 268 | szB_GUEST_IP = 0; |
| 269 | offB_HOST_EvC_COUNTER = 0; |
| 270 | offB_HOST_EvC_FAILADDR = 0; |
cerion | 92b6436 | 2005-12-13 12:02:26 +0000 | [diff] [blame] | 271 | mode64 = False; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 272 | chainingAllowed = False; |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 273 | |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 274 | vex_traceflags = vta->traceflags; |
sewardj | 58800ff | 2004-07-28 01:51:10 +0000 | [diff] [blame] | 275 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 276 | vassert(vex_initdone); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 277 | vassert(vta->needs_self_check != NULL); |
| 278 | vassert(vta->disp_cp_xassisted != NULL); |
| 279 | /* Both the chainers and the indir are either NULL or non-NULL. */ |
| 280 | if (vta->disp_cp_chain_me_to_slowEP != NULL) { |
| 281 | vassert(vta->disp_cp_chain_me_to_fastEP != NULL); |
| 282 | vassert(vta->disp_cp_xindir != NULL); |
| 283 | chainingAllowed = True; |
| 284 | } else { |
| 285 | vassert(vta->disp_cp_chain_me_to_fastEP == NULL); |
| 286 | vassert(vta->disp_cp_xindir == NULL); |
| 287 | } |
florian | 2eeeb9b | 2011-09-23 18:03:21 +0000 | [diff] [blame] | 288 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 289 | vexSetAllocModeTEMP_and_clear(); |
| 290 | vexAllocSanityCheck(); |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 291 | |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 292 | /* First off, check that the guest and host insn sets |
| 293 | are supported. */ |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 294 | |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 295 | switch (vta->arch_host) { |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 296 | |
sewardj | bef170b | 2004-12-21 01:23:00 +0000 | [diff] [blame] | 297 | case VexArchX86: |
sewardj | fb7373a | 2007-08-25 21:29:03 +0000 | [diff] [blame] | 298 | mode64 = False; |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 299 | getAllocableRegs_X86 ( &n_available_real_regs, |
| 300 | &available_real_regs ); |
sewardj | fb7373a | 2007-08-25 21:29:03 +0000 | [diff] [blame] | 301 | isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_X86Instr; |
sewardj | 2a1ed8e | 2009-12-31 19:26:03 +0000 | [diff] [blame] | 302 | getRegUsage = (void(*)(HRegUsage*,HInstr*, Bool)) |
| 303 | getRegUsage_X86Instr; |
sewardj | fb7373a | 2007-08-25 21:29:03 +0000 | [diff] [blame] | 304 | mapRegs = (void(*)(HRegRemap*,HInstr*, Bool)) mapRegs_X86Instr; |
sewardj | 2a1ed8e | 2009-12-31 19:26:03 +0000 | [diff] [blame] | 305 | genSpill = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) |
| 306 | genSpill_X86; |
| 307 | genReload = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) |
| 308 | genReload_X86; |
sewardj | fb7373a | 2007-08-25 21:29:03 +0000 | [diff] [blame] | 309 | directReload = (HInstr*(*)(HInstr*,HReg,Short)) directReload_X86; |
| 310 | ppInstr = (void(*)(HInstr*, Bool)) ppX86Instr; |
| 311 | ppReg = (void(*)(HReg)) ppHRegX86; |
| 312 | iselSB = iselSB_X86; |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 313 | emit = (Int(*)(Bool*,UChar*,Int,HInstr*,Bool,VexEndness, |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 314 | void*,void*,void*,void*)) |
sewardj | 010ac54 | 2011-05-29 09:29:18 +0000 | [diff] [blame] | 315 | emit_X86Instr; |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 316 | host_word_type = Ity_I32; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 317 | vassert(are_valid_hwcaps(VexArchX86, vta->archinfo_host.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 318 | vassert(vta->archinfo_host.endness == VexEndnessLE); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 319 | break; |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 320 | |
sewardj | c33671d | 2005-02-01 20:30:00 +0000 | [diff] [blame] | 321 | case VexArchAMD64: |
cerion | 92b6436 | 2005-12-13 12:02:26 +0000 | [diff] [blame] | 322 | mode64 = True; |
sewardj | c33671d | 2005-02-01 20:30:00 +0000 | [diff] [blame] | 323 | getAllocableRegs_AMD64 ( &n_available_real_regs, |
| 324 | &available_real_regs ); |
| 325 | isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_AMD64Instr; |
sewardj | 2a1ed8e | 2009-12-31 19:26:03 +0000 | [diff] [blame] | 326 | getRegUsage = (void(*)(HRegUsage*,HInstr*, Bool)) |
| 327 | getRegUsage_AMD64Instr; |
cerion | 92b6436 | 2005-12-13 12:02:26 +0000 | [diff] [blame] | 328 | mapRegs = (void(*)(HRegRemap*,HInstr*, Bool)) mapRegs_AMD64Instr; |
sewardj | 2a1ed8e | 2009-12-31 19:26:03 +0000 | [diff] [blame] | 329 | genSpill = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) |
| 330 | genSpill_AMD64; |
| 331 | genReload = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) |
| 332 | genReload_AMD64; |
cerion | 92b6436 | 2005-12-13 12:02:26 +0000 | [diff] [blame] | 333 | ppInstr = (void(*)(HInstr*, Bool)) ppAMD64Instr; |
sewardj | c33671d | 2005-02-01 20:30:00 +0000 | [diff] [blame] | 334 | ppReg = (void(*)(HReg)) ppHRegAMD64; |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 335 | iselSB = iselSB_AMD64; |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 336 | emit = (Int(*)(Bool*,UChar*,Int,HInstr*,Bool,VexEndness, |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 337 | void*,void*,void*,void*)) |
sewardj | 010ac54 | 2011-05-29 09:29:18 +0000 | [diff] [blame] | 338 | emit_AMD64Instr; |
sewardj | c33671d | 2005-02-01 20:30:00 +0000 | [diff] [blame] | 339 | host_word_type = Ity_I64; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 340 | vassert(are_valid_hwcaps(VexArchAMD64, vta->archinfo_host.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 341 | vassert(vta->archinfo_host.endness == VexEndnessLE); |
sewardj | c33671d | 2005-02-01 20:30:00 +0000 | [diff] [blame] | 342 | break; |
| 343 | |
cerion | 487e4c9 | 2005-02-04 16:28:19 +0000 | [diff] [blame] | 344 | case VexArchPPC32: |
cerion | 92b6436 | 2005-12-13 12:02:26 +0000 | [diff] [blame] | 345 | mode64 = False; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 346 | getAllocableRegs_PPC ( &n_available_real_regs, |
| 347 | &available_real_regs, mode64 ); |
| 348 | isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_PPCInstr; |
| 349 | getRegUsage = (void(*)(HRegUsage*,HInstr*,Bool)) getRegUsage_PPCInstr; |
| 350 | mapRegs = (void(*)(HRegRemap*,HInstr*,Bool)) mapRegs_PPCInstr; |
sewardj | 2a1ed8e | 2009-12-31 19:26:03 +0000 | [diff] [blame] | 351 | genSpill = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genSpill_PPC; |
| 352 | genReload = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genReload_PPC; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 353 | ppInstr = (void(*)(HInstr*,Bool)) ppPPCInstr; |
| 354 | ppReg = (void(*)(HReg)) ppHRegPPC; |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 355 | iselSB = iselSB_PPC; |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 356 | emit = (Int(*)(Bool*,UChar*,Int,HInstr*,Bool,VexEndness, |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 357 | void*,void*,void*,void*)) |
sewardj | 010ac54 | 2011-05-29 09:29:18 +0000 | [diff] [blame] | 358 | emit_PPCInstr; |
cerion | 487e4c9 | 2005-02-04 16:28:19 +0000 | [diff] [blame] | 359 | host_word_type = Ity_I32; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 360 | vassert(are_valid_hwcaps(VexArchPPC32, vta->archinfo_host.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 361 | vassert(vta->archinfo_host.endness == VexEndnessBE); |
cerion | 487e4c9 | 2005-02-04 16:28:19 +0000 | [diff] [blame] | 362 | break; |
| 363 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 364 | case VexArchPPC64: |
| 365 | mode64 = True; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 366 | getAllocableRegs_PPC ( &n_available_real_regs, |
| 367 | &available_real_regs, mode64 ); |
| 368 | isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_PPCInstr; |
| 369 | getRegUsage = (void(*)(HRegUsage*,HInstr*, Bool)) getRegUsage_PPCInstr; |
| 370 | mapRegs = (void(*)(HRegRemap*,HInstr*, Bool)) mapRegs_PPCInstr; |
sewardj | 2a1ed8e | 2009-12-31 19:26:03 +0000 | [diff] [blame] | 371 | genSpill = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genSpill_PPC; |
| 372 | genReload = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genReload_PPC; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 373 | ppInstr = (void(*)(HInstr*, Bool)) ppPPCInstr; |
| 374 | ppReg = (void(*)(HReg)) ppHRegPPC; |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 375 | iselSB = iselSB_PPC; |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 376 | emit = (Int(*)(Bool*,UChar*,Int,HInstr*,Bool,VexEndness, |
sewardj | 9e1cf15 | 2012-04-20 02:18:31 +0000 | [diff] [blame] | 377 | void*,void*,void*,void*)) |
sewardj | 010ac54 | 2011-05-29 09:29:18 +0000 | [diff] [blame] | 378 | emit_PPCInstr; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 379 | host_word_type = Ity_I64; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 380 | vassert(are_valid_hwcaps(VexArchPPC64, vta->archinfo_host.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 381 | vassert(vta->archinfo_host.endness == VexEndnessBE |
| 382 | /* later: || vta->archinfo_host.endness == VexEndnessLE */); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 383 | break; |
| 384 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 385 | case VexArchS390X: |
| 386 | mode64 = True; |
| 387 | getAllocableRegs_S390 ( &n_available_real_regs, |
| 388 | &available_real_regs, mode64 ); |
| 389 | isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_S390Instr; |
| 390 | getRegUsage = (void(*)(HRegUsage*,HInstr*, Bool)) getRegUsage_S390Instr; |
| 391 | mapRegs = (void(*)(HRegRemap*,HInstr*, Bool)) mapRegs_S390Instr; |
| 392 | genSpill = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genSpill_S390; |
| 393 | genReload = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genReload_S390; |
| 394 | ppInstr = (void(*)(HInstr*, Bool)) ppS390Instr; |
| 395 | ppReg = (void(*)(HReg)) ppHRegS390; |
| 396 | iselSB = iselSB_S390; |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 397 | emit = (Int(*)(Bool*,UChar*,Int,HInstr*,Bool,VexEndness, |
florian | 8844a63 | 2012-04-13 04:04:06 +0000 | [diff] [blame] | 398 | void*,void*,void*,void*)) emit_S390Instr; |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 399 | host_word_type = Ity_I64; |
| 400 | vassert(are_valid_hwcaps(VexArchS390X, vta->archinfo_host.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 401 | vassert(vta->archinfo_host.endness == VexEndnessBE); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 402 | break; |
| 403 | |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 404 | case VexArchARM: |
sewardj | 2a1ed8e | 2009-12-31 19:26:03 +0000 | [diff] [blame] | 405 | mode64 = False; |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 406 | getAllocableRegs_ARM ( &n_available_real_regs, |
| 407 | &available_real_regs ); |
sewardj | 2a1ed8e | 2009-12-31 19:26:03 +0000 | [diff] [blame] | 408 | isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_ARMInstr; |
| 409 | getRegUsage = (void(*)(HRegUsage*,HInstr*, Bool)) getRegUsage_ARMInstr; |
| 410 | mapRegs = (void(*)(HRegRemap*,HInstr*, Bool)) mapRegs_ARMInstr; |
| 411 | genSpill = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genSpill_ARM; |
| 412 | genReload = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genReload_ARM; |
| 413 | ppInstr = (void(*)(HInstr*, Bool)) ppARMInstr; |
| 414 | ppReg = (void(*)(HReg)) ppHRegARM; |
| 415 | iselSB = iselSB_ARM; |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 416 | emit = (Int(*)(Bool*,UChar*,Int,HInstr*,Bool,VexEndness, |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 417 | void*,void*,void*,void*)) |
sewardj | 010ac54 | 2011-05-29 09:29:18 +0000 | [diff] [blame] | 418 | emit_ARMInstr; |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 419 | host_word_type = Ity_I32; |
| 420 | vassert(are_valid_hwcaps(VexArchARM, vta->archinfo_host.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 421 | vassert(vta->archinfo_host.endness == VexEndnessLE); |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 422 | break; |
| 423 | |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 424 | case VexArchARM64: |
| 425 | mode64 = True; |
| 426 | getAllocableRegs_ARM64 ( &n_available_real_regs, |
| 427 | &available_real_regs ); |
| 428 | isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_ARM64Instr; |
| 429 | getRegUsage = (void(*)(HRegUsage*,HInstr*, Bool)) |
| 430 | getRegUsage_ARM64Instr; |
| 431 | mapRegs = (void(*)(HRegRemap*,HInstr*, Bool)) |
| 432 | mapRegs_ARM64Instr; |
| 433 | genSpill = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) |
| 434 | genSpill_ARM64; |
| 435 | genReload = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) |
| 436 | genReload_ARM64; |
| 437 | ppInstr = (void(*)(HInstr*, Bool)) ppARM64Instr; |
| 438 | ppReg = (void(*)(HReg)) ppHRegARM64; |
| 439 | iselSB = iselSB_ARM64; |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 440 | emit = (Int(*)(Bool*,UChar*,Int,HInstr*,Bool,VexEndness, |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 441 | void*,void*,void*,void*)) |
| 442 | emit_ARM64Instr; |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 443 | host_word_type = Ity_I64; |
| 444 | vassert(are_valid_hwcaps(VexArchARM64, vta->archinfo_host.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 445 | vassert(vta->archinfo_host.endness == VexEndnessLE); |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 446 | break; |
| 447 | |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 448 | case VexArchMIPS32: |
| 449 | mode64 = False; |
| 450 | getAllocableRegs_MIPS ( &n_available_real_regs, |
| 451 | &available_real_regs, mode64 ); |
| 452 | isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_MIPSInstr; |
| 453 | getRegUsage = (void(*)(HRegUsage*,HInstr*, Bool)) getRegUsage_MIPSInstr; |
| 454 | mapRegs = (void(*)(HRegRemap*,HInstr*, Bool)) mapRegs_MIPSInstr; |
| 455 | genSpill = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genSpill_MIPS; |
| 456 | genReload = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genReload_MIPS; |
| 457 | ppInstr = (void(*)(HInstr*, Bool)) ppMIPSInstr; |
| 458 | ppReg = (void(*)(HReg)) ppHRegMIPS; |
| 459 | iselSB = iselSB_MIPS; |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 460 | emit = (Int(*)(Bool*,UChar*,Int,HInstr*,Bool,VexEndness, |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 461 | void*,void*,void*,void*)) |
| 462 | emit_MIPSInstr; |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 463 | host_word_type = Ity_I32; |
| 464 | vassert(are_valid_hwcaps(VexArchMIPS32, vta->archinfo_host.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 465 | vassert(vta->archinfo_host.endness == VexEndnessLE |
| 466 | || vta->archinfo_host.endness == VexEndnessBE); |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 467 | break; |
| 468 | |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 469 | case VexArchMIPS64: |
| 470 | mode64 = True; |
| 471 | getAllocableRegs_MIPS ( &n_available_real_regs, |
| 472 | &available_real_regs, mode64 ); |
| 473 | isMove = (Bool(*)(HInstr*,HReg*,HReg*)) isMove_MIPSInstr; |
| 474 | getRegUsage = (void(*)(HRegUsage*,HInstr*, Bool)) getRegUsage_MIPSInstr; |
| 475 | mapRegs = (void(*)(HRegRemap*,HInstr*, Bool)) mapRegs_MIPSInstr; |
| 476 | genSpill = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genSpill_MIPS; |
| 477 | genReload = (void(*)(HInstr**,HInstr**,HReg,Int,Bool)) genReload_MIPS; |
| 478 | ppInstr = (void(*)(HInstr*, Bool)) ppMIPSInstr; |
| 479 | ppReg = (void(*)(HReg)) ppHRegMIPS; |
| 480 | iselSB = iselSB_MIPS; |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 481 | emit = (Int(*)(Bool*,UChar*,Int,HInstr*,Bool,VexEndness, |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 482 | void*,void*,void*,void*)) |
| 483 | emit_MIPSInstr; |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 484 | host_word_type = Ity_I64; |
| 485 | vassert(are_valid_hwcaps(VexArchMIPS64, vta->archinfo_host.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 486 | vassert(vta->archinfo_host.endness == VexEndnessLE |
| 487 | || vta->archinfo_host.endness == VexEndnessBE); |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 488 | break; |
| 489 | |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 490 | default: |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 491 | vpanic("LibVEX_Translate: unsupported host insn set"); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 492 | } |
| 493 | |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 494 | |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 495 | switch (vta->arch_guest) { |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 496 | |
sewardj | bef170b | 2004-12-21 01:23:00 +0000 | [diff] [blame] | 497 | case VexArchX86: |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 498 | preciseMemExnsFn = guest_x86_state_requires_precise_mem_exns; |
| 499 | disInstrFn = disInstr_X86; |
| 500 | specHelper = guest_x86_spechelper; |
| 501 | guest_sizeB = sizeof(VexGuestX86State); |
| 502 | guest_word_type = Ity_I32; |
| 503 | guest_layout = &x86guest_layout; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 504 | offB_CMSTART = offsetof(VexGuestX86State,guest_CMSTART); |
| 505 | offB_CMLEN = offsetof(VexGuestX86State,guest_CMLEN); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 506 | offB_GUEST_IP = offsetof(VexGuestX86State,guest_EIP); |
| 507 | szB_GUEST_IP = sizeof( ((VexGuestX86State*)0)->guest_EIP ); |
| 508 | offB_HOST_EvC_COUNTER = offsetof(VexGuestX86State,host_EvC_COUNTER); |
| 509 | offB_HOST_EvC_FAILADDR = offsetof(VexGuestX86State,host_EvC_FAILADDR); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 510 | vassert(are_valid_hwcaps(VexArchX86, vta->archinfo_guest.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 511 | vassert(vta->archinfo_guest.endness == VexEndnessLE); |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 512 | vassert(0 == sizeof(VexGuestX86State) % 16); |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 513 | vassert(sizeof( ((VexGuestX86State*)0)->guest_CMSTART) == 4); |
| 514 | vassert(sizeof( ((VexGuestX86State*)0)->guest_CMLEN ) == 4); |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 515 | vassert(sizeof( ((VexGuestX86State*)0)->guest_NRADDR ) == 4); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 516 | break; |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 517 | |
sewardj | 44d494d | 2005-01-20 20:26:33 +0000 | [diff] [blame] | 518 | case VexArchAMD64: |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 519 | preciseMemExnsFn = guest_amd64_state_requires_precise_mem_exns; |
| 520 | disInstrFn = disInstr_AMD64; |
| 521 | specHelper = guest_amd64_spechelper; |
| 522 | guest_sizeB = sizeof(VexGuestAMD64State); |
| 523 | guest_word_type = Ity_I64; |
| 524 | guest_layout = &amd64guest_layout; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 525 | offB_CMSTART = offsetof(VexGuestAMD64State,guest_CMSTART); |
| 526 | offB_CMLEN = offsetof(VexGuestAMD64State,guest_CMLEN); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 527 | offB_GUEST_IP = offsetof(VexGuestAMD64State,guest_RIP); |
| 528 | szB_GUEST_IP = sizeof( ((VexGuestAMD64State*)0)->guest_RIP ); |
| 529 | offB_HOST_EvC_COUNTER = offsetof(VexGuestAMD64State,host_EvC_COUNTER); |
| 530 | offB_HOST_EvC_FAILADDR = offsetof(VexGuestAMD64State,host_EvC_FAILADDR); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 531 | vassert(are_valid_hwcaps(VexArchAMD64, vta->archinfo_guest.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 532 | vassert(vta->archinfo_guest.endness == VexEndnessLE); |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 533 | vassert(0 == sizeof(VexGuestAMD64State) % 16); |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 534 | vassert(sizeof( ((VexGuestAMD64State*)0)->guest_CMSTART ) == 8); |
| 535 | vassert(sizeof( ((VexGuestAMD64State*)0)->guest_CMLEN ) == 8); |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 536 | vassert(sizeof( ((VexGuestAMD64State*)0)->guest_NRADDR ) == 8); |
sewardj | 44d494d | 2005-01-20 20:26:33 +0000 | [diff] [blame] | 537 | break; |
| 538 | |
cerion | aabdfbf | 2005-01-29 12:56:15 +0000 | [diff] [blame] | 539 | case VexArchPPC32: |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 540 | preciseMemExnsFn = guest_ppc32_state_requires_precise_mem_exns; |
| 541 | disInstrFn = disInstr_PPC; |
| 542 | specHelper = guest_ppc32_spechelper; |
| 543 | guest_sizeB = sizeof(VexGuestPPC32State); |
| 544 | guest_word_type = Ity_I32; |
| 545 | guest_layout = &ppc32Guest_layout; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 546 | offB_CMSTART = offsetof(VexGuestPPC32State,guest_CMSTART); |
| 547 | offB_CMLEN = offsetof(VexGuestPPC32State,guest_CMLEN); |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 548 | offB_GUEST_IP = offsetof(VexGuestPPC32State,guest_CIA); |
| 549 | szB_GUEST_IP = sizeof( ((VexGuestPPC32State*)0)->guest_CIA ); |
| 550 | offB_HOST_EvC_COUNTER = offsetof(VexGuestPPC32State,host_EvC_COUNTER); |
| 551 | offB_HOST_EvC_FAILADDR = offsetof(VexGuestPPC32State,host_EvC_FAILADDR); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 552 | vassert(are_valid_hwcaps(VexArchPPC32, vta->archinfo_guest.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 553 | vassert(vta->archinfo_guest.endness == VexEndnessBE); |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 554 | vassert(0 == sizeof(VexGuestPPC32State) % 16); |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 555 | vassert(sizeof( ((VexGuestPPC32State*)0)->guest_CMSTART ) == 4); |
| 556 | vassert(sizeof( ((VexGuestPPC32State*)0)->guest_CMLEN ) == 4); |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 557 | vassert(sizeof( ((VexGuestPPC32State*)0)->guest_NRADDR ) == 4); |
cerion | aabdfbf | 2005-01-29 12:56:15 +0000 | [diff] [blame] | 558 | break; |
| 559 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 560 | case VexArchPPC64: |
sewardj | 9e1cf15 | 2012-04-20 02:18:31 +0000 | [diff] [blame] | 561 | preciseMemExnsFn = guest_ppc64_state_requires_precise_mem_exns; |
| 562 | disInstrFn = disInstr_PPC; |
| 563 | specHelper = guest_ppc64_spechelper; |
| 564 | guest_sizeB = sizeof(VexGuestPPC64State); |
| 565 | guest_word_type = Ity_I64; |
| 566 | guest_layout = &ppc64Guest_layout; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 567 | offB_CMSTART = offsetof(VexGuestPPC64State,guest_CMSTART); |
| 568 | offB_CMLEN = offsetof(VexGuestPPC64State,guest_CMLEN); |
sewardj | 9e1cf15 | 2012-04-20 02:18:31 +0000 | [diff] [blame] | 569 | offB_GUEST_IP = offsetof(VexGuestPPC64State,guest_CIA); |
| 570 | szB_GUEST_IP = sizeof( ((VexGuestPPC64State*)0)->guest_CIA ); |
| 571 | offB_HOST_EvC_COUNTER = offsetof(VexGuestPPC64State,host_EvC_COUNTER); |
| 572 | offB_HOST_EvC_FAILADDR = offsetof(VexGuestPPC64State,host_EvC_FAILADDR); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 573 | vassert(are_valid_hwcaps(VexArchPPC64, vta->archinfo_guest.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 574 | vassert(vta->archinfo_guest.endness == VexEndnessBE |
| 575 | /* later: || vta->archinfo_guest.endness == VexEndnessBE */); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 576 | vassert(0 == sizeof(VexGuestPPC64State) % 16); |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 577 | vassert(sizeof( ((VexGuestPPC64State*)0)->guest_CMSTART ) == 8); |
| 578 | vassert(sizeof( ((VexGuestPPC64State*)0)->guest_CMLEN ) == 8); |
sewardj | 3fd3967 | 2006-01-27 22:05:55 +0000 | [diff] [blame] | 579 | vassert(sizeof( ((VexGuestPPC64State*)0)->guest_NRADDR ) == 8); |
| 580 | vassert(sizeof( ((VexGuestPPC64State*)0)->guest_NRADDR_GPR2) == 8); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 581 | break; |
| 582 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 583 | case VexArchS390X: |
| 584 | preciseMemExnsFn = guest_s390x_state_requires_precise_mem_exns; |
| 585 | disInstrFn = disInstr_S390; |
| 586 | specHelper = guest_s390x_spechelper; |
| 587 | guest_sizeB = sizeof(VexGuestS390XState); |
| 588 | guest_word_type = Ity_I64; |
| 589 | guest_layout = &s390xGuest_layout; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 590 | offB_CMSTART = offsetof(VexGuestS390XState,guest_CMSTART); |
| 591 | offB_CMLEN = offsetof(VexGuestS390XState,guest_CMLEN); |
florian | 8844a63 | 2012-04-13 04:04:06 +0000 | [diff] [blame] | 592 | offB_GUEST_IP = offsetof(VexGuestS390XState,guest_IA); |
| 593 | szB_GUEST_IP = sizeof( ((VexGuestS390XState*)0)->guest_IA); |
| 594 | offB_HOST_EvC_COUNTER = offsetof(VexGuestS390XState,host_EvC_COUNTER); |
| 595 | offB_HOST_EvC_FAILADDR = offsetof(VexGuestS390XState,host_EvC_FAILADDR); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 596 | vassert(are_valid_hwcaps(VexArchS390X, vta->archinfo_guest.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 597 | vassert(vta->archinfo_guest.endness == VexEndnessBE); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 598 | vassert(0 == sizeof(VexGuestS390XState) % 16); |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 599 | vassert(sizeof( ((VexGuestS390XState*)0)->guest_CMSTART ) == 8); |
| 600 | vassert(sizeof( ((VexGuestS390XState*)0)->guest_CMLEN ) == 8); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 601 | vassert(sizeof( ((VexGuestS390XState*)0)->guest_NRADDR ) == 8); |
| 602 | break; |
| 603 | |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 604 | case VexArchARM: |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 605 | preciseMemExnsFn = guest_arm_state_requires_precise_mem_exns; |
| 606 | disInstrFn = disInstr_ARM; |
| 607 | specHelper = guest_arm_spechelper; |
| 608 | guest_sizeB = sizeof(VexGuestARMState); |
| 609 | guest_word_type = Ity_I32; |
| 610 | guest_layout = &armGuest_layout; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 611 | offB_CMSTART = offsetof(VexGuestARMState,guest_CMSTART); |
| 612 | offB_CMLEN = offsetof(VexGuestARMState,guest_CMLEN); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 613 | offB_GUEST_IP = offsetof(VexGuestARMState,guest_R15T); |
| 614 | szB_GUEST_IP = sizeof( ((VexGuestARMState*)0)->guest_R15T ); |
| 615 | offB_HOST_EvC_COUNTER = offsetof(VexGuestARMState,host_EvC_COUNTER); |
| 616 | offB_HOST_EvC_FAILADDR = offsetof(VexGuestARMState,host_EvC_FAILADDR); |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 617 | vassert(are_valid_hwcaps(VexArchARM, vta->archinfo_guest.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 618 | vassert(vta->archinfo_guest.endness == VexEndnessLE); |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 619 | vassert(0 == sizeof(VexGuestARMState) % 16); |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 620 | vassert(sizeof( ((VexGuestARMState*)0)->guest_CMSTART) == 4); |
| 621 | vassert(sizeof( ((VexGuestARMState*)0)->guest_CMLEN ) == 4); |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 622 | vassert(sizeof( ((VexGuestARMState*)0)->guest_NRADDR ) == 4); |
| 623 | break; |
| 624 | |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 625 | case VexArchARM64: |
| 626 | preciseMemExnsFn = guest_arm64_state_requires_precise_mem_exns; |
| 627 | disInstrFn = disInstr_ARM64; |
| 628 | specHelper = guest_arm64_spechelper; |
| 629 | guest_sizeB = sizeof(VexGuestARM64State); |
| 630 | guest_word_type = Ity_I64; |
| 631 | guest_layout = &arm64Guest_layout; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 632 | offB_CMSTART = offsetof(VexGuestARM64State,guest_CMSTART); |
| 633 | offB_CMLEN = offsetof(VexGuestARM64State,guest_CMLEN); |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 634 | offB_GUEST_IP = offsetof(VexGuestARM64State,guest_PC); |
| 635 | szB_GUEST_IP = sizeof( ((VexGuestARM64State*)0)->guest_PC ); |
| 636 | offB_HOST_EvC_COUNTER = offsetof(VexGuestARM64State,host_EvC_COUNTER); |
| 637 | offB_HOST_EvC_FAILADDR = offsetof(VexGuestARM64State,host_EvC_FAILADDR); |
| 638 | vassert(are_valid_hwcaps(VexArchARM64, vta->archinfo_guest.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 639 | vassert(vta->archinfo_guest.endness == VexEndnessLE); |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 640 | vassert(0 == sizeof(VexGuestARM64State) % 16); |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 641 | vassert(sizeof( ((VexGuestARM64State*)0)->guest_CMSTART) == 8); |
| 642 | vassert(sizeof( ((VexGuestARM64State*)0)->guest_CMLEN ) == 8); |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 643 | vassert(sizeof( ((VexGuestARM64State*)0)->guest_NRADDR ) == 8); |
| 644 | break; |
| 645 | |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 646 | case VexArchMIPS32: |
| 647 | preciseMemExnsFn = guest_mips32_state_requires_precise_mem_exns; |
| 648 | disInstrFn = disInstr_MIPS; |
| 649 | specHelper = guest_mips32_spechelper; |
| 650 | guest_sizeB = sizeof(VexGuestMIPS32State); |
| 651 | guest_word_type = Ity_I32; |
| 652 | guest_layout = &mips32Guest_layout; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 653 | offB_CMSTART = offsetof(VexGuestMIPS32State,guest_CMSTART); |
| 654 | offB_CMLEN = offsetof(VexGuestMIPS32State,guest_CMLEN); |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 655 | offB_GUEST_IP = offsetof(VexGuestMIPS32State,guest_PC); |
| 656 | szB_GUEST_IP = sizeof( ((VexGuestMIPS32State*)0)->guest_PC ); |
| 657 | offB_HOST_EvC_COUNTER = offsetof(VexGuestMIPS32State,host_EvC_COUNTER); |
| 658 | offB_HOST_EvC_FAILADDR = offsetof(VexGuestMIPS32State,host_EvC_FAILADDR); |
| 659 | vassert(are_valid_hwcaps(VexArchMIPS32, vta->archinfo_guest.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 660 | vassert(vta->archinfo_guest.endness == VexEndnessLE |
| 661 | || vta->archinfo_guest.endness == VexEndnessBE); |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 662 | vassert(0 == sizeof(VexGuestMIPS32State) % 16); |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 663 | vassert(sizeof( ((VexGuestMIPS32State*)0)->guest_CMSTART) == 4); |
| 664 | vassert(sizeof( ((VexGuestMIPS32State*)0)->guest_CMLEN ) == 4); |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 665 | vassert(sizeof( ((VexGuestMIPS32State*)0)->guest_NRADDR ) == 4); |
| 666 | break; |
| 667 | |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 668 | case VexArchMIPS64: |
| 669 | preciseMemExnsFn = guest_mips64_state_requires_precise_mem_exns; |
| 670 | disInstrFn = disInstr_MIPS; |
| 671 | specHelper = guest_mips64_spechelper; |
| 672 | guest_sizeB = sizeof(VexGuestMIPS64State); |
| 673 | guest_word_type = Ity_I64; |
| 674 | guest_layout = &mips64Guest_layout; |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 675 | offB_CMSTART = offsetof(VexGuestMIPS64State,guest_CMSTART); |
| 676 | offB_CMLEN = offsetof(VexGuestMIPS64State,guest_CMLEN); |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 677 | offB_GUEST_IP = offsetof(VexGuestMIPS64State,guest_PC); |
| 678 | szB_GUEST_IP = sizeof( ((VexGuestMIPS64State*)0)->guest_PC ); |
| 679 | offB_HOST_EvC_COUNTER = offsetof(VexGuestMIPS64State,host_EvC_COUNTER); |
| 680 | offB_HOST_EvC_FAILADDR = offsetof(VexGuestMIPS64State,host_EvC_FAILADDR); |
| 681 | vassert(are_valid_hwcaps(VexArchMIPS64, vta->archinfo_guest.hwcaps)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 682 | vassert(vta->archinfo_guest.endness == VexEndnessLE |
| 683 | || vta->archinfo_guest.endness == VexEndnessBE); |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 684 | vassert(0 == sizeof(VexGuestMIPS64State) % 16); |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 685 | vassert(sizeof( ((VexGuestMIPS64State*)0)->guest_CMSTART) == 8); |
| 686 | vassert(sizeof( ((VexGuestMIPS64State*)0)->guest_CMLEN ) == 8); |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 687 | vassert(sizeof( ((VexGuestMIPS64State*)0)->guest_NRADDR ) == 8); |
| 688 | break; |
| 689 | |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 690 | default: |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 691 | vpanic("LibVEX_Translate: unsupported guest insn set"); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 692 | } |
| 693 | |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 694 | /* Set up result struct. */ |
| 695 | VexTranslateResult res; |
sewardj | fadbbe2 | 2012-04-24 11:49:03 +0000 | [diff] [blame] | 696 | res.status = VexTransOK; |
| 697 | res.n_sc_extents = 0; |
| 698 | res.offs_profInc = -1; |
| 699 | res.n_guest_instrs = 0; |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 700 | |
sewardj | 9df271d | 2004-12-31 22:37:42 +0000 | [diff] [blame] | 701 | /* yet more sanity checks ... */ |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 702 | if (vta->arch_guest == vta->arch_host) { |
sewardj | 9df271d | 2004-12-31 22:37:42 +0000 | [diff] [blame] | 703 | /* doesn't necessarily have to be true, but if it isn't it means |
sewardj | 0ec57c5 | 2005-02-01 15:24:10 +0000 | [diff] [blame] | 704 | we are simulating one flavour of an architecture a different |
| 705 | flavour of the same architecture, which is pretty strange. */ |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 706 | vassert(vta->archinfo_guest.hwcaps == vta->archinfo_host.hwcaps); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 707 | /* ditto */ |
| 708 | vassert(vta->archinfo_guest.endness == vta->archinfo_host.endness); |
sewardj | 9df271d | 2004-12-31 22:37:42 +0000 | [diff] [blame] | 709 | } |
sewardj | 2a9ad02 | 2004-11-25 02:46:58 +0000 | [diff] [blame] | 710 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 711 | vexAllocSanityCheck(); |
| 712 | |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 713 | if (vex_traceflags & VEX_TRACE_FE) |
| 714 | vex_printf("\n------------------------" |
| 715 | " Front end " |
| 716 | "------------------------\n\n"); |
| 717 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 718 | irsb = bb_to_IR ( vta->guest_extents, |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 719 | &res.n_sc_extents, |
sewardj | fadbbe2 | 2012-04-24 11:49:03 +0000 | [diff] [blame] | 720 | &res.n_guest_instrs, |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 721 | vta->callback_opaque, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 722 | disInstrFn, |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 723 | vta->guest_bytes, |
| 724 | vta->guest_bytes_addr, |
| 725 | vta->chase_into_ok, |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 726 | vta->archinfo_host.endness, |
sewardj | 442e51a | 2012-12-06 18:08:04 +0000 | [diff] [blame] | 727 | vta->sigill_diag, |
sewardj | a5f55da | 2006-04-30 23:37:32 +0000 | [diff] [blame] | 728 | vta->arch_guest, |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 729 | &vta->archinfo_guest, |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 730 | &vta->abiinfo_both, |
sewardj | db4738a | 2005-07-07 01:32:16 +0000 | [diff] [blame] | 731 | guest_word_type, |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 732 | vta->needs_self_check, |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 733 | vta->preamble_function, |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 734 | offB_CMSTART, |
| 735 | offB_CMLEN, |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 736 | offB_GUEST_IP, |
| 737 | szB_GUEST_IP ); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 738 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 739 | vexAllocSanityCheck(); |
| 740 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 741 | if (irsb == NULL) { |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 742 | /* Access failure. */ |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 743 | vexSetAllocModeTEMP_and_clear(); |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 744 | vex_traceflags = 0; |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 745 | res.status = VexTransAccessFail; return res; |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 746 | } |
sewardj | aa59f94 | 2004-10-09 09:34:36 +0000 | [diff] [blame] | 747 | |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 748 | vassert(vta->guest_extents->n_used >= 1 && vta->guest_extents->n_used <= 3); |
| 749 | vassert(vta->guest_extents->base[0] == vta->guest_bytes_addr); |
| 750 | for (i = 0; i < vta->guest_extents->n_used; i++) { |
| 751 | vassert(vta->guest_extents->len[i] < 10000); /* sanity */ |
sewardj | 72c7281 | 2005-01-19 11:49:45 +0000 | [diff] [blame] | 752 | } |
| 753 | |
sewardj | aa59f94 | 2004-10-09 09:34:36 +0000 | [diff] [blame] | 754 | /* If debugging, show the raw guest bytes for this bb. */ |
sewardj | 109ffdb | 2004-12-10 21:45:38 +0000 | [diff] [blame] | 755 | if (0 || (vex_traceflags & VEX_TRACE_FE)) { |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 756 | if (vta->guest_extents->n_used > 1) { |
sewardj | 72c7281 | 2005-01-19 11:49:45 +0000 | [diff] [blame] | 757 | vex_printf("can't show code due to extents > 1\n"); |
| 758 | } else { |
| 759 | /* HACK */ |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 760 | UChar* p = (UChar*)vta->guest_bytes; |
sewardj | 01f8cce | 2009-08-31 08:50:02 +0000 | [diff] [blame] | 761 | UInt sum = 0; |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 762 | UInt guest_bytes_read = (UInt)vta->guest_extents->len[0]; |
sewardj | 01f8cce | 2009-08-31 08:50:02 +0000 | [diff] [blame] | 763 | vex_printf("GuestBytes %llx %u ", vta->guest_bytes_addr, |
| 764 | guest_bytes_read ); |
| 765 | for (i = 0; i < guest_bytes_read; i++) { |
| 766 | UInt b = (UInt)p[i]; |
| 767 | vex_printf(" %02x", b ); |
| 768 | sum = (sum << 1) ^ b; |
| 769 | } |
| 770 | vex_printf(" %08x\n\n", sum); |
sewardj | 72c7281 | 2005-01-19 11:49:45 +0000 | [diff] [blame] | 771 | } |
sewardj | aa59f94 | 2004-10-09 09:34:36 +0000 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /* Sanity check the initial IR. */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 775 | sanityCheckIRSB( irsb, "initial IR", |
sewardj | b923075 | 2004-12-29 19:25:06 +0000 | [diff] [blame] | 776 | False/*can be non-flat*/, guest_word_type ); |
sewardj | e8e9d73 | 2004-07-16 21:03:45 +0000 | [diff] [blame] | 777 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 778 | vexAllocSanityCheck(); |
| 779 | |
sewardj | edf4d69 | 2004-08-17 13:52:58 +0000 | [diff] [blame] | 780 | /* Clean it up, hopefully a lot. */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 781 | irsb = do_iropt_BB ( irsb, specHelper, preciseMemExnsFn, |
sewardj | ec0d9a0 | 2010-08-22 12:54:56 +0000 | [diff] [blame] | 782 | vta->guest_bytes_addr, |
| 783 | vta->arch_guest ); |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 784 | sanityCheckIRSB( irsb, "after initial iropt", |
sewardj | b923075 | 2004-12-29 19:25:06 +0000 | [diff] [blame] | 785 | True/*must be flat*/, guest_word_type ); |
sewardj | edf4d69 | 2004-08-17 13:52:58 +0000 | [diff] [blame] | 786 | |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 787 | if (vex_traceflags & VEX_TRACE_OPT1) { |
| 788 | vex_printf("\n------------------------" |
| 789 | " After pre-instr IR optimisation " |
| 790 | "------------------------\n\n"); |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 791 | ppIRSB ( irsb ); |
sewardj | edf4d69 | 2004-08-17 13:52:58 +0000 | [diff] [blame] | 792 | vex_printf("\n"); |
| 793 | } |
| 794 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 795 | vexAllocSanityCheck(); |
| 796 | |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 797 | /* Get the thing instrumented. */ |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 798 | if (vta->instrument1) |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 799 | irsb = vta->instrument1(vta->callback_opaque, |
| 800 | irsb, guest_layout, |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 801 | vta->guest_extents, |
florian | 5048192 | 2012-10-07 21:58:07 +0000 | [diff] [blame] | 802 | &vta->archinfo_host, |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 803 | guest_word_type, host_word_type); |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 804 | vexAllocSanityCheck(); |
| 805 | |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 806 | if (vta->instrument2) |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 807 | irsb = vta->instrument2(vta->callback_opaque, |
| 808 | irsb, guest_layout, |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 809 | vta->guest_extents, |
florian | 5048192 | 2012-10-07 21:58:07 +0000 | [diff] [blame] | 810 | &vta->archinfo_host, |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 811 | guest_word_type, host_word_type); |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 812 | |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 813 | if (vex_traceflags & VEX_TRACE_INST) { |
| 814 | vex_printf("\n------------------------" |
| 815 | " After instrumentation " |
| 816 | "------------------------\n\n"); |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 817 | ppIRSB ( irsb ); |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 818 | vex_printf("\n"); |
| 819 | } |
| 820 | |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 821 | if (vta->instrument1 || vta->instrument2) |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 822 | sanityCheckIRSB( irsb, "after instrumentation", |
sewardj | b923075 | 2004-12-29 19:25:06 +0000 | [diff] [blame] | 823 | True/*must be flat*/, guest_word_type ); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 824 | |
sewardj | 9578a8b | 2004-11-04 19:44:48 +0000 | [diff] [blame] | 825 | /* Do a post-instrumentation cleanup pass. */ |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 826 | if (vta->instrument1 || vta->instrument2) { |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 827 | do_deadcode_BB( irsb ); |
| 828 | irsb = cprop_BB( irsb ); |
| 829 | do_deadcode_BB( irsb ); |
| 830 | sanityCheckIRSB( irsb, "after post-instrumentation cleanup", |
sewardj | b923075 | 2004-12-29 19:25:06 +0000 | [diff] [blame] | 831 | True/*must be flat*/, guest_word_type ); |
sewardj | 9578a8b | 2004-11-04 19:44:48 +0000 | [diff] [blame] | 832 | } |
| 833 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 834 | vexAllocSanityCheck(); |
| 835 | |
sewardj | 9578a8b | 2004-11-04 19:44:48 +0000 | [diff] [blame] | 836 | if (vex_traceflags & VEX_TRACE_OPT2) { |
| 837 | vex_printf("\n------------------------" |
| 838 | " After post-instr IR optimisation " |
| 839 | "------------------------\n\n"); |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 840 | ppIRSB ( irsb ); |
sewardj | 9578a8b | 2004-11-04 19:44:48 +0000 | [diff] [blame] | 841 | vex_printf("\n"); |
| 842 | } |
| 843 | |
sewardj | f9517d0 | 2005-11-28 13:39:37 +0000 | [diff] [blame] | 844 | /* Turn it into virtual-registerised code. Build trees -- this |
| 845 | also throws away any dead bindings. */ |
florian | 62140c1 | 2013-01-20 03:51:04 +0000 | [diff] [blame] | 846 | max_ga = ado_treebuild_BB( irsb, preciseMemExnsFn ); |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 847 | |
sewardj | be1b6ff | 2007-08-28 06:06:27 +0000 | [diff] [blame] | 848 | if (vta->finaltidy) { |
| 849 | irsb = vta->finaltidy(irsb); |
| 850 | } |
| 851 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 852 | vexAllocSanityCheck(); |
| 853 | |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 854 | if (vex_traceflags & VEX_TRACE_TREES) { |
| 855 | vex_printf("\n------------------------" |
| 856 | " After tree-building " |
| 857 | "------------------------\n\n"); |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 858 | ppIRSB ( irsb ); |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 859 | vex_printf("\n"); |
| 860 | } |
| 861 | |
sewardj | e908c42 | 2005-02-04 21:18:16 +0000 | [diff] [blame] | 862 | /* HACK */ |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 863 | if (0) { |
| 864 | *(vta->host_bytes_used) = 0; |
| 865 | res.status = VexTransOK; return res; |
| 866 | } |
sewardj | e908c42 | 2005-02-04 21:18:16 +0000 | [diff] [blame] | 867 | /* end HACK */ |
sewardj | c33671d | 2005-02-01 20:30:00 +0000 | [diff] [blame] | 868 | |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 869 | if (vex_traceflags & VEX_TRACE_VCODE) |
| 870 | vex_printf("\n------------------------" |
| 871 | " Instruction selection " |
| 872 | "------------------------\n"); |
| 873 | |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 874 | /* No guest has its IP field at offset zero. If this fails it |
| 875 | means some transformation pass somewhere failed to update/copy |
| 876 | irsb->offsIP properly. */ |
| 877 | vassert(irsb->offsIP >= 16); |
| 878 | |
| 879 | vcode = iselSB ( irsb, vta->arch_host, |
| 880 | &vta->archinfo_host, |
| 881 | &vta->abiinfo_both, |
| 882 | offB_HOST_EvC_COUNTER, |
| 883 | offB_HOST_EvC_FAILADDR, |
| 884 | chainingAllowed, |
| 885 | vta->addProfInc, |
| 886 | max_ga ); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 887 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 888 | vexAllocSanityCheck(); |
| 889 | |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 890 | if (vex_traceflags & VEX_TRACE_VCODE) |
| 891 | vex_printf("\n"); |
| 892 | |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 893 | if (vex_traceflags & VEX_TRACE_VCODE) { |
sewardj | 1f40a0a | 2004-07-21 12:28:07 +0000 | [diff] [blame] | 894 | for (i = 0; i < vcode->arr_used; i++) { |
| 895 | vex_printf("%3d ", i); |
cerion | 92b6436 | 2005-12-13 12:02:26 +0000 | [diff] [blame] | 896 | ppInstr(vcode->arr[i], mode64); |
sewardj | 1f40a0a | 2004-07-21 12:28:07 +0000 | [diff] [blame] | 897 | vex_printf("\n"); |
| 898 | } |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 899 | vex_printf("\n"); |
| 900 | } |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 901 | |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 902 | /* Register allocate. */ |
| 903 | rcode = doRegisterAllocation ( vcode, available_real_regs, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 904 | n_available_real_regs, |
sewardj | 72c7281 | 2005-01-19 11:49:45 +0000 | [diff] [blame] | 905 | isMove, getRegUsage, mapRegs, |
sewardj | fb7373a | 2007-08-25 21:29:03 +0000 | [diff] [blame] | 906 | genSpill, genReload, directReload, |
| 907 | guest_sizeB, |
cerion | 92b6436 | 2005-12-13 12:02:26 +0000 | [diff] [blame] | 908 | ppInstr, ppReg, mode64 ); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 909 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 910 | vexAllocSanityCheck(); |
| 911 | |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 912 | if (vex_traceflags & VEX_TRACE_RCODE) { |
| 913 | vex_printf("\n------------------------" |
| 914 | " Register-allocated code " |
| 915 | "------------------------\n\n"); |
sewardj | 1f40a0a | 2004-07-21 12:28:07 +0000 | [diff] [blame] | 916 | for (i = 0; i < rcode->arr_used; i++) { |
| 917 | vex_printf("%3d ", i); |
cerion | 92b6436 | 2005-12-13 12:02:26 +0000 | [diff] [blame] | 918 | ppInstr(rcode->arr[i], mode64); |
sewardj | 1f40a0a | 2004-07-21 12:28:07 +0000 | [diff] [blame] | 919 | vex_printf("\n"); |
| 920 | } |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 921 | vex_printf("\n"); |
| 922 | } |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 923 | |
sewardj | e908c42 | 2005-02-04 21:18:16 +0000 | [diff] [blame] | 924 | /* HACK */ |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 925 | if (0) { |
| 926 | *(vta->host_bytes_used) = 0; |
| 927 | res.status = VexTransOK; return res; |
| 928 | } |
sewardj | e908c42 | 2005-02-04 21:18:16 +0000 | [diff] [blame] | 929 | /* end HACK */ |
| 930 | |
sewardj | 81bd550 | 2004-07-21 18:49:27 +0000 | [diff] [blame] | 931 | /* Assemble */ |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 932 | if (vex_traceflags & VEX_TRACE_ASM) { |
| 933 | vex_printf("\n------------------------" |
| 934 | " Assembly " |
| 935 | "------------------------\n\n"); |
| 936 | } |
| 937 | |
sewardj | 81bd550 | 2004-07-21 18:49:27 +0000 | [diff] [blame] | 938 | out_used = 0; /* tracks along the host_bytes array */ |
| 939 | for (i = 0; i < rcode->arr_used; i++) { |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 940 | HInstr* hi = rcode->arr[i]; |
| 941 | Bool hi_isProfInc = False; |
| 942 | if (UNLIKELY(vex_traceflags & VEX_TRACE_ASM)) { |
| 943 | ppInstr(hi, mode64); |
sewardj | bad34a9 | 2004-07-22 01:14:11 +0000 | [diff] [blame] | 944 | vex_printf("\n"); |
| 945 | } |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 946 | j = emit( &hi_isProfInc, |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 947 | insn_bytes, sizeof insn_bytes, hi, |
| 948 | mode64, vta->archinfo_host.endness, |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 949 | vta->disp_cp_chain_me_to_slowEP, |
| 950 | vta->disp_cp_chain_me_to_fastEP, |
| 951 | vta->disp_cp_xindir, |
| 952 | vta->disp_cp_xassisted ); |
| 953 | if (UNLIKELY(vex_traceflags & VEX_TRACE_ASM)) { |
sewardj | bad34a9 | 2004-07-22 01:14:11 +0000 | [diff] [blame] | 954 | for (k = 0; k < j; k++) |
sewardj | 72c7281 | 2005-01-19 11:49:45 +0000 | [diff] [blame] | 955 | if (insn_bytes[k] < 16) |
sewardj | 86898e8 | 2004-07-22 17:26:12 +0000 | [diff] [blame] | 956 | vex_printf("0%x ", (UInt)insn_bytes[k]); |
| 957 | else |
| 958 | vex_printf("%x ", (UInt)insn_bytes[k]); |
sewardj | bad34a9 | 2004-07-22 01:14:11 +0000 | [diff] [blame] | 959 | vex_printf("\n\n"); |
| 960 | } |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 961 | if (UNLIKELY(out_used + j > vta->host_bytes_size)) { |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 962 | vexSetAllocModeTEMP_and_clear(); |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 963 | vex_traceflags = 0; |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 964 | res.status = VexTransOutputFull; |
| 965 | return res; |
sewardj | 81bd550 | 2004-07-21 18:49:27 +0000 | [diff] [blame] | 966 | } |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 967 | if (UNLIKELY(hi_isProfInc)) { |
| 968 | vassert(vta->addProfInc); /* else where did it come from? */ |
| 969 | vassert(res.offs_profInc == -1); /* there can be only one (tm) */ |
| 970 | vassert(out_used >= 0); |
| 971 | res.offs_profInc = out_used; |
| 972 | } |
| 973 | { UChar* dst = &vta->host_bytes[out_used]; |
| 974 | for (k = 0; k < j; k++) { |
| 975 | dst[k] = insn_bytes[k]; |
| 976 | } |
| 977 | out_used += j; |
sewardj | 81bd550 | 2004-07-21 18:49:27 +0000 | [diff] [blame] | 978 | } |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 979 | vassert(out_used <= vta->host_bytes_size); |
sewardj | 81bd550 | 2004-07-21 18:49:27 +0000 | [diff] [blame] | 980 | } |
sewardj | 17c7f95 | 2005-12-15 14:02:34 +0000 | [diff] [blame] | 981 | *(vta->host_bytes_used) = out_used; |
sewardj | 81bd550 | 2004-07-21 18:49:27 +0000 | [diff] [blame] | 982 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 983 | vexAllocSanityCheck(); |
| 984 | |
| 985 | vexSetAllocModeTEMP_and_clear(); |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 986 | |
sewardj | 65ea17e | 2012-12-28 09:01:59 +0000 | [diff] [blame] | 987 | if (vex_traceflags) { |
| 988 | /* Print the expansion ratio for this SB. */ |
| 989 | j = 0; /* total guest bytes */ |
| 990 | for (i = 0; i < vta->guest_extents->n_used; i++) { |
| 991 | j += vta->guest_extents->len[i]; |
| 992 | } |
| 993 | if (1) vex_printf("VexExpansionRatio %d %d %d :10\n\n", |
| 994 | j, out_used, (10 * out_used) / (j == 0 ? 1 : j)); |
| 995 | } |
| 996 | |
sewardj | f48ac19 | 2004-10-29 00:41:29 +0000 | [diff] [blame] | 997 | vex_traceflags = 0; |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 998 | res.status = VexTransOK; |
| 999 | return res; |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1003 | /* --------- Chain/Unchain XDirects. --------- */ |
| 1004 | |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1005 | VexInvalRange LibVEX_Chain ( VexArch arch_host, |
| 1006 | VexEndness endness_host, |
| 1007 | void* place_to_chain, |
| 1008 | void* disp_cp_chain_me_EXPECTED, |
| 1009 | void* place_to_jump_to ) |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1010 | { |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1011 | VexInvalRange (*chainXDirect)(VexEndness, void*, void*, void*) = NULL; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1012 | switch (arch_host) { |
| 1013 | case VexArchX86: |
| 1014 | chainXDirect = chainXDirect_X86; break; |
| 1015 | case VexArchAMD64: |
| 1016 | chainXDirect = chainXDirect_AMD64; break; |
| 1017 | case VexArchARM: |
| 1018 | chainXDirect = chainXDirect_ARM; break; |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 1019 | case VexArchARM64: |
| 1020 | chainXDirect = chainXDirect_ARM64; break; |
florian | 8844a63 | 2012-04-13 04:04:06 +0000 | [diff] [blame] | 1021 | case VexArchS390X: |
| 1022 | chainXDirect = chainXDirect_S390; break; |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 1023 | case VexArchPPC32: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1024 | return chainXDirect_PPC(endness_host, |
| 1025 | place_to_chain, |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 1026 | disp_cp_chain_me_EXPECTED, |
| 1027 | place_to_jump_to, False/*!mode64*/); |
sewardj | f252de5 | 2012-04-20 10:42:24 +0000 | [diff] [blame] | 1028 | case VexArchPPC64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1029 | return chainXDirect_PPC(endness_host, |
| 1030 | place_to_chain, |
sewardj | f252de5 | 2012-04-20 10:42:24 +0000 | [diff] [blame] | 1031 | disp_cp_chain_me_EXPECTED, |
| 1032 | place_to_jump_to, True/*mode64*/); |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1033 | case VexArchMIPS32: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1034 | return chainXDirect_MIPS(endness_host, |
| 1035 | place_to_chain, |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1036 | disp_cp_chain_me_EXPECTED, |
| 1037 | place_to_jump_to, False/*!mode64*/); |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1038 | case VexArchMIPS64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1039 | return chainXDirect_MIPS(endness_host, |
| 1040 | place_to_chain, |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1041 | disp_cp_chain_me_EXPECTED, |
| 1042 | place_to_jump_to, True/*!mode64*/); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1043 | default: |
| 1044 | vassert(0); |
| 1045 | } |
| 1046 | vassert(chainXDirect); |
| 1047 | VexInvalRange vir |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1048 | = chainXDirect(endness_host, place_to_chain, |
| 1049 | disp_cp_chain_me_EXPECTED, place_to_jump_to); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1050 | return vir; |
| 1051 | } |
| 1052 | |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1053 | VexInvalRange LibVEX_UnChain ( VexArch arch_host, |
| 1054 | VexEndness endness_host, |
| 1055 | void* place_to_unchain, |
| 1056 | void* place_to_jump_to_EXPECTED, |
| 1057 | void* disp_cp_chain_me ) |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1058 | { |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1059 | VexInvalRange (*unchainXDirect)(VexEndness, void*, void*, void*) = NULL; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1060 | switch (arch_host) { |
| 1061 | case VexArchX86: |
| 1062 | unchainXDirect = unchainXDirect_X86; break; |
| 1063 | case VexArchAMD64: |
| 1064 | unchainXDirect = unchainXDirect_AMD64; break; |
| 1065 | case VexArchARM: |
| 1066 | unchainXDirect = unchainXDirect_ARM; break; |
sewardj | c6acaa4 | 2014-02-19 17:42:59 +0000 | [diff] [blame] | 1067 | case VexArchARM64: |
| 1068 | unchainXDirect = unchainXDirect_ARM64; break; |
florian | 8844a63 | 2012-04-13 04:04:06 +0000 | [diff] [blame] | 1069 | case VexArchS390X: |
| 1070 | unchainXDirect = unchainXDirect_S390; break; |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 1071 | case VexArchPPC32: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1072 | return unchainXDirect_PPC(endness_host, |
| 1073 | place_to_unchain, |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 1074 | place_to_jump_to_EXPECTED, |
| 1075 | disp_cp_chain_me, False/*!mode64*/); |
sewardj | f252de5 | 2012-04-20 10:42:24 +0000 | [diff] [blame] | 1076 | case VexArchPPC64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1077 | return unchainXDirect_PPC(endness_host, |
| 1078 | place_to_unchain, |
sewardj | f252de5 | 2012-04-20 10:42:24 +0000 | [diff] [blame] | 1079 | place_to_jump_to_EXPECTED, |
| 1080 | disp_cp_chain_me, True/*mode64*/); |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1081 | case VexArchMIPS32: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1082 | return unchainXDirect_MIPS(endness_host, |
| 1083 | place_to_unchain, |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1084 | place_to_jump_to_EXPECTED, |
| 1085 | disp_cp_chain_me, False/*!mode64*/); |
| 1086 | case VexArchMIPS64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1087 | return unchainXDirect_MIPS(endness_host, |
| 1088 | place_to_unchain, |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1089 | place_to_jump_to_EXPECTED, |
| 1090 | disp_cp_chain_me, True/*!mode64*/); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1091 | default: |
| 1092 | vassert(0); |
| 1093 | } |
| 1094 | vassert(unchainXDirect); |
| 1095 | VexInvalRange vir |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1096 | = unchainXDirect(endness_host, place_to_unchain, |
| 1097 | place_to_jump_to_EXPECTED, disp_cp_chain_me); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1098 | return vir; |
| 1099 | } |
| 1100 | |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1101 | Int LibVEX_evCheckSzB ( VexArch arch_host, |
| 1102 | VexEndness endness_host ) |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1103 | { |
| 1104 | static Int cached = 0; /* DO NOT MAKE NON-STATIC */ |
| 1105 | if (UNLIKELY(cached == 0)) { |
| 1106 | switch (arch_host) { |
| 1107 | case VexArchX86: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1108 | cached = evCheckSzB_X86(endness_host); break; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1109 | case VexArchAMD64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1110 | cached = evCheckSzB_AMD64(endness_host); break; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1111 | case VexArchARM: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1112 | cached = evCheckSzB_ARM(endness_host); break; |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 1113 | case VexArchARM64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1114 | cached = evCheckSzB_ARM64(endness_host); break; |
florian | 8844a63 | 2012-04-13 04:04:06 +0000 | [diff] [blame] | 1115 | case VexArchS390X: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1116 | cached = evCheckSzB_S390(endness_host); break; |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 1117 | case VexArchPPC32: |
sewardj | f252de5 | 2012-04-20 10:42:24 +0000 | [diff] [blame] | 1118 | case VexArchPPC64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1119 | cached = evCheckSzB_PPC(endness_host); break; |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1120 | case VexArchMIPS32: |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1121 | case VexArchMIPS64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1122 | cached = evCheckSzB_MIPS(endness_host); break; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1123 | default: |
| 1124 | vassert(0); |
| 1125 | } |
| 1126 | } |
| 1127 | return cached; |
| 1128 | } |
| 1129 | |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1130 | VexInvalRange LibVEX_PatchProfInc ( VexArch arch_host, |
| 1131 | VexEndness endness_host, |
| 1132 | void* place_to_patch, |
| 1133 | ULong* location_of_counter ) |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1134 | { |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1135 | VexInvalRange (*patchProfInc)(VexEndness,void*,ULong*) = NULL; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1136 | switch (arch_host) { |
| 1137 | case VexArchX86: |
| 1138 | patchProfInc = patchProfInc_X86; break; |
| 1139 | case VexArchAMD64: |
| 1140 | patchProfInc = patchProfInc_AMD64; break; |
| 1141 | case VexArchARM: |
| 1142 | patchProfInc = patchProfInc_ARM; break; |
florian | 8844a63 | 2012-04-13 04:04:06 +0000 | [diff] [blame] | 1143 | case VexArchS390X: |
| 1144 | patchProfInc = patchProfInc_S390; break; |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 1145 | case VexArchPPC32: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1146 | return patchProfInc_PPC(endness_host, place_to_patch, |
sewardj | 3dee849 | 2012-04-20 00:13:28 +0000 | [diff] [blame] | 1147 | location_of_counter, False/*!mode64*/); |
sewardj | f252de5 | 2012-04-20 10:42:24 +0000 | [diff] [blame] | 1148 | case VexArchPPC64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1149 | return patchProfInc_PPC(endness_host, place_to_patch, |
sewardj | f252de5 | 2012-04-20 10:42:24 +0000 | [diff] [blame] | 1150 | location_of_counter, True/*mode64*/); |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1151 | case VexArchMIPS32: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1152 | return patchProfInc_MIPS(endness_host, place_to_patch, |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1153 | location_of_counter, False/*!mode64*/); |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1154 | case VexArchMIPS64: |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1155 | return patchProfInc_MIPS(endness_host, place_to_patch, |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1156 | location_of_counter, True/*!mode64*/); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1157 | default: |
| 1158 | vassert(0); |
| 1159 | } |
| 1160 | vassert(patchProfInc); |
| 1161 | VexInvalRange vir |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1162 | = patchProfInc(endness_host, place_to_patch, location_of_counter); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1163 | return vir; |
| 1164 | } |
| 1165 | |
| 1166 | |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1167 | /* --------- Emulation warnings. --------- */ |
| 1168 | |
florian | 1ff4756 | 2012-10-21 02:09:51 +0000 | [diff] [blame] | 1169 | const HChar* LibVEX_EmNote_string ( VexEmNote ew ) |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1170 | { |
| 1171 | switch (ew) { |
florian | 6ef84be | 2012-08-26 03:20:07 +0000 | [diff] [blame] | 1172 | case EmNote_NONE: |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1173 | return "none"; |
| 1174 | case EmWarn_X86_x87exns: |
| 1175 | return "Unmasking x87 FP exceptions"; |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1176 | case EmWarn_X86_x87precision: |
| 1177 | return "Selection of non-80-bit x87 FP precision"; |
| 1178 | case EmWarn_X86_sseExns: |
sewardj | 5edfc26 | 2004-12-15 12:13:52 +0000 | [diff] [blame] | 1179 | return "Unmasking SSE FP exceptions"; |
| 1180 | case EmWarn_X86_fz: |
| 1181 | return "Setting %mxcsr.fz (SSE flush-underflows-to-zero mode)"; |
| 1182 | case EmWarn_X86_daz: |
| 1183 | return "Setting %mxcsr.daz (SSE treat-denormals-as-zero mode)"; |
sewardj | 6d26984 | 2005-08-06 11:45:02 +0000 | [diff] [blame] | 1184 | case EmWarn_X86_acFlag: |
| 1185 | return "Setting %eflags.ac (setting noted but ignored)"; |
sewardj | 9dd9cf1 | 2006-01-20 14:13:55 +0000 | [diff] [blame] | 1186 | case EmWarn_PPCexns: |
| 1187 | return "Unmasking PPC32/64 FP exceptions"; |
| 1188 | case EmWarn_PPC64_redir_overflow: |
| 1189 | return "PPC64 function redirection stack overflow"; |
| 1190 | case EmWarn_PPC64_redir_underflow: |
| 1191 | return "PPC64 function redirection stack underflow"; |
florian | 4b8efad | 2012-09-02 18:07:08 +0000 | [diff] [blame] | 1192 | case EmWarn_S390X_fpext_rounding: |
| 1193 | return "The specified rounding mode cannot be supported. That\n" |
| 1194 | " feature requires the floating point extension facility.\n" |
| 1195 | " which is not available on this host. Continuing using\n" |
| 1196 | " the rounding mode from FPC. Results may differ!"; |
florian | f0fa1be | 2012-09-18 20:24:38 +0000 | [diff] [blame] | 1197 | case EmWarn_S390X_invalid_rounding: |
| 1198 | return "The specified rounding mode is invalid.\n" |
| 1199 | " Continuing using 'round to nearest'. Results may differ!"; |
florian | e75dafa | 2012-09-01 17:54:09 +0000 | [diff] [blame] | 1200 | case EmFail_S390X_stfle: |
florian | 4e0083e | 2012-08-26 03:41:56 +0000 | [diff] [blame] | 1201 | return "Instruction stfle is not supported on this host"; |
florian | e75dafa | 2012-09-01 17:54:09 +0000 | [diff] [blame] | 1202 | case EmFail_S390X_stckf: |
florian | c5c669b | 2012-08-26 14:32:28 +0000 | [diff] [blame] | 1203 | return "Instruction stckf is not supported on this host"; |
florian | e75dafa | 2012-09-01 17:54:09 +0000 | [diff] [blame] | 1204 | case EmFail_S390X_ecag: |
florian | 8c88cb6 | 2012-08-26 18:58:13 +0000 | [diff] [blame] | 1205 | return "Instruction ecag is not supported on this host"; |
florian | e75dafa | 2012-09-01 17:54:09 +0000 | [diff] [blame] | 1206 | case EmFail_S390X_fpext: |
| 1207 | return "Encountered an instruction that requires the floating " |
| 1208 | "point extension facility.\n" |
| 1209 | " That facility is not available on this host"; |
florian | 78d5ef7 | 2013-05-11 15:02:58 +0000 | [diff] [blame] | 1210 | case EmFail_S390X_invalid_PFPO_rounding_mode: |
| 1211 | return "The rounding mode specified in GPR 0 for PFPO instruction" |
| 1212 | " is invalid"; |
| 1213 | case EmFail_S390X_invalid_PFPO_function: |
| 1214 | return "The function code specified in GPR 0 for PFPO instruction" |
| 1215 | " is invalid"; |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1216 | default: |
florian | 6ef84be | 2012-08-26 03:20:07 +0000 | [diff] [blame] | 1217 | vpanic("LibVEX_EmNote_string: unknown warning"); |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1218 | } |
| 1219 | } |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 1220 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1221 | /* ------------------ Arch/HwCaps stuff. ------------------ */ |
sewardj | bef170b | 2004-12-21 01:23:00 +0000 | [diff] [blame] | 1222 | |
| 1223 | const HChar* LibVEX_ppVexArch ( VexArch arch ) |
| 1224 | { |
| 1225 | switch (arch) { |
| 1226 | case VexArch_INVALID: return "INVALID"; |
| 1227 | case VexArchX86: return "X86"; |
| 1228 | case VexArchAMD64: return "AMD64"; |
| 1229 | case VexArchARM: return "ARM"; |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 1230 | case VexArchARM64: return "ARM64"; |
sewardj | 0ec57c5 | 2005-02-01 15:24:10 +0000 | [diff] [blame] | 1231 | case VexArchPPC32: return "PPC32"; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1232 | case VexArchPPC64: return "PPC64"; |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 1233 | case VexArchS390X: return "S390X"; |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1234 | case VexArchMIPS32: return "MIPS32"; |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1235 | case VexArchMIPS64: return "MIPS64"; |
sewardj | bef170b | 2004-12-21 01:23:00 +0000 | [diff] [blame] | 1236 | default: return "VexArch???"; |
| 1237 | } |
| 1238 | } |
| 1239 | |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1240 | const HChar* LibVEX_ppVexEndness ( VexEndness endness ) |
| 1241 | { |
| 1242 | switch (endness) { |
| 1243 | case VexEndness_INVALID: return "INVALID"; |
| 1244 | case VexEndnessLE: return "LittleEndian"; |
| 1245 | case VexEndnessBE: return "BigEndian"; |
| 1246 | default: return "VexEndness???"; |
| 1247 | } |
| 1248 | } |
| 1249 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1250 | const HChar* LibVEX_ppVexHwCaps ( VexArch arch, UInt hwcaps ) |
sewardj | bef170b | 2004-12-21 01:23:00 +0000 | [diff] [blame] | 1251 | { |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 1252 | const HChar* str = show_hwcaps(arch,hwcaps); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1253 | return str ? str : "INVALID"; |
sewardj | bef170b | 2004-12-21 01:23:00 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1256 | |
sewardj | 27e1dd6 | 2005-06-30 11:49:14 +0000 | [diff] [blame] | 1257 | /* Write default settings info *vai. */ |
| 1258 | void LibVEX_default_VexArchInfo ( /*OUT*/VexArchInfo* vai ) |
| 1259 | { |
sewardj | 6590299 | 2014-05-03 21:20:56 +0000 | [diff] [blame] | 1260 | vex_bzero(vai, sizeof(*vai)); |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 1261 | vai->hwcaps = 0; |
| 1262 | vai->endness = VexEndness_INVALID; |
| 1263 | vai->ppc_icache_line_szB = 0; |
| 1264 | vai->ppc_dcbz_szB = 0; |
| 1265 | vai->ppc_dcbzl_szB = 0; |
sewardj | 6590299 | 2014-05-03 21:20:56 +0000 | [diff] [blame] | 1266 | vai->arm64_dMinLine_lg2_szB = 0; |
| 1267 | vai->arm64_iMinLine_lg2_szB = 0; |
florian | f192a39 | 2012-10-07 19:44:40 +0000 | [diff] [blame] | 1268 | vai->hwcache_info.num_levels = 0; |
| 1269 | vai->hwcache_info.num_caches = 0; |
sewardj | 6590299 | 2014-05-03 21:20:56 +0000 | [diff] [blame] | 1270 | vai->hwcache_info.caches = NULL; |
florian | f192a39 | 2012-10-07 19:44:40 +0000 | [diff] [blame] | 1271 | vai->hwcache_info.icaches_maintain_coherence = True; // whatever |
sewardj | 27e1dd6 | 2005-06-30 11:49:14 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1274 | /* Write default settings info *vbi. */ |
| 1275 | void LibVEX_default_VexAbiInfo ( /*OUT*/VexAbiInfo* vbi ) |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 1276 | { |
sewardj | 6590299 | 2014-05-03 21:20:56 +0000 | [diff] [blame] | 1277 | vex_bzero(vbi, sizeof(*vbi)); |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1278 | vbi->guest_stack_redzone_size = 0; |
sewardj | 2e28ac4 | 2008-12-04 00:05:12 +0000 | [diff] [blame] | 1279 | vbi->guest_amd64_assume_fs_is_zero = False; |
| 1280 | vbi->guest_amd64_assume_gs_is_0x60 = False; |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1281 | vbi->guest_ppc_zap_RZ_at_blr = False; |
| 1282 | vbi->guest_ppc_zap_RZ_at_bl = NULL; |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1283 | vbi->host_ppc_calls_use_fndescrs = False; |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
sewardj | 27e1dd6 | 2005-06-30 11:49:14 +0000 | [diff] [blame] | 1286 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1287 | /* Return a string showing the hwcaps in a nice way. The string will |
| 1288 | be NULL for invalid combinations of flags, so these functions also |
| 1289 | serve as a way to validate hwcaps values. */ |
| 1290 | |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 1291 | static const HChar* show_hwcaps_x86 ( UInt hwcaps ) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1292 | { |
mjw | 6c65c12 | 2013-08-27 10:19:03 +0000 | [diff] [blame] | 1293 | /* Monotonic, LZCNT > SSE3 > SSE2 > SSE1 > MMXEXT > baseline. */ |
sewardj | 536fbab | 2010-07-29 15:39:05 +0000 | [diff] [blame] | 1294 | switch (hwcaps) { |
| 1295 | case 0: |
| 1296 | return "x86-sse0"; |
mjw | 6c65c12 | 2013-08-27 10:19:03 +0000 | [diff] [blame] | 1297 | case VEX_HWCAPS_X86_MMXEXT: |
| 1298 | return "x86-mmxext"; |
| 1299 | case VEX_HWCAPS_X86_MMXEXT | VEX_HWCAPS_X86_SSE1: |
| 1300 | return "x86-mmxext-sse1"; |
| 1301 | case VEX_HWCAPS_X86_MMXEXT | VEX_HWCAPS_X86_SSE1 | VEX_HWCAPS_X86_SSE2: |
| 1302 | return "x86-mmxext-sse1-sse2"; |
| 1303 | case VEX_HWCAPS_X86_MMXEXT | VEX_HWCAPS_X86_SSE1 | VEX_HWCAPS_X86_SSE2 |
sewardj | 536fbab | 2010-07-29 15:39:05 +0000 | [diff] [blame] | 1304 | | VEX_HWCAPS_X86_LZCNT: |
mjw | 6c65c12 | 2013-08-27 10:19:03 +0000 | [diff] [blame] | 1305 | return "x86-mmxext-sse1-sse2-lzcnt"; |
| 1306 | case VEX_HWCAPS_X86_MMXEXT | VEX_HWCAPS_X86_SSE1 | VEX_HWCAPS_X86_SSE2 |
sewardj | 536fbab | 2010-07-29 15:39:05 +0000 | [diff] [blame] | 1307 | | VEX_HWCAPS_X86_SSE3: |
mjw | 6c65c12 | 2013-08-27 10:19:03 +0000 | [diff] [blame] | 1308 | return "x86-mmxext-sse1-sse2-sse3"; |
| 1309 | case VEX_HWCAPS_X86_MMXEXT | VEX_HWCAPS_X86_SSE1 | VEX_HWCAPS_X86_SSE2 |
sewardj | 536fbab | 2010-07-29 15:39:05 +0000 | [diff] [blame] | 1310 | | VEX_HWCAPS_X86_SSE3 | VEX_HWCAPS_X86_LZCNT: |
mjw | 6c65c12 | 2013-08-27 10:19:03 +0000 | [diff] [blame] | 1311 | return "x86-mmxext-sse1-sse2-sse3-lzcnt"; |
sewardj | 536fbab | 2010-07-29 15:39:05 +0000 | [diff] [blame] | 1312 | default: |
| 1313 | return NULL; |
| 1314 | } |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 1317 | static const HChar* show_hwcaps_amd64 ( UInt hwcaps ) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1318 | { |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 1319 | /* SSE3 and CX16 are orthogonal and > baseline, although we really |
| 1320 | don't expect to come across anything which can do SSE3 but can't |
sewardj | 536fbab | 2010-07-29 15:39:05 +0000 | [diff] [blame] | 1321 | do CX16. Still, we can handle that case. LZCNT is similarly |
sewardj | 818c730 | 2013-03-26 13:53:18 +0000 | [diff] [blame] | 1322 | orthogonal. */ |
| 1323 | |
| 1324 | /* Throw out obviously stupid cases: */ |
sewardj | 818c730 | 2013-03-26 13:53:18 +0000 | [diff] [blame] | 1325 | Bool have_sse3 = (hwcaps & VEX_HWCAPS_AMD64_SSE3) != 0; |
| 1326 | Bool have_avx = (hwcaps & VEX_HWCAPS_AMD64_AVX) != 0; |
sewardj | cc3d219 | 2013-03-27 11:37:33 +0000 | [diff] [blame] | 1327 | Bool have_bmi = (hwcaps & VEX_HWCAPS_AMD64_BMI) != 0; |
| 1328 | Bool have_avx2 = (hwcaps & VEX_HWCAPS_AMD64_AVX2) != 0; |
| 1329 | /* AVX without SSE3 */ |
sewardj | 818c730 | 2013-03-26 13:53:18 +0000 | [diff] [blame] | 1330 | if (have_avx && !have_sse3) |
| 1331 | return NULL; |
sewardj | cc3d219 | 2013-03-27 11:37:33 +0000 | [diff] [blame] | 1332 | /* AVX2 or BMI without AVX */ |
| 1333 | if ((have_avx2 || have_bmi) && !have_avx) |
| 1334 | return NULL; |
sewardj | 818c730 | 2013-03-26 13:53:18 +0000 | [diff] [blame] | 1335 | |
| 1336 | /* This isn't threadsafe. We might need to fix it at some point. */ |
| 1337 | static HChar buf[100] = { 0 }; |
| 1338 | if (buf[0] != 0) return buf; /* already constructed */ |
| 1339 | |
| 1340 | vex_bzero(buf, sizeof(buf)); |
| 1341 | |
| 1342 | HChar* p = &buf[0]; |
| 1343 | |
| 1344 | p = p + vex_sprintf(p, "%s", "amd64"); |
| 1345 | if (hwcaps == 0) { |
| 1346 | /* special-case the baseline case */ |
| 1347 | p = p + vex_sprintf(p, "%s", "-sse2"); |
| 1348 | goto out; |
sewardj | 536fbab | 2010-07-29 15:39:05 +0000 | [diff] [blame] | 1349 | } |
sewardj | 818c730 | 2013-03-26 13:53:18 +0000 | [diff] [blame] | 1350 | if (hwcaps & VEX_HWCAPS_AMD64_CX16) { |
| 1351 | p = p + vex_sprintf(p, "%s", "-cx16"); |
| 1352 | } |
| 1353 | if (hwcaps & VEX_HWCAPS_AMD64_LZCNT) { |
| 1354 | p = p + vex_sprintf(p, "%s", "-lzcnt"); |
| 1355 | } |
| 1356 | if (hwcaps & VEX_HWCAPS_AMD64_RDTSCP) { |
| 1357 | p = p + vex_sprintf(p, "%s", "-rdtscp"); |
| 1358 | } |
| 1359 | if (hwcaps & VEX_HWCAPS_AMD64_SSE3) { |
| 1360 | p = p + vex_sprintf(p, "%s", "-sse3"); |
| 1361 | } |
| 1362 | if (hwcaps & VEX_HWCAPS_AMD64_AVX) { |
| 1363 | p = p + vex_sprintf(p, "%s", "-avx"); |
| 1364 | } |
sewardj | cc3d219 | 2013-03-27 11:37:33 +0000 | [diff] [blame] | 1365 | if (hwcaps & VEX_HWCAPS_AMD64_AVX2) { |
| 1366 | p = p + vex_sprintf(p, "%s", "-avx2"); |
| 1367 | } |
| 1368 | if (hwcaps & VEX_HWCAPS_AMD64_BMI) { |
| 1369 | p = p + vex_sprintf(p, "%s", "-bmi"); |
| 1370 | } |
sewardj | 818c730 | 2013-03-26 13:53:18 +0000 | [diff] [blame] | 1371 | |
| 1372 | out: |
| 1373 | vassert(buf[sizeof(buf)-1] == 0); |
| 1374 | return buf; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 1377 | static const HChar* show_hwcaps_ppc32 ( UInt hwcaps ) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1378 | { |
| 1379 | /* Monotonic with complications. Basically V > F > baseline, |
| 1380 | but once you have F then you can have FX or GX too. */ |
| 1381 | const UInt F = VEX_HWCAPS_PPC32_F; |
| 1382 | const UInt V = VEX_HWCAPS_PPC32_V; |
| 1383 | const UInt FX = VEX_HWCAPS_PPC32_FX; |
| 1384 | const UInt GX = VEX_HWCAPS_PPC32_GX; |
sewardj | 66d5ef2 | 2011-04-15 11:55:00 +0000 | [diff] [blame] | 1385 | const UInt VX = VEX_HWCAPS_PPC32_VX; |
sewardj | c66d6fa | 2012-04-02 21:24:12 +0000 | [diff] [blame] | 1386 | const UInt DFP = VEX_HWCAPS_PPC32_DFP; |
carll | 0c74bb5 | 2013-08-12 18:01:40 +0000 | [diff] [blame] | 1387 | const UInt ISA2_07 = VEX_HWCAPS_PPC32_ISA2_07; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1388 | UInt c = hwcaps; |
| 1389 | if (c == 0) return "ppc32-int"; |
| 1390 | if (c == F) return "ppc32-int-flt"; |
| 1391 | if (c == (F|FX)) return "ppc32-int-flt-FX"; |
| 1392 | if (c == (F|GX)) return "ppc32-int-flt-GX"; |
| 1393 | if (c == (F|FX|GX)) return "ppc32-int-flt-FX-GX"; |
| 1394 | if (c == (F|V)) return "ppc32-int-flt-vmx"; |
| 1395 | if (c == (F|V|FX)) return "ppc32-int-flt-vmx-FX"; |
| 1396 | if (c == (F|V|GX)) return "ppc32-int-flt-vmx-GX"; |
| 1397 | if (c == (F|V|FX|GX)) return "ppc32-int-flt-vmx-FX-GX"; |
sewardj | c66d6fa | 2012-04-02 21:24:12 +0000 | [diff] [blame] | 1398 | if (c == (F|V|FX|GX|DFP)) return "ppc32-int-flt-vmx-FX-GX-DFP"; |
| 1399 | if (c == (F|V|FX|GX|VX|DFP)) return "ppc32-int-flt-vmx-FX-GX-VX-DFP"; |
carll | 0c74bb5 | 2013-08-12 18:01:40 +0000 | [diff] [blame] | 1400 | if (c == (F|V|FX|GX|VX|DFP|ISA2_07)) |
| 1401 | return "ppc32-int-flt-vmx-FX-GX-VX-DFP-ISA2_07"; |
| 1402 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1403 | return NULL; |
| 1404 | } |
| 1405 | |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 1406 | static const HChar* show_hwcaps_ppc64 ( UInt hwcaps ) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1407 | { |
| 1408 | /* Monotonic with complications. Basically V > baseline(==F), |
| 1409 | but once you have F then you can have FX or GX too. */ |
sewardj | 3fd3967 | 2006-01-27 22:05:55 +0000 | [diff] [blame] | 1410 | const UInt V = VEX_HWCAPS_PPC64_V; |
| 1411 | const UInt FX = VEX_HWCAPS_PPC64_FX; |
| 1412 | const UInt GX = VEX_HWCAPS_PPC64_GX; |
sewardj | 66d5ef2 | 2011-04-15 11:55:00 +0000 | [diff] [blame] | 1413 | const UInt VX = VEX_HWCAPS_PPC64_VX; |
sewardj | c66d6fa | 2012-04-02 21:24:12 +0000 | [diff] [blame] | 1414 | const UInt DFP = VEX_HWCAPS_PPC64_DFP; |
carll | 0c74bb5 | 2013-08-12 18:01:40 +0000 | [diff] [blame] | 1415 | const UInt ISA2_07 = VEX_HWCAPS_PPC64_ISA2_07; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1416 | UInt c = hwcaps; |
| 1417 | if (c == 0) return "ppc64-int-flt"; |
| 1418 | if (c == FX) return "ppc64-int-flt-FX"; |
| 1419 | if (c == GX) return "ppc64-int-flt-GX"; |
| 1420 | if (c == (FX|GX)) return "ppc64-int-flt-FX-GX"; |
| 1421 | if (c == V) return "ppc64-int-flt-vmx"; |
| 1422 | if (c == (V|FX)) return "ppc64-int-flt-vmx-FX"; |
| 1423 | if (c == (V|GX)) return "ppc64-int-flt-vmx-GX"; |
| 1424 | if (c == (V|FX|GX)) return "ppc64-int-flt-vmx-FX-GX"; |
sewardj | c66d6fa | 2012-04-02 21:24:12 +0000 | [diff] [blame] | 1425 | if (c == (V|FX|GX|DFP)) return "ppc64-int-flt-vmx-FX-GX-DFP"; |
| 1426 | if (c == (V|FX|GX|VX|DFP)) return "ppc64-int-flt-vmx-FX-GX-VX-DFP"; |
carll | 0c74bb5 | 2013-08-12 18:01:40 +0000 | [diff] [blame] | 1427 | if (c == (V|FX|GX|VX|DFP|ISA2_07)) |
| 1428 | return "ppc64-int-flt-vmx-FX-GX-VX-DFP-ISA2_07"; |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1429 | return NULL; |
| 1430 | } |
| 1431 | |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 1432 | static const HChar* show_hwcaps_arm ( UInt hwcaps ) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1433 | { |
sewardj | ec0d9a0 | 2010-08-22 12:54:56 +0000 | [diff] [blame] | 1434 | Bool N = ((hwcaps & VEX_HWCAPS_ARM_NEON) != 0); |
| 1435 | Bool vfp = ((hwcaps & (VEX_HWCAPS_ARM_VFP | |
| 1436 | VEX_HWCAPS_ARM_VFP2 | VEX_HWCAPS_ARM_VFP3)) != 0); |
| 1437 | switch (VEX_ARM_ARCHLEVEL(hwcaps)) { |
| 1438 | case 5: |
| 1439 | if (N) |
| 1440 | return NULL; |
| 1441 | if (vfp) |
| 1442 | return "ARMv5-vfp"; |
| 1443 | else |
| 1444 | return "ARMv5"; |
| 1445 | return NULL; |
| 1446 | case 6: |
| 1447 | if (N) |
| 1448 | return NULL; |
| 1449 | if (vfp) |
| 1450 | return "ARMv6-vfp"; |
| 1451 | else |
| 1452 | return "ARMv6"; |
| 1453 | return NULL; |
| 1454 | case 7: |
| 1455 | if (vfp) { |
| 1456 | if (N) |
| 1457 | return "ARMv7-vfp-neon"; |
| 1458 | else |
| 1459 | return "ARMv7-vfp"; |
| 1460 | } else { |
| 1461 | if (N) |
| 1462 | return "ARMv7-neon"; |
| 1463 | else |
| 1464 | return "ARMv7"; |
| 1465 | } |
| 1466 | default: |
| 1467 | return NULL; |
| 1468 | } |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1469 | return NULL; |
| 1470 | } |
| 1471 | |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 1472 | static const HChar* show_hwcaps_arm64 ( UInt hwcaps ) |
| 1473 | { |
| 1474 | /* Since there are no variants, just insist that hwcaps is zero, |
| 1475 | and declare it invalid otherwise. */ |
| 1476 | if (hwcaps == 0) |
| 1477 | return "baseline"; |
| 1478 | return NULL; |
| 1479 | } |
| 1480 | |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 1481 | static const HChar* show_hwcaps_s390x ( UInt hwcaps ) |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 1482 | { |
sewardj | d07b856 | 2011-04-27 11:58:22 +0000 | [diff] [blame] | 1483 | static const HChar prefix[] = "s390x"; |
florian | 9061eb3 | 2012-12-09 17:53:45 +0000 | [diff] [blame] | 1484 | static const struct { |
| 1485 | UInt hwcaps_bit; |
| 1486 | HChar name[6]; |
| 1487 | } hwcaps_list[] = { |
| 1488 | { VEX_HWCAPS_S390X_LDISP, "ldisp" }, |
| 1489 | { VEX_HWCAPS_S390X_EIMM, "eimm" }, |
| 1490 | { VEX_HWCAPS_S390X_GIE, "gie" }, |
| 1491 | { VEX_HWCAPS_S390X_DFP, "dfp" }, |
| 1492 | { VEX_HWCAPS_S390X_FGX, "fgx" }, |
| 1493 | { VEX_HWCAPS_S390X_STFLE, "stfle" }, |
| 1494 | { VEX_HWCAPS_S390X_ETF2, "etf2" }, |
| 1495 | { VEX_HWCAPS_S390X_ETF3, "etf3" }, |
| 1496 | { VEX_HWCAPS_S390X_STCKF, "stckf" }, |
| 1497 | { VEX_HWCAPS_S390X_FPEXT, "fpext" }, |
| 1498 | { VEX_HWCAPS_S390X_LSC, "lsc" }, |
florian | 78d5ef7 | 2013-05-11 15:02:58 +0000 | [diff] [blame] | 1499 | { VEX_HWCAPS_S390X_PFPO, "pfpo" }, |
sewardj | d07b856 | 2011-04-27 11:58:22 +0000 | [diff] [blame] | 1500 | }; |
florian | 9061eb3 | 2012-12-09 17:53:45 +0000 | [diff] [blame] | 1501 | #define NUM_HWCAPS (sizeof hwcaps_list / sizeof hwcaps_list[0]) |
| 1502 | static HChar buf[sizeof prefix + |
| 1503 | NUM_HWCAPS * (sizeof hwcaps_list[0].name + 1) + |
| 1504 | 1]; // '\0' |
| 1505 | HChar *p; |
| 1506 | UInt i; |
sewardj | d07b856 | 2011-04-27 11:58:22 +0000 | [diff] [blame] | 1507 | |
| 1508 | if (buf[0] != '\0') return buf; /* already constructed */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 1509 | |
sewardj | 652b56a | 2011-04-13 15:38:17 +0000 | [diff] [blame] | 1510 | hwcaps = VEX_HWCAPS_S390X(hwcaps); |
| 1511 | |
sewardj | d07b856 | 2011-04-27 11:58:22 +0000 | [diff] [blame] | 1512 | p = buf + vex_sprintf(buf, "%s", prefix); |
florian | 9061eb3 | 2012-12-09 17:53:45 +0000 | [diff] [blame] | 1513 | for (i = 0 ; i < NUM_HWCAPS; ++i) { |
| 1514 | if (hwcaps & hwcaps_list[i].hwcaps_bit) |
| 1515 | p = p + vex_sprintf(p, "-%s", hwcaps_list[i].name); |
| 1516 | } |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 1517 | |
sewardj | d07b856 | 2011-04-27 11:58:22 +0000 | [diff] [blame] | 1518 | /* If there are no facilities, add "zarch" */ |
| 1519 | if (hwcaps == 0) |
| 1520 | vex_sprintf(p, "-%s", "zarch"); |
| 1521 | |
| 1522 | return buf; |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 1525 | static const HChar* show_hwcaps_mips32 ( UInt hwcaps ) |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1526 | { |
dejanj | c3fee0d | 2013-07-25 09:08:03 +0000 | [diff] [blame] | 1527 | /* MIPS baseline. */ |
petarj | bc7d6f4 | 2013-09-16 18:11:59 +0000 | [diff] [blame] | 1528 | if (VEX_MIPS_COMP_ID(hwcaps) == VEX_PRID_COMP_MIPS) { |
dejanj | c3fee0d | 2013-07-25 09:08:03 +0000 | [diff] [blame] | 1529 | /* MIPS baseline with dspr2. */ |
petarj | bc7d6f4 | 2013-09-16 18:11:59 +0000 | [diff] [blame] | 1530 | if (VEX_MIPS_PROC_DSP2(hwcaps)) { |
dejanj | c3fee0d | 2013-07-25 09:08:03 +0000 | [diff] [blame] | 1531 | return "MIPS-baseline-dspr2"; |
| 1532 | } |
| 1533 | /* MIPS baseline with dsp. */ |
petarj | bc7d6f4 | 2013-09-16 18:11:59 +0000 | [diff] [blame] | 1534 | if (VEX_MIPS_PROC_DSP(hwcaps)) { |
dejanj | c3fee0d | 2013-07-25 09:08:03 +0000 | [diff] [blame] | 1535 | return "MIPS-baseline-dsp"; |
| 1536 | } |
| 1537 | return "MIPS-baseline"; |
| 1538 | } |
| 1539 | |
| 1540 | /* Broadcom baseline. */ |
petarj | bc7d6f4 | 2013-09-16 18:11:59 +0000 | [diff] [blame] | 1541 | if (VEX_MIPS_COMP_ID(hwcaps) == VEX_PRID_COMP_BROADCOM) { |
dejanj | c3fee0d | 2013-07-25 09:08:03 +0000 | [diff] [blame] | 1542 | return "Broadcom-baseline"; |
| 1543 | } |
| 1544 | |
| 1545 | /* Netlogic baseline. */ |
petarj | bc7d6f4 | 2013-09-16 18:11:59 +0000 | [diff] [blame] | 1546 | if (VEX_MIPS_COMP_ID(hwcaps) == VEX_PRID_COMP_NETLOGIC) { |
dejanj | c3fee0d | 2013-07-25 09:08:03 +0000 | [diff] [blame] | 1547 | return "Netlogic-baseline"; |
| 1548 | } |
| 1549 | |
petarj | bc7d6f4 | 2013-09-16 18:11:59 +0000 | [diff] [blame] | 1550 | /* Cavium baseline. */ |
| 1551 | if (VEX_MIPS_COMP_ID(hwcaps) == VEX_PRID_COMP_CAVIUM) { |
| 1552 | return "Cavium-baseline"; |
| 1553 | } |
| 1554 | |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1555 | return NULL; |
| 1556 | } |
| 1557 | |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1558 | static const HChar* show_hwcaps_mips64 ( UInt hwcaps ) |
| 1559 | { |
| 1560 | return "mips64-baseline"; |
| 1561 | } |
| 1562 | |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1563 | /* ---- */ |
florian | 55085f8 | 2012-11-21 00:36:55 +0000 | [diff] [blame] | 1564 | static const HChar* show_hwcaps ( VexArch arch, UInt hwcaps ) |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1565 | { |
| 1566 | switch (arch) { |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1567 | case VexArchX86: return show_hwcaps_x86(hwcaps); |
| 1568 | case VexArchAMD64: return show_hwcaps_amd64(hwcaps); |
| 1569 | case VexArchPPC32: return show_hwcaps_ppc32(hwcaps); |
| 1570 | case VexArchPPC64: return show_hwcaps_ppc64(hwcaps); |
| 1571 | case VexArchARM: return show_hwcaps_arm(hwcaps); |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 1572 | case VexArchARM64: return show_hwcaps_arm64(hwcaps); |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 1573 | case VexArchS390X: return show_hwcaps_s390x(hwcaps); |
| 1574 | case VexArchMIPS32: return show_hwcaps_mips32(hwcaps); |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 1575 | case VexArchMIPS64: return show_hwcaps_mips64(hwcaps); |
sewardj | 5117ce1 | 2006-01-27 21:20:15 +0000 | [diff] [blame] | 1576 | default: return NULL; |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | static Bool are_valid_hwcaps ( VexArch arch, UInt hwcaps ) |
| 1581 | { |
| 1582 | return show_hwcaps(arch,hwcaps) != NULL; |
| 1583 | } |
| 1584 | |
| 1585 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 1586 | /*---------------------------------------------------------------*/ |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 1587 | /*--- end main_main.c ---*/ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 1588 | /*---------------------------------------------------------------*/ |