2 * Copyright 2014 Google, Inc.
3 * Copyright (c) 2007 The Hewlett-Packard Development Company
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions are
17 * met: redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer;
19 * redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution;
22 * neither the name of the copyright holders nor the names of its
23 * contributors may be used to endorse or promote products derived from
24 * this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/signal.h>
46 #include "arch/x86/regs/int.hh"
47 #include "arch/x86/regs/misc.hh"
48 #include "arch/x86/pagetable_walker.hh"
49 #include "arch/x86/process.hh"
50 #include "arch/x86/remote_gdb.hh"
51 #include "arch/vtophys.hh"
52 #include "base/remote_gdb.hh"
53 #include "base/socket.hh"
54 #include "base/trace.hh"
55 #include "cpu/base.hh"
56 #include "cpu/thread_context.hh"
57 #include "mem/page_table.hh"
58 #include "sim/full_system.hh"
61 using namespace X86ISA
;
63 RemoteGDB::RemoteGDB(System
*_system
, ThreadContext
*c
) :
64 BaseRemoteGDB(_system
, c
, GDB_REG_BYTES
), singleStepEvent(this)
68 RemoteGDB::acc(Addr va
, size_t len
)
71 Walker
*walker
= context
->getDTBPtr()->getWalker();
73 Fault fault
= walker
->startFunctional(context
, va
, logBytes
,
78 Addr endVa
= va
+ len
- 1;
79 if ((va
& ~mask(logBytes
)) == (endVa
& ~mask(logBytes
)))
82 fault
= walker
->startFunctional(context
, endVa
, logBytes
,
84 return fault
== NoFault
;
87 return context
->getProcessPtr()->pTable
->lookup(va
, entry
);
92 RemoteGDB::SingleStepEvent::process()
94 if (!gdb
->singleStepEvent
.scheduled())
95 gdb
->scheduleInstCommitEvent(&gdb
->singleStepEvent
, 1);
102 HandyM5Reg m5reg
= context
->readMiscRegNoEffect(MISCREG_M5_REG
);
103 if (m5reg
.submode
== SixtyFourBitMode
) {
104 gdbregs
.regs64
[GDB64_RAX
] = context
->readIntReg(INTREG_RAX
);
105 gdbregs
.regs64
[GDB64_RBX
] = context
->readIntReg(INTREG_RBX
);
106 gdbregs
.regs64
[GDB64_RCX
] = context
->readIntReg(INTREG_RCX
);
107 gdbregs
.regs64
[GDB64_RDX
] = context
->readIntReg(INTREG_RDX
);
108 gdbregs
.regs64
[GDB64_RSI
] = context
->readIntReg(INTREG_RSI
);
109 gdbregs
.regs64
[GDB64_RDI
] = context
->readIntReg(INTREG_RDI
);
110 gdbregs
.regs64
[GDB64_RBP
] = context
->readIntReg(INTREG_RBP
);
111 gdbregs
.regs64
[GDB64_RSP
] = context
->readIntReg(INTREG_RSP
);
112 gdbregs
.regs64
[GDB64_R8
] = context
->readIntReg(INTREG_R8
);
113 gdbregs
.regs64
[GDB64_R9
] = context
->readIntReg(INTREG_R9
);
114 gdbregs
.regs64
[GDB64_R10
] = context
->readIntReg(INTREG_R10
);
115 gdbregs
.regs64
[GDB64_R11
] = context
->readIntReg(INTREG_R11
);
116 gdbregs
.regs64
[GDB64_R12
] = context
->readIntReg(INTREG_R12
);
117 gdbregs
.regs64
[GDB64_R13
] = context
->readIntReg(INTREG_R13
);
118 gdbregs
.regs64
[GDB64_R14
] = context
->readIntReg(INTREG_R14
);
119 gdbregs
.regs64
[GDB64_R15
] = context
->readIntReg(INTREG_R15
);
120 gdbregs
.regs64
[GDB64_RIP
] = context
->pcState().pc();
121 gdbregs
.regs32
[GDB64_RFLAGS_32
] =
122 context
->readMiscRegNoEffect(MISCREG_RFLAGS
);
123 gdbregs
.regs32
[GDB64_CS_32
] = context
->readMiscRegNoEffect(MISCREG_CS
);
124 gdbregs
.regs32
[GDB64_SS_32
] = context
->readMiscRegNoEffect(MISCREG_SS
);
125 gdbregs
.regs32
[GDB64_DS_32
] = context
->readMiscRegNoEffect(MISCREG_DS
);
126 gdbregs
.regs32
[GDB64_ES_32
] = context
->readMiscRegNoEffect(MISCREG_ES
);
127 gdbregs
.regs32
[GDB64_FS_32
] = context
->readMiscRegNoEffect(MISCREG_FS
);
128 gdbregs
.regs32
[GDB64_GS_32
] = context
->readMiscRegNoEffect(MISCREG_GS
);
130 gdbregs
.regs32
[GDB32_EAX
] = context
->readIntReg(INTREG_RAX
);
131 gdbregs
.regs32
[GDB32_ECX
] = context
->readIntReg(INTREG_RCX
);
132 gdbregs
.regs32
[GDB32_EDX
] = context
->readIntReg(INTREG_RDX
);
133 gdbregs
.regs32
[GDB32_EBX
] = context
->readIntReg(INTREG_RBX
);
134 gdbregs
.regs32
[GDB32_ESP
] = context
->readIntReg(INTREG_RSP
);
135 gdbregs
.regs32
[GDB32_EBP
] = context
->readIntReg(INTREG_RBP
);
136 gdbregs
.regs32
[GDB32_ESI
] = context
->readIntReg(INTREG_RSI
);
137 gdbregs
.regs32
[GDB32_EDI
] = context
->readIntReg(INTREG_RDI
);
138 gdbregs
.regs32
[GDB32_EIP
] = context
->pcState().pc();
139 gdbregs
.regs32
[GDB32_EFLAGS
] =
140 context
->readMiscRegNoEffect(MISCREG_RFLAGS
);
141 gdbregs
.regs32
[GDB32_CS
] = context
->readMiscRegNoEffect(MISCREG_CS
);
142 gdbregs
.regs32
[GDB32_CS
] = context
->readMiscRegNoEffect(MISCREG_SS
);
143 gdbregs
.regs32
[GDB32_CS
] = context
->readMiscRegNoEffect(MISCREG_DS
);
144 gdbregs
.regs32
[GDB32_CS
] = context
->readMiscRegNoEffect(MISCREG_ES
);
145 gdbregs
.regs32
[GDB32_CS
] = context
->readMiscRegNoEffect(MISCREG_FS
);
146 gdbregs
.regs32
[GDB32_CS
] = context
->readMiscRegNoEffect(MISCREG_GS
);
153 HandyM5Reg m5reg
= context
->readMiscRegNoEffect(MISCREG_M5_REG
);
154 if (m5reg
.submode
== SixtyFourBitMode
) {
155 context
->setIntReg(INTREG_RAX
, gdbregs
.regs64
[GDB64_RAX
]);
156 context
->setIntReg(INTREG_RBX
, gdbregs
.regs64
[GDB64_RBX
]);
157 context
->setIntReg(INTREG_RCX
, gdbregs
.regs64
[GDB64_RCX
]);
158 context
->setIntReg(INTREG_RDX
, gdbregs
.regs64
[GDB64_RDX
]);
159 context
->setIntReg(INTREG_RSI
, gdbregs
.regs64
[GDB64_RSI
]);
160 context
->setIntReg(INTREG_RDI
, gdbregs
.regs64
[GDB64_RDI
]);
161 context
->setIntReg(INTREG_RBP
, gdbregs
.regs64
[GDB64_RBP
]);
162 context
->setIntReg(INTREG_RSP
, gdbregs
.regs64
[GDB64_RSP
]);
163 context
->setIntReg(INTREG_R8
, gdbregs
.regs64
[GDB64_R8
]);
164 context
->setIntReg(INTREG_R9
, gdbregs
.regs64
[GDB64_R9
]);
165 context
->setIntReg(INTREG_R10
, gdbregs
.regs64
[GDB64_R10
]);
166 context
->setIntReg(INTREG_R11
, gdbregs
.regs64
[GDB64_R11
]);
167 context
->setIntReg(INTREG_R12
, gdbregs
.regs64
[GDB64_R12
]);
168 context
->setIntReg(INTREG_R13
, gdbregs
.regs64
[GDB64_R13
]);
169 context
->setIntReg(INTREG_R14
, gdbregs
.regs64
[GDB64_R14
]);
170 context
->setIntReg(INTREG_R15
, gdbregs
.regs64
[GDB64_R15
]);
171 context
->pcState(gdbregs
.regs64
[GDB64_RIP
]);
172 context
->setMiscReg(MISCREG_RFLAGS
, gdbregs
.regs32
[GDB64_RFLAGS_32
]);
173 if (gdbregs
.regs32
[GDB64_CS_32
] !=
174 context
->readMiscRegNoEffect(MISCREG_CS
)) {
175 warn("Remote gdb: Ignoring update to CS.\n");
177 if (gdbregs
.regs32
[GDB64_SS_32
] !=
178 context
->readMiscRegNoEffect(MISCREG_SS
)) {
179 warn("Remote gdb: Ignoring update to SS.\n");
181 if (gdbregs
.regs32
[GDB64_DS_32
] !=
182 context
->readMiscRegNoEffect(MISCREG_DS
)) {
183 warn("Remote gdb: Ignoring update to DS.\n");
185 if (gdbregs
.regs32
[GDB64_ES_32
] !=
186 context
->readMiscRegNoEffect(MISCREG_ES
)) {
187 warn("Remote gdb: Ignoring update to ES.\n");
189 if (gdbregs
.regs32
[GDB64_FS_32
] !=
190 context
->readMiscRegNoEffect(MISCREG_FS
)) {
191 warn("Remote gdb: Ignoring update to FS.\n");
193 if (gdbregs
.regs32
[GDB64_GS_32
] !=
194 context
->readMiscRegNoEffect(MISCREG_GS
)) {
195 warn("Remote gdb: Ignoring update to GS.\n");
198 context
->setIntReg(INTREG_RAX
, gdbregs
.regs32
[GDB32_EAX
]);
199 context
->setIntReg(INTREG_RCX
, gdbregs
.regs32
[GDB32_ECX
]);
200 context
->setIntReg(INTREG_RDX
, gdbregs
.regs32
[GDB32_EDX
]);
201 context
->setIntReg(INTREG_RBX
, gdbregs
.regs32
[GDB32_EBX
]);
202 context
->setIntReg(INTREG_RSP
, gdbregs
.regs32
[GDB32_ESP
]);
203 context
->setIntReg(INTREG_RBP
, gdbregs
.regs32
[GDB32_EBP
]);
204 context
->setIntReg(INTREG_RSI
, gdbregs
.regs32
[GDB32_ESI
]);
205 context
->setIntReg(INTREG_RDI
, gdbregs
.regs32
[GDB32_EDI
]);
206 context
->pcState(gdbregs
.regs32
[GDB32_EIP
]);
207 context
->setMiscReg(MISCREG_RFLAGS
, gdbregs
.regs32
[GDB32_EFLAGS
]);
208 if (gdbregs
.regs32
[GDB64_CS_32
] !=
209 context
->readMiscRegNoEffect(MISCREG_CS
)) {
210 warn("Remote gdb: Ignoring update to CS.\n");
212 if (gdbregs
.regs32
[GDB32_SS
] !=
213 context
->readMiscRegNoEffect(MISCREG_SS
)) {
214 warn("Remote gdb: Ignoring update to SS.\n");
216 if (gdbregs
.regs32
[GDB32_DS
] !=
217 context
->readMiscRegNoEffect(MISCREG_DS
)) {
218 warn("Remote gdb: Ignoring update to DS.\n");
220 if (gdbregs
.regs32
[GDB32_ES
] !=
221 context
->readMiscRegNoEffect(MISCREG_ES
)) {
222 warn("Remote gdb: Ignoring update to ES.\n");
224 if (gdbregs
.regs32
[GDB32_FS
] !=
225 context
->readMiscRegNoEffect(MISCREG_FS
)) {
226 warn("Remote gdb: Ignoring update to FS.\n");
228 if (gdbregs
.regs32
[GDB32_GS
] !=
229 context
->readMiscRegNoEffect(MISCREG_GS
)) {
230 warn("Remote gdb: Ignoring update to GS.\n");
236 RemoteGDB::clearSingleStep()
238 descheduleInstCommitEvent(&singleStepEvent
);
242 RemoteGDB::setSingleStep()
244 if (!singleStepEvent
.scheduled())
245 scheduleInstCommitEvent(&singleStepEvent
, 1);