Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 1 | /* |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 2 | * Copyright 2015 LabWare |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 3 | * Copyright 2014 Google, Inc. |
| 4 | * Copyright (c) 2010 ARM Limited |
| 5 | * All rights reserved |
| 6 | * |
| 7 | * The license below extends only to copyright in the software and shall |
| 8 | * not be construed as granting a license to any other intellectual |
| 9 | * property including but not limited to intellectual property relating |
| 10 | * to a hardware implementation of the functionality of the software |
| 11 | * licensed hereunder. You may use the software subject to the license |
| 12 | * terms below provided that you ensure that this notice is replicated |
| 13 | * unmodified and in its entirety in all distributions of the software, |
| 14 | * modified or unmodified, in source code or in binary form. |
| 15 | * |
| 16 | * Copyright (c) 2002-2005 The Regents of The University of Michigan |
| 17 | * All rights reserved. |
| 18 | * |
| 19 | * Redistribution and use in source and binary forms, with or without |
| 20 | * modification, are permitted provided that the following conditions are |
| 21 | * met: redistributions of source code must retain the above copyright |
| 22 | * notice, this list of conditions and the following disclaimer; |
| 23 | * redistributions in binary form must reproduce the above copyright |
| 24 | * notice, this list of conditions and the following disclaimer in the |
| 25 | * documentation and/or other materials provided with the distribution; |
| 26 | * neither the name of the copyright holders nor the names of its |
| 27 | * contributors may be used to endorse or promote products derived from |
| 28 | * this software without specific prior written permission. |
| 29 | * |
| 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 33 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 34 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 36 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 37 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 38 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 41 | * |
| 42 | * Authors: Nathan Binkert |
| 43 | * William Wang |
| 44 | * Deyuan Guo |
| 45 | * Boris Shingarov |
| 46 | */ |
| 47 | |
| 48 | /* |
| 49 | * Copyright (c) 1990, 1993 The Regents of the University of California |
| 50 | * All rights reserved |
| 51 | * |
| 52 | * This software was developed by the Computer Systems Engineering group |
| 53 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and |
| 54 | * contributed to Berkeley. |
| 55 | * |
| 56 | * All advertising materials mentioning features or use of this software |
| 57 | * must display the following acknowledgement: |
| 58 | * This product includes software developed by the University of |
| 59 | * California, Lawrence Berkeley Laboratories. |
| 60 | * |
| 61 | * Redistribution and use in source and binary forms, with or without |
| 62 | * modification, are permitted provided that the following conditions |
| 63 | * are met: |
| 64 | * 1. Redistributions of source code must retain the above copyright |
| 65 | * notice, this list of conditions and the following disclaimer. |
| 66 | * 2. Redistributions in binary form must reproduce the above copyright |
| 67 | * notice, this list of conditions and the following disclaimer in the |
| 68 | * documentation and/or other materials provided with the distribution. |
| 69 | * 3. All advertising materials mentioning features or use of this software |
| 70 | * must display the following acknowledgement: |
| 71 | * This product includes software developed by the University of |
| 72 | * California, Berkeley and its contributors. |
| 73 | * 4. Neither the name of the University nor the names of its contributors |
| 74 | * may be used to endorse or promote products derived from this software |
| 75 | * without specific prior written permission. |
| 76 | * |
| 77 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 78 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 79 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 80 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 81 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 82 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 83 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 84 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 85 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 86 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 87 | * SUCH DAMAGE. |
| 88 | * |
| 89 | * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 |
| 90 | */ |
| 91 | |
| 92 | /*- |
| 93 | * Copyright (c) 2001 The NetBSD Foundation, Inc. |
| 94 | * All rights reserved. |
| 95 | * |
| 96 | * This code is derived from software contributed to The NetBSD Foundation |
| 97 | * by Jason R. Thorpe. |
| 98 | * |
| 99 | * Redistribution and use in source and binary forms, with or without |
| 100 | * modification, are permitted provided that the following conditions |
| 101 | * are met: |
| 102 | * 1. Redistributions of source code must retain the above copyright |
| 103 | * notice, this list of conditions and the following disclaimer. |
| 104 | * 2. Redistributions in binary form must reproduce the above copyright |
| 105 | * notice, this list of conditions and the following disclaimer in the |
| 106 | * documentation and/or other materials provided with the distribution. |
| 107 | * 3. All advertising materials mentioning features or use of this software |
| 108 | * must display the following acknowledgement: |
| 109 | * This product includes software developed by the NetBSD |
| 110 | * Foundation, Inc. and its contributors. |
| 111 | * 4. Neither the name of The NetBSD Foundation nor the names of its |
| 112 | * contributors may be used to endorse or promote products derived |
| 113 | * from this software without specific prior written permission. |
| 114 | * |
| 115 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
| 116 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 117 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 118 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
| 119 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 120 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 121 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 122 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 123 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 124 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 125 | * POSSIBILITY OF SUCH DAMAGE. |
| 126 | */ |
| 127 | |
| 128 | /* |
| 129 | * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $ |
| 130 | * |
| 131 | * Taken from NetBSD |
| 132 | * |
| 133 | * "Stub" to allow remote cpu to debug over a serial line using gdb. |
| 134 | */ |
| 135 | |
Brandon Potter | a928a43 | 2016-11-09 14:27:40 -0600 | [diff] [blame] | 136 | |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 137 | #include "arch/power/remote_gdb.hh" |
| 138 | |
| 139 | #include <sys/signal.h> |
| 140 | #include <unistd.h> |
| 141 | |
| 142 | #include <string> |
| 143 | |
| 144 | #include "arch/power/vtophys.hh" |
| 145 | #include "cpu/thread_state.hh" |
| 146 | #include "debug/GDBAcc.hh" |
| 147 | #include "debug/GDBMisc.hh" |
Brandon Potter | a928a43 | 2016-11-09 14:27:40 -0600 | [diff] [blame] | 148 | #include "mem/page_table.hh" |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 149 | #include "sim/byteswap.hh" |
| 150 | |
| 151 | using namespace std; |
| 152 | using namespace PowerISA; |
| 153 | |
Gabe Black | ecec887 | 2018-01-16 01:25:39 -0800 | [diff] [blame] | 154 | RemoteGDB::RemoteGDB(System *_system, ThreadContext *tc, int _port) |
| 155 | : BaseRemoteGDB(_system, tc, _port), regCache(this) |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 156 | { |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * Determine if the mapping at va..(va+len) is valid. |
| 161 | */ |
| 162 | bool |
| 163 | RemoteGDB::acc(Addr va, size_t len) |
| 164 | { |
Gabe Black | 2a15bfd | 2018-01-05 15:01:00 -0800 | [diff] [blame] | 165 | // Check to make sure the first byte is mapped into the processes address |
| 166 | // space. At the time of this writing, the acc() check is used when |
| 167 | // processing the MemR/MemW packets before actually asking the translating |
| 168 | // port proxy to read/writeBlob. I (bgs) am not convinced the first byte |
| 169 | // check is enough. |
| 170 | panic_if(FullSystem, "acc not implemented for POWER FS!"); |
| 171 | return context()->getProcessPtr()->pTable->lookup(va) != nullptr; |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 174 | void |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 175 | RemoteGDB::PowerGdbRegCache::getRegs(ThreadContext *context) |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 176 | { |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 177 | DPRINTF(GDBAcc, "getRegs in remotegdb \n"); |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 178 | |
| 179 | // Default order on 32-bit PowerPC: |
| 180 | // R0-R31 (32-bit each), F0-F31 (64-bit IEEE754 double), |
| 181 | // PC, MSR, CR, LR, CTR, XER (32-bit each) |
| 182 | |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 183 | for (int i = 0; i < NumIntArchRegs; i++) |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 184 | r.gpr[i] = htobe((uint32_t)context->readIntReg(i)); |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 185 | |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 186 | for (int i = 0; i < NumFloatArchRegs; i++) |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 187 | r.fpr[i] = context->readFloatRegBits(i); |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 188 | |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 189 | r.pc = htobe((uint32_t)context->pcState().pc()); |
| 190 | r.msr = 0; // Is MSR modeled? |
| 191 | r.cr = htobe((uint32_t)context->readIntReg(INTREG_CR)); |
| 192 | r.lr = htobe((uint32_t)context->readIntReg(INTREG_LR)); |
| 193 | r.ctr = htobe((uint32_t)context->readIntReg(INTREG_CTR)); |
| 194 | r.xer = htobe((uint32_t)context->readIntReg(INTREG_XER)); |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 197 | void |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 198 | RemoteGDB::PowerGdbRegCache::setRegs(ThreadContext *context) const |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 199 | { |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 200 | DPRINTF(GDBAcc, "setRegs in remotegdb \n"); |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 201 | |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 202 | for (int i = 0; i < NumIntArchRegs; i++) |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 203 | context->setIntReg(i, betoh(r.gpr[i])); |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 204 | |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 205 | for (int i = 0; i < NumFloatArchRegs; i++) |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 206 | context->setFloatRegBits(i, r.fpr[i]); |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 207 | |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 208 | context->pcState(betoh(r.pc)); |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 209 | // Is MSR modeled? |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 210 | context->setIntReg(INTREG_CR, betoh(r.cr)); |
| 211 | context->setIntReg(INTREG_LR, betoh(r.lr)); |
| 212 | context->setIntReg(INTREG_CTR, betoh(r.ctr)); |
| 213 | context->setIntReg(INTREG_XER, betoh(r.xer)); |
Boris Shingarov | 58cb57b | 2015-10-25 16:01:52 -0700 | [diff] [blame] | 214 | } |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 215 | |
Gabe Black | ecec887 | 2018-01-16 01:25:39 -0800 | [diff] [blame] | 216 | BaseGdbRegCache* |
| 217 | RemoteGDB::gdbRegs() |
| 218 | { |
Gabe Black | 41ab3e6 | 2017-05-11 14:11:28 -0700 | [diff] [blame] | 219 | return ®Cache; |
Boris Shingarov | d765dbf | 2015-12-18 15:12:07 -0600 | [diff] [blame] | 220 | } |
| 221 | |