remote_gdb.cc revision 12221
13536SN/A/* 211274Sshingarov@labware.com * Copyright 2015 LabWare 310595Sgabeblack@google.com * Copyright 2014 Google Inc. 412109SRekai.GonzalezAlberquilla@arm.com * Copyright (c) 2010, 2013, 2016 ARM Limited 57752SWilliam.Wang@arm.com * All rights reserved 67752SWilliam.Wang@arm.com * 77752SWilliam.Wang@arm.com * The license below extends only to copyright in the software and shall 87752SWilliam.Wang@arm.com * not be construed as granting a license to any other intellectual 97752SWilliam.Wang@arm.com * property including but not limited to intellectual property relating 107752SWilliam.Wang@arm.com * to a hardware implementation of the functionality of the software 117752SWilliam.Wang@arm.com * licensed hereunder. You may use the software subject to the license 127752SWilliam.Wang@arm.com * terms below provided that you ensure that this notice is replicated 137752SWilliam.Wang@arm.com * unmodified and in its entirety in all distributions of the software, 147752SWilliam.Wang@arm.com * modified or unmodified, in source code or in binary form. 157752SWilliam.Wang@arm.com * 163536SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 173536SN/A * All rights reserved. 183536SN/A * 193536SN/A * Redistribution and use in source and binary forms, with or without 203536SN/A * modification, are permitted provided that the following conditions are 213536SN/A * met: redistributions of source code must retain the above copyright 223536SN/A * notice, this list of conditions and the following disclaimer; 233536SN/A * redistributions in binary form must reproduce the above copyright 243536SN/A * notice, this list of conditions and the following disclaimer in the 253536SN/A * documentation and/or other materials provided with the distribution; 263536SN/A * neither the name of the copyright holders nor the names of its 273536SN/A * contributors may be used to endorse or promote products derived from 283536SN/A * this software without specific prior written permission. 293536SN/A * 303536SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 313536SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 323536SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 333536SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 343536SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 353536SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 363536SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 373536SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 383536SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 393536SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 403536SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 413536SN/A * 423536SN/A * Authors: Nathan Binkert 437752SWilliam.Wang@arm.com * William Wang 4411274Sshingarov@labware.com * Boris Shingarov 453536SN/A */ 463536SN/A 473536SN/A/* 488332Snate@binkert.org * Copyright (c) 1990, 1993 The Regents of the University of California 498332Snate@binkert.org * All rights reserved 503536SN/A * 513536SN/A * This software was developed by the Computer Systems Engineering group 523536SN/A * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 533536SN/A * contributed to Berkeley. 543536SN/A * 553536SN/A * All advertising materials mentioning features or use of this software 563536SN/A * must display the following acknowledgement: 575543SN/A * This product includes software developed by the University of 585543SN/A * California, Lawrence Berkeley Laboratories. 593536SN/A * 603536SN/A * Redistribution and use in source and binary forms, with or without 613536SN/A * modification, are permitted provided that the following conditions 623536SN/A * are met: 633536SN/A * 1. Redistributions of source code must retain the above copyright 643536SN/A * notice, this list of conditions and the following disclaimer. 653536SN/A * 2. Redistributions in binary form must reproduce the above copyright 663536SN/A * notice, this list of conditions and the following disclaimer in the 673536SN/A * documentation and/or other materials provided with the distribution. 683536SN/A * 3. All advertising materials mentioning features or use of this software 693536SN/A * must display the following acknowledgement: 705543SN/A * This product includes software developed by the University of 715543SN/A * California, Berkeley and its contributors. 723536SN/A * 4. Neither the name of the University nor the names of its contributors 733536SN/A * may be used to endorse or promote products derived from this software 743536SN/A * without specific prior written permission. 753536SN/A * 763536SN/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 773536SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 783536SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 793536SN/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 803536SN/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 813536SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 823536SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 833536SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 843536SN/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 853536SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 863536SN/A * SUCH DAMAGE. 873536SN/A * 885543SN/A * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 893536SN/A */ 903536SN/A 913536SN/A/*- 923536SN/A * Copyright (c) 2001 The NetBSD Foundation, Inc. 933536SN/A * All rights reserved. 943536SN/A * 953536SN/A * This code is derived from software contributed to The NetBSD Foundation 963536SN/A * by Jason R. Thorpe. 973536SN/A * 983536SN/A * Redistribution and use in source and binary forms, with or without 993536SN/A * modification, are permitted provided that the following conditions 1003536SN/A * are met: 1013536SN/A * 1. Redistributions of source code must retain the above copyright 1023536SN/A * notice, this list of conditions and the following disclaimer. 1033536SN/A * 2. Redistributions in binary form must reproduce the above copyright 1043536SN/A * notice, this list of conditions and the following disclaimer in the 1053536SN/A * documentation and/or other materials provided with the distribution. 1063536SN/A * 3. All advertising materials mentioning features or use of this software 1073536SN/A * must display the following acknowledgement: 1085543SN/A * This product includes software developed by the NetBSD 1095543SN/A * Foundation, Inc. and its contributors. 1103536SN/A * 4. Neither the name of The NetBSD Foundation nor the names of its 1113536SN/A * contributors may be used to endorse or promote products derived 1123536SN/A * from this software without specific prior written permission. 1133536SN/A * 1143536SN/A * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1153536SN/A * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1163536SN/A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1173536SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1183536SN/A * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1193536SN/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1203536SN/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1213536SN/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1223536SN/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1233536SN/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1243536SN/A * POSSIBILITY OF SUCH DAMAGE. 1253536SN/A */ 1263536SN/A 1273536SN/A/* 1283536SN/A * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 1293536SN/A * 1303536SN/A * Taken from NetBSD 1313536SN/A * 1323536SN/A * "Stub" to allow remote cpu to debug over a serial line using gdb. 1333536SN/A */ 1343536SN/A 13511793Sbrandon.potter@amd.com#include "arch/arm/remote_gdb.hh" 13611793Sbrandon.potter@amd.com 1373536SN/A#include <sys/signal.h> 1385569SN/A#include <unistd.h> 1393536SN/A 1403536SN/A#include <string> 1413536SN/A 1429020Sgblack@eecs.umich.edu#include "arch/arm/decoder.hh" 1438229Snate@binkert.org#include "arch/arm/pagetable.hh" 1448229Snate@binkert.org#include "arch/arm/registers.hh" 14510037SARM gem5 Developers#include "arch/arm/system.hh" 1467752SWilliam.Wang@arm.com#include "arch/arm/utility.hh" 1477752SWilliam.Wang@arm.com#include "arch/arm/vtophys.hh" 14810707SAndreas.Sandberg@ARM.com#include "base/chunk_generator.hh" 1493536SN/A#include "base/intmath.hh" 1503536SN/A#include "base/remote_gdb.hh" 1513536SN/A#include "base/socket.hh" 1523536SN/A#include "base/trace.hh" 1538229Snate@binkert.org#include "cpu/static_inst.hh" 1543536SN/A#include "cpu/thread_context.hh" 1557752SWilliam.Wang@arm.com#include "cpu/thread_state.hh" 1568232Snate@binkert.org#include "debug/GDBAcc.hh" 1578232Snate@binkert.org#include "debug/GDBMisc.hh" 1588229Snate@binkert.org#include "mem/page_table.hh" 1593536SN/A#include "mem/physical.hh" 1603536SN/A#include "mem/port.hh" 1618782Sgblack@eecs.umich.edu#include "sim/full_system.hh" 1623536SN/A#include "sim/system.hh" 1633536SN/A 1643536SN/Ausing namespace std; 1657752SWilliam.Wang@arm.comusing namespace ArmISA; 1663536SN/A 1675569SN/ARemoteGDB::RemoteGDB(System *_system, ThreadContext *tc) 16812031Sgabeblack@google.com : BaseRemoteGDB(_system, tc), regCache32(this), regCache64(this) 1693536SN/A{ 1703536SN/A} 1713536SN/A 1725569SN/A/* 1735569SN/A * Determine if the mapping at va..(va+len) is valid. 1745569SN/A */ 1753536SN/Abool 1763536SN/ARemoteGDB::acc(Addr va, size_t len) 1773536SN/A{ 1788782Sgblack@eecs.umich.edu if (FullSystem) { 17910707SAndreas.Sandberg@ARM.com for (ChunkGenerator gen(va, len, PageBytes); !gen.done(); gen.next()) { 18010707SAndreas.Sandberg@ARM.com if (!virtvalid(context, gen.addr())) { 18110707SAndreas.Sandberg@ARM.com DPRINTF(GDBAcc, "acc: %#x mapping is invalid\n", va); 18210707SAndreas.Sandberg@ARM.com return false; 1838782Sgblack@eecs.umich.edu } 18410707SAndreas.Sandberg@ARM.com } 1858782Sgblack@eecs.umich.edu 1868782Sgblack@eecs.umich.edu DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va); 1878782Sgblack@eecs.umich.edu return true; 1888782Sgblack@eecs.umich.edu } else { 1898782Sgblack@eecs.umich.edu TlbEntry entry; 1908782Sgblack@eecs.umich.edu //Check to make sure the first byte is mapped into the processes address 1918782Sgblack@eecs.umich.edu //space. 1928782Sgblack@eecs.umich.edu if (context->getProcessPtr()->pTable->lookup(va, entry)) 1933536SN/A return true; 1948782Sgblack@eecs.umich.edu return false; 1958782Sgblack@eecs.umich.edu } 1963536SN/A} 1973536SN/A 1983536SN/Avoid 19911274Sshingarov@labware.comRemoteGDB::AArch64GdbRegCache::getRegs(ThreadContext *context) 2003536SN/A{ 20111274Sshingarov@labware.com DPRINTF(GDBAcc, "getRegs in remotegdb \n"); 2027752SWilliam.Wang@arm.com 20311274Sshingarov@labware.com for (int i = 0; i < 31; ++i) 20411274Sshingarov@labware.com r.x[i] = context->readIntReg(INTREG_X0 + i); 20511274Sshingarov@labware.com r.spx = context->readIntReg(INTREG_SPX); 20611274Sshingarov@labware.com r.pc = context->pcState().pc(); 20711274Sshingarov@labware.com r.cpsr = context->readMiscRegNoEffect(MISCREG_CPSR); 2083536SN/A 20911274Sshingarov@labware.com for (int i = 0; i < 32*4; i += 4) { 21011274Sshingarov@labware.com r.v[i + 0] = context->readFloatRegBits(i + 2); 21111274Sshingarov@labware.com r.v[i + 1] = context->readFloatRegBits(i + 3); 21211274Sshingarov@labware.com r.v[i + 2] = context->readFloatRegBits(i + 0); 21311274Sshingarov@labware.com r.v[i + 3] = context->readFloatRegBits(i + 1); 2143536SN/A } 21512109SRekai.GonzalezAlberquilla@arm.com 21612109SRekai.GonzalezAlberquilla@arm.com for (int i = 0; i < 32; i ++) { 21712109SRekai.GonzalezAlberquilla@arm.com r.vec[i] = context->readVecReg(RegId(VecRegClass,i)); 21812109SRekai.GonzalezAlberquilla@arm.com } 2193536SN/A} 2203536SN/A 2213536SN/Avoid 22211274Sshingarov@labware.comRemoteGDB::AArch64GdbRegCache::setRegs(ThreadContext *context) const 2233536SN/A{ 22411274Sshingarov@labware.com DPRINTF(GDBAcc, "setRegs in remotegdb \n"); 2257752SWilliam.Wang@arm.com 22611274Sshingarov@labware.com for (int i = 0; i < 31; ++i) 22711274Sshingarov@labware.com context->setIntReg(INTREG_X0 + i, r.x[i]); 22811274Sshingarov@labware.com context->pcState(r.pc); 22911274Sshingarov@labware.com context->setMiscRegNoEffect(MISCREG_CPSR, r.cpsr); 23011274Sshingarov@labware.com // Update the stack pointer. This should be done after 23111274Sshingarov@labware.com // updating CPSR/PSTATE since that might affect how SPX gets 23211274Sshingarov@labware.com // mapped. 23311274Sshingarov@labware.com context->setIntReg(INTREG_SPX, r.spx); 2347752SWilliam.Wang@arm.com 23511274Sshingarov@labware.com for (int i = 0; i < 32*4; i += 4) { 23611274Sshingarov@labware.com context->setFloatRegBits(i + 2, r.v[i + 0]); 23711274Sshingarov@labware.com context->setFloatRegBits(i + 3, r.v[i + 1]); 23811274Sshingarov@labware.com context->setFloatRegBits(i + 0, r.v[i + 2]); 23911274Sshingarov@labware.com context->setFloatRegBits(i + 1, r.v[i + 3]); 2403536SN/A } 24112109SRekai.GonzalezAlberquilla@arm.com 24212109SRekai.GonzalezAlberquilla@arm.com for (int i = 0; i < 32; i ++) { 24312109SRekai.GonzalezAlberquilla@arm.com context->setVecReg(RegId(VecRegClass, i), r.vec[i]); 24412109SRekai.GonzalezAlberquilla@arm.com } 2453536SN/A} 2463536SN/A 24711274Sshingarov@labware.comvoid 24811274Sshingarov@labware.comRemoteGDB::AArch32GdbRegCache::getRegs(ThreadContext *context) 2493536SN/A{ 25011274Sshingarov@labware.com DPRINTF(GDBAcc, "getRegs in remotegdb \n"); 25111274Sshingarov@labware.com 25211274Sshingarov@labware.com r.gpr[0] = context->readIntReg(INTREG_R0); 25311274Sshingarov@labware.com r.gpr[1] = context->readIntReg(INTREG_R1); 25411274Sshingarov@labware.com r.gpr[2] = context->readIntReg(INTREG_R2); 25511274Sshingarov@labware.com r.gpr[3] = context->readIntReg(INTREG_R3); 25611274Sshingarov@labware.com r.gpr[4] = context->readIntReg(INTREG_R4); 25711274Sshingarov@labware.com r.gpr[5] = context->readIntReg(INTREG_R5); 25811274Sshingarov@labware.com r.gpr[6] = context->readIntReg(INTREG_R6); 25911274Sshingarov@labware.com r.gpr[7] = context->readIntReg(INTREG_R7); 26011274Sshingarov@labware.com r.gpr[8] = context->readIntReg(INTREG_R8); 26111274Sshingarov@labware.com r.gpr[9] = context->readIntReg(INTREG_R9); 26211274Sshingarov@labware.com r.gpr[10] = context->readIntReg(INTREG_R10); 26311274Sshingarov@labware.com r.gpr[11] = context->readIntReg(INTREG_R11); 26411274Sshingarov@labware.com r.gpr[12] = context->readIntReg(INTREG_R12); 26511274Sshingarov@labware.com r.gpr[13] = context->readIntReg(INTREG_SP); 26611274Sshingarov@labware.com r.gpr[14] = context->readIntReg(INTREG_LR); 26711274Sshingarov@labware.com r.gpr[15] = context->pcState().pc(); 26811274Sshingarov@labware.com 26911274Sshingarov@labware.com // One day somebody will implement transfer of FPRs correctly. 27011274Sshingarov@labware.com for (int i=0; i<8*3; i++) r.fpr[i] = 0; 27111274Sshingarov@labware.com 27211274Sshingarov@labware.com r.fpscr = context->readMiscRegNoEffect(MISCREG_FPSCR); 27311274Sshingarov@labware.com r.cpsr = context->readMiscRegNoEffect(MISCREG_CPSR); 2743536SN/A} 2753536SN/A 27611274Sshingarov@labware.comvoid 27711274Sshingarov@labware.comRemoteGDB::AArch32GdbRegCache::setRegs(ThreadContext *context) const 27811274Sshingarov@labware.com{ 27911274Sshingarov@labware.com DPRINTF(GDBAcc, "setRegs in remotegdb \n"); 28011274Sshingarov@labware.com 28111274Sshingarov@labware.com context->setIntReg(INTREG_R0, r.gpr[0]); 28211274Sshingarov@labware.com context->setIntReg(INTREG_R1, r.gpr[1]); 28311274Sshingarov@labware.com context->setIntReg(INTREG_R2, r.gpr[2]); 28411274Sshingarov@labware.com context->setIntReg(INTREG_R3, r.gpr[3]); 28511274Sshingarov@labware.com context->setIntReg(INTREG_R4, r.gpr[4]); 28611274Sshingarov@labware.com context->setIntReg(INTREG_R5, r.gpr[5]); 28711274Sshingarov@labware.com context->setIntReg(INTREG_R6, r.gpr[6]); 28811274Sshingarov@labware.com context->setIntReg(INTREG_R7, r.gpr[7]); 28911274Sshingarov@labware.com context->setIntReg(INTREG_R8, r.gpr[8]); 29011274Sshingarov@labware.com context->setIntReg(INTREG_R9, r.gpr[9]); 29111274Sshingarov@labware.com context->setIntReg(INTREG_R10, r.gpr[10]); 29211274Sshingarov@labware.com context->setIntReg(INTREG_R11, r.gpr[11]); 29311274Sshingarov@labware.com context->setIntReg(INTREG_R12, r.gpr[12]); 29411274Sshingarov@labware.com context->setIntReg(INTREG_SP, r.gpr[13]); 29511274Sshingarov@labware.com context->setIntReg(INTREG_LR, r.gpr[14]); 29611274Sshingarov@labware.com context->pcState(r.gpr[15]); 29711274Sshingarov@labware.com 29811274Sshingarov@labware.com // One day somebody will implement transfer of FPRs correctly. 29911274Sshingarov@labware.com 30011274Sshingarov@labware.com context->setMiscReg(MISCREG_FPSCR, r.fpscr); 30111274Sshingarov@labware.com context->setMiscRegNoEffect(MISCREG_CPSR, r.cpsr); 30211274Sshingarov@labware.com} 30311274Sshingarov@labware.com 30411274Sshingarov@labware.comRemoteGDB::BaseGdbRegCache* 30511274Sshingarov@labware.comRemoteGDB::gdbRegs() 30611274Sshingarov@labware.com{ 30711274Sshingarov@labware.com if (inAArch64(context)) 30812221Sshingarov@gmail.com return ®Cache64; 30912221Sshingarov@gmail.com else 31012031Sgabeblack@google.com return ®Cache32; 31111274Sshingarov@labware.com} 312