remote_gdb.cc revision 12031
12686Sksewell@umich.edu/* 25254Sksewell@umich.edu * Copyright 2015 LabWare 35254Sksewell@umich.edu * Copyright 2014 Google, Inc. 42686Sksewell@umich.edu * Copyright (c) 2010 ARM Limited 55254Sksewell@umich.edu * All rights reserved 65254Sksewell@umich.edu * 75254Sksewell@umich.edu * The license below extends only to copyright in the software and shall 85254Sksewell@umich.edu * not be construed as granting a license to any other intellectual 95254Sksewell@umich.edu * property including but not limited to intellectual property relating 105254Sksewell@umich.edu * to a hardware implementation of the functionality of the software 115254Sksewell@umich.edu * licensed hereunder. You may use the software subject to the license 125254Sksewell@umich.edu * terms below provided that you ensure that this notice is replicated 135254Sksewell@umich.edu * unmodified and in its entirety in all distributions of the software, 145254Sksewell@umich.edu * modified or unmodified, in source code or in binary form. 152686Sksewell@umich.edu * 165254Sksewell@umich.edu * Copyright (c) 2017 The University of Virginia 175254Sksewell@umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 185254Sksewell@umich.edu * All rights reserved. 195254Sksewell@umich.edu * 205254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 215254Sksewell@umich.edu * modification, are permitted provided that the following conditions are 225254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 235254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 245254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 255254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 265254Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 272706Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 285254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 292686Sksewell@umich.edu * this software without specific prior written permission. 302686Sksewell@umich.edu * 314661Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 322686Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 334661Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 344661Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 354661Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 364661Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 374661Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 382980Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 392686Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 405222Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 415222Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 425222Sksewell@umich.edu * 435222Sksewell@umich.edu * Authors: Nathan Binkert 445222Sksewell@umich.edu * William Wang 455222Sksewell@umich.edu * Deyuan Guo 462686Sksewell@umich.edu * Boris Shingarov 474661Sksewell@umich.edu * Alec Roelke 482686Sksewell@umich.edu */ 495222Sksewell@umich.edu 505222Sksewell@umich.edu/* 512686Sksewell@umich.edu * Copyright (c) 1990, 1993 The Regents of the University of California 525222Sksewell@umich.edu * All rights reserved 535222Sksewell@umich.edu * 545222Sksewell@umich.edu * This software was developed by the Computer Systems Engineering group 555222Sksewell@umich.edu * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 565222Sksewell@umich.edu * contributed to Berkeley. 575222Sksewell@umich.edu * 585222Sksewell@umich.edu * All advertising materials mentioning features or use of this software 595222Sksewell@umich.edu * must display the following acknowledgement: 605222Sksewell@umich.edu * This product includes software developed by the University of 615222Sksewell@umich.edu * California, Lawrence Berkeley Laboratories. 625222Sksewell@umich.edu * 635222Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 645222Sksewell@umich.edu * modification, are permitted provided that the following conditions 655222Sksewell@umich.edu * are met: 665222Sksewell@umich.edu * 1. Redistributions of source code must retain the above copyright 675222Sksewell@umich.edu * notice, this list of conditions and the following disclaimer. 685222Sksewell@umich.edu * 2. Redistributions in binary form must reproduce the above copyright 695222Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 705222Sksewell@umich.edu * documentation and/or other materials provided with the distribution. 715222Sksewell@umich.edu * 3. All advertising materials mentioning features or use of this software 725222Sksewell@umich.edu * must display the following acknowledgement: 735222Sksewell@umich.edu * This product includes software developed by the University of 745222Sksewell@umich.edu * California, Berkeley and its contributors. 755222Sksewell@umich.edu * 4. Neither the name of the University nor the names of its contributors 762686Sksewell@umich.edu * may be used to endorse or promote products derived from this software 772686Sksewell@umich.edu * without specific prior written permission. 782686Sksewell@umich.edu * 792686Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 802686Sksewell@umich.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 812686Sksewell@umich.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 822686Sksewell@umich.edu * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 832686Sksewell@umich.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 842686Sksewell@umich.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 852686Sksewell@umich.edu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 862686Sksewell@umich.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 872686Sksewell@umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 882686Sksewell@umich.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 892686Sksewell@umich.edu * SUCH DAMAGE. 902686Sksewell@umich.edu * 912686Sksewell@umich.edu * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 922686Sksewell@umich.edu */ 932686Sksewell@umich.edu 942686Sksewell@umich.edu/*- 952686Sksewell@umich.edu * Copyright (c) 2001 The NetBSD Foundation, Inc. 962686Sksewell@umich.edu * All rights reserved. 972686Sksewell@umich.edu * 982686Sksewell@umich.edu * This code is derived from software contributed to The NetBSD Foundation 992686Sksewell@umich.edu * by Jason R. Thorpe. 1002686Sksewell@umich.edu * 1012686Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 1022686Sksewell@umich.edu * modification, are permitted provided that the following conditions 1032686Sksewell@umich.edu * are met: 1042686Sksewell@umich.edu * 1. Redistributions of source code must retain the above copyright 1052686Sksewell@umich.edu * notice, this list of conditions and the following disclaimer. 1062686Sksewell@umich.edu * 2. Redistributions in binary form must reproduce the above copyright 1072686Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 1082686Sksewell@umich.edu * documentation and/or other materials provided with the distribution. 1092686Sksewell@umich.edu * 3. All advertising materials mentioning features or use of this software 1102686Sksewell@umich.edu * must display the following acknowledgement: 1112686Sksewell@umich.edu * This product includes software developed by the NetBSD 1122686Sksewell@umich.edu * Foundation, Inc. and its contributors. 1132686Sksewell@umich.edu * 4. Neither the name of The NetBSD Foundation nor the names of its 1142686Sksewell@umich.edu * contributors may be used to endorse or promote products derived 1152686Sksewell@umich.edu * from this software without specific prior written permission. 1162686Sksewell@umich.edu * 1172686Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1182686Sksewell@umich.edu * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1195222Sksewell@umich.edu * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1202686Sksewell@umich.edu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1212686Sksewell@umich.edu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1222686Sksewell@umich.edu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1232686Sksewell@umich.edu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1242686Sksewell@umich.edu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1252686Sksewell@umich.edu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1262686Sksewell@umich.edu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1272686Sksewell@umich.edu * POSSIBILITY OF SUCH DAMAGE. 1282686Sksewell@umich.edu */ 1292686Sksewell@umich.edu 1305222Sksewell@umich.edu/* 1312686Sksewell@umich.edu * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 1322686Sksewell@umich.edu * 1332686Sksewell@umich.edu * Taken from NetBSD 1342686Sksewell@umich.edu * 1352686Sksewell@umich.edu * "Stub" to allow remote cpu to debug over a serial line using gdb. 1362686Sksewell@umich.edu */ 1375222Sksewell@umich.edu 1382686Sksewell@umich.edu#include "arch/riscv/remote_gdb.hh" 1392686Sksewell@umich.edu 1402686Sksewell@umich.edu#include <string> 1412686Sksewell@umich.edu 1422686Sksewell@umich.edu#include "arch/riscv/registers.hh" 1432686Sksewell@umich.edu#include "cpu/thread_state.hh" 1442686Sksewell@umich.edu#include "debug/GDBAcc.hh" 1455222Sksewell@umich.edu#include "mem/page_table.hh" 1462686Sksewell@umich.edu#include "sim/full_system.hh" 1472686Sksewell@umich.edu 1482686Sksewell@umich.eduusing namespace std; 1492686Sksewell@umich.eduusing namespace RiscvISA; 1502686Sksewell@umich.edu 1512686Sksewell@umich.eduRemoteGDB::RemoteGDB(System *_system, ThreadContext *tc) 1522686Sksewell@umich.edu : BaseRemoteGDB(_system, tc), regCache(this) 1532686Sksewell@umich.edu{ 1542686Sksewell@umich.edu} 1552686Sksewell@umich.edu 1562686Sksewell@umich.edubool 1575222Sksewell@umich.eduRemoteGDB::acc(Addr va, size_t len) 1582686Sksewell@umich.edu{ 1592686Sksewell@umich.edu TlbEntry entry; 1602686Sksewell@umich.edu if (FullSystem) 1612686Sksewell@umich.edu panic("acc not implemented for RISCV FS!"); 1622686Sksewell@umich.edu else 1632686Sksewell@umich.edu return context->getProcessPtr()->pTable->lookup(va, entry); 1642686Sksewell@umich.edu} 1652686Sksewell@umich.edu 1662686Sksewell@umich.eduvoid 1672686Sksewell@umich.eduRemoteGDB::RiscvGdbRegCache::getRegs(ThreadContext *context) 1682686Sksewell@umich.edu{ 1692686Sksewell@umich.edu DPRINTF(GDBAcc, "getregs in remotegdb, size %lu\n", size()); 1702686Sksewell@umich.edu for (int i = 0; i < NumIntArchRegs; i++) 1715222Sksewell@umich.edu r.gpr[i] = context->readIntReg(i); 1722686Sksewell@umich.edu r.pc = context->pcState().pc(); 1732686Sksewell@umich.edu for (int i = 0; i < NumFloatRegs; i++) 1742686Sksewell@umich.edu r.fpr[i] = context->readFloatRegBits(i); 1752686Sksewell@umich.edu 1762686Sksewell@umich.edu r.csr_base = context->readMiscReg(0); 1772686Sksewell@umich.edu r.fflags = context->readMiscReg(MISCREG_FFLAGS); 1782686Sksewell@umich.edu r.frm = context->readMiscReg(MISCREG_FRM); 1792686Sksewell@umich.edu r.fcsr = context->readMiscReg(MISCREG_FCSR); 1802686Sksewell@umich.edu for (int i = ExplicitCSRs; i < NumMiscRegs; i++) 1812686Sksewell@umich.edu r.csr[i - ExplicitCSRs] = context->readMiscReg(i); 1822686Sksewell@umich.edu} 1832686Sksewell@umich.edu 1842686Sksewell@umich.eduvoid 1852686Sksewell@umich.eduRemoteGDB::RiscvGdbRegCache::setRegs(ThreadContext *context) const 1862686Sksewell@umich.edu{ 1872686Sksewell@umich.edu DPRINTF(GDBAcc, "setregs in remotegdb \n"); 1882686Sksewell@umich.edu for (int i = 0; i < NumIntArchRegs; i++) 1892686Sksewell@umich.edu context->setIntReg(i, r.gpr[i]); 1902686Sksewell@umich.edu context->pcState(r.pc); 1912686Sksewell@umich.edu for (int i = 0; i < NumFloatRegs; i++) 1922686Sksewell@umich.edu context->setFloatRegBits(i, r.fpr[i]); 1932686Sksewell@umich.edu 1945222Sksewell@umich.edu context->setMiscReg(0, r.csr_base); 1952686Sksewell@umich.edu context->setMiscReg(MISCREG_FFLAGS, r.fflags); 1962686Sksewell@umich.edu context->setMiscReg(MISCREG_FRM, r.frm); 1972686Sksewell@umich.edu context->setMiscReg(MISCREG_FCSR, r.fcsr); 1982686Sksewell@umich.edu for (int i = ExplicitCSRs; i < NumMiscRegs; i++) 1992686Sksewell@umich.edu context->setMiscReg(i, r.csr[i - ExplicitCSRs]); 2002686Sksewell@umich.edu} 2012686Sksewell@umich.edu 2022686Sksewell@umich.eduRemoteGDB::BaseGdbRegCache* 2032686Sksewell@umich.eduRemoteGDB::gdbRegs() { 2042686Sksewell@umich.edu return ®Cache; 2052686Sksewell@umich.edu} 2062686Sksewell@umich.edu