• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Low level interface to valgrind, for the remote server for GDB integrated
2    in valgrind.
3    Copyright (C) 2011
4    Free Software Foundation, Inc.
5 
6    This file is part of VALGRIND.
7    It has been inspired from a file from gdbserver in gdb 6.6.
8 
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.
13 
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.
18 
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.  */
23 
24 #include "server.h"
25 #include "target.h"
26 #include "regdef.h"
27 #include "regcache.h"
28 
29 #include "pub_core_aspacemgr.h"
30 #include "pub_tool_machine.h"
31 #include "pub_core_threadstate.h"
32 #include "pub_core_transtab.h"
33 #include "pub_core_gdbserver.h"
34 
35 #include "valgrind_low.h"
36 
37 #include "libvex_guest_s390x.h"
38 
39 static struct reg regs[] = {
40   { "pswm", 0, 64 },
41   { "pswa", 64, 64 },
42   { "r0", 128, 64 },
43   { "r1", 192, 64 },
44   { "r2", 256, 64 },
45   { "r3", 320, 64 },
46   { "r4", 384, 64 },
47   { "r5", 448, 64 },
48   { "r6", 512, 64 },
49   { "r7", 576, 64 },
50   { "r8", 640, 64 },
51   { "r9", 704, 64 },
52   { "r10", 768, 64 },
53   { "r11", 832, 64 },
54   { "r12", 896, 64 },
55   { "r13", 960, 64 },
56   { "r14", 1024, 64 },
57   { "r15", 1088, 64 },
58   { "acr0", 1152, 32 },
59   { "acr1", 1184, 32 },
60   { "acr2", 1216, 32 },
61   { "acr3", 1248, 32 },
62   { "acr4", 1280, 32 },
63   { "acr5", 1312, 32 },
64   { "acr6", 1344, 32 },
65   { "acr7", 1376, 32 },
66   { "acr8", 1408, 32 },
67   { "acr9", 1440, 32 },
68   { "acr10", 1472, 32 },
69   { "acr11", 1504, 32 },
70   { "acr12", 1536, 32 },
71   { "acr13", 1568, 32 },
72   { "acr14", 1600, 32 },
73   { "acr15", 1632, 32 },
74   { "fpc", 1664, 32 },
75   { "f0", 1696, 64 },
76   { "f1", 1760, 64 },
77   { "f2", 1824, 64 },
78   { "f3", 1888, 64 },
79   { "f4", 1952, 64 },
80   { "f5", 2016, 64 },
81   { "f6", 2080, 64 },
82   { "f7", 2144, 64 },
83   { "f8", 2208, 64 },
84   { "f9", 2272, 64 },
85   { "f10", 2336, 64 },
86   { "f11", 2400, 64 },
87   { "f12", 2464, 64 },
88   { "f13", 2528, 64 },
89   { "f14", 2592, 64 },
90   { "f15", 2656, 64 },
91   { "orig_r2", 2720, 64 },
92 };
93 static const char *expedite_regs[] = { "r14", "r15", "pswa", 0 };
94 #define num_regs (sizeof (regs) / sizeof (regs[0]))
95 
96 static
get_pc(void)97 CORE_ADDR get_pc (void)
98 {
99    unsigned long pc;
100 
101    collect_register_by_name ("pswa", &pc);
102 
103    dlog(1, "stop pc is %p\n", (void *) pc);
104    return pc;
105 }
106 
107 static
set_pc(CORE_ADDR newpc)108 void set_pc (CORE_ADDR newpc)
109 {
110    Bool mod;
111    supply_register_by_name ("pswa", &newpc, &mod);
112    if (mod)
113       dlog(1, "set pc to %p\n", C2v (newpc));
114    else
115       dlog(1, "set pc not changed %p\n", C2v (newpc));
116 }
117 
118 /* store registers in the guest state (gdbserver_to_valgrind)
119    or fetch register from the guest state (valgrind_to_gdbserver). */
120 static
transfer_register(ThreadId tid,int abs_regno,void * buf,transfer_direction dir,int size,Bool * mod)121 void transfer_register (ThreadId tid, int abs_regno, void * buf,
122                         transfer_direction dir, int size, Bool *mod)
123 {
124    ThreadState* tst = VG_(get_ThreadState)(tid);
125    int set = abs_regno / num_regs;
126    int regno = abs_regno % num_regs;
127    *mod = False;
128 
129    VexGuestS390XState* s390x = (VexGuestS390XState*) get_arch (set, tst);
130 
131    switch (regno) {
132    // numbers here have to match the order of regs above
133    // Attention: gdb order does not match valgrind order.
134    case 0:  *mod = False; break; //GDBTD??? { "pswm", 0, 64 },
135    case 1:  VG_(transfer) (&s390x->guest_IA,  buf, dir, size, mod); break;
136    case 2:  VG_(transfer) (&s390x->guest_r0,  buf, dir, size, mod); break;
137    case 3:  VG_(transfer) (&s390x->guest_r1,  buf, dir, size, mod); break;
138    case 4:  VG_(transfer) (&s390x->guest_r2,  buf, dir, size, mod); break;
139    case 5:  VG_(transfer) (&s390x->guest_r3,  buf, dir, size, mod); break;
140    case 6:  VG_(transfer) (&s390x->guest_r4,  buf, dir, size, mod); break;
141    case 7:  VG_(transfer) (&s390x->guest_r5,  buf, dir, size, mod); break;
142    case 8:  VG_(transfer) (&s390x->guest_r6,  buf, dir, size, mod); break;
143    case 9:  VG_(transfer) (&s390x->guest_r7,  buf, dir, size, mod); break;
144    case 10: VG_(transfer) (&s390x->guest_r8,  buf, dir, size, mod); break;
145    case 11: VG_(transfer) (&s390x->guest_r9,  buf, dir, size, mod); break;
146    case 12: VG_(transfer) (&s390x->guest_r10, buf, dir, size, mod); break;
147    case 13: VG_(transfer) (&s390x->guest_r11, buf, dir, size, mod); break;
148    case 14: VG_(transfer) (&s390x->guest_r12, buf, dir, size, mod); break;
149    case 15: VG_(transfer) (&s390x->guest_r13, buf, dir, size, mod); break;
150    case 16: VG_(transfer) (&s390x->guest_r14, buf, dir, size, mod); break;
151    case 17: VG_(transfer) (&s390x->guest_r15, buf, dir, size, mod); break;
152    case 18: VG_(transfer) (&s390x->guest_a0,  buf, dir, size, mod); break;
153    case 19: VG_(transfer) (&s390x->guest_a1,  buf, dir, size, mod); break;
154    case 20: VG_(transfer) (&s390x->guest_a2,  buf, dir, size, mod); break;
155    case 21: VG_(transfer) (&s390x->guest_a3,  buf, dir, size, mod); break;
156    case 22: VG_(transfer) (&s390x->guest_a4,  buf, dir, size, mod); break;
157    case 23: VG_(transfer) (&s390x->guest_a5,  buf, dir, size, mod); break;
158    case 24: VG_(transfer) (&s390x->guest_a6,  buf, dir, size, mod); break;
159    case 25: VG_(transfer) (&s390x->guest_a7,  buf, dir, size, mod); break;
160    case 26: VG_(transfer) (&s390x->guest_a8,  buf, dir, size, mod); break;
161    case 27: VG_(transfer) (&s390x->guest_a9,  buf, dir, size, mod); break;
162    case 28: VG_(transfer) (&s390x->guest_a10, buf, dir, size, mod); break;
163    case 29: VG_(transfer) (&s390x->guest_a11, buf, dir, size, mod); break;
164    case 30: VG_(transfer) (&s390x->guest_a12, buf, dir, size, mod); break;
165    case 31: VG_(transfer) (&s390x->guest_a13, buf, dir, size, mod); break;
166    case 32: VG_(transfer) (&s390x->guest_a14, buf, dir, size, mod); break;
167    case 33: VG_(transfer) (&s390x->guest_a15, buf, dir, size, mod); break;
168    case 34: VG_(transfer) (&s390x->guest_fpc, buf, dir, size, mod); break;
169    case 35: VG_(transfer) (&s390x->guest_f0,  buf, dir, size, mod); break;
170    case 36: VG_(transfer) (&s390x->guest_f1,  buf, dir, size, mod); break;
171    case 37: VG_(transfer) (&s390x->guest_f2,  buf, dir, size, mod); break;
172    case 38: VG_(transfer) (&s390x->guest_f3,  buf, dir, size, mod); break;
173    case 39: VG_(transfer) (&s390x->guest_f4,  buf, dir, size, mod); break;
174    case 40: VG_(transfer) (&s390x->guest_f5,  buf, dir, size, mod); break;
175    case 41: VG_(transfer) (&s390x->guest_f6,  buf, dir, size, mod); break;
176    case 42: VG_(transfer) (&s390x->guest_f7,  buf, dir, size, mod); break;
177    case 43: VG_(transfer) (&s390x->guest_f8,  buf, dir, size, mod); break;
178    case 44: VG_(transfer) (&s390x->guest_f9,  buf, dir, size, mod); break;
179    case 45: VG_(transfer) (&s390x->guest_f10, buf, dir, size, mod); break;
180    case 46: VG_(transfer) (&s390x->guest_f11, buf, dir, size, mod); break;
181    case 47: VG_(transfer) (&s390x->guest_f12, buf, dir, size, mod); break;
182    case 48: VG_(transfer) (&s390x->guest_f13, buf, dir, size, mod); break;
183    case 49: VG_(transfer) (&s390x->guest_f14, buf, dir, size, mod); break;
184    case 50: VG_(transfer) (&s390x->guest_f15, buf, dir, size, mod); break;
185    case 51:  *mod = False; break; //GDBTD??? { "orig_r2", 0, 64 },
186    default: vg_assert(0);
187    }
188 }
189 
190 static
target_xml(Bool shadow_mode)191 char* target_xml (Bool shadow_mode)
192 {
193    if (shadow_mode) {
194       return "s390x-generic-valgrind.xml";
195    } else {
196       return "s390x-generic.xml";
197    }
198 }
199 
200 static struct valgrind_target_ops low_target = {
201    num_regs,
202    regs,
203    17, //sp = r15, which is register offset 17 in regs
204    transfer_register,
205    get_pc,
206    set_pc,
207    "s390x",
208    target_xml
209 };
210 
s390x_init_architecture(struct valgrind_target_ops * target)211 void s390x_init_architecture (struct valgrind_target_ops *target)
212 {
213    *target = low_target;
214    set_register_cache (regs, num_regs);
215    gdbserver_expedite_regs = expedite_regs;
216 }
217