3 * Michael Smith, All rights reserved.
4 * Copyright (c) 1992, 1993, 1996
5 * Berkeley Software Design, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Berkeley Software
20 * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * from: BSDI doscmd.c,v 2.3 1996/04/08 19:32:30 bostic Exp
34 * $FreeBSD: src/usr.bin/doscmd/debug.c,v 1.3.2.2 2002/04/25 11:04:50 tg Exp $
35 * $DragonFly: src/usr.bin/doscmd/debug.c,v 1.2 2003/06/17 04:29:25 dillon Exp $
43 /* debug output goes here */
46 /* see doscmd.h for flag names */
47 int debug_flags
= D_ALWAYS
;
49 /* include register dumps when reporting unknown interrupts */
52 /* interrupts to trace */
53 #define BPW (sizeof(u_long) << 3)
54 u_long debug_ints
[256/BPW
];
56 /* Debug flag manipulation */
61 debug_ints
[x
/BPW
] |= 1 << (x
& (BPW
- 1));
68 debug_ints
[x
/BPW
] &= ~(1 << (x
& (BPW
- 1)));
75 return(debug_ints
[x
/BPW
] & (1 << (x
& (BPW
- 1))));
80 ** Emit a debugging message if (flags) matches the current
84 debug(int flags
, const char *fmt
, ...)
88 if (flags
& (debug_flags
& ~0xff)) {
89 if ((debug_flags
& 0xff) == 0
90 && (flags
& (D_ITRAPS
| D_TRAPS
))
91 && !debug_isset(flags
& 0xff))
94 vfprintf (debugf
, fmt
, args
);
100 ** Emit a terminal error message and exit
103 fatal(const char *fmt
, ...)
113 va_start (args
, fmt
);
114 vfprintf (debugf
, fmt
, args
);
115 vsprintf (buf
, fmt
, args
);
119 for (m
= buf
; *m
; ++m
)
120 tty_write(*m
, 0x0400);
123 for (m
= "(PRESS <CTRL-ALT> ANY MOUSE BUTTON TO exit)"; *m
; ++m
)
124 tty_write(*m
, 0x0900);
130 va_start (args
, fmt
);
131 fprintf (debugf
, "doscmd: fatal error ");
132 vfprintf (debugf
, fmt
, args
);
138 ** Emit a register dump (usually when dying)
141 dump_regs(regcontext_t
*REGS
)
147 debug (D_ALWAYS
, "\n");
148 debug (D_ALWAYS
, "ax=%04x bx=%04x cx=%04x dx=%04x\n", R_AX
, R_BX
, R_CX
, R_DX
);
149 debug (D_ALWAYS
, "si=%04x di=%04x sp=%04x bp=%04x\n", R_SI
, R_DI
, R_SP
, R_BP
);
150 debug (D_ALWAYS
, "cs=%04x ss=%04x ds=%04x es=%04x\n", R_CS
, R_SS
, R_DS
, R_ES
);
151 debug (D_ALWAYS
, "ip=%x eflags=%lx\n", R_IP
, R_EFLAGS
);
153 addr
= (u_char
*)MAKEPTR(R_CS
, R_IP
);
155 for (i
= 0; i
< 16; i
++)
156 debug (D_ALWAYS
, "%02x ", addr
[i
]);
157 debug (D_ALWAYS
, "\n");
159 addr
= (char *)MAKEPTR(R_CS
, R_IP
);
160 i386dis(R_CS
, R_IP
, addr
, buf
, 0);
162 debug (D_ALWAYS
, "%s\n", buf
);
166 ** Unknown interrupt error messages
169 unknown_int2(int maj
, int min
, regcontext_t
*REGS
)
171 if (vflag
) dump_regs(REGS
);
172 printf("Unknown interrupt %02x function %02x\n", maj
, min
);
177 unknown_int3(int maj
, int min
, int sub
, regcontext_t
*REGS
)
179 if (vflag
) dump_regs(REGS
);
180 printf("Unknown interrupt %02x function %02x subfunction %02x\n",
186 unknown_int4(int maj
, int min
, int sub
, int ss
, regcontext_t
*REGS
)
188 if (vflag
) dump_regs(REGS
);
189 printf("Unknown interrupt %02x function %02x subfunction %02x %02x\n",