remote_gdb.cc revision 11176:741b3059946e
1/* 2 * Copyright 2014 Google, Inc. 3 * Copyright (c) 2010 ARM Limited 4 * All rights reserved 5 * 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. 14 * 15 * Copyright (c) 2002-2005 The Regents of The University of Michigan 16 * All rights reserved. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions are 20 * met: redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer; 22 * redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution; 25 * neither the name of the copyright holders nor the names of its 26 * contributors may be used to endorse or promote products derived from 27 * this software without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Authors: Nathan Binkert 42 * William Wang 43 * Deyuan Guo 44 * Boris Shingarov 45 */ 46 47/* 48 * Copyright (c) 1990, 1993 The Regents of the University of California 49 * All rights reserved 50 * 51 * This software was developed by the Computer Systems Engineering group 52 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 53 * contributed to Berkeley. 54 * 55 * All advertising materials mentioning features or use of this software 56 * must display the following acknowledgement: 57 * This product includes software developed by the University of 58 * California, Lawrence Berkeley Laboratories. 59 * 60 * Redistribution and use in source and binary forms, with or without 61 * modification, are permitted provided that the following conditions 62 * are met: 63 * 1. Redistributions of source code must retain the above copyright 64 * notice, this list of conditions and the following disclaimer. 65 * 2. Redistributions in binary form must reproduce the above copyright 66 * notice, this list of conditions and the following disclaimer in the 67 * documentation and/or other materials provided with the distribution. 68 * 3. All advertising materials mentioning features or use of this software 69 * must display the following acknowledgement: 70 * This product includes software developed by the University of 71 * California, Berkeley and its contributors. 72 * 4. Neither the name of the University nor the names of its contributors 73 * may be used to endorse or promote products derived from this software 74 * without specific prior written permission. 75 * 76 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 77 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 78 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 79 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 80 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 81 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 82 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 83 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 84 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 85 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 86 * SUCH DAMAGE. 87 * 88 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 89 */ 90 91/*- 92 * Copyright (c) 2001 The NetBSD Foundation, Inc. 93 * All rights reserved. 94 * 95 * This code is derived from software contributed to The NetBSD Foundation 96 * by Jason R. Thorpe. 97 * 98 * Redistribution and use in source and binary forms, with or without 99 * modification, are permitted provided that the following conditions 100 * are met: 101 * 1. Redistributions of source code must retain the above copyright 102 * notice, this list of conditions and the following disclaimer. 103 * 2. Redistributions in binary form must reproduce the above copyright 104 * notice, this list of conditions and the following disclaimer in the 105 * documentation and/or other materials provided with the distribution. 106 * 3. All advertising materials mentioning features or use of this software 107 * must display the following acknowledgement: 108 * This product includes software developed by the NetBSD 109 * Foundation, Inc. and its contributors. 110 * 4. Neither the name of The NetBSD Foundation nor the names of its 111 * contributors may be used to endorse or promote products derived 112 * from this software without specific prior written permission. 113 * 114 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 115 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 116 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 117 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 118 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 119 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 120 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 121 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 122 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 123 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 124 * POSSIBILITY OF SUCH DAMAGE. 125 */ 126 127/* 128 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 129 * 130 * Taken from NetBSD 131 * 132 * "Stub" to allow remote cpu to debug over a serial line using gdb. 133 */ 134 135#include "arch/power/remote_gdb.hh" 136 137#include <sys/signal.h> 138#include <unistd.h> 139 140#include <string> 141 142#include "arch/power/vtophys.hh" 143#include "cpu/thread_state.hh" 144#include "debug/GDBAcc.hh" 145#include "debug/GDBMisc.hh" 146#include "sim/byteswap.hh" 147 148using namespace std; 149using namespace PowerISA; 150 151RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc) 152 : BaseRemoteGDB(_system, tc, GDB_REG_BYTES) 153{ 154} 155 156/* 157 * Determine if the mapping at va..(va+len) is valid. 158 */ 159bool 160RemoteGDB::acc(Addr va, size_t len) 161{ 162 TlbEntry entry; 163 //Check to make sure the first byte is mapped into the processes address 164 //space. At the time of this writing, the acc() check is used when 165 //processing the MemR/MemW packets before actually asking the translating 166 //port proxy to read/writeBlob. I (bgs) am not convinced the first byte 167 //check is enough. 168 if (FullSystem) 169 panic("acc not implemented for POWER FS!"); 170 else 171 return context->getProcessPtr()->pTable->lookup(va, entry); 172} 173 174/* 175 * Translate the kernel debugger register format into the GDB register 176 * format. 177 * 178 * The PowerPC ISA is quite flexible in what register sets may be present 179 * depending on the features implemented by the particular CPU; 180 * GDB addresses this by describing the format of how register contents 181 * are transferred on the wire, in XML files such as 'power-core.xml'. 182 * Ideally, we should be reading these files instead of hardcoding this 183 * information, but for now the following implementation is enough to 184 * serve as the RSP backend for the out-of-the-box, default GDB. 185 */ 186void 187RemoteGDB::getregs() 188{ 189 DPRINTF(GDBAcc, "getregs in remotegdb \n"); 190 memset(gdbregs.regs, 0, gdbregs.bytes()); 191 192 // Default order on 32-bit PowerPC: 193 // R0-R31 (32-bit each), F0-F31 (64-bit IEEE754 double), 194 // PC, MSR, CR, LR, CTR, XER (32-bit each) 195 196 // INTREG: R0~R31 197 for (int i = 0; i < NumIntArchRegs; i++) 198 gdbregs.regs32[GdbFirstGPRIndex + i] = htobe((uint32_t)context->readIntReg(i)); 199 200 // FLOATREG: F0~F31 201 for (int i = 0; i < NumFloatArchRegs; i++) 202 gdbregs.regs32[GdbFirstFPRIndex + i] = context->readFloatRegBits(i); 203 204 // PC, MSR, CR, LR, CTR, XER 205 gdbregs.regs32[GdbPCIndex] = htobe((uint32_t)context->pcState().pc()); 206 gdbregs.regs32[GdbMSRIndex] = 0; // Is MSR modeled? 207 gdbregs.regs32[GdbCRIndex] = htobe((uint32_t)context->readIntReg(INTREG_CR)); 208 gdbregs.regs32[GdbLRIndex] = htobe((uint32_t)context->readIntReg(INTREG_LR)); 209 gdbregs.regs32[GdbCTRIndex] = htobe((uint32_t)context->readIntReg(INTREG_CTR)); 210 gdbregs.regs32[GdbXERIndex] = htobe((uint32_t)context->readIntReg(INTREG_XER)); 211} 212 213/* 214 * Translate the GDB register format into the kernel debugger register 215 * format. 216 */ 217void 218RemoteGDB::setregs() 219{ 220 DPRINTF(GDBAcc, "setregs in remotegdb \n"); 221 222 // INTREG: R0~R31 223 for (int i = 0; i < NumIntArchRegs; i++) 224 context->setIntReg(i, betoh(gdbregs.regs32[GdbFirstGPRIndex + i])); 225 226 // FLOATREG: F0~F31 227 for (int i = 0; i < NumFloatArchRegs; i++) 228 context->setFloatRegBits(i, gdbregs.regs64[GdbFirstFPRIndex + i]); 229 230 // PC, MSR, CR, LR, CTR, XER 231 context->pcState(betoh(gdbregs.regs32[GdbPCIndex])); 232 // Is MSR modeled? 233 context->setIntReg(INTREG_CR, betoh(gdbregs.regs32[GdbCRIndex])); 234 context->setIntReg(INTREG_LR, betoh(gdbregs.regs32[GdbLRIndex])); 235 context->setIntReg(INTREG_CTR, betoh(gdbregs.regs32[GdbCTRIndex])); 236 context->setIntReg(INTREG_XER, betoh(gdbregs.regs32[GdbXERIndex])); 237} 238