2 /*--------------------------------------------------------------------*/
3 /*--- The core dispatch loop, for jumping to a code address. ---*/
4 /*--- dispatch-arm-linux.S ---*/
5 /*--------------------------------------------------------------------*/
8 This file is part of Valgrind, a dynamic binary instrumentation
11 Copyright (C) 2008-2013 Evan Geller
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 #if defined(VGP_arm_linux)
35 #include "pub_core_basics_asm.h"
36 #include "pub_core_dispatch_asm.h"
37 #include "pub_core_transtab_asm.h"
38 #include "libvex_guest_offsets.h" /* for OFFSET_arm_R* */
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,
59 .global VG_(disp_run_translations)
60 VG_(disp_run_translations):
65 /* The number of regs in this list needs to be even, in
66 order to keep the stack 8-aligned. */
67 push {r0, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}
69 /* set FPSCR to vex-required default value */
73 /* Set up the guest state pointer */
76 /* and jump into the code cache. Chained translations in
77 the code cache run, until for whatever reason, they can't
78 continue. When that happens, the translation in question
79 will jump (or call) to one of the continuation points
84 /*----------------------------------------------------*/
85 /*--- Postamble and exit. ---*/
86 /*----------------------------------------------------*/
89 /* At this point, r1 and r2 contain two
90 words to be returned to the caller. r1
91 holds a TRC value, and r2 optionally may
92 hold another word (for CHAIN_ME exits, the
93 address of the place to patch.) */
95 /* We're leaving. Check that nobody messed with
96 FPSCR in ways we don't expect. */
98 bic r4, #0xF8000000 /* mask out NZCV and QC */
99 bic r4, #0x0000009F /* mask out IDC,IXC,UFC,OFC,DZC,IOC */
101 beq remove_frame /* we're OK */
102 /* otherwise we have an invariant violation */
103 movw r1, #VG_TRC_INVARIANT_FAILED
108 /* Restore int regs, including importantly r0 (two_words) */
109 pop {r0, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}
110 /* Stash return values */
115 /*----------------------------------------------------*/
116 /*--- Continuation points ---*/
117 /*----------------------------------------------------*/
119 /* ------ Chain me to slow entry point ------ */
120 .global VG_(disp_cp_chain_me_to_slowEP)
121 VG_(disp_cp_chain_me_to_slowEP):
122 /* We got called. The return address indicates
123 where the patching needs to happen. Collect
124 the return address and, exit back to C land,
125 handing the caller the pair (Chain_me_S, RA) */
126 mov r1, #VG_TRC_CHAIN_ME_TO_SLOW_EP
128 /* 4 = movw r12, lo16(disp_cp_chain_me_to_slowEP)
129 4 = movt r12, hi16(disp_cp_chain_me_to_slowEP)
134 /* ------ Chain me to fast entry point ------ */
135 .global VG_(disp_cp_chain_me_to_fastEP)
136 VG_(disp_cp_chain_me_to_fastEP):
137 /* We got called. The return address indicates
138 where the patching needs to happen. Collect
139 the return address and, exit back to C land,
140 handing the caller the pair (Chain_me_F, RA) */
141 mov r1, #VG_TRC_CHAIN_ME_TO_FAST_EP
143 /* 4 = movw r12, lo16(disp_cp_chain_me_to_fastEP)
144 4 = movt r12, hi16(disp_cp_chain_me_to_fastEP)
149 /* ------ Indirect but boring jump ------ */
150 .global VG_(disp_cp_xindir)
152 /* Where are we going? */
153 ldr r0, [r8, #OFFSET_arm_R15T]
156 movw r1, #:lower16:vgPlain_stats__n_xindirs_32
157 movt r1, #:upper16:vgPlain_stats__n_xindirs_32
162 /* try a fast lookup in the translation cache */
163 // r0 = next guest, r1,r2,r3,r4 scratch
164 movw r1, #VG_TT_FAST_MASK // r1 = VG_TT_FAST_MASK
165 movw r4, #:lower16:VG_(tt_fast)
167 and r2, r1, r0, LSR #1 // r2 = entry #
168 movt r4, #:upper16:VG_(tt_fast) // r4 = &VG_(tt_fast)
170 add r1, r4, r2, LSL #3 // r1 = &tt_fast[entry#]
172 ldrd r4, r5, [r1, #0] // r4 = .guest, r5 = .host
176 // jump to host if lookup succeeded
179 /* otherwise the fast lookup failed */
180 /* RM ME -- stats only */
181 movw r1, #:lower16:vgPlain_stats__n_xindir_misses_32
182 movt r1, #:upper16:vgPlain_stats__n_xindir_misses_32
187 mov r1, #VG_TRC_INNER_FASTMISS
191 /* ------ Assisted jump ------ */
192 .global VG_(disp_cp_xassisted)
193 VG_(disp_cp_xassisted):
194 /* r8 contains the TRC */
199 /* ------ Event check failed ------ */
200 .global VG_(disp_cp_evcheck_fail)
201 VG_(disp_cp_evcheck_fail):
202 mov r1, #VG_TRC_INNER_COUNTERZERO
207 .size VG_(disp_run_translations), .-VG_(disp_run_translations)
209 /* Let the linker know we don't need an executable stack */
210 .section .note.GNU-stack,"",%progbits
212 #endif // defined(VGP_arm_linux)
214 /*--------------------------------------------------------------------*/
215 /*--- end dispatch-arm-linux.S ---*/
216 /*--------------------------------------------------------------------*/