1/* 2 * Copyright 2014 Google Inc. 3 * Copyright (c) 2010, 2013 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 */ 44 45/* 46 * Copyright (c) 1990, 1993 The Regents of the University of California 47 * All rights reserved 48 * 49 * This software was developed by the Computer Systems Engineering group 50 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 51 * contributed to Berkeley. 52 * 53 * All advertising materials mentioning features or use of this software 54 * must display the following acknowledgement: 55 * This product includes software developed by the University of 56 * California, Lawrence Berkeley Laboratories. 57 * 58 * Redistribution and use in source and binary forms, with or without 59 * modification, are permitted provided that the following conditions 60 * are met: 61 * 1. Redistributions of source code must retain the above copyright 62 * notice, this list of conditions and the following disclaimer. 63 * 2. Redistributions in binary form must reproduce the above copyright 64 * notice, this list of conditions and the following disclaimer in the 65 * documentation and/or other materials provided with the distribution. 66 * 3. All advertising materials mentioning features or use of this software 67 * must display the following acknowledgement: 68 * This product includes software developed by the University of 69 * California, Berkeley and its contributors. 70 * 4. Neither the name of the University nor the names of its contributors 71 * may be used to endorse or promote products derived from this software 72 * without specific prior written permission. 73 * 74 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 75 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 76 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 77 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 78 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 79 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 80 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 81 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 82 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 83 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 84 * SUCH DAMAGE. 85 * 86 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 87 */ 88 89/*- 90 * Copyright (c) 2001 The NetBSD Foundation, Inc. 91 * All rights reserved. 92 * 93 * This code is derived from software contributed to The NetBSD Foundation 94 * by Jason R. Thorpe. 95 * 96 * Redistribution and use in source and binary forms, with or without 97 * modification, are permitted provided that the following conditions 98 * are met: 99 * 1. Redistributions of source code must retain the above copyright 100 * notice, this list of conditions and the following disclaimer. 101 * 2. Redistributions in binary form must reproduce the above copyright 102 * notice, this list of conditions and the following disclaimer in the 103 * documentation and/or other materials provided with the distribution. 104 * 3. All advertising materials mentioning features or use of this software 105 * must display the following acknowledgement: 106 * This product includes software developed by the NetBSD 107 * Foundation, Inc. and its contributors. 108 * 4. Neither the name of The NetBSD Foundation nor the names of its 109 * contributors may be used to endorse or promote products derived 110 * from this software without specific prior written permission. 111 * 112 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 113 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 114 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 115 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 116 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 117 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 118 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 119 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 120 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 121 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 122 * POSSIBILITY OF SUCH DAMAGE. 123 */ 124 125/* 126 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 127 * 128 * Taken from NetBSD 129 * 130 * "Stub" to allow remote cpu to debug over a serial line using gdb. 131 */ 132 133#include <sys/signal.h> 134#include <unistd.h> 135 136#include <string> 137 138#include "arch/arm/decoder.hh" 139#include "arch/arm/pagetable.hh" 140#include "arch/arm/registers.hh" 141#include "arch/arm/remote_gdb.hh" 142#include "arch/arm/system.hh" 143#include "arch/arm/utility.hh" 144#include "arch/arm/vtophys.hh"
|
182 183 DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va); 184 return true; 185 } else { 186 TlbEntry entry; 187 //Check to make sure the first byte is mapped into the processes address 188 //space. 189 if (context->getProcessPtr()->pTable->lookup(va, entry)) 190 return true; 191 return false; 192 } 193} 194 195/* 196 * Translate the kernel debugger register format into the GDB register 197 * format. 198 */ 199void 200RemoteGDB::getregs() 201{ 202 DPRINTF(GDBAcc, "getregs in remotegdb \n"); 203 204 memset(gdbregs.regs, 0, gdbregs.bytes()); 205 206 if (inAArch64(context)) { // AArch64 207 // x0-x31 208 for (int i = 0; i < 32; ++i) 209 gdbregs.regs64[GDB64_X0 + i] = context->readIntReg(INTREG_X0 + i); 210 // pc 211 gdbregs.regs64[GDB64_PC] = context->pcState().pc(); 212 // cpsr 213 gdbregs.regs64[GDB64_CPSR] = 214 context->readMiscRegNoEffect(MISCREG_CPSR); 215 // v0-v31 216 for (int i = 0; i < 128; i += 4) { 217 int gdboff = GDB64_V0_32 + i; 218 gdbregs.regs32[gdboff + 0] = context->readFloatRegBits(i + 2); 219 gdbregs.regs32[gdboff + 1] = context->readFloatRegBits(i + 3); 220 gdbregs.regs32[gdboff + 2] = context->readFloatRegBits(i + 0); 221 gdbregs.regs32[gdboff + 3] = context->readFloatRegBits(i + 1); 222 } 223 } else { // AArch32 224 // R0-R15 supervisor mode 225 gdbregs.regs32[GDB32_R0 + 0] = context->readIntReg(INTREG_R0); 226 gdbregs.regs32[GDB32_R0 + 1] = context->readIntReg(INTREG_R1); 227 gdbregs.regs32[GDB32_R0 + 2] = context->readIntReg(INTREG_R2); 228 gdbregs.regs32[GDB32_R0 + 3] = context->readIntReg(INTREG_R3); 229 gdbregs.regs32[GDB32_R0 + 4] = context->readIntReg(INTREG_R4); 230 gdbregs.regs32[GDB32_R0 + 5] = context->readIntReg(INTREG_R5); 231 gdbregs.regs32[GDB32_R0 + 6] = context->readIntReg(INTREG_R6); 232 gdbregs.regs32[GDB32_R0 + 7] = context->readIntReg(INTREG_R7); 233 gdbregs.regs32[GDB32_R0 + 8] = context->readIntReg(INTREG_R8); 234 gdbregs.regs32[GDB32_R0 + 9] = context->readIntReg(INTREG_R9); 235 gdbregs.regs32[GDB32_R0 + 10] = context->readIntReg(INTREG_R10); 236 gdbregs.regs32[GDB32_R0 + 11] = context->readIntReg(INTREG_R11); 237 gdbregs.regs32[GDB32_R0 + 12] = context->readIntReg(INTREG_R12); 238 gdbregs.regs32[GDB32_R0 + 13] = context->readIntReg(INTREG_SP); 239 gdbregs.regs32[GDB32_R0 + 14] = context->readIntReg(INTREG_LR); 240 gdbregs.regs32[GDB32_R0 + 15] = context->pcState().pc(); 241 242 // CPSR 243 gdbregs.regs32[GDB32_CPSR] = context->readMiscRegNoEffect(MISCREG_CPSR); 244 245 // vfpv3/neon floating point registers (32 double or 64 float) 246 for (int i = 0; i < NumFloatV7ArchRegs; ++i) 247 gdbregs.regs32[GDB32_F0 + i] = context->readFloatRegBits(i); 248 249 // FPSCR 250 gdbregs.regs32[GDB32_FPSCR] = 251 context->readMiscRegNoEffect(MISCREG_FPSCR); 252 } 253} 254 255/* 256 * Translate the GDB register format into the kernel debugger register 257 * format. 258 */ 259void 260RemoteGDB::setregs() 261{ 262 263 DPRINTF(GDBAcc, "setregs in remotegdb \n"); 264 if (inAArch64(context)) { // AArch64 265 // x0-x31 266 for (int i = 0; i < 32; ++i) 267 context->setIntReg(INTREG_X0 + i, gdbregs.regs64[GDB64_X0 + i]); 268 // pc 269 context->pcState(gdbregs.regs64[GDB64_PC]); 270 // cpsr 271 context->setMiscRegNoEffect(MISCREG_CPSR, gdbregs.regs64[GDB64_CPSR]); 272 // v0-v31 273 for (int i = 0; i < 128; i += 4) { 274 int gdboff = GDB64_V0_32 + i; 275 context->setFloatRegBits(i + 2, gdbregs.regs32[gdboff + 0]); 276 context->setFloatRegBits(i + 3, gdbregs.regs32[gdboff + 1]); 277 context->setFloatRegBits(i + 0, gdbregs.regs32[gdboff + 2]); 278 context->setFloatRegBits(i + 1, gdbregs.regs32[gdboff + 3]); 279 } 280 } else { // AArch32 281 // R0-R15 supervisor mode 282 // arm registers are 32 bits wide, gdb registers are 64 bits wide 283 // two arm registers are packed into one gdb register (little endian) 284 context->setIntReg(INTREG_R0, gdbregs.regs32[GDB32_R0 + 0]); 285 context->setIntReg(INTREG_R1, gdbregs.regs32[GDB32_R0 + 1]); 286 context->setIntReg(INTREG_R2, gdbregs.regs32[GDB32_R0 + 2]); 287 context->setIntReg(INTREG_R3, gdbregs.regs32[GDB32_R0 + 3]); 288 context->setIntReg(INTREG_R4, gdbregs.regs32[GDB32_R0 + 4]); 289 context->setIntReg(INTREG_R5, gdbregs.regs32[GDB32_R0 + 5]); 290 context->setIntReg(INTREG_R6, gdbregs.regs32[GDB32_R0 + 6]); 291 context->setIntReg(INTREG_R7, gdbregs.regs32[GDB32_R0 + 7]); 292 context->setIntReg(INTREG_R8, gdbregs.regs32[GDB32_R0 + 8]); 293 context->setIntReg(INTREG_R9, gdbregs.regs32[GDB32_R0 + 9]); 294 context->setIntReg(INTREG_R10, gdbregs.regs32[GDB32_R0 + 10]); 295 context->setIntReg(INTREG_R11, gdbregs.regs32[GDB32_R0 + 11]); 296 context->setIntReg(INTREG_R12, gdbregs.regs32[GDB32_R0 + 12]); 297 context->setIntReg(INTREG_SP, gdbregs.regs32[GDB32_R0 + 13]); 298 context->setIntReg(INTREG_LR, gdbregs.regs32[GDB32_R0 + 14]); 299 context->pcState(gdbregs.regs32[GDB32_R0 + 7]); 300 301 //CPSR 302 context->setMiscRegNoEffect(MISCREG_CPSR, gdbregs.regs32[GDB32_CPSR]); 303 304 //vfpv3/neon floating point registers (32 double or 64 float) 305 for (int i = 0; i < NumFloatV7ArchRegs; ++i) 306 context->setFloatRegBits(i, gdbregs.regs32[GDB32_F0 + i]); 307 308 //FPSCR 309 context->setMiscReg(MISCREG_FPSCR, gdbregs.regs32[GDB32_FPSCR]); 310 } 311} 312 313// Write bytes to kernel address space for debugger. 314bool 315RemoteGDB::write(Addr vaddr, size_t size, const char *data) 316{ 317 return BaseRemoteGDB::write(vaddr, size, data); 318} 319
|