2 /*--------------------------------------------------------------------*/
3 /*--- The core dispatch loop, for jumping to a code address. ---*/
4 /*--- dispatch-s390x-linux.S ---*/
5 /*--------------------------------------------------------------------*/
8 This file is part of Valgrind, a dynamic binary instrumentation
11 Copyright IBM Corp. 2010-2017
12 Copyright (C) 2011-2017, Florian Krohm (britzel@acm.org)
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 The GNU General Public License is contained in the file COPYING.
32 /* Contributed by Florian Krohm and Christian Borntraeger */
34 #include "pub_core_basics_asm.h"
35 #include "pub_core_dispatch_asm.h"
36 #include "pub_core_transtab_asm.h"
37 #include "libvex_guest_offsets.h"
38 #include "libvex_s390x_common.h"
40 #if defined(VGA_s390x)
42 /*------------------------------------------------------------*/
44 /*--- The dispatch loop. VG_(disp_run_translations) is ---*/
45 /*--- used to run all translations, ---*/
46 /*--- including no-redir ones. ---*/
48 /*------------------------------------------------------------*/
50 /* Convenience definitions for readability */
52 #define SP S390_REGNO_STACK_POINTER
55 #define LR S390_REGNO_LINK_REGISTER
57 /* Location of valgrind's saved FPC register */
58 #define S390_LOC_SAVED_FPC_V S390_OFFSET_SAVED_FPC_V(SP)
60 /* Location of saved R2 register */
61 #define S390_LOC_SAVED_R2 S390_OFFSET_SAVED_R2(SP)
64 /*----------------------------------------------------*/
65 /*--- Entry and preamble (set everything up) ---*/
66 /*----------------------------------------------------*/
69 void VG_(disp_run_translations)( UWord* two_words,
73 Return results are placed in two_words:
75 two_words[0] is set to the TRC
76 two_words[1] is set to the address to patch (in case two_words[0] is
77 VG_TRC_CHAIN_ME_TO_{SLOW,FAST}_EP). Otherwise, it is 0.
81 .globl VG_(disp_run_translations)
82 .type VG_(disp_run_translations), @function
83 VG_(disp_run_translations):
85 /* r2 holds two_words */
86 /* r3 holds pointer to guest_state */
87 /* r4 holds host_addr, i.e. the address of the translation to run */
89 /* Save gprs ABI: r6...r13 and r15 */
93 aghi SP,-S390_INNERLOOP_FRAME_SIZE
95 /* Save fprs: ABI: f8...f15 */
105 /* Load address of guest state into guest state register (r13) */
108 /* Save R2 on stack. In postamble it will be restored such that the
109 return values can be written */
110 stg %r2,S390_LOC_SAVED_R2
112 /* Save valgrind's FPC on stack so postamble can restore
114 stfpc S390_LOC_SAVED_FPC_V
116 /* Load the FPC the way the client code wants it. I.e. pull the
117 value from the guest state. */
118 lfpc OFFSET_s390x_fpc(%r13)
120 /* Jump into the code cache. Chained translations in
121 the code cache run, until for whatever reason, they can't
122 continue. When that happens, the translation in question
123 will jump (or call) to one of the continuation points
124 VG_(cp_...) below. */
128 /*----------------------------------------------------*/
129 /*--- Postamble and return to C code. ---*/
130 /*----------------------------------------------------*/
133 /* At this point, %r0 and %r1 contain two
134 words to be returned to the caller. %r0
135 holds a TRC value, and %r1 optionally may
136 hold another word (for CHAIN_ME exits, the
137 address of the place to patch.) */
139 /* We're leaving. AMD has some code here to check invariants.
140 We don't have (need) that, as we save and restore the FPC register
141 whenever we switch between valgrind proper to client code. */
143 /* Restore valgrind's FPC, as client code may have changed it. */
144 lfpc S390_LOC_SAVED_FPC_V
146 /* Restore %r2 from stack; holds address of two_words */
147 lg %r2,S390_LOC_SAVED_R2
149 stg %r0,0(%r2) /* Store %r0 to two_words[0] */
150 stg %r1,8(%r2) /* Store %r1 to two_words[1] */
152 /* Restore callee-saved registers... */
154 /* Floating-point regs */
164 /* Remove stack frame */
165 aghi SP,S390_INNERLOOP_FRAME_SIZE
167 /* General-purpose regs. This also restores the original link
168 register (r14) and stack pointer (r15). */
175 /*----------------------------------------------------*/
176 /*--- Continuation points ---*/
177 /*----------------------------------------------------*/
179 /* ------ Chain me to slow entry point ------ */
180 .global VG_(disp_cp_chain_me_to_slowEP)
181 VG_(disp_cp_chain_me_to_slowEP):
182 /* When we come here %r1 contains the address of the place to patch.
183 The return values (TRC, address-to-patch) are stored here in
184 %r0 and %r1, respectively */
185 lghi %r0,VG_TRC_CHAIN_ME_TO_SLOW_EP
189 /* ------ Chain me to fast entry point ------ */
190 .global VG_(disp_cp_chain_me_to_fastEP)
191 VG_(disp_cp_chain_me_to_fastEP):
192 /* Identical to VG_(disp_cp_chain_me_to_slowEP), except value of %r0. */
193 lghi %r0,VG_TRC_CHAIN_ME_TO_FAST_EP
197 /* ------ Indirect but boring jump ------ */
198 .global VG_(disp_cp_xindir)
200 /* Where are we going? */
201 lg %r2, OFFSET_s390x_IA(%r13)
203 /* Increment VG_(stats__n_xindirs_32) */
204 larl %r8, VG_(stats__n_xindirs_32)
209 /* Try a fast lookup in the translation cache:
210 Compute offset (not index) into VT_(tt_fast):
212 offset = VG_TT_FAST_HASH(addr) * sizeof(FastCacheEntry)
214 with VG_TT_FAST_HASH(addr) == (addr >> 1) & VG_TT_FAST_MASK
215 and sizeof(FastCacheEntry) == 16
217 offset = ((addr >> 1) & VG_TT_FAST_MASK) << 4
219 offset = ((addr & (VG_TT_FAST_MASK << 1) ) << 3
221 larl %r8, VG_(tt_fast)
222 llill %r5,(VG_TT_FAST_MASK << 1) & 0xffff
223 #if ((( VG_TT_FAST_MASK << 1) & 0xffff0000) >> 16 != 0)
224 iilh %r5,((VG_TT_FAST_MASK << 1) & 0xffff0000) >> 16
228 lg %r11, 8(%r8,%r7) /* .host */
229 cg %r2, 0(%r8,%r7) /* next guest address == .guest ? */
230 jne fast_lookup_failed
232 /* Found a match. Call .host.
233 r11 is an address. There we will find the instrumented client code.
234 That code may modify the guest state register r13. */
236 .long 0x0 /* persuade insn decoders not to speculate past here */
239 /* Increment VG_(stats__n_xindir_misses_32) */
240 larl %r8, VG_(stats__n_xindir_misses_32)
245 lghi %r0,VG_TRC_INNER_FASTMISS
250 /* ------ Assisted jump ------ */
251 .global VG_(disp_cp_xassisted)
252 VG_(disp_cp_xassisted):
253 /* guest-state-pointer contains the TRC. Put the value into the
260 /* ------ Event check failed ------ */
261 .global VG_(disp_cp_evcheck_fail)
262 VG_(disp_cp_evcheck_fail):
263 lghi %r0,VG_TRC_INNER_COUNTERZERO
268 .size VG_(disp_run_translations), .-VG_(disp_run_translations)
270 #endif /* VGA_s390x */
272 /* Let the linker know we don't need an executable stack */
275 /*--------------------------------------------------------------------*/
276 /*--- end dispatch-s390x-linux.S ---*/
277 /*--------------------------------------------------------------------*/