POWER: Add support for the Power ISA
[gem5.git] / src / arch / sparc / remote_gdb.cc
index c76f8b820646400dc2a44458fca33831f401d75f..615c5b55168da8d6424b2bc4394fb7da892e64cb 100644 (file)
@@ -30,7 +30,7 @@
 
 /*
  * Copyright (c) 1990, 1993
- *     The Regents of the University of California.  All rights reserved.
+ *      The Regents of the University of California.  All rights reserved.
  *
  * This software was developed by the Computer Systems Engineering group
  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
@@ -38,8 +38,8 @@
  *
  * All advertising materials mentioning features or use of this software
  * must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Lawrence Berkeley Laboratories.
+ *      This product includes software developed by the University of
+ *      California, Lawrence Berkeley Laboratories.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -51,8 +51,8 @@
  *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software
  *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
+ *      This product includes software developed by the University of
+ *      California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -69,7 +69,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
+ *      @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
  */
 
 /*-
@@ -89,8 +89,8 @@
  *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software
  *    must display the following acknowledgement:
- *     This product includes software developed by the NetBSD
- *     Foundation, Inc. and its contributors.
+ *      This product includes software developed by the NetBSD
+ *      Foundation, Inc. and its contributors.
  * 4. Neither the name of The NetBSD Foundation nor the names of its
  *    contributors may be used to endorse or promote products derived
  *    from this software without specific prior written permission.
 #include "config/full_system.hh"
 #include "cpu/thread_context.hh"
 #include "cpu/static_inst.hh"
+#include "mem/page_table.hh"
 #include "mem/physical.hh"
 #include "mem/port.hh"
+#include "sim/process.hh"
 #include "sim/system.hh"
 
 using namespace std;
-using namespace TheISA;
+using namespace SparcISA;
 
 RemoteGDB::RemoteGDB(System *_system, ThreadContext *c)
-    : BaseRemoteGDB(_system, c, NumGDBRegs)
+    : BaseRemoteGDB(_system, c, NumGDBRegs), nextBkpt(0)
 {}
 
 ///////////////////////////////////////////////////////////
 // RemoteGDB::acc
 //
-//     Determine if the mapping at va..(va+len) is valid.
+//      Determine if the mapping at va..(va+len) is valid.
 //
 bool
 RemoteGDB::acc(Addr va, size_t len)
 {
     //@Todo In NetBSD, this function checks if all addresses
-    //from va to va + len have valid page mape entries. Not
+    //from va to va + len have valid page map entries. Not
     //sure how this will work for other OSes or in general.
-    return true;
+#if FULL_SYSTEM
+    if (va)
+        return true;
+    return false;
+#else
+    TlbEntry entry;
+    //Check to make sure the first byte is mapped into the processes address
+    //space.
+    if (context->getProcessPtr()->pTable->lookup(va, entry))
+        return true;
+    return false;
+#endif
 }
 
 ///////////////////////////////////////////////////////////
 // RemoteGDB::getregs
 //
-//     Translate the kernel debugger register format into
-//     the GDB register format.
+//      Translate the kernel debugger register format into
+//      the GDB register format.
 void
 RemoteGDB::getregs()
 {
     memset(gdbregs.regs, 0, gdbregs.size);
 
-    gdbregs.regs[RegPc] = context->readPC();
-    gdbregs.regs[RegNpc] = context->readNextPC();
-    for(int x = RegG0; x <= RegI0 + 7; x++)
-        gdbregs.regs[x] = context->readIntReg(x - RegG0);
+    if (context->readMiscReg(MISCREG_PSTATE) &
+           PSTATE::am) {
+        uint32_t *regs;
+        regs = (uint32_t*)gdbregs.regs;
+        regs[Reg32Pc] = htobe((uint32_t)context->readPC());
+        regs[Reg32Npc] = htobe((uint32_t)context->readNextPC());
+        for(int x = RegG0; x <= RegI0 + 7; x++)
+            regs[x] = htobe((uint32_t)context->readIntReg(x - RegG0));
+
+        regs[Reg32Y] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 1));
+        regs[Reg32Psr] = htobe((uint32_t)context->readMiscReg(MISCREG_PSTATE));
+        regs[Reg32Fsr] = htobe((uint32_t)context->readMiscReg(MISCREG_FSR));
+        regs[Reg32Csr] = htobe((uint32_t)context->readIntReg(NumIntArchRegs + 2));
+    } else {
+        gdbregs.regs[RegPc] = htobe(context->readPC());
+        gdbregs.regs[RegNpc] = htobe(context->readNextPC());
+        for(int x = RegG0; x <= RegI0 + 7; x++)
+            gdbregs.regs[x] = htobe(context->readIntReg(x - RegG0));
+
+        gdbregs.regs[RegFsr] = htobe(context->readMiscReg(MISCREG_FSR));
+        gdbregs.regs[RegFprs] = htobe(context->readMiscReg(MISCREG_FPRS));
+        gdbregs.regs[RegY] = htobe(context->readIntReg(NumIntArchRegs + 1));
+        gdbregs.regs[RegState] = htobe(
+            context->readMiscReg(MISCREG_CWP) |
+            context->readMiscReg(MISCREG_PSTATE) << 8 |
+            context->readMiscReg(MISCREG_ASI) << 24 |
+            context->readIntReg(NumIntArchRegs + 2) << 32);
+    }
+
+    DPRINTF(GDBRead, "PC=%#x\n", gdbregs.regs[RegPc]);
+
     //Floating point registers are left at 0 in netbsd
     //All registers other than the pc, npc and int regs
     //are ignored as well.
@@ -177,8 +217,8 @@ RemoteGDB::getregs()
 ///////////////////////////////////////////////////////////
 // RemoteGDB::setregs
 //
-//     Translate the GDB register format into the kernel
-//     debugger register format.
+//      Translate the GDB register format into the kernel
+//      debugger register format.
 //
 void
 RemoteGDB::setregs()
@@ -193,11 +233,13 @@ RemoteGDB::setregs()
 void
 RemoteGDB::clearSingleStep()
 {
-    panic("SPARC does not support hardware single stepping\n");
+   if (nextBkpt)
+       clearTempBreakpoint(nextBkpt);
 }
 
 void
 RemoteGDB::setSingleStep()
 {
-    panic("SPARC does not support hardware single stepping\n");
+    nextBkpt = context->readNextPC();
+    setTempBreakpoint(nextBkpt);
 }