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 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 }; 92 static const char *expedite_regs[] = { "r14", "r15", "pswa", 0 }; 93 #define num_regs (sizeof (regs) / sizeof (regs[0])) 94 95 static 96 CORE_ADDR get_pc (void) 97 { 98 unsigned long pc; 99 100 collect_register_by_name ("pswa", &pc); 101 102 dlog(1, "stop pc is %p\n", (void *) pc); 103 return pc; 104 } 105 106 static 107 void set_pc (CORE_ADDR newpc) 108 { 109 Bool mod; 110 supply_register_by_name ("pswa", &newpc, &mod); 111 if (mod) 112 dlog(1, "set pc to %p\n", C2v (newpc)); 113 else 114 dlog(1, "set pc not changed %p\n", C2v (newpc)); 115 } 116 117 /* store registers in the guest state (gdbserver_to_valgrind) 118 or fetch register from the guest state (valgrind_to_gdbserver). */ 119 static 120 void transfer_register (ThreadId tid, int abs_regno, void * buf, 121 transfer_direction dir, int size, Bool *mod) 122 { 123 ThreadState* tst = VG_(get_ThreadState)(tid); 124 int set = abs_regno / num_regs; 125 int regno = abs_regno % num_regs; 126 *mod = False; 127 128 VexGuestS390XState* s390x = (VexGuestS390XState*) get_arch (set, tst); 129 130 switch (regno) { 131 // numbers here have to match the order of regs above 132 // Attention: gdb order does not match valgrind order. 133 case 0: *mod = False; break; //GDBTD??? { "pswm", 0, 64 }, 134 case 1: VG_(transfer) (&s390x->guest_IA, buf, dir, size, mod); break; 135 case 2: VG_(transfer) (&s390x->guest_r0, buf, dir, size, mod); break; 136 case 3: VG_(transfer) (&s390x->guest_r1, buf, dir, size, mod); break; 137 case 4: VG_(transfer) (&s390x->guest_r2, buf, dir, size, mod); break; 138 case 5: VG_(transfer) (&s390x->guest_r3, buf, dir, size, mod); break; 139 case 6: VG_(transfer) (&s390x->guest_r4, buf, dir, size, mod); break; 140 case 7: VG_(transfer) (&s390x->guest_r5, buf, dir, size, mod); break; 141 case 8: VG_(transfer) (&s390x->guest_r6, buf, dir, size, mod); break; 142 case 9: VG_(transfer) (&s390x->guest_r7, buf, dir, size, mod); break; 143 case 10: VG_(transfer) (&s390x->guest_r8, buf, dir, size, mod); break; 144 case 11: VG_(transfer) (&s390x->guest_r9, buf, dir, size, mod); break; 145 case 12: VG_(transfer) (&s390x->guest_r10, buf, dir, size, mod); break; 146 case 13: VG_(transfer) (&s390x->guest_r11, buf, dir, size, mod); break; 147 case 14: VG_(transfer) (&s390x->guest_r12, buf, dir, size, mod); break; 148 case 15: VG_(transfer) (&s390x->guest_r13, buf, dir, size, mod); break; 149 case 16: VG_(transfer) (&s390x->guest_r14, buf, dir, size, mod); break; 150 case 17: VG_(transfer) (&s390x->guest_r15, buf, dir, size, mod); break; 151 case 18: VG_(transfer) (&s390x->guest_a0, buf, dir, size, mod); break; 152 case 19: VG_(transfer) (&s390x->guest_a1, buf, dir, size, mod); break; 153 case 20: VG_(transfer) (&s390x->guest_a2, buf, dir, size, mod); break; 154 case 21: VG_(transfer) (&s390x->guest_a3, buf, dir, size, mod); break; 155 case 22: VG_(transfer) (&s390x->guest_a4, buf, dir, size, mod); break; 156 case 23: VG_(transfer) (&s390x->guest_a5, buf, dir, size, mod); break; 157 case 24: VG_(transfer) (&s390x->guest_a6, buf, dir, size, mod); break; 158 case 25: VG_(transfer) (&s390x->guest_a7, buf, dir, size, mod); break; 159 case 26: VG_(transfer) (&s390x->guest_a8, buf, dir, size, mod); break; 160 case 27: VG_(transfer) (&s390x->guest_a9, buf, dir, size, mod); break; 161 case 28: VG_(transfer) (&s390x->guest_a10, buf, dir, size, mod); break; 162 case 29: VG_(transfer) (&s390x->guest_a11, buf, dir, size, mod); break; 163 case 30: VG_(transfer) (&s390x->guest_a12, buf, dir, size, mod); break; 164 case 31: VG_(transfer) (&s390x->guest_a13, buf, dir, size, mod); break; 165 case 32: VG_(transfer) (&s390x->guest_a14, buf, dir, size, mod); break; 166 case 33: VG_(transfer) (&s390x->guest_a15, buf, dir, size, mod); break; 167 case 34: VG_(transfer) (&s390x->guest_fpc, buf, dir, size, mod); break; 168 case 35: VG_(transfer) (&s390x->guest_f0, buf, dir, size, mod); break; 169 case 36: VG_(transfer) (&s390x->guest_f1, buf, dir, size, mod); break; 170 case 37: VG_(transfer) (&s390x->guest_f2, buf, dir, size, mod); break; 171 case 38: VG_(transfer) (&s390x->guest_f3, buf, dir, size, mod); break; 172 case 39: VG_(transfer) (&s390x->guest_f4, buf, dir, size, mod); break; 173 case 40: VG_(transfer) (&s390x->guest_f5, buf, dir, size, mod); break; 174 case 41: VG_(transfer) (&s390x->guest_f6, buf, dir, size, mod); break; 175 case 42: VG_(transfer) (&s390x->guest_f7, buf, dir, size, mod); break; 176 case 43: VG_(transfer) (&s390x->guest_f8, buf, dir, size, mod); break; 177 case 44: VG_(transfer) (&s390x->guest_f9, buf, dir, size, mod); break; 178 case 45: VG_(transfer) (&s390x->guest_f10, buf, dir, size, mod); break; 179 case 46: VG_(transfer) (&s390x->guest_f11, buf, dir, size, mod); break; 180 case 47: VG_(transfer) (&s390x->guest_f12, buf, dir, size, mod); break; 181 case 48: VG_(transfer) (&s390x->guest_f13, buf, dir, size, mod); break; 182 case 49: VG_(transfer) (&s390x->guest_f14, buf, dir, size, mod); break; 183 case 50: VG_(transfer) (&s390x->guest_f15, buf, dir, size, mod); break; 184 default: vg_assert(0); 185 } 186 } 187 188 static struct valgrind_target_ops low_target = { 189 num_regs, 190 regs, 191 17, //sp = r15, which is register offset 17 in regs 192 transfer_register, 193 get_pc, 194 set_pc, 195 "s390x", 196 NULL, // target_xml not needed. 197 NULL // no xml shadow target description (yet?) 198 }; 199 200 void s390x_init_architecture (struct valgrind_target_ops *target) 201 { 202 *target = low_target; 203 set_register_cache (regs, num_regs); 204 gdbserver_expedite_regs = expedite_regs; 205 } 206