Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew STUBBS <andrew.stubbs@st.com>
To: GDB Patches <gdb-patches@sourceware.org>
Subject: [PATCH][SH] simulator mis-executing pre-decrement
Date: Fri, 23 Feb 2007 14:55:00 -0000	[thread overview]
Message-ID: <45DF002F.2090403@st.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1178 bytes --]

Hi,

The attached patch fixes a problem with pre-decrement store instructions 
on the SH simulator.

The problem can be demonstrated with the following program:

#include <stdio.h>

int
main()
{
	int i[2] = {0,0};
	int *p = &i[1];

	asm ("mov.l %0,@-%0\n" : "+r" (p));

	if ((int*)i[0] == &i[1])
	  printf ("PASS: Value Correct.\n");
	else
	  printf ("FAIL: Incorrect value written.\n");

	return 0;
}

The issue is that, when both operands use the same register, the *value* 
to be stored is decremented, but only the *address* of the store should 
have been decremented. I.e. in the example, it is supposed to store "p" 
at "p - 4", but actually stores "p - 4" at "p - 4".

Note that GCC has a similar error which means that the two work together 
(probably not an accident), but the binaries may not work on real 
silicon. I think a patch for this problem will be submitted to GCC 
sometime soon.

:ADDPATCH sh sim:

Unfortunately, I can't test it on the latest GDB because CVS isn't 
accessible (corporate IT issue), but I'm fairly sure it works in the 
sources I do have. For the same reason, I'll have to ask somebody else 
to do the commit for me.

Thanks

Andrew Stubbs

[-- Attachment #2: sim.patch --]
[-- Type: text/plain, Size: 1447 bytes --]

2007-02-22  Andrew Stubbs  <andrew.stubbs@st.com>

	* gencode.c (tab): Correct pre-decrement instructions when m == n.

Index: src/sim/sh/gencode.c
===================================================================
--- src.orig/sim/sh/gencode.c	2005-06-17 04:13:07.000000000 +0100
+++ src/sim/sh/gencode.c	2007-02-23 12:04:35.000000000 +0000
@@ -970,9 +970,11 @@ op tab[] =
     "WBAT (R[n] + R0, R[m]);",
   },
   { "n", "nm", "mov.b <REG_M>,@-<REG_N>", "0010nnnnmmmm0100",
+    /* Allow for the case where m == n.  */
+    "int t = R[m];",
     "MA (1);",
     "R[n] -= 1;",
-    "WBAT (R[n], R[m]);",
+    "WBAT (R[n], t);",
   },
   { "n", "n0", "mov.b R0,@<REG_N>+", "0100nnnn10001011",
     "MA (1);",
@@ -1035,9 +1037,11 @@ op tab[] =
     "WLAT (R0 + R[n], R[m]);",
   },
   { "n", "nm", "mov.l <REG_M>,@-<REG_N>", "0010nnnnmmmm0110",
+    /* Allow for the case where m == n.  */
+    "int t = R[m];",
     "MA (1) ;",
     "R[n] -= 4;",
-    "WLAT (R[n], R[m]);",
+    "WLAT (R[n], t);",
   },
   { "n", "n0", "mov.l R0,@<REG_N>+", "0100nnnn10101011",
     "MA (1) ;",
@@ -1099,9 +1103,11 @@ op tab[] =
     "WWAT (R0 + R[n], R[m]);",
   },
   { "n", "mn", "mov.w <REG_M>,@-<REG_N>", "0010nnnnmmmm0101",
+    /* Allow for the case where m == n.  */
+    "int t = R[m];",
     "MA (1);",
     "R[n] -= 2;",
-    "WWAT (R[n], R[m]);",
+    "WWAT (R[n], t);",
   },
   { "n", "0n", "mov.w R0,@<REG_N>+", "0100nnnn10011011",
     "MA (1);",

             reply	other threads:[~2007-02-23 14:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-23 14:55 Andrew STUBBS [this message]
2007-03-02 11:44 ` Andrew STUBBS
2007-03-02 12:00   ` Daniel Jacobowitz
2007-03-02 12:04     ` Andrew STUBBS
2007-03-02 12:15       ` Daniel Jacobowitz
2007-03-02 12:18         ` Andrew STUBBS

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45DF002F.2090403@st.com \
    --to=andrew.stubbs@st.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox