blob: 9918403d5e8dbbbd3433b1808fab47b6f33b4b0c [file] [log] [blame]
sewardjc68994d2012-06-07 09:23:23 +00001
2/*--------------------------------------------------------------------*/
3/*--- The core dispatch loop, for jumping to a code address. ---*/
4/*--- dispatch-mips-linux.S ---*/
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 (C) 2000-2017 RT-RK
sewardjc68994d2012-06-07 09:23:23 +000012 mips-valgrind@rt-rk.com
13
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.
18
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.
23
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
27 02111-1307, USA.
28
29 The GNU General Public License is contained in the file COPYING.
30*/
31
florian3f1d6132015-09-30 20:30:48 +000032#include "pub_core_basics_asm.h"
sewardjc68994d2012-06-07 09:23:23 +000033
34#if defined(VGP_mips32_linux)
35
sewardjc68994d2012-06-07 09:23:23 +000036#include "pub_core_dispatch_asm.h"
37#include "pub_core_transtab_asm.h"
38#include "libvex_guest_offsets.h" /* for OFFSET_mips_PC */
39
40
41/*------------------------------------------------------------*/
42/*--- ---*/
43/*--- The dispatch loop. VG_(disp_run_translations) is ---*/
44/*--- used to run all translations, ---*/
45/*--- including no-redir ones. ---*/
46/*--- ---*/
47/*------------------------------------------------------------*/
48
49/*----------------------------------------------------*/
50/*--- Entry and preamble (set everything up) ---*/
51/*----------------------------------------------------*/
52
53/* signature:
54void VG_(disp_run_translations)( UWord* two_words,
55 void* guest_state,
56 Addr host_addr );
57*/
58
59.text
60.globl VG_(disp_run_translations)
61VG_(disp_run_translations):
62 /* a0 ($4) holds two_words */
63 /* a1 ($5) holds guest_state */
64 /* a2 ($6) holds host_addr */
65
66 /* New stack frame. Stack must remain 8 aligned (at least) */
petarj1b1420b2012-10-22 17:43:57 +000067 addiu $29, -64
sewardjc68994d2012-06-07 09:23:23 +000068
69 /* Save ra */
petarj1b1420b2012-10-22 17:43:57 +000070 sw $31, 16($29)
sewardjc68994d2012-06-07 09:23:23 +000071
72 /* ... and s0 - s7 */
petarj1b1420b2012-10-22 17:43:57 +000073 sw $16, 20($29)
74 sw $17, 24($29)
75 sw $18, 28($29)
76 sw $19, 32($29)
77 sw $20, 36($29)
78 sw $21, 40($29)
79 sw $22, 44($29)
80 sw $23, 48($29)
sewardjc68994d2012-06-07 09:23:23 +000081
82 /* ... and gp, fp/s8 */
petarj1b1420b2012-10-22 17:43:57 +000083 sw $28, 52($29)
84 sw $30, 56($29)
sewardjc68994d2012-06-07 09:23:23 +000085
86 /* Save a0 ($4) on stack. In postamble it will be restored such that the
87 return values can be written */
petarj1b1420b2012-10-22 17:43:57 +000088 sw $4, 60($29)
sewardjc68994d2012-06-07 09:23:23 +000089
petarj4df0bfc2013-02-27 23:17:33 +000090 /* Load address of guest state into guest state register ($23) */
91 move $23, $5
sewardjc68994d2012-06-07 09:23:23 +000092
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
97 VG_(cp_...) below. */
98 jr $6
99 /*NOTREACHED*/
100
101/*----------------------------------------------------*/
102/*--- Postamble and exit. ---*/
103/*----------------------------------------------------*/
104
105postamble:
petarj4df0bfc2013-02-27 23:17:33 +0000106 /* 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
sewardjc68994d2012-06-07 09:23:23 +0000109 hold another word (for CHAIN_ME exits, the
110 address of the place to patch.) */
111
112 /* Restore $4 from stack; holds address of two_words */
petarj1b1420b2012-10-22 17:43:57 +0000113 lw $4, 60($29)
sewardjc68994d2012-06-07 09:23:23 +0000114 sw $2, 0($4) /* Store $2 to two_words[0] */
115 sw $3, 4($4) /* Store $3 to two_words[1] */
116
117 /* Restore callee-saved registers... */
118
119 /* Restore ra */
petarj1b1420b2012-10-22 17:43:57 +0000120 lw $31, 16($29)
sewardjc68994d2012-06-07 09:23:23 +0000121
122 /* ... and s0 - s7 */
petarj1b1420b2012-10-22 17:43:57 +0000123 lw $16, 20($29)
124 lw $17, 24($29)
125 lw $18, 28($29)
126 lw $19, 32($29)
127 lw $20, 36($29)
128 lw $21, 40($29)
129 lw $22, 44($29)
130 lw $23, 48($29)
sewardjc68994d2012-06-07 09:23:23 +0000131
132 /* ... and gp, fp/s8 */
petarj1b1420b2012-10-22 17:43:57 +0000133 lw $28, 52($29)
134 lw $30, 56($29)
sewardjc68994d2012-06-07 09:23:23 +0000135
petarj1b1420b2012-10-22 17:43:57 +0000136 addiu $29, 64 /* stack_size */
sewardjc68994d2012-06-07 09:23:23 +0000137 jr $31
138 nop
139
140/*----------------------------------------------------*/
141/*--- Continuation points ---*/
142/*----------------------------------------------------*/
143
144/* ------ Chain me to slow entry point ------ */
145.global VG_(disp_cp_chain_me_to_slowEP)
146VG_(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
152 move $3, $31
153 /* 8 = mkLoadImm_EXACTLY2or5
154 4 = jalr $9
155 4 = nop */
156 addiu $3, $3, -16
157 b postamble
158
159/* ------ Chain me to slow entry point ------ */
160.global VG_(disp_cp_chain_me_to_fastEP)
161VG_(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
167 move $3, $31
168 /* 8 = mkLoadImm_EXACTLY2or5
169 4 = jalr $9
170 4 = nop */
171 addiu $3, $3, -16
172 b postamble
173
174/* ------ Indirect but boring jump ------ */
175.global VG_(disp_cp_xindir)
176VG_(disp_cp_xindir):
177 /* Where are we going? */
petarj4df0bfc2013-02-27 23:17:33 +0000178 lw $11, OFFSET_mips32_PC($23)
sewardjc68994d2012-06-07 09:23:23 +0000179
180 lw $13, vgPlain_stats__n_xindirs_32
181 addiu $13, $13, 0x1
182 sw $13, vgPlain_stats__n_xindirs_32
183
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 */
187
188 move $14, $11
189 li $12, VG_TT_FAST_MASK
190 srl $14, $14, 2
191 and $14, $14, $12
192 sll $14, $14, 3
193
194 /* t2 = (addr of VG_(tt_fast)) + t1 */
195 la $13, VG_(tt_fast)
196 addu $13, $13, $14
197
198 lw $12, 0($13) /* t3 = VG_(tt_fast)[hash] :: ULong* */
Elliott Hughesa0664b92017-04-18 17:46:52 -0700199 addiu $13, $13, 4
sewardjc68994d2012-06-07 09:23:23 +0000200 lw $25, 0($13) /* little-endian, so comparing 1st 32bit word */
201 nop
202
203check:
204 bne $12, $11, fast_lookup_failed
205 /* run the translation */
206 jr $25
207 .long 0x0 /* persuade insn decoders not to speculate past here */
208
209fast_lookup_failed:
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
214 addiu $13, $13, 0x1
215 sw $13, vgPlain_stats__n_xindirs_32
216 li $2, VG_TRC_INNER_FASTMISS
217 li $3, 0
218 b postamble
219
220/* ------ Assisted jump ------ */
221 .global VG_(disp_cp_xassisted)
222VG_(disp_cp_xassisted):
223 /* guest-state-pointer contains the TRC. Put the value into the
224 return register */
petarj4df0bfc2013-02-27 23:17:33 +0000225 move $2, $23
sewardjc68994d2012-06-07 09:23:23 +0000226 move $3, $0
227 b postamble
228
229/* ------ Event check failed ------ */
230 .global VG_(disp_cp_evcheck_fail)
231VG_(disp_cp_evcheck_fail):
232 li $2, VG_TRC_INNER_COUNTERZERO
233 move $3, $0
234 b postamble
235
236.size VG_(disp_run_translations), .-VG_(disp_run_translations)
237
sewardjc68994d2012-06-07 09:23:23 +0000238#endif // defined(VGP_mips32_linux)
florian3f1d6132015-09-30 20:30:48 +0000239
240/* Let the linker know we don't need an executable stack */
241MARK_STACK_NO_EXEC
242
sewardjc68994d2012-06-07 09:23:23 +0000243/*--------------------------------------------------------------------*/
244/*--- end ---*/
245/*--------------------------------------------------------------------*/