Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MavN2-0000mc-HI for qemu-devel@nongnu.org; Tue, 11 Aug 2009 13:42:48 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MavN2-0000lj-09 for qemu-devel@nongnu.org; Tue, 11 Aug 2009 13:42:48 -0400 Received: from [199.232.76.173] (port=51563 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MavN1-0000lZ-Hs for qemu-devel@nongnu.org; Tue, 11 Aug 2009 13:42:47 -0400 Received: from ey-out-1920.google.com ([74.125.78.148]:59754) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MavN0-0007yv-Mq for qemu-devel@nongnu.org; Tue, 11 Aug 2009 13:42:47 -0400 Received: by ey-out-1920.google.com with SMTP id 5so889313eyb.4 for ; Tue, 11 Aug 2009 10:42:44 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 11 Aug 2009 19:42:44 +0200 Message-ID: <7d63a1530908111042o5b065f4ap3b3dae93ebcb5f2e@mail.gmail.com> From: Klaus F Content-Type: multipart/alternative; boundary=0016e6d644efde59e50470e13ac8 Subject: [Qemu-devel] Creating an own target. How to deal with Flags and Branches in TCG? List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel --0016e6d644efde59e50470e13ac8 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi, 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) - 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. What I'd like to know - which tcg_gen commands modify flags and which ones don't ? - how can I forward the flag values to my target status register ? - how can I conditionally branch on flags? Let's assume my target had one AND instruction, that ands two registers, but does not modify the status registers and an alternative instruction, that modifies the statis registers. How would I model this with TCG Example code piece for an imaginary target platform MVI R0, 0x03 ; R0 <- 0x03 MVI R1, 0x06 ; R1 <- 0x06 MVI R2, 0x0c ; R2 <- 0x0c ANDF R3,R0,R2 ; R3 <- R0 & R2 / additionally set zero flag if R3 is zero AND R4,R0,R1 ; R4 <- R0 & R1 / but do NOT change the flags BRZ PC+0x10 NEXT_INSTRUCTION I would translate this into tcg_gen_movi_tl(cpu_R[0], 0x03); tcg_gen_movi_tl(cpu_R[1], 0x06); tcg_gen_movi_tl(cpu_R[2], 0x0c); tcg_gen_add_tl(cpu_R[3].cpu_R[0],cpu_R[2]); // Now I'd like to keep the flags tcg_gen_add_tl(cpu_R[4],cpu_R[0],cpu_R[1]); // Now I'd like to discard the flags // here I'd like to jump conditionally to PC+0x10 thanks in advance for any pointers / suggestions Klaus --0016e6d644efde59e50470e13ac8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

I'm interested in creating my own target for qemu
My goal= is to learn how to implement own target processors and own target peripher= als with qemu.
I'm having minor difficulties in understanding how co= mditional branches and the handling of flags is done.
I'll continue looking by myself, but if any of you has some ncie pointe= rs, then I would really appreciate it.


tcg/README is a nice star= ing point,
but I didn't understand the section about labels and con= ditions 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 regist= ers.
Now I'd like to work on status registers and conditional branch= es.

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 simp= le)
- 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 pe= rform ALU operations

What I am not 100% clear about is how flags (Ca= rry,Zero, . . .) are synchroniced between the TCG engine und my virtual tar= get.
What I'd like to know
- which tcg_gen commands modify flags and whic= h ones don't ?
- how can I forward the flag values to my target stat= us register ?
- how can I conditionally branch on flags?

Let'= s assume my target had one AND instruction, that ands two registers, but do= es not modify the status registers and an alternative
instruction, that modifies the statis registers. How would I model this wit= h TCG

Example code piece for an imaginary target platform
MVI R0,= 0x03=A0=A0 ; R0 <- 0x03
MVI R1, 0x06=A0=A0 ; R1 <- 0x06
MVI R2= , 0x0c=A0 ; R2 <- 0x0c
ANDF R3,R0,R2=A0=A0 ; R3 <- R0 & R2 / additionally set zero flag if = R3 is zero
AND=A0 R4,R0,R1=A0=A0 ; R4 <- R0 & R1 / but do NOT cha= nge the flags
BRZ PC+0x10
NEXT_INSTRUCTION

I would translate t= his into

tcg_gen_movi_tl(cpu_R[0], 0x03);
tcg_gen_movi_tl(cpu_R[1], 0x06); tcg_gen_movi_tl(cpu_R[2], 0x0c);
tcg_gen_add_tl(cpu_R[3].cpu_R[0],cpu_R[= 2]);
// Now I'd like to keep the flags
tcg_gen_add_tl(cpu_R[4],cp= u_R[0],cpu_R[1]);
// Now I'd like to discard the flags
// here I&= #39;d like to jump conditionally to PC+0x10


thanks in advance for any pointers / suggestions

Klaus

--0016e6d644efde59e50470e13ac8--