remote_gdb.cc revision 8767
13536Sgblack@eecs.umich.edu/* 23536Sgblack@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 33536Sgblack@eecs.umich.edu * All rights reserved. 43536Sgblack@eecs.umich.edu * 53536Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 63536Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 73536Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 83536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 93536Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 103536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 113536Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 123536Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 133536Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 143536Sgblack@eecs.umich.edu * this software without specific prior written permission. 153536Sgblack@eecs.umich.edu * 163536Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173536Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183536Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193536Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203536Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213536Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223536Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233536Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243536Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253536Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263536Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273536Sgblack@eecs.umich.edu * 283536Sgblack@eecs.umich.edu * Authors: Nathan Binkert 293536Sgblack@eecs.umich.edu */ 303536Sgblack@eecs.umich.edu 313536Sgblack@eecs.umich.edu/* 328332Snate@binkert.org * Copyright (c) 1990, 1993 The Regents of the University of California 338332Snate@binkert.org * All rights reserved 343536Sgblack@eecs.umich.edu * 353536Sgblack@eecs.umich.edu * This software was developed by the Computer Systems Engineering group 363536Sgblack@eecs.umich.edu * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 373536Sgblack@eecs.umich.edu * contributed to Berkeley. 383536Sgblack@eecs.umich.edu * 393536Sgblack@eecs.umich.edu * All advertising materials mentioning features or use of this software 403536Sgblack@eecs.umich.edu * must display the following acknowledgement: 415543Ssaidi@eecs.umich.edu * This product includes software developed by the University of 425543Ssaidi@eecs.umich.edu * California, Lawrence Berkeley Laboratories. 433536Sgblack@eecs.umich.edu * 443536Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 453536Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions 463536Sgblack@eecs.umich.edu * are met: 473536Sgblack@eecs.umich.edu * 1. Redistributions of source code must retain the above copyright 483536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer. 493536Sgblack@eecs.umich.edu * 2. Redistributions in binary form must reproduce the above copyright 503536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 513536Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution. 523536Sgblack@eecs.umich.edu * 3. All advertising materials mentioning features or use of this software 533536Sgblack@eecs.umich.edu * must display the following acknowledgement: 545543Ssaidi@eecs.umich.edu * This product includes software developed by the University of 555543Ssaidi@eecs.umich.edu * California, Berkeley and its contributors. 563536Sgblack@eecs.umich.edu * 4. Neither the name of the University nor the names of its contributors 573536Sgblack@eecs.umich.edu * may be used to endorse or promote products derived from this software 583536Sgblack@eecs.umich.edu * without specific prior written permission. 593536Sgblack@eecs.umich.edu * 603536Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 613536Sgblack@eecs.umich.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 623536Sgblack@eecs.umich.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 633536Sgblack@eecs.umich.edu * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 643536Sgblack@eecs.umich.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 653536Sgblack@eecs.umich.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 663536Sgblack@eecs.umich.edu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 673536Sgblack@eecs.umich.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 683536Sgblack@eecs.umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 693536Sgblack@eecs.umich.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 703536Sgblack@eecs.umich.edu * SUCH DAMAGE. 713536Sgblack@eecs.umich.edu * 725543Ssaidi@eecs.umich.edu * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 733536Sgblack@eecs.umich.edu */ 743536Sgblack@eecs.umich.edu 753536Sgblack@eecs.umich.edu/*- 763536Sgblack@eecs.umich.edu * Copyright (c) 2001 The NetBSD Foundation, Inc. 773536Sgblack@eecs.umich.edu * All rights reserved. 783536Sgblack@eecs.umich.edu * 793536Sgblack@eecs.umich.edu * This code is derived from software contributed to The NetBSD Foundation 803536Sgblack@eecs.umich.edu * by Jason R. Thorpe. 813536Sgblack@eecs.umich.edu * 823536Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 833536Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions 843536Sgblack@eecs.umich.edu * are met: 853536Sgblack@eecs.umich.edu * 1. Redistributions of source code must retain the above copyright 863536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer. 873536Sgblack@eecs.umich.edu * 2. Redistributions in binary form must reproduce the above copyright 883536Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 893536Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution. 903536Sgblack@eecs.umich.edu * 3. All advertising materials mentioning features or use of this software 913536Sgblack@eecs.umich.edu * must display the following acknowledgement: 925543Ssaidi@eecs.umich.edu * This product includes software developed by the NetBSD 935543Ssaidi@eecs.umich.edu * Foundation, Inc. and its contributors. 943536Sgblack@eecs.umich.edu * 4. Neither the name of The NetBSD Foundation nor the names of its 953536Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived 963536Sgblack@eecs.umich.edu * from this software without specific prior written permission. 973536Sgblack@eecs.umich.edu * 983536Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 993536Sgblack@eecs.umich.edu * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1003536Sgblack@eecs.umich.edu * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1013536Sgblack@eecs.umich.edu * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1023536Sgblack@eecs.umich.edu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1033536Sgblack@eecs.umich.edu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1043536Sgblack@eecs.umich.edu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1053536Sgblack@eecs.umich.edu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1063536Sgblack@eecs.umich.edu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1073536Sgblack@eecs.umich.edu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1083536Sgblack@eecs.umich.edu * POSSIBILITY OF SUCH DAMAGE. 1093536Sgblack@eecs.umich.edu */ 1103536Sgblack@eecs.umich.edu 1113536Sgblack@eecs.umich.edu/* 1123536Sgblack@eecs.umich.edu * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 1133536Sgblack@eecs.umich.edu * 1143536Sgblack@eecs.umich.edu * Taken from NetBSD 1153536Sgblack@eecs.umich.edu * 1163536Sgblack@eecs.umich.edu * "Stub" to allow remote cpu to debug over a serial line using gdb. 1173536Sgblack@eecs.umich.edu */ 1183536Sgblack@eecs.umich.edu 1193536Sgblack@eecs.umich.edu#include <sys/signal.h> 1208229Snate@binkert.org#include <unistd.h> 1213536Sgblack@eecs.umich.edu 1223536Sgblack@eecs.umich.edu#include <string> 1233536Sgblack@eecs.umich.edu 1248229Snate@binkert.org#include "arch/sparc/remote_gdb.hh" 1253536Sgblack@eecs.umich.edu#include "arch/vtophys.hh" 1263536Sgblack@eecs.umich.edu#include "base/intmath.hh" 1273536Sgblack@eecs.umich.edu#include "base/remote_gdb.hh" 1283536Sgblack@eecs.umich.edu#include "base/socket.hh" 1293536Sgblack@eecs.umich.edu#include "base/trace.hh" 1303536Sgblack@eecs.umich.edu#include "config/full_system.hh" 1318229Snate@binkert.org#include "cpu/static_inst.hh" 1323536Sgblack@eecs.umich.edu#include "cpu/thread_context.hh" 1338232Snate@binkert.org#include "debug/GDBRead.hh" 1345107Sgblack@eecs.umich.edu#include "mem/page_table.hh" 1353536Sgblack@eecs.umich.edu#include "mem/physical.hh" 1363536Sgblack@eecs.umich.edu#include "mem/port.hh" 1377678Sgblack@eecs.umich.edu#include "sim/byteswap.hh" 1388767Sgblack@eecs.umich.edu#include "sim/full_system.hh" 1395107Sgblack@eecs.umich.edu#include "sim/process.hh" 1403536Sgblack@eecs.umich.edu#include "sim/system.hh" 1413536Sgblack@eecs.umich.edu 1423536Sgblack@eecs.umich.eduusing namespace std; 1435567Snate@binkert.orgusing namespace SparcISA; 1443536Sgblack@eecs.umich.edu 1453550Sgblack@eecs.umich.eduRemoteGDB::RemoteGDB(System *_system, ThreadContext *c) 1464060Ssaidi@eecs.umich.edu : BaseRemoteGDB(_system, c, NumGDBRegs), nextBkpt(0) 1473536Sgblack@eecs.umich.edu{} 1483536Sgblack@eecs.umich.edu 1493536Sgblack@eecs.umich.edu/////////////////////////////////////////////////////////// 1503536Sgblack@eecs.umich.edu// RemoteGDB::acc 1513536Sgblack@eecs.umich.edu// 1525543Ssaidi@eecs.umich.edu// Determine if the mapping at va..(va+len) is valid. 1533536Sgblack@eecs.umich.edu// 1543536Sgblack@eecs.umich.edubool 1553536Sgblack@eecs.umich.eduRemoteGDB::acc(Addr va, size_t len) 1563536Sgblack@eecs.umich.edu{ 1573571Sgblack@eecs.umich.edu //@Todo In NetBSD, this function checks if all addresses 1587741Sgblack@eecs.umich.edu // from va to va + len have valid page map entries. Not 1597741Sgblack@eecs.umich.edu // sure how this will work for other OSes or in general. 1608767Sgblack@eecs.umich.edu if (FullSystem) { 1618767Sgblack@eecs.umich.edu if (va) 1628767Sgblack@eecs.umich.edu return true; 1638767Sgblack@eecs.umich.edu return false; 1648767Sgblack@eecs.umich.edu } else { 1658767Sgblack@eecs.umich.edu TlbEntry entry; 1668767Sgblack@eecs.umich.edu // Check to make sure the first byte is mapped into the processes 1678767Sgblack@eecs.umich.edu // address space. 1688767Sgblack@eecs.umich.edu if (context->getProcessPtr()->pTable->lookup(va, entry)) 1698767Sgblack@eecs.umich.edu return true; 1708767Sgblack@eecs.umich.edu return false; 1718767Sgblack@eecs.umich.edu } 1723536Sgblack@eecs.umich.edu} 1733536Sgblack@eecs.umich.edu 1743536Sgblack@eecs.umich.edu/////////////////////////////////////////////////////////// 1753536Sgblack@eecs.umich.edu// RemoteGDB::getregs 1763536Sgblack@eecs.umich.edu// 1775543Ssaidi@eecs.umich.edu// Translate the kernel debugger register format into 1785543Ssaidi@eecs.umich.edu// the GDB register format. 1793536Sgblack@eecs.umich.eduvoid 1803536Sgblack@eecs.umich.eduRemoteGDB::getregs() 1813536Sgblack@eecs.umich.edu{ 1823536Sgblack@eecs.umich.edu memset(gdbregs.regs, 0, gdbregs.size); 1833536Sgblack@eecs.umich.edu 1847720Sgblack@eecs.umich.edu PCState pc = context->pcState(); 1857720Sgblack@eecs.umich.edu 1864172Ssaidi@eecs.umich.edu if (context->readMiscReg(MISCREG_PSTATE) & 1874070Ssaidi@eecs.umich.edu PSTATE::am) { 1884070Ssaidi@eecs.umich.edu uint32_t *regs; 1894070Ssaidi@eecs.umich.edu regs = (uint32_t*)gdbregs.regs; 1907720Sgblack@eecs.umich.edu regs[Reg32Pc] = htobe((uint32_t)pc.pc()); 1917720Sgblack@eecs.umich.edu regs[Reg32Npc] = htobe((uint32_t)pc.npc()); 1927741Sgblack@eecs.umich.edu for (int x = RegG0; x <= RegI0 + 7; x++) 1934070Ssaidi@eecs.umich.edu regs[x] = htobe((uint32_t)context->readIntReg(x - RegG0)); 1944060Ssaidi@eecs.umich.edu 1954070Ssaidi@eecs.umich.edu regs[Reg32Y] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 1)); 1964172Ssaidi@eecs.umich.edu regs[Reg32Psr] = htobe((uint32_t)context->readMiscReg(MISCREG_PSTATE)); 1974172Ssaidi@eecs.umich.edu regs[Reg32Fsr] = htobe((uint32_t)context->readMiscReg(MISCREG_FSR)); 1984070Ssaidi@eecs.umich.edu regs[Reg32Csr] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 2)); 1994070Ssaidi@eecs.umich.edu } else { 2007720Sgblack@eecs.umich.edu gdbregs.regs[RegPc] = htobe(pc.pc()); 2017720Sgblack@eecs.umich.edu gdbregs.regs[RegNpc] = htobe(pc.npc()); 2027741Sgblack@eecs.umich.edu for (int x = RegG0; x <= RegI0 + 7; x++) 2034070Ssaidi@eecs.umich.edu gdbregs.regs[x] = htobe(context->readIntReg(x - RegG0)); 2044060Ssaidi@eecs.umich.edu 2054172Ssaidi@eecs.umich.edu gdbregs.regs[RegFsr] = htobe(context->readMiscReg(MISCREG_FSR)); 2064172Ssaidi@eecs.umich.edu gdbregs.regs[RegFprs] = htobe(context->readMiscReg(MISCREG_FPRS)); 2074070Ssaidi@eecs.umich.edu gdbregs.regs[RegY] = htobe(context->readIntReg(NumIntArchRegs + 1)); 2084070Ssaidi@eecs.umich.edu gdbregs.regs[RegState] = htobe( 2094172Ssaidi@eecs.umich.edu context->readMiscReg(MISCREG_CWP) | 2104172Ssaidi@eecs.umich.edu context->readMiscReg(MISCREG_PSTATE) << 8 | 2114172Ssaidi@eecs.umich.edu context->readMiscReg(MISCREG_ASI) << 24 | 2124070Ssaidi@eecs.umich.edu context->readIntReg(NumIntArchRegs + 2) << 32); 2134070Ssaidi@eecs.umich.edu } 2144060Ssaidi@eecs.umich.edu 2154060Ssaidi@eecs.umich.edu DPRINTF(GDBRead, "PC=%#x\n", gdbregs.regs[RegPc]); 2164060Ssaidi@eecs.umich.edu 2177741Sgblack@eecs.umich.edu // Floating point registers are left at 0 in netbsd 2187741Sgblack@eecs.umich.edu // All registers other than the pc, npc and int regs 2197741Sgblack@eecs.umich.edu // are ignored as well. 2203536Sgblack@eecs.umich.edu} 2213536Sgblack@eecs.umich.edu 2223536Sgblack@eecs.umich.edu/////////////////////////////////////////////////////////// 2233536Sgblack@eecs.umich.edu// RemoteGDB::setregs 2243536Sgblack@eecs.umich.edu// 2255543Ssaidi@eecs.umich.edu// Translate the GDB register format into the kernel 2265543Ssaidi@eecs.umich.edu// debugger register format. 2273536Sgblack@eecs.umich.edu// 2283536Sgblack@eecs.umich.eduvoid 2293536Sgblack@eecs.umich.eduRemoteGDB::setregs() 2303536Sgblack@eecs.umich.edu{ 2317720Sgblack@eecs.umich.edu PCState pc; 2327720Sgblack@eecs.umich.edu pc.pc(gdbregs.regs[RegPc]); 2337720Sgblack@eecs.umich.edu pc.npc(gdbregs.regs[RegNpc]); 2347720Sgblack@eecs.umich.edu pc.nnpc(pc.npc() + sizeof(MachInst)); 2357720Sgblack@eecs.umich.edu pc.upc(0); 2367720Sgblack@eecs.umich.edu pc.nupc(1); 2377720Sgblack@eecs.umich.edu context->pcState(pc); 2387741Sgblack@eecs.umich.edu for (int x = RegG0; x <= RegI0 + 7; x++) 2393550Sgblack@eecs.umich.edu context->setIntReg(x - RegG0, gdbregs.regs[x]); 2407741Sgblack@eecs.umich.edu // Only the integer registers, pc and npc are set in netbsd 2413536Sgblack@eecs.umich.edu} 2423536Sgblack@eecs.umich.edu 2433536Sgblack@eecs.umich.eduvoid 2443536Sgblack@eecs.umich.eduRemoteGDB::clearSingleStep() 2453536Sgblack@eecs.umich.edu{ 2464060Ssaidi@eecs.umich.edu if (nextBkpt) 2474060Ssaidi@eecs.umich.edu clearTempBreakpoint(nextBkpt); 2483536Sgblack@eecs.umich.edu} 2493536Sgblack@eecs.umich.edu 2503536Sgblack@eecs.umich.eduvoid 2513536Sgblack@eecs.umich.eduRemoteGDB::setSingleStep() 2523536Sgblack@eecs.umich.edu{ 2537720Sgblack@eecs.umich.edu nextBkpt = context->pcState().npc(); 2544060Ssaidi@eecs.umich.edu setTempBreakpoint(nextBkpt); 2553536Sgblack@eecs.umich.edu} 256