remote_gdb.cc revision 10707
13536SN/A/* 210595Sgabeblack@google.com * Copyright 2014 Google Inc. 310037SARM gem5 Developers * Copyright (c) 2010, 2013 ARM Limited 47752SWilliam.Wang@arm.com * All rights reserved 57752SWilliam.Wang@arm.com * 67752SWilliam.Wang@arm.com * The license below extends only to copyright in the software and shall 77752SWilliam.Wang@arm.com * not be construed as granting a license to any other intellectual 87752SWilliam.Wang@arm.com * property including but not limited to intellectual property relating 97752SWilliam.Wang@arm.com * to a hardware implementation of the functionality of the software 107752SWilliam.Wang@arm.com * licensed hereunder. You may use the software subject to the license 117752SWilliam.Wang@arm.com * terms below provided that you ensure that this notice is replicated 127752SWilliam.Wang@arm.com * unmodified and in its entirety in all distributions of the software, 137752SWilliam.Wang@arm.com * modified or unmodified, in source code or in binary form. 147752SWilliam.Wang@arm.com * 153536SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 163536SN/A * All rights reserved. 173536SN/A * 183536SN/A * Redistribution and use in source and binary forms, with or without 193536SN/A * modification, are permitted provided that the following conditions are 203536SN/A * met: redistributions of source code must retain the above copyright 213536SN/A * notice, this list of conditions and the following disclaimer; 223536SN/A * redistributions in binary form must reproduce the above copyright 233536SN/A * notice, this list of conditions and the following disclaimer in the 243536SN/A * documentation and/or other materials provided with the distribution; 253536SN/A * neither the name of the copyright holders nor the names of its 263536SN/A * contributors may be used to endorse or promote products derived from 273536SN/A * this software without specific prior written permission. 283536SN/A * 293536SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 303536SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 313536SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 323536SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 333536SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 343536SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 353536SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 363536SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 373536SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 383536SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 393536SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 403536SN/A * 413536SN/A * Authors: Nathan Binkert 427752SWilliam.Wang@arm.com * William Wang 433536SN/A */ 443536SN/A 453536SN/A/* 468332Snate@binkert.org * Copyright (c) 1990, 1993 The Regents of the University of California 478332Snate@binkert.org * All rights reserved 483536SN/A * 493536SN/A * This software was developed by the Computer Systems Engineering group 503536SN/A * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 513536SN/A * contributed to Berkeley. 523536SN/A * 533536SN/A * All advertising materials mentioning features or use of this software 543536SN/A * must display the following acknowledgement: 555543SN/A * This product includes software developed by the University of 565543SN/A * California, Lawrence Berkeley Laboratories. 573536SN/A * 583536SN/A * Redistribution and use in source and binary forms, with or without 593536SN/A * modification, are permitted provided that the following conditions 603536SN/A * are met: 613536SN/A * 1. Redistributions of source code must retain the above copyright 623536SN/A * notice, this list of conditions and the following disclaimer. 633536SN/A * 2. Redistributions in binary form must reproduce the above copyright 643536SN/A * notice, this list of conditions and the following disclaimer in the 653536SN/A * documentation and/or other materials provided with the distribution. 663536SN/A * 3. All advertising materials mentioning features or use of this software 673536SN/A * must display the following acknowledgement: 685543SN/A * This product includes software developed by the University of 695543SN/A * California, Berkeley and its contributors. 703536SN/A * 4. Neither the name of the University nor the names of its contributors 713536SN/A * may be used to endorse or promote products derived from this software 723536SN/A * without specific prior written permission. 733536SN/A * 743536SN/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 753536SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 763536SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 773536SN/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 783536SN/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 793536SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 803536SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 813536SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 823536SN/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 833536SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 843536SN/A * SUCH DAMAGE. 853536SN/A * 865543SN/A * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 873536SN/A */ 883536SN/A 893536SN/A/*- 903536SN/A * Copyright (c) 2001 The NetBSD Foundation, Inc. 913536SN/A * All rights reserved. 923536SN/A * 933536SN/A * This code is derived from software contributed to The NetBSD Foundation 943536SN/A * by Jason R. Thorpe. 953536SN/A * 963536SN/A * Redistribution and use in source and binary forms, with or without 973536SN/A * modification, are permitted provided that the following conditions 983536SN/A * are met: 993536SN/A * 1. Redistributions of source code must retain the above copyright 1003536SN/A * notice, this list of conditions and the following disclaimer. 1013536SN/A * 2. Redistributions in binary form must reproduce the above copyright 1023536SN/A * notice, this list of conditions and the following disclaimer in the 1033536SN/A * documentation and/or other materials provided with the distribution. 1043536SN/A * 3. All advertising materials mentioning features or use of this software 1053536SN/A * must display the following acknowledgement: 1065543SN/A * This product includes software developed by the NetBSD 1075543SN/A * Foundation, Inc. and its contributors. 1083536SN/A * 4. Neither the name of The NetBSD Foundation nor the names of its 1093536SN/A * contributors may be used to endorse or promote products derived 1103536SN/A * from this software without specific prior written permission. 1113536SN/A * 1123536SN/A * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1133536SN/A * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1143536SN/A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1153536SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1163536SN/A * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1173536SN/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1183536SN/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1193536SN/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1203536SN/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1213536SN/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1223536SN/A * POSSIBILITY OF SUCH DAMAGE. 1233536SN/A */ 1243536SN/A 1253536SN/A/* 1263536SN/A * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 1273536SN/A * 1283536SN/A * Taken from NetBSD 1293536SN/A * 1303536SN/A * "Stub" to allow remote cpu to debug over a serial line using gdb. 1313536SN/A */ 1323536SN/A 1333536SN/A#include <sys/signal.h> 1345569SN/A#include <unistd.h> 1353536SN/A 1363536SN/A#include <string> 1373536SN/A 1389020Sgblack@eecs.umich.edu#include "arch/arm/decoder.hh" 1398229Snate@binkert.org#include "arch/arm/pagetable.hh" 1408229Snate@binkert.org#include "arch/arm/registers.hh" 1418229Snate@binkert.org#include "arch/arm/remote_gdb.hh" 14210037SARM gem5 Developers#include "arch/arm/system.hh" 1437752SWilliam.Wang@arm.com#include "arch/arm/utility.hh" 1447752SWilliam.Wang@arm.com#include "arch/arm/vtophys.hh" 14510707SAndreas.Sandberg@ARM.com#include "base/chunk_generator.hh" 1463536SN/A#include "base/intmath.hh" 1473536SN/A#include "base/remote_gdb.hh" 1483536SN/A#include "base/socket.hh" 1493536SN/A#include "base/trace.hh" 1508229Snate@binkert.org#include "cpu/static_inst.hh" 1513536SN/A#include "cpu/thread_context.hh" 1527752SWilliam.Wang@arm.com#include "cpu/thread_state.hh" 1538232Snate@binkert.org#include "debug/GDBAcc.hh" 1548232Snate@binkert.org#include "debug/GDBMisc.hh" 1558229Snate@binkert.org#include "mem/page_table.hh" 1563536SN/A#include "mem/physical.hh" 1573536SN/A#include "mem/port.hh" 1588782Sgblack@eecs.umich.edu#include "sim/full_system.hh" 1593536SN/A#include "sim/system.hh" 1603536SN/A 1613536SN/Ausing namespace std; 1627752SWilliam.Wang@arm.comusing namespace ArmISA; 1633536SN/A 1645569SN/ARemoteGDB::RemoteGDB(System *_system, ThreadContext *tc) 16510601Sgabeblack@google.com : BaseRemoteGDB(_system, tc, GDB_REG_BYTES) 1663536SN/A{ 1673536SN/A} 1683536SN/A 1695569SN/A/* 1705569SN/A * Determine if the mapping at va..(va+len) is valid. 1715569SN/A */ 1723536SN/Abool 1733536SN/ARemoteGDB::acc(Addr va, size_t len) 1743536SN/A{ 1758782Sgblack@eecs.umich.edu if (FullSystem) { 17610707SAndreas.Sandberg@ARM.com for (ChunkGenerator gen(va, len, PageBytes); !gen.done(); gen.next()) { 17710707SAndreas.Sandberg@ARM.com if (!virtvalid(context, gen.addr())) { 17810707SAndreas.Sandberg@ARM.com DPRINTF(GDBAcc, "acc: %#x mapping is invalid\n", va); 17910707SAndreas.Sandberg@ARM.com return false; 1808782Sgblack@eecs.umich.edu } 18110707SAndreas.Sandberg@ARM.com } 1828782Sgblack@eecs.umich.edu 1838782Sgblack@eecs.umich.edu DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va); 1848782Sgblack@eecs.umich.edu return true; 1858782Sgblack@eecs.umich.edu } else { 1868782Sgblack@eecs.umich.edu TlbEntry entry; 1878782Sgblack@eecs.umich.edu //Check to make sure the first byte is mapped into the processes address 1888782Sgblack@eecs.umich.edu //space. 1898782Sgblack@eecs.umich.edu if (context->getProcessPtr()->pTable->lookup(va, entry)) 1903536SN/A return true; 1918782Sgblack@eecs.umich.edu return false; 1928782Sgblack@eecs.umich.edu } 1933536SN/A} 1943536SN/A 1955569SN/A/* 1965569SN/A * Translate the kernel debugger register format into the GDB register 1975569SN/A * format. 1985569SN/A */ 1993536SN/Avoid 2003536SN/ARemoteGDB::getregs() 2013536SN/A{ 2027752SWilliam.Wang@arm.com DPRINTF(GDBAcc, "getregs in remotegdb \n"); 2037752SWilliam.Wang@arm.com 2043579SN/A memset(gdbregs.regs, 0, gdbregs.bytes()); 2053536SN/A 20610037SARM gem5 Developers if (inAArch64(context)) { // AArch64 20710037SARM gem5 Developers // x0-x31 20810595Sgabeblack@google.com for (int i = 0; i < 32; ++i) 20910595Sgabeblack@google.com gdbregs.regs64[GDB64_X0 + i] = context->readIntReg(INTREG_X0 + i); 21010037SARM gem5 Developers // pc 21110595Sgabeblack@google.com gdbregs.regs64[GDB64_PC] = context->pcState().pc(); 21210037SARM gem5 Developers // cpsr 21310595Sgabeblack@google.com gdbregs.regs64[GDB64_CPSR] = 21410595Sgabeblack@google.com context->readMiscRegNoEffect(MISCREG_CPSR); 21510037SARM gem5 Developers // v0-v31 21610595Sgabeblack@google.com for (int i = 0; i < 128; i += 4) { 21710595Sgabeblack@google.com int gdboff = GDB64_V0_32 + i; 21810595Sgabeblack@google.com gdbregs.regs32[gdboff + 0] = context->readFloatRegBits(i + 2); 21910595Sgabeblack@google.com gdbregs.regs32[gdboff + 1] = context->readFloatRegBits(i + 3); 22010595Sgabeblack@google.com gdbregs.regs32[gdboff + 2] = context->readFloatRegBits(i + 0); 22110595Sgabeblack@google.com gdbregs.regs32[gdboff + 3] = context->readFloatRegBits(i + 1); 22210037SARM gem5 Developers } 22310037SARM gem5 Developers } else { // AArch32 22410037SARM gem5 Developers // R0-R15 supervisor mode 22510595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 0] = context->readIntReg(INTREG_R0); 22610595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 1] = context->readIntReg(INTREG_R1); 22710595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 2] = context->readIntReg(INTREG_R2); 22810595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 3] = context->readIntReg(INTREG_R3); 22910595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 4] = context->readIntReg(INTREG_R4); 23010595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 5] = context->readIntReg(INTREG_R5); 23110595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 6] = context->readIntReg(INTREG_R6); 23210595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 7] = context->readIntReg(INTREG_R7); 23310595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 8] = context->readIntReg(INTREG_R8); 23410595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 9] = context->readIntReg(INTREG_R9); 23510595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 10] = context->readIntReg(INTREG_R10); 23610595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 11] = context->readIntReg(INTREG_R11); 23710595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 12] = context->readIntReg(INTREG_R12); 23810595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 13] = context->readIntReg(INTREG_SP); 23910595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 14] = context->readIntReg(INTREG_LR); 24010595Sgabeblack@google.com gdbregs.regs32[GDB32_R0 + 15] = context->pcState().pc(); 2413536SN/A 24210037SARM gem5 Developers // CPSR 24310595Sgabeblack@google.com gdbregs.regs32[GDB32_CPSR] = context->readMiscRegNoEffect(MISCREG_CPSR); 2447752SWilliam.Wang@arm.com 24510037SARM gem5 Developers // vfpv3/neon floating point registers (32 double or 64 float) 24610595Sgabeblack@google.com for (int i = 0; i < NumFloatV7ArchRegs; ++i) 24710595Sgabeblack@google.com gdbregs.regs32[GDB32_F0 + i] = context->readFloatRegBits(i); 24810037SARM gem5 Developers 24910037SARM gem5 Developers // FPSCR 25010595Sgabeblack@google.com gdbregs.regs32[GDB32_FPSCR] = 25110595Sgabeblack@google.com context->readMiscRegNoEffect(MISCREG_FPSCR); 2523536SN/A } 2533536SN/A} 2543536SN/A 2555569SN/A/* 2565569SN/A * Translate the GDB register format into the kernel debugger register 2575569SN/A * format. 2585569SN/A */ 2593536SN/Avoid 2603536SN/ARemoteGDB::setregs() 2613536SN/A{ 2627752SWilliam.Wang@arm.com 2637752SWilliam.Wang@arm.com DPRINTF(GDBAcc, "setregs in remotegdb \n"); 26410037SARM gem5 Developers if (inAArch64(context)) { // AArch64 26510037SARM gem5 Developers // x0-x31 26610595Sgabeblack@google.com for (int i = 0; i < 32; ++i) 26710595Sgabeblack@google.com context->setIntReg(INTREG_X0 + i, gdbregs.regs64[GDB64_X0 + i]); 26810037SARM gem5 Developers // pc 26910595Sgabeblack@google.com context->pcState(gdbregs.regs64[GDB64_PC]); 27010037SARM gem5 Developers // cpsr 27110595Sgabeblack@google.com context->setMiscRegNoEffect(MISCREG_CPSR, gdbregs.regs64[GDB64_CPSR]); 27210037SARM gem5 Developers // v0-v31 27310595Sgabeblack@google.com for (int i = 0; i < 128; i += 4) { 27410595Sgabeblack@google.com int gdboff = GDB64_V0_32 + i; 27510595Sgabeblack@google.com context->setFloatRegBits(i + 2, gdbregs.regs32[gdboff + 0]); 27610595Sgabeblack@google.com context->setFloatRegBits(i + 3, gdbregs.regs32[gdboff + 1]); 27710595Sgabeblack@google.com context->setFloatRegBits(i + 0, gdbregs.regs32[gdboff + 2]); 27810595Sgabeblack@google.com context->setFloatRegBits(i + 1, gdbregs.regs32[gdboff + 3]); 27910037SARM gem5 Developers } 28010037SARM gem5 Developers } else { // AArch32 28110037SARM gem5 Developers // R0-R15 supervisor mode 28210037SARM gem5 Developers // arm registers are 32 bits wide, gdb registers are 64 bits wide 28310037SARM gem5 Developers // two arm registers are packed into one gdb register (little endian) 28410595Sgabeblack@google.com context->setIntReg(INTREG_R0, gdbregs.regs32[GDB32_R0 + 0]); 28510595Sgabeblack@google.com context->setIntReg(INTREG_R1, gdbregs.regs32[GDB32_R0 + 1]); 28610595Sgabeblack@google.com context->setIntReg(INTREG_R2, gdbregs.regs32[GDB32_R0 + 2]); 28710595Sgabeblack@google.com context->setIntReg(INTREG_R3, gdbregs.regs32[GDB32_R0 + 3]); 28810595Sgabeblack@google.com context->setIntReg(INTREG_R4, gdbregs.regs32[GDB32_R0 + 4]); 28910595Sgabeblack@google.com context->setIntReg(INTREG_R5, gdbregs.regs32[GDB32_R0 + 5]); 29010595Sgabeblack@google.com context->setIntReg(INTREG_R6, gdbregs.regs32[GDB32_R0 + 6]); 29110595Sgabeblack@google.com context->setIntReg(INTREG_R7, gdbregs.regs32[GDB32_R0 + 7]); 29210595Sgabeblack@google.com context->setIntReg(INTREG_R8, gdbregs.regs32[GDB32_R0 + 8]); 29310595Sgabeblack@google.com context->setIntReg(INTREG_R9, gdbregs.regs32[GDB32_R0 + 9]); 29410595Sgabeblack@google.com context->setIntReg(INTREG_R10, gdbregs.regs32[GDB32_R0 + 10]); 29510595Sgabeblack@google.com context->setIntReg(INTREG_R11, gdbregs.regs32[GDB32_R0 + 11]); 29610595Sgabeblack@google.com context->setIntReg(INTREG_R12, gdbregs.regs32[GDB32_R0 + 12]); 29710595Sgabeblack@google.com context->setIntReg(INTREG_SP, gdbregs.regs32[GDB32_R0 + 13]); 29810595Sgabeblack@google.com context->setIntReg(INTREG_LR, gdbregs.regs32[GDB32_R0 + 14]); 29910595Sgabeblack@google.com context->pcState(gdbregs.regs32[GDB32_R0 + 7]); 3007752SWilliam.Wang@arm.com 30110037SARM gem5 Developers //CPSR 30210595Sgabeblack@google.com context->setMiscRegNoEffect(MISCREG_CPSR, gdbregs.regs32[GDB32_CPSR]); 3037752SWilliam.Wang@arm.com 30410037SARM gem5 Developers //vfpv3/neon floating point registers (32 double or 64 float) 30510595Sgabeblack@google.com for (int i = 0; i < NumFloatV7ArchRegs; ++i) 30610595Sgabeblack@google.com context->setFloatRegBits(i, gdbregs.regs32[GDB32_F0 + i]); 3077752SWilliam.Wang@arm.com 30810037SARM gem5 Developers //FPSCR 30910595Sgabeblack@google.com context->setMiscReg(MISCREG_FPSCR, gdbregs.regs32[GDB32_FPSCR]); 3103536SN/A } 3113536SN/A} 3123536SN/A 3133536SN/A// Write bytes to kernel address space for debugger. 3143536SN/Abool 3153536SN/ARemoteGDB::write(Addr vaddr, size_t size, const char *data) 3163536SN/A{ 3177752SWilliam.Wang@arm.com return BaseRemoteGDB::write(vaddr, size, data); 3183536SN/A} 3193536SN/A 320