diff mbox series

[v5,2/5] target/arm: handle M-profile semihosting at translate time

Message ID 20190911164959.11003-3-alex.bennee@linaro.org
State Superseded
Headers show
Series semihosting cleanups (plus minor tests/tcg tweak) | expand

Commit Message

Alex Bennée Sept. 11, 2019, 4:49 p.m. UTC
We do this for other semihosting calls so we might as well do it for
M-profile as well.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


---
v2
  - update for change to gen_exception_internal_insn API
v3
  - update for decode tree
v4
  - use !IS_USER
---
 target/arm/m_helper.c  | 18 ++++++------------
 target/arm/translate.c |  8 +++++++-
 2 files changed, 13 insertions(+), 13 deletions(-)

-- 
2.20.1

Comments

Peter Maydell Sept. 13, 2019, 1:03 p.m. UTC | #1
On Wed, 11 Sep 2019 at 17:50, Alex Bennée <alex.bennee@linaro.org> wrote:
>

> We do this for other semihosting calls so we might as well do it for

> M-profile as well.

>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

>

> ---

> v2

>   - update for change to gen_exception_internal_insn API

> v3

>   - update for decode tree

> v4

>   - use !IS_USER

> ---


> diff --git a/target/arm/translate.c b/target/arm/translate.c

> index 34bb280e3da..6689acc911e 100644

> --- a/target/arm/translate.c

> +++ b/target/arm/translate.c

> @@ -8424,7 +8424,13 @@ static bool trans_BKPT(DisasContext *s, arg_BKPT *a)

>      if (!ENABLE_ARCH_5) {

>          return false;

>      }

> -    gen_exception_bkpt_insn(s, syn_aa32_bkpt(a->imm, false));

> +    if (arm_dc_feature(s, ARM_FEATURE_M) &&

> +        semihosting_enabled() && !IS_USER(s) &&

> +        (a->imm == 0xab)) {

> +        gen_exception_internal_insn(s, s->base.pc_next, EXCP_SEMIHOST);

> +    } else {

> +        gen_exception_bkpt_insn(s, syn_aa32_bkpt(a->imm, false));

> +    }

>      return true;

>  }


This is still disabling semihosting for the linux-user-mode
build for M-profile, isn't it ?

thanks
-- PMM
Alex Bennée Sept. 13, 2019, 1:28 p.m. UTC | #2
Peter Maydell <peter.maydell@linaro.org> writes:

> On Wed, 11 Sep 2019 at 17:50, Alex Bennée <alex.bennee@linaro.org> wrote:

>>

>> We do this for other semihosting calls so we might as well do it for

>> M-profile as well.

>>

>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

>>

>> ---

>> v2

>>   - update for change to gen_exception_internal_insn API

>> v3

>>   - update for decode tree

>> v4

>>   - use !IS_USER

>> ---

>

>> diff --git a/target/arm/translate.c b/target/arm/translate.c

>> index 34bb280e3da..6689acc911e 100644

>> --- a/target/arm/translate.c

>> +++ b/target/arm/translate.c

>> @@ -8424,7 +8424,13 @@ static bool trans_BKPT(DisasContext *s, arg_BKPT *a)

>>      if (!ENABLE_ARCH_5) {

>>          return false;

>>      }

>> -    gen_exception_bkpt_insn(s, syn_aa32_bkpt(a->imm, false));

>> +    if (arm_dc_feature(s, ARM_FEATURE_M) &&

>> +        semihosting_enabled() && !IS_USER(s) &&

>> +        (a->imm == 0xab)) {

>> +        gen_exception_internal_insn(s, s->base.pc_next, EXCP_SEMIHOST);

>> +    } else {

>> +        gen_exception_bkpt_insn(s, syn_aa32_bkpt(a->imm, false));

>> +    }

>>      return true;

>>  }

>

> This is still disabling semihosting for the linux-user-mode

> build for M-profile, isn't it ?


Sure - as rth suggested. But m-profile doesn't run Linux so why would we
support it in linux-user?

>

> thanks

> -- PMM



--
Alex Bennée
Peter Maydell Sept. 13, 2019, 1:31 p.m. UTC | #3
On Fri, 13 Sep 2019 at 14:28, Alex Bennée <alex.bennee@linaro.org> wrote:
>

>

> Peter Maydell <peter.maydell@linaro.org> writes:

> > This is still disabling semihosting for the linux-user-mode

> > build for M-profile, isn't it ?

>

> Sure - as rth suggested. But m-profile doesn't run Linux so why would we

> support it in linux-user?


(a) Linux does support Cortex-M, since it has no-mmu uCLinux style
support these days
(b) gcc test case binaries, which tend to get run on linux-user
even though in theory they're not actually Linux binaries

thanks
-- PMM
Peter Maydell Sept. 13, 2019, 1:48 p.m. UTC | #4
On Fri, 13 Sep 2019 at 14:31, Peter Maydell <peter.maydell@linaro.org> wrote:
>

> On Fri, 13 Sep 2019 at 14:28, Alex Bennée <alex.bennee@linaro.org> wrote:

> >

> >

> > Peter Maydell <peter.maydell@linaro.org> writes:

> > > This is still disabling semihosting for the linux-user-mode

> > > build for M-profile, isn't it ?

> >

> > Sure - as rth suggested. But m-profile doesn't run Linux so why would we

> > support it in linux-user?

>

> (a) Linux does support Cortex-M, since it has no-mmu uCLinux style

> support these days

> (b) gcc test case binaries, which tend to get run on linux-user

> even though in theory they're not actually Linux binaries


also I think (c) general principle -- don't change behaviour in what
looks like it's just a refactoring patchset.

thanks
-- PMM
Alex Bennée Sept. 13, 2019, 1:48 p.m. UTC | #5
Peter Maydell <peter.maydell@linaro.org> writes:

> On Fri, 13 Sep 2019 at 14:28, Alex Bennée <alex.bennee@linaro.org> wrote:

>>

>>

>> Peter Maydell <peter.maydell@linaro.org> writes:

>> > This is still disabling semihosting for the linux-user-mode

>> > build for M-profile, isn't it ?

>>

>> Sure - as rth suggested. But m-profile doesn't run Linux so why would we

>> support it in linux-user?

>

> (a) Linux does support Cortex-M, since it has no-mmu uCLinux style

> support these days


TIL

> (b) gcc test case binaries, which tend to get run on linux-user

> even though in theory they're not actually Linux binaries


Ahh ok - that's fair. I'll add the ifndef for that then.

>

> thanks

> -- PMM



--
Alex Bennée
diff mbox series

Patch

diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c
index 884d35d2b02..27cd2f3f964 100644
--- a/target/arm/m_helper.c
+++ b/target/arm/m_helper.c
@@ -2114,19 +2114,13 @@  void arm_v7m_cpu_do_interrupt(CPUState *cs)
             break;
         }
         break;
+    case EXCP_SEMIHOST:
+        qemu_log_mask(CPU_LOG_INT,
+                      "...handling as semihosting call 0x%x\n",
+                      env->regs[0]);
+        env->regs[0] = do_arm_semihosting(env);
+        return;
     case EXCP_BKPT:
-        if (semihosting_enabled()) {
-            int nr;
-            nr = arm_lduw_code(env, env->regs[15], arm_sctlr_b(env)) & 0xff;
-            if (nr == 0xab) {
-                env->regs[15] += 2;
-                qemu_log_mask(CPU_LOG_INT,
-                              "...handling as semihosting call 0x%x\n",
-                              env->regs[0]);
-                env->regs[0] = do_arm_semihosting(env);
-                return;
-            }
-        }
         armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG, false);
         break;
     case EXCP_IRQ:
diff --git a/target/arm/translate.c b/target/arm/translate.c
index 34bb280e3da..6689acc911e 100644
--- a/target/arm/translate.c
+++ b/target/arm/translate.c
@@ -8424,7 +8424,13 @@  static bool trans_BKPT(DisasContext *s, arg_BKPT *a)
     if (!ENABLE_ARCH_5) {
         return false;
     }
-    gen_exception_bkpt_insn(s, syn_aa32_bkpt(a->imm, false));
+    if (arm_dc_feature(s, ARM_FEATURE_M) &&
+        semihosting_enabled() && !IS_USER(s) &&
+        (a->imm == 0xab)) {
+        gen_exception_internal_insn(s, s->base.pc_next, EXCP_SEMIHOST);
+    } else {
+        gen_exception_bkpt_insn(s, syn_aa32_bkpt(a->imm, false));
+    }
     return true;
 }