remote_gdb.cc revision 8229
14684SN/A/* 25419SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 34684SN/A * All rights reserved. 44684SN/A * 57087SN/A * Redistribution and use in source and binary forms, with or without 67087SN/A * modification, are permitted provided that the following conditions are 77087SN/A * met: redistributions of source code must retain the above copyright 87087SN/A * notice, this list of conditions and the following disclaimer; 97087SN/A * redistributions in binary form must reproduce the above copyright 107087SN/A * notice, this list of conditions and the following disclaimer in the 117087SN/A * documentation and/or other materials provided with the distribution; 127087SN/A * neither the name of the copyright holders nor the names of its 134684SN/A * contributors may be used to endorse or promote products derived from 147087SN/A * this software without specific prior written permission. 157087SN/A * 167087SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177087SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187087SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197087SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207087SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217087SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224684SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237087SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244684SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254684SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264684SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274684SN/A * 284684SN/A * Authors: Nathan Binkert 294684SN/A */ 304684SN/A 314684SN/A/* 324684SN/A * Copyright (c) 1990, 1993 334684SN/A * The Regents of the University of California. All rights reserved. 344684SN/A * 354684SN/A * This software was developed by the Computer Systems Engineering group 364684SN/A * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 374684SN/A * contributed to Berkeley. 384684SN/A * 394684SN/A * All advertising materials mentioning features or use of this software 404684SN/A * must display the following acknowledgement: 414684SN/A * This product includes software developed by the University of 424684SN/A * California, Lawrence Berkeley Laboratories. 437629Sgblack@eecs.umich.edu * 445025SN/A * Redistribution and use in source and binary forms, with or without 454684SN/A * modification, are permitted provided that the following conditions 464684SN/A * are met: 475086SN/A * 1. Redistributions of source code must retain the above copyright 485086SN/A * notice, this list of conditions and the following disclaimer. 495086SN/A * 2. Redistributions in binary form must reproduce the above copyright 505086SN/A * notice, this list of conditions and the following disclaimer in the 515086SN/A * documentation and/or other materials provided with the distribution. 525086SN/A * 3. All advertising materials mentioning features or use of this software 534684SN/A * must display the following acknowledgement: 544684SN/A * This product includes software developed by the University of 554684SN/A * California, Berkeley and its contributors. 564684SN/A * 4. Neither the name of the University nor the names of its contributors 574684SN/A * may be used to endorse or promote products derived from this software 584684SN/A * without specific prior written permission. 594684SN/A * 604684SN/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 614684SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 624684SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 634868SN/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 644684SN/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 654684SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 664684SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 679010Snilay@cs.wisc.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 689211Snilay@cs.wisc.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 699010Snilay@cs.wisc.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 705426SN/A * SUCH DAMAGE. 715426SN/A * 725426SN/A * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 735426SN/A */ 745426SN/A 755426SN/A/*- 765426SN/A * Copyright (c) 2001 The NetBSD Foundation, Inc. 775426SN/A * All rights reserved. 785426SN/A * 795426SN/A * This code is derived from software contributed to The NetBSD Foundation 805426SN/A * by Jason R. Thorpe. 815426SN/A * 829470Snilay@cs.wisc.edu * Redistribution and use in source and binary forms, with or without 839470Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions 849470Snilay@cs.wisc.edu * are met: 859470Snilay@cs.wisc.edu * 1. Redistributions of source code must retain the above copyright 869470Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer. 879470Snilay@cs.wisc.edu * 2. Redistributions in binary form must reproduce the above copyright 889470Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the 899470Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution. 909470Snilay@cs.wisc.edu * 3. All advertising materials mentioning features or use of this software 919470Snilay@cs.wisc.edu * must display the following acknowledgement: 929470Snilay@cs.wisc.edu * This product includes software developed by the NetBSD 939470Snilay@cs.wisc.edu * Foundation, Inc. and its contributors. 949470Snilay@cs.wisc.edu * 4. Neither the name of The NetBSD Foundation nor the names of its 959470Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived 969470Snilay@cs.wisc.edu * from this software without specific prior written permission. 979470Snilay@cs.wisc.edu * 989470Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 999470Snilay@cs.wisc.edu * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1009470Snilay@cs.wisc.edu * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1014700SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1024700SN/A * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1034700SN/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1044700SN/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1054862SN/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1064862SN/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1074700SN/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1084700SN/A * POSSIBILITY OF SUCH DAMAGE. 1094700SN/A */ 1104700SN/A 1114700SN/A/* 1124700SN/A * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ 1134700SN/A * 1144700SN/A * Taken from NetBSD 1154700SN/A * 1164700SN/A * "Stub" to allow remote cpu to debug over a serial line using gdb. 1174700SN/A */ 1184700SN/A 1194700SN/A#include <sys/signal.h> 1204700SN/A#include <unistd.h> 1214700SN/A 1224700SN/A#include <string> 1234700SN/A 1245025SN/A#include "config/full_system.hh" 1254862SN/A#if FULL_SYSTEM 1264700SN/A#include "arch/alpha/vtophys.hh" 1274700SN/A#endif 1284700SN/A 1294700SN/A#include "arch/alpha/kgdb.h" 1304700SN/A#include "arch/alpha/regredir.hh" 1314700SN/A#include "arch/alpha/remote_gdb.hh" 1324700SN/A#include "arch/alpha/utility.hh" 1334700SN/A#include "base/intmath.hh" 1344700SN/A#include "base/remote_gdb.hh" 1355025SN/A#include "base/socket.hh" 1364700SN/A#include "base/trace.hh" 1375429SN/A#include "cpu/static_inst.hh" 1385429SN/A#include "cpu/thread_context.hh" 1395429SN/A#include "mem/physical.hh" 1405138SN/A#include "mem/port.hh" 1415138SN/A#include "sim/system.hh" 1425138SN/A 1435138SN/Ausing namespace std; 1445138SN/Ausing namespace AlphaISA; 1455138SN/A 1465138SN/ARemoteGDB::RemoteGDB(System *_system, ThreadContext *tc) 1475138SN/A : BaseRemoteGDB(_system, tc, KGDB_NUMREGS) 1485138SN/A{ 1495138SN/A memset(gdbregs.regs, 0, gdbregs.bytes()); 1505138SN/A} 1515138SN/A 1525138SN/A/* 1535138SN/A * Determine if the mapping at va..(va+len) is valid. 1545138SN/A */ 1555138SN/Abool 1565138SN/ARemoteGDB::acc(Addr va, size_t len) 1575138SN/A{ 1585138SN/A#if !FULL_SYSTEM 1595138SN/A panic("acc function needs to be rewritten for SE mode\n"); 1605138SN/A#else 1615138SN/A Addr last_va; 1625138SN/A 1635138SN/A va = TruncPage(va); 1645138SN/A last_va = RoundPage(va + len); 1655138SN/A 1665138SN/A do { 1675138SN/A if (IsK0Seg(va)) { 1685138SN/A if (va < (K0SegBase + pmem->size())) { 1695138SN/A DPRINTF(GDBAcc, "acc: Mapping is valid K0SEG <= " 1705138SN/A "%#x < K0SEG + size\n", va); 1715138SN/A return true; 1726346SN/A } else { 1735138SN/A DPRINTF(GDBAcc, "acc: Mapping invalid %#x > K0SEG + size\n", 1746346SN/A va); 1755138SN/A return false; 1765138SN/A } 1775138SN/A } 1785138SN/A 1795138SN/A /** 1805138SN/A * This code says that all accesses to palcode (instruction 1815138SN/A * and data) are valid since there isn't a va->pa mapping 1825138SN/A * because palcode is accessed physically. At some point this 1836346SN/A * should probably be cleaned up but there is no easy way to 1845138SN/A * do it. 1856346SN/A */ 1865138SN/A 1875138SN/A if (PcPAL(va) || va < 0x10000) 1885138SN/A return true; 1895149SN/A 1905138SN/A Addr ptbr = context->readMiscRegNoEffect(IPR_PALtemp20); 1915138SN/A PageTableEntry pte = 1925138SN/A kernel_pte_lookup(context->getPhysPort(), ptbr, va); 1935138SN/A if (!pte.valid()) { 1945138SN/A DPRINTF(GDBAcc, "acc: %#x pte is invalid\n", va); 1955138SN/A return false; 1965138SN/A } 1975138SN/A va += PageBytes; 1985138SN/A } while (va < last_va); 1995138SN/A 2005138SN/A DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va); 2015138SN/A return true; 2025138SN/A#endif 2035138SN/A} 2045138SN/A 2055138SN/A/* 2065138SN/A * Translate the kernel debugger register format into the GDB register 2075419SN/A * format. 2085419SN/A */ 2095419SN/Avoid 2106346SN/ARemoteGDB::getregs() 2115138SN/A{ 2126346SN/A memset(gdbregs.regs, 0, gdbregs.bytes()); 2135138SN/A 2145138SN/A gdbregs.regs[KGDB_REG_PC] = context->pcState().pc(); 2155138SN/A 2165138SN/A // @todo: Currently this is very Alpha specific. 2175138SN/A if (PcPAL(gdbregs.regs[KGDB_REG_PC])) { 2185419SN/A for (int i = 0; i < NumIntArchRegs; ++i) { 2195419SN/A gdbregs.regs[i] = context->readIntReg(reg_redir[i]); 2205419SN/A } 2216346SN/A } else { 2225138SN/A for (int i = 0; i < NumIntArchRegs; ++i) { 2236346SN/A gdbregs.regs[i] = context->readIntReg(i); 2245138SN/A } 2255138SN/A } 2265138SN/A 2275138SN/A#ifdef KGDB_FP_REGS 2285138SN/A for (int i = 0; i < NumFloatArchRegs; ++i) { 2295419SN/A gdbregs.regs[i + KGDB_REG_F0] = context->readFloatRegBits(i); 2305419SN/A } 2315419SN/A#endif 2326346SN/A} 2335138SN/A 2346346SN/A/* 2355138SN/A * Translate the GDB register format into the kernel debugger register 2365138SN/A * format. 2375138SN/A */ 2385138SN/Avoid 2395138SN/ARemoteGDB::setregs() 2405419SN/A{ 2415419SN/A // @todo: Currently this is very Alpha specific. 2425419SN/A if (PcPAL(gdbregs.regs[KGDB_REG_PC])) { 2436346SN/A for (int i = 0; i < NumIntArchRegs; ++i) { 2445138SN/A context->setIntReg(reg_redir[i], gdbregs.regs[i]); 2455135SN/A } 2466346SN/A } else { 2475135SN/A for (int i = 0; i < NumIntArchRegs; ++i) { 2485138SN/A context->setIntReg(i, gdbregs.regs[i]); 2495138SN/A } 2505138SN/A } 2515138SN/A 2525138SN/A#ifdef KGDB_FP_REGS 2535138SN/A for (int i = 0; i < NumFloatArchRegs; ++i) { 2545138SN/A context->setFloatRegBits(i, gdbregs.regs[i + KGDB_REG_F0]); 2555138SN/A } 2565138SN/A#endif 2575138SN/A context->pcState(gdbregs.regs[KGDB_REG_PC]); 2585138SN/A} 2595138SN/A 2605138SN/Avoid 2615138SN/ARemoteGDB::clearSingleStep() 2625138SN/A{ 2636346SN/A DPRINTF(GDBMisc, "clearSingleStep bt_addr=%#x nt_addr=%#x\n", 2645138SN/A takenBkpt, notTakenBkpt); 2656346SN/A 2665138SN/A if (takenBkpt != 0) 2675138SN/A clearTempBreakpoint(takenBkpt); 2685138SN/A 2695138SN/A if (notTakenBkpt != 0) 2706346SN/A clearTempBreakpoint(notTakenBkpt); 2715138SN/A} 2726346SN/A 2735138SN/Avoid 2745138SN/ARemoteGDB::setSingleStep() 2755138SN/A{ 2765138SN/A PCState pc = context->pcState(); 2776346SN/A PCState bpc; 2785138SN/A bool set_bt = false; 2796346SN/A 2805138SN/A // User was stopped at pc, e.g. the instruction at pc was not 2815138SN/A // executed. 2826346SN/A MachInst inst = read<MachInst>(pc.pc()); 2835138SN/A StaticInstPtr si(inst, pc.pc()); 2846346SN/A if (si->hasBranchTarget(pc, context, bpc)) { 2855138SN/A // Don't bother setting a breakpoint on the taken branch if it 2865138SN/A // is the same as the next pc 2875138SN/A if (bpc.pc() != pc.npc()) 2885138SN/A set_bt = true; 2895138SN/A } 2905138SN/A 2915138SN/A DPRINTF(GDBMisc, "setSingleStep bt_addr=%#x nt_addr=%#x\n", 2925138SN/A takenBkpt, notTakenBkpt); 2935138SN/A 2945138SN/A setTempBreakpoint(notTakenBkpt = pc.npc()); 2954700SN/A 2964862SN/A if (set_bt) 2974862SN/A setTempBreakpoint(takenBkpt = bpc.pc()); 2984700SN/A} 2994700SN/A 3004700SN/A// Write bytes to kernel address space for debugger. 3014700SN/Abool 3024700SN/ARemoteGDB::write(Addr vaddr, size_t size, const char *data) 3035294SN/A{ 3045294SN/A if (BaseRemoteGDB::write(vaddr, size, data)) { 3055294SN/A#ifdef IMB 3065294SN/A alpha_pal_imb(); 3075294SN/A#endif 3085294SN/A return true; 3095294SN/A } else { 3104700SN/A return false; 3114700SN/A } 3125294SN/A} 3134862SN/A 3144700SN/A