From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:33246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq8R7-0007dh-QF for qemu-devel@nongnu.org; Wed, 25 Jan 2012 14:23:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rq8R6-0002jx-5t for qemu-devel@nongnu.org; Wed, 25 Jan 2012 14:23:13 -0500 Received: from mail-qy0-f173.google.com ([209.85.216.173]:38297) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq8R6-0002jf-3e for qemu-devel@nongnu.org; Wed, 25 Jan 2012 14:23:12 -0500 Received: by qcse13 with SMTP id e13so3121421qcs.4 for ; Wed, 25 Jan 2012 11:23:11 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 25 Jan 2012 19:23:10 +0000 Message-ID: From: Peter Maydell Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] TCG register allocator List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xin Tong Cc: qemu-devel On 25 January 2012 19:10, Xin Tong wrote: Peter Maydell wrote: >> cpu_restore_state() calls gen_intermediate_code_pc() to >> request a retranslation of the TB with extra info to allow >> us to do a host-PC-to-guest-PC lookup >> =C2=A0* Note that gen_intermediate_code_pc() overwrites the generated >> code that already exists in memory, and stops as soon as it >> reaches the point of the exception. This is harmless because >> we are just rewriting the same bytes to memory that were there >> already, but disastrous if... > in the case you described above, which code guarantees that the > re-generated code is laid down in the place where the old code is. > This has to be do somewhere in tcg. Actually, it's not in TCG but in the bit of QEMU which calls TCG. When we first translate a block of code we decide where its generated code will sit (in exec.c:tb_gen_code()) and set tb->tc_ptr to point at this location. Then when translate-all.c:cpu_gen_code() does this first translation it passes tcg_gen_code() a gen_code_buf argument which is this tb->tc_ptr. Later if we need to do a restore, translate-all.c:cpu_restore_state() calls tcg_gen_code_search_pc(), and again it passes a gen_code_buf argument for where generated code should be written. It uses tb->tc_ptr for the TranslationBlock, so it will always be at the same place. -- PMM