2 /*--------------------------------------------------------------------*/
3 /*--- The core dispatch loop, for jumping to a code address. ---*/
4 /*--- dispatch-mips64-linux.S ---*/
5 /*--------------------------------------------------------------------*/
8 This file is part of Valgrind, a dynamic binary instrumentation
11 Copyright (C) 2000-2017 RT-RK
12 mips-valgrind@rt-rk.com
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 #include "pub_core_basics_asm.h"
34 #if defined(VGP_mips64_linux)
36 #include "pub_core_dispatch_asm.h"
37 #include "pub_core_transtab_asm.h"
38 #include "libvex_guest_offsets.h" /* for OFFSET_mips_PC */
41 /*------------------------------------------------------------*/
43 /*--- The dispatch loop. VG_(disp_run_translations) is ---*/
44 /*--- used to run all translations, ---*/
45 /*--- including no-redir ones. ---*/
47 /*------------------------------------------------------------*/
49 /*----------------------------------------------------*/
50 /*--- Entry and preamble (set everything up) ---*/
51 /*----------------------------------------------------*/
54 void VG_(disp_run_translations)( UWord* two_words,
60 .globl VG_(disp_run_translations)
61 VG_(disp_run_translations):
62 /* a0 ($4) holds two_words */
63 /* a1 ($5) holds guest_state */
64 /* a2 ($6) holds host_addr */
66 /* New stack frame. Stack must remain 16 aligned (at least) */
82 /* ... and gp, fp/s8 */
86 /* Save a0 ($4) on stack. In postamble it will be restored such that the
87 return values can be written */
90 /* Load address of guest state into guest state register ($23) */
93 /* and jump into the code cache. Chained translations in
94 the code cache run, until for whatever reason, they can't
95 continue. When that happens, the translation in question
96 will jump (or call) to one of the continuation points
101 /*----------------------------------------------------*/
102 /*--- Postamble and exit. ---*/
103 /*----------------------------------------------------*/
106 /* At this point, $2 and $3 contain two
107 words to be returned to the caller. $2
108 holds a TRC value, and $3 optionally may
109 hold another word (for CHAIN_ME exits, the
110 address of the place to patch.) */
112 /* Restore $4 from stack; holds address of two_words */
114 sd $2, 0($4) /* Store $2 to two_words[0] */
115 sd $3, 8($4) /* Store $3 to two_words[1] */
117 /* Restore callee-saved registers... */
122 /* ... and s0 - s7 */
132 /* ... and gp, fp/s8 */
136 daddiu $29, 176 /* stack_size */
140 /*----------------------------------------------------*/
141 /*--- Continuation points ---*/
142 /*----------------------------------------------------*/
144 /* ------ Chain me to slow entry point ------ */
145 .global VG_(disp_cp_chain_me_to_slowEP)
146 VG_(disp_cp_chain_me_to_slowEP):
147 /* We got called. The return address indicates
148 where the patching needs to happen. Collect
149 the return address and, exit back to C land,
150 handing the caller the pair (Chain_me_S, RA) */
151 li $2, VG_TRC_CHAIN_ME_TO_SLOW_EP
153 /* 8 = mkLoadImm_EXACTLY2or6
159 /* ------ Chain me to slow entry point ------ */
160 .global VG_(disp_cp_chain_me_to_fastEP)
161 VG_(disp_cp_chain_me_to_fastEP):
162 /* We got called. The return address indicates
163 where the patching needs to happen. Collect
164 the return address and, exit back to C land,
165 handing the caller the pair (Chain_me_S, RA) */
166 li $2, VG_TRC_CHAIN_ME_TO_FAST_EP
168 /* 8 = mkLoadImm_EXACTLY2or6
174 /* ------ Indirect but boring jump ------ */
175 .global VG_(disp_cp_xindir)
177 /* Where are we going? */
178 ld $11, OFFSET_mips64_PC($23)
180 lw $13, vgPlain_stats__n_xindirs_32
182 sw $13, vgPlain_stats__n_xindirs_32
184 /* try a fast lookup in the translation cache */
185 /* t1 = VG_TT_FAST_HASH(addr) * sizeof(ULong*)
186 = (t8 >> 2 & VG_TT_FAST_MASK) << 3 */
189 li $12, VG_TT_FAST_MASK
194 /* t2 = (addr of VG_(tt_fast)) + t1 */
195 dla $13, VG_(tt_fast)
198 ld $12, 0($13) /* t3 = VG_(tt_fast)[hash] :: ULong* */
200 ld $25, 0($13) /* little-endian, so comparing 1st 32bit word */
204 bne $12, $11, fast_lookup_failed
205 /* run the translation */
207 .long 0x0 /* persuade insn decoders not to speculate past here */
210 /* %PC is up to date */
211 /* back out decrement of the dispatch counter */
212 /* hold dispatch_ctr in t0 (r8) */
213 lw $13, vgPlain_stats__n_xindirs_32
215 sw $13, vgPlain_stats__n_xindirs_32
216 li $2, VG_TRC_INNER_FASTMISS
220 /* ------ Assisted jump ------ */
221 .global VG_(disp_cp_xassisted)
222 VG_(disp_cp_xassisted):
223 /* guest-state-pointer contains the TRC. Put the value into the
229 /* ------ Event check failed ------ */
230 .global VG_(disp_cp_evcheck_fail)
231 VG_(disp_cp_evcheck_fail):
232 li $2, VG_TRC_INNER_COUNTERZERO
236 .size VG_(disp_run_translations), .-VG_(disp_run_translations)
238 #endif // defined(VGP_mips64_linux)
240 /* Let the linker know we don't need an executable stack */
243 /*--------------------------------------------------------------------*/
245 /*--------------------------------------------------------------------*/