blob: 8ba6d943194463cd9a5387dc815a83a3088bd19e [file] [log] [blame]
sewardj2019a972011-03-07 16:04:07 +00001/* -*- 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
Elliott Hughesed398002017-06-21 14:41:24 -070011 Copyright IBM Corp. 2010-2017
sewardj2019a972011-03-07 16:04:07 +000012
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
floriane88b3c92011-07-05 02:48:39 +000036#include "libvex_basictypes.h" // offsetof
sewardj2019a972011-03-07 16:04:07 +000037#include "guest_generic_bb_to_IR.h" // DisResult
florianad43b3a2012-02-20 15:01:14 +000038#include "libvex_guest_s390x.h" // VexGuestS390XState
sewardj2019a972011-03-07 16:04:07 +000039
florianb4df7682011-07-05 02:09:01 +000040
sewardj2019a972011-03-07 16:04:07 +000041/* Convert one s390 insn to IR. See the type DisOneInstrFn in
Elliott Hughesed398002017-06-21 14:41:24 -070042 guest_generic_bb_to_IR.h. */
sewardj2019a972011-03-07 16:04:07 +000043DisResult disInstr_S390 ( IRSB* irbb,
florianbeac5302014-12-31 12:09:38 +000044 Bool (*resteerOkFn) ( void*, Addr ),
sewardj2019a972011-03-07 16:04:07 +000045 Bool resteerCisOk,
46 void* callback_opaque,
florian8462d112014-09-24 15:18:09 +000047 const UChar* guest_code,
sewardj2019a972011-03-07 16:04:07 +000048 Long delta,
floriand4cc0de2015-01-02 11:44:12 +000049 Addr guest_IP,
sewardj2019a972011-03-07 16:04:07 +000050 VexArch guest_arch,
floriancacba8e2014-12-15 18:58:07 +000051 const VexArchInfo* archinfo,
52 const VexAbiInfo* abiinfo,
sewardj9b769162014-07-24 12:42:03 +000053 VexEndness host_endness,
sewardj442e51a2012-12-06 18:08:04 +000054 Bool sigill_diag );
sewardj2019a972011-03-07 16:04:07 +000055
56/* Used by the optimiser to specialise calls to helpers. */
florian1ff47562012-10-21 02:09:51 +000057IRExpr* guest_s390x_spechelper ( const HChar *function_name,
sewardj2019a972011-03-07 16:04:07 +000058 IRExpr **args,
59 IRStmt **precedingStmts,
60 Int n_precedingStmts);
61
62
sewardjca2c3c72015-02-05 12:53:20 +000063/* Describes to the optimiser which part of the guest state require
sewardj2019a972011-03-07 16:04:07 +000064 precise memory exceptions. This is logically part of the guest
65 state description. */
sewardjca2c3c72015-02-05 12:53:20 +000066Bool guest_s390x_state_requires_precise_mem_exns ( Int, Int,
67 VexRegisterUpdates );
sewardj2019a972011-03-07 16:04:07 +000068
florianb4df7682011-07-05 02:09:01 +000069extern VexGuestLayout s390xGuest_layout;
sewardj2019a972011-03-07 16:04:07 +000070
71
floriane88b3c92011-07-05 02:48:39 +000072#define S390X_GUEST_OFFSET(x) offsetof(VexGuestS390XState, x)
sewardj2019a972011-03-07 16:04:07 +000073
74/*------------------------------------------------------------*/
floriane711c802012-07-15 02:25:55 +000075/*--- Helper functions. ---*/
sewardj2019a972011-03-07 16:04:07 +000076/*------------------------------------------------------------*/
77void s390x_dirtyhelper_EX(ULong torun);
sewardj1e5fea62011-05-17 16:18:36 +000078ULong s390x_dirtyhelper_STCK(ULong *addr);
79ULong s390x_dirtyhelper_STCKF(ULong *addr);
80ULong s390x_dirtyhelper_STCKE(ULong *addr);
florianae884112012-07-27 20:55:01 +000081ULong s390x_dirtyhelper_STFLE(VexGuestS390XState *guest_state, ULong *addr);
floriana0100c92012-07-20 00:06:35 +000082void s390x_dirtyhelper_CUxy(UChar *addr, ULong data, ULong num_bytes);
sewardj2019a972011-03-07 16:04:07 +000083
florian3f8a96a2012-08-05 02:59:55 +000084ULong s390_do_cu12_cu14_helper1(UInt byte1, UInt etf3_and_m3_is_1);
florian6d9b9b22012-08-03 18:35:39 +000085ULong s390_do_cu12_helper2(UInt byte1, UInt byte2, UInt byte3, UInt byte4,
86 ULong stuff);
florian3f8a96a2012-08-05 02:59:55 +000087ULong s390_do_cu14_helper2(UInt byte1, UInt byte2, UInt byte3, UInt byte4,
88 ULong stuff);
floriana0100c92012-07-20 00:06:35 +000089ULong s390_do_cu21(UInt srcvalue, UInt low_surrogate);
florian2a415a12012-07-21 17:41:36 +000090ULong s390_do_cu24(UInt srcvalue, UInt low_surrogate);
florianaf2194f2012-08-06 00:07:54 +000091ULong s390_do_cu41(UInt srcvalue);
florian956194b2012-07-28 22:18:32 +000092ULong s390_do_cu42(UInt srcvalue);
floriane711c802012-07-15 02:25:55 +000093UInt s390_do_cvb(ULong decimal);
94ULong s390_do_cvd(ULong binary);
florian8c88cb62012-08-26 18:58:13 +000095ULong s390_do_ecag(ULong op2addr);
florian78d5ef72013-05-11 15:02:58 +000096UInt s390_do_pfpo(UInt gpr0);
floriane711c802012-07-15 02:25:55 +000097
sewardj2019a972011-03-07 16:04:07 +000098/* The various ways to compute the condition code. */
sewardj2019a972011-03-07 16:04:07 +000099enum {
100 S390_CC_OP_BITWISE = 0,
101 S390_CC_OP_SIGNED_COMPARE = 1,
102 S390_CC_OP_UNSIGNED_COMPARE = 2,
103 S390_CC_OP_SIGNED_ADD_32 = 3,
104 S390_CC_OP_SIGNED_ADD_64 = 4,
105 S390_CC_OP_UNSIGNED_ADD_32 = 5,
106 S390_CC_OP_UNSIGNED_ADD_64 = 6,
107 S390_CC_OP_UNSIGNED_ADDC_32 = 7,
108 S390_CC_OP_UNSIGNED_ADDC_64 = 8,
109 S390_CC_OP_SIGNED_SUB_32 = 9,
110 S390_CC_OP_SIGNED_SUB_64 = 10,
111 S390_CC_OP_UNSIGNED_SUB_32 = 11,
112 S390_CC_OP_UNSIGNED_SUB_64 = 12,
113 S390_CC_OP_UNSIGNED_SUBB_32 = 13,
114 S390_CC_OP_UNSIGNED_SUBB_64 = 14,
115 S390_CC_OP_LOAD_AND_TEST = 15,
116 S390_CC_OP_LOAD_POSITIVE_32 = 16,
117 S390_CC_OP_LOAD_POSITIVE_64 = 17,
florian7700fc92012-01-16 17:25:55 +0000118 S390_CC_OP_TEST_UNDER_MASK_8 = 18,
119 S390_CC_OP_TEST_UNDER_MASK_16 = 19,
120 S390_CC_OP_SHIFT_LEFT_32 = 20,
121 S390_CC_OP_SHIFT_LEFT_64 = 21,
122 S390_CC_OP_INSERT_CHAR_MASK_32 = 22,
123 S390_CC_OP_BFP_RESULT_32 = 23,
124 S390_CC_OP_BFP_RESULT_64 = 24,
125 S390_CC_OP_BFP_RESULT_128 = 25,
126 S390_CC_OP_BFP_32_TO_INT_32 = 26,
127 S390_CC_OP_BFP_64_TO_INT_32 = 27,
128 S390_CC_OP_BFP_128_TO_INT_32 = 28,
129 S390_CC_OP_BFP_32_TO_INT_64 = 29,
130 S390_CC_OP_BFP_64_TO_INT_64 = 30,
131 S390_CC_OP_BFP_128_TO_INT_64 = 31,
132 S390_CC_OP_BFP_TDC_32 = 32,
133 S390_CC_OP_BFP_TDC_64 = 33,
134 S390_CC_OP_BFP_TDC_128 = 34,
florian1c8f7ff2012-09-01 00:12:11 +0000135 S390_CC_OP_SET = 35,
136 S390_CC_OP_BFP_32_TO_UINT_32 = 36,
137 S390_CC_OP_BFP_64_TO_UINT_32 = 37,
138 S390_CC_OP_BFP_128_TO_UINT_32 = 38,
139 S390_CC_OP_BFP_32_TO_UINT_64 = 39,
140 S390_CC_OP_BFP_64_TO_UINT_64 = 40,
florian12390202012-11-10 22:34:14 +0000141 S390_CC_OP_BFP_128_TO_UINT_64 = 41,
floriane38f6412012-12-21 17:32:12 +0000142 S390_CC_OP_DFP_RESULT_64 = 42,
floriance9e3db2012-12-27 20:14:03 +0000143 S390_CC_OP_DFP_RESULT_128 = 43,
144 S390_CC_OP_DFP_TDC_32 = 44,
145 S390_CC_OP_DFP_TDC_64 = 45,
146 S390_CC_OP_DFP_TDC_128 = 46,
147 S390_CC_OP_DFP_TDG_32 = 47,
148 S390_CC_OP_DFP_TDG_64 = 48,
florian5f034622013-01-13 02:29:05 +0000149 S390_CC_OP_DFP_TDG_128 = 49,
150 S390_CC_OP_DFP_64_TO_UINT_32 = 50,
151 S390_CC_OP_DFP_128_TO_UINT_32 = 51,
152 S390_CC_OP_DFP_64_TO_UINT_64 = 52,
153 S390_CC_OP_DFP_128_TO_UINT_64 = 53,
154 S390_CC_OP_DFP_64_TO_INT_32 = 54,
floriana887acd2013-02-08 23:32:54 +0000155 S390_CC_OP_DFP_128_TO_INT_32 = 55,
156 S390_CC_OP_DFP_64_TO_INT_64 = 56,
florian78d5ef72013-05-11 15:02:58 +0000157 S390_CC_OP_DFP_128_TO_INT_64 = 57,
florian7ab421d2013-06-17 21:03:56 +0000158 S390_CC_OP_PFPO_32 = 58,
159 S390_CC_OP_PFPO_64 = 59,
160 S390_CC_OP_PFPO_128 = 60
sewardj2019a972011-03-07 16:04:07 +0000161};
162
163/*------------------------------------------------------------*/
164/*--- Thunk layout ---*/
165/*------------------------------------------------------------*/
166
167/*
168 Z -- value is zero extended to 32 / 64 bit
169 S -- value is sign extended to 32 / 64 bit
170 F -- a binary floating point value
floriancb2b24e2012-12-20 14:31:19 +0000171 D -- a decimal floating point value
sewardj2019a972011-03-07 16:04:07 +0000172
florian19e00772012-09-06 03:13:22 +0000173 +--------------------------------+-----------------------+----------------------+-----------------+
174 | op | cc_dep1 | cc_dep2 | cc_ndep |
175 +--------------------------------+-----------------------+----------------------+-----------------+
176 | S390_CC_OP_BITWISE | Z result | | |
177 | S390_CC_OP_SIGNED_COMPARE | S 1st operand | S 2nd operand | |
178 | S390_CC_OP_UNSIGNED_COMPARE | Z 1st operand | Z 2nd operand | |
179 | S390_CC_OP_SIGNED_ADD_32 | S 1st operand | S 2nd operand | |
180 | S390_CC_OP_SIGNED_ADD_64 | S 1st operand | S 2nd operand | |
181 | S390_CC_OP_UNSIGNED_ADD_32 | Z 1st operand | Z 2nd operand | |
182 | S390_CC_OP_UNSIGNED_ADD_64 | Z 1st operand | Z 2nd operand | |
183 | S390_CC_OP_UNSIGNED_ADDC_32 | Z 1st operand | Z 2nd operand | Z carry in |
184 | S390_CC_OP_UNSIGNED_ADDC_64 | Z 1st operand | Z 2nd operand | Z carry in |
185 | S390_CC_OP_SIGNED_SUB_32 | S left operand | S right operand | |
186 | S390_CC_OP_SIGNED_SUB_64 | S left operand | S right operand | |
187 | S390_CC_OP_UNSIGNED_SUB_32 | Z left operand | Z right operand | |
188 | S390_CC_OP_UNSIGNED_SUB_64 | Z left operand | Z right operand | |
189 | S390_CC_OP_UNSIGNED_SUBB_32 | Z left operand | Z right operand | Z borrow in |
190 | S390_CC_OP_UNSIGNED_SUBB_64 | Z left operand | Z right operand | Z borrow in |
191 | S390_CC_OP_LOAD_AND_TEST | S loaded value | | |
192 | S390_CC_OP_LOAD_POSITIVE_32 | S loaded value | | |
193 | S390_CC_OP_LOAD_POSITIVE_64 | S loaded value | | |
194 | S390_CC_OP_TEST_UNDER_MASK_8 | Z tested value | Z mask | |
195 | S390_CC_OP_TEST_UNDER_MASK_16 | Z tested value | Z mask | |
196 | S390_CC_OP_SHIFT_LEFT_32 | Z value to be shifted | Z shift amount | |
197 | S390_CC_OP_SHIFT_LEFT_64 | Z value to be shifted | Z shift amount | |
198 | S390_CC_OP_INSERT_CHAR_MASK_32 | Z result | Z mask | |
199 | S390_CC_OP_BFP_RESULT_32 | F result | | |
200 | S390_CC_OP_BFP_RESULT_64 | F result | | |
201 | S390_CC_OP_BFP_RESULT_128 | F result hi 64 bits | F result low 64 bits | |
202 | S390_CC_OP_BFP_32_TO_INT_32 | F source | Z rounding mode | |
203 | S390_CC_OP_BFP_64_TO_INT_32 | F source | Z rounding mode | |
204 | S390_CC_OP_BFP_128_TO_INT_32 | F source hi 64 bits | F source low 64 bits | Z rounding mode |
205 | S390_CC_OP_BFP_32_TO_INT_64 | F source | Z rounding mode | |
206 | S390_CC_OP_BFP_64_TO_INT_64 | F source | Z rounding mode | |
207 | S390_CC_OP_BFP_128_TO_INT_64 | F source hi 64 bits | F source low 64 bits | Z rounding mode |
208 | S390_CC_OP_BFP_TDC_32 | F value | Z class | |
209 | S390_CC_OP_BFP_TDC_64 | F value | Z class | |
210 | S390_CC_OP_BFP_TDC_128 | F value hi 64 bits | F value low 64 bits | Z class |
211 | S390_CC_OP_SET | Z condition code | | |
212 | S390_CC_OP_BFP_32_TO_UINT_32 | F source | Z rounding mode | |
213 | S390_CC_OP_BFP_64_TO_UINT_32 | F source | Z rounding mode | |
214 | S390_CC_OP_BFP_128_TO_UINT_32 | F source hi 64 bits | F source low 64 bits | Z rounding mode |
215 | S390_CC_OP_BFP_32_TO_UINT_64 | F source | Z rounding mode | |
216 | S390_CC_OP_BFP_64_TO_UINT_64 | F source | Z rounding mode | |
217 | S390_CC_OP_BFP_128_TO_UINT_64 | F source hi 64 bits | F source low 64 bits | Z rounding mode |
floriancb2b24e2012-12-20 14:31:19 +0000218 | S390_CC_OP_DFP_RESULT_64 | D result | | |
floriane38f6412012-12-21 17:32:12 +0000219 | S390_CC_OP_DFP_RESULT_128 | D result hi 64 bits | D result low 64 bits | |
floriance9e3db2012-12-27 20:14:03 +0000220 | S390_CC_OP_DFP_TDC_32 | D value | Z class | |
221 | S390_CC_OP_DFP_TDC_64 | D value | Z class | |
222 | S390_CC_OP_DFP_TDC_128 | D value hi 64 bits | D value low 64 bits | Z class |
223 | S390_CC_OP_DFP_TDG_32 | D value | Z group | |
224 | S390_CC_OP_DFP_TDG_64 | D value | Z group | |
225 | S390_CC_OP_DFP_TDG_128 | D value hi 64 bits | D value low 64 bits | Z group |
florian5f034622013-01-13 02:29:05 +0000226 | S390_CC_OP_DFP_64_TO_UINT_32 | D source | Z rounding mode | |
227 | S390_CC_OP_DFP_128_TO_UINT_32 | D source hi 64 bits | D source low 64 bits | Z rounding mode |
228 | S390_CC_OP_DFP_64_TO_UINT_64 | D source | Z rounding mode | |
229 | S390_CC_OP_DFP_128_TO_UINT_64 | D source hi 64 bits | D source low 64 bits | Z rounding mode |
florian1fd227c2013-02-08 16:01:23 +0000230 | S390_CC_OP_DFP_64_TO_INT_32 | D source | Z rounding mode | |
231 | S390_CC_OP_DFP_128_TO_INT_32 | D source hi 64 bits | D source low 64 bits | Z rounding mode |
florian5f034622013-01-13 02:29:05 +0000232 | S390_CC_OP_DFP_64_TO_INT_64 | D source | Z rounding mode | |
233 | S390_CC_OP_DFP_128_TO_INT_64 | D source hi 64 bits | D source low 64 bits | Z rounding mode |
florian7ab421d2013-06-17 21:03:56 +0000234 | S390_CC_OP_PFPO_32 | F|D source | Z GR0 low 32 bits | |
florian78d5ef72013-05-11 15:02:58 +0000235 | S390_CC_OP_PFPO_64 | F|D source | Z GR0 low 32 bits | |
236 | S390_CC_OP_PFPO_128 | F|D source hi 64 bits | F|D src low 64 bits | Z GR0 low 32 bits |
florian19e00772012-09-06 03:13:22 +0000237 +--------------------------------+-----------------------+----------------------+-----------------+
sewardj2019a972011-03-07 16:04:07 +0000238*/
239
240/*------------------------------------------------------------*/
florianb4df7682011-07-05 02:09:01 +0000241/*--- Condition code helpers. ---*/
sewardj2019a972011-03-07 16:04:07 +0000242/*------------------------------------------------------------*/
243UInt s390_calculate_cc(ULong cc_op, ULong cc_dep1, ULong cc_dep2,
244 ULong cc_ndep);
sewardj2019a972011-03-07 16:04:07 +0000245UInt s390_calculate_cond(ULong mask, ULong op, ULong dep1, ULong dep2,
246 ULong ndep);
247
248/* Size of special instruction preamble */
249#define S390_SPECIAL_OP_PREAMBLE_SIZE 8
250
251/* Size of special instructions */
252#define S390_SPECIAL_OP_SIZE 2
253
254/* Last target instruction for the EX helper */
255extern ULong last_execute_target;
256
257/*---------------------------------------------------------------*/
258/*--- end guest_s390_defs.h ---*/
259/*---------------------------------------------------------------*/
260
261#endif /* __VEX_GUEST_S390_DEFS_H */