All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eduardo Habkost <ehabkost@redhat.com>
Subject: [Qemu-devel] [PATCH 19/31] target-ppc/helper.c: LOG_MMU macro
Date: Fri, 12 Dec 2008 13:08:58 -0200	[thread overview]
Message-ID: <1229094550-2022-20-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1229094550-2022-1-git-send-email-ehabkost@redhat.com>

Create a LOG_MMU macro and use it instead of #ifdef DEBUG_MMU.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-ppc/helper.c |   95 +++++++++++++--------------------------------------
 1 files changed, 24 insertions(+), 71 deletions(-)

diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 538d9f3..85e7612 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -38,6 +38,15 @@
 //#define DEBUG_EXCEPTIONS
 //#define FLUSH_ALL_TLBS
 
+#ifdef DEBUG_MMU
+#  define LOG_MMU(...) do {              \
+     if (loglevel)                       \
+       fprintf(logfile, ## __VA_ARGS__); \
+   } while (0)
+#else
+#  define LOG_MMU(...) do { } while (0)
+#endif
+
 /*****************************************************************************/
 /* PowerPC MMU emulation */
 
@@ -217,16 +226,10 @@ static always_inline int _pte_check (mmu_ctx_t *ctx, int is_64b,
             ret = check_prot(ctx->prot, rw, type);
             if (ret == 0) {
                 /* Access granted */
-#if defined (DEBUG_MMU)
-                if (loglevel != 0)
-                    fprintf(logfile, "PTE access granted !\n");
-#endif
+                LOG_MMU("PTE access granted !\n");
             } else {
                 /* Access right violation */
-#if defined (DEBUG_MMU)
-                if (loglevel != 0)
-                    fprintf(logfile, "PTE access rejected\n");
-#endif
+                LOG_MMU("PTE access rejected\n");
             }
         }
     }
@@ -608,30 +611,22 @@ static always_inline int _find_pte (mmu_ctx_t *ctx, int is_64b, int h,
             pte0 = ldq_phys(base + (i * 16));
             pte1 =  ldq_phys(base + (i * 16) + 8);
             r = pte64_check(ctx, pte0, pte1, h, rw, type);
-#if defined (DEBUG_MMU)
-            if (loglevel != 0) {
-                fprintf(logfile, "Load pte from " ADDRX " => " ADDRX " " ADDRX
+            LOG_MMU("Load pte from " ADDRX " => " ADDRX " " ADDRX
                         " %d %d %d " ADDRX "\n",
                         base + (i * 16), pte0, pte1,
                         (int)(pte0 & 1), h, (int)((pte0 >> 1) & 1),
                         ctx->ptem);
-            }
-#endif
         } else
 #endif
         {
             pte0 = ldl_phys(base + (i * 8));
             pte1 =  ldl_phys(base + (i * 8) + 4);
             r = pte32_check(ctx, pte0, pte1, h, rw, type);
-#if defined (DEBUG_MMU)
-            if (loglevel != 0) {
-                fprintf(logfile, "Load pte from " ADDRX " => " ADDRX " " ADDRX
+            LOG_MMU("Load pte from " ADDRX " => " ADDRX " " ADDRX
                         " %d %d %d " ADDRX "\n",
                         base + (i * 8), pte0, pte1,
                         (int)(pte0 >> 31), h, (int)((pte0 >> 6) & 1),
                         ctx->ptem);
-            }
-#endif
         }
         switch (r) {
         case -3:
@@ -659,12 +654,8 @@ static always_inline int _find_pte (mmu_ctx_t *ctx, int is_64b, int h,
     }
     if (good != -1) {
     done:
-#if defined (DEBUG_MMU)
-        if (loglevel != 0) {
-            fprintf(logfile, "found PTE at addr " PADDRX " prot=%01x ret=%d\n",
+        LOG_MMU("found PTE at addr " PADDRX " prot=%01x ret=%d\n",
                     ctx->raddr, ctx->prot, ret);
-        }
-#endif
         /* Update page flags */
         pte1 = ctx->raddr;
         if (pte_update_flags(ctx, &pte1, ret, rw) == 1) {
@@ -910,11 +901,7 @@ static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx,
     pr = msr_pr;
 #if defined(TARGET_PPC64)
     if (env->mmu_model & POWERPC_MMU_64) {
-#if defined (DEBUG_MMU)
-        if (loglevel != 0) {
-            fprintf(logfile, "Check SLBs\n");
-        }
-#endif
+        LOG_MMU("Check SLBs\n");
         ret = slb_lookup(env, eaddr, &vsid, &page_mask, &attr);
         if (ret < 0)
             return ret;
@@ -940,22 +927,14 @@ static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx,
         vsid_sh = 6;
         sdr_sh = 16;
         sdr_mask = 0xFFC0;
-#if defined (DEBUG_MMU)
-        if (loglevel != 0) {
-            fprintf(logfile, "Check segment v=" ADDRX " %d " ADDRX
+        LOG_MMU("Check segment v=" ADDRX " %d " ADDRX
                     " nip=" ADDRX " lr=" ADDRX " ir=%d dr=%d pr=%d %d t=%d\n",
                     eaddr, (int)(eaddr >> 28), sr, env->nip,
                     env->lr, (int)msr_ir, (int)msr_dr, pr != 0 ? 1 : 0,
                     rw, type);
-        }
-#endif
     }
-#if defined (DEBUG_MMU)
-    if (loglevel != 0) {
-        fprintf(logfile, "pte segment: key=%d ds %d nx %d vsid " ADDRX "\n",
+    LOG_MMU("pte segment: key=%d ds %d nx %d vsid " ADDRX "\n",
                 ctx->key, ds, ctx->nx, vsid);
-    }
-#endif
     ret = -1;
     if (!ds) {
         /* Check if instruction fetch is allowed, if needed */
@@ -976,23 +955,15 @@ static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx,
                 hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask;
             }
             mask = (htab_mask << sdr_sh) | sdr_mask;
-#if defined (DEBUG_MMU)
-            if (loglevel != 0) {
-                fprintf(logfile, "sdr " PADDRX " sh %d hash " PADDRX
+            LOG_MMU("sdr " PADDRX " sh %d hash " PADDRX
                         " mask " PADDRX " " ADDRX "\n",
                         sdr, sdr_sh, hash, mask, page_mask);
-            }
-#endif
             ctx->pg_addr[0] = get_pgaddr(sdr, sdr_sh, hash, mask);
             /* Secondary table address */
             hash = (~hash) & vsid_mask;
-#if defined (DEBUG_MMU)
-            if (loglevel != 0) {
-                fprintf(logfile, "sdr " PADDRX " sh %d hash " PADDRX
+            LOG_MMU("sdr " PADDRX " sh %d hash " PADDRX
                         " mask " PADDRX "\n",
                         sdr, sdr_sh, hash, mask);
-            }
-#endif
             ctx->pg_addr[1] = get_pgaddr(sdr, sdr_sh, hash, mask);
 #if defined(TARGET_PPC64)
             if (env->mmu_model & POWERPC_MMU_64) {
@@ -1010,14 +981,10 @@ static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx,
                 /* Software TLB search */
                 ret = ppc6xx_tlb_check(env, ctx, eaddr, rw, type);
             } else {
-#if defined (DEBUG_MMU)
-                if (loglevel != 0) {
-                    fprintf(logfile, "0 sdr1=" PADDRX " vsid=" ADDRX " "
+                LOG_MMU("0 sdr1=" PADDRX " vsid=" ADDRX " "
                             "api=" ADDRX " hash=" PADDRX
                             " pg_addr=" PADDRX "\n",
                             sdr, vsid, pgidx, hash, ctx->pg_addr[0]);
-                }
-#endif
                 /* Primary table lookup */
                 ret = find_pte(env, ctx, 0, rw, type);
                 if (ret < 0) {
@@ -1055,17 +1022,11 @@ static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx,
             }
 #endif
         } else {
-#if defined (DEBUG_MMU)
-            if (loglevel != 0)
-                fprintf(logfile, "No access allowed\n");
-#endif
+            LOG_MMU("No access allowed\n");
             ret = -3;
         }
     } else {
-#if defined (DEBUG_MMU)
-        if (loglevel != 0)
-            fprintf(logfile, "direct store...\n");
-#endif
+        LOG_MMU("direct store...\n");
         /* Direct-store segment : absolutely *BUGGY* for now */
         switch (type) {
         case ACCESS_INT:
@@ -2044,11 +2005,7 @@ void ppc_store_asr (CPUPPCState *env, target_ulong value)
 
 void ppc_store_sdr1 (CPUPPCState *env, target_ulong value)
 {
-#if defined (DEBUG_MMU)
-    if (loglevel != 0) {
-        fprintf(logfile, "%s: " ADDRX "\n", __func__, value);
-    }
-#endif
+    LOG_MMU("%s: " ADDRX "\n", __func__, value);
     if (env->sdr1 != value) {
         /* XXX: for PowerPC 64, should check that the HTABSIZE value
          *      is <= 28
@@ -2060,12 +2017,8 @@ void ppc_store_sdr1 (CPUPPCState *env, target_ulong value)
 
 void ppc_store_sr (CPUPPCState *env, int srnum, target_ulong value)
 {
-#if defined (DEBUG_MMU)
-    if (loglevel != 0) {
-        fprintf(logfile, "%s: reg=%d " ADDRX " " ADDRX "\n",
+    LOG_MMU("%s: reg=%d " ADDRX " " ADDRX "\n",
                 __func__, srnum, value, env->sr[srnum]);
-    }
-#endif
     if (env->sr[srnum] != value) {
         env->sr[srnum] = value;
 #if !defined(FLUSH_ALL_TLBS) && 0
-- 
1.5.5.GIT

  parent reply	other threads:[~2008-12-12 15:10 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-12 15:08 [Qemu-devel] [PATCH 00/31] Logging code cleanup, take 2 Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 01/31] hw/ppc.c: LOG_IRQ macro Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 02/31] hw/ppc.c: use LOG_IRQ instead of #ifdefs Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 03/31] hw/ppc.c: LOG_TB macro Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 04/31] hw/ppc.c: use LOG_TB instead of #ifdefs Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 05/31] vl.c: LOG_IOPORT macro Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 06/31] vl.c: use LOG_IOPORT instead of #ifdefs Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 07/31] kqemu.c: LOG_INT macro Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 08/31] kqemu.c: use LOG_INT instead of #ifdefs Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 09/31] kqemu.c: LOG_INT_STATE macro Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 10/31] kqemu.c: use LOG_INT_STATE instead of #ifdefs Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 11/31] kqemu.c: kill remaining DEBUG #ifdefs Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 12/31] target-i386/op_helper.c: LOG_PCALL macro Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 13/31] target-i386/op_helper.c: LOG_PCALL_STATE macro Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 14/31] target-i386/op_helper.c: use LOG_PCALL instead of #ifdefs Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 15/31] target-i386/op_helper.c: use LOG_PCALL/LOG_PCALL_STATE Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 16/31] target-cris/translate.c: LOG_DIS macro Eduardo Habkost
2008-12-12 18:59   ` Stuart Brady
2008-12-12 15:08 ` [Qemu-devel] [PATCH 17/31] target-cris: replace D(fprintf(logfile, ...)) macros with D_LOG(...) Eduardo Habkost
2008-12-12 15:08 ` [Qemu-devel] [PATCH 18/31] target-mips/translate.c: LOG_DISAS macro Eduardo Habkost
2008-12-12 15:08 ` Eduardo Habkost [this message]
2008-12-12 15:08 ` [Qemu-devel] [PATCH 20/31] target-ppc/helper.c: LOG_SWTLB macro Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 21/31] target-ppc/helper.c: convert commented-out debug code to LOG_SWTLB Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 22/31] target-ppc/helper.c: LOG_BATS macro Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 23/31] target-ppc/helper.c: LOG_SLB macro Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 24/31] target-ppc/helper.c: LOG_EXCP macro Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 25/31] target-ppc/helper.c: remaining LOG_BATS & LOG_MMU conversions Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 26/31] target-ppc/helper.c: LOG_MMU_STATE macro Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 27/31] target-ppc/op_helper.c: LOG_SWTLB macro Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 28/31] target-ppc/translate.c: LOG_DISAS macro Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 29/31] hw/ppc4xx_devs.c: LOG_UIC macro Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 30/31] target-alpha/translate.c: LOG_DISAS macro Eduardo Habkost
2008-12-12 15:09 ` [Qemu-devel] [PATCH 31/31] linux-user/vm86.c: LOG_VM86 macro Eduardo Habkost
2008-12-12 16:25 ` [Qemu-devel] [PATCH 00/31] Logging code cleanup, take 2 Blue Swirl
2008-12-12 16:54   ` Eduardo Habkost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1229094550-2022-20-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.