qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Chris McNett" <mcnett@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Bug: ARM target uses an inconsistent offset when storing R15
Date: Mon, 21 Aug 2006 10:28:20 -0700	[thread overview]
Message-ID: <9f4a5ebe0608211028v37cc0c7aidec043ce414060bb@mail.gmail.com> (raw)

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

Hi,

According to the ARM Architecture Reference Manual:
"An implementation must use the same offset for all STR and STM instructions
that store R15.  It cannot use 8 for some of them and 12 for others."

Qemu appears to be inconsistent in this behavior.  Specifically, the
following two instructions:

 stmdb sp!, {pc}
 str pc, [sp, #-4]

use different offsets.

The following test code will verify this:

#include <stdio.h>

int main(void) {
 unsigned long x, y;
 asm volatile(
 "sub r1, pc, #4\n"
 "stmdb sp!, {pc}\n"
 "ldmia sp!, {r2}\n"
 "sub %0, r2, r1" :
 "=r"(x) :
 :
 "r1", "r2");

 asm volatile(
 "sub r1, pc, #4\n"
 "str pc, [sp, #-4]\n"
 "ldr r2, [sp, #-4]\n"
 "sub %0, r2, r1" :
 "=r"(y) :
 :
 "r1", "r2");
 printf("%ld %ld\n", x, y);
}

On qemu, the code prints "12 8".  On an XScale processor, the code prints "8
8".

In the qemu-0.8.2 sources, one fix for this is to change lines 1727-1728 of
target-arm/translate.c from:
                                /* special case: r15 = PC + 12 */
                                val = (long)s->pc + 8;
to:
                                /* special case: r15 = PC + 8 */
                                val = (long)s->pc + 4;

Once this change is made, the test code will print out "8 8" as XScale
hardware does.

As an alternative, the offset used in other store instructions could be
changed to 12 instead of 8.

Thanks,
Chris McNett

[-- Attachment #2: Type: text/html, Size: 2501 bytes --]

                 reply	other threads:[~2006-08-21 17:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=9f4a5ebe0608211028v37cc0c7aidec043ce414060bb@mail.gmail.com \
    --to=mcnett@gmail.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).