Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* PATCH : H8300 GDB simulator
@ 2003-12-04 11:57 Anil Paranjape
  2003-12-04 19:38 ` Michael Snyder
  0 siblings, 1 reply; 4+ messages in thread
From: Anil Paranjape @ 2003-12-04 11:57 UTC (permalink / raw)
  To: gdb-patches

Hi,

The CPU can access word data and longword data in memory, but word or longword data must begin at an even address. If an attempt is made to access word or longword data at an odd address, no address error occurs but the least significant bit of the address is regarded as 0, so the access starts at the preceding address. This is the case in actual H/W.

Now if an odd address is assigned to any word or long word memory pointer in H8 simulator and then if data at that address is accessed byte by byte then simulator was neither showing correct data (which is the case in actual H/W) not generating SIGBUS exception (which is the case in SH).

Patch below fixes this problem and after patch, simulator shows correct value as is the case in actual H/W.

ChangeLog/sim/h8300

2003-12-03  Anil Paranjpe <anilp1@kpitcummins.com>

        * compile.c : In all word and double word memory operations, 
			    address is forced to be always even.

Patch for /sim/h8300/compile.c

--- compile.c.orig	Fri Oct 17 18:15:56 2003
+++ compile.c	Wed Dec  3 22:04:22 2003
@@ -1265,20 +1265,19 @@
 
 #define GET_MEMORY_L(X) \
   ((X) < memory_size \
-   ? ((h8_get_memory (sd, (X)+0) << 24) | (h8_get_memory (sd, (X)+1) << 16)  \
-    | (h8_get_memory (sd, (X)+2) <<  8) | (h8_get_memory (sd, (X)+3) <<  0)) \
-   : ((h8_get_eightbit (sd, ((X)+0) & 0xff) << 24) \
-    | (h8_get_eightbit (sd, ((X)+1) & 0xff) << 16) \
-    | (h8_get_eightbit (sd, ((X)+2) & 0xff) <<  8) \
-    | (h8_get_eightbit (sd, ((X)+3) & 0xff) <<  0)))
+   ? ((h8_get_memory (sd, ((X) & 0xfffffffe)+0) << 24) | (h8_get_memory (sd, ((X) & 0xfffffffe)+1) << 16)  \
+    | (h8_get_memory (sd, ((X) & 0xfffffffe)+2) <<  8) | (h8_get_memory (sd, ((X) & 0xfffffffe)+3) <<  0)) \
+   : ((h8_get_eightbit (sd, (((X) & 0xfffffffe)+0) & 0xff) << 24) \
+    | (h8_get_eightbit (sd, (((X) & 0xfffffffe)+1) & 0xff) << 16) \
+    | (h8_get_eightbit (sd, (((X) & 0xfffffffe)+2) & 0xff) <<  8) \
+    | (h8_get_eightbit (sd, (((X) & 0xfffffffe)+3) & 0xff) <<  0)))
 
 #define GET_MEMORY_W(X) \
   ((X) < memory_size \
-   ? ((h8_get_memory   (sd, (X)+0) << 8) \
-    | (h8_get_memory   (sd, (X)+1) << 0)) \
-   : ((h8_get_eightbit (sd, ((X)+0) & 0xff) << 8) \
-    | (h8_get_eightbit (sd, ((X)+1) & 0xff) << 0)))
-
+   ? ((h8_get_memory   (sd, ((X) & 0xfffffffe)+0) << 8) \
+    | (h8_get_memory   (sd, ((X) & 0xfffffffe)+1) << 0)) \
+   : ((h8_get_eightbit (sd, (((X) & 0xfffffffe)+0) & 0xff) << 8) \
+    | (h8_get_eightbit (sd, (((X) & 0xfffffffe)+1) & 0xff) << 0)))
 
 #define GET_MEMORY_B(X) \
   ((X) < memory_size ? (h8_get_memory   (sd, (X))) \
@@ -1286,16 +1285,16 @@
 
 #define SET_MEMORY_L(X, Y)  \
 {  register unsigned char *_p; register int __y = (Y); \
-   _p = ((X) < memory_size ? h8_get_memory_buf   (sd) +  (X) : \
-                             h8_get_eightbit_buf (sd) + ((X) & 0xff)); \
+    _p = ((X) < memory_size ? h8_get_memory_buf   (sd) +  ((X) & 0xfffffffe) : \
+                             h8_get_eightbit_buf (sd) + (((X) & 0xfffffffe) & 0xff)); \
    _p[0] = __y >> 24; _p[1] = __y >> 16; \
    _p[2] = __y >>  8; _p[3] = __y >>  0; \
 }
 
 #define SET_MEMORY_W(X, Y) \
 {  register unsigned char *_p; register int __y = (Y); \
-   _p = ((X) < memory_size ? h8_get_memory_buf   (sd) +  (X) : \
-                             h8_get_eightbit_buf (sd) + ((X) & 0xff)); \
+   _p = ((X) < memory_size ? h8_get_memory_buf   (sd) +  ((X) & 0xfffffffe) : \
+                             h8_get_eightbit_buf (sd) + (((X) & 0xfffffffe) & 0xff)); \
    _p[0] = __y >> 8; _p[1] = __y; \
 }
 

Regards,
Anil Paranjpe


^ permalink raw reply	[flat|nested] 4+ messages in thread
* RE: PATCH : H8300 GDB simulator
@ 2003-12-08  9:51 Anil Paranjape
  2003-12-16 21:31 ` Michael Snyder
  0 siblings, 1 reply; 4+ messages in thread
From: Anil Paranjape @ 2003-12-08  9:51 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches

Hi Michael,

Please find following source code in C as a testcase for H8 simulator bug,

*********************************************************************************
int main()
{
	unsigned char test[10];
	unsigned short *pWord;
	pWord = (unsigned short *) &test[1];
	memset ( test, 0, sizeof(test));
	*pWord = 0x1234;
	printf ("Test[0] = 0x%02x\r\n", test[0] );
	printf ("Test[1] = 0x%02x\r\n", test[1] );
	return ( 0 );
}
**********************************************************************************

Simulator output before patch,
Test[0] = 0x00
Test[1] = 0x12

Simulator output after patch and same as in case of H/W,
Test[0] = 0x12
Test[1] = 0x34

Regards,
Anil

-----Original Message-----
From: Michael Snyder [mailto:msnyder@redhat.com]
Sent: Friday, December 05, 2003 1:08 AM
To: Anil Paranjape
Cc: gdb-patches@sources.redhat.com
Subject: Re: PATCH : H8300 GDB simulator


Anil Paranjape wrote:
> Hi,
> 
> The CPU can access word data and longword data in memory, but word or longword data must begin at an even address. If an attempt is made to access word or longword data at an odd address, no address error occurs but the least significant bit of the address is regarded as 0, so the access starts at the preceding address. This is the case in actual H/W.
> 
> Now if an odd address is assigned to any word or long word memory pointer in H8 simulator and then if data at that address is accessed byte by byte then simulator was neither showing correct data (which is the case in actual H/W) not generating SIGBUS exception (which is the case in SH).
> 
> Patch below fixes this problem and after patch, simulator shows correct value as is the case in actual H/W.

This sounds good (though I hope one of the folks with more knowledge of
the architecture will verify it).  One request -- could you include a
testcase for the sim testsuite, such that it will fail before your mods,
and pass after?  Existing tests (for examples) are at
sim/testsuite/sim/h8300.

Thanks,
Michael


> ChangeLog/sim/h8300
> 
> 2003-12-03  Anil Paranjpe <anilp1@kpitcummins.com>
> 
>         * compile.c : In all word and double word memory operations, 
> 			    address is forced to be always even.
> 
> Patch for /sim/h8300/compile.c
> 
> --- compile.c.orig	Fri Oct 17 18:15:56 2003
> +++ compile.c	Wed Dec  3 22:04:22 2003
> @@ -1265,20 +1265,19 @@
>  
>  #define GET_MEMORY_L(X) \
>    ((X) < memory_size \
> -   ? ((h8_get_memory (sd, (X)+0) << 24) | (h8_get_memory (sd, (X)+1) << 16)  \
> -    | (h8_get_memory (sd, (X)+2) <<  8) | (h8_get_memory (sd, (X)+3) <<  0)) \
> -   : ((h8_get_eightbit (sd, ((X)+0) & 0xff) << 24) \
> -    | (h8_get_eightbit (sd, ((X)+1) & 0xff) << 16) \
> -    | (h8_get_eightbit (sd, ((X)+2) & 0xff) <<  8) \
> -    | (h8_get_eightbit (sd, ((X)+3) & 0xff) <<  0)))
> +   ? ((h8_get_memory (sd, ((X) & 0xfffffffe)+0) << 24) | (h8_get_memory (sd, ((X) & 0xfffffffe)+1) << 16)  \
> +    | (h8_get_memory (sd, ((X) & 0xfffffffe)+2) <<  8) | (h8_get_memory (sd, ((X) & 0xfffffffe)+3) <<  0)) \
> +   : ((h8_get_eightbit (sd, (((X) & 0xfffffffe)+0) & 0xff) << 24) \
> +    | (h8_get_eightbit (sd, (((X) & 0xfffffffe)+1) & 0xff) << 16) \
> +    | (h8_get_eightbit (sd, (((X) & 0xfffffffe)+2) & 0xff) <<  8) \
> +    | (h8_get_eightbit (sd, (((X) & 0xfffffffe)+3) & 0xff) <<  0)))
>  
>  #define GET_MEMORY_W(X) \
>    ((X) < memory_size \
> -   ? ((h8_get_memory   (sd, (X)+0) << 8) \
> -    | (h8_get_memory   (sd, (X)+1) << 0)) \
> -   : ((h8_get_eightbit (sd, ((X)+0) & 0xff) << 8) \
> -    | (h8_get_eightbit (sd, ((X)+1) & 0xff) << 0)))
> -
> +   ? ((h8_get_memory   (sd, ((X) & 0xfffffffe)+0) << 8) \
> +    | (h8_get_memory   (sd, ((X) & 0xfffffffe)+1) << 0)) \
> +   : ((h8_get_eightbit (sd, (((X) & 0xfffffffe)+0) & 0xff) << 8) \
> +    | (h8_get_eightbit (sd, (((X) & 0xfffffffe)+1) & 0xff) << 0)))
>  
>  #define GET_MEMORY_B(X) \
>    ((X) < memory_size ? (h8_get_memory   (sd, (X))) \
> @@ -1286,16 +1285,16 @@
>  
>  #define SET_MEMORY_L(X, Y)  \
>  {  register unsigned char *_p; register int __y = (Y); \
> -   _p = ((X) < memory_size ? h8_get_memory_buf   (sd) +  (X) : \
> -                             h8_get_eightbit_buf (sd) + ((X) & 0xff)); \
> +    _p = ((X) < memory_size ? h8_get_memory_buf   (sd) +  ((X) & 0xfffffffe) : \
> +                             h8_get_eightbit_buf (sd) + (((X) & 0xfffffffe) & 0xff)); \
>     _p[0] = __y >> 24; _p[1] = __y >> 16; \
>     _p[2] = __y >>  8; _p[3] = __y >>  0; \
>  }
>  
>  #define SET_MEMORY_W(X, Y) \
>  {  register unsigned char *_p; register int __y = (Y); \
> -   _p = ((X) < memory_size ? h8_get_memory_buf   (sd) +  (X) : \
> -                             h8_get_eightbit_buf (sd) + ((X) & 0xff)); \
> +   _p = ((X) < memory_size ? h8_get_memory_buf   (sd) +  ((X) & 0xfffffffe) : \
> +                             h8_get_eightbit_buf (sd) + (((X) & 0xfffffffe) & 0xff)); \
>     _p[0] = __y >> 8; _p[1] = __y; \
>  }
>  
> 
> Regards,
> Anil Paranjpe
> 
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-12-16 21:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-04 11:57 PATCH : H8300 GDB simulator Anil Paranjape
2003-12-04 19:38 ` Michael Snyder
2003-12-08  9:51 Anil Paranjape
2003-12-16 21:31 ` Michael Snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox