From: Sergey Fedorov <serge.fdrv@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
qemu-arm@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
patches@linaro.org,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Subject: Re: [Qemu-devel] [PATCH 4/8] target-arm: Pull semihosting handling out to arm_cpu_do_interrupt()
Date: Fri, 29 Jan 2016 19:46:54 +0300 [thread overview]
Message-ID: <56AB977E.6040300@gmail.com> (raw)
In-Reply-To: <1452796451-2946-5-git-send-email-peter.maydell@linaro.org>
On 14.01.2016 21:34, Peter Maydell wrote:
> Handling of semihosting calls should depend on the register width
> of the calling code, not on that of any higher exception level,
> so we need to identify and handle semihosting calls before we
> decide whether to deliver the exception as an entry to AArch32
> or AArch64. (EXCP_SEMIHOST is also an "internal exception" so
> it has no target exception level in the first place.)
>
> This will allow AArch32 EL1 code to use semihosting calls when
> running under an AArch64 EL3.
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> target-arm/helper.c | 120 +++++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 81 insertions(+), 39 deletions(-)
>
> diff --git a/target-arm/helper.c b/target-arm/helper.c
> index 962bb3c..d37c82c 100644
> --- a/target-arm/helper.c
> +++ b/target-arm/helper.c
> @@ -5754,27 +5754,6 @@ static void arm_cpu_do_interrupt_aarch32(CPUState *cs)
> offset = 4;
> break;
> case EXCP_SWI:
> - if (semihosting_enabled()) {
> - /* Check for semihosting interrupt. */
> - if (env->thumb) {
> - mask = arm_lduw_code(env, env->regs[15] - 2, env->bswap_code)
> - & 0xff;
> - } else {
> - mask = arm_ldl_code(env, env->regs[15] - 4, env->bswap_code)
> - & 0xffffff;
> - }
> - /* Only intercept calls from privileged modes, to provide some
> - semblance of security. */
> - if (((mask == 0x123456 && !env->thumb)
> - || (mask == 0xab && env->thumb))
> - && (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR) {
> - qemu_log_mask(CPU_LOG_INT,
> - "...handling as semihosting call 0x%x\n",
> - env->regs[0]);
> - env->regs[0] = do_arm_semihosting(env);
> - return;
> - }
> - }
> new_mode = ARM_CPU_MODE_SVC;
> addr = 0x08;
> mask = CPSR_I;
> @@ -5782,19 +5761,6 @@ static void arm_cpu_do_interrupt_aarch32(CPUState *cs)
> offset = 0;
> break;
> case EXCP_BKPT:
> - /* See if this is a semihosting syscall. */
> - if (env->thumb && semihosting_enabled()) {
> - mask = arm_lduw_code(env, env->regs[15], env->bswap_code) & 0xff;
> - if (mask == 0xab
> - && (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR) {
> - 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;
> - }
> - }
> env->exception.fsr = 2;
> /* Fall through to prefetch abort. */
> case EXCP_PREFETCH_ABORT:
> @@ -5970,6 +5936,78 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
> new_el, env->pc, pstate_read(env));
> }
>
> +static inline bool check_for_semihosting(CPUState *cs)
> +{
> + /* Check whether this exception is a semihosting call; if so
> + * then handle it and return true; otherwise return false.
> + */
> + ARMCPU *cpu = ARM_CPU(cs);
> + CPUARMState *env = &cpu->env;
> +
> + if (is_a64(env)) {
> + if (cs->exception_index == EXCP_SEMIHOST) {
> + /* This is always the 64-bit semihosting exception.
> + * The "is this usermode" and "is semihosting enabled"
> + * checks have been done at translate time.
> + */
> + qemu_log_mask(CPU_LOG_INT,
> + "...handling as semihosting call 0x%" PRIx64 "\n",
> + env->xregs[0]);
> + env->xregs[0] = do_arm_semihosting(env);
> + return true;
> + }
> + return false;
> + } else {
> + uint32_t imm;
> +
> + /* Only intercept calls from privileged modes, to provide some
> + * semblance of security.
> + */
> + if (!semihosting_enabled() ||
> + ((env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR)) {
> + return false;
> + }
> +
> + switch (cs->exception_index) {
> + case EXCP_SWI:
> + /* Check for semihosting interrupt. */
> + if (env->thumb) {
> + imm = arm_lduw_code(env, env->regs[15] - 2, env->bswap_code)
> + & 0xff;
> + if (imm == 0xab) {
> + break;
> + }
> + } else {
> + imm = arm_ldl_code(env, env->regs[15] - 4, env->bswap_code)
> + & 0xffffff;
> + if (imm == 0x123456) {
> + break;
> + }
> + }
> + return false;
> + case EXCP_BKPT:
> + /* See if this is a semihosting syscall. */
> + if (env->thumb) {
> + imm = arm_lduw_code(env, env->regs[15], env->bswap_code)
> + & 0xff;
> + if (imm == 0xab) {
> + env->regs[15] += 2;
> + break;
> + }
> + }
> + return false;
> + default:
> + return false;
> + }
> +
> + qemu_log_mask(CPU_LOG_INT,
> + "...handling as semihosting call 0x%x\n",
> + env->regs[0]);
> + env->regs[0] = do_arm_semihosting(env);
> + return true;
> + }
> +}
> +
> /* Handle a CPU exception for A and R profile CPUs.
> * Do any appropriate logging, handle PSCI calls, and then hand off
> * to the AArch64-entry or AArch32-entry function depending on the
> @@ -5999,12 +6037,16 @@ void arm_cpu_do_interrupt(CPUState *cs)
> return;
> }
>
> - /* Temporary special case for EXCP_SEMIHOST, which is used only
> - * for 64-bit semihosting calls -- as this is an internal exception
> - * it has no specified target level and arm_el_is_aa64() would
> - * assert because new_el could be 0.
> + /* Semihosting semantics depend on the register width of the
> + * code that caused the exception, not the target exception level,
> + * so must be handled here.
> */
> - if (cs->exception_index == EXCP_SEMIHOST || arm_el_is_aa64(env, new_el)) {
> + if (check_for_semihosting(cs)) {
> + return;
> + }
> +
> + assert(!excp_is_internal(cs->exception_index));
> + if (arm_el_is_aa64(env, new_el)) {
> arm_cpu_do_interrupt_aarch64(cs);
> } else {
> arm_cpu_do_interrupt_aarch32(cs);
next prev parent reply other threads:[~2016-01-29 16:47 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-14 18:34 [Qemu-devel] [PATCH 0/8] target-arm: support mixed 32/64 bit execution beyond EL0 Peter Maydell
2016-01-14 18:34 ` [Qemu-devel] [PATCH 1/8] target-arm: Properly support EL2 and EL3 in arm_el_is_aa64() Peter Maydell
2016-01-15 14:38 ` Edgar E. Iglesias
2016-01-15 14:50 ` Peter Maydell
2016-01-15 15:37 ` Edgar E. Iglesias
2016-01-15 15:47 ` Peter Maydell
2016-01-15 20:37 ` Edgar E. Iglesias
2016-01-29 16:45 ` Sergey Fedorov
2016-01-29 16:50 ` Sergey Fedorov
2016-01-29 17:05 ` Peter Maydell
2016-01-29 17:08 ` Sergey Fedorov
2016-01-14 18:34 ` [Qemu-devel] [PATCH 2/8] target-arm: Move aarch64_cpu_do_interrupt() to helper.c Peter Maydell
2016-01-15 14:39 ` Edgar E. Iglesias
2016-01-29 16:46 ` Sergey Fedorov
2016-01-14 18:34 ` [Qemu-devel] [PATCH 3/8] target-arm: Use a single entry point for AArch64 and AArch32 exceptions Peter Maydell
2016-01-15 14:54 ` Edgar E. Iglesias
2016-01-29 16:46 ` [Qemu-devel] [Qemu-arm] " Sergey Fedorov
2016-01-14 18:34 ` [Qemu-devel] [PATCH 4/8] target-arm: Pull semihosting handling out to arm_cpu_do_interrupt() Peter Maydell
2016-01-29 16:46 ` Sergey Fedorov [this message]
2016-01-14 18:34 ` [Qemu-devel] [PATCH 5/8] target-arm: Fix wrong AArch64 entry offset for EL2/EL3 target Peter Maydell
2016-01-19 16:40 ` Edgar E. Iglesias
2016-01-29 16:47 ` Sergey Fedorov
2016-01-14 18:34 ` [Qemu-devel] [PATCH 6/8] target-arm: Handle exception return from AArch64 to non-EL0 AArch32 Peter Maydell
2016-01-19 16:47 ` Edgar E. Iglesias
2016-01-29 16:47 ` [Qemu-devel] [Qemu-arm] " Sergey Fedorov
2016-01-14 18:34 ` [Qemu-devel] [PATCH 7/8] target-arm: Implement remaining illegal return event checks Peter Maydell
2016-01-19 16:53 ` Edgar E. Iglesias
2016-01-19 16:58 ` Peter Maydell
2016-01-29 16:47 ` Sergey Fedorov
2016-01-14 18:34 ` [Qemu-devel] [PATCH 8/8] target-arm: ignore ELR_ELx[1] for exception return to 32-bit ARM mode Peter Maydell
2016-01-19 16:56 ` Edgar E. Iglesias
2016-01-29 16:48 ` [Qemu-devel] [Qemu-arm] " Sergey Fedorov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56AB977E.6040300@gmail.com \
--to=serge.fdrv@gmail.com \
--cc=alex.bennee@linaro.org \
--cc=edgar.iglesias@gmail.com \
--cc=patches@linaro.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).