From patchwork Mon Jun 2 16:21:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 31291 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5211E20AE6 for ; Mon, 2 Jun 2014 16:23:22 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id z6sf26118489yhz.1 for ; Mon, 02 Jun 2014 09:23:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=3nTNAVdGr4wk8qns8iruY7hdu0u+ka7h4eiGiHqfEQo=; b=ZnKvPVtQhEozSQYucTforf32dwhH/3doBAb2FKkmGdhR16PHjPdFl39CBnI3F2Tbbf GncMOkCSX1rqWKPgyC/lXjUNCsqLB9SbLKS6gyDmL1azTrksP+52r2QUT/FQ0EwBfmeD raS+f7JToFCYKVN6UOXOQdmO600baCfSd9+m4IJVGBldZpd8IJVBBqS2L9TmsEAB/5mk LO06ryTyBmf1L5HCoUgfXwc6jKv4pQPdIjWnQWBpe4J5koRjRD/uIjPA4NxUEA7j6Rdv e0plRkYu8BPgVd3LCYMB67nBOrdGkvMxTwoH7zHL+SKF+qukpJKOIG/QuF6Gr469u7fk IwHA== X-Gm-Message-State: ALoCoQmwqhcs/VVb5rBcRMEaWggif9JdCNhvailGb+IKhqryqeOSHO1fGIw70zjYDVJeYp+n5AFz X-Received: by 10.58.30.108 with SMTP id r12mr14415664veh.17.1401726202074; Mon, 02 Jun 2014 09:23:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.84 with SMTP id h78ls2118088qge.54.gmail; Mon, 02 Jun 2014 09:23:21 -0700 (PDT) X-Received: by 10.58.29.16 with SMTP id f16mr31730244veh.23.1401726201933; Mon, 02 Jun 2014 09:23:21 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id ks14si8185876veb.45.2014.06.02.09.23.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 09:23:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id ik5so2422552vcb.4 for ; Mon, 02 Jun 2014 09:23:21 -0700 (PDT) X-Received: by 10.58.245.2 with SMTP id xk2mr31226862vec.9.1401726201860; Mon, 02 Jun 2014 09:23:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp109985vcb; Mon, 2 Jun 2014 09:23:21 -0700 (PDT) X-Received: by 10.140.106.3 with SMTP id d3mr47353742qgf.44.1401726201366; Mon, 02 Jun 2014 09:23:21 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a8si18665049qae.1.2014.06.02.09.23.21 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 02 Jun 2014 09:23:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:47719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrV16-0005YB-RV for patch@linaro.org; Mon, 02 Jun 2014 12:23:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrV09-0004Zs-BQ for qemu-devel@nongnu.org; Mon, 02 Jun 2014 12:22:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrV01-0007CI-SC for qemu-devel@nongnu.org; Mon, 02 Jun 2014 12:22:21 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:41875 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrV01-0007CB-Kg for qemu-devel@nongnu.org; Mon, 02 Jun 2014 12:22:13 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaro.local) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1WrV1A-0007B7-Ax; Mon, 02 Jun 2014 18:23:24 +0200 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Mon, 2 Jun 2014 17:21:55 +0100 Message-Id: <1401726122-11132-2-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1401726122-11132-1-git-send-email-alex.bennee@linaro.org> References: <1401726122-11132-1-git-send-email-alex.bennee@linaro.org> X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: alex.bennee@linaro.org X-SA-Exim-Scanned: No (on socrates.bennee.com); SAEximRunCond expanded to false X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 88.198.71.155 Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , greg.bellows@linaro.org Subject: [Qemu-devel] [RCF PATCH 1/8] target-arm/cpu.h: document various program state functions 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.bennee@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 We have a number of program state saving functions (pstate, cpsr, xpsr) which are dependant on the mode the CPU is in. This commit adds a little documentation to each function and asserts to defend against incorrect use. diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 8d04385..5e6df38 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -459,22 +459,34 @@ int arm_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw, #define PSTATE_MODE_EL1t 4 #define PSTATE_MODE_EL0t 0 -/* Return the current PSTATE value. For the moment we don't support 32<->64 bit - * interprocessing, so we don't attempt to sync with the cpsr state used by - * the 32 bit decoder. +/* ARMv8 ARM D1.7 Process state, PSTATE + * + * 31 28 27 24 23 22 21 20 22 21 20 19 16 15 8 7 5 4 0 + * +------+------+-------+-----+--------+---+------+------+-----+------+ + * | NZCV | DAIF | SS IL | EL | nRW SP | Q | GE | IT | JTE | Mode | + * +------+------+-------+-----+--------+---+------+------+-----+------+ + * + * The PSTATE is an abstraction of a number of Return the current + * PSTATE value. This is only valid for A64 hardware although can be + * read when in AArch32 mode. */ static inline uint32_t pstate_read(CPUARMState *env) { int ZF; + g_assert(is_a64(env)); + ZF = (env->ZF == 0); return (env->NF & 0x80000000) | (ZF << 30) | (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | env->pstate | env->daif; } +/* Update the current PSTATE value. This doesn't include nRW which is */ static inline void pstate_write(CPUARMState *env, uint32_t val) { + g_assert(is_a64(env)); + env->ZF = (~val) & PSTATE_Z; env->NF = val; env->CF = (val >> 29) & 1; @@ -483,15 +495,23 @@ static inline void pstate_write(CPUARMState *env, uint32_t val) env->pstate = val & ~CACHED_PSTATE_BITS; } -/* Return the current CPSR value. */ +/* ARMv7-AR ARM B1.3.3 Current Program Status Register, CPSR + * + * Unlike the above PSTATE implementation these functions will attempt + * to switch processor mode when the M[4:0] bits are set. + */ uint32_t cpsr_read(CPUARMState *env); /* Set the CPSR. Note that some bits of mask must be all-set or all-clear. */ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask); -/* Return the current xPSR value. */ +/* ARMv7-M ARM B1.4.2, special purpose program status register xPSR */ static inline uint32_t xpsr_read(CPUARMState *env) { int ZF; + + g_assert(!is_a64(env)); +// g_assert(IS_M(env)); + ZF = (env->ZF == 0); return (env->NF & 0x80000000) | (ZF << 30) | (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27) @@ -503,6 +523,9 @@ static inline uint32_t xpsr_read(CPUARMState *env) /* Set the xPSR. Note that some bits of mask must be all-set or all-clear. */ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) { + g_assert(!is_a64(env)); +// g_assert(IS_M(env)); + if (mask & CPSR_NZCV) { env->ZF = (~val) & CPSR_Z; env->NF = val; diff --git a/target-arm/helper-a64.c b/target-arm/helper-a64.c index cccda74..48ca351 100644 --- a/target-arm/helper-a64.c +++ b/target-arm/helper-a64.c @@ -506,8 +506,8 @@ void aarch64_cpu_do_interrupt(CPUState *cs) env->condexec_bits = 0; } - pstate_write(env, PSTATE_DAIF | PSTATE_MODE_EL1h); env->aarch64 = 1; + pstate_write(env, PSTATE_DAIF | PSTATE_MODE_EL1h); env->pc = addr; cs->interrupt_request |= CPU_INTERRUPT_EXITTB;