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_debuginfo.h"
31 #include "pub_core_threadstate.h"
32 #include "pub_core_transtab.h"
33 #include "pub_core_gdbserver.h"
35 #include "valgrind_low.h"
37 #include "libvex_guest_mips32.h"
39 static struct reg regs
[] = {
72 { "status", 1024, 32 },
73 { "badvaddr", 1120, 32 },
74 { "cause", 1152, 32 },
78 #define num_regs (sizeof (regs) / sizeof (regs[0]))
80 static const char *expedite_regs
[] = { "r29", "pc", 0 };
83 CORE_ADDR
get_pc (void)
87 collect_register_by_name ("pc", &pc
);
89 dlog(1, "stop pc is %p\n", (void *) pc
);
94 void set_pc (CORE_ADDR newpc
)
96 supply_register_by_name ("pc", &newpc
);
99 /* These are the fields of 32 bit mips instructions. */
100 #define itype_op(x) (x >> 26)
101 #define itype_rs(x) ((x >> 21) & 0x1f)
102 #define itype_rt(x) ((x >> 16) & 0x1f)
103 #define rtype_funct(x) (x & 0x3f)
105 static inline UInt
getUInt(UChar
* p
) __attribute__((unused
));
106 /* Do a endian load of a 32-bit word, regardless of the
107 endianness of the underlying host. */
108 static inline UInt
getUInt(UChar
* p
)
111 #if defined (_MIPSEL)
116 #elif defined (_MIPSEB)
125 /* store registers in the guest state (gdbserver_to_valgrind)
126 or fetch register from the guest state (valgrind_to_gdbserver). */
128 void transfer_register (ThreadId tid
, int abs_regno
, void * buf
,
129 transfer_direction dir
, int size
, Bool
*mod
)
131 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
132 int set
= abs_regno
/ num_regs
;
133 int regno
= abs_regno
% num_regs
;
136 VexGuestMIPS32State
* mips1
= (VexGuestMIPS32State
*) get_arch (set
, tst
);
139 case 0: VG_(transfer
) (&mips1
->guest_r0
, buf
, dir
, size
, mod
); break;
140 case 1: VG_(transfer
) (&mips1
->guest_r1
, buf
, dir
, size
, mod
); break;
141 case 2: VG_(transfer
) (&mips1
->guest_r2
, buf
, dir
, size
, mod
); break;
142 case 3: VG_(transfer
) (&mips1
->guest_r3
, buf
, dir
, size
, mod
); break;
143 case 4: VG_(transfer
) (&mips1
->guest_r4
, buf
, dir
, size
, mod
); break;
144 case 5: VG_(transfer
) (&mips1
->guest_r5
, buf
, dir
, size
, mod
); break;
145 case 6: VG_(transfer
) (&mips1
->guest_r6
, buf
, dir
, size
, mod
); break;
146 case 7: VG_(transfer
) (&mips1
->guest_r7
, buf
, dir
, size
, mod
); break;
147 case 8: VG_(transfer
) (&mips1
->guest_r8
, buf
, dir
, size
, mod
); break;
148 case 9: VG_(transfer
) (&mips1
->guest_r9
, buf
, dir
, size
, mod
); break;
149 case 10: VG_(transfer
) (&mips1
->guest_r10
, buf
, dir
, size
, mod
); break;
150 case 11: VG_(transfer
) (&mips1
->guest_r11
, buf
, dir
, size
, mod
); break;
151 case 12: VG_(transfer
) (&mips1
->guest_r12
, buf
, dir
, size
, mod
); break;
152 case 13: VG_(transfer
) (&mips1
->guest_r13
, buf
, dir
, size
, mod
); break;
153 case 14: VG_(transfer
) (&mips1
->guest_r14
, buf
, dir
, size
, mod
); break;
154 case 15: VG_(transfer
) (&mips1
->guest_r15
, buf
, dir
, size
, mod
); break;
155 case 16: VG_(transfer
) (&mips1
->guest_r16
, buf
, dir
, size
, mod
); break;
156 case 17: VG_(transfer
) (&mips1
->guest_r17
, buf
, dir
, size
, mod
); break;
157 case 18: VG_(transfer
) (&mips1
->guest_r18
, buf
, dir
, size
, mod
); break;
158 case 19: VG_(transfer
) (&mips1
->guest_r19
, buf
, dir
, size
, mod
); break;
159 case 20: VG_(transfer
) (&mips1
->guest_r20
, buf
, dir
, size
, mod
); break;
160 case 21: VG_(transfer
) (&mips1
->guest_r21
, buf
, dir
, size
, mod
); break;
161 case 22: VG_(transfer
) (&mips1
->guest_r22
, buf
, dir
, size
, mod
); break;
162 case 23: VG_(transfer
) (&mips1
->guest_r23
, buf
, dir
, size
, mod
); break;
163 case 24: VG_(transfer
) (&mips1
->guest_r24
, buf
, dir
, size
, mod
); break;
164 case 25: VG_(transfer
) (&mips1
->guest_r25
, buf
, dir
, size
, mod
); break;
165 case 26: VG_(transfer
) (&mips1
->guest_r26
, buf
, dir
, size
, mod
); break;
166 case 27: VG_(transfer
) (&mips1
->guest_r27
, buf
, dir
, size
, mod
); break;
167 case 28: VG_(transfer
) (&mips1
->guest_r28
, buf
, dir
, size
, mod
); break;
168 case 29: VG_(transfer
) (&mips1
->guest_r29
, buf
, dir
, size
, mod
); break;
169 case 30: VG_(transfer
) (&mips1
->guest_r30
, buf
, dir
, size
, mod
); break;
170 case 31: VG_(transfer
) (&mips1
->guest_r31
, buf
, dir
, size
, mod
); break;
171 case 32: *mod
= False
; break; // GDBTD???? VEX { "status", 1024, 32 },
172 case 33: VG_(transfer
) (&mips1
->guest_LO
, buf
, dir
, size
, mod
); break;
173 case 34: VG_(transfer
) (&mips1
->guest_HI
, buf
, dir
, size
, mod
); break;
174 case 35: *mod
= False
; break; // GDBTD???? VEX { "badvaddr", 1120, 32 },
175 case 36: *mod
= False
; break; // GDBTD???? VEX { "cause", 1152, 32 },
176 case 37: VG_(transfer
) (&mips1
->guest_PC
, buf
, dir
, size
, mod
); break;
177 case 72: *mod
= False
; break; // GDBTD???? VEX{ "restart", 2304, 32 },
178 default: VG_(printf
)("regno: %d\n", regno
); vg_assert(0);
183 const char* target_xml (Bool shadow_mode
)
186 return "mips-linux-valgrind.xml";
188 return "mips-linux.xml";
192 static CORE_ADDR
** target_get_dtv (ThreadState
*tst
)
194 VexGuestMIPS32State
* mips32
= (VexGuestMIPS32State
*)&tst
->arch
.vex
;
195 // Top of nanoMIPS tcbhead structure is located 0x7000 bytes before the value
196 // of ULR. Dtv is the first of two pointers in tcbhead structure.
197 return (CORE_ADDR
**)((CORE_ADDR
)mips32
->guest_ULR
198 - 0x7000 - 2 * sizeof(CORE_ADDR
));
201 static struct valgrind_target_ops low_target
= {
203 29, //sp = r29, which is register offset 29 in regs
213 void nanomips_init_architecture (struct valgrind_target_ops
*target
)
215 *target
= low_target
;
216 set_register_cache (regs
, num_regs
);
217 gdbserver_expedite_regs
= expedite_regs
;