From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEqwp-0002Cu-7I for qemu-devel@nongnu.org; Thu, 20 Sep 2012 20:18:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TEqwo-0005sS-1F for qemu-devel@nongnu.org; Thu, 20 Sep 2012 20:18:23 -0400 Received: from mail-lb0-f173.google.com ([209.85.217.173]:51669) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEqwn-0005s1-Pc for qemu-devel@nongnu.org; Thu, 20 Sep 2012 20:18:21 -0400 Received: by mail-lb0-f173.google.com with SMTP id gm13so3065486lbb.4 for ; Thu, 20 Sep 2012 17:18:21 -0700 (PDT) From: Max Filippov Date: Fri, 21 Sep 2012 04:18:08 +0400 Message-Id: <1348186688-29410-3-git-send-email-jcmvbkbc@gmail.com> In-Reply-To: <1348186688-29410-1-git-send-email-jcmvbkbc@gmail.com> References: <1348186688-29410-1-git-send-email-jcmvbkbc@gmail.com> Subject: [Qemu-devel] [PATCH 2/2] tcg: add TB sanity checking List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Max Filippov , Peter Maydell , Aurelien Jarno , Richard Henderson Do a sanity checking pass on the intermediate code. Check that goto_tb indices are either 0 or 1 and used at most once per TB. Signed-off-by: Max Filippov --- tcg/tcg.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 69 insertions(+), 0 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index b8a1bec..cdd1975 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1454,6 +1454,71 @@ static void check_regs(TCGContext *s) } #endif +#ifdef CONFIG_DEBUG_TCG +static void tcg_sanity_check(TCGContext *s) +{ + const uint16_t *opc_ptr; + const TCGArg *args; + TCGArg arg; + TCGOpcode c; + int nb_oargs, nb_iargs, nb_cargs, error_count = 0; + const TCGOpDef *def; + unsigned goto_tb_slots[2] = {0}; + + opc_ptr = gen_opc_buf; + args = gen_opparam_buf; + while (opc_ptr < gen_opc_ptr) { + c = *opc_ptr++; + def = &tcg_op_defs[c]; + if (c == INDEX_op_call) { + TCGArg arg; + + /* variable number of arguments */ + arg = *args++; + nb_oargs = arg >> 16; + nb_iargs = arg & 0xffff; + nb_cargs = def->nb_cargs; + } else { + if (c == INDEX_op_nopn) { + /* variable number of arguments */ + nb_cargs = *args; + nb_oargs = 0; + nb_iargs = 0; + } else { + nb_oargs = def->nb_oargs; + nb_iargs = def->nb_iargs; + nb_cargs = def->nb_cargs; + } + } + + switch (c) { + case INDEX_op_goto_tb: + arg = args[0]; + if (arg != 0 && arg != 1) { + qemu_log("TB ERROR: wrong goto_tb slot index: %"TCG_PRIlx"\n", + arg); + ++error_count; + } else { + ++goto_tb_slots[arg]; + if (goto_tb_slots[arg] > 1) { + qemu_log("TB ERROR: multiple goto_tb(%"TCG_PRIlx")\n", arg); + ++error_count; + } + } + break; + + default: + break; + } + + args += nb_iargs + nb_oargs + nb_cargs; + } + if (error_count) { + qemu_log("\n"); + } +} +#endif + static void temp_allocate_frame(TCGContext *s, int temp) { TCGTemp *ts; @@ -2082,6 +2147,10 @@ static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf, } #endif +#ifdef CONFIG_DEBUG_TCG + tcg_sanity_check(s); +#endif + tcg_reg_alloc_start(s); s->code_buf = gen_code_buf; -- 1.7.7.6