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 | |
| 11 | Copyright IBM Corp. 2010-2011 |
| 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 "libvex_ir.h" // IRSB (needed by bb_to_IR.h) |
| 38 | #include "libvex.h" // VexArch (needed by bb_to_IR.h) |
| 39 | #include "guest_generic_bb_to_IR.h" // DisResult |
| 40 | |
florian | b4df768 | 2011-07-05 02:09:01 +0000 | [diff] [blame] | 41 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 42 | /* Convert one s390 insn to IR. See the type DisOneInstrFn in |
| 43 | bb_to_IR.h. */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 44 | DisResult disInstr_S390 ( IRSB* irbb, |
| 45 | Bool put_IP, |
| 46 | Bool (*resteerOkFn) ( void*, Addr64 ), |
| 47 | Bool resteerCisOk, |
| 48 | void* callback_opaque, |
| 49 | UChar* guest_code, |
| 50 | Long delta, |
| 51 | Addr64 guest_IP, |
| 52 | VexArch guest_arch, |
| 53 | VexArchInfo* archinfo, |
| 54 | VexAbiInfo* abiinfo, |
| 55 | Bool host_bigendian ); |
| 56 | |
| 57 | /* Used by the optimiser to specialise calls to helpers. */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 58 | IRExpr* guest_s390x_spechelper ( HChar *function_name, |
| 59 | IRExpr **args, |
| 60 | IRStmt **precedingStmts, |
| 61 | Int n_precedingStmts); |
| 62 | |
| 63 | |
| 64 | /* Describes to the optimser which part of the guest state require |
| 65 | precise memory exceptions. This is logically part of the guest |
| 66 | state description. */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 67 | Bool guest_s390x_state_requires_precise_mem_exns ( Int, Int ); |
| 68 | |
florian | b4df768 | 2011-07-05 02:09:01 +0000 | [diff] [blame] | 69 | extern VexGuestLayout s390xGuest_layout; |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 70 | |
| 71 | |
florian | e88b3c9 | 2011-07-05 02:48:39 +0000 | [diff] [blame] | 72 | #define S390X_GUEST_OFFSET(x) offsetof(VexGuestS390XState, x) |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 73 | |
| 74 | /*------------------------------------------------------------*/ |
| 75 | /*--- Dirty Helper functions. ---*/ |
| 76 | /*------------------------------------------------------------*/ |
florian | 30e8901 | 2011-08-08 18:22:58 +0000 | [diff] [blame] | 77 | void s390x_dirtyhelper_00(VexGuestS390XState *guest_state); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 78 | void s390x_dirtyhelper_EX(ULong torun); |
sewardj | 1e5fea6 | 2011-05-17 16:18:36 +0000 | [diff] [blame] | 79 | ULong s390x_dirtyhelper_STCK(ULong *addr); |
| 80 | ULong s390x_dirtyhelper_STCKF(ULong *addr); |
| 81 | ULong s390x_dirtyhelper_STCKE(ULong *addr); |
florian | 933065d | 2011-07-11 01:48:02 +0000 | [diff] [blame] | 82 | ULong s390x_dirtyhelper_STFLE(VexGuestS390XState *guest_state, HWord addr); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 83 | |
| 84 | /* The various ways to compute the condition code. */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 85 | enum { |
| 86 | S390_CC_OP_BITWISE = 0, |
| 87 | S390_CC_OP_SIGNED_COMPARE = 1, |
| 88 | S390_CC_OP_UNSIGNED_COMPARE = 2, |
| 89 | S390_CC_OP_SIGNED_ADD_32 = 3, |
| 90 | S390_CC_OP_SIGNED_ADD_64 = 4, |
| 91 | S390_CC_OP_UNSIGNED_ADD_32 = 5, |
| 92 | S390_CC_OP_UNSIGNED_ADD_64 = 6, |
| 93 | S390_CC_OP_UNSIGNED_ADDC_32 = 7, |
| 94 | S390_CC_OP_UNSIGNED_ADDC_64 = 8, |
| 95 | S390_CC_OP_SIGNED_SUB_32 = 9, |
| 96 | S390_CC_OP_SIGNED_SUB_64 = 10, |
| 97 | S390_CC_OP_UNSIGNED_SUB_32 = 11, |
| 98 | S390_CC_OP_UNSIGNED_SUB_64 = 12, |
| 99 | S390_CC_OP_UNSIGNED_SUBB_32 = 13, |
| 100 | S390_CC_OP_UNSIGNED_SUBB_64 = 14, |
| 101 | S390_CC_OP_LOAD_AND_TEST = 15, |
| 102 | S390_CC_OP_LOAD_POSITIVE_32 = 16, |
| 103 | S390_CC_OP_LOAD_POSITIVE_64 = 17, |
florian | 7700fc9 | 2012-01-16 17:25:55 +0000 | [diff] [blame^] | 104 | S390_CC_OP_TEST_UNDER_MASK_8 = 18, |
| 105 | S390_CC_OP_TEST_UNDER_MASK_16 = 19, |
| 106 | S390_CC_OP_SHIFT_LEFT_32 = 20, |
| 107 | S390_CC_OP_SHIFT_LEFT_64 = 21, |
| 108 | S390_CC_OP_INSERT_CHAR_MASK_32 = 22, |
| 109 | S390_CC_OP_BFP_RESULT_32 = 23, |
| 110 | S390_CC_OP_BFP_RESULT_64 = 24, |
| 111 | S390_CC_OP_BFP_RESULT_128 = 25, |
| 112 | S390_CC_OP_BFP_32_TO_INT_32 = 26, |
| 113 | S390_CC_OP_BFP_64_TO_INT_32 = 27, |
| 114 | S390_CC_OP_BFP_128_TO_INT_32 = 28, |
| 115 | S390_CC_OP_BFP_32_TO_INT_64 = 29, |
| 116 | S390_CC_OP_BFP_64_TO_INT_64 = 30, |
| 117 | S390_CC_OP_BFP_128_TO_INT_64 = 31, |
| 118 | S390_CC_OP_BFP_TDC_32 = 32, |
| 119 | S390_CC_OP_BFP_TDC_64 = 33, |
| 120 | S390_CC_OP_BFP_TDC_128 = 34, |
| 121 | S390_CC_OP_SET = 35 |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | /*------------------------------------------------------------*/ |
| 125 | /*--- Thunk layout ---*/ |
| 126 | /*------------------------------------------------------------*/ |
| 127 | |
| 128 | /* |
| 129 | Z -- value is zero extended to 32 / 64 bit |
| 130 | S -- value is sign extended to 32 / 64 bit |
| 131 | F -- a binary floating point value |
| 132 | |
| 133 | +--------------------------------+-----------------------+----------------------+-------------+ |
| 134 | | op | cc_dep1 | cc_dep2 | cc_ndep | |
| 135 | +--------------------------------+-----------------------+----------------------+-------------+ |
| 136 | | S390_CC_OP_BITWISE | Z result | | | |
| 137 | | S390_CC_OP_SIGNED_COMPARE | S 1st operand | S 2nd operand | | |
| 138 | | S390_CC_OP_UNSIGNED_COMPARE | Z 1st operand | Z 2nd operand | | |
| 139 | | S390_CC_OP_SIGNED_ADD_32 | S 1st operand | S 2nd operand | | |
| 140 | | S390_CC_OP_SIGNED_ADD_64 | S 1st operand | S 2nd operand | | |
| 141 | | S390_CC_OP_UNSIGNED_ADD_32 | Z 1st operand | Z 2nd operand | | |
| 142 | | S390_CC_OP_UNSIGNED_ADD_64 | Z 1st operand | Z 2nd operand | | |
| 143 | | S390_CC_OP_UNSIGNED_ADDC_32 | Z 1st operand | Z 2nd operand | Z carry in | |
| 144 | | S390_CC_OP_UNSIGNED_ADDC_64 | Z 1st operand | Z 2nd operand | Z carry in | |
| 145 | | S390_CC_OP_SIGNED_SUB_32 | S left operand | S right operand | | |
| 146 | | S390_CC_OP_SIGNED_SUB_64 | S left operand | S right operand | | |
| 147 | | S390_CC_OP_UNSIGNED_SUB_32 | Z left operand | Z right operand | | |
| 148 | | S390_CC_OP_UNSIGNED_SUB_64 | Z left operand | Z right operand | | |
| 149 | | S390_CC_OP_UNSIGNED_SUBB_32 | Z left operand | Z right operand | Z borrow in | |
| 150 | | S390_CC_OP_UNSIGNED_SUBB_64 | Z left operand | Z right operand | Z borrow in | |
| 151 | | S390_CC_OP_LOAD_AND_TEST | S loaded value | | | |
| 152 | | S390_CC_OP_LOAD_POSITIVE_32 | S loaded value | | | |
| 153 | | S390_CC_OP_LOAD_POSITIVE_64 | S loaded value | | | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 154 | | S390_CC_OP_TEST_UNDER_MASK_8 | Z tested value | Z mask | | |
| 155 | | S390_CC_OP_TEST_UNDER_MASK_16 | Z tested value | Z mask | | |
| 156 | | S390_CC_OP_SHIFT_LEFT_32 | Z value to be shifted | Z shift amount | | |
| 157 | | S390_CC_OP_SHIFT_LEFT_64 | Z value to be shifted | Z shift amount | | |
| 158 | | S390_CC_OP_INSERT_CHAR_MASK_32 | Z result | Z mask | | |
| 159 | | S390_CC_OP_BFP_RESULT_32 | F result | | | |
| 160 | | S390_CC_OP_BFP_RESULT_64 | F result | | | |
| 161 | | S390_CC_OP_BFP_RESULT_128 | F result hi 64 bits | F result low 64 bits | | |
| 162 | | S390_CC_OP_BFP_32_TO_INT_32 | F source | | | |
| 163 | | S390_CC_OP_BFP_64_TO_INT_32 | F source | | | |
| 164 | | S390_CC_OP_BFP_128_TO_INT_32 | F source hi 64 bits | | | |
| 165 | | S390_CC_OP_BFP_32_TO_INT_64 | F source | | | |
| 166 | | S390_CC_OP_BFP_64_TO_INT_64 | F source | | | |
| 167 | | S390_CC_OP_BFP_128_TO_INT_64 | F source hi 64 bits | | | |
| 168 | | S390_CC_OP_BFP_TDC_32 | F value | Z class | | |
| 169 | | S390_CC_OP_BFP_TDC_64 | F value | Z class | | |
| 170 | | S390_CC_OP_BFP_TDC_128 | F value hi 64 bits | F value low 64 bits | Z class | |
| 171 | | S390_CC_OP_SET | Z condition code | | | |
| 172 | +--------------------------------+-----------------------+----------------------+-------------+ |
| 173 | */ |
| 174 | |
| 175 | /*------------------------------------------------------------*/ |
florian | b4df768 | 2011-07-05 02:09:01 +0000 | [diff] [blame] | 176 | /*--- Condition code helpers. ---*/ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 177 | /*------------------------------------------------------------*/ |
| 178 | UInt s390_calculate_cc(ULong cc_op, ULong cc_dep1, ULong cc_dep2, |
| 179 | ULong cc_ndep); |
| 180 | UInt s390_calculate_icc(ULong op, ULong dep1, ULong dep2); |
| 181 | UInt s390_calculate_cond(ULong mask, ULong op, ULong dep1, ULong dep2, |
| 182 | ULong ndep); |
| 183 | |
| 184 | /* Size of special instruction preamble */ |
| 185 | #define S390_SPECIAL_OP_PREAMBLE_SIZE 8 |
| 186 | |
| 187 | /* Size of special instructions */ |
| 188 | #define S390_SPECIAL_OP_SIZE 2 |
| 189 | |
| 190 | /* Last target instruction for the EX helper */ |
| 191 | extern ULong last_execute_target; |
| 192 | |
| 193 | /*---------------------------------------------------------------*/ |
| 194 | /*--- end guest_s390_defs.h ---*/ |
| 195 | /*---------------------------------------------------------------*/ |
| 196 | |
| 197 | #endif /* __VEX_GUEST_S390_DEFS_H */ |