This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: SH Simulator - MAC.L implementation and MAC.W correction


Hi,
At present in SH simulator of GDB there are two problems.

1. The GDB crashes during simulation of MAC.W instruction. 
2. Simulation of MAC.L is not present in GDB simulator.

Following patch corrects the MAC.W crash problem and implements the MAC.L instruction.

The simulation algorithm for MAC.L is taken from Hitachi SH1/2 programming manual 
page no. 177 available at http://www.hitachi-eu.com/hel/ecg/products/micro/pdf/sh1_2p.pdf

Regards,
Shrinivas

Changelog:

2002-11-26  Shrinivas Atre  <shrinivasa@kpit.com>	
	* sim/sh/gencode.c : Addition of MAC.L handler and correction for MAC.W handler
	* sim/sh/interp.c  : Implementation of MAC.L handler.
	
===============================================================================
--- sim/sh/gencode.cvs.c	Thu Nov 21 14:42:16 2002
+++ sim/sh/gencode.c	Fri Nov 22 09:58:54 2002
@@ -577,12 +577,12 @@ op tab[] =
   },
 
   { "", "nm", "mac.l @<REG_M>+,@<REG_N>+", "0000nnnnmmmm1111",
-    "trap (255, R0, PC, memory, maskl, maskw, endianw);",
+    "macl(&R0,memory,n,m);",
     "/* FIXME: mac.l support */",
   },
 
   { "", "nm", "mac.w @<REG_M>+,@<REG_N>+", "0100nnnnmmmm1111",
-    "macw(R0,memory,n,m,endianw);",
+    "macw(&R0,memory,n,m,endianw);",
   },
 
   { "n", "", "mov #<imm>,<REG_N>", "1110nnnni8*1....",


--- sim/sh/interp.cvs.c	Thu Nov 21 14:42:16 2002
+++ sim/sh/interp.c	Thu Nov 21 14:55:34 2002
@@ -169,6 +169,7 @@ static char **prog_argv;
 
 #if 1
 static int maskw = 0;
+static int maskl = 0;
 #endif
 
 static SIM_OPEN_KIND sim_kind;
@@ -651,6 +652,7 @@ rbat_fast (memory, x, maskb)
 
 #define RUWAT(x)  (RWAT(x) & 0xffff)
 #define RSWAT(x)  ((short)(RWAT(x)))
+#define RSLAT(x)  ((long)(RLAT(x)))
 #define RSBAT(x)  (SEXT(RBAT(x)))
 
 #define RDAT(x, n) (do_rdat (memory, (x), (n), (maskl)))
@@ -1347,6 +1349,96 @@ macw (regs, memory, n, m, endianw)
     }
   MACL = sum;
 }
+
+static void
+macl (regs, memory, n, m)
+     int *regs;
+     unsigned char *memory;
+     int m, n;
+{
+	unsigned long RnL,RnH,RmL,RmH,Res0,Res1,Res2;
+	unsigned long temp0,temp1,temp2,temp3;
+	long tempm,tempn,fnLmL;
+
+	tempm=RSLAT(regs[m]);
+	regs[m]+=4;
+
+	tempn=RSLAT(regs[n]);
+	regs[n]+=4;
+
+	if ((long)(tempn^tempm) < 0)
+		fnLmL = -1;
+	else
+		fnLmL = 0;
+
+	if (tempn < 0)
+		tempn = 0 - tempn;
+	if (tempm < 0)
+		tempm = 0 - tempm;
+
+	temp1 = (unsigned long)tempn;
+	temp2 = (unsigned long)tempm;
+
+	RnL = temp1 & 0x0000FFFF;
+
+	RnH = (temp1>>16) & 0x0000FFFF;
+	RmL = temp2 & 0x0000FFFF;
+	RmH = (temp2 >> 16) & 0x0000FFFF;
+	temp0 = RmL * RnL;
+	temp1 = RmH * RnL;
+	temp2 = RmL * RnH;
+	temp3 = RmH * RnH;
+	Res2  = 0;
+	Res1  = temp1 + temp2;
+
+	if ( Res1 < temp1)
+		Res2+=0x00010000;
+
+	temp1 = (Res1 << 16) & 0xFFFF0000;
+	Res0  =  temp0 + temp1;
+
+	if ( Res0 < temp0 )
+		Res2++;
+	Res2 = Res2 + (( Res1 >> 16 ) & 0x0000FFFF) + temp3;
+	if(fnLmL < 0)
+	{
+		Res2 = ~Res2;
+		if (Res0 == 0)
+			Res2++;
+		else
+			Res0 = (~Res0) + 1;
+	}
+	if(S==1)
+	{
+		Res0 = MACL + Res0;
+		if ( MACL > Res0 )
+			Res2++;
+		Res2 += ( MACH & 0x0000FFFF );
+		if(((long)Res2 < 0) && ( Res2 < 0xFFFF8000))
+		{
+			Res2 = 0x00008000;
+			Res0 = 0x00000000;
+		}
+		if(((long)Res2 > 0) && (Res2 > 0x00007FFF))
+		{
+			Res2 = 0x00007FFF;
+			Res0 = 0xFFFFFFFF;
+		};
+
+		MACH = Res2;
+		MACL = Res0;
+	}
+	else
+	{
+		Res0 = MACL + Res0;
+		if( MACL > Res0)
+			Res2++;
+		Res2 += MACH;
+		MACH = Res2;
+		MACL = Res0;
+	}
+}
+
 
 static struct loop_bounds
 get_loop_bounds (rs, re, memory, mem_end, maskw, endianw)

===============================================================================

-----------------------------------------------------------------------------
Free download of GNUSH and GNUH8 tool chains for Hitachi's SH and H8 Series.
The following site also offers free support to European customers.
Read more at http://www.kpit.com/products/support.htm
Latest versions of GNUSH and GNUH8 are released on October 1, 2002.
-----------------------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]