Module Name: src
Committed By: tsutsui
Date: Wed May 25 15:47:19 UTC 2011
Modified Files:
src/sys/arch/m68k/fpe: fpu_calcea.c
Log Message:
- consistently use #ifdef DEBUG_FPE and #ifdef DIAGNOSTIC
- use DPRINTF() style debug printfs
- use __func__ to print function names
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/m68k/fpe/fpu_calcea.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/m68k/fpe/fpu_calcea.c
diff -u src/sys/arch/m68k/fpe/fpu_calcea.c:1.23 src/sys/arch/m68k/fpe/fpu_calcea.c:1.24
--- src/sys/arch/m68k/fpe/fpu_calcea.c:1.23 Wed May 25 15:17:21 2011
+++ src/sys/arch/m68k/fpe/fpu_calcea.c Wed May 25 15:47:19 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: fpu_calcea.c,v 1.23 2011/05/25 15:17:21 tsutsui Exp $ */
+/* $NetBSD: fpu_calcea.c,v 1.24 2011/05/25 15:47:19 tsutsui Exp $ */
/*
* Copyright (c) 1995 Gordon W. Ross
@@ -34,7 +34,7 @@
#include "opt_m68k_arch.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu_calcea.c,v 1.23 2011/05/25 15:17:21 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_calcea.c,v 1.24 2011/05/25 15:47:19 tsutsui Exp $");
#include <sys/param.h>
#include <sys/signal.h>
@@ -44,6 +44,12 @@
#include "fpu_emulate.h"
+#ifdef DEBUG_FPE
+#define DPRINTF(x) printf x
+#else
+#define DPRINTF(x) do {} while (/* CONSTCOND */ 0)
+#endif
+
/*
* Prototypes of static functions
*/
@@ -67,9 +73,9 @@
{
int sig;
-#ifdef DEBUG
+#ifdef DIAGNOSTIC
if (insn->is_datasize < 0)
- panic("decode_ea: called with uninitialized datasize");
+ panic("%s: called with uninitialized datasize", __func__);
#endif
sig = 0;
@@ -81,16 +87,14 @@
/* register direct */
ea->ea_regnum = modreg & 0xf;
ea->ea_flags = EA_DIRECT;
-#ifdef DEBUG_FPE
- printf("decode_ea: register direct reg=%d\n", ea->ea_regnum);
-#endif
+ DPRINTF(("%s: register direct reg=%d\n",
+ __func__, ea->ea_regnum));
} else if ((modreg & 077) == 074) {
/* immediate */
ea->ea_flags = EA_IMMED;
sig = fetch_immed(frame, insn, &ea->ea_immed[0]);
-#ifdef DEBUG_FPE
- printf("decode_ea: immediate size=%d\n", insn->is_datasize);
-#endif
+ DPRINTF(("%s: immediate size=%d\n",
+ __func__, insn->is_datasize));
}
/*
* rest of the address modes need to be separately
@@ -101,10 +105,8 @@
/* LC040 */
ea->ea_flags = EA_FRAME_EA;
ea->ea_fea = frame->f_fmt4.f_fa;
-#ifdef DEBUG_FPE
- printf("decode_ea: 68LC040 - in-frame EA (%p) size %d\n",
- (void *)ea->ea_fea, insn->is_datasize);
-#endif
+ DPRINTF(("%s: 68LC040 - in-frame EA (%p) size %d\n",
+ __func__, (void *)ea->ea_fea, insn->is_datasize));
if ((modreg & 070) == 030) {
/* postincrement mode */
ea->ea_flags |= EA_POSTINCR;
@@ -127,35 +129,27 @@
case 020: /* (An) */
ea->ea_flags = 0;
-#ifdef DEBUG_FPE
- printf("decode_ea: register indirect reg=%d\n",
- ea->ea_regnum);
-#endif
+ DPRINTF(("%s: register indirect reg=%d\n",
+ __func__, ea->ea_regnum));
break;
case 030: /* (An)+ */
ea->ea_flags = EA_POSTINCR;
-#ifdef DEBUG_FPE
- printf("decode_ea: reg indirect postincrement reg=%d\n",
- ea->ea_regnum);
-#endif
+ DPRINTF(("%s: reg indirect postincrement reg=%d\n",
+ __func__, ea->ea_regnum));
break;
case 040: /* -(An) */
ea->ea_flags = EA_PREDECR;
-#ifdef DEBUG_FPE
- printf("decode_ea: reg indirect predecrement reg=%d\n",
- ea->ea_regnum);
-#endif
+ DPRINTF(("%s: reg indirect predecrement reg=%d\n",
+ __func__, ea->ea_regnum));
break;
case 050: /* (d16,An) */
ea->ea_flags = EA_OFFSET;
sig = fetch_disp(frame, insn, 1, &ea->ea_offset);
-#ifdef DEBUG_FPE
- printf("decode_ea: reg indirect with displacement "
- "reg=%d\n", ea->ea_regnum);
-#endif
+ DPRINTF(("%s: reg indirect with displacement reg=%d\n",
+ __func__, ea->ea_regnum));
break;
case 060: /* (d8,An,Xn) */
@@ -171,28 +165,24 @@
ea->ea_flags = EA_ABS;
sig = fetch_disp(frame, insn, 1,
&ea->ea_absaddr);
-#ifdef DEBUG_FPE
- printf("decode_ea: absolute address (word)\n");
-#endif
+ DPRINTF(("%s: absolute address (word)\n",
+ __func__));
break;
case 1: /* (xxxxxxxx).L */
ea->ea_flags = EA_ABS;
sig = fetch_disp(frame, insn, 2,
&ea->ea_absaddr);
-#ifdef DEBUG_FPE
- printf("decode_ea: absolute address (long)\n");
-#endif
+ DPRINTF(("%s: absolute address (long)\n",
+ __func__));
break;
case 2: /* (d16,PC) */
ea->ea_flags = EA_PC_REL | EA_OFFSET;
sig = fetch_disp(frame, insn, 1,
&ea->ea_absaddr);
-#ifdef DEBUG_FPE
- printf("decode_ea: pc relative word "
- "displacement\n");
-#endif
+ DPRINTF(("%s: pc relative word displacement\n",
+ __func__));
break;
case 3: /* (d8,PC,Xn) */
@@ -203,10 +193,8 @@
case 4: /* #data */
/* it should have been taken care of earlier */
default:
-#ifdef DEBUG_FPE
- printf("decode_ea: invalid addr mode (7,%d)\n",
- modreg & 7);
-#endif
+ DPRINTF(("%s: invalid addr mode (7,%d)\n",
+ __func__, modreg & 7));
return SIGILL;
}
break;
@@ -257,10 +245,8 @@
ea->ea_basedisp = idx + basedisp;
ea->ea_outerdisp = 0;
-#if DEBUG_FPE
- printf("decode_ea6: brief ext word idxreg=%d, basedisp=%08x\n",
- ea->ea_idxreg, ea->ea_basedisp);
-#endif
+ DPRINTF(("%s: brief ext word idxreg=%d, basedisp=%08x\n",
+ __func__, ea->ea_idxreg, ea->ea_basedisp));
} else {
/* full extension word */
if (extword & 0x80) {
@@ -291,23 +277,17 @@
ea->ea_outerdisp = outerdisp;
break;
default:
-#ifdef DEBUG
- printf("decode_ea6: invalid indirect mode: "
- "ext word %04x\n", extword);
-#endif
+ DPRINTF(("%s: invalid indirect mode: ext word %04x\n",
+ __func__, extword));
return SIGILL;
break;
}
-#if DEBUG_FPE
- printf("decode_ea6: full ext idxreg=%d, basedisp=%x, "
- "outerdisp=%x\n",
- ea->ea_idxreg, ea->ea_basedisp, ea->ea_outerdisp);
-#endif
+ DPRINTF(("%s: full ext idxreg=%d, basedisp=%x, outerdisp=%x\n",
+ __func__,
+ ea->ea_idxreg, ea->ea_basedisp, ea->ea_outerdisp));
}
-#if DEBUG_FPE
- printf("decode_ea6: regnum=%d, flags=%x\n",
- ea->ea_regnum, ea->ea_flags);
-#endif
+ DPRINTF(("%s: regnum=%d, flags=%x\n",
+ __func__, ea->ea_regnum, ea->ea_flags));
return 0;
}
@@ -326,12 +306,10 @@
#ifdef DIAGNOSTIC
if (ea->ea_regnum & ~0xF)
- panic("load_ea: bad regnum");
+ panic("%s: bad regnum", __func__);
#endif
-#ifdef DEBUG_FPE
- printf("load_ea: frame at %p\n", frame);
-#endif
+ DPRINTF(("%s: frame at %p\n", __func__, frame));
/* dst is always int or larger. */
len = insn->is_datasize;
if (len < 4)
@@ -343,10 +321,10 @@
/* Using LC040 frame EA */
#ifdef DEBUG_FPE
if (ea->ea_flags & (EA_PREDECR|EA_POSTINCR)) {
- printf("load_ea: frame ea %08x w/r%d\n",
- ea->ea_fea, ea->ea_regnum);
+ printf("%s: frame ea %08x w/r%d\n",
+ __func__, ea->ea_fea, ea->ea_regnum);
} else {
- printf("load_ea: frame ea %08x\n", ea->ea_fea);
+ printf("%s: frame ea %08x\n", __func__, ea->ea_fea);
}
#endif
src = (char *)ea->ea_fea;
@@ -367,85 +345,66 @@
#endif
if (ea->ea_flags & EA_DIRECT) {
if (len > 4) {
-#ifdef DEBUG
- printf("load_ea: operand doesn't fit CPU reg\n");
-#endif
+ DPRINTF(("%s: operand doesn't fit CPU reg\n",
+ __func__));
return SIGILL;
}
if (ea->ea_moffs > 0) {
-#ifdef DEBUG
- printf("load_ea: more than one move from CPU reg\n");
-#endif
+ DPRINTF(("%s: more than one move from CPU reg\n",
+ __func__));
return SIGILL;
}
src = (char *)&frame->f_regs[ea->ea_regnum];
/* The source is an int. */
if (len < 4) {
src += (4 - len);
-#ifdef DEBUG_FPE
- printf("load_ea: short/byte opr - addr adjusted\n");
-#endif
+ DPRINTF(("%s: short/byte opr - addr adjusted\n",
+ __func__));
}
-#ifdef DEBUG_FPE
- printf("load_ea: src %p\n", src);
-#endif
+ DPRINTF(("%s: src %p\n", __func__, src));
memcpy(dst, src, len);
} else if (ea->ea_flags & EA_IMMED) {
-#ifdef DEBUG_FPE
- printf("load_ea: immed %08x%08x%08x size %d\n",
- ea->ea_immed[0], ea->ea_immed[1], ea->ea_immed[2], len);
-#endif
+ DPRINTF(("%s: immed %08x%08x%08x size %d\n", __func__,
+ ea->ea_immed[0], ea->ea_immed[1], ea->ea_immed[2], len));
src = (char *)&ea->ea_immed[0];
if (len < 4) {
src += (4 - len);
-#ifdef DEBUG_FPE
- printf("load_ea: short/byte immed opr - "
- "addr adjusted\n");
-#endif
+ DPRINTF(("%s: short/byte immed opr - "
+ "addr adjusted\n", __func__));
}
memcpy(dst, src, len);
} else if (ea->ea_flags & EA_ABS) {
-#ifdef DEBUG_FPE
- printf("load_ea: abs addr %08x\n", ea->ea_absaddr);
-#endif
+ DPRINTF(("%s: abs addr %08x\n", __func__, ea->ea_absaddr));
src = (char *)ea->ea_absaddr;
copyin(src, dst, len);
} else /* register indirect */ {
if (ea->ea_flags & EA_PC_REL) {
-#ifdef DEBUG_FPE
- printf("load_ea: using PC\n");
-#endif
+ DPRINTF(("%s: using PC\n", __func__));
reg = NULL;
/*
* Grab the register contents. 4 is offset to the first
* extension word from the opcode
*/
src = (char *)insn->is_pc + 4;
-#ifdef DEBUG_FPE
- printf("load_ea: pc relative pc+4 = %p\n", src);
-#endif
+ DPRINTF(("%s: pc relative pc+4 = %p\n", __func__, src));
} else /* not PC relative */ {
-#ifdef DEBUG_FPE
- printf("load_ea: using register %c%d\n",
- (ea->ea_regnum >= 8) ? 'a' : 'd', ea->ea_regnum & 7);
-#endif
+ DPRINTF(("%s: using register %c%d\n",
+ __func__,
+ (ea->ea_regnum >= 8) ? 'a' : 'd',
+ ea->ea_regnum & 7));
/* point to the register */
reg = &frame->f_regs[ea->ea_regnum];
if (ea->ea_flags & EA_PREDECR) {
-#ifdef DEBUG_FPE
- printf("load_ea: predecr mode - "
- "reg decremented\n");
-#endif
+ DPRINTF(("%s: predecr mode - "
+ "reg decremented\n", __func__));
*reg -= step;
ea->ea_moffs = 0;
}
/* Grab the register contents. */
src = (char *)*reg;
-#ifdef DEBUG_FPE
- printf("load_ea: reg indirect reg = %p\n", src);
-#endif
+ DPRINTF(("%s: reg indirect reg = %p\n", __func__, src));
}
sig = calc_ea(ea, src, &src);
@@ -457,16 +416,14 @@
/* do post-increment */
if (ea->ea_flags & EA_POSTINCR) {
if (ea->ea_flags & EA_PC_REL) {
-#ifdef DEBUG
- printf("load_ea: tried to postincrement PC\n");
-#endif
+ DPRINTF(("%s: tried to postincrement PC\n",
+ __func__));
return SIGILL;
}
*reg += step;
ea->ea_moffs = 0;
-#ifdef DEBUG_FPE
- printf("load_ea: postinc mode - reg incremented\n");
-#endif
+ DPRINTF(("%s: postinc mode - reg incremented\n",
+ __func__));
} else {
ea->ea_moffs += len;
}
@@ -488,16 +445,14 @@
int len, step;
int sig;
-#ifdef DIAGNOSTIC
+#ifdef DIAGNOSTIC
if (ea->ea_regnum & ~0xf)
- panic("store_ea: bad regnum");
+ panic("%s: bad regnum", __func__);
#endif
if (ea->ea_flags & (EA_IMMED|EA_PC_REL)) {
/* not alterable address mode */
-#ifdef DEBUG
- printf("store_ea: not alterable address mode\n");
-#endif
+ DPRINTF(("%s: not alterable address mode\n", __func__));
return SIGILL;
}
@@ -511,10 +466,10 @@
/* Using LC040 frame EA */
#ifdef DEBUG_FPE
if (ea->ea_flags & (EA_PREDECR|EA_POSTINCR)) {
- printf("store_ea: frame ea %08x w/r%d\n",
- ea->ea_fea, ea->ea_regnum);
+ printf("%s: frame ea %08x w/r%d\n",
+ __func__, ea->ea_fea, ea->ea_regnum);
} else {
- printf("store_ea: frame ea %08x\n", ea->ea_fea);
+ printf("%s: frame ea %08x\n", __func__, ea->ea_fea);
}
#endif
dst = (char *)ea->ea_fea;
@@ -532,51 +487,40 @@
}
/* That's it, folks */
} else if (ea->ea_flags & EA_ABS) {
-#ifdef DEBUG_FPE
- printf("store_ea: abs addr %08x\n", ea->ea_absaddr);
-#endif
+ DPRINTF(("%s: abs addr %08x\n", __func__, ea->ea_absaddr));
dst = (char *)ea->ea_absaddr;
copyout(src, dst + ea->ea_moffs, len);
ea->ea_moffs += len;
} else if (ea->ea_flags & EA_DIRECT) {
if (len > 4) {
-#ifdef DEBUG
- printf("store_ea: operand doesn't fit CPU reg\n");
-#endif
+ DPRINTF(("%s: operand doesn't fit CPU reg\n",
+ __func__));
return SIGILL;
}
if (ea->ea_moffs > 0) {
-#ifdef DEBUG
- printf("store_ea: more than one move to CPU reg\n");
-#endif
+ DPRINTF(("%s: more than one move to CPU reg\n",
+ __func__));
return SIGILL;
}
dst = (char *)&frame->f_regs[ea->ea_regnum];
/* The destination is an int. */
if (len < 4) {
dst += (4 - len);
-#ifdef DEBUG_FPE
- printf("store_ea: short/byte opr - "
- "dst addr adjusted\n");
-#endif
+ DPRINTF(("%s: short/byte opr - dst addr adjusted\n",
+ __func__));
}
-#ifdef DEBUG_FPE
- printf("store_ea: dst %p\n", dst);
-#endif
+ DPRINTF(("%s: dst %p\n", __func__, dst));
memcpy(dst, src, len);
} else /* One of MANY indirect forms... */ {
-#ifdef DEBUG_FPE
- printf("store_ea: using register %c%d\n",
- (ea->ea_regnum >= 8) ? 'a' : 'd', ea->ea_regnum & 7);
-#endif
+ DPRINTF(("%s: using register %c%d\n", __func__,
+ (ea->ea_regnum >= 8) ? 'a' : 'd', ea->ea_regnum & 7));
/* point to the register */
reg = &(frame->f_regs[ea->ea_regnum]);
/* do pre-decrement */
if (ea->ea_flags & EA_PREDECR) {
-#ifdef DEBUG_FPE
- printf("store_ea: predecr mode - reg decremented\n");
-#endif
+ DPRINTF(("%s: predecr mode - reg decremented\n",
+ __func__));
*reg -= step;
ea->ea_moffs = 0;
}
@@ -586,18 +530,15 @@
if (sig)
return sig;
-#ifdef DEBUG_FPE
- printf("store_ea: dst addr=%p+%d\n", dst, ea->ea_moffs);
-#endif
+ DPRINTF(("%s: dst addr=%p+%d\n", __func__, dst, ea->ea_moffs));
copyout(src, dst + ea->ea_moffs, len);
/* do post-increment */
if (ea->ea_flags & EA_POSTINCR) {
*reg += step;
ea->ea_moffs = 0;
-#ifdef DEBUG_FPE
- printf("store_ea: postinc mode - reg incremented\n");
-#endif
+ DPRINTF(("%s: postinc mode - reg incremented\n",
+ __func__));
} else {
ea->ea_moffs += len;
}
@@ -716,20 +657,14 @@
{
int data, word;
-#if DEBUG_FPE
- printf("calc_ea: reg indirect (reg) = %p\n", ptr);
-#endif
+ DPRINTF(("%s: reg indirect (reg) = %p\n", __func__, ptr));
if (ea->ea_flags & EA_OFFSET) {
/* apply the signed offset */
-#if DEBUG_FPE
- printf("calc_ea: offset %d\n", ea->ea_offset);
-#endif
+ DPRINTF(("%s: offset %d\n", __func__, ea->ea_offset));
ptr += ea->ea_offset;
} else if (ea->ea_flags & EA_INDEXED) {
-#if DEBUG_FPE
- printf("calc_ea: indexed mode\n");
-#endif
+ DPRINTF(("%s: indexed mode\n", __func__));
if (ea->ea_flags & EA_BASE_SUPPRSS) {
/* base register is suppressed */
@@ -739,12 +674,10 @@
}
if (ea->ea_flags & EA_MEM_INDIR) {
-#if DEBUG_FPE
- printf("calc_ea: mem indir mode: basedisp=%08x, "
+ DPRINTF(("%s: mem indir mode: basedisp=%08x, "
"outerdisp=%08x\n",
- ea->ea_basedisp, ea->ea_outerdisp);
- printf("calc_ea: addr fetched from %p\n", ptr);
-#endif
+ __func__, ea->ea_basedisp, ea->ea_outerdisp));
+ DPRINTF(("%s: addr fetched from %p\n", __func__, ptr));
/* memory indirect modes */
word = fusword(ptr);
if (word < 0)
@@ -754,9 +687,7 @@
if (data < 0)
return SIGSEGV;
word |= data;
-#if DEBUG_FPE
- printf("calc_ea: fetched ptr 0x%08x\n", word);
-#endif
+ DPRINTF(("%s: fetched ptr 0x%08x\n", __func__, word));
ptr = (char *)word + ea->ea_outerdisp;
}
}