1112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/* Low level interface to valgrind, for the remote server for GDB integrated
2112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   in valgrind.
3112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   Copyright (C) 2012
4112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   Free Software Foundation, Inc.
5112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
6112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   This file is part of VALGRIND.
7112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   It has been inspired from a file from gdbserver in gdb 6.6.
8112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
9112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   This program is free software; you can redistribute it and/or modify
10112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   it under the terms of the GNU General Public License as published by
11112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   the Free Software Foundation; either version 2 of the License, or
12112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   (at your option) any later version.
13112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
14112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   This program is distributed in the hope that it will be useful,
15112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   but WITHOUT ANY WARRANTY; without even the implied warranty of
16112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   GNU General Public License for more details.
18112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
19112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   You should have received a copy of the GNU General Public License
20112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   along with this program; if not, write to the Free Software
21112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   Foundation, Inc., 51 Franklin Street, Fifth Floor,
22112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   Boston, MA 02110-1301, USA. */
23112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
24112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "server.h"
25112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "target.h"
26112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "regdef.h"
27112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "regcache.h"
28112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
29112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_aspacemgr.h"
30112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_threadstate.h"
31112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_transtab.h"
32112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_gdbserver.h"
33112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
34112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "valgrind_low.h"
35112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
36112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "libvex_guest_tilegx.h"
37112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#define  REG_ONE(_n)  { "r"#_n, 64 * (_n), 64 }
38112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#define  REG_ONE_NAME(_n, _name) { _name, 64 * (_n), 64 }
39112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
40112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstatic struct reg regs[] = {
41112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(0),
42112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(1),
43112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(2),
44112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(3),
45112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(4),
46112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(5),
47112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(6),
48112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(7),
49112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(8),
50112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(9),
51112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
52112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(10),
53112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(11),
54112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(12),
55112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(13),
56112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(14),
57112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(15),
58112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(16),
59112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(17),
60112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(18),
61112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(19),
62112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
63112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(20),
64112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(21),
65112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(22),
66112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(23),
67112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(24),
68112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(25),
69112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(26),
70112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(27),
71112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(28),
72112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(29),
73112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
74112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(30),
75112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(31),
76112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(32),
77112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(33),
78112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(34),
79112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(35),
80112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(36),
81112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(37),
82112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(38),
83112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(39),
84112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
85112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(40),
86112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(41),
87112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(42),
88112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(43),
89112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(44),
90112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(45),
91112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(46),
92112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(47),
93112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(48),
94112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(49),
95112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
96112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(50),
97112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(51),
98112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(52),
99112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(53),
100112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
101112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE_NAME(54, "sp"),
102112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE_NAME(55, "lr"),
103112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(56),
104112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(57),
105112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(58),
106112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(59),
107112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
108112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(60),
109112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(61),
110112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE(62),
111112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE_NAME(63, "zero"),
112112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  REG_ONE_NAME(64, "pc"),
113112711afefcfcd43680c7c4aa8d38ef180e8811esewardj};
114112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
115112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#define num_regs (sizeof (regs) / sizeof (regs[0]))
116112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
117112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstatic const char *expedite_regs[] = { "sp", "pc", 0 };
118112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
119112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstatic
120112711afefcfcd43680c7c4aa8d38ef180e8811esewardjCORE_ADDR get_pc (void)
121112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{
122112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  unsigned long pc;
123112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
124112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  collect_register_by_name ("pc", &pc);
125112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
126112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  dlog(1, "stop pc is %p\n", (void *) pc);
127112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  return pc;
128112711afefcfcd43680c7c4aa8d38ef180e8811esewardj}
129112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
130112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstatic
131112711afefcfcd43680c7c4aa8d38ef180e8811esewardjvoid set_pc ( CORE_ADDR newpc )
132112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{
133112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  Bool mod;
134112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  supply_register_by_name ("pc", &newpc, &mod);
135112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  if (mod)
136112711afefcfcd43680c7c4aa8d38ef180e8811esewardj    dlog(1, "set pc to %p\n", C2v (newpc));
137112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  else
138112711afefcfcd43680c7c4aa8d38ef180e8811esewardj    dlog(1, "set pc not changed %p\n", C2v (newpc));
139112711afefcfcd43680c7c4aa8d38ef180e8811esewardj}
140112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
141112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/* store registers in the guest state (gdbserver_to_valgrind)
142112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   or fetch register from the guest state (valgrind_to_gdbserver). */
143112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstatic
144112711afefcfcd43680c7c4aa8d38ef180e8811esewardjvoid transfer_register ( ThreadId tid, int abs_regno, void * buf,
145112711afefcfcd43680c7c4aa8d38ef180e8811esewardj                         transfer_direction dir, int size, Bool *mod )
146112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{
147112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  ThreadState* tst = VG_(get_ThreadState)(tid);
148112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  int set = abs_regno / num_regs;
149112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  int regno = abs_regno % num_regs;
150112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  *mod = False;
151112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
152112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  VexGuestTILEGXState* tilegx = (VexGuestTILEGXState*) get_arch (set, tst);
153112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
154112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  switch (regno) {
155112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 0: VG_(transfer) (&tilegx->guest_r0, buf, dir, size, mod); break;
156112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 1: VG_(transfer) (&tilegx->guest_r1, buf, dir, size, mod); break;
157112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 2: VG_(transfer) (&tilegx->guest_r2, buf, dir, size, mod); break;
158112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 3: VG_(transfer) (&tilegx->guest_r3, buf, dir, size, mod); break;
159112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 4: VG_(transfer) (&tilegx->guest_r4, buf, dir, size, mod); break;
160112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 5: VG_(transfer) (&tilegx->guest_r5, buf, dir, size, mod); break;
161112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 6: VG_(transfer) (&tilegx->guest_r6, buf, dir, size, mod); break;
162112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 7: VG_(transfer) (&tilegx->guest_r7, buf, dir, size, mod); break;
163112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 8: VG_(transfer) (&tilegx->guest_r8, buf, dir, size, mod); break;
164112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 9: VG_(transfer) (&tilegx->guest_r9, buf, dir, size, mod); break;
165112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 10: VG_(transfer) (&tilegx->guest_r10, buf, dir, size, mod); break;
166112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 11: VG_(transfer) (&tilegx->guest_r11, buf, dir, size, mod); break;
167112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 12: VG_(transfer) (&tilegx->guest_r12, buf, dir, size, mod); break;
168112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 13: VG_(transfer) (&tilegx->guest_r13, buf, dir, size, mod); break;
169112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 14: VG_(transfer) (&tilegx->guest_r14, buf, dir, size, mod); break;
170112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 15: VG_(transfer) (&tilegx->guest_r15, buf, dir, size, mod); break;
171112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 16: VG_(transfer) (&tilegx->guest_r16, buf, dir, size, mod); break;
172112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 17: VG_(transfer) (&tilegx->guest_r17, buf, dir, size, mod); break;
173112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 18: VG_(transfer) (&tilegx->guest_r18, buf, dir, size, mod); break;
174112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 19: VG_(transfer) (&tilegx->guest_r19, buf, dir, size, mod); break;
175112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 20: VG_(transfer) (&tilegx->guest_r20, buf, dir, size, mod); break;
176112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 21: VG_(transfer) (&tilegx->guest_r21, buf, dir, size, mod); break;
177112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 22: VG_(transfer) (&tilegx->guest_r22, buf, dir, size, mod); break;
178112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 23: VG_(transfer) (&tilegx->guest_r23, buf, dir, size, mod); break;
179112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 24: VG_(transfer) (&tilegx->guest_r24, buf, dir, size, mod); break;
180112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 25: VG_(transfer) (&tilegx->guest_r25, buf, dir, size, mod); break;
181112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 26: VG_(transfer) (&tilegx->guest_r26, buf, dir, size, mod); break;
182112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 27: VG_(transfer) (&tilegx->guest_r27, buf, dir, size, mod); break;
183112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 28: VG_(transfer) (&tilegx->guest_r28, buf, dir, size, mod); break;
184112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 29: VG_(transfer) (&tilegx->guest_r29, buf, dir, size, mod); break;
185112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 30: VG_(transfer) (&tilegx->guest_r30, buf, dir, size, mod); break;
186112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 31: VG_(transfer) (&tilegx->guest_r31, buf, dir, size, mod); break;
187112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 32: VG_(transfer) (&tilegx->guest_r32, buf, dir, size, mod); break;
188112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 33: VG_(transfer) (&tilegx->guest_r33, buf, dir, size, mod); break;
189112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 34: VG_(transfer) (&tilegx->guest_r34, buf, dir, size, mod); break;
190112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 35: VG_(transfer) (&tilegx->guest_r35, buf, dir, size, mod); break;
191112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 36: VG_(transfer) (&tilegx->guest_r36, buf, dir, size, mod); break;
192112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 37: VG_(transfer) (&tilegx->guest_r37, buf, dir, size, mod); break;
193112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 38: VG_(transfer) (&tilegx->guest_r38, buf, dir, size, mod); break;
194112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 39: VG_(transfer) (&tilegx->guest_r39, buf, dir, size, mod); break;
195112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 40: VG_(transfer) (&tilegx->guest_r40, buf, dir, size, mod); break;
196112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 41: VG_(transfer) (&tilegx->guest_r41, buf, dir, size, mod); break;
197112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 42: VG_(transfer) (&tilegx->guest_r42, buf, dir, size, mod); break;
198112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 43: VG_(transfer) (&tilegx->guest_r43, buf, dir, size, mod); break;
199112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 44: VG_(transfer) (&tilegx->guest_r44, buf, dir, size, mod); break;
200112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 45: VG_(transfer) (&tilegx->guest_r45, buf, dir, size, mod); break;
201112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 46: VG_(transfer) (&tilegx->guest_r46, buf, dir, size, mod); break;
202112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 47: VG_(transfer) (&tilegx->guest_r47, buf, dir, size, mod); break;
203112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 48: VG_(transfer) (&tilegx->guest_r48, buf, dir, size, mod); break;
204112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 49: VG_(transfer) (&tilegx->guest_r49, buf, dir, size, mod); break;
205112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 50: VG_(transfer) (&tilegx->guest_r50, buf, dir, size, mod); break;
206112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 51: VG_(transfer) (&tilegx->guest_r51, buf, dir, size, mod); break;
207112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 52: VG_(transfer) (&tilegx->guest_r52, buf, dir, size, mod); break;
208112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 53: VG_(transfer) (&tilegx->guest_r53, buf, dir, size, mod); break;
209112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 54: VG_(transfer) (&tilegx->guest_r54, buf, dir, size, mod); break;
210112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 55: VG_(transfer) (&tilegx->guest_r55, buf, dir, size, mod); break;
211112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 56: VG_(transfer) (&tilegx->guest_r56, buf, dir, size, mod); break;
212112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 57: VG_(transfer) (&tilegx->guest_r57, buf, dir, size, mod); break;
213112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 58: VG_(transfer) (&tilegx->guest_r58, buf, dir, size, mod); break;
214112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 59: VG_(transfer) (&tilegx->guest_r59, buf, dir, size, mod); break;
215112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 60: VG_(transfer) (&tilegx->guest_r60, buf, dir, size, mod); break;
216112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 61: VG_(transfer) (&tilegx->guest_r61, buf, dir, size, mod); break;
217112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 62: VG_(transfer) (&tilegx->guest_r62, buf, dir, size, mod); break;
218112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 63: VG_(transfer) (&tilegx->guest_r63, buf, dir, size, mod); break;
219112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  case 64: VG_(transfer) (&tilegx->guest_pc,  buf, dir, size, mod); break;
220112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
221112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  default: VG_(printf)("regno: %d\n", regno); vg_assert(0);
222112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  }
223112711afefcfcd43680c7c4aa8d38ef180e8811esewardj}
224112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
225112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstatic
226112711afefcfcd43680c7c4aa8d38ef180e8811esewardjconst char* target_xml ( Bool shadow_mode )
227112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{
228112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  if (shadow_mode) {
229112711afefcfcd43680c7c4aa8d38ef180e8811esewardj    return "tilegx-linux-valgrind.xml";
230112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  } else {
231112711afefcfcd43680c7c4aa8d38ef180e8811esewardj    return "tilegx-linux.xml";
232112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  }
233112711afefcfcd43680c7c4aa8d38ef180e8811esewardj}
234112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
235112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstatic CORE_ADDR** target_get_dtv (ThreadState *tst)
236112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{
237112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  VexGuestTILEGXState* tilegx = (VexGuestTILEGXState*)&tst->arch.vex;
238112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  // tilegx dtv location similar to mips
239112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  return (CORE_ADDR**)((CORE_ADDR)tilegx->guest_r53
240112711afefcfcd43680c7c4aa8d38ef180e8811esewardj                        - 0x7000 - sizeof(CORE_ADDR));
241112711afefcfcd43680c7c4aa8d38ef180e8811esewardj}
242112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
243112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstatic struct valgrind_target_ops low_target = {
244112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  num_regs,
245112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  regs,
246112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  54, //sp = r54, which is register offset 54 in regs
247112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  transfer_register,
248112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  get_pc,
249112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  set_pc,
250112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  "tilegx",
251112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  target_xml,
252112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  target_get_dtv
253112711afefcfcd43680c7c4aa8d38ef180e8811esewardj};
254112711afefcfcd43680c7c4aa8d38ef180e8811esewardj
255112711afefcfcd43680c7c4aa8d38ef180e8811esewardjvoid tilegx_init_architecture ( struct valgrind_target_ops *target )
256112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{
257112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  *target = low_target;
258112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  set_register_cache (regs, num_regs);
259112711afefcfcd43680c7c4aa8d38ef180e8811esewardj  gdbserver_expedite_regs = expedite_regs;
260112711afefcfcd43680c7c4aa8d38ef180e8811esewardj}
261