remote_gdb.cc revision 8541:27aaee8ec7cc
11689SN/A/* 29444SAndreas.Sandberg@ARM.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 37854SAli.Saidi@ARM.com * All rights reserved. 47854SAli.Saidi@ARM.com * 57854SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 67854SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are 77854SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright 87854SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer; 97854SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright 107854SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the 117854SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution; 127854SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its 137854SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from 142329SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271689SN/A * 281689SN/A * Authors: Nathan Binkert 291689SN/A */ 301689SN/A 311689SN/A/* 321689SN/A * Copyright (c) 1990, 1993 The Regents of the University of California 331689SN/A * All rights reserved. 341689SN/A * 351689SN/A * This software was developed by the Computer Systems Engineering group 361689SN/A * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 371689SN/A * contributed to Berkeley. 381689SN/A * 392665Ssaidi@eecs.umich.edu * All advertising materials mentioning features or use of this software 402665Ssaidi@eecs.umich.edu * must display the following acknowledgement: 412935Sksewell@umich.edu * This product includes software developed by the University of 421689SN/A * California, Lawrence Berkeley Laboratories. 431689SN/A * 441060SN/A * Redistribution and use in source and binary forms, with or without 451060SN/A * modification, are permitted provided that the following conditions 463773Sgblack@eecs.umich.edu * are met: 476329Sgblack@eecs.umich.edu * 1. Redistributions of source code must retain the above copyright 486658Snate@binkert.org * notice, this list of conditions and the following disclaimer. 491717SN/A * 2. Redistributions in binary form must reproduce the above copyright 508232Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 518232Snate@binkert.org * documentation and/or other materials provided with the distribution. 525529Snate@binkert.org * 3. All advertising materials mentioning features or use of this software 531060SN/A * must display the following acknowledgement: 546221Snate@binkert.org * This product includes software developed by the University of 556221Snate@binkert.org * California, Berkeley and its contributors. 561061SN/A * 4. Neither the name of the University nor the names of its contributors 575529Snate@binkert.org * may be used to endorse or promote products derived from this software 584329Sktlim@umich.edu * without specific prior written permission. 594329Sktlim@umich.edu * 602292SN/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 612292SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 622292SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 632292SN/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 645529Snate@binkert.org * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 652361SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 661060SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 672292SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 688907Slukefahr@umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 692292SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 702292SN/A * SUCH DAMAGE. 712292SN/A * 722292SN/A * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 732292SN/A */ 742292SN/A 752292SN/A/*- 761060SN/A * Copyright (c) 2001 The NetBSD Foundation, Inc. 771060SN/A * All rights reserved. 781061SN/A * 791060SN/A * This code is derived from software contributed to The NetBSD Foundation 802292SN/A * by Jason R. Thorpe. 811062SN/A * 821062SN/A * Redistribution and use in source and binary forms, with or without 838240Snate@binkert.org * modification, are permitted provided that the following conditions 841062SN/A * are met: 851062SN/A * 1. Redistributions of source code must retain the above copyright 861062SN/A * notice, this list of conditions and the following disclaimer. 878240Snate@binkert.org * 2. Redistributions in binary form must reproduce the above copyright 881062SN/A * notice, this list of conditions and the following disclaimer in the 891062SN/A * documentation and/or other materials provided with the distribution. 901062SN/A * 3. All advertising materials mentioning features or use of this software 918240Snate@binkert.org * must display the following acknowledgement: 921062SN/A * This product includes software developed by the NetBSD 931062SN/A * Foundation, Inc. and its contributors. 942301SN/A * 4. Neither the name of The NetBSD Foundation nor the names of its 958240Snate@binkert.org * contributors may be used to endorse or promote products derived 962301SN/A * from this software without specific prior written permission. 972301SN/A * 982292SN/A * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 998240Snate@binkert.org * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1002292SN/A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1012292SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1021062SN/A * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1038240Snate@binkert.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1041062SN/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1051062SN/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1061062SN/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1078240Snate@binkert.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1081062SN/A * POSSIBILITY OF SUCH DAMAGE. 1091062SN/A */ 1101062SN/A 1118240Snate@binkert.org/* 1121062SN/A * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 1131062SN/A * 1141062SN/A * Taken from NetBSD 1158240Snate@binkert.org * 1162292SN/A * "Stub" to allow remote cpu to debug over a serial line using gdb. 1171062SN/A */ 1181062SN/A 1198240Snate@binkert.org#include <sys/signal.h> 1202292SN/A#include <unistd.h> 1211062SN/A 1222292SN/A#include <string> 1238240Snate@binkert.org 1242292SN/A#include "config/full_system.hh" 1252292SN/A#if FULL_SYSTEM 1261062SN/A#include "arch/alpha/vtophys.hh" 1278240Snate@binkert.org#endif 1281062SN/A 1291062SN/A#include "arch/alpha/kgdb.h" 1301062SN/A#include "arch/alpha/regredir.hh" 1318240Snate@binkert.org#include "arch/alpha/remote_gdb.hh" 1321062SN/A#include "arch/alpha/utility.hh" 1331062SN/A#include "base/intmath.hh" 1341062SN/A#include "base/remote_gdb.hh" 1358240Snate@binkert.org#include "base/socket.hh" 1361062SN/A#include "base/trace.hh" 1371062SN/A#include "cpu/decode.hh" 1381062SN/A#include "cpu/static_inst.hh" 1398240Snate@binkert.org#include "cpu/thread_context.hh" 1401062SN/A#include "debug/GDBAcc.hh" 1411062SN/A#include "debug/GDBMisc.hh" 1421062SN/A#include "mem/physical.hh" 1438240Snate@binkert.org#include "mem/port.hh" 1441062SN/A#include "sim/system.hh" 1451062SN/A 1462301SN/Ausing namespace std; 1478240Snate@binkert.orgusing namespace AlphaISA; 1482301SN/A 1492301SN/ARemoteGDB::RemoteGDB(System *_system, ThreadContext *tc) 1502301SN/A : BaseRemoteGDB(_system, tc, KGDB_NUMREGS) 1512301SN/A{ 1528240Snate@binkert.org memset(gdbregs.regs, 0, gdbregs.bytes()); 1532301SN/A} 1542301SN/A 1552301SN/A/* 1562307SN/A * Determine if the mapping at va..(va+len) is valid. 1578240Snate@binkert.org */ 1582307SN/Abool 1592307SN/ARemoteGDB::acc(Addr va, size_t len) 1602307SN/A{ 1617897Shestness@cs.utexas.edu#if !FULL_SYSTEM 1628240Snate@binkert.org panic("acc function needs to be rewritten for SE mode\n"); 1637897Shestness@cs.utexas.edu#else 1647897Shestness@cs.utexas.edu Addr last_va; 1657897Shestness@cs.utexas.edu 1668240Snate@binkert.org va = TruncPage(va); 1677897Shestness@cs.utexas.edu last_va = RoundPage(va + len); 1687897Shestness@cs.utexas.edu 1691062SN/A do { 1701062SN/A if (IsK0Seg(va)) { 1711062SN/A if (va < (K0SegBase + pmem->size())) { 1721062SN/A DPRINTF(GDBAcc, "acc: Mapping is valid K0SEG <= " 1732292SN/A "%#x < K0SEG + size\n", va); 1741060SN/A return true; 1751060SN/A } else { 1761060SN/A DPRINTF(GDBAcc, "acc: Mapping invalid %#x > K0SEG + size\n", 1771060SN/A va); 1781060SN/A return false; 1791060SN/A } 1801060SN/A } 1811060SN/A 1821060SN/A /** 1831060SN/A * This code says that all accesses to palcode (instruction 1841060SN/A * and data) are valid since there isn't a va->pa mapping 1851060SN/A * because palcode is accessed physically. At some point this 1861060SN/A * should probably be cleaned up but there is no easy way to 1871061SN/A * do it. 1881060SN/A */ 1892292SN/A 1901060SN/A if (PcPAL(va) || va < 0x10000) 1911060SN/A return true; 1921060SN/A 1931060SN/A Addr ptbr = context->readMiscRegNoEffect(IPR_PALtemp20); 1941060SN/A PageTableEntry pte = 1951060SN/A kernel_pte_lookup(context->getPhysPort(), ptbr, va); 1961060SN/A if (!pte.valid()) { 1971061SN/A DPRINTF(GDBAcc, "acc: %#x pte is invalid\n", va); 1981060SN/A return false; 1992292SN/A } 2001060SN/A va += PageBytes; 2011060SN/A } while (va < last_va); 2021060SN/A 2031060SN/A DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va); 2041060SN/A return true; 2051060SN/A#endif 2061060SN/A} 2071061SN/A 2081060SN/A/* 2099427SAndreas.Sandberg@ARM.com * Translate the kernel debugger register format into the GDB register 2101060SN/A * format. 2119444SAndreas.Sandberg@ARM.com */ 2129444SAndreas.Sandberg@ARM.comvoid 2139444SAndreas.Sandberg@ARM.comRemoteGDB::getregs() 2149444SAndreas.Sandberg@ARM.com{ 2159444SAndreas.Sandberg@ARM.com memset(gdbregs.regs, 0, gdbregs.bytes()); 2169444SAndreas.Sandberg@ARM.com 2179444SAndreas.Sandberg@ARM.com gdbregs.regs[KGDB_REG_PC] = context->pcState().pc(); 2189444SAndreas.Sandberg@ARM.com 2199444SAndreas.Sandberg@ARM.com // @todo: Currently this is very Alpha specific. 2209444SAndreas.Sandberg@ARM.com if (PcPAL(gdbregs.regs[KGDB_REG_PC])) { 2219444SAndreas.Sandberg@ARM.com for (int i = 0; i < NumIntArchRegs; ++i) { 2229444SAndreas.Sandberg@ARM.com gdbregs.regs[i] = context->readIntReg(reg_redir[i]); 2232329SN/A } 2246221Snate@binkert.org } else { 2259444SAndreas.Sandberg@ARM.com for (int i = 0; i < NumIntArchRegs; ++i) { 2269444SAndreas.Sandberg@ARM.com gdbregs.regs[i] = context->readIntReg(i); 2272292SN/A } 2282292SN/A } 2292292SN/A 2302292SN/A#ifdef KGDB_FP_REGS 2319444SAndreas.Sandberg@ARM.com for (int i = 0; i < NumFloatArchRegs; ++i) { 2329444SAndreas.Sandberg@ARM.com gdbregs.regs[i + KGDB_REG_F0] = context->readFloatRegBits(i); 2339444SAndreas.Sandberg@ARM.com } 2349444SAndreas.Sandberg@ARM.com#endif 2359444SAndreas.Sandberg@ARM.com} 2369444SAndreas.Sandberg@ARM.com 2379444SAndreas.Sandberg@ARM.com/* 2389444SAndreas.Sandberg@ARM.com * Translate the GDB register format into the kernel debugger register 2392292SN/A * format. 2401060SN/A */ 2411060SN/Avoid 2422292SN/ARemoteGDB::setregs() 2432292SN/A{ 2446221Snate@binkert.org // @todo: Currently this is very Alpha specific. 2452292SN/A if (PcPAL(gdbregs.regs[KGDB_REG_PC])) { 2462292SN/A for (int i = 0; i < NumIntArchRegs; ++i) { 2472292SN/A context->setIntReg(reg_redir[i], gdbregs.regs[i]); 2482292SN/A } 2492292SN/A } else { 2501061SN/A for (int i = 0; i < NumIntArchRegs; ++i) { 2511060SN/A context->setIntReg(i, gdbregs.regs[i]); 2522292SN/A } 2531060SN/A } 2546221Snate@binkert.org 2556221Snate@binkert.org#ifdef KGDB_FP_REGS 2561060SN/A for (int i = 0; i < NumFloatArchRegs; ++i) { 2571060SN/A context->setFloatRegBits(i, gdbregs.regs[i + KGDB_REG_F0]); 2581061SN/A } 2591060SN/A#endif 2602292SN/A context->pcState(gdbregs.regs[KGDB_REG_PC]); 2611060SN/A} 2622292SN/A 2632292SN/Avoid 2641060SN/ARemoteGDB::clearSingleStep() 2652292SN/A{ 2662292SN/A DPRINTF(GDBMisc, "clearSingleStep bt_addr=%#x nt_addr=%#x\n", 2672292SN/A takenBkpt, notTakenBkpt); 2682292SN/A 2692292SN/A if (takenBkpt != 0) 2701060SN/A clearTempBreakpoint(takenBkpt); 2711060SN/A 2721061SN/A if (notTakenBkpt != 0) 2732863Sktlim@umich.edu clearTempBreakpoint(notTakenBkpt); 2749444SAndreas.Sandberg@ARM.com} 2751060SN/A 2769444SAndreas.Sandberg@ARM.comvoid 2779444SAndreas.Sandberg@ARM.comRemoteGDB::setSingleStep() 2789444SAndreas.Sandberg@ARM.com{ 2799444SAndreas.Sandberg@ARM.com PCState pc = context->pcState(); 2809444SAndreas.Sandberg@ARM.com PCState bpc; 2819444SAndreas.Sandberg@ARM.com bool set_bt = false; 2829444SAndreas.Sandberg@ARM.com 2832863Sktlim@umich.edu // User was stopped at pc, e.g. the instruction at pc was not 2842316SN/A // executed. 2851060SN/A MachInst inst = read<MachInst>(pc.pc()); 2862316SN/A StaticInstPtr si = context->getDecoderPtr()->decode(inst, pc.pc()); 2872316SN/A if (si->hasBranchTarget(pc, context, bpc)) { 2882307SN/A // Don't bother setting a breakpoint on the taken branch if it 2891060SN/A // is the same as the next pc 2909444SAndreas.Sandberg@ARM.com if (bpc.pc() != pc.npc()) 2919444SAndreas.Sandberg@ARM.com set_bt = true; 2921060SN/A } 2939444SAndreas.Sandberg@ARM.com 2949444SAndreas.Sandberg@ARM.com DPRINTF(GDBMisc, "setSingleStep bt_addr=%#x nt_addr=%#x\n", 2959444SAndreas.Sandberg@ARM.com takenBkpt, notTakenBkpt); 2969444SAndreas.Sandberg@ARM.com 2976221Snate@binkert.org setTempBreakpoint(notTakenBkpt = pc.npc()); 2989444SAndreas.Sandberg@ARM.com 2999444SAndreas.Sandberg@ARM.com if (set_bt) 3009444SAndreas.Sandberg@ARM.com setTempBreakpoint(takenBkpt = bpc.pc()); 3019444SAndreas.Sandberg@ARM.com} 3022307SN/A 3032307SN/A// Write bytes to kernel address space for debugger. 3042307SN/Abool 3052307SN/ARemoteGDB::write(Addr vaddr, size_t size, const char *data) 3062307SN/A{ 3076221Snate@binkert.org if (BaseRemoteGDB::write(vaddr, size, data)) { 3081858SN/A#ifdef IMB 3092292SN/A alpha_pal_imb(); 3101858SN/A#endif 3112292SN/A return true; 3122292SN/A } else { 3132292SN/A return false; 3142292SN/A } 3153788Sgblack@eecs.umich.edu} 3162292SN/A 3172698Sktlim@umich.edu