Received: from eggs.gnu.org ([2001:4830:134:3::10]:36870) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhpeA-0005Ir-V0 for qemu-devel@nongnu.org; Thu, 01 Oct 2015 22:00:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zhpe4-0007TG-DP for qemu-devel@nongnu.org; Thu, 01 Oct 2015 22:00:30 -0400 Received: from blu004-omc2s9.hotmail.com ([65.55.111.84]:63787) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhpe4-0007T1-88 for qemu-devel@nongnu.org; Thu, 01 Oct 2015 22:00:24 -0400 Message-ID: Date: Fri, 2 Oct 2015 10:02:34 +0800 From: Chen Gang MIME-Version: 1.0 References: <1443703035-4433-1-git-send-email-gang.chen.5i5j@gmail.com> <560DD1AB.7080808@twiddle.net> <560DDE8D.8040202@ezchip.com> In-Reply-To: <560DDE8D.8040202@ezchip.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3] target-tilegx: Support iret instruction and related special registers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Chris Metcalf , Richard Henderson , gang.chen.5i5j@gmail.com, peter.maydell@linaro.org Cc: qemu-devel@nongnu.org OK=2C thanks. I shall try to send patch v4 for it within 2 days. On 10/2/15 09:31=2C Chris Metcalf wrote: > On 10/1/2015 8:36 PM=2C Richard Henderson wrote: >> On 10/01/2015 10:37 PM=2C gang.chen.5i5j@gmail.com wrote: >>> { >>> mtspr INTERRUPT_CRITICAL_SECTION=2C r3 >>> shli r2=2C r2=2C SPR_EX_CONTEXT_0_1__ICS_SHIFT >>> } >>> >>> { >>> mtspr EX_CONTEXT_0_0=2C lr >>> ori r2=2C r2=2C RETURN_PL >>> } >>> >>> { >>> or r0=2C r1=2C r0 >>> mtspr EX_CONTEXT_0_1=2C r2 >>> } >>> >>> iret >>> >>> jrp lr >>> >>> Until now=2C EX_CONTEXT_0_0 and EX_CONTEXT_0_1 are only used in mtspr= =2C so >>> just skip them=2C at present. "jrp lr" in __longjmp is for historical >>> reasons=2C and might get removed in the future. >> >> So=2C really=2C iret is supposed to branch to EX_CONTEXT_0_0=2C and (pre= sumably) validate the privilege level in EX_CONTEXT_0_1 continues to be use= r-mode. >=20 > Yes=2C I gave the same feedback earlier today. EX_CONTEXT_0_1 should be = either 0 or 1 to set INTERRUPT_CRITICAL_SECTION appropriately=2C and raise = GPV for any other value. (Obviously it's more complex if you're really emu= lating system software=2C but for now that's out of scope=2C I think.) >=20 >> >>> + case OE_RR_X1(IRET): >>> + if (srca) { >>> + return TILEGX_EXCP_OPCODE_UNIMPLEMENTED=3B >>> + } >>> + srca =3D TILEGX_R_LR=3B >>> + mnemonic =3D "iret"=3B >>> + goto do_jr=3B >> >> which means this is wrong=2C but just happens to work for __longjmp. >> >> It appears that the entire point of this iret path is to atomically bran= ch and set INTERRUPT_CRITICAL_SECTION at the same time. So=2C this isn't c= omplete. >> >> What INTERRUPT_CRITICAL_SECTION is supposed to *do* at user mode=2C I do= n't know. >=20 > It disables interrupts from being delivered. This means asynchronous int= errupts get deferred until ICS is set back to zero=2C and synchronous inter= rupts (page fault=2C etc) cause a double-fault instead. ICS is automatical= ly set on entry to interrupt handlers=2C so the handler has time to acquire= any information about the interrupt from SPRs=2C and it is expected that I= CS is cleared as soon as possible. ICS can also be used before returning f= rom interrupts if you need to do something like adjust the interrupt mask p= rior to returning. >=20 --=20 Chen Gang (=E9=99=88=E5=88=9A) Open=2C share=2C and attitude like air=2C water=2C and life which God bless= ed