1 /* Low level interface to valgrind, for the remote server for GDB integrated
4 Free Software Foundation, Inc.
6 This file is part of VALGRIND.
7 It has been inspired from a file from gdbserver in gdb 6.6.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
29 #include "pub_core_machine.h"
30 #include "pub_core_threadstate.h"
31 #include "pub_core_transtab.h"
32 #include "pub_core_gdbserver.h"
33 #include "pub_core_debuginfo.h"
35 #include "valgrind_low.h"
37 #include "libvex_guest_arm64.h"
39 static struct reg regs
[] = {
100 { "v26", 5472, 128 },
101 { "v27", 5600, 128 },
102 { "v28", 5728, 128 },
103 { "v29", 5856, 128 },
104 { "v30", 5984, 128 },
105 { "v31", 6112, 128 },
106 { "fpsr", 6240, 32 },
107 { "fpcr", 6272, 32 },
110 static const char *expedite_regs
[] = { "x29", "sp", "pc", 0 };
112 #define num_regs (sizeof (regs) / sizeof (regs[0]))
115 CORE_ADDR
get_pc (void)
119 collect_register_by_name ("pc", &pc
);
121 dlog(1, "stop pc is %p\n", (void *) pc
);
126 void set_pc (CORE_ADDR newpc
)
129 supply_register_by_name ("pc", &newpc
, &mod
);
131 dlog(1, "set pc to %p\n", C2v (newpc
));
133 dlog(1, "set pc not changed %p\n", C2v (newpc
));
136 /* store registers in the guest state (gdbserver_to_valgrind)
137 or fetch register from the guest state (valgrind_to_gdbserver). */
139 void transfer_register (ThreadId tid
, int abs_regno
, void * buf
,
140 transfer_direction dir
, int size
, Bool
*mod
)
142 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
143 int set
= abs_regno
/ num_regs
;
144 int regno
= abs_regno
% num_regs
;
147 VexGuestARM64State
* arm
= (VexGuestARM64State
*) get_arch (set
, tst
);
150 // numbers here have to match the order of regs above
151 // Attention: gdb order does not match valgrind order.
152 case 0: VG_(transfer
) (&arm
->guest_X0
, buf
, dir
, size
, mod
); break;
153 case 1: VG_(transfer
) (&arm
->guest_X1
, buf
, dir
, size
, mod
); break;
154 case 2: VG_(transfer
) (&arm
->guest_X2
, buf
, dir
, size
, mod
); break;
155 case 3: VG_(transfer
) (&arm
->guest_X3
, buf
, dir
, size
, mod
); break;
156 case 4: VG_(transfer
) (&arm
->guest_X4
, buf
, dir
, size
, mod
); break;
157 case 5: VG_(transfer
) (&arm
->guest_X5
, buf
, dir
, size
, mod
); break;
158 case 6: VG_(transfer
) (&arm
->guest_X6
, buf
, dir
, size
, mod
); break;
159 case 7: VG_(transfer
) (&arm
->guest_X7
, buf
, dir
, size
, mod
); break;
160 case 8: VG_(transfer
) (&arm
->guest_X8
, buf
, dir
, size
, mod
); break;
161 case 9: VG_(transfer
) (&arm
->guest_X9
, buf
, dir
, size
, mod
); break;
162 case 10: VG_(transfer
) (&arm
->guest_X10
, buf
, dir
, size
, mod
); break;
163 case 11: VG_(transfer
) (&arm
->guest_X11
, buf
, dir
, size
, mod
); break;
164 case 12: VG_(transfer
) (&arm
->guest_X12
, buf
, dir
, size
, mod
); break;
165 case 13: VG_(transfer
) (&arm
->guest_X13
, buf
, dir
, size
, mod
); break;
166 case 14: VG_(transfer
) (&arm
->guest_X14
, buf
, dir
, size
, mod
); break;
167 case 15: VG_(transfer
) (&arm
->guest_X15
, buf
, dir
, size
, mod
); break;
168 case 16: VG_(transfer
) (&arm
->guest_X16
, buf
, dir
, size
, mod
); break;
169 case 17: VG_(transfer
) (&arm
->guest_X17
, buf
, dir
, size
, mod
); break;
170 case 18: VG_(transfer
) (&arm
->guest_X18
, buf
, dir
, size
, mod
); break;
171 case 19: VG_(transfer
) (&arm
->guest_X19
, buf
, dir
, size
, mod
); break;
172 case 20: VG_(transfer
) (&arm
->guest_X20
, buf
, dir
, size
, mod
); break;
173 case 21: VG_(transfer
) (&arm
->guest_X21
, buf
, dir
, size
, mod
); break;
174 case 22: VG_(transfer
) (&arm
->guest_X22
, buf
, dir
, size
, mod
); break;
175 case 23: VG_(transfer
) (&arm
->guest_X23
, buf
, dir
, size
, mod
); break;
176 case 24: VG_(transfer
) (&arm
->guest_X24
, buf
, dir
, size
, mod
); break;
177 case 25: VG_(transfer
) (&arm
->guest_X25
, buf
, dir
, size
, mod
); break;
178 case 26: VG_(transfer
) (&arm
->guest_X26
, buf
, dir
, size
, mod
); break;
179 case 27: VG_(transfer
) (&arm
->guest_X27
, buf
, dir
, size
, mod
); break;
180 case 28: VG_(transfer
) (&arm
->guest_X28
, buf
, dir
, size
, mod
); break;
181 case 29: VG_(transfer
) (&arm
->guest_X29
, buf
, dir
, size
, mod
); break;
182 case 30: VG_(transfer
) (&arm
->guest_X30
, buf
, dir
, size
, mod
); break;
183 case 31: VG_(transfer
) (&arm
->guest_XSP
, buf
, dir
, size
, mod
); break;
184 case 32: VG_(transfer
) (&arm
->guest_PC
, buf
, dir
, size
, mod
); break;
185 case 33: *mod
= False
; break; // GDBTD cpsr what to do for arm64 ???
187 case 34: VG_(transfer
) (&arm
->guest_Q0
, buf
, dir
, size
, mod
); break;
188 case 35: VG_(transfer
) (&arm
->guest_Q1
, buf
, dir
, size
, mod
); break;
189 case 36: VG_(transfer
) (&arm
->guest_Q2
, buf
, dir
, size
, mod
); break;
190 case 37: VG_(transfer
) (&arm
->guest_Q3
, buf
, dir
, size
, mod
); break;
191 case 38: VG_(transfer
) (&arm
->guest_Q4
, buf
, dir
, size
, mod
); break;
192 case 39: VG_(transfer
) (&arm
->guest_Q5
, buf
, dir
, size
, mod
); break;
193 case 40: VG_(transfer
) (&arm
->guest_Q6
, buf
, dir
, size
, mod
); break;
194 case 41: VG_(transfer
) (&arm
->guest_Q7
, buf
, dir
, size
, mod
); break;
195 case 42: VG_(transfer
) (&arm
->guest_Q8
, buf
, dir
, size
, mod
); break;
196 case 43: VG_(transfer
) (&arm
->guest_Q9
, buf
, dir
, size
, mod
); break;
197 case 44: VG_(transfer
) (&arm
->guest_Q10
, buf
, dir
, size
, mod
); break;
198 case 45: VG_(transfer
) (&arm
->guest_Q11
, buf
, dir
, size
, mod
); break;
199 case 46: VG_(transfer
) (&arm
->guest_Q12
, buf
, dir
, size
, mod
); break;
200 case 47: VG_(transfer
) (&arm
->guest_Q13
, buf
, dir
, size
, mod
); break;
201 case 48: VG_(transfer
) (&arm
->guest_Q14
, buf
, dir
, size
, mod
); break;
202 case 49: VG_(transfer
) (&arm
->guest_Q15
, buf
, dir
, size
, mod
); break;
203 case 50: VG_(transfer
) (&arm
->guest_Q16
, buf
, dir
, size
, mod
); break;
204 case 51: VG_(transfer
) (&arm
->guest_Q17
, buf
, dir
, size
, mod
); break;
205 case 52: VG_(transfer
) (&arm
->guest_Q18
, buf
, dir
, size
, mod
); break;
206 case 53: VG_(transfer
) (&arm
->guest_Q19
, buf
, dir
, size
, mod
); break;
207 case 54: VG_(transfer
) (&arm
->guest_Q20
, buf
, dir
, size
, mod
); break;
208 case 55: VG_(transfer
) (&arm
->guest_Q21
, buf
, dir
, size
, mod
); break;
209 case 56: VG_(transfer
) (&arm
->guest_Q22
, buf
, dir
, size
, mod
); break;
210 case 57: VG_(transfer
) (&arm
->guest_Q23
, buf
, dir
, size
, mod
); break;
211 case 58: VG_(transfer
) (&arm
->guest_Q24
, buf
, dir
, size
, mod
); break;
212 case 59: VG_(transfer
) (&arm
->guest_Q25
, buf
, dir
, size
, mod
); break;
213 case 60: VG_(transfer
) (&arm
->guest_Q26
, buf
, dir
, size
, mod
); break;
214 case 61: VG_(transfer
) (&arm
->guest_Q27
, buf
, dir
, size
, mod
); break;
215 case 62: VG_(transfer
) (&arm
->guest_Q28
, buf
, dir
, size
, mod
); break;
216 case 63: VG_(transfer
) (&arm
->guest_Q29
, buf
, dir
, size
, mod
); break;
217 case 64: VG_(transfer
) (&arm
->guest_Q30
, buf
, dir
, size
, mod
); break;
218 case 65: VG_(transfer
) (&arm
->guest_Q31
, buf
, dir
, size
, mod
); break;
220 /* The VEX ARM64 FPSR representation is not the same as the
221 architecturally defined representation. Hence use conversion
222 functions to convert to/from it.
223 VEX FPSR only models QC (bit 27), and uses a 64 bits to store
224 this FPSR QC bit. So, we need to transfer from/to the lowest
225 significant part of the ULong that VEX provides/needs,
226 as GDB expects or gives only 4 bytes. */
227 if (dir
== valgrind_to_gdbserver
) {
228 ULong fpsr64
= LibVEX_GuestARM64_get_fpsr(arm
);
229 UInt fpsr
= (UInt
)fpsr64
;
230 VG_(transfer
) (&fpsr
, buf
, dir
, size
, mod
);
234 VG_(transfer
) ((UInt
*)&fpsr
, buf
, dir
, size
, mod
);
236 LibVEX_GuestARM64_set_fpsr(arm
, fpsr64
);
237 /* resync the cache with the part of fpsr that VEX represents. */
238 fpsr64
= LibVEX_GuestARM64_get_fpsr(arm
);
240 VG_(transfer
) (&fpsr
, buf
, valgrind_to_gdbserver
, size
, mod
);
244 case 67: VG_(transfer
) (&arm
->guest_FPCR
, buf
, dir
, size
, mod
); break;
245 default: vg_assert(0);
250 const char* target_xml (Bool shadow_mode
)
256 return "arm-with-vfpv3-valgrind.xml";
258 return "arm-with-vfpv3.xml";
263 static CORE_ADDR
** target_get_dtv (ThreadState
*tst
)
265 VexGuestARM64State
* arm64
= (VexGuestARM64State
*)&tst
->arch
.vex
;
266 // arm64 dtv is pointed to by TPIDR_EL0.
267 return (CORE_ADDR
**)((CORE_ADDR
)arm64
->guest_TPIDR_EL0
);
270 static struct valgrind_target_ops low_target
= {
282 void arm64_init_architecture (struct valgrind_target_ops
*target
)
284 *target
= low_target
;
285 set_register_cache (regs
, num_regs
);
286 gdbserver_expedite_regs
= expedite_regs
;