From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8120 invoked by alias); 23 Feb 2007 14:55:28 -0000 Received: (qmail 8108 invoked by uid 22791); 23 Feb 2007 14:55:26 -0000 X-Spam-Check-By: sourceware.org Received: from lon-del-01.spheriq.net (HELO lon-del-01.spheriq.net) (195.46.50.97) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 23 Feb 2007 14:55:15 +0000 Received: from lon-out-01.spheriq.net ([195.46.50.129]) by lon-del-01.spheriq.net with ESMTP id l1NEt1Ac001051 for ; Fri, 23 Feb 2007 14:55:01 GMT Received: from lon-cus-01.spheriq.net (lon-cus-01.spheriq.net [195.46.50.37]) by lon-out-01.spheriq.net with ESMTP id l1NEt0Od020963 for ; Fri, 23 Feb 2007 14:55:00 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by lon-cus-01.spheriq.net with ESMTP id l1NEsfRO011508 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Fri, 23 Feb 2007 14:54:42 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 78EB4DA41 for ; Fri, 23 Feb 2007 14:54:41 +0000 (GMT) Received: from mail1.bri.st.com (mail1.bri.st.com [164.129.8.218]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3C3DE472F8 for ; Fri, 23 Feb 2007 14:54:41 +0000 (GMT) Received: from [164.129.15.13] (bri1043.bri.st.com [164.129.15.13]) by mail1.bri.st.com (MOS 3.7.5a-GA) with ESMTP id CIN32174 (AUTH stubbsa); Fri, 23 Feb 2007 14:54:40 GMT Message-ID: <45DF002F.2090403@st.com> Date: Fri, 23 Feb 2007 14:55:00 -0000 From: Andrew STUBBS User-Agent: Thunderbird 2.0b2 (Windows/20070116) MIME-Version: 1.0 To: GDB Patches Subject: [PATCH][SH] simulator mis-executing pre-decrement Content-Type: multipart/mixed; boundary="------------040705090904020005020500" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-02/txt/msg00288.txt.bz2 This is a multi-part message in MIME format. --------------040705090904020005020500 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1178 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 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 --------------040705090904020005020500 Content-Type: text/plain; name="sim.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sim.patch" Content-length: 1447 2007-02-22 Andrew Stubbs * 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 ,@-", "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,@+", "0100nnnn10001011", "MA (1);", @@ -1035,9 +1037,11 @@ op tab[] = "WLAT (R0 + R[n], R[m]);", }, { "n", "nm", "mov.l ,@-", "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,@+", "0100nnnn10101011", "MA (1) ;", @@ -1099,9 +1103,11 @@ op tab[] = "WWAT (R0 + R[n], R[m]);", }, { "n", "mn", "mov.w ,@-", "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,@+", "0100nnnn10011011", "MA (1);", --------------040705090904020005020500--