remote_gdb.cc revision 12455
12SN/A/* 21762SN/A * Copyright 2015 LabWare 32SN/A * Copyright 2014 Google, Inc. 42SN/A * Copyright (c) 2010 ARM Limited 52SN/A * All rights reserved 62SN/A * 72SN/A * The license below extends only to copyright in the software and shall 82SN/A * not be construed as granting a license to any other intellectual 92SN/A * property including but not limited to intellectual property relating 102SN/A * to a hardware implementation of the functionality of the software 112SN/A * licensed hereunder. You may use the software subject to the license 122SN/A * terms below provided that you ensure that this notice is replicated 132SN/A * unmodified and in its entirety in all distributions of the software, 142SN/A * modified or unmodified, in source code or in binary form. 152SN/A * 162SN/A * Copyright (c) 2017 The University of Virginia 172SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 182SN/A * All rights reserved. 192SN/A * 202SN/A * Redistribution and use in source and binary forms, with or without 212SN/A * modification, are permitted provided that the following conditions are 222SN/A * met: redistributions of source code must retain the above copyright 232SN/A * notice, this list of conditions and the following disclaimer; 242SN/A * redistributions in binary form must reproduce the above copyright 252SN/A * notice, this list of conditions and the following disclaimer in the 262SN/A * documentation and/or other materials provided with the distribution; 272665Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its 282665Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 292665Ssaidi@eecs.umich.edu * this software without specific prior written permission. 302SN/A * 312SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 322SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 332SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 342SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 352147SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 367678Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 378229Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 388229Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 397878Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 402147SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 412147SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 422680Sktlim@umich.edu * 432132SN/A * Authors: Nathan Binkert 442147SN/A * William Wang 455999Snate@binkert.org * Deyuan Guo 462147SN/A * Boris Shingarov 472147SN/A * Alec Roelke 482147SN/A */ 492147SN/A 502147SN/A/* 512147SN/A * Copyright (c) 1990, 1993 The Regents of the University of California 522147SN/A * All rights reserved 532147SN/A * 542147SN/A * This software was developed by the Computer Systems Engineering group 552090SN/A * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 562147SN/A * contributed to Berkeley. 574695Sgblack@eecs.umich.edu * 587678Sgblack@eecs.umich.edu * All advertising materials mentioning features or use of this software 597678Sgblack@eecs.umich.edu * must display the following acknowledgement: 604695Sgblack@eecs.umich.edu * This product includes software developed by the University of 614695Sgblack@eecs.umich.edu * California, Lawrence Berkeley Laboratories. 622SN/A * 632SN/A * Redistribution and use in source and binary forms, with or without 642612SN/A * modification, are permitted provided that the following conditions 652612SN/A * are met: 662612SN/A * 1. Redistributions of source code must retain the above copyright 672612SN/A * notice, this list of conditions and the following disclaimer. 682612SN/A * 2. Redistributions in binary form must reproduce the above copyright 692612SN/A * notice, this list of conditions and the following disclaimer in the 702612SN/A * documentation and/or other materials provided with the distribution. 712612SN/A * 3. All advertising materials mentioning features or use of this software 722612SN/A * must display the following acknowledgement: 734695Sgblack@eecs.umich.edu * This product includes software developed by the University of 747678Sgblack@eecs.umich.edu * California, Berkeley and its contributors. 757678Sgblack@eecs.umich.edu * 4. Neither the name of the University nor the names of its contributors 762612SN/A * may be used to endorse or promote products derived from this software 772612SN/A * without specific prior written permission. 784183Sgblack@eecs.umich.edu * 795004Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 804183Sgblack@eecs.umich.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 814183Sgblack@eecs.umich.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 824183Sgblack@eecs.umich.edu * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 834183Sgblack@eecs.umich.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 845004Sgblack@eecs.umich.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 855004Sgblack@eecs.umich.edu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 867678Sgblack@eecs.umich.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 877678Sgblack@eecs.umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 885004Sgblack@eecs.umich.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 895004Sgblack@eecs.umich.edu * SUCH DAMAGE. 905004Sgblack@eecs.umich.edu * 915004Sgblack@eecs.umich.edu * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 925004Sgblack@eecs.umich.edu */ 935004Sgblack@eecs.umich.edu 945004Sgblack@eecs.umich.edu/*- 955004Sgblack@eecs.umich.edu * Copyright (c) 2001 The NetBSD Foundation, Inc. 965004Sgblack@eecs.umich.edu * All rights reserved. 977678Sgblack@eecs.umich.edu * 987678Sgblack@eecs.umich.edu * This code is derived from software contributed to The NetBSD Foundation 994183Sgblack@eecs.umich.edu * by Jason R. Thorpe. 1004183Sgblack@eecs.umich.edu * 1014183Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 1022SN/A * modification, are permitted provided that the following conditions 103 * are met: 104 * 1. Redistributions of source code must retain the above copyright 105 * notice, this list of conditions and the following disclaimer. 106 * 2. Redistributions in binary form must reproduce the above copyright 107 * notice, this list of conditions and the following disclaimer in the 108 * documentation and/or other materials provided with the distribution. 109 * 3. All advertising materials mentioning features or use of this software 110 * must display the following acknowledgement: 111 * This product includes software developed by the NetBSD 112 * Foundation, Inc. and its contributors. 113 * 4. Neither the name of The NetBSD Foundation nor the names of its 114 * contributors may be used to endorse or promote products derived 115 * from this software without specific prior written permission. 116 * 117 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 118 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 119 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 120 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 121 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 122 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 123 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 124 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 125 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 126 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 127 * POSSIBILITY OF SUCH DAMAGE. 128 */ 129 130/* 131 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 132 * 133 * Taken from NetBSD 134 * 135 * "Stub" to allow remote cpu to debug over a serial line using gdb. 136 */ 137 138#include "arch/riscv/remote_gdb.hh" 139 140#include <string> 141 142#include "arch/riscv/registers.hh" 143#include "cpu/thread_state.hh" 144#include "debug/GDBAcc.hh" 145#include "mem/page_table.hh" 146#include "sim/full_system.hh" 147 148using namespace std; 149using namespace RiscvISA; 150 151RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port) 152 : BaseRemoteGDB(_system, tc, _port), regCache(this) 153{ 154} 155 156bool 157RemoteGDB::acc(Addr va, size_t len) 158{ 159 panic_if(FullSystem, "acc not implemented for RISCV FS!"); 160 return context()->getProcessPtr()->pTable->lookup(va) != nullptr; 161} 162 163void 164RemoteGDB::RiscvGdbRegCache::getRegs(ThreadContext *context) 165{ 166 DPRINTF(GDBAcc, "getregs in remotegdb, size %lu\n", size()); 167 for (int i = 0; i < NumIntArchRegs; i++) 168 r.gpr[i] = context->readIntReg(i); 169 r.pc = context->pcState().pc(); 170 for (int i = 0; i < NumFloatRegs; i++) 171 r.fpr[i] = context->readFloatRegBits(i); 172 173 r.csr_base = context->readMiscReg(0); 174 r.fflags = context->readMiscReg(MISCREG_FFLAGS); 175 r.frm = context->readMiscReg(MISCREG_FRM); 176 r.fcsr = context->readMiscReg(MISCREG_FCSR); 177 for (int i = ExplicitCSRs; i < NumMiscRegs; i++) 178 r.csr[i - ExplicitCSRs] = context->readMiscReg(i); 179} 180 181void 182RemoteGDB::RiscvGdbRegCache::setRegs(ThreadContext *context) const 183{ 184 DPRINTF(GDBAcc, "setregs in remotegdb \n"); 185 for (int i = 0; i < NumIntArchRegs; i++) 186 context->setIntReg(i, r.gpr[i]); 187 context->pcState(r.pc); 188 for (int i = 0; i < NumFloatRegs; i++) 189 context->setFloatRegBits(i, r.fpr[i]); 190 191 context->setMiscReg(0, r.csr_base); 192 context->setMiscReg(MISCREG_FFLAGS, r.fflags); 193 context->setMiscReg(MISCREG_FRM, r.frm); 194 context->setMiscReg(MISCREG_FCSR, r.fcsr); 195 for (int i = ExplicitCSRs; i < NumMiscRegs; i++) 196 context->setMiscReg(i, r.csr[i - ExplicitCSRs]); 197} 198 199BaseGdbRegCache* 200RemoteGDB::gdbRegs() 201{ 202 return ®Cache; 203} 204