From patchwork Mon Oct 15 16:39:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Liu X-Patchwork-Id: 191607 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B93682C00A8 for ; Tue, 16 Oct 2012 04:12:38 +1100 (EST) Received: from localhost ([::1]:35795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNnjR-00016S-Vb for incoming@patchwork.ozlabs.org; Mon, 15 Oct 2012 12:41:33 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNni6-0006hm-AB for qemu-devel@nongnu.org; Mon, 15 Oct 2012 12:40:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNni0-0005yz-LL for qemu-devel@nongnu.org; Mon, 15 Oct 2012 12:40:09 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:65132) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNni0-0005pr-Cz for qemu-devel@nongnu.org; Mon, 15 Oct 2012 12:40:04 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp2so5035865pbb.4 for ; Mon, 15 Oct 2012 09:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :content-type; bh=EDmNMuPS4VAR3iTmo04jG3sGyvvGpC7V4dKdNZziQU0=; b=BYU1c5Zz/24xGnqk8NMHyj4c+s92oxx/90POaOxqwLeg7qzrGgG9x/1W1NfuGtsfw6 d6beSy7/VEMUmDJt6VIZMSVfCOh3j2e04QyfljiqZTEA31ZzFoJd2fngeTS+aDLYVJ8n XR7StA2AQdJie1vvQaONNJuk8Vs5V9DhuleNtTr/ESIJhwcpAQ1NBfl7l0QU7rpzse01 jgSED/gvG0QQX6sxJUTfTEpRSKekeYxNhycuxFIBmutsQQLPe1eK8k6OlfO3ck9EOHP4 LcAEJxZD7Ll6gGhiX9pCtSWi2KvKWgXV+WycAnnUFr8OJlXYEOaPF3IQ0aRMwi/A6weO fZow== Received: by 10.66.86.201 with SMTP id r9mr34501993paz.16.1350319203238; Mon, 15 Oct 2012 09:40:03 -0700 (PDT) Received: from localhost.localdomain ([123.150.196.81]) by mx.google.com with ESMTPS id ka4sm9289654pbc.61.2012.10.15.09.39.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 09:40:01 -0700 (PDT) From: Jia Liu To: qemu-devel@nongnu.org Date: Tue, 16 Oct 2012 00:39:06 +0800 Message-Id: <1350319158-7263-3-git-send-email-proljc@gmail.com> X-Mailer: git-send-email 1.7.10.2 (Apple Git-33) In-Reply-To: <1350319158-7263-1-git-send-email-proljc@gmail.com> References: <1350319158-7263-1-git-send-email-proljc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: aurelien@aurel32.net Subject: [Qemu-devel] [PATCH v11 02/14] target-mips: Add ASE DSP resources access check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add MIPS ASE DSP resources access check. Signed-off-by: Jia Liu Acked-by: Aurelien Jarno --- linux-user/main.c | 6 ++++++ target-mips/cpu.h | 23 +++++++++++++++++++++-- target-mips/helper.c | 3 +++ target-mips/translate.c | 23 +++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index f4bbe69..f263c2e 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -2286,6 +2286,12 @@ done_syscall: queue_signal(env, info.si_signo, &info); } break; + case EXCP_DSPDIS: + info.si_signo = TARGET_SIGILL; + info.si_errno = 0; + info.si_code = TARGET_ILL_ILLOPC; + queue_signal(env, info.si_signo, &info); + break; default: // error: fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n", diff --git a/target-mips/cpu.h b/target-mips/cpu.h index b7a5112..31476cf 100644 --- a/target-mips/cpu.h +++ b/target-mips/cpu.h @@ -415,7 +415,7 @@ struct CPUMIPSState { int error_code; uint32_t hflags; /* CPU State */ /* TMASK defines different execution modes */ -#define MIPS_HFLAG_TMASK 0x007FF +#define MIPS_HFLAG_TMASK 0xC07FF #define MIPS_HFLAG_MODE 0x00007 /* execution modes */ /* The KSU flags must be the lowest bits in hflags. The flag order must be the same as defined for CP0 Status. This allows to use @@ -453,6 +453,9 @@ struct CPUMIPSState { #define MIPS_HFLAG_BDS32 0x10000 /* branch requires 32-bit delay slot */ #define MIPS_HFLAG_BX 0x20000 /* branch exchanges execution mode */ #define MIPS_HFLAG_BMASK (MIPS_HFLAG_BMASK_BASE | MIPS_HFLAG_BMASK_EXT) + /* MIPS DSP resources access. */ +#define MIPS_HFLAG_DSP 0x40000 /* Enable access to MIPS DSP resources. */ +#define MIPS_HFLAG_DSPR2 0x80000 /* Enable access to MIPS DSPR2 resources. */ target_ulong btarget; /* Jump / branch target */ target_ulong bcond; /* Branch condition (if needed) */ @@ -610,8 +613,9 @@ enum { EXCP_MDMX, EXCP_C2E, EXCP_CACHE, /* 32 */ + EXCP_DSPDIS, - EXCP_LAST = EXCP_CACHE, + EXCP_LAST = EXCP_DSPDIS, }; /* Dummy exception for conditional stores. */ #define EXCP_SC 0x100 @@ -772,6 +776,21 @@ static inline void compute_hflags(CPUMIPSState *env) if (env->CP0_Status & (1 << CP0St_FR)) { env->hflags |= MIPS_HFLAG_F64; } + if (env->insn_flags & ASE_DSPR2) { + /* Enables access MIPS DSP resources, now our cpu is DSP ASER2, + so enable to access DSPR2 resources. */ + if (env->CP0_Status & (1 << CP0St_MX)) { + env->hflags |= MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2; + } + + } else if (env->insn_flags & ASE_DSP) { + /* Enables access MIPS DSP resources, now our cpu is DSP ASE, + so enable to access DSP resources. */ + if (env->CP0_Status & (1 << CP0St_MX)) { + env->hflags |= MIPS_HFLAG_DSP; + } + + } if (env->insn_flags & ISA_MIPS32R2) { if (env->active_fpu.fcr0 & (1 << FCR0_F64)) { env->hflags |= MIPS_HFLAG_COP1X; diff --git a/target-mips/helper.c b/target-mips/helper.c index 4208bb2..edbe2b0 100644 --- a/target-mips/helper.c +++ b/target-mips/helper.c @@ -592,6 +592,9 @@ void do_interrupt (CPUMIPSState *env) case EXCP_THREAD: cause = 25; goto set_EPC; + case EXCP_DSPDIS: + cause = 26; + goto set_EPC; case EXCP_CACHE: cause = 30; if (env->CP0_Status & (1 << CP0St_BEV)) { diff --git a/target-mips/translate.c b/target-mips/translate.c index 454e5cc..8b6ebbc 100644 --- a/target-mips/translate.c +++ b/target-mips/translate.c @@ -942,6 +942,24 @@ static inline void check_cp1_registers(DisasContext *ctx, int regs) generate_exception(ctx, EXCP_RI); } +/* Verify that the processor is running with DSP instructions enabled. + This is enabled by CP0 Status register MX(24) bit. + */ + +static inline void check_dsp(DisasContext *ctx) +{ + if (unlikely(!(ctx->hflags & MIPS_HFLAG_DSP))) { + generate_exception(ctx, EXCP_DSPDIS); + } +} + +static inline void check_dspr2(DisasContext *ctx) +{ + if (unlikely(!(ctx->hflags & MIPS_HFLAG_DSPR2))) { + generate_exception(ctx, EXCP_DSPDIS); + } +} + /* This code generates a "reserved instruction" exception if the CPU does not support the instruction set corresponding to flags. */ static inline void check_insn(CPUMIPSState *env, DisasContext *ctx, int flags) @@ -13197,6 +13215,11 @@ void cpu_state_reset(CPUMIPSState *env) if (env->CP0_Config1 & (1 << CP0C1_FP)) { env->CP0_Status |= (1 << CP0St_CU1); } + if (env->cpu_model->insn_flags & ASE_DSPR2) { + env->hflags |= MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2; + } else if (env->cpu_model->insn_flags & ASE_DSP) { + env->hflags |= MIPS_HFLAG_DSP; + } #else if (env->hflags & MIPS_HFLAG_BMASK) { /* If the exception was raised from a delay slot,