diff mbox

[2/2,for-2.6] target-sparc: fix Trap Based Address Register behavior for sparc64

Message ID 1d5b26fed5e9648e4672545085509ea5ad8a9a60.1460625412.git.atar4qemu@gmail.com
State New
Headers show

Commit Message

Artyom Tarasenko April 14, 2016, 9:29 a.m. UTC
Accoding the chapter 7.6 Trap Processing of the SPARC Architecture Manual v9,
the Trap Based Address Register is not modified as a trap is taken.

This fix allows booting FreeBSD-10.3-RELEASE-sparc64.

Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com>
---
 target-sparc/int64_helper.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Mark Cave-Ayland April 14, 2016, 1:43 p.m. UTC | #1
On 14/04/16 10:29, Artyom Tarasenko wrote:

> Accoding the chapter 7.6 Trap Processing of the SPARC Architecture Manual v9,
> the Trap Based Address Register is not modified as a trap is taken.
> 
> This fix allows booting FreeBSD-10.3-RELEASE-sparc64.
> 
> Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com>
> ---
>  target-sparc/int64_helper.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/target-sparc/int64_helper.c b/target-sparc/int64_helper.c
> index aa876cd..29360fa 100644
> --- a/target-sparc/int64_helper.c
> +++ b/target-sparc/int64_helper.c
> @@ -158,9 +158,8 @@ void sparc_cpu_do_interrupt(CPUState *cs)
>      } else if ((intno & 0x1c0) == TT_FILL) {
>          cpu_set_cwp(env, cpu_cwp_inc(env, env->cwp + 1));
>      }
> -    env->tbr &= ~0x7fffULL;
> -    env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
> -    env->pc = env->tbr;
> +    env->pc = env->tbr  & ~0x7fffULL;
> +    env->pc |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
>      env->npc = env->pc + 4;
>      cs->exception_index = -1;
>  }
> 

Gosh yes, this is entirely obvious when you consider that taking a trap
shouldn't actually alter the register containing the address of the trap
table in memory :(

Again the patch applies with fuzz and checkpatch.pl complains about
line-endings but if you can rebase/resend then you can add my
Reviewed-by. Given that such a trivial fix unlocks FreeBSD then I'm okay
with this in 2.6 too.


ATB,

Mark.
Artyom Tarasenko April 14, 2016, 2:01 p.m. UTC | #2
On Thu, Apr 14, 2016 at 3:43 PM, Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
> On 14/04/16 10:29, Artyom Tarasenko wrote:
>
>> Accoding the chapter 7.6 Trap Processing of the SPARC Architecture Manual v9,
>> the Trap Based Address Register is not modified as a trap is taken.
>>
>> This fix allows booting FreeBSD-10.3-RELEASE-sparc64.
>>
>> Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com>
>> ---
>>  target-sparc/int64_helper.c | 5 ++---
>>  1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/target-sparc/int64_helper.c b/target-sparc/int64_helper.c
>> index aa876cd..29360fa 100644
>> --- a/target-sparc/int64_helper.c
>> +++ b/target-sparc/int64_helper.c
>> @@ -158,9 +158,8 @@ void sparc_cpu_do_interrupt(CPUState *cs)
>>      } else if ((intno & 0x1c0) == TT_FILL) {
>>          cpu_set_cwp(env, cpu_cwp_inc(env, env->cwp + 1));
>>      }
>> -    env->tbr &= ~0x7fffULL;
>> -    env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
>> -    env->pc = env->tbr;
>> +    env->pc = env->tbr  & ~0x7fffULL;
>> +    env->pc |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
>>      env->npc = env->pc + 4;
>>      cs->exception_index = -1;
>>  }
>>
>
> Gosh yes, this is entirely obvious when you consider that taking a trap
> shouldn't actually alter the register containing the address of the trap
> table in memory :(

Well, it does alter it in SPARCv8, I guess that's where the bug is coming from.

>
> Again the patch applies with fuzz and checkpatch.pl complains about
> line-endings but if you can rebase/resend then you can add my

This is strange. I've rebased it today on
8b4aaba736e55c8ab6d71350f850a6642f0165b9,
and

$  scripts/checkpatch.pl
0002-target-sparc-fix-Trap-Based-Address-Register-behavio.patch
total: 0 errors, 0 warnings, 11 lines checked
0002-target-sparc-fix-Trap-Based-Address-Register-behavio.patch has no
obvious style problems and is ready for Submission.

Artyom

> Reviewed-by. Given that such a trivial fix unlocks FreeBSD then I'm okay
> with this in 2.6 too.
>
>
> ATB,
>
> Mark.
>
diff mbox

Patch

diff --git a/target-sparc/int64_helper.c b/target-sparc/int64_helper.c
index aa876cd..29360fa 100644
--- a/target-sparc/int64_helper.c
+++ b/target-sparc/int64_helper.c
@@ -158,9 +158,8 @@  void sparc_cpu_do_interrupt(CPUState *cs)
     } else if ((intno & 0x1c0) == TT_FILL) {
         cpu_set_cwp(env, cpu_cwp_inc(env, env->cwp + 1));
     }
-    env->tbr &= ~0x7fffULL;
-    env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
-    env->pc = env->tbr;
+    env->pc = env->tbr  & ~0x7fffULL;
+    env->pc |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
     env->npc = env->pc + 4;
     cs->exception_index = -1;
 }