sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
| 2 | |
| 3 | /*---------------------------------------------------------------*/ |
| 4 | /*--- begin guest_s390_defs.h ---*/ |
| 5 | /*---------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
| 8 | This file is part of Valgrind, a dynamic binary instrumentation |
| 9 | framework. |
| 10 | |
florian | 61f23c1 | 2012-08-06 18:33:21 +0000 | [diff] [blame] | 11 | Copyright IBM Corp. 2010-2012 |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 12 | |
| 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. |
| 17 | |
| 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 |
| 26 | 02110-1301, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | /* Contributed by Florian Krohm */ |
| 32 | |
| 33 | #ifndef __VEX_GUEST_S390_DEFS_H |
| 34 | #define __VEX_GUEST_S390_DEFS_H |
| 35 | |
florian | e88b3c9 | 2011-07-05 02:48:39 +0000 | [diff] [blame] | 36 | #include "libvex_basictypes.h" // offsetof |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 37 | #include "guest_generic_bb_to_IR.h" // DisResult |
florian | ad43b3a | 2012-02-20 15:01:14 +0000 | [diff] [blame] | 38 | #include "libvex_guest_s390x.h" // VexGuestS390XState |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 39 | |
florian | b4df768 | 2011-07-05 02:09:01 +0000 | [diff] [blame] | 40 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 41 | /* Convert one s390 insn to IR. See the type DisOneInstrFn in |
| 42 | bb_to_IR.h. */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 43 | DisResult disInstr_S390 ( IRSB* irbb, |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 44 | Bool (*resteerOkFn) ( void*, Addr64 ), |
| 45 | Bool resteerCisOk, |
| 46 | void* callback_opaque, |
| 47 | UChar* guest_code, |
| 48 | Long delta, |
| 49 | Addr64 guest_IP, |
| 50 | VexArch guest_arch, |
| 51 | VexArchInfo* archinfo, |
| 52 | VexAbiInfo* abiinfo, |
sewardj | 442e51a | 2012-12-06 18:08:04 +0000 | [diff] [blame] | 53 | Bool host_bigendian, |
| 54 | Bool sigill_diag ); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 55 | |
| 56 | /* Used by the optimiser to specialise calls to helpers. */ |
florian | 1ff4756 | 2012-10-21 02:09:51 +0000 | [diff] [blame] | 57 | IRExpr* guest_s390x_spechelper ( const HChar *function_name, |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 58 | IRExpr **args, |
| 59 | IRStmt **precedingStmts, |
| 60 | Int n_precedingStmts); |
| 61 | |
| 62 | |
| 63 | /* Describes to the optimser which part of the guest state require |
| 64 | precise memory exceptions. This is logically part of the guest |
| 65 | state description. */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 66 | Bool guest_s390x_state_requires_precise_mem_exns ( Int, Int ); |
| 67 | |
florian | b4df768 | 2011-07-05 02:09:01 +0000 | [diff] [blame] | 68 | extern VexGuestLayout s390xGuest_layout; |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 69 | |
| 70 | |
florian | e88b3c9 | 2011-07-05 02:48:39 +0000 | [diff] [blame] | 71 | #define S390X_GUEST_OFFSET(x) offsetof(VexGuestS390XState, x) |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 72 | |
| 73 | /*------------------------------------------------------------*/ |
florian | e711c80 | 2012-07-15 02:25:55 +0000 | [diff] [blame] | 74 | /*--- Helper functions. ---*/ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 75 | /*------------------------------------------------------------*/ |
| 76 | void s390x_dirtyhelper_EX(ULong torun); |
sewardj | 1e5fea6 | 2011-05-17 16:18:36 +0000 | [diff] [blame] | 77 | ULong s390x_dirtyhelper_STCK(ULong *addr); |
| 78 | ULong s390x_dirtyhelper_STCKF(ULong *addr); |
| 79 | ULong s390x_dirtyhelper_STCKE(ULong *addr); |
florian | ae88411 | 2012-07-27 20:55:01 +0000 | [diff] [blame] | 80 | ULong s390x_dirtyhelper_STFLE(VexGuestS390XState *guest_state, ULong *addr); |
florian | a0100c9 | 2012-07-20 00:06:35 +0000 | [diff] [blame] | 81 | void s390x_dirtyhelper_CUxy(UChar *addr, ULong data, ULong num_bytes); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 82 | |
florian | 3f8a96a | 2012-08-05 02:59:55 +0000 | [diff] [blame] | 83 | ULong s390_do_cu12_cu14_helper1(UInt byte1, UInt etf3_and_m3_is_1); |
florian | 6d9b9b2 | 2012-08-03 18:35:39 +0000 | [diff] [blame] | 84 | ULong s390_do_cu12_helper2(UInt byte1, UInt byte2, UInt byte3, UInt byte4, |
| 85 | ULong stuff); |
florian | 3f8a96a | 2012-08-05 02:59:55 +0000 | [diff] [blame] | 86 | ULong s390_do_cu14_helper2(UInt byte1, UInt byte2, UInt byte3, UInt byte4, |
| 87 | ULong stuff); |
florian | a0100c9 | 2012-07-20 00:06:35 +0000 | [diff] [blame] | 88 | ULong s390_do_cu21(UInt srcvalue, UInt low_surrogate); |
florian | 2a415a1 | 2012-07-21 17:41:36 +0000 | [diff] [blame] | 89 | ULong s390_do_cu24(UInt srcvalue, UInt low_surrogate); |
florian | af2194f | 2012-08-06 00:07:54 +0000 | [diff] [blame] | 90 | ULong s390_do_cu41(UInt srcvalue); |
florian | 956194b | 2012-07-28 22:18:32 +0000 | [diff] [blame] | 91 | ULong s390_do_cu42(UInt srcvalue); |
florian | e711c80 | 2012-07-15 02:25:55 +0000 | [diff] [blame] | 92 | UInt s390_do_cvb(ULong decimal); |
| 93 | ULong s390_do_cvd(ULong binary); |
florian | 8c88cb6 | 2012-08-26 18:58:13 +0000 | [diff] [blame] | 94 | ULong s390_do_ecag(ULong op2addr); |
florian | e711c80 | 2012-07-15 02:25:55 +0000 | [diff] [blame] | 95 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 96 | /* The various ways to compute the condition code. */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 97 | enum { |
| 98 | S390_CC_OP_BITWISE = 0, |
| 99 | S390_CC_OP_SIGNED_COMPARE = 1, |
| 100 | S390_CC_OP_UNSIGNED_COMPARE = 2, |
| 101 | S390_CC_OP_SIGNED_ADD_32 = 3, |
| 102 | S390_CC_OP_SIGNED_ADD_64 = 4, |
| 103 | S390_CC_OP_UNSIGNED_ADD_32 = 5, |
| 104 | S390_CC_OP_UNSIGNED_ADD_64 = 6, |
| 105 | S390_CC_OP_UNSIGNED_ADDC_32 = 7, |
| 106 | S390_CC_OP_UNSIGNED_ADDC_64 = 8, |
| 107 | S390_CC_OP_SIGNED_SUB_32 = 9, |
| 108 | S390_CC_OP_SIGNED_SUB_64 = 10, |
| 109 | S390_CC_OP_UNSIGNED_SUB_32 = 11, |
| 110 | S390_CC_OP_UNSIGNED_SUB_64 = 12, |
| 111 | S390_CC_OP_UNSIGNED_SUBB_32 = 13, |
| 112 | S390_CC_OP_UNSIGNED_SUBB_64 = 14, |
| 113 | S390_CC_OP_LOAD_AND_TEST = 15, |
| 114 | S390_CC_OP_LOAD_POSITIVE_32 = 16, |
| 115 | S390_CC_OP_LOAD_POSITIVE_64 = 17, |
florian | 7700fc9 | 2012-01-16 17:25:55 +0000 | [diff] [blame] | 116 | S390_CC_OP_TEST_UNDER_MASK_8 = 18, |
| 117 | S390_CC_OP_TEST_UNDER_MASK_16 = 19, |
| 118 | S390_CC_OP_SHIFT_LEFT_32 = 20, |
| 119 | S390_CC_OP_SHIFT_LEFT_64 = 21, |
| 120 | S390_CC_OP_INSERT_CHAR_MASK_32 = 22, |
| 121 | S390_CC_OP_BFP_RESULT_32 = 23, |
| 122 | S390_CC_OP_BFP_RESULT_64 = 24, |
| 123 | S390_CC_OP_BFP_RESULT_128 = 25, |
| 124 | S390_CC_OP_BFP_32_TO_INT_32 = 26, |
| 125 | S390_CC_OP_BFP_64_TO_INT_32 = 27, |
| 126 | S390_CC_OP_BFP_128_TO_INT_32 = 28, |
| 127 | S390_CC_OP_BFP_32_TO_INT_64 = 29, |
| 128 | S390_CC_OP_BFP_64_TO_INT_64 = 30, |
| 129 | S390_CC_OP_BFP_128_TO_INT_64 = 31, |
| 130 | S390_CC_OP_BFP_TDC_32 = 32, |
| 131 | S390_CC_OP_BFP_TDC_64 = 33, |
| 132 | S390_CC_OP_BFP_TDC_128 = 34, |
florian | 1c8f7ff | 2012-09-01 00:12:11 +0000 | [diff] [blame] | 133 | S390_CC_OP_SET = 35, |
| 134 | S390_CC_OP_BFP_32_TO_UINT_32 = 36, |
| 135 | S390_CC_OP_BFP_64_TO_UINT_32 = 37, |
| 136 | S390_CC_OP_BFP_128_TO_UINT_32 = 38, |
| 137 | S390_CC_OP_BFP_32_TO_UINT_64 = 39, |
| 138 | S390_CC_OP_BFP_64_TO_UINT_64 = 40, |
florian | 1239020 | 2012-11-10 22:34:14 +0000 | [diff] [blame] | 139 | S390_CC_OP_BFP_128_TO_UINT_64 = 41, |
florian | e38f641 | 2012-12-21 17:32:12 +0000 | [diff] [blame^] | 140 | S390_CC_OP_DFP_RESULT_64 = 42, |
| 141 | S390_CC_OP_DFP_RESULT_128 = 43 |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | /*------------------------------------------------------------*/ |
| 145 | /*--- Thunk layout ---*/ |
| 146 | /*------------------------------------------------------------*/ |
| 147 | |
| 148 | /* |
| 149 | Z -- value is zero extended to 32 / 64 bit |
| 150 | S -- value is sign extended to 32 / 64 bit |
| 151 | F -- a binary floating point value |
florian | cb2b24e | 2012-12-20 14:31:19 +0000 | [diff] [blame] | 152 | D -- a decimal floating point value |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 153 | |
florian | 19e0077 | 2012-09-06 03:13:22 +0000 | [diff] [blame] | 154 | +--------------------------------+-----------------------+----------------------+-----------------+ |
| 155 | | op | cc_dep1 | cc_dep2 | cc_ndep | |
| 156 | +--------------------------------+-----------------------+----------------------+-----------------+ |
| 157 | | S390_CC_OP_BITWISE | Z result | | | |
| 158 | | S390_CC_OP_SIGNED_COMPARE | S 1st operand | S 2nd operand | | |
| 159 | | S390_CC_OP_UNSIGNED_COMPARE | Z 1st operand | Z 2nd operand | | |
| 160 | | S390_CC_OP_SIGNED_ADD_32 | S 1st operand | S 2nd operand | | |
| 161 | | S390_CC_OP_SIGNED_ADD_64 | S 1st operand | S 2nd operand | | |
| 162 | | S390_CC_OP_UNSIGNED_ADD_32 | Z 1st operand | Z 2nd operand | | |
| 163 | | S390_CC_OP_UNSIGNED_ADD_64 | Z 1st operand | Z 2nd operand | | |
| 164 | | S390_CC_OP_UNSIGNED_ADDC_32 | Z 1st operand | Z 2nd operand | Z carry in | |
| 165 | | S390_CC_OP_UNSIGNED_ADDC_64 | Z 1st operand | Z 2nd operand | Z carry in | |
| 166 | | S390_CC_OP_SIGNED_SUB_32 | S left operand | S right operand | | |
| 167 | | S390_CC_OP_SIGNED_SUB_64 | S left operand | S right operand | | |
| 168 | | S390_CC_OP_UNSIGNED_SUB_32 | Z left operand | Z right operand | | |
| 169 | | S390_CC_OP_UNSIGNED_SUB_64 | Z left operand | Z right operand | | |
| 170 | | S390_CC_OP_UNSIGNED_SUBB_32 | Z left operand | Z right operand | Z borrow in | |
| 171 | | S390_CC_OP_UNSIGNED_SUBB_64 | Z left operand | Z right operand | Z borrow in | |
| 172 | | S390_CC_OP_LOAD_AND_TEST | S loaded value | | | |
| 173 | | S390_CC_OP_LOAD_POSITIVE_32 | S loaded value | | | |
| 174 | | S390_CC_OP_LOAD_POSITIVE_64 | S loaded value | | | |
| 175 | | S390_CC_OP_TEST_UNDER_MASK_8 | Z tested value | Z mask | | |
| 176 | | S390_CC_OP_TEST_UNDER_MASK_16 | Z tested value | Z mask | | |
| 177 | | S390_CC_OP_SHIFT_LEFT_32 | Z value to be shifted | Z shift amount | | |
| 178 | | S390_CC_OP_SHIFT_LEFT_64 | Z value to be shifted | Z shift amount | | |
| 179 | | S390_CC_OP_INSERT_CHAR_MASK_32 | Z result | Z mask | | |
| 180 | | S390_CC_OP_BFP_RESULT_32 | F result | | | |
| 181 | | S390_CC_OP_BFP_RESULT_64 | F result | | | |
| 182 | | S390_CC_OP_BFP_RESULT_128 | F result hi 64 bits | F result low 64 bits | | |
| 183 | | S390_CC_OP_BFP_32_TO_INT_32 | F source | Z rounding mode | | |
| 184 | | S390_CC_OP_BFP_64_TO_INT_32 | F source | Z rounding mode | | |
| 185 | | S390_CC_OP_BFP_128_TO_INT_32 | F source hi 64 bits | F source low 64 bits | Z rounding mode | |
| 186 | | S390_CC_OP_BFP_32_TO_INT_64 | F source | Z rounding mode | | |
| 187 | | S390_CC_OP_BFP_64_TO_INT_64 | F source | Z rounding mode | | |
| 188 | | S390_CC_OP_BFP_128_TO_INT_64 | F source hi 64 bits | F source low 64 bits | Z rounding mode | |
| 189 | | S390_CC_OP_BFP_TDC_32 | F value | Z class | | |
| 190 | | S390_CC_OP_BFP_TDC_64 | F value | Z class | | |
| 191 | | S390_CC_OP_BFP_TDC_128 | F value hi 64 bits | F value low 64 bits | Z class | |
| 192 | | S390_CC_OP_SET | Z condition code | | | |
| 193 | | S390_CC_OP_BFP_32_TO_UINT_32 | F source | Z rounding mode | | |
| 194 | | S390_CC_OP_BFP_64_TO_UINT_32 | F source | Z rounding mode | | |
| 195 | | S390_CC_OP_BFP_128_TO_UINT_32 | F source hi 64 bits | F source low 64 bits | Z rounding mode | |
| 196 | | S390_CC_OP_BFP_32_TO_UINT_64 | F source | Z rounding mode | | |
| 197 | | S390_CC_OP_BFP_64_TO_UINT_64 | F source | Z rounding mode | | |
| 198 | | S390_CC_OP_BFP_128_TO_UINT_64 | F source hi 64 bits | F source low 64 bits | Z rounding mode | |
florian | cb2b24e | 2012-12-20 14:31:19 +0000 | [diff] [blame] | 199 | | S390_CC_OP_DFP_RESULT_64 | D result | | | |
florian | e38f641 | 2012-12-21 17:32:12 +0000 | [diff] [blame^] | 200 | | S390_CC_OP_DFP_RESULT_128 | D result hi 64 bits | D result low 64 bits | | |
florian | 19e0077 | 2012-09-06 03:13:22 +0000 | [diff] [blame] | 201 | +--------------------------------+-----------------------+----------------------+-----------------+ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 202 | */ |
| 203 | |
| 204 | /*------------------------------------------------------------*/ |
florian | b4df768 | 2011-07-05 02:09:01 +0000 | [diff] [blame] | 205 | /*--- Condition code helpers. ---*/ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 206 | /*------------------------------------------------------------*/ |
| 207 | UInt s390_calculate_cc(ULong cc_op, ULong cc_dep1, ULong cc_dep2, |
| 208 | ULong cc_ndep); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 209 | UInt s390_calculate_cond(ULong mask, ULong op, ULong dep1, ULong dep2, |
| 210 | ULong ndep); |
| 211 | |
| 212 | /* Size of special instruction preamble */ |
| 213 | #define S390_SPECIAL_OP_PREAMBLE_SIZE 8 |
| 214 | |
| 215 | /* Size of special instructions */ |
| 216 | #define S390_SPECIAL_OP_SIZE 2 |
| 217 | |
| 218 | /* Last target instruction for the EX helper */ |
| 219 | extern ULong last_execute_target; |
| 220 | |
| 221 | /*---------------------------------------------------------------*/ |
| 222 | /*--- end guest_s390_defs.h ---*/ |
| 223 | /*---------------------------------------------------------------*/ |
| 224 | |
| 225 | #endif /* __VEX_GUEST_S390_DEFS_H */ |