target/arm: Introduce read_pc
commitfdbcf6329d0c2984c55d7019419a72bf8e583c36
authorRichard Henderson <richard.henderson@linaro.org>
Thu, 15 Aug 2019 08:46:43 +0000 (15 09:46 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Fri, 16 Aug 2019 13:02:49 +0000 (16 14:02 +0100)
tree9498811dafb764903aa7670486990ecc24454e2e
parent43722a6d4f0c92f7e7e1e291580039b0f9789df1
target/arm: Introduce read_pc

We currently have 3 different ways of computing the architectural
value of "PC" as seen in the ARM ARM.

The value of s->pc has been incremented past the current insn,
but that is all.  Thus for a32, PC = s->pc + 4; for t32, PC = s->pc;
for t16, PC = s->pc + 2.  These differing computations make it
impossible at present to unify the various code paths.

With the newly introduced s->pc_curr, we can compute the correct
value for all cases, using the formula given in the ARM ARM.

This changes the behaviour for load_reg() and load_reg_var()
when called with reg==15 from a 32-bit Thumb instruction:
previously they would have returned the incorrect value
of pc_curr + 6, and now they will return the architecturally
correct value of PC, which is pc_curr + 4. This will not
affect well-behaved guest software, because all of the places
we call these functions from T32 code are instructions where
using r15 is UNPREDICTABLE. Using the architectural PC value
here is more consistent with the T16 and A32 behaviour.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20190807045335.1361-4-richard.henderson@linaro.org
[PMM: added commit message note about UNPREDICTABLE T32 cases]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
target/arm/translate.c