qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ARM (Thumb) read from R15
@ 2007-06-28 14:31 Ulrich Hecht
  2007-06-28 15:30 ` Ulrich Hecht
  2007-06-30  2:19 ` Paul Brook
  0 siblings, 2 replies; 6+ messages in thread
From: Ulrich Hecht @ 2007-06-28 14:31 UTC (permalink / raw)
  To: qemu-devel

Hi!

QEMU does not set the Thumb bit when reading from R15 in Thumb mode. 
Here's the fix:

Index: target-arm/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/translate.c,v
retrieving revision 1.53
diff -u -r1.53 translate.c
--- target-arm/translate.c      11 Jun 2007 18:59:35 -0000      1.53
+++ target-arm/translate.c      28 Jun 2007 14:29:15 -0000
@@ -307,7 +307,7 @@
     if (reg == 15) {
         /* normaly, since we updated PC, we need only to add one insn */
         if (s->thumb)
-            val = (long)s->pc + 2;
+            val = (long)s->pc + 3;
         else
             val = (long)s->pc + 4;
         gen_op_movl_TN_im[t](val);

CU
Uli

-- 
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH] ARM (Thumb) read from R15
  2007-06-28 14:31 [Qemu-devel] [PATCH] ARM (Thumb) read from R15 Ulrich Hecht
@ 2007-06-28 15:30 ` Ulrich Hecht
  2007-06-28 15:53   ` Ulrich Hecht
  2007-06-30  2:19 ` Paul Brook
  1 sibling, 1 reply; 6+ messages in thread
From: Ulrich Hecht @ 2007-06-28 15:30 UTC (permalink / raw)
  To: qemu-devel

On Thursday 28 June 2007 16:31, Ulrich Hecht wrote:
> QEMU does not set the Thumb bit when reading from R15 in Thumb mode.
> Here's the fix:

Maybe not; this seems to break some cases ... :(

CU
Uli

-- 
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH] ARM (Thumb) read from R15
  2007-06-28 15:30 ` Ulrich Hecht
@ 2007-06-28 15:53   ` Ulrich Hecht
  0 siblings, 0 replies; 6+ messages in thread
From: Ulrich Hecht @ 2007-06-28 15:53 UTC (permalink / raw)
  To: qemu-devel

On Thursday 28 June 2007 17:30, Ulrich Hecht wrote:
> On Thursday 28 June 2007 16:31, Ulrich Hecht wrote:
> > QEMU does not set the Thumb bit when reading from R15 in Thumb mode.
> > Here's the fix:
>
> Maybe not; this seems to break some cases ... :(

This works in all my cases, although I am not sure if it is correct:

Index: target-arm/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/translate.c,v
retrieving revision 1.53
diff -u -r1.53 translate.c
--- target-arm/translate.c      11 Jun 2007 18:59:35 -0000      1.53
+++ target-arm/translate.c      28 Jun 2007 15:48:59 -0000
@@ -307,7 +307,7 @@
     if (reg == 15) {
         /* normaly, since we updated PC, we need only to add one insn */
         if (s->thumb)
-            val = (long)s->pc + 2;
+            val = (long)s->pc + 3;
         else
             val = (long)s->pc + 4;
         gen_op_movl_TN_im[t](val);
@@ -3062,7 +3062,10 @@
                     gen_op_movl_T1_im(val);
                     gen_movl_reg_T1(s, 14);
                 }
-                gen_movl_T0_reg(s, rm);
+                if (rm == 15)
+                  gen_op_movl_T0_im(s->pc + 2);
+                else
+                  gen_movl_T0_reg(s, rm);
                 gen_bx(s);
                 break;
             }

CU
Uli

-- 
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH] ARM (Thumb) read from R15
  2007-06-28 14:31 [Qemu-devel] [PATCH] ARM (Thumb) read from R15 Ulrich Hecht
  2007-06-28 15:30 ` Ulrich Hecht
@ 2007-06-30  2:19 ` Paul Brook
  2007-07-02 11:12   ` Ulrich Hecht
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Brook @ 2007-06-30  2:19 UTC (permalink / raw)
  To: qemu-devel

> QEMU does not set the Thumb bit when reading from R15 in Thumb mode.

Neither does real hardware.

Paul

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

* Re: [Qemu-devel] [PATCH] ARM (Thumb) read from R15
  2007-06-30  2:19 ` Paul Brook
@ 2007-07-02 11:12   ` Ulrich Hecht
  2007-07-02 13:17     ` Paul Brook
  0 siblings, 1 reply; 6+ messages in thread
From: Ulrich Hecht @ 2007-07-02 11:12 UTC (permalink / raw)
  To: qemu-devel

On Saturday 30 June 2007 04:19, Paul Brook wrote:
> > QEMU does not set the Thumb bit when reading from R15 in Thumb mode.
>
> Neither does real hardware.

You are, unsurprisingly, right. The problem seems to be a different one. 
Quoting the ARM on "pop pc":

"In ARM architecture 5 and above, bit[0] of the loaded value determines 
whether execution continues after this branch in ARM state or in Thumb 
state[...] In T variants of architecture version 4, bit[0] of the loaded 
value is ignored and execution continues in Thumb state[...]"

My code is supposed to run on a 4T. I guess I'll have to implement an 
ARM_FEATURE_THUMB1.

CU
Uli

-- 
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH] ARM (Thumb) read from R15
  2007-07-02 11:12   ` Ulrich Hecht
@ 2007-07-02 13:17     ` Paul Brook
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Brook @ 2007-07-02 13:17 UTC (permalink / raw)
  To: qemu-devel

On Monday 02 July 2007, Ulrich Hecht wrote:
> On Saturday 30 June 2007 04:19, Paul Brook wrote:
> > > QEMU does not set the Thumb bit when reading from R15 in Thumb mode.
> >
> > Neither does real hardware.
>
> You are, unsurprisingly, right. The problem seems to be a different one.
> Quoting the ARM on "pop pc":
>
> "In ARM architecture 5 and above, bit[0] of the loaded value determines
> whether execution continues after this branch in ARM state or in Thumb
> state[...] In T variants of architecture version 4, bit[0] of the loaded
> value is ignored and execution continues in Thumb state[...]"
>
> My code is supposed to run on a 4T. I guess I'll have to implement an
> ARM_FEATURE_THUMB1.

As you have found out, qemu doesn't currently emulate v4t. There are a couple 
of other instructions that should be disabled (blx) if you do this.

Paul

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

end of thread, other threads:[~2007-07-02 13:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-28 14:31 [Qemu-devel] [PATCH] ARM (Thumb) read from R15 Ulrich Hecht
2007-06-28 15:30 ` Ulrich Hecht
2007-06-28 15:53   ` Ulrich Hecht
2007-06-30  2:19 ` Paul Brook
2007-07-02 11:12   ` Ulrich Hecht
2007-07-02 13:17     ` Paul Brook

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).