18544Sguodeyuan@tsinghua.org.cn/*
211274Sshingarov@labware.com * Copyright 2015 LabWare
310595Sgabeblack@google.com * Copyright 2014 Google, Inc.
48544Sguodeyuan@tsinghua.org.cn * Copyright (c) 2010 ARM Limited
58544Sguodeyuan@tsinghua.org.cn * All rights reserved
68544Sguodeyuan@tsinghua.org.cn *
78544Sguodeyuan@tsinghua.org.cn * The license below extends only to copyright in the software and shall
88544Sguodeyuan@tsinghua.org.cn * not be construed as granting a license to any other intellectual
98544Sguodeyuan@tsinghua.org.cn * property including but not limited to intellectual property relating
108544Sguodeyuan@tsinghua.org.cn * to a hardware implementation of the functionality of the software
118544Sguodeyuan@tsinghua.org.cn * licensed hereunder.  You may use the software subject to the license
128544Sguodeyuan@tsinghua.org.cn * terms below provided that you ensure that this notice is replicated
138544Sguodeyuan@tsinghua.org.cn * unmodified and in its entirety in all distributions of the software,
148544Sguodeyuan@tsinghua.org.cn * modified or unmodified, in source code or in binary form.
158544Sguodeyuan@tsinghua.org.cn *
168544Sguodeyuan@tsinghua.org.cn * Copyright (c) 2002-2005 The Regents of The University of Michigan
178544Sguodeyuan@tsinghua.org.cn * All rights reserved.
188544Sguodeyuan@tsinghua.org.cn *
198544Sguodeyuan@tsinghua.org.cn * Redistribution and use in source and binary forms, with or without
208544Sguodeyuan@tsinghua.org.cn * modification, are permitted provided that the following conditions are
218544Sguodeyuan@tsinghua.org.cn * met: redistributions of source code must retain the above copyright
228544Sguodeyuan@tsinghua.org.cn * notice, this list of conditions and the following disclaimer;
238544Sguodeyuan@tsinghua.org.cn * redistributions in binary form must reproduce the above copyright
248544Sguodeyuan@tsinghua.org.cn * notice, this list of conditions and the following disclaimer in the
258544Sguodeyuan@tsinghua.org.cn * documentation and/or other materials provided with the distribution;
268544Sguodeyuan@tsinghua.org.cn * neither the name of the copyright holders nor the names of its
278544Sguodeyuan@tsinghua.org.cn * contributors may be used to endorse or promote products derived from
288544Sguodeyuan@tsinghua.org.cn * this software without specific prior written permission.
298544Sguodeyuan@tsinghua.org.cn *
308544Sguodeyuan@tsinghua.org.cn * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
318544Sguodeyuan@tsinghua.org.cn * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
328544Sguodeyuan@tsinghua.org.cn * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
338544Sguodeyuan@tsinghua.org.cn * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
348544Sguodeyuan@tsinghua.org.cn * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
358544Sguodeyuan@tsinghua.org.cn * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
368544Sguodeyuan@tsinghua.org.cn * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
378544Sguodeyuan@tsinghua.org.cn * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
388544Sguodeyuan@tsinghua.org.cn * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
398544Sguodeyuan@tsinghua.org.cn * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
408544Sguodeyuan@tsinghua.org.cn * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
418544Sguodeyuan@tsinghua.org.cn *
428544Sguodeyuan@tsinghua.org.cn * Authors: Nathan Binkert
438544Sguodeyuan@tsinghua.org.cn *          William Wang
448544Sguodeyuan@tsinghua.org.cn *          Deyuan Guo
4511274Sshingarov@labware.com *          Boris Shingarov
468544Sguodeyuan@tsinghua.org.cn */
478544Sguodeyuan@tsinghua.org.cn
488544Sguodeyuan@tsinghua.org.cn/*
498544Sguodeyuan@tsinghua.org.cn * Copyright (c) 1990, 1993 The Regents of the University of California
508544Sguodeyuan@tsinghua.org.cn * All rights reserved
518544Sguodeyuan@tsinghua.org.cn *
528544Sguodeyuan@tsinghua.org.cn * This software was developed by the Computer Systems Engineering group
538544Sguodeyuan@tsinghua.org.cn * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
548544Sguodeyuan@tsinghua.org.cn * contributed to Berkeley.
558544Sguodeyuan@tsinghua.org.cn *
568544Sguodeyuan@tsinghua.org.cn * All advertising materials mentioning features or use of this software
578544Sguodeyuan@tsinghua.org.cn * must display the following acknowledgement:
588544Sguodeyuan@tsinghua.org.cn *      This product includes software developed by the University of
598544Sguodeyuan@tsinghua.org.cn *      California, Lawrence Berkeley Laboratories.
608544Sguodeyuan@tsinghua.org.cn *
618544Sguodeyuan@tsinghua.org.cn * Redistribution and use in source and binary forms, with or without
628544Sguodeyuan@tsinghua.org.cn * modification, are permitted provided that the following conditions
638544Sguodeyuan@tsinghua.org.cn * are met:
648544Sguodeyuan@tsinghua.org.cn * 1. Redistributions of source code must retain the above copyright
658544Sguodeyuan@tsinghua.org.cn *    notice, this list of conditions and the following disclaimer.
668544Sguodeyuan@tsinghua.org.cn * 2. Redistributions in binary form must reproduce the above copyright
678544Sguodeyuan@tsinghua.org.cn *    notice, this list of conditions and the following disclaimer in the
688544Sguodeyuan@tsinghua.org.cn *    documentation and/or other materials provided with the distribution.
698544Sguodeyuan@tsinghua.org.cn * 3. All advertising materials mentioning features or use of this software
708544Sguodeyuan@tsinghua.org.cn *    must display the following acknowledgement:
718544Sguodeyuan@tsinghua.org.cn *      This product includes software developed by the University of
728544Sguodeyuan@tsinghua.org.cn *      California, Berkeley and its contributors.
738544Sguodeyuan@tsinghua.org.cn * 4. Neither the name of the University nor the names of its contributors
748544Sguodeyuan@tsinghua.org.cn *    may be used to endorse or promote products derived from this software
758544Sguodeyuan@tsinghua.org.cn *    without specific prior written permission.
768544Sguodeyuan@tsinghua.org.cn *
778544Sguodeyuan@tsinghua.org.cn * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
788544Sguodeyuan@tsinghua.org.cn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
798544Sguodeyuan@tsinghua.org.cn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
808544Sguodeyuan@tsinghua.org.cn * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
818544Sguodeyuan@tsinghua.org.cn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
828544Sguodeyuan@tsinghua.org.cn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
838544Sguodeyuan@tsinghua.org.cn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
848544Sguodeyuan@tsinghua.org.cn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
858544Sguodeyuan@tsinghua.org.cn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
868544Sguodeyuan@tsinghua.org.cn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
878544Sguodeyuan@tsinghua.org.cn * SUCH DAMAGE.
888544Sguodeyuan@tsinghua.org.cn *
898544Sguodeyuan@tsinghua.org.cn *      @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
908544Sguodeyuan@tsinghua.org.cn */
918544Sguodeyuan@tsinghua.org.cn
928544Sguodeyuan@tsinghua.org.cn/*-
938544Sguodeyuan@tsinghua.org.cn * Copyright (c) 2001 The NetBSD Foundation, Inc.
948544Sguodeyuan@tsinghua.org.cn * All rights reserved.
958544Sguodeyuan@tsinghua.org.cn *
968544Sguodeyuan@tsinghua.org.cn * This code is derived from software contributed to The NetBSD Foundation
978544Sguodeyuan@tsinghua.org.cn * by Jason R. Thorpe.
988544Sguodeyuan@tsinghua.org.cn *
998544Sguodeyuan@tsinghua.org.cn * Redistribution and use in source and binary forms, with or without
1008544Sguodeyuan@tsinghua.org.cn * modification, are permitted provided that the following conditions
1018544Sguodeyuan@tsinghua.org.cn * are met:
1028544Sguodeyuan@tsinghua.org.cn * 1. Redistributions of source code must retain the above copyright
1038544Sguodeyuan@tsinghua.org.cn *    notice, this list of conditions and the following disclaimer.
1048544Sguodeyuan@tsinghua.org.cn * 2. Redistributions in binary form must reproduce the above copyright
1058544Sguodeyuan@tsinghua.org.cn *    notice, this list of conditions and the following disclaimer in the
1068544Sguodeyuan@tsinghua.org.cn *    documentation and/or other materials provided with the distribution.
1078544Sguodeyuan@tsinghua.org.cn * 3. All advertising materials mentioning features or use of this software
1088544Sguodeyuan@tsinghua.org.cn *    must display the following acknowledgement:
1098544Sguodeyuan@tsinghua.org.cn *      This product includes software developed by the NetBSD
1108544Sguodeyuan@tsinghua.org.cn *      Foundation, Inc. and its contributors.
1118544Sguodeyuan@tsinghua.org.cn * 4. Neither the name of The NetBSD Foundation nor the names of its
1128544Sguodeyuan@tsinghua.org.cn *    contributors may be used to endorse or promote products derived
1138544Sguodeyuan@tsinghua.org.cn *    from this software without specific prior written permission.
1148544Sguodeyuan@tsinghua.org.cn *
1158544Sguodeyuan@tsinghua.org.cn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1168544Sguodeyuan@tsinghua.org.cn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1178544Sguodeyuan@tsinghua.org.cn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1188544Sguodeyuan@tsinghua.org.cn * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1198544Sguodeyuan@tsinghua.org.cn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1208544Sguodeyuan@tsinghua.org.cn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1218544Sguodeyuan@tsinghua.org.cn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1228544Sguodeyuan@tsinghua.org.cn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1238544Sguodeyuan@tsinghua.org.cn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1248544Sguodeyuan@tsinghua.org.cn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1258544Sguodeyuan@tsinghua.org.cn * POSSIBILITY OF SUCH DAMAGE.
1268544Sguodeyuan@tsinghua.org.cn */
1278544Sguodeyuan@tsinghua.org.cn
1288544Sguodeyuan@tsinghua.org.cn/*
1298544Sguodeyuan@tsinghua.org.cn * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
1308544Sguodeyuan@tsinghua.org.cn *
1318544Sguodeyuan@tsinghua.org.cn * Taken from NetBSD
1328544Sguodeyuan@tsinghua.org.cn *
1338544Sguodeyuan@tsinghua.org.cn * "Stub" to allow remote cpu to debug over a serial line using gdb.
1348544Sguodeyuan@tsinghua.org.cn */
1358544Sguodeyuan@tsinghua.org.cn
13611793Sbrandon.potter@amd.com#include "arch/mips/remote_gdb.hh"
13711793Sbrandon.potter@amd.com
1388544Sguodeyuan@tsinghua.org.cn#include <sys/signal.h>
1398544Sguodeyuan@tsinghua.org.cn#include <unistd.h>
1408544Sguodeyuan@tsinghua.org.cn
1418544Sguodeyuan@tsinghua.org.cn#include <string>
1428544Sguodeyuan@tsinghua.org.cn
1439020Sgblack@eecs.umich.edu#include "arch/mips/decoder.hh"
1448544Sguodeyuan@tsinghua.org.cn#include "arch/mips/vtophys.hh"
1458544Sguodeyuan@tsinghua.org.cn#include "cpu/thread_state.hh"
1468544Sguodeyuan@tsinghua.org.cn#include "debug/GDBAcc.hh"
1478544Sguodeyuan@tsinghua.org.cn#include "debug/GDBMisc.hh"
1488544Sguodeyuan@tsinghua.org.cn#include "mem/page_table.hh"
1498775Sgblack@eecs.umich.edu#include "sim/full_system.hh"
1508544Sguodeyuan@tsinghua.org.cn
1518544Sguodeyuan@tsinghua.org.cnusing namespace std;
1528544Sguodeyuan@tsinghua.org.cnusing namespace MipsISA;
1538544Sguodeyuan@tsinghua.org.cn
15412449Sgabeblack@google.comRemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
15512449Sgabeblack@google.com    : BaseRemoteGDB(_system, tc, _port), regCache(this)
1568544Sguodeyuan@tsinghua.org.cn{
1578544Sguodeyuan@tsinghua.org.cn}
1588544Sguodeyuan@tsinghua.org.cn
1598544Sguodeyuan@tsinghua.org.cn/*
1608544Sguodeyuan@tsinghua.org.cn * Determine if the mapping at va..(va+len) is valid.
1618544Sguodeyuan@tsinghua.org.cn */
1628544Sguodeyuan@tsinghua.org.cnbool
1638544Sguodeyuan@tsinghua.org.cnRemoteGDB::acc(Addr va, size_t len)
1648544Sguodeyuan@tsinghua.org.cn{
16512455Sgabeblack@google.com    // Check to make sure the first byte is mapped into the processes address
16612455Sgabeblack@google.com    // space.
16712455Sgabeblack@google.com    panic_if(FullSystem, "acc not implemented for MIPS FS!");
16812455Sgabeblack@google.com    return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
1698544Sguodeyuan@tsinghua.org.cn}
1708544Sguodeyuan@tsinghua.org.cn
1718544Sguodeyuan@tsinghua.org.cnvoid
17211274Sshingarov@labware.comRemoteGDB::MipsGdbRegCache::getRegs(ThreadContext *context)
1738544Sguodeyuan@tsinghua.org.cn{
1748544Sguodeyuan@tsinghua.org.cn    DPRINTF(GDBAcc, "getregs in remotegdb \n");
1758544Sguodeyuan@tsinghua.org.cn
17611274Sshingarov@labware.com    for (int i = 0; i < 32; i++) r.gpr[i] = context->readIntReg(i);
17711274Sshingarov@labware.com    r.sr = context->readMiscRegNoEffect(MISCREG_STATUS);
17811274Sshingarov@labware.com    r.lo = context->readIntReg(INTREG_LO);
17911274Sshingarov@labware.com    r.hi = context->readIntReg(INTREG_HI);
18011274Sshingarov@labware.com    r.badvaddr = context->readMiscRegNoEffect(MISCREG_BADVADDR);
18111274Sshingarov@labware.com    r.cause = context->readMiscRegNoEffect(MISCREG_CAUSE);
18211274Sshingarov@labware.com    r.pc = context->pcState().pc();
18313611Sgabeblack@google.com    for (int i = 0; i < 32; i++) r.fpr[i] = context->readFloatReg(i);
18413611Sgabeblack@google.com    r.fsr = context->readFloatReg(FLOATREG_FCCR);
18513611Sgabeblack@google.com    r.fir = context->readFloatReg(FLOATREG_FIR);
1868544Sguodeyuan@tsinghua.org.cn}
1878544Sguodeyuan@tsinghua.org.cn
1888544Sguodeyuan@tsinghua.org.cnvoid
18911274Sshingarov@labware.comRemoteGDB::MipsGdbRegCache::setRegs(ThreadContext *context) const
1908544Sguodeyuan@tsinghua.org.cn{
1918544Sguodeyuan@tsinghua.org.cn    DPRINTF(GDBAcc, "setregs in remotegdb \n");
1928544Sguodeyuan@tsinghua.org.cn
19311274Sshingarov@labware.com    for (int i = 1; i < 32; i++) context->setIntReg(i, r.gpr[i]);
19411274Sshingarov@labware.com    context->setMiscRegNoEffect(MISCREG_STATUS, r.sr);
19511274Sshingarov@labware.com    context->setIntReg(INTREG_LO, r.lo);
19611274Sshingarov@labware.com    context->setIntReg(INTREG_HI, r.hi);
19711274Sshingarov@labware.com    context->setMiscRegNoEffect(MISCREG_BADVADDR, r.badvaddr);
19811274Sshingarov@labware.com    context->setMiscRegNoEffect(MISCREG_CAUSE, r.cause);
19911274Sshingarov@labware.com    context->pcState(r.pc);
20013611Sgabeblack@google.com    for (int i = 0; i < 32; i++) context->setFloatReg(i, r.fpr[i]);
20113611Sgabeblack@google.com    context->setFloatReg(FLOATREG_FCCR, r.fsr);
20213611Sgabeblack@google.com    context->setFloatReg(FLOATREG_FIR, r.fir);
2038544Sguodeyuan@tsinghua.org.cn}
20411274Sshingarov@labware.com
20512449Sgabeblack@google.comBaseGdbRegCache*
20612449Sgabeblack@google.comRemoteGDB::gdbRegs()
20712449Sgabeblack@google.com{
20812031Sgabeblack@google.com    return &regCache;
20911274Sshingarov@labware.com}
210