Patchwork m68k: implement move to/from usp register instruction

login
register
mail settings
Submitter Greg Ungerer
Date Sept. 13, 2012, 6:33 a.m.
Message ID <1347517980-16721-1-git-send-email-gerg@snapgear.com>
Download mbox | patch
Permalink /patch/183631/
State New
Headers show

Comments

Greg Ungerer - Sept. 13, 2012, 6:33 a.m.
From: Greg Ungerer <gerg@uclinux.org>

Fill out the code support for the move to/from usp instructions. They are
being decoded, but there is no code to support there actions. So add it.

Current versions of Linux running on the ColdFire 5208 use these instructions.

Signed-off-by: Greg Ungerer <gerg@uclinux.org>
---
 target-m68k/helper.c    |   10 ++++++++++
 target-m68k/helpers.h   |    2 ++
 target-m68k/translate.c |   10 ++++++----
 3 files changed, 18 insertions(+), 4 deletions(-)
Richard Henderson - Sept. 13, 2012, 5:34 p.m.
On 09/12/2012 11:33 PM, gerg@snapgear.com wrote:
> +uint32_t HELPER(move_from_usp)(CPUM68KState * env)
> +{
> +    return env->sp[M68K_USP];
> +}

You don't need helpers for these.

>  DISAS_INSN(move_from_usp)
>  {
> +    TCGv reg;
>      if (IS_USER(s)) {
>          gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
>          return;
>      }
> -    /* TODO: Implement USP.  */
> -    gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
> +    reg = AREG(insn, 0);
> +    gen_helper_move_from_usp(reg, cpu_env);

  tcg_gen_ld_i32(AREG(insn, 0), offsetof(CPUM68KState, sp[M68K_USP]));

>  DISAS_INSN(move_to_usp)
>  {
> +    TCGv reg;
>      if (IS_USER(s)) {
>          gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
>          return;
>      }
> -    /* TODO: Implement USP.  */
> -    gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
> +    reg = AREG(insn, 0);
> +    gen_helper_move_to_usp(cpu_env, reg);

  tcg_gen_st_i32(AREG(insn, 0), offsetof(CPUM68KState, sp[M68K_USP]));


r~
Greg Ungerer - Sept. 13, 2012, 11:36 p.m.
Hi Richard,

On 14/09/12 03:34, Richard Henderson wrote:
> On 09/12/2012 11:33 PM, gerg@snapgear.com wrote:
>> +uint32_t HELPER(move_from_usp)(CPUM68KState * env)
>> +{
>> +    return env->sp[M68K_USP];
>> +}
>
> You don't need helpers for these.
>
>>   DISAS_INSN(move_from_usp)
>>   {
>> +    TCGv reg;
>>       if (IS_USER(s)) {
>>           gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
>>           return;
>>       }
>> -    /* TODO: Implement USP.  */
>> -    gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
>> +    reg = AREG(insn, 0);
>> +    gen_helper_move_from_usp(reg, cpu_env);
>
>    tcg_gen_ld_i32(AREG(insn, 0), offsetof(CPUM68KState, sp[M68K_USP]));
>
>>   DISAS_INSN(move_to_usp)
>>   {
>> +    TCGv reg;
>>       if (IS_USER(s)) {
>>           gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
>>           return;
>>       }
>> -    /* TODO: Implement USP.  */
>> -    gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
>> +    reg = AREG(insn, 0);
>> +    gen_helper_move_to_usp(cpu_env, reg);
>
>    tcg_gen_st_i32(AREG(insn, 0), offsetof(CPUM68KState, sp[M68K_USP]));

That looks cleaner, thanks. I'll send a revised patch.

Regards
Greg


------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     gerg@snapgear.com
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com

Patch

diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index eac0053..722dbd9 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -229,6 +229,16 @@  void HELPER(movec)(CPUM68KState *env, uint32_t reg, uint32_t val)
     }
 }
 
+uint32_t HELPER(move_from_usp)(CPUM68KState * env)
+{
+    return env->sp[M68K_USP];
+}
+
+void HELPER(move_to_usp)(CPUM68KState * env, uint32_t val)
+{
+    env->sp[M68K_USP] = val;
+}
+
 void HELPER(set_macsr)(CPUM68KState *env, uint32_t val)
 {
     uint32_t acc;
diff --git a/target-m68k/helpers.h b/target-m68k/helpers.h
index cb8a0c7..bca780b 100644
--- a/target-m68k/helpers.h
+++ b/target-m68k/helpers.h
@@ -13,6 +13,8 @@  DEF_HELPER_3(sar_cc, i32, env, i32, i32)
 DEF_HELPER_2(xflag_lt, i32, i32, i32)
 DEF_HELPER_2(set_sr, void, env, i32)
 DEF_HELPER_3(movec, void, env, i32, i32)
+DEF_HELPER_1(move_from_usp, i32, env)
+DEF_HELPER_2(move_to_usp, void, env, i32)
 
 DEF_HELPER_2(f64_to_i32, f32, env, f64)
 DEF_HELPER_2(f64_to_f32, f32, env, f64)
diff --git a/target-m68k/translate.c b/target-m68k/translate.c
index 9fc1e31..5609240 100644
--- a/target-m68k/translate.c
+++ b/target-m68k/translate.c
@@ -1976,22 +1976,24 @@  DISAS_INSN(move_to_sr)
 
 DISAS_INSN(move_from_usp)
 {
+    TCGv reg;
     if (IS_USER(s)) {
         gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
         return;
     }
-    /* TODO: Implement USP.  */
-    gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
+    reg = AREG(insn, 0);
+    gen_helper_move_from_usp(reg, cpu_env);
 }
 
 DISAS_INSN(move_to_usp)
 {
+    TCGv reg;
     if (IS_USER(s)) {
         gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
         return;
     }
-    /* TODO: Implement USP.  */
-    gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
+    reg = AREG(insn, 0);
+    gen_helper_move_to_usp(cpu_env, reg);
 }
 
 DISAS_INSN(halt)