Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mh0jD-0007VX-Tr for qemu-devel@nongnu.org; Fri, 28 Aug 2009 08:38:52 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mh0j9-0007TZ-SG for qemu-devel@nongnu.org; Fri, 28 Aug 2009 08:38:51 -0400 Received: from [199.232.76.173] (port=59414 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mh0j9-0007TD-GU for qemu-devel@nongnu.org; Fri, 28 Aug 2009 08:38:47 -0400 Received: from miranda.se.axis.com ([193.13.178.8]:54394) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Mh0j8-0004wu-Vc for qemu-devel@nongnu.org; Fri, 28 Aug 2009 08:38:47 -0400 Date: Fri, 28 Aug 2009 14:33:11 +0200 From: "Edgar E. Iglesias" Subject: Re: [Qemu-devel] Creating an own target. How to deal with Flags and Branches in TCG? Message-ID: <20090828123311.GB23521@edde.se.axis.com> References: <7d63a1530908111042o5b065f4ap3b3dae93ebcb5f2e@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7d63a1530908111042o5b065f4ap3b3dae93ebcb5f2e@mail.gmail.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Klaus F Cc: qemu-devel On Tue, Aug 11, 2009 at 07:42:44PM +0200, Klaus F wrote: > Hi, Hi, Sorry for the late answer, I've been offline... > I'm interested in creating my own target for qemu > My goal is to learn how to implement own target processors and own > target peripherals with qemu. > I'm having minor difficulties in understanding how comditional branches > and the handling of flags is done. > I'll continue looking by myself, but if any of you has some ncie > pointers, then I would really appreciate it. > tcg/README is a nice staring point, > but I didn't understand the section about labels and conditions that > well. > Currently I'm looking at the generation of an own target CPU. > I can already execute my first few instructions, which load and modify > registers. > Now I'd like to work on status registers and conditional branches. > What I did so far: > - As starting point I took the Xilinx Microblaze target (randomly > chosen, as I thought an FPGA core might be relatively simple) The microblaze port is one of the smaller and simpler ones, so yes it probably is a good starting point. > - I am using gen_intermediate_code_internal() and replaced only the > part for decoding instructions > - I added decoding for a few instructions and can now load registers > and perform ALU operations > What I am not 100% clear about is how flags (Carry,Zero, . . .) are > synchroniced between the TCG engine und my virtual target. Regarding status flags, microblaze might not be the best target to look at because it doesn't have many flags. Microblaze does not store the traditional Z, N nor V flags in a status reg. They are only used in the pipe to properly execute the compare-and-conditionally-branch and compare instructions. Carry is there though. See helper_addkc() and helper_subkc() for more detail on how carry is computed and updated. > What I'd like to know > - which tcg_gen commands modify flags and which ones don't ? TCG does not really have flags. You have to implement emulation of whatever target flags you need on top of TCG. > - how can I forward the flag values to my target status register ? The same way you would set or clear bits in any TCG variable. > - how can I conditionally branch on flags? For the microblaze target, I suggest looking at eval_cc(), eval_cond_jmp() and dec_bcc(). Cheers