111176Sshingarov@labware.com/* 211274Sshingarov@labware.com * Copyright 2015 LabWare 311176Sshingarov@labware.com * Copyright 2014 Google, Inc. 411176Sshingarov@labware.com * Copyright (c) 2010 ARM Limited 511176Sshingarov@labware.com * All rights reserved 611176Sshingarov@labware.com * 711176Sshingarov@labware.com * The license below extends only to copyright in the software and shall 811176Sshingarov@labware.com * not be construed as granting a license to any other intellectual 911176Sshingarov@labware.com * property including but not limited to intellectual property relating 1011176Sshingarov@labware.com * to a hardware implementation of the functionality of the software 1111176Sshingarov@labware.com * licensed hereunder. You may use the software subject to the license 1211176Sshingarov@labware.com * terms below provided that you ensure that this notice is replicated 1311176Sshingarov@labware.com * unmodified and in its entirety in all distributions of the software, 1411176Sshingarov@labware.com * modified or unmodified, in source code or in binary form. 1511176Sshingarov@labware.com * 1611176Sshingarov@labware.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 1711176Sshingarov@labware.com * All rights reserved. 1811176Sshingarov@labware.com * 1911176Sshingarov@labware.com * Redistribution and use in source and binary forms, with or without 2011176Sshingarov@labware.com * modification, are permitted provided that the following conditions are 2111176Sshingarov@labware.com * met: redistributions of source code must retain the above copyright 2211176Sshingarov@labware.com * notice, this list of conditions and the following disclaimer; 2311176Sshingarov@labware.com * redistributions in binary form must reproduce the above copyright 2411176Sshingarov@labware.com * notice, this list of conditions and the following disclaimer in the 2511176Sshingarov@labware.com * documentation and/or other materials provided with the distribution; 2611176Sshingarov@labware.com * neither the name of the copyright holders nor the names of its 2711176Sshingarov@labware.com * contributors may be used to endorse or promote products derived from 2811176Sshingarov@labware.com * this software without specific prior written permission. 2911176Sshingarov@labware.com * 3011176Sshingarov@labware.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3111176Sshingarov@labware.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3211176Sshingarov@labware.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3311176Sshingarov@labware.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3411176Sshingarov@labware.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3511176Sshingarov@labware.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3611176Sshingarov@labware.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3711176Sshingarov@labware.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3811176Sshingarov@labware.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3911176Sshingarov@labware.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4011176Sshingarov@labware.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4111176Sshingarov@labware.com * 4211176Sshingarov@labware.com * Authors: Nathan Binkert 4311176Sshingarov@labware.com * William Wang 4411176Sshingarov@labware.com * Deyuan Guo 4511176Sshingarov@labware.com * Boris Shingarov 4611176Sshingarov@labware.com */ 4711176Sshingarov@labware.com 4811176Sshingarov@labware.com/* 4911176Sshingarov@labware.com * Copyright (c) 1990, 1993 The Regents of the University of California 5011176Sshingarov@labware.com * All rights reserved 5111176Sshingarov@labware.com * 5211176Sshingarov@labware.com * This software was developed by the Computer Systems Engineering group 5311176Sshingarov@labware.com * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 5411176Sshingarov@labware.com * contributed to Berkeley. 5511176Sshingarov@labware.com * 5611176Sshingarov@labware.com * All advertising materials mentioning features or use of this software 5711176Sshingarov@labware.com * must display the following acknowledgement: 5811176Sshingarov@labware.com * This product includes software developed by the University of 5911176Sshingarov@labware.com * California, Lawrence Berkeley Laboratories. 6011176Sshingarov@labware.com * 6111176Sshingarov@labware.com * Redistribution and use in source and binary forms, with or without 6211176Sshingarov@labware.com * modification, are permitted provided that the following conditions 6311176Sshingarov@labware.com * are met: 6411176Sshingarov@labware.com * 1. Redistributions of source code must retain the above copyright 6511176Sshingarov@labware.com * notice, this list of conditions and the following disclaimer. 6611176Sshingarov@labware.com * 2. Redistributions in binary form must reproduce the above copyright 6711176Sshingarov@labware.com * notice, this list of conditions and the following disclaimer in the 6811176Sshingarov@labware.com * documentation and/or other materials provided with the distribution. 6911176Sshingarov@labware.com * 3. All advertising materials mentioning features or use of this software 7011176Sshingarov@labware.com * must display the following acknowledgement: 7111176Sshingarov@labware.com * This product includes software developed by the University of 7211176Sshingarov@labware.com * California, Berkeley and its contributors. 7311176Sshingarov@labware.com * 4. Neither the name of the University nor the names of its contributors 7411176Sshingarov@labware.com * may be used to endorse or promote products derived from this software 7511176Sshingarov@labware.com * without specific prior written permission. 7611176Sshingarov@labware.com * 7711176Sshingarov@labware.com * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 7811176Sshingarov@labware.com * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 7911176Sshingarov@labware.com * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 8011176Sshingarov@labware.com * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 8111176Sshingarov@labware.com * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 8211176Sshingarov@labware.com * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 8311176Sshingarov@labware.com * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 8411176Sshingarov@labware.com * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 8511176Sshingarov@labware.com * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 8611176Sshingarov@labware.com * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 8711176Sshingarov@labware.com * SUCH DAMAGE. 8811176Sshingarov@labware.com * 8911176Sshingarov@labware.com * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 9011176Sshingarov@labware.com */ 9111176Sshingarov@labware.com 9211176Sshingarov@labware.com/*- 9311176Sshingarov@labware.com * Copyright (c) 2001 The NetBSD Foundation, Inc. 9411176Sshingarov@labware.com * All rights reserved. 9511176Sshingarov@labware.com * 9611176Sshingarov@labware.com * This code is derived from software contributed to The NetBSD Foundation 9711176Sshingarov@labware.com * by Jason R. Thorpe. 9811176Sshingarov@labware.com * 9911176Sshingarov@labware.com * Redistribution and use in source and binary forms, with or without 10011176Sshingarov@labware.com * modification, are permitted provided that the following conditions 10111176Sshingarov@labware.com * are met: 10211176Sshingarov@labware.com * 1. Redistributions of source code must retain the above copyright 10311176Sshingarov@labware.com * notice, this list of conditions and the following disclaimer. 10411176Sshingarov@labware.com * 2. Redistributions in binary form must reproduce the above copyright 10511176Sshingarov@labware.com * notice, this list of conditions and the following disclaimer in the 10611176Sshingarov@labware.com * documentation and/or other materials provided with the distribution. 10711176Sshingarov@labware.com * 3. All advertising materials mentioning features or use of this software 10811176Sshingarov@labware.com * must display the following acknowledgement: 10911176Sshingarov@labware.com * This product includes software developed by the NetBSD 11011176Sshingarov@labware.com * Foundation, Inc. and its contributors. 11111176Sshingarov@labware.com * 4. Neither the name of The NetBSD Foundation nor the names of its 11211176Sshingarov@labware.com * contributors may be used to endorse or promote products derived 11311176Sshingarov@labware.com * from this software without specific prior written permission. 11411176Sshingarov@labware.com * 11511176Sshingarov@labware.com * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 11611176Sshingarov@labware.com * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 11711176Sshingarov@labware.com * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 11811176Sshingarov@labware.com * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 11911176Sshingarov@labware.com * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 12011176Sshingarov@labware.com * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 12111176Sshingarov@labware.com * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 12211176Sshingarov@labware.com * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 12311176Sshingarov@labware.com * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 12411176Sshingarov@labware.com * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 12511176Sshingarov@labware.com * POSSIBILITY OF SUCH DAMAGE. 12611176Sshingarov@labware.com */ 12711176Sshingarov@labware.com 12811176Sshingarov@labware.com/* 12911176Sshingarov@labware.com * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 13011176Sshingarov@labware.com * 13111176Sshingarov@labware.com * Taken from NetBSD 13211176Sshingarov@labware.com * 13311176Sshingarov@labware.com * "Stub" to allow remote cpu to debug over a serial line using gdb. 13411176Sshingarov@labware.com */ 13511176Sshingarov@labware.com 13611800Sbrandon.potter@amd.com 13711176Sshingarov@labware.com#include "arch/power/remote_gdb.hh" 13811176Sshingarov@labware.com 13911176Sshingarov@labware.com#include <sys/signal.h> 14011176Sshingarov@labware.com#include <unistd.h> 14111176Sshingarov@labware.com 14211176Sshingarov@labware.com#include <string> 14311176Sshingarov@labware.com 14411176Sshingarov@labware.com#include "arch/power/vtophys.hh" 14511176Sshingarov@labware.com#include "cpu/thread_state.hh" 14611176Sshingarov@labware.com#include "debug/GDBAcc.hh" 14711176Sshingarov@labware.com#include "debug/GDBMisc.hh" 14811800Sbrandon.potter@amd.com#include "mem/page_table.hh" 14911176Sshingarov@labware.com#include "sim/byteswap.hh" 15011176Sshingarov@labware.com 15111176Sshingarov@labware.comusing namespace std; 15211176Sshingarov@labware.comusing namespace PowerISA; 15311176Sshingarov@labware.com 15412449Sgabeblack@google.comRemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port) 15512449Sgabeblack@google.com : BaseRemoteGDB(_system, tc, _port), regCache(this) 15611176Sshingarov@labware.com{ 15711176Sshingarov@labware.com} 15811176Sshingarov@labware.com 15911176Sshingarov@labware.com/* 16011176Sshingarov@labware.com * Determine if the mapping at va..(va+len) is valid. 16111176Sshingarov@labware.com */ 16211176Sshingarov@labware.combool 16311176Sshingarov@labware.comRemoteGDB::acc(Addr va, size_t len) 16411176Sshingarov@labware.com{ 16512455Sgabeblack@google.com // Check to make sure the first byte is mapped into the processes address 16612455Sgabeblack@google.com // space. At the time of this writing, the acc() check is used when 16712455Sgabeblack@google.com // processing the MemR/MemW packets before actually asking the translating 16812455Sgabeblack@google.com // port proxy to read/writeBlob. I (bgs) am not convinced the first byte 16912455Sgabeblack@google.com // check is enough. 17012455Sgabeblack@google.com panic_if(FullSystem, "acc not implemented for POWER FS!"); 17112455Sgabeblack@google.com return context()->getProcessPtr()->pTable->lookup(va) != nullptr; 17211176Sshingarov@labware.com} 17311176Sshingarov@labware.com 17411176Sshingarov@labware.comvoid 17511274Sshingarov@labware.comRemoteGDB::PowerGdbRegCache::getRegs(ThreadContext *context) 17611176Sshingarov@labware.com{ 17711274Sshingarov@labware.com DPRINTF(GDBAcc, "getRegs in remotegdb \n"); 17811176Sshingarov@labware.com 17911176Sshingarov@labware.com // Default order on 32-bit PowerPC: 18011176Sshingarov@labware.com // R0-R31 (32-bit each), F0-F31 (64-bit IEEE754 double), 18111176Sshingarov@labware.com // PC, MSR, CR, LR, CTR, XER (32-bit each) 18211176Sshingarov@labware.com 18311176Sshingarov@labware.com for (int i = 0; i < NumIntArchRegs; i++) 18411274Sshingarov@labware.com r.gpr[i] = htobe((uint32_t)context->readIntReg(i)); 18511176Sshingarov@labware.com 18611176Sshingarov@labware.com for (int i = 0; i < NumFloatArchRegs; i++) 18713611Sgabeblack@google.com r.fpr[i] = context->readFloatReg(i); 18811176Sshingarov@labware.com 18911274Sshingarov@labware.com r.pc = htobe((uint32_t)context->pcState().pc()); 19011274Sshingarov@labware.com r.msr = 0; // Is MSR modeled? 19111274Sshingarov@labware.com r.cr = htobe((uint32_t)context->readIntReg(INTREG_CR)); 19211274Sshingarov@labware.com r.lr = htobe((uint32_t)context->readIntReg(INTREG_LR)); 19311274Sshingarov@labware.com r.ctr = htobe((uint32_t)context->readIntReg(INTREG_CTR)); 19411274Sshingarov@labware.com r.xer = htobe((uint32_t)context->readIntReg(INTREG_XER)); 19511176Sshingarov@labware.com} 19611176Sshingarov@labware.com 19711176Sshingarov@labware.comvoid 19811274Sshingarov@labware.comRemoteGDB::PowerGdbRegCache::setRegs(ThreadContext *context) const 19911176Sshingarov@labware.com{ 20011274Sshingarov@labware.com DPRINTF(GDBAcc, "setRegs in remotegdb \n"); 20111176Sshingarov@labware.com 20211176Sshingarov@labware.com for (int i = 0; i < NumIntArchRegs; i++) 20311274Sshingarov@labware.com context->setIntReg(i, betoh(r.gpr[i])); 20411176Sshingarov@labware.com 20511176Sshingarov@labware.com for (int i = 0; i < NumFloatArchRegs; i++) 20613611Sgabeblack@google.com context->setFloatReg(i, r.fpr[i]); 20711176Sshingarov@labware.com 20811274Sshingarov@labware.com context->pcState(betoh(r.pc)); 20911176Sshingarov@labware.com // Is MSR modeled? 21011274Sshingarov@labware.com context->setIntReg(INTREG_CR, betoh(r.cr)); 21111274Sshingarov@labware.com context->setIntReg(INTREG_LR, betoh(r.lr)); 21211274Sshingarov@labware.com context->setIntReg(INTREG_CTR, betoh(r.ctr)); 21311274Sshingarov@labware.com context->setIntReg(INTREG_XER, betoh(r.xer)); 21411176Sshingarov@labware.com} 21511274Sshingarov@labware.com 21612449Sgabeblack@google.comBaseGdbRegCache* 21712449Sgabeblack@google.comRemoteGDB::gdbRegs() 21812449Sgabeblack@google.com{ 21912031Sgabeblack@google.com return ®Cache; 22011274Sshingarov@labware.com} 22111274Sshingarov@labware.com 222