remote_gdb.cc revision 7720:65d338a8dba4
12SN/A/*
21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
292SN/A */
302SN/A
311464SN/A/*
321464SN/A * Copyright (c) 1990, 1993
332SN/A *      The Regents of the University of California.  All rights reserved.
342SN/A *
352SN/A * This software was developed by the Computer Systems Engineering group
362SN/A * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
378229Snate@binkert.org * contributed to Berkeley.
387720Sgblack@eecs.umich.edu *
392439SN/A * All advertising materials mentioning features or use of this software
4056SN/A * must display the following acknowledgement:
416216Snate@binkert.org *      This product includes software developed by the University of
428229Snate@binkert.org *      California, Lawrence Berkeley Laboratories.
432410SN/A *
448542Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
459338SAndreas.Sandberg@arm.com * modification, are permitted provided that the following conditions
467878Sgblack@eecs.umich.edu * are met:
472SN/A * 1. Redistributions of source code must retain the above copyright
482SN/A *    notice, this list of conditions and the following disclaimer.
491061SN/A * 2. Redistributions in binary form must reproduce the above copyright
502296SN/A *    notice, this list of conditions and the following disclaimer in the
512296SN/A *    documentation and/or other materials provided with the distribution.
52705SN/A * 3. All advertising materials mentioning features or use of this software
532623SN/A *    must display the following acknowledgement:
541464SN/A *      This product includes software developed by the University of
558737Skoansin.tan@gmail.com *      California, Berkeley and its contributors.
565597Sgblack@eecs.umich.edu * 4. Neither the name of the University nor the names of its contributors
575597Sgblack@eecs.umich.edu *    may be used to endorse or promote products derived from this software
585865Sksewell@umich.edu *    without specific prior written permission.
595865Sksewell@umich.edu *
602296SN/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
612312SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62716SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
632623SN/A * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
642623SN/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
651128SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
662SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
672SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
682SN/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
692SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
702SN/A * SUCH DAMAGE.
712SN/A *
722SN/A *      @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
732SN/A */
742SN/A
752SN/A/*-
762SN/A * Copyright (c) 2001 The NetBSD Foundation, Inc.
772SN/A * All rights reserved.
782SN/A *
792SN/A * This code is derived from software contributed to The NetBSD Foundation
808542Sgblack@eecs.umich.edu * by Jason R. Thorpe.
812SN/A *
827619Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
838542Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions
848542Sgblack@eecs.umich.edu * are met:
858542Sgblack@eecs.umich.edu * 1. Redistributions of source code must retain the above copyright
868542Sgblack@eecs.umich.edu *    notice, this list of conditions and the following disclaimer.
878542Sgblack@eecs.umich.edu * 2. Redistributions in binary form must reproduce the above copyright
888542Sgblack@eecs.umich.edu *    notice, this list of conditions and the following disclaimer in the
898542Sgblack@eecs.umich.edu *    documentation and/or other materials provided with the distribution.
908902Sandreas.hansson@arm.com * 3. All advertising materials mentioning features or use of this software
918542Sgblack@eecs.umich.edu *    must display the following acknowledgement:
922SN/A *      This product includes software developed by the NetBSD
932SN/A *      Foundation, Inc. and its contributors.
942SN/A * 4. Neither the name of The NetBSD Foundation nor the names of its
952SN/A *    contributors may be used to endorse or promote products derived
962SN/A *    from this software without specific prior written permission.
972SN/A *
982SN/A * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
992SN/A * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1002SN/A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1012SN/A * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1022SN/A * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
103753SN/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1042SN/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1052SN/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1062SN/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
107512SN/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
108512SN/A * POSSIBILITY OF SUCH DAMAGE.
109512SN/A */
110512SN/A
111512SN/A/*
112512SN/A * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
1132SN/A *
1142SN/A * Taken from NetBSD
1155543Ssaidi@eecs.umich.edu *
1162SN/A * "Stub" to allow remote cpu to debug over a serial line using gdb.
1175543Ssaidi@eecs.umich.edu */
1185543Ssaidi@eecs.umich.edu
1192SN/A#include <sys/signal.h>
1205543Ssaidi@eecs.umich.edu
1215543Ssaidi@eecs.umich.edu#include <string>
1225543Ssaidi@eecs.umich.edu#include <unistd.h>
1232336SN/A
1245222Sksewell@umich.edu#include "arch/vtophys.hh"
1255543Ssaidi@eecs.umich.edu#include "arch/sparc/remote_gdb.hh"
1265543Ssaidi@eecs.umich.edu#include "base/intmath.hh"
1272SN/A#include "base/remote_gdb.hh"
1285543Ssaidi@eecs.umich.edu#include "base/socket.hh"
1295543Ssaidi@eecs.umich.edu#include "base/trace.hh"
1305543Ssaidi@eecs.umich.edu#include "config/full_system.hh"
1315543Ssaidi@eecs.umich.edu#include "cpu/thread_context.hh"
1325543Ssaidi@eecs.umich.edu#include "cpu/static_inst.hh"
1335543Ssaidi@eecs.umich.edu#include "mem/page_table.hh"
1345543Ssaidi@eecs.umich.edu#include "mem/physical.hh"
1352SN/A#include "mem/port.hh"
1362135SN/A#include "sim/byteswap.hh"
1372135SN/A#include "sim/process.hh"
1385543Ssaidi@eecs.umich.edu#include "sim/system.hh"
139512SN/A
1405543Ssaidi@eecs.umich.eduusing namespace std;
141512SN/Ausing namespace SparcISA;
1422103SN/A
1432103SN/ARemoteGDB::RemoteGDB(System *_system, ThreadContext *c)
1445543Ssaidi@eecs.umich.edu    : BaseRemoteGDB(_system, c, NumGDBRegs), nextBkpt(0)
1455543Ssaidi@eecs.umich.edu{}
1465922Sgblack@eecs.umich.edu
1475222Sksewell@umich.edu///////////////////////////////////////////////////////////
1482SN/A// RemoteGDB::acc
149725SN/A//
1502336SN/A//      Determine if the mapping at va..(va+len) is valid.
1512227SN/A//
1522336SN/Abool
1532336SN/ARemoteGDB::acc(Addr va, size_t len)
154725SN/A{
1554828Sgblack@eecs.umich.edu    //@Todo In NetBSD, this function checks if all addresses
1564828Sgblack@eecs.umich.edu    //from va to va + len have valid page map entries. Not
1574828Sgblack@eecs.umich.edu    //sure how this will work for other OSes or in general.
1583271Sgblack@eecs.umich.edu#if FULL_SYSTEM
1594539Sgblack@eecs.umich.edu    if (va)
1605543Ssaidi@eecs.umich.edu        return true;
1615543Ssaidi@eecs.umich.edu    return false;
1625543Ssaidi@eecs.umich.edu#else
1635543Ssaidi@eecs.umich.edu    TlbEntry entry;
1643271Sgblack@eecs.umich.edu    //Check to make sure the first byte is mapped into the processes address
1655543Ssaidi@eecs.umich.edu    //space.
1665222Sksewell@umich.edu    if (context->getProcessPtr()->pTable->lookup(va, entry))
1677784SAli.Saidi@ARM.com        return true;
1682SN/A    return false;
1692SN/A#endif
1702SN/A}
1717619Sgblack@eecs.umich.edu
1727619Sgblack@eecs.umich.edu///////////////////////////////////////////////////////////
1732SN/A// RemoteGDB::getregs
1742SN/A//
1752SN/A//      Translate the kernel debugger register format into
1762SN/A//      the GDB register format.
1772SN/Avoid
1782SN/ARemoteGDB::getregs()
1792SN/A{
1802SN/A    memset(gdbregs.regs, 0, gdbregs.size);
1812SN/A
1822SN/A    PCState pc = context->pcState();
1832SN/A
1842SN/A    if (context->readMiscReg(MISCREG_PSTATE) &
1852SN/A           PSTATE::am) {
1862SN/A        uint32_t *regs;
1872SN/A        regs = (uint32_t*)gdbregs.regs;
1882SN/A        regs[Reg32Pc] = htobe((uint32_t)pc.pc());
1892SN/A        regs[Reg32Npc] = htobe((uint32_t)pc.npc());
1902SN/A        for(int x = RegG0; x <= RegI0 + 7; x++)
1912SN/A            regs[x] = htobe((uint32_t)context->readIntReg(x - RegG0));
1922SN/A
1932SN/A        regs[Reg32Y] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 1));
1942SN/A        regs[Reg32Psr] = htobe((uint32_t)context->readMiscReg(MISCREG_PSTATE));
1952SN/A        regs[Reg32Fsr] = htobe((uint32_t)context->readMiscReg(MISCREG_FSR));
1962SN/A        regs[Reg32Csr] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 2));
1972SN/A    } else {
1982SN/A        gdbregs.regs[RegPc] = htobe(pc.pc());
1992SN/A        gdbregs.regs[RegNpc] = htobe(pc.npc());
2002SN/A        for(int x = RegG0; x <= RegI0 + 7; x++)
2012SN/A            gdbregs.regs[x] = htobe(context->readIntReg(x - RegG0));
2022SN/A
2032SN/A        gdbregs.regs[RegFsr] = htobe(context->readMiscReg(MISCREG_FSR));
2042SN/A        gdbregs.regs[RegFprs] = htobe(context->readMiscReg(MISCREG_FPRS));
2052SN/A        gdbregs.regs[RegY] = htobe(context->readIntReg(NumIntArchRegs + 1));
2062SN/A        gdbregs.regs[RegState] = htobe(
2072SN/A            context->readMiscReg(MISCREG_CWP) |
2082SN/A            context->readMiscReg(MISCREG_PSTATE) << 8 |
2092SN/A            context->readMiscReg(MISCREG_ASI) << 24 |
2102SN/A            context->readIntReg(NumIntArchRegs + 2) << 32);
2112SN/A    }
2128542Sgblack@eecs.umich.edu
2132SN/A    DPRINTF(GDBRead, "PC=%#x\n", gdbregs.regs[RegPc]);
2142SN/A
2152SN/A    //Floating point registers are left at 0 in netbsd
2165543Ssaidi@eecs.umich.edu    //All registers other than the pc, npc and int regs
2172SN/A    //are ignored as well.
2185543Ssaidi@eecs.umich.edu}
2195543Ssaidi@eecs.umich.edu
2205543Ssaidi@eecs.umich.edu///////////////////////////////////////////////////////////
2215543Ssaidi@eecs.umich.edu// RemoteGDB::setregs
2222SN/A//
2232SN/A//      Translate the GDB register format into the kernel
2247725SAli.Saidi@ARM.com//      debugger register format.
2257725SAli.Saidi@ARM.com//
2262SN/Avoid
2275543Ssaidi@eecs.umich.eduRemoteGDB::setregs()
2285543Ssaidi@eecs.umich.edu{
2292SN/A    PCState pc;
2305543Ssaidi@eecs.umich.edu    pc.pc(gdbregs.regs[RegPc]);
2315543Ssaidi@eecs.umich.edu    pc.npc(gdbregs.regs[RegNpc]);
2325543Ssaidi@eecs.umich.edu    pc.nnpc(pc.npc() + sizeof(MachInst));
2335543Ssaidi@eecs.umich.edu    pc.upc(0);
2342SN/A    pc.nupc(1);
2355543Ssaidi@eecs.umich.edu    context->pcState(pc);
2365543Ssaidi@eecs.umich.edu    for(int x = RegG0; x <= RegI0 + 7; x++)
2372935Sksewell@umich.edu        context->setIntReg(x - RegG0, gdbregs.regs[x]);
2382SN/A    //Only the integer registers, pc and npc are set in netbsd
2392SN/A}
2402103SN/A
2412103SN/Avoid
2422103SN/ARemoteGDB::clearSingleStep()
2432103SN/A{
2442103SN/A   if (nextBkpt)
2457784SAli.Saidi@ARM.com       clearTempBreakpoint(nextBkpt);
246512SN/A}
247512SN/A
248725SN/Avoid
2492296SN/ARemoteGDB::setSingleStep()
2502336SN/A{
2512312SN/A    nextBkpt = context->pcState().npc();
2524828Sgblack@eecs.umich.edu    setTempBreakpoint(nextBkpt);
2534539Sgblack@eecs.umich.edu}
2544539Sgblack@eecs.umich.edu