From patchwork Mon Dec 12 15:37:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 5603 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id DFD1623E01 for ; Mon, 12 Dec 2011 15:37:40 +0000 (UTC) Received: from mail-bw0-f52.google.com (mail-bw0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id C6D73A1856E for ; Mon, 12 Dec 2011 15:37:40 +0000 (UTC) Received: by bke17 with SMTP id 17so7486085bke.11 for ; Mon, 12 Dec 2011 07:37:40 -0800 (PST) Received: by 10.204.152.138 with SMTP id g10mr8153106bkw.36.1323704260465; Mon, 12 Dec 2011 07:37:40 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.129.2 with SMTP id hg2cs50826bkc; Mon, 12 Dec 2011 07:37:40 -0800 (PST) Received: by 10.14.7.68 with SMTP id 44mr2796482eeo.23.1323704258969; Mon, 12 Dec 2011 07:37:38 -0800 (PST) Received: from mail-ey0-f178.google.com (mail-ey0-f178.google.com [209.85.215.178]) by mx.google.com with ESMTPS id x5si9564959eeb.213.2011.12.12.07.37.38 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 12 Dec 2011 07:37:38 -0800 (PST) Received-SPF: neutral (google.com: 209.85.215.178 is neither permitted nor denied by best guess record for domain of david.gilbert@linaro.org) client-ip=209.85.215.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.215.178 is neither permitted nor denied by best guess record for domain of david.gilbert@linaro.org) smtp.mail=david.gilbert@linaro.org Received: by eaad13 with SMTP id d13so1101988eaa.37 for ; Mon, 12 Dec 2011 07:37:38 -0800 (PST) Received: by 10.204.136.220 with SMTP id s28mr10505518bkt.59.1323704257733; Mon, 12 Dec 2011 07:37:37 -0800 (PST) Received: from davesworkthinkpad (gbibp9ph1--blueice3n2.emea.ibm.com. [195.212.29.84]) by mx.google.com with ESMTPS id zv9sm32635135bkb.0.2011.12.12.07.37.36 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 12 Dec 2011 07:37:36 -0800 (PST) Date: Mon, 12 Dec 2011 15:37:31 +0000 From: "Dr. David Alan Gilbert" To: qemu-devel@nongnu.org Cc: patches@linaro.org, peter.maydell@linaro.org Subject: [PATCH] ARM - Remove fixed map code buffer restriction Message-ID: <20111212153730.GA9583@davesworkthinkpad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) On ARM, don't map the code buffer at a fixed location, and fix up the call/goto tcg routines to let it do long jumps. Mapping the code buffer at a fixed address could sometimes result in it being mapped over the top of the heap with pretty random results. This diff is against v1.0. Signed-off-by: Dr. David Alan Gilbert --- exec.c | 4 +--- tcg/arm/tcg-target.c | 31 ++++++++++++------------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/exec.c b/exec.c index 6b92198..ef83da1 100644 --- a/exec.c +++ b/exec.c @@ -497,9 +497,7 @@ static void code_gen_alloc(unsigned long tb_size) if (code_gen_buffer_size > (512 * 1024 * 1024)) code_gen_buffer_size = (512 * 1024 * 1024); #elif defined(__arm__) - /* Map the buffer below 32M, so we can use direct calls and branches */ - flags |= MAP_FIXED; - start = (void *) 0x01000000UL; + /* Keep the buffer no bigger than 16GB to branch between blocks */ if (code_gen_buffer_size > 16 * 1024 * 1024) code_gen_buffer_size = 16 * 1024 * 1024; #elif defined(__s390x__) diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c index e05a64f..730d913 100644 --- a/tcg/arm/tcg-target.c +++ b/tcg/arm/tcg-target.c @@ -842,6 +842,12 @@ static inline void tcg_out_st8(TCGContext *s, int cond, tcg_out_st8_12(s, cond, rd, rn, offset); } +/* The _goto case is normally between TBs within the same code buffer, + and with the code buffer limited to 16GB we shouldn't need the long + case. + + .... except to the prologue that is in its own buffer. + */ static inline void tcg_out_goto(TCGContext *s, int cond, uint32_t addr) { int32_t val; @@ -855,22 +861,20 @@ static inline void tcg_out_goto(TCGContext *s, int cond, uint32_t addr) if (val - 8 < 0x01fffffd && val - 8 > -0x01fffffd) tcg_out_b(s, cond, val); else { -#if 1 - tcg_abort(); -#else if (cond == COND_AL) { tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4); - tcg_out32(s, addr); /* XXX: This is l->u.value, can we use it? */ + tcg_out32(s, addr); } else { tcg_out_movi32(s, cond, TCG_REG_R8, val - 8); tcg_out_dat_reg(s, cond, ARITH_ADD, TCG_REG_PC, TCG_REG_PC, TCG_REG_R8, SHIFT_IMM_LSL(0)); } -#endif } } +/* The call case is mostly used for helpers - so it's not unreasonable + for them to be beyond branch range */ static inline void tcg_out_call(TCGContext *s, uint32_t addr) { int32_t val; @@ -887,20 +891,9 @@ static inline void tcg_out_call(TCGContext *s, uint32_t addr) tcg_out_bl(s, COND_AL, val); } } else { -#if 1 - tcg_abort(); -#else - if (cond == COND_AL) { - tcg_out_dat_imm(s, cond, ARITH_ADD, TCG_REG_R14, TCG_REG_PC, 4); - tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4); - tcg_out32(s, addr); /* XXX: This is l->u.value, can we use it? */ - } else { - tcg_out_movi32(s, cond, TCG_REG_R9, addr); - tcg_out_dat_reg(s, cond, ARITH_MOV, TCG_REG_R14, 0, - TCG_REG_PC, SHIFT_IMM_LSL(0)); - tcg_out_bx(s, cond, TCG_REG_R9); - } -#endif + tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R14, TCG_REG_PC, 4); + tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4); + tcg_out32(s, addr); } }