From patchwork Sun Jan 27 13:32:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 216003 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 478752C007B for ; Mon, 28 Jan 2013 02:03:45 +1100 (EST) Received: from localhost ([::1]:45780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzSNw-0001dr-Fp for incoming@patchwork.ozlabs.org; Sun, 27 Jan 2013 08:35:00 -0500 Received: from eggs.gnu.org ([208.118.235.92]:38227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzSMU-0007oh-Fe for qemu-devel@nongnu.org; Sun, 27 Jan 2013 08:33:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TzSMM-0003Gx-Oh for qemu-devel@nongnu.org; Sun, 27 Jan 2013 08:33:30 -0500 Received: from cantor2.suse.de ([195.135.220.15]:48536 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzSMM-0003Fl-DL for qemu-devel@nongnu.org; Sun, 27 Jan 2013 08:33:22 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 674FFA522F; Sun, 27 Jan 2013 14:32:53 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Sun, 27 Jan 2013 14:32:09 +0100 Message-Id: <1359293537-8251-12-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359293537-8251-1-git-send-email-afaerber@suse.de> References: <1359293537-8251-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: "Edgar E. Iglesias" , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC 11/19] target-cris: Refactor debug output macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make debug output compile-testable even if disabled. Introduce DPRINTF() in helper.c and consolidate stdout and stderr output. Introduce DPRINTF() in mmu.c and inline remaining D(x). Drop unused D(x) macro in op_helper.c. Signed-off-by: Andreas Färber --- target-cris/helper.c | 21 +++++++++-------- target-cris/mmu.c | 58 +++++++++++++++++++++++++++-------------------- target-cris/op_helper.c | 15 +++++------- target-cris/translate.c | 18 ++++----------- 4 Dateien geändert, 56 Zeilen hinzugefügt(+), 56 Zeilen entfernt(-) diff --git a/target-cris/helper.c b/target-cris/helper.c index de04143..31bf358 100644 --- a/target-cris/helper.c +++ b/target-cris/helper.c @@ -23,16 +23,17 @@ #include "qemu/host-utils.h" -//#define CRIS_HELPER_DEBUG +#define CRIS_HELPER_DEBUG 0 +#define D_LOG(...) G_STMT_START \ + if (CRIS_HELPER_DEBUG) { \ + qemu_log(__VA_ARGS__); \ + } G_STMT_END -#ifdef CRIS_HELPER_DEBUG -#define D(x) x -#define D_LOG(...) qemu_log(__VA_ARGS__) -#else -#define D(x) -#define D_LOG(...) do { } while (0) -#endif +#define DPRINTF(...) G_STMT_START \ + if (CRIS_HELPER_DEBUG) { \ + fprintf(stderr, ## __VA_ARGS__); \ + } G_STMT_END #if defined(CONFIG_USER_ONLY) @@ -71,7 +72,7 @@ int cpu_cris_handle_mmu_fault(CPUCRISState *env, target_ulong address, int rw, int r = -1; target_ulong phy; - D(printf("%s addr=%x pc=%x rw=%x\n", __func__, address, env->pc, rw)); + DPRINTF("%s addr=%x pc=%x rw=%x\n", __func__, address, env->pc, rw); miss = cris_mmu_translate(&res, env, address & TARGET_PAGE_MASK, rw, mmu_idx, 0); if (miss) { @@ -259,7 +260,7 @@ hwaddr cpu_get_phys_page_debug(CPUCRISState * env, target_ulong addr) if (!miss) { phy = res.phy; } - D(fprintf(stderr, "%s %x -> %x\n", __func__, addr, phy)); + DPRINTF("%s %x -> %x\n", __func__, addr, phy); return phy; } #endif diff --git a/target-cris/mmu.c b/target-cris/mmu.c index ee31e2a..f930230 100644 --- a/target-cris/mmu.c +++ b/target-cris/mmu.c @@ -24,13 +24,23 @@ #include "mmu.h" #ifdef DEBUG -#define D(x) x -#define D_LOG(...) qemu_log(__VA_ARGS__) +#define CRIS_ENABLE_DEBUG 1 #else -#define D(x) do { } while (0) -#define D_LOG(...) do { } while (0) +#define CRIS_ENABLE_DEBUG 0 #endif +#define DPRINTF(...) G_STMT_START \ + if (CRIS_ENABLE_DEBUG) { \ + printf(__VA_ARGS__); \ + } \ + G_STMT_END + +#define D_LOG(...) G_STMT_START \ + if (CRIS_ENABLE_DEBUG) { \ + qemu_log(__VA_ARGS__); \ + } \ + G_STMT_END + void cris_mmu_init(CPUCRISState *env) { env->mmu_rand_lfsr = 0xcccc; @@ -105,7 +115,6 @@ static inline void set_field(uint32_t *dst, unsigned int val, *dst |= val; } -#ifdef DEBUG static void dump_tlb(CPUCRISState *env, int mmu) { int set; @@ -124,7 +133,6 @@ static void dump_tlb(CPUCRISState *env, int mmu) } } } -#endif /* rw 0 = read, 1 = write, 2 = exec. */ static int cris_mmu_translate_page(struct cris_mmu_result *res, @@ -225,23 +233,23 @@ static int cris_mmu_translate_page(struct cris_mmu_result *res, set_exception_vector(0x0b, d_mmu_write); */ if (cfg_k && tlb_k && usermode) { - D(printf("tlb: kernel protected %x lo=%x pc=%x\n", - vaddr, lo, env->pc)); + DPRINTF("tlb: kernel protected %x lo=%x pc=%x\n", + vaddr, lo, env->pc); match = 0; res->bf_vec = vect_base + 2; } else if (rw == 1 && cfg_w && !tlb_w) { - D(printf("tlb: write protected %x lo=%x pc=%x\n", - vaddr, lo, env->pc)); + DPRINTF("tlb: write protected %x lo=%x pc=%x\n", + vaddr, lo, env->pc); match = 0; /* write accesses never go through the I mmu. */ res->bf_vec = vect_base + 3; } else if (rw == 2 && cfg_x && !tlb_x) { - D(printf("tlb: exec protected %x lo=%x pc=%x\n", - vaddr, lo, env->pc)); + DPRINTF("tlb: exec protected %x lo=%x pc=%x\n", + vaddr, lo, env->pc); match = 0; res->bf_vec = vect_base + 3; } else if (cfg_v && !tlb_v) { - D(printf("tlb: invalid %x\n", vaddr)); + DPRINTF("tlb: invalid %x\n", vaddr); match = 0; res->bf_vec = vect_base + 1; } @@ -256,7 +264,9 @@ static int cris_mmu_translate_page(struct cris_mmu_result *res, res->prot |= PAGE_EXEC; } } else { - D(dump_tlb(env, mmu)); + if (CRIS_ENABLE_DEBUG) { + dump_tlb(env, mmu); + } } } else { /* If refill, provide a randomized set. */ @@ -279,18 +289,18 @@ static int cris_mmu_translate_page(struct cris_mmu_result *res, set_field(&r_cause, vpage, 13, 19); set_field(&r_cause, pid, 0, 8); env->sregs[SFR_R_MM_CAUSE] = r_cause; - D(printf("refill vaddr=%x pc=%x\n", vaddr, env->pc)); + DPRINTF("refill vaddr=%x pc=%x\n", vaddr, env->pc); } - D(printf("%s rw=%d mtch=%d pc=%x va=%x vpn=%x tlbvpn=%x pfn=%x pid=%x" - " %x cause=%x sel=%x sp=%x %x %x\n", - __func__, rw, match, env->pc, - vaddr, vpage, - tlb_vpn, tlb_pfn, tlb_pid, - pid, - r_cause, - env->sregs[SFR_RW_MM_TLB_SEL], - env->regs[R_SP], env->pregs[PR_USP], env->ksp)); + DPRINTF("%s rw=%d mtch=%d pc=%x va=%x vpn=%x tlbvpn=%x pfn=%x pid=%x" + " %x cause=%x sel=%x sp=%x %x %x\n", + __func__, rw, match, env->pc, + vaddr, vpage, + tlb_vpn, tlb_pfn, tlb_pid, + pid, + r_cause, + env->sregs[SFR_RW_MM_TLB_SEL], + env->regs[R_SP], env->pregs[PR_USP], env->ksp); res->phy = tlb_pfn << TARGET_PAGE_BITS; return !match; diff --git a/target-cris/op_helper.c b/target-cris/op_helper.c index b580513..da37f40 100644 --- a/target-cris/op_helper.c +++ b/target-cris/op_helper.c @@ -23,16 +23,13 @@ #include "helper.h" #include "qemu/host-utils.h" -//#define CRIS_OP_HELPER_DEBUG +#define CRIS_OP_HELPER_DEBUG 0 - -#ifdef CRIS_OP_HELPER_DEBUG -#define D(x) x -#define D_LOG(...) qemu_log(__VA_ARGS__) -#else -#define D(x) -#define D_LOG(...) do { } while (0) -#endif +#define D_LOG(...) G_STMT_START \ + if (CRIS_OP_HELPER_DEBUG) { \ + qemu_log(__VA_ARGS__); \ + } \ + G_STMT_END #if !defined(CONFIG_USER_ONLY) #include "exec/softmmu_exec.h" diff --git a/target-cris/translate.c b/target-cris/translate.c index 09e6011..88ad038 100644 --- a/target-cris/translate.c +++ b/target-cris/translate.c @@ -34,11 +34,11 @@ #include "helper.h" #define DISAS_CRIS 0 -#if DISAS_CRIS -# define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__) -#else -# define LOG_DIS(...) do { } while (0) -#endif +#define LOG_DIS(...) G_STMT_START \ + if (DISAS_CRIS) { \ + qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__); \ + } \ + G_STMT_END #define D(x) #define BUG() (gen_BUG(dc, __FILE__, __LINE__)) @@ -1263,7 +1263,6 @@ static inline void t_gen_zext(TCGv d, TCGv s, int size) } } -#if DISAS_CRIS static char memsize_char(int size) { switch (size) { @@ -1275,7 +1274,6 @@ static char memsize_char(int size) break; } } -#endif static inline unsigned int memsize_z(DisasContext *dc) { @@ -1370,7 +1368,6 @@ static int dec_prep_alu_m(CPUCRISState *env, DisasContext *dc, return insn_len; } -#if DISAS_CRIS static const char *cc_name(int cc) { static const char *cc_names[16] = { @@ -1380,7 +1377,6 @@ static const char *cc_name(int cc) assert(cc < 16); return cc_names[cc]; } -#endif /* Start of insn decoders. */ @@ -1842,7 +1838,6 @@ static int dec_mcp_r(CPUCRISState *env, DisasContext *dc) return 2; } -#if DISAS_CRIS static char * swapmode_name(int mode, char *modename) { int i = 0; if (mode & 8) { @@ -1860,14 +1855,11 @@ static char * swapmode_name(int mode, char *modename) { modename[i++] = 0; return modename; } -#endif static int dec_swap_r(CPUCRISState *env, DisasContext *dc) { TCGv t0; -#if DISAS_CRIS char modename[4]; -#endif LOG_DIS("swap%s $r%u\n", swapmode_name(dc->op2, modename), dc->op1);