[Vm-dev] [commit][3027] Improve the GdbARMPlugin.

commits at squeakvm.org commits at squeakvm.org
Thu Jul 3 00:26:28 UTC 2014


Revision: 3027
Author:   rowledge
Date:     2014-07-02 17:26:26 -0700 (Wed, 02 Jul 2014)
Log Message:
-----------
Improve the GdbARMPlugin.
Add support for separate read & write error notifications to the VM sim.
Fix problem with loading bytes - the lower code was happily fetching 
the word at 0xXXXX3 and then assorted shifts & masks provided completely the 
wrong byte...
Makefile changes - and more needed to be properly clean
Pay attention to early comment in sqGdbARMPlugin.c about link to config.h

Modified Paths:
--------------
    trunk/platforms/Cross/plugins/GdbARMPlugin/GdbARMPlugin.h
    trunk/platforms/Cross/plugins/GdbARMPlugin/Makefile
    trunk/platforms/Cross/plugins/GdbARMPlugin/Makefile.unix
    trunk/platforms/Cross/plugins/GdbARMPlugin/armulmem.c
    trunk/platforms/Cross/plugins/GdbARMPlugin/sqGdbARMPlugin.c

Modified: trunk/platforms/Cross/plugins/GdbARMPlugin/GdbARMPlugin.h
===================================================================
--- trunk/platforms/Cross/plugins/GdbARMPlugin/GdbARMPlugin.h	2014-07-02 22:44:11 UTC (rev 3026)
+++ trunk/platforms/Cross/plugins/GdbARMPlugin/GdbARMPlugin.h	2014-07-03 00:26:26 UTC (rev 3027)
@@ -2,15 +2,19 @@
 /* Bochs seems to use error code 1 for execution errors.
  * So we use > 1 for various errors
  */
+
+/* TPR - added MemoryWriteBoundsError */
 #define NoError 0
 #define ExecutionError 1
 #define BadCPUInstance 2
-#define MemoryBoundsError 3
-#define PanicError 4
-#define UnsupportedOperationError 5
-#define SomethingLoggedError 6
+#define MemoryLoadBoundsError 3
+#define MemoryWriteBoundsError 4
+#define InstructionPrefetchError 5
+#define PanicError 6
+#define UnsupportedOperationError 7
+#define SomethingLoggedError 8
 
-// The library is compiled with TFlag, therefore, we also need to set it.
+// TPR - The library is compiled with TFlag, therefore, we also need to set it.
 #define MODET
 
 #if !defined(ulong)

Modified: trunk/platforms/Cross/plugins/GdbARMPlugin/Makefile
===================================================================
--- trunk/platforms/Cross/plugins/GdbARMPlugin/Makefile	2014-07-02 22:44:11 UTC (rev 3026)
+++ trunk/platforms/Cross/plugins/GdbARMPlugin/Makefile	2014-07-03 00:26:26 UTC (rev 3027)
@@ -1,4 +1,6 @@
-GDBBUILDFOLDER = /d/build/gdb-7.4
+# edit this to suit your system; it really ought to use relative paths
+# or some other convenience
+GDBBUILDFOLDER = /home/tim/Documents/Raspbian-Cog/gdb-arm/gdb-7.6
 
 CC      = gcc
 CFLAGS  = -I$(GBDBUILDFOLDER)/bfd 

Modified: trunk/platforms/Cross/plugins/GdbARMPlugin/Makefile.unix
===================================================================
--- trunk/platforms/Cross/plugins/GdbARMPlugin/Makefile.unix	2014-07-02 22:44:11 UTC (rev 3026)
+++ trunk/platforms/Cross/plugins/GdbARMPlugin/Makefile.unix	2014-07-03 00:26:26 UTC (rev 3027)
@@ -1,4 +1,6 @@
-GDBBUILDFOLDER	= $(topdir)/../gdb
+# edit this to suit your system; it really ought to use relative paths
+# or some other convenience
+GDBBUILDFOLDER	= /home/tim/Documents/Raspbian-Cog/gdb-arm/gdb-7.6
 XCFLAGS		= -m32 -DNEED_UI_LOOP_HOOK
 
 XINCLUDES	+= -I$(GDBBUILDFOLDER)/sim/arm

Modified: trunk/platforms/Cross/plugins/GdbARMPlugin/armulmem.c
===================================================================
--- trunk/platforms/Cross/plugins/GdbARMPlugin/armulmem.c	2014-07-02 22:44:11 UTC (rev 3026)
+++ trunk/platforms/Cross/plugins/GdbARMPlugin/armulmem.c	2014-07-03 00:26:26 UTC (rev 3027)
@@ -1,7 +1,9 @@
 /*
   This file is a compy of armvirt.c, which is part of the ARMulator distributed e.g. with gdb and skyeye.
-  In order to overwrite GetWord and PutWord, I had to copy the whole file.
+  In order to overwrite GetWord and PutWord, I (lars wasserman) had to copy the whole file and alter the Make to use it instead of the default ARM armvirt.c.
   Also changed: ReLoadInstr.
+  TPR - changed the errors returned in PutWord & GetWord to discriminate between read & write bounds errors for better simulation
+  TPR - changed Get/PutWord to ensure address used is an actual word address ie bottom two bits are zeros. Without that, fetching bytes becomes... fun
 */
 #include "GdbARMPlugin.h"
 
@@ -71,14 +73,14 @@
   if(address < minReadAddress || address + 4 > (state->MemSize))
   {
     //raise memory access error
-    state->EndCondition = MemoryBoundsError;
+    state->EndCondition = MemoryLoadBoundsError;
     state->Emulate = FALSE;
     gdb_log_printf(NULL, "Illegal memory read at %#p. ", address);
     return 0;
   }
   else
   {
-    return *((ARMword*) (state->MemDataPtr + address));
+    return *((ARMword*) (state->MemDataPtr + (address & ~3)));
   }
 }
 
@@ -92,12 +94,12 @@
   if(address < minWriteAddress || address + 4 > (state->MemSize))
   {
     state->Emulate = FALSE;
-    state->EndCondition = MemoryBoundsError;
+    state->EndCondition = MemoryWriteBoundsError;
     gdb_log_printf(NULL, "Illegal memory write at %#p. ", address);
   } 
   else
   {
-    *((ARMword*) (state->MemDataPtr + address)) = data;
+    *((ARMword*) (state->MemDataPtr + (address & ~3))) = data;
   }
 }
 

Modified: trunk/platforms/Cross/plugins/GdbARMPlugin/sqGdbARMPlugin.c
===================================================================
--- trunk/platforms/Cross/plugins/GdbARMPlugin/sqGdbARMPlugin.c	2014-07-02 22:44:11 UTC (rev 3026)
+++ trunk/platforms/Cross/plugins/GdbARMPlugin/sqGdbARMPlugin.c	2014-07-03 00:26:26 UTC (rev 3027)
@@ -2,8 +2,8 @@
 #define FOR_COG_PLUGIN 1
 
 #include "GdbARMPlugin.h"
-
 //disassembler
+#include <gdbconfig.h> /*  TPR - <---- this is actually a *link* to the gdb gdb-7.6/bfd/config.h because it otherwise clashes with the Squeak one also in the assorted include paths. Must be a proper way to handle this case; it must happen elsewhere */
 #include <bfd.h>
 #include <dis-asm.h>
 
@@ -45,6 +45,7 @@
 {
 	if(lastCPU == NULL) ARMul_EmulateInit();
 	lastCPU = ARMul_NewState();
+	ARMul_SelectProcessor (lastCPU, ARM_v5_Prop | ARM_v5e_Prop | ARM_XScale_Prop | ARM_v6_Prop);
 	return lastCPU;
 }
 
@@ -165,6 +166,8 @@
 	dis->buffer = memory;
 	dis->buffer_length = byteSize;
 	
+	// first print the address
+	gdb_log_printf( NULL, "%08lx: ", laddr);
 	//other possible functions are listed in opcodes/dissassemble.c
 	unsigned int size = print_insn_little_arm((bfd_vma) laddr, dis);
 	
@@ -202,7 +205,7 @@
 			// This is the SWI number which is returned by our memory interface 
 			// if there is an instruction fetch for an illegal address.
 			state->Emulate = STOP;
-			state->EndCondition = MemoryBoundsError;
+			state->EndCondition = InstructionPrefetchError;
 			
 			// during execution, the pc points the next fetch address, which is 8 byte after the current instruction.
 			gdb_log_printf(NULL, "Illegal Instruction fetch address (%#p).", state->Reg[15]-8);



More information about the Vm-dev mailing list