blob: 7b87856cf40a1df77461824b439da08d0daf646f [file] [log] [blame]
sewardj3b290482011-05-06 21:02:55 +00001/* Definitions of interface to the "low" (arch specific) functions
2 needed for interfacing the Valgrind gdbserver with the Valgrind
3 guest.
4
philippe0447bbd2012-10-17 21:32:03 +00005 Copyright (C) 2011, 2012
sewardj3b290482011-05-06 21:02:55 +00006 Free Software Foundation, Inc.
7
8 This file has been inspired from a file that is part of GDB.
9 It has been modified to integrate it in valgrind
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA. */
25
26#ifndef VALGRIND_LOW_H
27#define VALGRIND_LOW_H
28
florian535fb1b2013-09-15 13:54:34 +000029#include "pub_core_basics.h" // ThreadId
30#include "server.h" // CORE_ADDR
31
sewardj3b290482011-05-06 21:02:55 +000032/* defines the characteristics of the "low" valgrind target architecture.
33 In other words, struct valgrind_target_ops defines the functions and
34 data which are specific to the architecture (x86 or amd64 or
35 ppc32 or ...). */
36struct valgrind_target_ops
37{
38 int num_regs;
39 struct reg *reg_defs;
40
41 int stack_pointer_regno;
42 /* register number of the stack pointer register */
43
44 /* transfer the register regno from/to valgrind (guest state)
45 to/from buf
46 according to transfer_direction.
47 *mod set to True if destination content is modified by the transfer
48 otherwise it is set to False. */
49 void (*transfer_register) (ThreadId tid, int regno, void * buf,
50 transfer_direction dir, int size, Bool *mod);
51
52
53 CORE_ADDR (*get_pc) (void);
54 void (*set_pc) (CORE_ADDR newpc);
55
56 /* What string to report to GDB when it asks for the architecture,
57 or NULL not to answer. */
58 const char *arch_string;
59
philippe419d5f22012-05-24 21:33:17 +000060 /* Returns the target xml description of the set of registers.
sewardj3b290482011-05-06 21:02:55 +000061 For some architectures (e.g. arm), it is mandatory
62 to give a description of the registers, otherwise
63 gdb does not understand the reply to the 'g' packet
philippe419d5f22012-05-24 21:33:17 +000064 (which is used to get the registers).
65 If shadow_mode, returns a target xml description
66 including the two shadow registers sets.
67 This is mandatory to use the option --vgdb-shadow-registers=yes.
68 Returns NULL if there is no target xml file*/
florian6bd9dc12012-11-23 16:17:43 +000069 const char* (*target_xml) (Bool shadow_mode);
sewardj3b290482011-05-06 21:02:55 +000070
philippe1670b052014-08-15 10:27:52 +000071 /* Returns the address in the thread control block where dtv is found.
72 Return NULL if an error occurs or no support for tls/dtv is available.
73 Note that the addressability of the returned result has not been
74 verified. In other words, target_get_dtv just adds some magic
75 offset to the arch specific thread register or thread pointer or ...
76
77 The implementation of this is of course depending on the arch
78 but also depends on the way pthread lib arranges its data.
79 For background info about tls handling, read
80 'ELF Handling For Thread-Local Storage'
81 http://www.akkadia.org/drepper/tls.pdf
82 (slightly obsolete e.g. the size of a dtv entry is 2 words now).
83 The reference is the glibc source, in particular the arch specific
84 file tls.h.
85
86 For platforms where the dtv is located in the tcb, the magic offset
87 to add to the thread pointer/register/... can be found by doing:
88 cd none/tests
89 gdb ./tls
90 set debug-file-directory /usr/lib/debug # or equivalent
91 start
92 p &((struct pthread*)0x0)->header.dtv
93 Currently the dtv offset is hardcoded, based on the assumption
94 that this is relatively stable. If that would be false, then
95 getoff-<platform> should be modified to output this offset e.g.
96 depending on the glibc version. */
97 CORE_ADDR** (*target_get_dtv)(ThreadState *tst);
98
sewardj3b290482011-05-06 21:02:55 +000099};
100
sewardj3b290482011-05-06 21:02:55 +0000101extern void x86_init_architecture (struct valgrind_target_ops *target);
102extern void amd64_init_architecture (struct valgrind_target_ops *target);
103extern void arm_init_architecture (struct valgrind_target_ops *target);
sewardjf0c12502014-01-12 12:54:00 +0000104extern void arm64_init_architecture (struct valgrind_target_ops *target);
sewardj3b290482011-05-06 21:02:55 +0000105extern void ppc32_init_architecture (struct valgrind_target_ops *target);
106extern void ppc64_init_architecture (struct valgrind_target_ops *target);
107extern void s390x_init_architecture (struct valgrind_target_ops *target);
sewardj5db15402012-06-07 09:13:21 +0000108extern void mips32_init_architecture (struct valgrind_target_ops *target);
petarj4df0bfc2013-02-27 23:17:33 +0000109extern void mips64_init_architecture (struct valgrind_target_ops *target);
sewardj3b290482011-05-06 21:02:55 +0000110
111#endif