1997-08-09 01:43:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996
|
|
|
|
* Michael Smith, All rights reserved.
|
|
|
|
* Copyright (c) 1992, 1993, 1996
|
|
|
|
* Berkeley Software Design, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Berkeley Software
|
|
|
|
* Design, Inc.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from: BSDI doscmd.c,v 2.3 1996/04/08 19:32:30 bostic Exp
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1997-08-09 01:43:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "doscmd.h"
|
2001-07-24 11:50:23 +00:00
|
|
|
#include "tty.h"
|
1997-08-09 01:43:15 +00:00
|
|
|
|
|
|
|
/* debug output goes here */
|
2001-08-13 21:56:39 +00:00
|
|
|
FILE *debugf;
|
1997-08-09 01:43:15 +00:00
|
|
|
|
|
|
|
/* see doscmd.h for flag names */
|
|
|
|
int debug_flags = D_ALWAYS;
|
|
|
|
|
|
|
|
/* include register dumps when reporting unknown interrupts */
|
|
|
|
int vflag = 0;
|
|
|
|
|
|
|
|
/* interrupts to trace */
|
|
|
|
#define BPW (sizeof(u_long) << 3)
|
|
|
|
u_long debug_ints[256/BPW];
|
|
|
|
|
|
|
|
/* Debug flag manipulation */
|
|
|
|
void
|
|
|
|
debug_set(int x)
|
|
|
|
{
|
|
|
|
x &= 0xff;
|
|
|
|
debug_ints[x/BPW] |= 1 << (x & (BPW - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
debug_unset(int x)
|
|
|
|
{
|
|
|
|
x &= 0xff;
|
|
|
|
debug_ints[x/BPW] &= ~(1 << (x & (BPW - 1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
u_long
|
|
|
|
debug_isset(int x)
|
|
|
|
{
|
|
|
|
x &= 0xff;
|
|
|
|
return(debug_ints[x/BPW] & (1 << (x & (BPW - 1))));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Emit a debugging message if (flags) matches the current
|
|
|
|
** debugging mode.
|
|
|
|
*/
|
|
|
|
void
|
2001-08-08 10:58:50 +00:00
|
|
|
debug(int flags, const char *fmt, ...)
|
1997-08-09 01:43:15 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (flags & (debug_flags & ~0xff)) {
|
|
|
|
if ((debug_flags & 0xff) == 0
|
2001-08-08 10:58:50 +00:00
|
|
|
&& (flags & (D_ITRAPS | D_TRAPS))
|
1997-08-09 01:43:15 +00:00
|
|
|
&& !debug_isset(flags & 0xff))
|
|
|
|
return;
|
|
|
|
va_start (args, fmt);
|
|
|
|
vfprintf (debugf, fmt, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Emit a terminal error message and exit
|
|
|
|
*/
|
|
|
|
void
|
2001-08-08 10:58:50 +00:00
|
|
|
fatal(const char *fmt, ...)
|
1997-08-09 01:43:15 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
dead = 1;
|
|
|
|
|
|
|
|
if (xmode) {
|
|
|
|
char buf[1024];
|
2001-08-08 10:58:50 +00:00
|
|
|
const char *m;
|
1997-08-09 01:43:15 +00:00
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
vfprintf (debugf, fmt, args);
|
|
|
|
vsprintf (buf, fmt, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
tty_move(23, 0);
|
|
|
|
for (m = buf; *m; ++m)
|
|
|
|
tty_write(*m, 0x0400);
|
|
|
|
|
|
|
|
tty_move(24, 0);
|
|
|
|
for (m = "(PRESS <CTRL-ALT> ANY MOUSE BUTTON TO exit)"; *m; ++m)
|
|
|
|
tty_write(*m, 0x0900);
|
|
|
|
tty_move(-1, -1);
|
|
|
|
for (;;)
|
|
|
|
tty_pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
fprintf (debugf, "doscmd: fatal error ");
|
|
|
|
vfprintf (debugf, fmt, args);
|
|
|
|
va_end (args);
|
|
|
|
quit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Emit a register dump (usually when dying)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
dump_regs(regcontext_t *REGS)
|
|
|
|
{
|
|
|
|
u_char *addr;
|
|
|
|
int i;
|
|
|
|
char buf[100];
|
|
|
|
|
|
|
|
debug (D_ALWAYS, "\n");
|
|
|
|
debug (D_ALWAYS, "ax=%04x bx=%04x cx=%04x dx=%04x\n", R_AX, R_BX, R_CX, R_DX);
|
|
|
|
debug (D_ALWAYS, "si=%04x di=%04x sp=%04x bp=%04x\n", R_SI, R_DI, R_SP, R_BP);
|
|
|
|
debug (D_ALWAYS, "cs=%04x ss=%04x ds=%04x es=%04x\n", R_CS, R_SS, R_DS, R_ES);
|
2001-07-31 11:27:48 +00:00
|
|
|
debug (D_ALWAYS, "ip=%x eflags=%lx\n", R_IP, R_EFLAGS);
|
1997-08-09 01:43:15 +00:00
|
|
|
|
1999-09-29 20:09:19 +00:00
|
|
|
addr = (u_char *)MAKEPTR(R_CS, R_IP);
|
1997-08-09 01:43:15 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
debug (D_ALWAYS, "%02x ", addr[i]);
|
|
|
|
debug (D_ALWAYS, "\n");
|
|
|
|
|
1999-09-29 20:09:19 +00:00
|
|
|
addr = (char *)MAKEPTR(R_CS, R_IP);
|
1997-08-09 01:43:15 +00:00
|
|
|
i386dis(R_CS, R_IP, addr, buf, 0);
|
|
|
|
|
|
|
|
debug (D_ALWAYS, "%s\n", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Unknown interrupt error messages
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
unknown_int2(int maj, int min, regcontext_t *REGS)
|
|
|
|
{
|
|
|
|
if (vflag) dump_regs(REGS);
|
|
|
|
printf("Unknown interrupt %02x function %02x\n", maj, min);
|
|
|
|
R_FLAGS |= PSL_C;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
unknown_int3(int maj, int min, int sub, regcontext_t *REGS)
|
|
|
|
{
|
|
|
|
if (vflag) dump_regs(REGS);
|
|
|
|
printf("Unknown interrupt %02x function %02x subfunction %02x\n",
|
|
|
|
maj, min, sub);
|
|
|
|
R_FLAGS |= PSL_C;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
unknown_int4(int maj, int min, int sub, int ss, regcontext_t *REGS)
|
|
|
|
{
|
|
|
|
if (vflag) dump_regs(REGS);
|
|
|
|
printf("Unknown interrupt %02x function %02x subfunction %02x %02x\n",
|
|
|
|
maj, min, sub, ss);
|
|
|
|
R_FLAGS |= PSL_C;
|
|
|
|
}
|
|
|
|
|