111723Sar4jc@virginia.edu/*
211963Sar4jc@virginia.edu * Copyright 2015 LabWare
311963Sar4jc@virginia.edu * Copyright 2014 Google, Inc.
411963Sar4jc@virginia.edu * Copyright (c) 2010 ARM Limited
511963Sar4jc@virginia.edu * All rights reserved
611963Sar4jc@virginia.edu *
711963Sar4jc@virginia.edu * The license below extends only to copyright in the software and shall
811963Sar4jc@virginia.edu * not be construed as granting a license to any other intellectual
911963Sar4jc@virginia.edu * property including but not limited to intellectual property relating
1011963Sar4jc@virginia.edu * to a hardware implementation of the functionality of the software
1111963Sar4jc@virginia.edu * licensed hereunder.  You may use the software subject to the license
1211963Sar4jc@virginia.edu * terms below provided that you ensure that this notice is replicated
1311963Sar4jc@virginia.edu * unmodified and in its entirety in all distributions of the software,
1411963Sar4jc@virginia.edu * modified or unmodified, in source code or in binary form.
1511963Sar4jc@virginia.edu *
1611963Sar4jc@virginia.edu * Copyright (c) 2017 The University of Virginia
1711723Sar4jc@virginia.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan
1811723Sar4jc@virginia.edu * All rights reserved.
1911723Sar4jc@virginia.edu *
2011723Sar4jc@virginia.edu * Redistribution and use in source and binary forms, with or without
2111723Sar4jc@virginia.edu * modification, are permitted provided that the following conditions are
2211723Sar4jc@virginia.edu * met: redistributions of source code must retain the above copyright
2311723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer;
2411723Sar4jc@virginia.edu * redistributions in binary form must reproduce the above copyright
2511723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer in the
2611723Sar4jc@virginia.edu * documentation and/or other materials provided with the distribution;
2711723Sar4jc@virginia.edu * neither the name of the copyright holders nor the names of its
2811723Sar4jc@virginia.edu * contributors may be used to endorse or promote products derived from
2911723Sar4jc@virginia.edu * this software without specific prior written permission.
3011723Sar4jc@virginia.edu *
3111723Sar4jc@virginia.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3211723Sar4jc@virginia.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3311723Sar4jc@virginia.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3411723Sar4jc@virginia.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3511723Sar4jc@virginia.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3611723Sar4jc@virginia.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3711723Sar4jc@virginia.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3811723Sar4jc@virginia.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3911723Sar4jc@virginia.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4011723Sar4jc@virginia.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4111723Sar4jc@virginia.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4211723Sar4jc@virginia.edu *
4311723Sar4jc@virginia.edu * Authors: Nathan Binkert
4411963Sar4jc@virginia.edu *          William Wang
4511963Sar4jc@virginia.edu *          Deyuan Guo
4611963Sar4jc@virginia.edu *          Boris Shingarov
4711963Sar4jc@virginia.edu *          Alec Roelke
4811723Sar4jc@virginia.edu */
4911723Sar4jc@virginia.edu
5011963Sar4jc@virginia.edu/*
5111963Sar4jc@virginia.edu * Copyright (c) 1990, 1993 The Regents of the University of California
5211963Sar4jc@virginia.edu * All rights reserved
5311963Sar4jc@virginia.edu *
5411963Sar4jc@virginia.edu * This software was developed by the Computer Systems Engineering group
5511963Sar4jc@virginia.edu * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
5611963Sar4jc@virginia.edu * contributed to Berkeley.
5711963Sar4jc@virginia.edu *
5811963Sar4jc@virginia.edu * All advertising materials mentioning features or use of this software
5911963Sar4jc@virginia.edu * must display the following acknowledgement:
6011963Sar4jc@virginia.edu *      This product includes software developed by the University of
6111963Sar4jc@virginia.edu *      California, Lawrence Berkeley Laboratories.
6211963Sar4jc@virginia.edu *
6311963Sar4jc@virginia.edu * Redistribution and use in source and binary forms, with or without
6411963Sar4jc@virginia.edu * modification, are permitted provided that the following conditions
6511963Sar4jc@virginia.edu * are met:
6611963Sar4jc@virginia.edu * 1. Redistributions of source code must retain the above copyright
6711963Sar4jc@virginia.edu *    notice, this list of conditions and the following disclaimer.
6811963Sar4jc@virginia.edu * 2. Redistributions in binary form must reproduce the above copyright
6911963Sar4jc@virginia.edu *    notice, this list of conditions and the following disclaimer in the
7011963Sar4jc@virginia.edu *    documentation and/or other materials provided with the distribution.
7111963Sar4jc@virginia.edu * 3. All advertising materials mentioning features or use of this software
7211963Sar4jc@virginia.edu *    must display the following acknowledgement:
7311963Sar4jc@virginia.edu *      This product includes software developed by the University of
7411963Sar4jc@virginia.edu *      California, Berkeley and its contributors.
7511963Sar4jc@virginia.edu * 4. Neither the name of the University nor the names of its contributors
7611963Sar4jc@virginia.edu *    may be used to endorse or promote products derived from this software
7711963Sar4jc@virginia.edu *    without specific prior written permission.
7811963Sar4jc@virginia.edu *
7911963Sar4jc@virginia.edu * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
8011963Sar4jc@virginia.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8111963Sar4jc@virginia.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8211963Sar4jc@virginia.edu * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
8311963Sar4jc@virginia.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
8411963Sar4jc@virginia.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8511963Sar4jc@virginia.edu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8611963Sar4jc@virginia.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
8711963Sar4jc@virginia.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
8811963Sar4jc@virginia.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
8911963Sar4jc@virginia.edu * SUCH DAMAGE.
9011963Sar4jc@virginia.edu *
9111963Sar4jc@virginia.edu *      @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
9211963Sar4jc@virginia.edu */
9311963Sar4jc@virginia.edu
9411963Sar4jc@virginia.edu/*-
9511963Sar4jc@virginia.edu * Copyright (c) 2001 The NetBSD Foundation, Inc.
9611963Sar4jc@virginia.edu * All rights reserved.
9711963Sar4jc@virginia.edu *
9811963Sar4jc@virginia.edu * This code is derived from software contributed to The NetBSD Foundation
9911963Sar4jc@virginia.edu * by Jason R. Thorpe.
10011963Sar4jc@virginia.edu *
10111963Sar4jc@virginia.edu * Redistribution and use in source and binary forms, with or without
10211963Sar4jc@virginia.edu * modification, are permitted provided that the following conditions
10311963Sar4jc@virginia.edu * are met:
10411963Sar4jc@virginia.edu * 1. Redistributions of source code must retain the above copyright
10511963Sar4jc@virginia.edu *    notice, this list of conditions and the following disclaimer.
10611963Sar4jc@virginia.edu * 2. Redistributions in binary form must reproduce the above copyright
10711963Sar4jc@virginia.edu *    notice, this list of conditions and the following disclaimer in the
10811963Sar4jc@virginia.edu *    documentation and/or other materials provided with the distribution.
10911963Sar4jc@virginia.edu * 3. All advertising materials mentioning features or use of this software
11011963Sar4jc@virginia.edu *    must display the following acknowledgement:
11111963Sar4jc@virginia.edu *      This product includes software developed by the NetBSD
11211963Sar4jc@virginia.edu *      Foundation, Inc. and its contributors.
11311963Sar4jc@virginia.edu * 4. Neither the name of The NetBSD Foundation nor the names of its
11411963Sar4jc@virginia.edu *    contributors may be used to endorse or promote products derived
11511963Sar4jc@virginia.edu *    from this software without specific prior written permission.
11611963Sar4jc@virginia.edu *
11711963Sar4jc@virginia.edu * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
11811963Sar4jc@virginia.edu * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
11911963Sar4jc@virginia.edu * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12011963Sar4jc@virginia.edu * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
12111963Sar4jc@virginia.edu * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
12211963Sar4jc@virginia.edu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
12311963Sar4jc@virginia.edu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
12411963Sar4jc@virginia.edu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
12511963Sar4jc@virginia.edu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
12611963Sar4jc@virginia.edu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
12711963Sar4jc@virginia.edu * POSSIBILITY OF SUCH DAMAGE.
12811963Sar4jc@virginia.edu */
12911963Sar4jc@virginia.edu
13011963Sar4jc@virginia.edu/*
13111963Sar4jc@virginia.edu * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
13211963Sar4jc@virginia.edu *
13311963Sar4jc@virginia.edu * Taken from NetBSD
13411963Sar4jc@virginia.edu *
13511963Sar4jc@virginia.edu * "Stub" to allow remote cpu to debug over a serial line using gdb.
13611963Sar4jc@virginia.edu */
13711963Sar4jc@virginia.edu
13811963Sar4jc@virginia.edu#include "arch/riscv/remote_gdb.hh"
13911963Sar4jc@virginia.edu
14011963Sar4jc@virginia.edu#include <string>
14111963Sar4jc@virginia.edu
14211963Sar4jc@virginia.edu#include "arch/riscv/registers.hh"
14311963Sar4jc@virginia.edu#include "cpu/thread_state.hh"
14411963Sar4jc@virginia.edu#include "debug/GDBAcc.hh"
14511963Sar4jc@virginia.edu#include "mem/page_table.hh"
14611963Sar4jc@virginia.edu#include "sim/full_system.hh"
14711723Sar4jc@virginia.edu
14811723Sar4jc@virginia.eduusing namespace std;
14911723Sar4jc@virginia.eduusing namespace RiscvISA;
15011723Sar4jc@virginia.edu
15112449Sgabeblack@google.comRemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port)
15212449Sgabeblack@google.com    : BaseRemoteGDB(_system, tc, _port), regCache(this)
15311723Sar4jc@virginia.edu{
15411723Sar4jc@virginia.edu}
15511723Sar4jc@virginia.edu
15611963Sar4jc@virginia.edubool
15711963Sar4jc@virginia.eduRemoteGDB::acc(Addr va, size_t len)
15811723Sar4jc@virginia.edu{
15912455Sgabeblack@google.com    panic_if(FullSystem, "acc not implemented for RISCV FS!");
16012455Sgabeblack@google.com    return context()->getProcessPtr()->pTable->lookup(va) != nullptr;
16111723Sar4jc@virginia.edu}
16211723Sar4jc@virginia.edu
16311723Sar4jc@virginia.eduvoid
16411963Sar4jc@virginia.eduRemoteGDB::RiscvGdbRegCache::getRegs(ThreadContext *context)
16511723Sar4jc@virginia.edu{
16611963Sar4jc@virginia.edu    DPRINTF(GDBAcc, "getregs in remotegdb, size %lu\n", size());
16711963Sar4jc@virginia.edu    for (int i = 0; i < NumIntArchRegs; i++)
16811963Sar4jc@virginia.edu        r.gpr[i] = context->readIntReg(i);
16911963Sar4jc@virginia.edu    r.pc = context->pcState().pc();
17011723Sar4jc@virginia.edu}
17111723Sar4jc@virginia.edu
17211723Sar4jc@virginia.eduvoid
17311963Sar4jc@virginia.eduRemoteGDB::RiscvGdbRegCache::setRegs(ThreadContext *context) const
17411723Sar4jc@virginia.edu{
17511963Sar4jc@virginia.edu    DPRINTF(GDBAcc, "setregs in remotegdb \n");
17611963Sar4jc@virginia.edu    for (int i = 0; i < NumIntArchRegs; i++)
17711963Sar4jc@virginia.edu        context->setIntReg(i, r.gpr[i]);
17811963Sar4jc@virginia.edu    context->pcState(r.pc);
17911723Sar4jc@virginia.edu}
18011963Sar4jc@virginia.edu
18112449Sgabeblack@google.comBaseGdbRegCache*
18212449Sgabeblack@google.comRemoteGDB::gdbRegs()
18312449Sgabeblack@google.com{
18412031Sgabeblack@google.com    return &regCache;
18511963Sar4jc@virginia.edu}
186