2 /*---------------------------------------------------------------*/
3 /*--- begin guest_ppc_defs.h ---*/
4 /*---------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2004-2017 OpenWorks LLP
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
28 Neither the names of the U.S. Department of Energy nor the
29 University of California nor the names of its contributors may be
30 used to endorse or promote products derived from this software
31 without prior written permission.
34 /* Only to be used within the guest-ppc directory. */
37 #ifndef __VEX_GUEST_PPC_DEFS_H
38 #define __VEX_GUEST_PPC_DEFS_H
40 #include "libvex_basictypes.h"
41 #include "libvex_guest_ppc32.h" // VexGuestPPC32State
42 #include "libvex_guest_ppc64.h" // VexGuestPPC64State
43 #include "guest_generic_bb_to_IR.h" // DisResult
45 /*---------------------------------------------------------*/
46 /*--- ppc to IR conversion ---*/
47 /*---------------------------------------------------------*/
49 /* Convert one ppc insn to IR. See the type DisOneInstrFn in
50 guest_generic_bb_to_IR.h. */
52 DisResult
disInstr_PPC ( IRSB
* irbb
,
53 const UChar
* guest_code
,
57 const VexArchInfo
* archinfo
,
58 const VexAbiInfo
* abiinfo
,
59 VexEndness host_endness
,
62 /* Used by the optimiser to specialise calls to helpers. */
64 IRExpr
* guest_ppc32_spechelper ( const HChar
* function_name
,
66 IRStmt
** precedingStmts
,
67 Int n_precedingStmts
);
70 IRExpr
* guest_ppc64_spechelper ( const HChar
* function_name
,
72 IRStmt
** precedingStmts
,
73 Int n_precedingStmts
);
75 /* Describes to the optimser which part of the guest state require
76 precise memory exceptions. This is logically part of the guest
79 Bool
guest_ppc32_state_requires_precise_mem_exns ( Int
, Int
,
83 Bool
guest_ppc64_state_requires_precise_mem_exns ( Int
, Int
,
87 VexGuestLayout ppc32Guest_layout
;
90 VexGuestLayout ppc64Guest_layout
;
93 /* FP Rounding mode - different encoding to IR */
102 /* Floating point comparison values - different encoding to IR */
113 Enumeration for xer_ca/ov calculation helper functions
116 /* 0 */ PPCG_FLAG_OP_ADD
=0, // addc[o], addic
117 /* 1 */ PPCG_FLAG_OP_ADDE
, // adde[o], addme[o], addze[o]
118 /* 2 */ PPCG_FLAG_OP_DIVW
, // divwo
119 /* 3 */ PPCG_FLAG_OP_DIVWU
, // divwuo
120 /* 4 */ PPCG_FLAG_OP_MULLW
, // mullwo
121 /* 5 */ PPCG_FLAG_OP_NEG
, // nego
122 /* 6 */ PPCG_FLAG_OP_SUBF
, // subfo
123 /* 7 */ PPCG_FLAG_OP_SUBFC
, // subfc[o]
124 /* 8 */ PPCG_FLAG_OP_SUBFE
, // subfe[o], subfme[o], subfze[o]
125 /* 9 */ PPCG_FLAG_OP_SUBFI
, // subfic
126 /* 10 */ PPCG_FLAG_OP_SRAW
, // sraw
127 /* 11 */ PPCG_FLAG_OP_SRAWI
, // srawi
128 /* 12 */ PPCG_FLAG_OP_SRAD
, // srad
129 /* 13 */ PPCG_FLAG_OP_SRADI
, // sradi
130 /* 14 */ PPCG_FLAG_OP_DIVDE
, // divdeo
131 /* 15 */ PPCG_FLAG_OP_DIVWEU
, // divweuo
132 /* 16 */ PPCG_FLAG_OP_DIVWE
, // divweo
133 /* 17 */ PPCG_FLAG_OP_DIVDEU
, // divdeuo
134 /* 18 */ PPCG_FLAG_OP_MULLD
, // mulldo
139 /*---------------------------------------------------------*/
140 /*--- ppc guest helpers ---*/
141 /*---------------------------------------------------------*/
143 /* --- CLEAN HELPERS --- */
145 extern ULong
is_BCDstring128_helper( ULong Signed
, ULong hi64
, ULong low64
);
146 extern ULong
increment_BCDstring32_helper( ULong Signed
,
147 ULong bcd_string
, ULong carry_in
);
148 extern ULong
convert_to_zoned_helper( ULong src_hi
, ULong src_low
,
150 ULong return_upper
);
151 extern ULong
convert_to_national_helper( ULong src
, ULong return_upper
);
152 extern ULong
convert_from_zoned_helper( ULong src_hi
, ULong src_low
);
153 extern ULong
convert_from_floattobf16_helper( ULong src
);
154 extern ULong
convert_from_bf16tofloat_helper( ULong src
);
155 extern ULong
convert_from_national_helper( ULong src_hi
, ULong src_low
);
156 extern ULong
generate_C_FPCC_helper( ULong size
, ULong src_hi
, ULong src
);
157 extern ULong
extract_bits_under_mask_helper( ULong src
, ULong mask
,
159 extern UInt
generate_DFP_FPRF_value_helper( UInt gfield
, ULong exponent
,
162 UInt sign
, UInt T_value_is_zero
);
163 extern UInt
count_bits_under_mask_helper( ULong src
, ULong mask
,
165 extern ULong
deposit_bits_under_mask_helper( ULong src
, ULong mask
);
166 extern ULong
population_count64_helper( ULong src
);
167 extern UInt
vbpermq_clean_helper( ULong vA_high
, ULong vA_low
, ULong vB
);
168 extern ULong
vector_evaluate64_helper( ULong srcA
, ULong srcB
, ULong srcC
,
170 void write_ACC_entry (VexGuestPPC64State
* gst
, UInt offset
, UInt acc
,
171 UInt reg
, UInt
*result
);
172 void get_ACC_entry (VexGuestPPC64State
* gst
, UInt offset
, UInt acc
,
173 UInt reg
, UInt
*result
);
175 extern void vector_gen_pvc_byte_mask_dirty_helper( VexGuestPPC64State
* gst
,
178 UInt rtn_val
, UInt IMM
);
179 extern void vector_gen_pvc_hword_mask_dirty_helper( VexGuestPPC64State
* gst
,
182 UInt rtn_val
, UInt IMM
);
183 extern void vector_gen_pvc_word_mask_dirty_helper( VexGuestPPC64State
* gst
,
186 UInt rtn_val
, UInt IMM
);
187 extern void vector_gen_pvc_dword_mask_dirty_helper( VexGuestPPC64State
* gst
,
190 UInt rtn_val
, UInt IMM
);
192 /* 8-bit XO value from instruction description */
193 #define XVI4GER8 0b00100011
194 #define XVI4GER8PP 0b00100010
195 #define XVI8GER4 0b00000011
196 #define XVI8GER4PP 0b00000010
197 #define XVI8GER4SPP 0b01100011
198 #define XVI16GER2 0b01001011
199 #define XVI16GER2PP 0b01101011
200 #define XVI16GER2S 0b00101011
201 #define XVI16GER2SPP 0b00101010
202 #define XVF16GER2 0b00010011
203 #define XVF16GER2PP 0b00010010
204 #define XVF16GER2PN 0b10010010
205 #define XVF16GER2NP 0b01010010
206 #define XVF16GER2NN 0b11010010
207 #define XVBF16GER2 0b00110011
208 #define XVBF16GER2PP 0b00110010
209 #define XVBF16GER2PN 0b10110010
210 #define XVBF16GER2NP 0b01110010
211 #define XVBF16GER2NN 0b11110010
212 #define XVF32GER 0b00011011
213 #define XVF32GERPP 0b00011010
214 #define XVF32GERPN 0b10011010
215 #define XVF32GERNP 0b01011010
216 #define XVF32GERNN 0b11011010
217 #define XVF64GER 0b00111011
218 #define XVF64GERPP 0b00111010
219 #define XVF64GERPN 0b10111010
220 #define XVF64GERNP 0b01111010
221 #define XVF64GERNN 0b11111010
223 #define INVALD_INST 1
226 #define CPABORT_INST 4
228 /* --- DIRTY HELPERS --- */
230 extern ULong
ppcg_dirtyhelper_MFTB ( void );
232 extern UInt
ppc32g_dirtyhelper_MFSPR_268_269 ( UInt
);
234 extern UInt
ppc32g_dirtyhelper_MFSPR_287 ( void );
236 extern void ppc32g_dirtyhelper_LVS ( VexGuestPPC32State
* gst
,
237 UInt vD_idx
, UInt sh
,
240 extern void ppc64g_dirtyhelper_LVS ( VexGuestPPC64State
* gst
,
241 UInt vD_idx
, UInt sh
,
245 extern void vsx_matrix_4bit_ger_dirty_helper( VexGuestPPC64State
* gst
,
247 ULong srcA_hi
, ULong srcA_lo
,
248 ULong srcB_hi
, ULong srcB_lo
,
250 extern void vsx_matrix_8bit_ger_dirty_helper( VexGuestPPC64State
* gst
,
252 ULong srcA_hi
, ULong srcA_lo
,
253 ULong srcB_hi
, ULong srcB_lo
,
255 extern void vsx_matrix_16bit_ger_dirty_helper( VexGuestPPC64State
* gst
,
257 ULong srcA_hi
, ULong srcA_lo
,
258 ULong srcB_hi
, ULong srcB_lo
,
260 extern void vsx_matrix_16bit_float_ger_dirty_helper( VexGuestPPC64State
* gst
,
267 extern void vsx_matrix_32bit_float_ger_dirty_helper( VexGuestPPC64State
* gst
,
274 extern void vsx_matrix_64bit_float_ger_dirty_helper( VexGuestPPC64State
* gst
,
281 extern ULong
darn_dirty_helper ( UInt L
);
282 extern UInt
copy_paste_abort_dirty_helper(UInt addr
, UInt op
);
284 #endif /* ndef __VEX_GUEST_PPC_DEFS_H */
286 /* SCV flag defines. Must be consistently defined here and in
287 coregrind/pub_core_syscall.h,in the do_syscall_WRK() assembly code in
288 coregrind/m_syscall.c and coregrind/m_syswrap/syscall-ppc64le-linux.S
293 /*---------------------------------------------------------------*/
294 /*--- end guest_ppc_defs.h ---*/
295 /*---------------------------------------------------------------*/