Received: from eggs.gnu.org ([2001:4830:134:3::10]:60768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atcfO-000453-OF for qemu-devel@nongnu.org; Fri, 22 Apr 2016 11:06:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1atcfK-00088j-03 for qemu-devel@nongnu.org; Fri, 22 Apr 2016 11:06:46 -0400 Received: from nougat.ucs.ed.ac.uk ([129.215.13.205]:64098) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atcfJ-000874-OI for qemu-devel@nongnu.org; Fri, 22 Apr 2016 11:06:41 -0400 Received: from lmtp1.ucs.ed.ac.uk (lmtp1.ucs.ed.ac.uk [129.215.149.64]) by nougat.ucs.ed.ac.uk (8.13.8/8.13.4) with ESMTP id u3MF6Jnc021083 for ; Fri, 22 Apr 2016 16:06:24 +0100 (BST) Received: from ardgay.inf.ed.ac.uk (ardgay.inf.ed.ac.uk [129.215.25.204]) by lmtp1.ucs.ed.ac.uk (8.13.8/8.13.7) with ESMTP id u3MF6Dm8006839 for ; Fri, 22 Apr 2016 16:06:18 +0100 (BST) From: Tom Spink Message-ID: <571A3DE5.4010209@sms.ed.ac.uk> Date: Fri, 22 Apr 2016 16:06:13 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: [Qemu-devel] ARM PC-relative Loads, and TBs in soft MMU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hello, I have a question about ARM PC-relative load instructions in softmmu execution, and how the PC is constant-folded at JIT compilation time into a TB. I have observed in translate.c the following code: /* Set a variable to the value of a CPU register. */ static void load_reg_var(DisasContext *s, TCGv_i32 var, int reg) { if (reg == 15) { uint32_t addr; if (s->thumb) addr = (long)s->pc + 2; else addr = (long)s->pc + 4; tcg_gen_movi_i32(var, addr); } else { tcg_gen_mov_i32(var, cpu_R[reg]); } } This constant folds the value of the PC into the TCG mov for (potential) use by a memory operation, but it is my understanding that this will be the *virtual* PC. It is also my understanding that since TBs are physically indexed in the TB cache, they aren't invalidated when the guest page tables change. So, my question is, how can a TB for a particular block containing a constant folded *virtual* PC work, if the MMU mappings change and a different virtual address is used to access the same physical address? E.g. assume we have an instruction such as: ldr r0, [pc, #8] If this is compiled in a block that begins at virtual address 0x10000, then the load will be emitted as a constant load from address 0x10008 (and will be subject to the usual TLB lookup code). But, if the MMU mappings change, and the block is entered from virtual address 0x20000 (because 0x20000 now points to the same physical page), then the load will be incorrect, as it would still be accessing address 0x10000, but should actually be accessing address 0x20008. Have I made any incorrect assumptions, or is there something else going on that I'm not aware of? Thanks in advance for any information you can give me, Tom -- Kindest Regards, Tom Spink University of Edinburgh The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.