On Thu, Feb 21, 2013 at 4:25 AM, Andreas Färber <afaer...@suse.de> wrote: > Make debug output compile-testable even if disabled. > > Inline DEBUG_FEATURES and introduce features_printf() in cpu.c. > Inline DEBUG_MMU in ldst_helper.c but leave DPRINTF_MMU() as is due > to "MMU: " prefix. > Inline DEBUG_{MXCC,ASI} in ldst_helper.c. > > Signed-off-by: Andreas Färber <afaer...@suse.de>
Acked-by: Blue Swirl <blauwir...@gmail.com> > --- > target-sparc/cpu.c | 38 +++++--- > target-sparc/ldst_helper.c | 221 > +++++++++++++++++++++++++++----------------- > 2 Dateien geändert, 158 Zeilen hinzugefügt(+), 101 Zeilen entfernt(-) > > diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c > index ef52df6..86dbf40 100644 > --- a/target-sparc/cpu.c > +++ b/target-sparc/cpu.c > @@ -21,6 +21,22 @@ > > //#define DEBUG_FEATURES > > +#ifdef DEBUG_FEATURES > +static const bool debug_features = true; > +#else > +static const bool debug_features; > +#endif > + > +static void GCC_FMT_ATTR(1, 2) features_printf(const char *fmt, ...) > +{ > + if (debug_features) { > + va_list ap; > + va_start(ap, fmt); > + vfprintf(stderr, fmt, ap); > + va_end(ap); > + } > +} > + > static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char > *cpu_model); > > /* CPUClass::reset() */ > @@ -676,9 +692,7 @@ static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, > const char *cpu_model) > goto error; > } > cpu_def->iu_version = iu_version; > -#ifdef DEBUG_FEATURES > - fprintf(stderr, "iu_version %" PRIx64 "\n", iu_version); > -#endif > + features_printf("iu_version %" PRIx64 "\n", iu_version); > } else if (!strcmp(featurestr, "fpu_version")) { > char *err; > > @@ -688,9 +702,7 @@ static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, > const char *cpu_model) > goto error; > } > cpu_def->fpu_version = fpu_version; > -#ifdef DEBUG_FEATURES > - fprintf(stderr, "fpu_version %x\n", fpu_version); > -#endif > + features_printf("fpu_version %x\n", fpu_version); > } else if (!strcmp(featurestr, "mmu_version")) { > char *err; > > @@ -700,9 +712,7 @@ static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, > const char *cpu_model) > goto error; > } > cpu_def->mmu_version = mmu_version; > -#ifdef DEBUG_FEATURES > - fprintf(stderr, "mmu_version %x\n", mmu_version); > -#endif > + features_printf("mmu_version %x\n", mmu_version); > } else if (!strcmp(featurestr, "nwindows")) { > char *err; > > @@ -713,9 +723,7 @@ static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, > const char *cpu_model) > goto error; > } > cpu_def->nwindows = nwindows; > -#ifdef DEBUG_FEATURES > - fprintf(stderr, "nwindows %d\n", nwindows); > -#endif > + features_printf("nwindows %d\n", nwindows); > } else { > fprintf(stderr, "unrecognized feature %s\n", featurestr); > goto error; > @@ -729,9 +737,9 @@ static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, > const char *cpu_model) > } > cpu_def->features |= plus_features; > cpu_def->features &= ~minus_features; > -#ifdef DEBUG_FEATURES > - print_features(stderr, fprintf, cpu_def->features, NULL); > -#endif > + if (debug_features) { > + print_features(stderr, fprintf, cpu_def->features, NULL); > + } > g_free(s); > return 0; > > diff --git a/target-sparc/ldst_helper.c b/target-sparc/ldst_helper.c > index 7decd66..9be9e41 100644 > --- a/target-sparc/ldst_helper.c > +++ b/target-sparc/ldst_helper.c > @@ -28,29 +28,87 @@ > //#define DEBUG_CACHE_CONTROL > > #ifdef DEBUG_MMU > -#define DPRINTF_MMU(fmt, ...) \ > - do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0) > +static const bool debug_mmu = true; > #else > -#define DPRINTF_MMU(fmt, ...) do {} while (0) > +static const bool debug_mmu; > #endif > > #ifdef DEBUG_MXCC > -#define DPRINTF_MXCC(fmt, ...) \ > - do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0) > +static const bool debug_mxcc = true; > #else > -#define DPRINTF_MXCC(fmt, ...) do {} while (0) > +static const bool debug_mxcc; > #endif > > #ifdef DEBUG_ASI > -#define DPRINTF_ASI(fmt, ...) \ > - do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0) > +static const bool debug_asi = true; > +#else > +static const bool debug_asi; > #endif > > #ifdef DEBUG_CACHE_CONTROL > -#define DPRINTF_CACHE_CONTROL(fmt, ...) \ > - do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0) > +static const bool debug_cache_control = true; > #else > -#define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0) > +static const bool debug_cache_control; > +#endif > + > +#define DPRINTF_MMU(fmt, ...) \ > + dprintf_mmu("MMU: " fmt, ## __VA_ARGS__) > + > +#ifndef CONFIG_USER_ONLY > +static void GCC_FMT_ATTR(1, 2) dprintf_mmu(const char *fmt, ...) > +{ > + if (debug_mmu) { > + va_list ap; > + va_start(ap, fmt); > + vprintf(fmt, ap); > + va_end(ap); > + } > +} > + > +#define DPRINTF_MXCC(fmt, ...) \ > + dprintf_mxcc("MXCC: " fmt, ## __VA_ARGS__) > + > +#ifndef TARGET_SPARC64 > +static void GCC_FMT_ATTR(1, 2) dprintf_mxcc(const char *fmt, ...) > +{ > + if (debug_mxcc) { > + va_list ap; > + va_start(ap, fmt); > + vprintf(fmt, ap); > + va_end(ap); > + } > +} > +#endif /* !TARGET_SPARC64 */ > +#endif /* !CONFIG_USER_ONLY */ > + > +#define DPRINTF_ASI(fmt, ...) \ > + dprintf_asi("ASI:" fmt, ## __VA_ARGS__) > + > +#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64) > +static void GCC_FMT_ATTR(1, 2) dprintf_asi(const char *fmt, ...) > +{ > + if (debug_asi) { > + va_list ap; > + va_start(ap, fmt); > + vprintf(fmt , ap); > + va_end(ap); > + } > +} > +#endif > + > +#define DPRINTF_CACHE_CONTROL(fmt, ...) \ > + dprintf_cache_control("CACHE_CONTROL: " fmt, ## __VA_ARGS__) > + > +#if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) > +static void GCC_FMT_ATTR(1, 2) dprintf_cache_control(const char *fmt, ...) > +{ > + if (debug_cache_control) { > + va_list ap; > + va_start(ap, fmt); > + vprintf(fmt, ap); > + va_end(ap); > + } > +} > #endif > > #ifdef TARGET_SPARC64 > @@ -209,10 +267,10 @@ static void demap_tlb(SparcTLBEntry *tlb, target_ulong > demap_addr, > } > > replace_tlb_entry(&tlb[i], 0, 0, env1); > -#ifdef DEBUG_MMU > DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu, i); > - dump_mmu(stdout, fprintf, env1); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env1); > + } > } > } > } > @@ -227,10 +285,10 @@ static void replace_tlb_1bit_lru(SparcTLBEntry *tlb, > for (i = 0; i < 64; i++) { > if (!TTE_IS_VALID(tlb[i].tte)) { > replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1); > -#ifdef DEBUG_MMU > DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu, i); > - dump_mmu(stdout, fprintf, env1); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env1); > + } > return; > } > } > @@ -245,11 +303,12 @@ static void replace_tlb_1bit_lru(SparcTLBEntry *tlb, > if (!TTE_IS_LOCKED(tlb[i].tte) && !TTE_IS_USED(tlb[i].tte)) { > > replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1); > -#ifdef DEBUG_MMU > + > DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n", > strmmu, (replace_used ? "used" : "unused"), i); > - dump_mmu(stdout, fprintf, env1); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env1); > + } > return; > } > } > @@ -261,9 +320,7 @@ static void replace_tlb_1bit_lru(SparcTLBEntry *tlb, > } > } > > -#ifdef DEBUG_MMU > DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu); > -#endif > /* error state? */ > } > > @@ -327,8 +384,7 @@ void helper_check_align(CPUSPARCState *env, target_ulong > addr, uint32_t align) > } > } > > -#if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \ > - defined(DEBUG_MXCC) > +#if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) > static void dump_mxcc(CPUSPARCState *env) > { > printf("mxccdata: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" > PRIx64 > @@ -346,8 +402,7 @@ static void dump_mxcc(CPUSPARCState *env) > } > #endif > > -#if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \ > - && defined(DEBUG_ASI) > +#if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) > static void dump_asi(const char *txt, target_ulong addr, int asi, int size, > uint64_t r1) > { > @@ -448,9 +503,7 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong > addr, int asi, int size, > int sign) > { > uint64_t ret = 0; > -#if defined(DEBUG_MXCC) || defined(DEBUG_ASI) > uint32_t last_addr = addr; > -#endif > > helper_check_align(env, addr, size - 1); > switch (asi) { > @@ -509,9 +562,9 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong > addr, int asi, int size, > DPRINTF_MXCC("asi = %d, size = %d, sign = %d, " > "addr = %08x -> ret = %" PRIx64 "," > "addr = %08x\n", asi, size, sign, last_addr, ret, addr); > -#ifdef DEBUG_MXCC > - dump_mxcc(env); > -#endif > + if (debug_mxcc) { > + dump_mxcc(env); > + } > break; > case 3: /* MMU probe */ > { > @@ -702,9 +755,9 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong > addr, int asi, int size, > break; > } > } > -#ifdef DEBUG_ASI > - dump_asi("read ", last_addr, asi, size, ret); > -#endif > + if (debug_asi) { > + dump_asi("read ", last_addr, asi, size, ret); > + } > return ret; > } > > @@ -839,9 +892,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong addr, > uint64_t val, int asi, > } > DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64 "\n", > asi, size, addr, val); > -#ifdef DEBUG_MXCC > - dump_mxcc(env); > -#endif > + if (debug_mxcc) { > + dump_mxcc(env); > + } > break; > case 3: /* MMU flush */ > { > @@ -862,9 +915,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong addr, > uint64_t val, int asi, > default: > break; > } > -#ifdef DEBUG_MMU > - dump_mmu(stdout, fprintf, env); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env); > + } > } > break; > case 4: /* write MMU regs */ > @@ -916,9 +969,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong addr, > uint64_t val, int asi, > DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n", > reg, oldreg, env->mmuregs[reg]); > } > -#ifdef DEBUG_MMU > - dump_mmu(stdout, fprintf, env); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env); > + } > } > break; > case 5: /* Turbosparc ITLB Diagnostic */ > @@ -1085,9 +1138,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong > addr, uint64_t val, int asi, > cpu_unassigned_access(env, addr, 1, 0, asi, size); > break; > } > -#ifdef DEBUG_ASI > - dump_asi("write", addr, asi, size, val); > -#endif > + if (debug_asi) { > + dump_asi("write", addr, asi, size, val); > + } > } > > #endif /* CONFIG_USER_ONLY */ > @@ -1098,9 +1151,7 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong > addr, int asi, int size, > int sign) > { > uint64_t ret = 0; > -#if defined(DEBUG_ASI) > target_ulong last_addr = addr; > -#endif > > if (asi < 0x80) { > helper_raise_exception(env, TT_PRIV_ACT); > @@ -1113,9 +1164,9 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong > addr, int asi, int size, > case 0x82: /* Primary no-fault */ > case 0x8a: /* Primary no-fault LE */ > if (page_check_range(addr, size, PAGE_READ) == -1) { > -#ifdef DEBUG_ASI > - dump_asi("read ", last_addr, asi, size, ret); > -#endif > + if (debug_asi) { > + dump_asi("read ", last_addr, asi, size, ret); > + } > return 0; > } > /* Fall through */ > @@ -1142,9 +1193,9 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong > addr, int asi, int size, > case 0x83: /* Secondary no-fault */ > case 0x8b: /* Secondary no-fault LE */ > if (page_check_range(addr, size, PAGE_READ) == -1) { > -#ifdef DEBUG_ASI > - dump_asi("read ", last_addr, asi, size, ret); > -#endif > + if (debug_asi) { > + dump_asi("read ", last_addr, asi, size, ret); > + } > return 0; > } > /* Fall through */ > @@ -1195,18 +1246,18 @@ uint64_t helper_ld_asi(CPUSPARCState *env, > target_ulong addr, int asi, int size, > break; > } > } > -#ifdef DEBUG_ASI > - dump_asi("read ", last_addr, asi, size, ret); > -#endif > + if (debug_asi) { > + dump_asi("read ", last_addr, asi, size, ret); > + } > return ret; > } > > void helper_st_asi(CPUSPARCState *env, target_ulong addr, target_ulong val, > int asi, int size) > { > -#ifdef DEBUG_ASI > - dump_asi("write", addr, asi, size, val); > -#endif > + if (debug_asi) { > + dump_asi("write", addr, asi, size, val); > + } > if (asi < 0x80) { > helper_raise_exception(env, TT_PRIV_ACT); > } > @@ -1277,9 +1328,7 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong > addr, int asi, int size, > int sign) > { > uint64_t ret = 0; > -#if defined(DEBUG_ASI) > target_ulong last_addr = addr; > -#endif > > asi &= 0xff; > > @@ -1305,9 +1354,9 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong > addr, int asi, int size, > } > > if (cpu_get_phys_page_nofault(env, addr, mmu_idx) == -1ULL) { > -#ifdef DEBUG_ASI > - dump_asi("read ", last_addr, asi, size, ret); > -#endif > + if (debug_asi) { > + dump_asi("read ", last_addr, asi, size, ret); > + } > /* env->exception_index is set in get_physical_address_data(). */ > helper_raise_exception(env, env->exception_index); > } > @@ -1635,18 +1684,18 @@ uint64_t helper_ld_asi(CPUSPARCState *env, > target_ulong addr, int asi, int size, > break; > } > } > -#ifdef DEBUG_ASI > - dump_asi("read ", last_addr, asi, size, ret); > -#endif > + if (debug_asi) { > + dump_asi("read ", last_addr, asi, size, ret); > + } > return ret; > } > > void helper_st_asi(CPUSPARCState *env, target_ulong addr, target_ulong val, > int asi, int size) > { > -#ifdef DEBUG_ASI > - dump_asi("write", addr, asi, size, val); > -#endif > + if (debug_asi) { > + dump_asi("write", addr, asi, size, val); > + } > > asi &= 0xff; > > @@ -1849,9 +1898,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong > addr, target_ulong val, > if (oldreg != env->lsu) { > DPRINTF_MMU("LSU change: 0x%" PRIx64 " -> 0x%" PRIx64 "\n", > oldreg, env->lsu); > -#ifdef DEBUG_MMU > - dump_mmu(stdout, fprintf, env); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env); > + } > tlb_flush(env, 1); > } > return; > @@ -1895,9 +1944,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong > addr, target_ulong val, > DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64 " -> 0x%016" > PRIx64 "\n", reg, oldreg, env->immuregs[reg]); > } > -#ifdef DEBUG_MMU > - dump_mmu(stdout, fprintf, env); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env); > + } > return; > } > case 0x54: /* I-MMU data in */ > @@ -1911,10 +1960,10 @@ void helper_st_asi(CPUSPARCState *env, target_ulong > addr, target_ulong val, > > replace_tlb_entry(&env->itlb[i], env->immu.tag_access, val, env); > > -#ifdef DEBUG_MMU > DPRINTF_MMU("immu data access replaced entry [%i]\n", i); > - dump_mmu(stdout, fprintf, env); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env); > + } > return; > } > case 0x57: /* I-MMU demap */ > @@ -1968,9 +2017,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong > addr, target_ulong val, > DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64 " -> 0x%016" > PRIx64 "\n", reg, oldreg, env->dmmuregs[reg]); > } > -#ifdef DEBUG_MMU > - dump_mmu(stdout, fprintf, env); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env); > + } > return; > } > case 0x5c: /* D-MMU data in */ > @@ -1982,10 +2031,10 @@ void helper_st_asi(CPUSPARCState *env, target_ulong > addr, target_ulong val, > > replace_tlb_entry(&env->dtlb[i], env->dmmu.tag_access, val, env); > > -#ifdef DEBUG_MMU > DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i); > - dump_mmu(stdout, fprintf, env); > -#endif > + if (debug_mmu) { > + dump_mmu(stdout, fprintf, env); > + } > return; > } > case 0x5f: /* D-MMU demap */ > -- > 1.7.10.4 >