Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/m68k/fpe - use DPRINTF() style debug printfs



details:   https://anonhg.NetBSD.org/src/rev/4855f30f8f7f
branches:  trunk
changeset: 765258:4855f30f8f7f
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Mon May 23 15:40:34 2011 +0000

description:
- use DPRINTF() style debug printfs
- use __func__ to print function names
- consistently use #ifdef DEBUG_FPE
- add some missing debug messages including \n in error paths

diffstat:

 sys/arch/m68k/fpe/fpu_emulate.c |  298 ++++++++++++---------------------------
 1 files changed, 96 insertions(+), 202 deletions(-)

diffs (truncated from 640 to 300 lines):

diff -r 1abc6671e1fe -r 4855f30f8f7f sys/arch/m68k/fpe/fpu_emulate.c
--- a/sys/arch/m68k/fpe/fpu_emulate.c   Mon May 23 15:37:35 2011 +0000
+++ b/sys/arch/m68k/fpe/fpu_emulate.c   Mon May 23 15:40:34 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fpu_emulate.c,v 1.32 2011/05/23 14:52:31 tsutsui Exp $ */
+/*     $NetBSD: fpu_emulate.c,v 1.33 2011/05/23 15:40:34 tsutsui Exp $ */
 
 /*
  * Copyright (c) 1995 Gordon W. Ross
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu_emulate.c,v 1.32 2011/05/23 14:52:31 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_emulate.c,v 1.33 2011/05/23 15:40:34 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -67,13 +67,16 @@
 static int test_cc(struct fpemu *, int);
 static struct fpn *fpu_cmp(struct fpemu *);
 
-#if DEBUG_FPE
+#ifdef DEBUG_FPE
 #define DUMP_INSN(insn)                                                        \
-       printf("fpu_emulate: insn={adv=%d,siz=%d,op=%04x,w1=%04x}\n",   \
+       printf("%s: insn={adv=%d,siz=%d,op=%04x,w1=%04x}\n",            \
+           __func__,                                                   \
            (insn)->is_advance, (insn)->is_datasize,                    \
            (insn)->is_opcode, (insn)->is_word1)
+#define DPRINTF(x)     printf x
 #else
-#define DUMP_INSN(insn)
+#define DUMP_INSN(insn)        do {} while (/* CONSTCOND */ 0)
+#define DPRINTF(x)     do {} while (/* CONSTCOND */ 0)
 #endif
 
 /*
@@ -97,10 +100,8 @@
        fe.fe_fpsr = fpf->fpf_fpsr;
        fe.fe_fpcr = fpf->fpf_fpcr;
 
-#if DEBUG_FPE
-       printf("ENTERING fpu_emulate: FPSR=%08x, FPCR=%08x\n",
-           fe.fe_fpsr, fe.fe_fpcr);
-#endif
+       DPRINTF(("%s: ENTERING: FPSR=%08x, FPCR=%08x\n",
+           __func__, fe.fe_fpsr, fe.fe_fpcr));
 
        /* always set this (to avoid a warning) */
        insn.is_pc = frame->f_pc;
@@ -127,23 +128,18 @@
 
        word = fusword((void *)(insn.is_pc));
        if (word < 0) {
-#ifdef DEBUG
-               printf("fpu_emulate: fault reading opcode\n");
-#endif
+               DPRINTF(("%s: fault reading opcode\n", __func__));
                fpe_abort(frame, ksi, SIGSEGV, SEGV_ACCERR);
        }
 
        if ((word & 0xf000) != 0xf000) {
-#ifdef DEBUG
-               printf("fpu_emulate: not coproc. insn.: opcode=0x%x\n", word);
-#endif
+               DPRINTF(("%s: not coproc. insn.: opcode=0x%x\n",
+                   __func__, word));
                fpe_abort(frame, ksi, SIGILL, ILL_ILLOPC);
        }
 
        if ((word & 0x0E00) != 0x0200) {
-#ifdef DEBUG
-               printf("fpu_emulate: bad coproc. id: opcode=0x%x\n", word);
-#endif
+               DPRINTF(("%s: bad coproc. id: opcode=0x%x\n", __func__, word));
                fpe_abort(frame, ksi, SIGILL, ILL_ILLOPC);
        }
 
@@ -152,9 +148,7 @@
 
        word = fusword((void *)(insn.is_pc + 2));
        if (word < 0) {
-#ifdef DEBUG
-               printf("fpu_emulate: fault reading word1\n");
-#endif
+               DPRINTF(("%s: fault reading word1\n", __func__));
                fpe_abort(frame, ksi, SIGSEGV, SEGV_ACCERR);
        }
        insn.is_word1 = word;
@@ -171,68 +165,48 @@
        if (optype == 0x0000) {
                /* type=0: generic */
                if ((word & 0xc000) == 0xc000) {
-#if DEBUG_FPE
-                       printf("fpu_emulate: fmovm FPr\n");
-#endif
+                       DPRINTF(("%s: fmovm FPr\n", __func__));
                        sig = fpu_emul_fmovm(&fe, &insn);
                } else if ((word & 0xc000) == 0x8000) {
-#if DEBUG_FPE
-                       printf("fpu_emulate: fmovm FPcr\n");
-#endif
+                       DPRINTF(("%s: fmovm FPcr\n", __func__));
                        sig = fpu_emul_fmovmcr(&fe, &insn);
                } else if ((word & 0xe000) == 0x6000) {
                        /* fstore = fmove FPn,mem */
-#if DEBUG_FPE
-                       printf("fpu_emulate: fmove to mem\n");
-#endif
+                       DPRINTF(("%s: fmove to mem\n", __func__));
                        sig = fpu_emul_fstore(&fe, &insn);
                } else if ((word & 0xfc00) == 0x5c00) {
                        /* fmovecr */
-#if DEBUG_FPE
-                       printf("fpu_emulate: fmovecr\n");
-#endif
+                       DPRINTF(("%s: fmovecr\n", __func__));
                        sig = fpu_emul_fmovecr(&fe, &insn);
                } else if ((word & 0xa07f) == 0x26) {
                        /* fscale */
-#if DEBUG_FPE
-                       printf("fpu_emulate: fscale\n");
-#endif
+                       DPRINTF(("%s: fscale\n", __func__));
                        sig = fpu_emul_fscale(&fe, &insn);
                } else {
-#if DEBUG_FPE
-                       printf("fpu_emulate: other type0\n");
-#endif
+                       DPRINTF(("%s: other type0\n", __func__));
                        /* all other type0 insns are arithmetic */
                        sig = fpu_emul_arith(&fe, &insn);
                }
                if (sig == 0) {
-#if DEBUG_FPE
-                       printf("fpu_emulate: type 0 returned 0\n");
-#endif
+                       DPRINTF(("%s: type 0 returned 0\n", __func__));
                        sig = fpu_upd_excp(&fe);
                }
        } else if (optype == 0x0080 || optype == 0x00C0) {
                /* type=2 or 3: fbcc, short or long disp. */
-#if DEBUG_FPE
-               printf("fpu_emulate: fbcc %s\n",
-                   (optype & 0x40) ? "long" : "short");
-#endif
+               DPRINTF(("%s: fbcc %s\n", __func__,
+                   (optype & 0x40) ? "long" : "short"));
                sig = fpu_emul_brcc(&fe, &insn);
        } else if (optype == 0x0040) {
                /* type=1: fdbcc, fscc, ftrapcc */
-#if DEBUG_FPE
-               printf("fpu_emulate: type1\n");
-#endif
+               DPRINTF(("%s: type1\n", __func__));
                sig = fpu_emul_type1(&fe, &insn);
        } else {
                /* type=4: fsave    (privileged) */
                /* type=5: frestore (privileged) */
                /* type=6: reserved */
                /* type=7: reserved */
-#ifdef DEBUG
-               printf("fpu_emulate: bad opcode type: opcode=0x%x\n",
-                   insn.is_opcode);
-#endif
+               DPRINTF(("%s: bad opcode type: opcode=0x%x\n", __func__,
+                   insn.is_opcode));
                sig = SIGILL;
        }
 
@@ -247,7 +221,7 @@
                frame->f_pc += insn.is_advance;
 #if defined(DDB) && defined(DEBUG_FPE)
        else {
-               printf("fpu_emulate: sig=%d, opcode=%x, word1=%x\n",
+               printf("%s: sig=%d, opcode=%x, word1=%x\n", __func__,
                    sig, insn.is_opcode, insn.is_word1);
                kdb_trap(-1, (db_regs_t *)&frame);
        }
@@ -260,10 +234,8 @@
        }
 #endif
 
-#if DEBUG_FPE
-       printf("EXITING fpu_emulate: w/FPSR=%08x, FPCR=%08x\n",
-           fe.fe_fpsr, fe.fe_fpcr);
-#endif
+       DPRINTF(("%s: EXITING: w/FPSR=%08x, FPCR=%08x\n", __func__,
+           fe.fe_fpsr, fe.fe_fpcr));
 
        if (sig)
                fpe_abort(frame, ksi, sig, 0);
@@ -310,64 +282,44 @@
 {
        u_int fpsr;
 
-#if DEBUG_FPE
-       printf("fpu_upd_fpsr: previous fpsr=%08x\n", fe->fe_fpsr);
-#endif
+       DPRINTF(("%s: previous fpsr=%08x\n", __func__, fe->fe_fpsr));
        /* clear all condition code */
        fpsr = fe->fe_fpsr & ~FPSR_CCB;
 
-#if DEBUG_FPE
-       printf("fpu_upd_fpsr: result is a ");
-#endif
+       DPRINTF(("%s: result is a ", __func__));
        if (fp->fp_sign) {
-#if DEBUG_FPE
-               printf("negative ");
-#endif
+               DPRINTF(("negative "));
                fpsr |= FPSR_NEG;
-#if DEBUG_FPE
        } else {
-               printf("positive ");
-#endif
+               DPRINTF(("positive "));
        }
 
        switch (fp->fp_class) {
        case FPC_SNAN:
-#if DEBUG_FPE
-               printf("signaling NAN\n");
-#endif
+               DPRINTF(("signaling NAN\n"));
                fpsr |= (FPSR_NAN | FPSR_SNAN);
                break;
        case FPC_QNAN:
-#if DEBUG_FPE
-               printf("quiet NAN\n");
-#endif
+               DPRINTF(("quiet NAN\n"));
                fpsr |= FPSR_NAN;
                break;
        case FPC_ZERO:
-#if DEBUG_FPE
-               printf("Zero\n");
-#endif
+               DPRINTF(("Zero\n"));
                fpsr |= FPSR_ZERO;
                break;
        case FPC_INF:
-#if DEBUG_FPE
-               printf("Inf\n");
-#endif
+               DPRINTF(("Inf\n"));
                fpsr |= FPSR_INF;
                break;
        default:
-#if DEBUG_FPE
-               printf("Number\n");
-#endif
+               DPRINTF(("Number\n"));
                /* anything else is treated as if it is a number */
                break;
        }
 
        fe->fe_fpsr = fe->fe_fpframe->fpf_fpsr = fpsr;
 
-#if DEBUG_FPE
-       printf("fpu_upd_fpsr: new fpsr=%08x\n", fe->fe_fpframe->fpf_fpsr);
-#endif
+       DPRINTF(("%s: new fpsr=%08x\n", __func__, fe->fe_fpframe->fpf_fpsr));
 
        return fpsr;
 }
@@ -395,9 +347,7 @@
        if (reglist != 1 && reglist != 2 && reglist != 4 &&
            (insn->is_ea.ea_flags & EA_DIRECT)) {
                /* attempted to copy more than one FPcr to CPU regs */
-#ifdef DEBUG
-               printf("fpu_emul_fmovmcr: tried to copy too many FPcr\n");
-#endif
+               DPRINTF(("%s: tried to copy too many FPcr\n", __func__));
                return SIGILL;
        }
 
@@ -406,10 +356,8 @@
                if ((insn->is_ea.ea_flags & EA_DIRECT) &&
                    insn->is_ea.ea_regnum >= 8 /* address reg */) {
                        /* attempted to copy FPCR to An */
-#ifdef DEBUG
-                       printf("fpu_emul_fmovmcr: tried to copy FPCR from/to "
-                           "A%d\n", insn->is_ea.ea_regnum & 7);
-#endif
+                       DPRINTF(("%s: tried to copy FPCR from/to A%d\n",
+                           __func__, insn->is_ea.ea_regnum & 7));
                        return SIGILL;
                }
                if (fpu_to_mem) {
@@ -428,10 +376,8 @@
                if ((insn->is_ea.ea_flags & EA_DIRECT) &&
                    insn->is_ea.ea_regnum >= 8 /* address reg */) {
                        /* attempted to copy FPSR to An */
-#ifdef DEBUG
-                       printf("fpu_emul_fmovmcr: tried to copy FPSR from/to "
-                           "A%d\n", insn->is_ea.ea_regnum & 7);
-#endif



Home | Main Index | Thread Index | Old Index