Received: from eggs.gnu.org ([2001:4830:134:3::10]:57130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrcRX-0005bt-Cj for qemu-devel@nongnu.org; Tue, 25 Jun 2013 19:14:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UrcRV-0000Wt-J4 for qemu-devel@nongnu.org; Tue, 25 Jun 2013 19:14:35 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:46817) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrcRV-0000Wl-Ah for qemu-devel@nongnu.org; Tue, 25 Jun 2013 19:14:33 -0400 From: Mike Frysinger Date: Tue, 25 Jun 2013 19:14:30 -0400 References: <1371453226-11396-1-git-send-email-vapier@gentoo.org> <1371453383-11484-1-git-send-email-vapier@gentoo.org> <51CA0A6D.8030803@twiddle.net> In-Reply-To: <51CA0A6D.8030803@twiddle.net> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1784153.n3bXcOuXmf"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201306251914.35602.vapier@gentoo.org> Subject: Re: [Qemu-devel] [PATCH 2/5] Blackfin: initial port List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: qemu-devel@nongnu.org --nextPart1784153.n3bXcOuXmf Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable On Tuesday 25 June 2013 17:23:57 Richard Henderson wrote: whee, got a review! :) i've snipped items that were obvious in the "i'll g= o=20 do this" category rather than just copying & pasting "OK" many times. got = a=20 long flight coming up soon, so hopefully i can tackle the majority of this = work=20 then. > > diff --git a/target-bfin/bfin-sim.c b/target-bfin/bfin-sim.c >=20 > Why this separate file from translate.c? because this port is based on the GNU/sim Blackfin port. bfin-sim.c focuse= s on=20 the actual opcode translation while the higher level file (translate.c in Q= EMU=20 and interp.c in GNU/sim) takes care of the higher layers (like clock tickin= g). =20 i like keeping the core structure the same between the two sims so that i c= an=20 more easily merge changes between them. > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include >=20 > Certainly you shouldn't need these, since this isn't a separately > compiled object -- you're included from translate.c. yes, this is most likely true. it's due to the previous reason. maybe i=20 should make it a sep compiled file then there won't be any confusion ... > > +#define HOST_LONG_WORD_SIZE (sizeof(long) * 8) >=20 > You mean TCG_TARGET_REG_BITS? maybe? this is for extracting target encoded immediates and properly=20 extending them up to the system that is running the code (e.g. x86_64) so t= hat=20 it can then be checked naturally (like comparing it to a -1). but this is= =20 done in the decode logic, not in the tcg output logic, so i'm not sure TCG = is=20 the right abstraction. > > +static TCGv > > +get_allreg(DisasContext *dc, int grp, int reg) > > +{ > > + TCGv *ret =3D cpu_regs[(grp << 3) | reg]; > > + if (ret) { > > + return *ret; > > + } > > + abort(); > > + illegal_instruction(dc); > > +} >=20 > Well, which is it? abort or illegal_instruction. i had this in there while doing the initial port to track down bad things. = i=20 can probably cut it over to illegal_instruction() now. > And come to that, how is > abort any better than SEGV from dereferecing the null? Certainly the lat= er > will generate a faster translator... QEMU doesn't need any help segfaulting :p. an abort() is much better at=20 showing the source of the problem. > > +decode_multfunc_tl(DisasContext *dc, int h0, int h1, int src0, int src= 1, > > + int mmod, int MM, TCGv psat) > > +{ > > + TCGv s0, s1, val; > > + > > + s0 =3D tcg_temp_local_new(); >=20 > You'll really want to avoid local temps and branches, if at all possible.= =20 > For some of the more complex stuff that you're open-coding, you may be > better off with helper functions instead. it seemed like having generated (and cached) opcodes was better than relyin= g=20 on helpers since helpers requires interrupting the native code flow and muc= k=20 around with state ? is there a good (or even semi-decent) rule of thumb i = can=20 use to decide when to use one over the other ? > > +static void > > +saturate_s32(TCGv_i64 val, TCGv overflow) >=20 > I shall now stop mentioning movcond. I sense there are many locations to > come. looks like movcond was introduced after i did the initial (bulk) port. so= =20 there are probably many locations that can take advantage of it. i'll have= to=20 go through the code top-to-bottom looking for things. and probably look at= =20 the history of tcg/README to see what other interesting opcodes have been=20 added since. > > + } else if (prgfunc =3D=3D 11 && poprnd < 6) { > > + /* TESTSET (Preg{poprnd}); */ > > + TCGv tmp =3D tcg_temp_new(); > > + tcg_gen_qemu_ld8u(tmp, cpu_preg[poprnd], dc->mem_idx); > > + tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_cc, tmp, 0); > > + tcg_gen_ori_tl(tmp, tmp, 0x80); > > + tcg_gen_qemu_st8(tmp, cpu_preg[poprnd], dc->mem_idx); > > + tcg_temp_free(tmp); >=20 > I'll note that this is fine for system code, but for user code ought to be > atomic. There are a bunch of really bad examples in the tree, and no real > good solutions atm. i general, i completely agree with you. in practice, i think a (mis)featur= e=20 of the Blackfin arch helps out here. TESTSET doesn't work on cached memory= ,=20 and it only works on system memory (i.e. not L1), and every Linux build run= s=20 with caches turned on. so maybe flaky misbehavior is a good thing ? :) i can drop a note in there noting the issue though > > + /* Everything here needs to be aligned, so check once */ > > + gen_align_check(dc, cpu_spreg, 4, false); >=20 > You ought not need to generate explicit alignment checks. Yes, we don't = do > that correctly for user-mode, but we do for system mode. >=20 > My hope is that user mode eventually has the option of using the system > mode page tables too -- there are just too many things that don't work > correctly when host and target page sizes don't match, or the host and > target don't have the same unaligned access characteristics. i had this code because it wasn't working in user mode, and someone in a=20 previous review suggested i check out gen_helper_memalign(). i actually ha= ve=20 this disabled by default because the speed impact is fairly substantial. i= =20 was debating turning this into a configure time check. > > + } else if (grp =3D=3D 4 && (reg =3D=3D 0 || reg =3D=3D 2)) { > > + /* Push A#.X */ > > + tmp64 =3D tcg_temp_new_i64(); > > + tcg_gen_shri_i64(tmp64, cpu_areg[reg >> 1], 32); > > + tmp =3D tcg_temp_new(); > > + tcg_gen_trunc_i64_i32(tmp, tmp64); > > + tcg_temp_free_i64(tmp64); > > + tcg_gen_andi_tl(tmp, tmp, 0xff); >=20 > Do we ever allow the high 24 bits to be non-zero? Is this andi actually > redundant? yes & no. in the hardware, it'll always be 0. there is some code which wi= ll=20 might sign extend things (so that you can correctly compare the 40bit=20 accumulator using 64bit regs), and that would interact badly here. maybe i= t=20 would be better to drop this and force the accumulator handling code to do = the=20 right thing with the sign rather than store the result. > > + if (W =3D=3D 1) { > > + /* [--SP] =3D ({d}R7:imm{dr}, {p}P5:imm{pr}); */ > > + if (d) { > > + for (i =3D dr; i < 8; i++) { > > + tcg_gen_subi_tl(cpu_spreg, cpu_spreg, 4); > > + tcg_gen_qemu_st32(cpu_dreg[i], cpu_spreg, dc->mem_idx); > > + } > > + } >=20 > What's the cpu exception effect of the second store causing a page fault? > Normally one needs to do the address increment in a temporary and only > update the real SP register at the end, so that the instruction can be > restarted. this was me being lazy when getting started with the port ;). the GNU/sim= =20 code matches the hardware and that is as you suspected -- the SP reg isn't= =20 updated until after all the push/pops finish. i wasn't sweating the differ= ence=20 here too much as in user mode, the exception would just kill the program=20 (ignoring apps that catch like SIGSEGV). i'll have to generate a tmp reg based on SP and do it correctly though now= =20 that this port is out of the infant stage. > > +#include "linux-fixed-code.h" > > + > > +static uint32_t bfin_lduw_code(DisasContext *dc, target_ulong pc) > > +{ > > +#ifdef CONFIG_USER_ONLY > > + /* Intercept jump to the magic kernel page */ > > + if (((dc->env->personality & 0xff/*PER_MASK*/) =3D=3D 0/*PER_LINUX= */) && > > + (pc & 0xFFFFFF00) =3D=3D 0x400) { > > + uint32_t off =3D pc - 0x400; > > + if (off < sizeof(bfin_linux_fixed_code)) { > > + return ((uint16_t)bfin_linux_fixed_code[off + 1] << 8) | > > + bfin_linux_fixed_code[off]; > > + } > > + } > > +#endif >=20 > Surely this memory setup belongs in linux-user/. i couldn't find good examples previously to make this work so i put it in h= ere. =20 i came across the arm handling of its fixed code recently though (which i t= hink=20 does it in linux-user), so i'll see about moving it there. > > +/* Interpret a single Blackfin insn; breaks up parallel insns */ > > +static void > > +interp_insn_bfin(DisasContext *dc) > > +{ > > + _interp_insn_bfin(dc, dc->pc); >=20 > I'd prefer a suffix like "1" rather than a prefix of "_". this matches the GNU/sim code, so i'd prefer to stick to that where possibl= e. =20 underscore prefix is a common "this is internal" indicator. > > +static inline void cpu_get_tb_cpu_state(CPUArchState *env, target_ulong > > *pc, + target_ulong *cs_base, int > > *flags) +{ > > + *pc =3D cpu_get_pc(env); > > + *cs_base =3D 0; > > + *flags =3D env->astat[ASTAT_RND_MOD]; > > +} >=20 > You'll probably be better off with a bit that notes whether the loop > registers are active, or something, so that you don't have to always > generate code that handles them. whether loop registers are active is purely based on the PC and the current= =20 values in the loop registers/counters. the hardware logic is basically: # After every single insn is executed. oldpc =3D PC PC +=3D insn_length; if (oldpc =3D=3D LB1 && LC1) { PC =3D LT1; --LC1; } if (oldpc =3D=3D LB0 && LB0) { PC =3D LT0; --LC0; } i didn't think it was really possible to check the cpu state at runtime sin= ce=20 ideally you'd generate a bunch of TB's, cache them, and then let them run=20 w/out invoking the translator again. > > +DEF_HELPER_3(raise_exception, void, env, i32, i32) >=20 > Lots of these can use better settings for flags. Here, the only side > effect is to raise an exception, which leads to reading the globals. So > TCG_CALL_NO_WG. the flags are newer than the port, so i'll have to go through them all for = a=20 refresh > > +static void gen_goto_tb(DisasContext *dc, int tb_num, TCGv dest) > > +{ > > +/* > > + TranslationBlock *tb; > > + tb =3D dc->tb; > > + > > + if ((tb->pc & TARGET_PAGE_MASK) =3D=3D (dest & TARGET_PAGE_MASK)) { > > + tcg_gen_goto_tb(tb_num); > > + tcg_gen_mov_tl(cpu_pc, dest); > > + tcg_gen_exit_tb((long)tb + tb_num); > > + } else */{ > > + gen_astat_update(dc, false); > > + tcg_gen_mov_tl(cpu_pc, dest); > > + tcg_gen_exit_tb(0); > > + } >=20 > Why the astat update here, when you have it on almost no other exits from > the tb? it's really the only way i could get it to [mostly] work :/. i tried to fi= gure=20 out how x86 was handling its delayed eflags updates (since Blackfin will do= =20 pretty much the same exact thing for the same reason), but i failed at that= =20 too. in general, the TB logic is magic to me. there are a number of optimizatio= ns=20 that are blocked because i haven't been able to figure it out. i'm surpris= ed=20 it really works at all. you can see how my gen_goto_tb always does=20 tct_gen_exit_tb(0) which forces a PC look up every time. =2Dmike --nextPart1784153.n3bXcOuXmf Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQIcBAABAgAGBQJRyiRbAAoJEEFjO5/oN/WBlPgP/j3c0wWay7awQMwNLSRS9gPn wAAsnhoHh2mmLI8MFu+HS5XMhlDrKqzwAxvR9PcMCVS4q07ExMonWsbRg2uj8d5Y flLhXZlpUAczSV/CxOY1EpdVKOrklRkNiAf+U2RLBGYU8PEs5b1QVi1sbVwC6/MW NeX/W3JA+t3UZQKN0v3NKYcGzb70YGfCeKc6LgyeOG/xh65YFW52wLkv5Naz89YA 0siVqD+xHJLyibmtaZziXsJzKnf90AR/3GriebUACtEcjijlTbK5tejOdQt630ew vIpRla8+TeFQM3ozxQfw5LQFO77ZdCzATwBTtHLsfQZpb+HC3RN8PR5PWbDg4ptY QTA3znTjIf0cidWNcYiNGgFruDDLZMJIdq4ZPaK1PYFagr3n9o7VvNCSrMzDTdDD zmtnJ5z3hgCCrOg5ZN9UGfC/VOQyA/ftGf24NE7wjFpSZeAPDvtBxxdoW+N6upmK /feSSVSTdTyCVr/sSfilPWXI2KPncfo6NIZMdb1OKAwfHuTymP4i2P7LdQICKvsH xg7oUqk21tTwGCE3vRyFFrh9c12ybvrGD4Cj+3Pk9LCcNyGOhIlZ9nmaU8AHXvC9 BT9j5UBIZC2/agsGq2JRkcBrB2yNZkFP7VtcJrRC/Q1X0Recw9cagtdfx2GLIlij s4CoWTknbvvJXHLAqPnP =igcm -----END PGP SIGNATURE----- --nextPart1784153.n3bXcOuXmf--