remote_gdb.cc revision 11793:ef606668d247
16145SN/A/* 26145SN/A * Copyright 2015 LabWare 36145SN/A * Copyright 2014 Google, Inc. 46145SN/A * Copyright (c) 2010 ARM Limited 56145SN/A * All rights reserved 66145SN/A * 76145SN/A * The license below extends only to copyright in the software and shall 86145SN/A * not be construed as granting a license to any other intellectual 96145SN/A * property including but not limited to intellectual property relating 106145SN/A * to a hardware implementation of the functionality of the software 116145SN/A * licensed hereunder. You may use the software subject to the license 126145SN/A * terms below provided that you ensure that this notice is replicated 136145SN/A * unmodified and in its entirety in all distributions of the software, 146145SN/A * modified or unmodified, in source code or in binary form. 156145SN/A * 166145SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 176145SN/A * All rights reserved. 186145SN/A * 196145SN/A * Redistribution and use in source and binary forms, with or without 206145SN/A * modification, are permitted provided that the following conditions are 216145SN/A * met: redistributions of source code must retain the above copyright 226145SN/A * notice, this list of conditions and the following disclaimer; 236145SN/A * redistributions in binary form must reproduce the above copyright 246145SN/A * notice, this list of conditions and the following disclaimer in the 256145SN/A * documentation and/or other materials provided with the distribution; 266145SN/A * neither the name of the copyright holders nor the names of its 276145SN/A * contributors may be used to endorse or promote products derived from 286145SN/A * this software without specific prior written permission. 297832SN/A * 307832SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 319356Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 328232SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 337054SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 348257SBrad.Beckmann@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 358255SBrad.Beckmann@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 367054SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 376145SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 387055SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 397055SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 407054SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 418257SBrad.Beckmann@amd.com * 426145SN/A * Authors: Nathan Binkert 436145SN/A * William Wang 446145SN/A * Deyuan Guo 456145SN/A * Boris Shingarov 466145SN/A */ 476145SN/A 486145SN/A/* 4911096Snilay@cs.wisc.edu * Copyright (c) 1990, 1993 The Regents of the University of California 5011096Snilay@cs.wisc.edu * All rights reserved 5111096Snilay@cs.wisc.edu * 5211096Snilay@cs.wisc.edu * This software was developed by the Computer Systems Engineering group 5311096Snilay@cs.wisc.edu * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 546145SN/A * contributed to Berkeley. 556881SN/A * 566881SN/A * All advertising materials mentioning features or use of this software 576285SN/A * must display the following acknowledgement: 5811663Stushar@ece.gatech.edu * This product includes software developed by the University of 5911663Stushar@ece.gatech.edu * California, Lawrence Berkeley Laboratories. 6011663Stushar@ece.gatech.edu * 6111663Stushar@ece.gatech.edu * Redistribution and use in source and binary forms, with or without 6211663Stushar@ece.gatech.edu * modification, are permitted provided that the following conditions 6311663Stushar@ece.gatech.edu * are met: 6411663Stushar@ece.gatech.edu * 1. Redistributions of source code must retain the above copyright 6511663Stushar@ece.gatech.edu * notice, this list of conditions and the following disclaimer. 669594Snilay@cs.wisc.edu * 2. Redistributions in binary form must reproduce the above copyright 679594Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the 688257SBrad.Beckmann@amd.com * documentation and/or other materials provided with the distribution. 698257SBrad.Beckmann@amd.com * 3. All advertising materials mentioning features or use of this software 708257SBrad.Beckmann@amd.com * must display the following acknowledgement: 716881SN/A * This product includes software developed by the University of 7210078Snilay@cs.wisc.edu * California, Berkeley and its contributors. 739869Sjthestness@gmail.com * 4. Neither the name of the University nor the names of its contributors 747054SN/A * may be used to endorse or promote products derived from this software 758257SBrad.Beckmann@amd.com * without specific prior written permission. 766145SN/A * 778257SBrad.Beckmann@amd.com * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 7811663Stushar@ece.gatech.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 7911663Stushar@ece.gatech.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 8011663Stushar@ece.gatech.edu * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 8111663Stushar@ece.gatech.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 827054SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 836145SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 8411663Stushar@ece.gatech.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 859594Snilay@cs.wisc.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 869594Snilay@cs.wisc.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 878257SBrad.Beckmann@amd.com * SUCH DAMAGE. 8811663Stushar@ece.gatech.edu * 8911663Stushar@ece.gatech.edu * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 906881SN/A */ 9111664Stushar@ece.gatech.edu 9211664Stushar@ece.gatech.edu/*- 9311664Stushar@ece.gatech.edu * Copyright (c) 2001 The NetBSD Foundation, Inc. 948257SBrad.Beckmann@amd.com * All rights reserved. 958257SBrad.Beckmann@amd.com * 968257SBrad.Beckmann@amd.com * This code is derived from software contributed to The NetBSD Foundation 9711663Stushar@ece.gatech.edu * by Jason R. Thorpe. 9811663Stushar@ece.gatech.edu * 998257SBrad.Beckmann@amd.com * Redistribution and use in source and binary forms, with or without 10011663Stushar@ece.gatech.edu * modification, are permitted provided that the following conditions 10111664Stushar@ece.gatech.edu * are met: 1027054SN/A * 1. Redistributions of source code must retain the above copyright 1036145SN/A * notice, this list of conditions and the following disclaimer. 1046145SN/A * 2. Redistributions in binary form must reproduce the above copyright 1058257SBrad.Beckmann@amd.com * notice, this list of conditions and the following disclaimer in the 1069799Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution. 1077054SN/A * 3. All advertising materials mentioning features or use of this software 1087054SN/A * must display the following acknowledgement: 1097054SN/A * This product includes software developed by the NetBSD 1108257SBrad.Beckmann@amd.com * Foundation, Inc. and its contributors. 1118257SBrad.Beckmann@amd.com * 4. Neither the name of The NetBSD Foundation nor the names of its 11210005Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived 1138257SBrad.Beckmann@amd.com * from this software without specific prior written permission. 11411320Ssteve.reinhardt@amd.com * 1157054SN/A * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1166881SN/A * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1178257SBrad.Beckmann@amd.com * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1187054SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 11911096Snilay@cs.wisc.edu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 12011096Snilay@cs.wisc.edu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 12111096Snilay@cs.wisc.edu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 12211096Snilay@cs.wisc.edu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 12311096Snilay@cs.wisc.edu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 12411096Snilay@cs.wisc.edu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1256145SN/A * POSSIBILITY OF SUCH DAMAGE. 1267054SN/A */ 1277054SN/A 1287054SN/A/* 1297054SN/A * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 1306145SN/A * 1317054SN/A * Taken from NetBSD 1328257SBrad.Beckmann@amd.com * 1338257SBrad.Beckmann@amd.com * "Stub" to allow remote cpu to debug over a serial line using gdb. 1348257SBrad.Beckmann@amd.com */ 1358257SBrad.Beckmann@amd.com 1368257SBrad.Beckmann@amd.com#include "arch/mips/remote_gdb.hh" 1378257SBrad.Beckmann@amd.com 13811096Snilay@cs.wisc.edu#include <sys/signal.h> 1398257SBrad.Beckmann@amd.com#include <unistd.h> 1407054SN/A 14111320Ssteve.reinhardt@amd.com#include <string> 1427054SN/A 14311096Snilay@cs.wisc.edu#include "arch/mips/decoder.hh" 14411096Snilay@cs.wisc.edu#include "arch/mips/vtophys.hh" 14511096Snilay@cs.wisc.edu#include "cpu/thread_state.hh" 1467054SN/A#include "debug/GDBAcc.hh" 1477054SN/A#include "debug/GDBMisc.hh" 1487054SN/A#include "mem/page_table.hh" 1497054SN/A#include "sim/full_system.hh" 1509799Snilay@cs.wisc.edu 1519799Snilay@cs.wisc.eduusing namespace std; 1529799Snilay@cs.wisc.eduusing namespace MipsISA; 1537054SN/A 1547054SN/ARemoteGDB::RemoteGDB(System *_system, ThreadContext *tc) 1556895SN/A : BaseRemoteGDB(_system, tc) 1566895SN/A{ 1576895SN/A} 1587054SN/A 15911664Stushar@ece.gatech.edu/* 16011664Stushar@ece.gatech.edu * Determine if the mapping at va..(va+len) is valid. 16111664Stushar@ece.gatech.edu */ 1627054SN/Abool 1637832SN/ARemoteGDB::acc(Addr va, size_t len) 1647832SN/A{ 16511320Ssteve.reinhardt@amd.com TlbEntry entry; 1668257SBrad.Beckmann@amd.com //Check to make sure the first byte is mapped into the processes address 1678257SBrad.Beckmann@amd.com //space. 1688257SBrad.Beckmann@amd.com if (FullSystem) 1698257SBrad.Beckmann@amd.com panic("acc not implemented for MIPS FS!"); 1708257SBrad.Beckmann@amd.com else 1718257SBrad.Beckmann@amd.com return context->getProcessPtr()->pTable->lookup(va, entry); 17211664Stushar@ece.gatech.edu} 17311664Stushar@ece.gatech.edu 1748257SBrad.Beckmann@amd.comvoid 1757054SN/ARemoteGDB::MipsGdbRegCache::getRegs(ThreadContext *context) 1767054SN/A{ 1777054SN/A DPRINTF(GDBAcc, "getregs in remotegdb \n"); 1787054SN/A 1799799Snilay@cs.wisc.edu for (int i = 0; i < 32; i++) r.gpr[i] = context->readIntReg(i); 1807054SN/A r.sr = context->readMiscRegNoEffect(MISCREG_STATUS); 1817054SN/A r.lo = context->readIntReg(INTREG_LO); 1827054SN/A r.hi = context->readIntReg(INTREG_HI); 1837054SN/A r.badvaddr = context->readMiscRegNoEffect(MISCREG_BADVADDR); 1847054SN/A r.cause = context->readMiscRegNoEffect(MISCREG_CAUSE); 1858257SBrad.Beckmann@amd.com r.pc = context->pcState().pc(); 18611320Ssteve.reinhardt@amd.com for (int i = 0; i < 32; i++) r.fpr[i] = context->readFloatRegBits(i); 1878257SBrad.Beckmann@amd.com r.fsr = context->readFloatRegBits(FLOATREG_FCCR); 1887054SN/A r.fir = context->readFloatRegBits(FLOATREG_FIR); 1898257SBrad.Beckmann@amd.com} 1908257SBrad.Beckmann@amd.com 1918257SBrad.Beckmann@amd.comvoid 19211663Stushar@ece.gatech.eduRemoteGDB::MipsGdbRegCache::setRegs(ThreadContext *context) const 19311663Stushar@ece.gatech.edu{ 1947054SN/A DPRINTF(GDBAcc, "setregs in remotegdb \n"); 1957054SN/A 1968257SBrad.Beckmann@amd.com for (int i = 1; i < 32; i++) context->setIntReg(i, r.gpr[i]); 1978257SBrad.Beckmann@amd.com context->setMiscRegNoEffect(MISCREG_STATUS, r.sr); 1988257SBrad.Beckmann@amd.com context->setIntReg(INTREG_LO, r.lo); 1998257SBrad.Beckmann@amd.com context->setIntReg(INTREG_HI, r.hi); 20011663Stushar@ece.gatech.edu context->setMiscRegNoEffect(MISCREG_BADVADDR, r.badvaddr); 20111663Stushar@ece.gatech.edu context->setMiscRegNoEffect(MISCREG_CAUSE, r.cause); 2027054SN/A context->pcState(r.pc); 2038257SBrad.Beckmann@amd.com for (int i = 0; i < 32; i++) context->setFloatRegBits(i, r.fpr[i]); 2048257SBrad.Beckmann@amd.com context->setFloatRegBits(FLOATREG_FCCR, r.fsr); 2058257SBrad.Beckmann@amd.com context->setFloatRegBits(FLOATREG_FIR, r.fir); 2068257SBrad.Beckmann@amd.com} 2078257SBrad.Beckmann@amd.com 20811663Stushar@ece.gatech.eduRemoteGDB::BaseGdbRegCache* 20911664Stushar@ece.gatech.eduRemoteGDB::gdbRegs() { 21011664Stushar@ece.gatech.edu return new MipsGdbRegCache(this); 21111664Stushar@ece.gatech.edu} 2127054SN/A