Received: from eggs.gnu.org ([2001:4830:134:3::10]:47554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwa7s-0005sq-Dh for qemu-devel@nongnu.org; Tue, 18 Oct 2016 15:32:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwa7o-0001Y5-Gi for qemu-devel@nongnu.org; Tue, 18 Oct 2016 15:32:40 -0400 Received: from mail-out.m-online.net ([2001:a60:0:28:0:1:25:1]:38090) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bwa7o-0001Xd-5c for qemu-devel@nongnu.org; Tue, 18 Oct 2016 15:32:36 -0400 References: <20160927233049.5429-1-marex@denx.de> <20160927233049.5429-2-marex@denx.de> <20d61df8-b345-b097-8d9b-4a619849d86c@twiddle.net> <82ddeb82-768b-57d1-5962-a6940e5001c7@denx.de> <496742f4-af10-e029-62a2-f2c5054c9303@twiddle.net> From: Marek Vasut Message-ID: <15816d97-1ea9-44df-01d0-10ee10430af2@denx.de> Date: Tue, 18 Oct 2016 20:32:39 +0200 MIME-Version: 1.0 In-Reply-To: <496742f4-af10-e029-62a2-f2c5054c9303@twiddle.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/7] nios2: Add architecture emulation support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson , qemu-devel@nongnu.org Cc: Jeff Da Silva , Chris Wulff , Sandra Loosemore , Yves Vandervennet , Ley Foon Tan On 10/18/2016 05:31 PM, Richard Henderson wrote: > On 10/17/2016 08:58 PM, Marek Vasut wrote: >>> There's no particular reason why R_PC needs to be 64; if you change it >>> to 32, you can simplify this. >> >> I believe this is in fact needed, see [1] page 18 (section 2, Register >> file), quote: >> >> " >> The Nios II architecture supports a flat register file, consisting of >> thirty-two 32-bit general-purpose integer >> registers, and up to thirty-two 32-bit control registers. The >> architecture supports supervisor and user >> modes that allow system code to protect the control registers from >> errant applications. >> " >> >> So the CPU supports 32 general purpose regs (R_ZERO..R_RA), then up-to >> 32 Control registers (CR_STATUS..CR_MPUACC) and then the PC . > > The architecture manual doesn't imply anything about the numbering of > these registers. But the instruction encoding does, so I can use the field from the instruction to directly index the register array. >>> You're not doing anything to make sure that r0 reads as 0, and ignores >>> writes. You need to look at target-alpha, target-mips, or target-sparc >>> to see various ways in which a zero register may be handled. >> >> Any hint on this one ? > > Well, there's three hints right there. But look at target-alpha, and > the functions load_gpr and dest_gpr (note that for alpha, 31 is the zero > register). Thanks, I hope this is fixed now, although I mostly special-case the R_ZERO handling throughout the code. Any writes to R_ZERO are now ignored and any usage is converted to mov/movi instructions where applicable. >>> Since divide-by-zero is undefined, this can be done with >>> >>> TCGv t0 = tcg_const_tl(0); >>> tcg_gen_setcond_tl(TCG_COND_EQ, t0, dc->cpu_R[instr->b], t0); >>> tcg_gen_or_tl(t0, t0, dc->cpu_R[instr->b]); >>> tcg_gen_divu_tl(dc->cpu_R[instr->c], dc->cpu_R[instr->a], t0); >>> tcg_temp_free_tl(t0); >> >> Just so I get it completely, isn't this handled somehow by the >> tcg_gen_divu_tl() itself ? > > No, tcg_gen_divu_tl is a plain host divide instruction. > > For guests that require exceptions to be raised, we handle those > manually beforehand. At which point extra checks in tcg_gen_divu_tl are > wasted. OK, got it, thanks! -- Best regards, Marek Vasut