]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdbserver/linux-amd64-ipa.c
2011-02-24 Michael Snyder <msnyder@vmware.com>
[thirdparty/binutils-gdb.git] / gdb / gdbserver / linux-amd64-ipa.c
CommitLineData
fa593d66
PA
1/* GNU/Linux/x86-64 specific low level interface, for the in-process
2 agent library for GDB.
3
7b6bb8da 4 Copyright (C) 2010, 2011 Free Software Foundation, Inc.
fa593d66
PA
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21#include "server.h"
22
23/* Defined in auto-generated file amd64-linux.c. */
24void init_registers_amd64_linux (void);
25
26/* fast tracepoints collect registers. */
27
28#define FT_CR_RIP 0
29#define FT_CR_EFLAGS 1
30#define FT_CR_R8 2
31#define FT_CR_R9 3
32#define FT_CR_R10 4
33#define FT_CR_R11 5
34#define FT_CR_R12 6
35#define FT_CR_R13 7
36#define FT_CR_R14 8
37#define FT_CR_R15 9
38#define FT_CR_RAX 10
39#define FT_CR_RBX 11
40#define FT_CR_RCX 12
41#define FT_CR_RDX 13
42#define FT_CR_RSI 14
43#define FT_CR_RDI 15
44#define FT_CR_RBP 16
45#define FT_CR_RSP 17
46
47static const int x86_64_ft_collect_regmap[] = {
48 FT_CR_RAX * 8, FT_CR_RBX * 8, FT_CR_RCX * 8, FT_CR_RDX * 8,
49 FT_CR_RSI * 8, FT_CR_RDI * 8, FT_CR_RBP * 8, FT_CR_RSP * 8,
50 FT_CR_R8 * 8, FT_CR_R9 * 8, FT_CR_R10 * 8, FT_CR_R11 * 8,
51 FT_CR_R12 * 8, FT_CR_R13 * 8, FT_CR_R14 * 8, FT_CR_R15 * 8,
52 FT_CR_RIP * 8, FT_CR_EFLAGS * 8
53};
54
55#define X86_64_NUM_FT_COLLECT_GREGS \
56 (sizeof (x86_64_ft_collect_regmap) / sizeof(x86_64_ft_collect_regmap[0]))
57
58void
59supply_fast_tracepoint_registers (struct regcache *regcache,
60 const unsigned char *buf)
61{
62 int i;
63
64 for (i = 0; i < X86_64_NUM_FT_COLLECT_GREGS; i++)
65 supply_register (regcache, i,
66 ((char *) buf) + x86_64_ft_collect_regmap[i]);
67}
68
6a271cae
PA
69ULONGEST __attribute__ ((visibility("default"), used))
70gdb_agent_get_raw_reg (const unsigned char *raw_regs, int regnum)
71{
72 if (regnum > X86_64_NUM_FT_COLLECT_GREGS)
73 return 0;
74
75 return *(ULONGEST *) (raw_regs + x86_64_ft_collect_regmap[regnum]);
76}
77
0fb4aa4b
PA
78#ifdef HAVE_UST
79
80#include <ust/processor.h>
81
82/* "struct registers" is the UST object type holding the registers at
83 the time of the static tracepoint marker call. This doesn't
84 contain RIP, but we know what it must have been (the marker
85 address). */
86
87#define ST_REGENTRY(REG) \
88 { \
89 offsetof (struct registers, REG), \
90 sizeof (((struct registers *) NULL)->REG) \
91 }
92
93static struct
94{
95 int offset;
96 int size;
97} x86_64_st_collect_regmap[] =
98 {
99 ST_REGENTRY(rax),
100 ST_REGENTRY(rbx),
101 ST_REGENTRY(rcx),
102 ST_REGENTRY(rdx),
103 ST_REGENTRY(rsi),
104 ST_REGENTRY(rdi),
105 ST_REGENTRY(rbp),
106 ST_REGENTRY(rsp),
107 ST_REGENTRY(r8),
108 ST_REGENTRY(r9),
109 ST_REGENTRY(r10),
110 ST_REGENTRY(r11),
111 ST_REGENTRY(r12),
112 ST_REGENTRY(r13),
113 ST_REGENTRY(r14),
114 ST_REGENTRY(r15),
115 { -1, 0 },
116 ST_REGENTRY(rflags),
117 ST_REGENTRY(cs),
118 ST_REGENTRY(ss),
119 };
120
121#define X86_64_NUM_ST_COLLECT_GREGS \
122 (sizeof (x86_64_st_collect_regmap) / sizeof (x86_64_st_collect_regmap[0]))
123
124/* GDB's RIP register number. */
125#define AMD64_RIP_REGNUM 16
126
127void
128supply_static_tracepoint_registers (struct regcache *regcache,
129 const unsigned char *buf,
130 CORE_ADDR pc)
131{
132 int i;
133 unsigned long newpc = pc;
134
135 supply_register (regcache, AMD64_RIP_REGNUM, &newpc);
136
137 for (i = 0; i < X86_64_NUM_ST_COLLECT_GREGS; i++)
138 if (x86_64_st_collect_regmap[i].offset != -1)
139 {
140 switch (x86_64_st_collect_regmap[i].size)
141 {
142 case 8:
143 supply_register (regcache, i,
144 ((char *) buf)
145 + x86_64_st_collect_regmap[i].offset);
146 break;
147 case 2:
148 {
149 unsigned long reg
150 = * (short *) (((char *) buf)
151 + x86_64_st_collect_regmap[i].offset);
152 reg &= 0xffff;
153 supply_register (regcache, i, &reg);
154 }
155 break;
156 default:
157 internal_error (__FILE__, __LINE__,
158 "unhandled register size: %d",
159 x86_64_st_collect_regmap[i].size);
160 break;
161 }
162 }
163}
164
165#endif /* HAVE_UST */
166
fa593d66
PA
167/* This is only needed because reg-i386-linux-lib.o references it. We
168 may use it proper at some point. */
169const char *gdbserver_xmltarget;
170
171void
172initialize_low_tracepoint (void)
173{
174 init_registers_amd64_linux ();
175}