remote_gdb.cc revision 14186:146c010fa764
16019Shines@cs.fsu.edu/* 212528Schuan.zhu@arm.com * Copyright 2015 LabWare 37093Sgblack@eecs.umich.edu * Copyright 2014 Google, Inc. 47093Sgblack@eecs.umich.edu * Copyright (c) 2010 ARM Limited 57093Sgblack@eecs.umich.edu * All rights reserved 67093Sgblack@eecs.umich.edu * 77093Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall 87093Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual 97093Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating 107093Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software 117093Sgblack@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 127093Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 137093Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 146019Shines@cs.fsu.edu * modified or unmodified, in source code or in binary form. 156019Shines@cs.fsu.edu * 166019Shines@cs.fsu.edu * Copyright (c) 2017 The University of Virginia 176019Shines@cs.fsu.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 186019Shines@cs.fsu.edu * All rights reserved. 196019Shines@cs.fsu.edu * 206019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without 216019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are 226019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright 236019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer; 246019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright 256019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the 266019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution; 276019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its 286019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from 296019Shines@cs.fsu.edu * this software without specific prior written permission. 306019Shines@cs.fsu.edu * 316019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 326019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 336019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 346019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 356019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 366019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 376019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 386019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 396019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 407399SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 417399SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 426019Shines@cs.fsu.edu * 436019Shines@cs.fsu.edu * Authors: Nathan Binkert 446019Shines@cs.fsu.edu * William Wang 4510873Sandreas.sandberg@arm.com * Deyuan Guo 4610873Sandreas.sandberg@arm.com * Boris Shingarov 4710474Sandreas.hansson@arm.com * Alec Roelke 486019Shines@cs.fsu.edu */ 496019Shines@cs.fsu.edu 506019Shines@cs.fsu.edu/* 516116Snate@binkert.org * Copyright (c) 1990, 1993 The Regents of the University of California 526019Shines@cs.fsu.edu * All rights reserved 5311793Sbrandon.potter@amd.com * 5411793Sbrandon.potter@amd.com * This software was developed by the Computer Systems Engineering group 558782Sgblack@eecs.umich.edu * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 568756Sgblack@eecs.umich.edu * contributed to Berkeley. 576019Shines@cs.fsu.edu * 5812005Sandreas.sandberg@arm.com * All advertising materials mentioning features or use of this software 596019Shines@cs.fsu.edu * must display the following acknowledgement: 606019Shines@cs.fsu.edu * This product includes software developed by the University of 616019Shines@cs.fsu.edu * California, Lawrence Berkeley Laboratories. 6210024Sdam.sunwoo@arm.com * 636019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without 648232Snate@binkert.org * modification, are permitted provided that the following conditions 658232Snate@binkert.org * are met: 668232Snate@binkert.org * 1. Redistributions of source code must retain the above copyright 676116Snate@binkert.org * notice, this list of conditions and the following disclaimer. 6811608Snikos.nikoleris@arm.com * 2. Redistributions in binary form must reproduce the above copyright 696116Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 708756Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution. 716019Shines@cs.fsu.edu * 3. All advertising materials mentioning features or use of this software 726019Shines@cs.fsu.edu * must display the following acknowledgement: 736019Shines@cs.fsu.edu * This product includes software developed by the University of 746019Shines@cs.fsu.edu * California, Berkeley and its contributors. 756019Shines@cs.fsu.edu * 4. Neither the name of the University nor the names of its contributors 7610037SARM gem5 Developers * may be used to endorse or promote products derived from this software 7710037SARM gem5 Developers * without specific prior written permission. 7813374Sanouk.vanlaer@arm.com * 7910418Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 8011395Sandreas.sandberg@arm.com * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 8110537Sandreas.hansson@arm.com * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 8213453Srekai.gonzalezalberquilla@arm.com * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 8311152Smitch.hayenga@arm.com * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 846019Shines@cs.fsu.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 8512005Sandreas.sandberg@arm.com * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 8612005Sandreas.sandberg@arm.com * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 8710037SARM gem5 Developers * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 887399SAli.Saidi@ARM.com * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 8910037SARM gem5 Developers * SUCH DAMAGE. 9010037SARM gem5 Developers * 9110037SARM gem5 Developers * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 9210037SARM gem5 Developers */ 9312005Sandreas.sandberg@arm.com 9412005Sandreas.sandberg@arm.com/*- 9512005Sandreas.sandberg@arm.com * Copyright (c) 2001 The NetBSD Foundation, Inc. 966019Shines@cs.fsu.edu * All rights reserved. 976019Shines@cs.fsu.edu * 986019Shines@cs.fsu.edu * This code is derived from software contributed to The NetBSD Foundation 996019Shines@cs.fsu.edu * by Jason R. Thorpe. 10010037SARM gem5 Developers * 10110037SARM gem5 Developers * Redistribution and use in source and binary forms, with or without 10210037SARM gem5 Developers * modification, are permitted provided that the following conditions 10310037SARM gem5 Developers * are met: 10410037SARM gem5 Developers * 1. Redistributions of source code must retain the above copyright 10510037SARM gem5 Developers * notice, this list of conditions and the following disclaimer. 10610037SARM gem5 Developers * 2. Redistributions in binary form must reproduce the above copyright 10710037SARM gem5 Developers * notice, this list of conditions and the following disclaimer in the 10810037SARM gem5 Developers * documentation and/or other materials provided with the distribution. 10910037SARM gem5 Developers * 3. All advertising materials mentioning features or use of this software 11010037SARM gem5 Developers * must display the following acknowledgement: 11110717Sandreas.hansson@arm.com * This product includes software developed by the NetBSD 11210037SARM gem5 Developers * Foundation, Inc. and its contributors. 11310037SARM gem5 Developers * 4. Neither the name of The NetBSD Foundation nor the names of its 11410717Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived 1156019Shines@cs.fsu.edu * from this software without specific prior written permission. 1166019Shines@cs.fsu.edu * 1177694SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1187694SAli.Saidi@ARM.com * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1197694SAli.Saidi@ARM.com * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 12010037SARM gem5 Developers * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 12110037SARM gem5 Developers * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 12210037SARM gem5 Developers * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 12310037SARM gem5 Developers * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 12410037SARM gem5 Developers * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 12510037SARM gem5 Developers * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 12610037SARM gem5 Developers * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 12710037SARM gem5 Developers * POSSIBILITY OF SUCH DAMAGE. 12810037SARM gem5 Developers */ 1297694SAli.Saidi@ARM.com 1307694SAli.Saidi@ARM.com/* 1317694SAli.Saidi@ARM.com * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 1327694SAli.Saidi@ARM.com * 1337694SAli.Saidi@ARM.com * Taken from NetBSD 1347694SAli.Saidi@ARM.com * 1359738Sandreas@sandberg.pp.se * "Stub" to allow remote cpu to debug over a serial line using gdb. 13612749Sgiacomo.travaglini@arm.com */ 13712749Sgiacomo.travaglini@arm.com 1389738Sandreas@sandberg.pp.se#include "arch/riscv/remote_gdb.hh" 13912005Sandreas.sandberg@arm.com 14012005Sandreas.sandberg@arm.com#include <string> 14112005Sandreas.sandberg@arm.com 14212005Sandreas.sandberg@arm.com#include "arch/riscv/registers.hh" 14312005Sandreas.sandberg@arm.com#include "cpu/thread_state.hh" 14412005Sandreas.sandberg@arm.com#include "debug/GDBAcc.hh" 14512005Sandreas.sandberg@arm.com#include "mem/page_table.hh" 14612005Sandreas.sandberg@arm.com#include "sim/full_system.hh" 14712005Sandreas.sandberg@arm.com 1489738Sandreas@sandberg.pp.seusing namespace std; 1499738Sandreas@sandberg.pp.seusing namespace RiscvISA; 1509738Sandreas@sandberg.pp.se 1517404SAli.Saidi@ARM.comRemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port) 15210037SARM gem5 Developers : BaseRemoteGDB(_system, tc, _port), regCache(this) 15310037SARM gem5 Developers{ 1546019Shines@cs.fsu.edu} 1557404SAli.Saidi@ARM.com 1567404SAli.Saidi@ARM.combool 1577404SAli.Saidi@ARM.comRemoteGDB::acc(Addr va, size_t len) 15810037SARM gem5 Developers{ 1597404SAli.Saidi@ARM.com panic_if(FullSystem, "acc not implemented for RISCV FS!"); 1607404SAli.Saidi@ARM.com return context()->getProcessPtr()->pTable->lookup(va) != nullptr; 16110037SARM gem5 Developers} 16210037SARM gem5 Developers 16310037SARM gem5 Developersvoid 16410037SARM gem5 DevelopersRemoteGDB::RiscvGdbRegCache::getRegs(ThreadContext *context) 16510037SARM gem5 Developers{ 1669535Smrinmoy.ghosh@arm.com DPRINTF(GDBAcc, "getregs in remotegdb, size %lu\n", size()); 1677697SAli.Saidi@ARM.com for (int i = 0; i < NumIntArchRegs; i++) 16811321Ssteve.reinhardt@amd.com r.gpr[i] = context->readIntReg(i); 16910037SARM gem5 Developers r.pc = context->pcState().pc(); 1707697SAli.Saidi@ARM.com} 1717697SAli.Saidi@ARM.com 1727697SAli.Saidi@ARM.comvoid 1737697SAli.Saidi@ARM.comRemoteGDB::RiscvGdbRegCache::setRegs(ThreadContext *context) const 1747697SAli.Saidi@ARM.com{ 1757404SAli.Saidi@ARM.com DPRINTF(GDBAcc, "setregs in remotegdb \n"); 1767404SAli.Saidi@ARM.com for (int i = 0; i < NumIntArchRegs; i++) 17710037SARM gem5 Developers context->setIntReg(i, r.gpr[i]); 1787404SAli.Saidi@ARM.com context->pcState(r.pc); 1797404SAli.Saidi@ARM.com} 18010037SARM gem5 Developers 18110037SARM gem5 DevelopersBaseGdbRegCache* 18210037SARM gem5 DevelopersRemoteGDB::gdbRegs() 18310037SARM gem5 Developers{ 18410037SARM gem5 Developers return ®Cache; 18510037SARM gem5 Developers} 18610037SARM gem5 Developers