13536Sgblack@eecs.umich.edu/* 210595Sgabeblack@google.com * Copyright 2014 Google, Inc. 33536Sgblack@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 43536Sgblack@eecs.umich.edu * All rights reserved. 53536Sgblack@eecs.umich.edu * 63536Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 73536Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 83536Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 93536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 103536Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 113536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 123536Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 133536Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 143536Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 153536Sgblack@eecs.umich.edu * this software without specific prior written permission. 163536Sgblack@eecs.umich.edu * 173536Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 183536Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 193536Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 203536Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 213536Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 223536Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 233536Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 243536Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 253536Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 263536Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 273536Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 283536Sgblack@eecs.umich.edu * 293536Sgblack@eecs.umich.edu * Authors: Nathan Binkert 303536Sgblack@eecs.umich.edu */ 313536Sgblack@eecs.umich.edu 323536Sgblack@eecs.umich.edu/* 338332Snate@binkert.org * Copyright (c) 1990, 1993 The Regents of the University of California 348332Snate@binkert.org * All rights reserved. 353536Sgblack@eecs.umich.edu * 363536Sgblack@eecs.umich.edu * This software was developed by the Computer Systems Engineering group 373536Sgblack@eecs.umich.edu * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 383536Sgblack@eecs.umich.edu * contributed to Berkeley. 393536Sgblack@eecs.umich.edu * 403536Sgblack@eecs.umich.edu * All advertising materials mentioning features or use of this software 413536Sgblack@eecs.umich.edu * must display the following acknowledgement: 425543Ssaidi@eecs.umich.edu * This product includes software developed by the University of 435543Ssaidi@eecs.umich.edu * California, Lawrence Berkeley Laboratories. 443536Sgblack@eecs.umich.edu * 453536Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 463536Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions 473536Sgblack@eecs.umich.edu * are met: 483536Sgblack@eecs.umich.edu * 1. Redistributions of source code must retain the above copyright 493536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer. 503536Sgblack@eecs.umich.edu * 2. Redistributions in binary form must reproduce the above copyright 513536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 523536Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution. 533536Sgblack@eecs.umich.edu * 3. All advertising materials mentioning features or use of this software 543536Sgblack@eecs.umich.edu * must display the following acknowledgement: 555543Ssaidi@eecs.umich.edu * This product includes software developed by the University of 565543Ssaidi@eecs.umich.edu * California, Berkeley and its contributors. 573536Sgblack@eecs.umich.edu * 4. Neither the name of the University nor the names of its contributors 583536Sgblack@eecs.umich.edu * may be used to endorse or promote products derived from this software 593536Sgblack@eecs.umich.edu * without specific prior written permission. 603536Sgblack@eecs.umich.edu * 613536Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 623536Sgblack@eecs.umich.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 633536Sgblack@eecs.umich.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 643536Sgblack@eecs.umich.edu * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 653536Sgblack@eecs.umich.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 663536Sgblack@eecs.umich.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 673536Sgblack@eecs.umich.edu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 683536Sgblack@eecs.umich.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 693536Sgblack@eecs.umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 703536Sgblack@eecs.umich.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 713536Sgblack@eecs.umich.edu * SUCH DAMAGE. 723536Sgblack@eecs.umich.edu * 735543Ssaidi@eecs.umich.edu * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 743536Sgblack@eecs.umich.edu */ 753536Sgblack@eecs.umich.edu 763536Sgblack@eecs.umich.edu/*- 773536Sgblack@eecs.umich.edu * Copyright (c) 2001 The NetBSD Foundation, Inc. 783536Sgblack@eecs.umich.edu * All rights reserved. 793536Sgblack@eecs.umich.edu * 803536Sgblack@eecs.umich.edu * This code is derived from software contributed to The NetBSD Foundation 813536Sgblack@eecs.umich.edu * by Jason R. Thorpe. 823536Sgblack@eecs.umich.edu * 833536Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 843536Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions 853536Sgblack@eecs.umich.edu * are met: 863536Sgblack@eecs.umich.edu * 1. Redistributions of source code must retain the above copyright 873536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer. 883536Sgblack@eecs.umich.edu * 2. Redistributions in binary form must reproduce the above copyright 893536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 903536Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution. 913536Sgblack@eecs.umich.edu * 3. All advertising materials mentioning features or use of this software 923536Sgblack@eecs.umich.edu * must display the following acknowledgement: 935543Ssaidi@eecs.umich.edu * This product includes software developed by the NetBSD 945543Ssaidi@eecs.umich.edu * Foundation, Inc. and its contributors. 953536Sgblack@eecs.umich.edu * 4. Neither the name of The NetBSD Foundation nor the names of its 963536Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived 973536Sgblack@eecs.umich.edu * from this software without specific prior written permission. 983536Sgblack@eecs.umich.edu * 993536Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1003536Sgblack@eecs.umich.edu * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1013536Sgblack@eecs.umich.edu * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1023536Sgblack@eecs.umich.edu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1033536Sgblack@eecs.umich.edu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1043536Sgblack@eecs.umich.edu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1053536Sgblack@eecs.umich.edu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1063536Sgblack@eecs.umich.edu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1073536Sgblack@eecs.umich.edu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1083536Sgblack@eecs.umich.edu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1093536Sgblack@eecs.umich.edu * POSSIBILITY OF SUCH DAMAGE. 1103536Sgblack@eecs.umich.edu */ 1113536Sgblack@eecs.umich.edu 1123536Sgblack@eecs.umich.edu/* 1133536Sgblack@eecs.umich.edu * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 1143536Sgblack@eecs.umich.edu * 1153536Sgblack@eecs.umich.edu * Taken from NetBSD 1163536Sgblack@eecs.umich.edu * 1173536Sgblack@eecs.umich.edu * "Stub" to allow remote cpu to debug over a serial line using gdb. 1183536Sgblack@eecs.umich.edu */ 1193536Sgblack@eecs.umich.edu 12011793Sbrandon.potter@amd.com#include "arch/alpha/remote_gdb.hh" 12111793Sbrandon.potter@amd.com 1223536Sgblack@eecs.umich.edu#include <sys/signal.h> 1235569Snate@binkert.org#include <unistd.h> 1243536Sgblack@eecs.umich.edu 1253536Sgblack@eecs.umich.edu#include <string> 1263536Sgblack@eecs.umich.edu 1279020Sgblack@eecs.umich.edu#include "arch/alpha/decoder.hh" 1286327Sgblack@eecs.umich.edu#include "arch/alpha/regredir.hh" 1298229Snate@binkert.org#include "arch/alpha/utility.hh" 1308780Sgblack@eecs.umich.edu#include "arch/alpha/vtophys.hh" 1313536Sgblack@eecs.umich.edu#include "base/intmath.hh" 1323536Sgblack@eecs.umich.edu#include "base/remote_gdb.hh" 1333536Sgblack@eecs.umich.edu#include "base/socket.hh" 1343536Sgblack@eecs.umich.edu#include "base/trace.hh" 1358229Snate@binkert.org#include "cpu/static_inst.hh" 1363536Sgblack@eecs.umich.edu#include "cpu/thread_context.hh" 1378232Snate@binkert.org#include "debug/GDBAcc.hh" 1388232Snate@binkert.org#include "debug/GDBMisc.hh" 1393536Sgblack@eecs.umich.edu#include "mem/physical.hh" 1403536Sgblack@eecs.umich.edu#include "mem/port.hh" 14111793Sbrandon.potter@amd.com#include "sim/full_system.hh" 1423536Sgblack@eecs.umich.edu#include "sim/system.hh" 1433536Sgblack@eecs.umich.edu 1443536Sgblack@eecs.umich.eduusing namespace std; 1455567Snate@binkert.orgusing namespace AlphaISA; 1463536Sgblack@eecs.umich.edu 14712449Sgabeblack@google.comRemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port) 14812449Sgabeblack@google.com : BaseRemoteGDB(_system, tc, _port) 1493536Sgblack@eecs.umich.edu{ 15012449Sgabeblack@google.com warn_once("Breakpoints do not work in Alpha PAL mode.\n" 15112449Sgabeblack@google.com " See PCEventQueue::doService() in cpu/pc_event.cc.\n"); 1523536Sgblack@eecs.umich.edu} 1533536Sgblack@eecs.umich.edu 1545569Snate@binkert.org/* 1555569Snate@binkert.org * Determine if the mapping at va..(va+len) is valid. 1565569Snate@binkert.org */ 1573536Sgblack@eecs.umich.edubool 1583536Sgblack@eecs.umich.eduRemoteGDB::acc(Addr va, size_t len) 1593536Sgblack@eecs.umich.edu{ 1608806Sgblack@eecs.umich.edu if (!FullSystem) 1618806Sgblack@eecs.umich.edu panic("acc function needs to be rewritten for SE mode\n"); 1623536Sgblack@eecs.umich.edu 1638806Sgblack@eecs.umich.edu Addr last_va; 1643536Sgblack@eecs.umich.edu 1658806Sgblack@eecs.umich.edu va = TruncPage(va); 1668806Sgblack@eecs.umich.edu last_va = RoundPage(va + len); 1678780Sgblack@eecs.umich.edu 1688806Sgblack@eecs.umich.edu do { 1698806Sgblack@eecs.umich.edu if (IsK0Seg(va)) { 17012449Sgabeblack@google.com if (va < (K0SegBase + system()->memSize())) { 1718806Sgblack@eecs.umich.edu DPRINTF(GDBAcc, "acc: Mapping is valid K0SEG <= " 1728806Sgblack@eecs.umich.edu "%#x < K0SEG + size\n", va); 1733536Sgblack@eecs.umich.edu return true; 1748806Sgblack@eecs.umich.edu } else { 1758806Sgblack@eecs.umich.edu DPRINTF(GDBAcc, "acc: Mapping invalid %#x " 1768806Sgblack@eecs.umich.edu "> K0SEG + size\n", va); 1773536Sgblack@eecs.umich.edu return false; 1783536Sgblack@eecs.umich.edu } 1798806Sgblack@eecs.umich.edu } 1803536Sgblack@eecs.umich.edu 1818806Sgblack@eecs.umich.edu /** 1828806Sgblack@eecs.umich.edu * This code says that all accesses to palcode (instruction 1838806Sgblack@eecs.umich.edu * and data) are valid since there isn't a va->pa mapping 1848806Sgblack@eecs.umich.edu * because palcode is accessed physically. At some point this 1858806Sgblack@eecs.umich.edu * should probably be cleaned up but there is no easy way to 1868806Sgblack@eecs.umich.edu * do it. 1878806Sgblack@eecs.umich.edu */ 1888806Sgblack@eecs.umich.edu 1898806Sgblack@eecs.umich.edu if (PcPAL(va) || va < 0x10000) 1908806Sgblack@eecs.umich.edu return true; 1918806Sgblack@eecs.umich.edu 19212449Sgabeblack@google.com Addr ptbr = context()->readMiscRegNoEffect(IPR_PALtemp20); 1938806Sgblack@eecs.umich.edu PageTableEntry pte = 19412449Sgabeblack@google.com kernel_pte_lookup(context()->getPhysProxy(), ptbr, va); 1958806Sgblack@eecs.umich.edu if (!pte.valid()) { 1968806Sgblack@eecs.umich.edu DPRINTF(GDBAcc, "acc: %#x pte is invalid\n", va); 1978806Sgblack@eecs.umich.edu return false; 1988806Sgblack@eecs.umich.edu } 1998806Sgblack@eecs.umich.edu va += PageBytes; 2008806Sgblack@eecs.umich.edu } while (va < last_va); 2018806Sgblack@eecs.umich.edu 2028806Sgblack@eecs.umich.edu DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va); 2038806Sgblack@eecs.umich.edu return true; 2043536Sgblack@eecs.umich.edu} 2053536Sgblack@eecs.umich.edu 2063536Sgblack@eecs.umich.eduvoid 20711274Sshingarov@labware.comRemoteGDB::AlphaGdbRegCache::getRegs(ThreadContext *context) 2083536Sgblack@eecs.umich.edu{ 20911274Sshingarov@labware.com DPRINTF(GDBAcc, "getRegs in remotegdb \n"); 2103536Sgblack@eecs.umich.edu 21111274Sshingarov@labware.com r.pc = context->pcState().pc(); 2123536Sgblack@eecs.umich.edu 21311274Sshingarov@labware.com if (PcPAL(r.pc)) { 21411274Sshingarov@labware.com for (int i = 0; i < 32; ++i) 21511274Sshingarov@labware.com r.gpr[i] = context->readIntReg(reg_redir[i]); 2163536Sgblack@eecs.umich.edu } else { 21711274Sshingarov@labware.com for (int i = 0; i < 32; ++i) 21811274Sshingarov@labware.com r.gpr[i] = context->readIntReg(i); 2193536Sgblack@eecs.umich.edu } 2203536Sgblack@eecs.umich.edu 22111274Sshingarov@labware.com for (int i = 0; i < 32; ++i) 2223536Sgblack@eecs.umich.edu#ifdef KGDB_FP_REGS 22313611Sgabeblack@google.com r.fpr[i] = context->readFloatReg(i); 22411274Sshingarov@labware.com#else 22511274Sshingarov@labware.com r.fpr[i] = 0; 2263536Sgblack@eecs.umich.edu#endif 2273536Sgblack@eecs.umich.edu} 2283536Sgblack@eecs.umich.edu 2293536Sgblack@eecs.umich.eduvoid 23011274Sshingarov@labware.comRemoteGDB::AlphaGdbRegCache::setRegs(ThreadContext *context) const 2313536Sgblack@eecs.umich.edu{ 23211274Sshingarov@labware.com DPRINTF(GDBAcc, "setRegs in remotegdb \n"); 23311274Sshingarov@labware.com 23411274Sshingarov@labware.com if (PcPAL(r.pc)) { 23511274Sshingarov@labware.com for (int i = 0; i < 32; ++i) { 23611274Sshingarov@labware.com context->setIntReg(reg_redir[i], r.gpr[i]); 2373536Sgblack@eecs.umich.edu } 2383536Sgblack@eecs.umich.edu } else { 23911274Sshingarov@labware.com for (int i = 0; i < 32; ++i) { 24011274Sshingarov@labware.com context->setIntReg(i, r.gpr[i]); 2413536Sgblack@eecs.umich.edu } 2423536Sgblack@eecs.umich.edu } 2433536Sgblack@eecs.umich.edu 2443536Sgblack@eecs.umich.edu#ifdef KGDB_FP_REGS 2455568Snate@binkert.org for (int i = 0; i < NumFloatArchRegs; ++i) { 24613611Sgabeblack@google.com context->setFloatReg(i, gdbregs.regs64[i + KGDB_REG_F0]); 2473536Sgblack@eecs.umich.edu } 2483536Sgblack@eecs.umich.edu#endif 24911274Sshingarov@labware.com context->pcState(r.pc); 2503536Sgblack@eecs.umich.edu} 2513536Sgblack@eecs.umich.edu 25212449Sgabeblack@google.com 25312449Sgabeblack@google.comBaseGdbRegCache* 25412449Sgabeblack@google.comRemoteGDB::gdbRegs() 2553536Sgblack@eecs.umich.edu{ 25612449Sgabeblack@google.com return new AlphaGdbRegCache(this); 2573536Sgblack@eecs.umich.edu} 2583536Sgblack@eecs.umich.edu 259