Cleanup from magnum branch.

This commit is contained in:
mycroft 1993-12-19 03:41:30 +00:00
parent e1a021aee8
commit 90b25c90a1
4 changed files with 543 additions and 720 deletions

View File

@ -23,42 +23,8 @@
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*
* $Id: db_disasm.c,v 1.3 1993/07/17 12:28:47 cgd Exp $
*/
/*
* HISTORY
* $Log: db_disasm.c,v $
* Revision 1.3 1993/07/17 12:28:47 cgd
* Fixed two occarances of ldos which should have been lods.
* (From Christoph Robitschko)
*
* Revision 1.2 1993/05/22 07:59:42 cgd
* add rcsids to everything and clean up headers
*
* Revision 1.1.1.1 1993/03/21 09:45:52 cgd
* initial import of 386bsd-0.1 sources
*
* Revision 1.1 1992/03/25 21:42:01 pace
* Initial revision
*
* Revision 2.3 91/02/05 17:11:03 mrt
* Changed to new Mach copyright
* [91/02/01 17:31:03 mrt]
*
* Revision 2.2 90/08/27 21:55:56 dbg
* Fix register operand for move to/from control/test/debug
* register instructions. Add i486 instructions.
* [90/08/27 dbg]
*
* Import db_sym.h. Print instruction displacements in
* current radix (signed). Change calling sequence of
* db_disasm.
* [90/08/21 dbg]
* Fix includes.
* [90/08/08 dbg]
* Created.
* [90/07/25 dbg]
*
* From: Id: db_disasm.c,v 2.3 91/02/05 17:11:03 mrt (CMU)
* $Id: db_disasm.c,v 1.4 1993/12/19 03:41:30 mycroft Exp $
*/
/*
@ -882,8 +848,10 @@ int db_lengths[] = {
};
#define get_value_inc(result, loc, size, is_signed) \
result = db_get_value((loc), (size), (is_signed)); \
(loc) += (size);
do { \
result = db_get_value((loc), (size), (is_signed)); \
(loc) += (size); \
} while (0)
/*
* Read address at location and return updated location.
@ -901,74 +869,69 @@ db_read_address(loc, short_addr, regmodrm, addrp)
rm = f_rm(regmodrm);
if (mod == 3) {
addrp->is_reg = TRUE;
addrp->disp = rm;
return (loc);
addrp->is_reg = TRUE;
addrp->disp = rm;
return (loc);
}
addrp->is_reg = FALSE;
addrp->index = 0;
if (short_addr) {
addrp->index = 0;
addrp->ss = 0;
switch (mod) {
case 0:
if (rm == 6) {
addrp->index = 0;
addrp->ss = 0;
switch (mod) {
case 0:
if (rm == 6) {
get_value_inc(disp, loc, 2, TRUE);
addrp->disp = disp;
addrp->base = 0;
} else {
addrp->disp = 0;
addrp->base = db_index_reg_16[rm];
}
break;
case 1:
get_value_inc(disp, loc, 1, TRUE);
addrp->disp = disp;
addrp->base = db_index_reg_16[rm];
break;
case 2:
get_value_inc(disp, loc, 2, TRUE);
addrp->disp = disp;
addrp->base = 0;
}
else {
addrp->disp = 0;
addrp->base = db_index_reg_16[rm];
}
break;
case 1:
get_value_inc(disp, loc, 1, TRUE);
addrp->disp = disp;
addrp->base = db_index_reg_16[rm];
break;
case 2:
get_value_inc(disp, loc, 2, TRUE);
addrp->disp = disp;
addrp->base = db_index_reg_16[rm];
break;
}
}
else {
if (mod != 3 && rm == 4) {
get_value_inc(sib, loc, 1, FALSE);
rm = sib_base(sib);
index = sib_index(sib);
if (index != 4)
addrp->index = db_reg[LONG][index];
addrp->ss = sib_ss(sib);
}
break;
}
} else {
if (mod != 3 && rm == 4) {
get_value_inc(sib, loc, 1, FALSE);
rm = sib_base(sib);
index = sib_index(sib);
if (index != 4)
addrp->index = db_reg[LONG][index];
addrp->ss = sib_ss(sib);
}
switch (mod) {
case 0:
if (rm == 5) {
get_value_inc(addrp->disp, loc, 4, FALSE);
addrp->base = 0;
}
else {
addrp->disp = 0;
switch (mod) {
case 0:
if (rm == 5) {
get_value_inc(addrp->disp, loc, 4, FALSE);
addrp->base = 0;
} else {
addrp->disp = 0;
addrp->base = db_reg[LONG][rm];
}
break;
case 1:
get_value_inc(disp, loc, 1, TRUE);
addrp->disp = disp;
addrp->base = db_reg[LONG][rm];
}
break;
case 1:
get_value_inc(disp, loc, 1, TRUE);
addrp->disp = disp;
addrp->base = db_reg[LONG][rm];
break;
case 2:
get_value_inc(disp, loc, 4, FALSE);
addrp->disp = disp;
addrp->base = db_reg[LONG][rm];
break;
}
break;
case 2:
get_value_inc(disp, loc, 4, FALSE);
addrp->disp = disp;
addrp->base = db_reg[LONG][rm];
break;
}
}
return (loc);
}
@ -980,22 +943,21 @@ db_print_address(seg, size, addrp)
struct i_addr *addrp;
{
if (addrp->is_reg) {
db_printf("%s", db_reg[size][addrp->disp]);
return;
db_printf("%s", db_reg[size][addrp->disp]);
return;
}
if (seg) {
db_printf("%s:", seg);
}
if (seg)
db_printf("%s:", seg);
db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
if (addrp->base != 0 || addrp->index != 0) {
db_printf("(");
if (addrp->base)
db_printf("%s", addrp->base);
if (addrp->index)
db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
db_printf(")");
db_printf("(");
if (addrp->base)
db_printf("%s", addrp->base);
if (addrp->index)
db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
db_printf(")");
}
}
@ -1021,64 +983,63 @@ db_disasm_esc(loc, inst, short_addr, size, seg)
fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
mod = f_mod(regmodrm);
if (mod != 3) {
/*
* Normal address modes.
*/
loc = db_read_address(loc, short_addr, regmodrm, &address);
db_printf(fp->f_name);
switch(fp->f_size) {
case SNGL:
db_printf("s");
break;
case DBLR:
db_printf("l");
break;
case EXTR:
db_printf("t");
break;
case WORD:
db_printf("s");
break;
case LONG:
db_printf("l");
break;
case QUAD:
db_printf("q");
break;
default:
break;
}
db_printf("\t");
db_print_address(seg, BYTE, &address);
}
else {
/*
* 'reg-reg' - special formats
*/
switch (fp->f_rrmode) {
case op2(ST,STI):
name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
db_printf("%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
break;
case op2(STI,ST):
name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
db_printf("%s\t%%st(%d),%%st",name, f_rm(regmodrm));
break;
case op1(STI):
name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
db_printf("%s\t%%st(%d)",name, f_rm(regmodrm));
break;
case op1(X):
db_printf("%s", ((char **)fp->f_rrname)[f_rm(regmodrm)]);
break;
case op1(XA):
db_printf("%s\t%%ax",
((char **)fp->f_rrname)[f_rm(regmodrm)]);
break;
default:
db_printf("<bad instruction>");
break;
}
/*
* Normal address modes.
*/
loc = db_read_address(loc, short_addr, regmodrm, &address);
db_printf(fp->f_name);
switch(fp->f_size) {
case SNGL:
db_printf("s");
break;
case DBLR:
db_printf("l");
break;
case EXTR:
db_printf("t");
break;
case WORD:
db_printf("s");
break;
case LONG:
db_printf("l");
break;
case QUAD:
db_printf("q");
break;
default:
break;
}
db_printf("\t");
db_print_address(seg, BYTE, &address);
} else {
/*
* 'reg-reg' - special formats
*/
switch (fp->f_rrmode) {
case op2(ST,STI):
name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
db_printf("%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
break;
case op2(STI,ST):
name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
db_printf("%s\t%%st(%d),%%st",name, f_rm(regmodrm));
break;
case op1(STI):
name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
db_printf("%s\t%%st(%d)",name, f_rm(regmodrm));
break;
case op1(X):
db_printf("%s", ((char **)fp->f_rrname)[f_rm(regmodrm)]);
break;
case op1(XA):
db_printf("%s\t%%ax",
((char **)fp->f_rrname)[f_rm(regmodrm)]);
break;
default:
db_printf("<bad instruction>");
break;
}
}
return (loc);
@ -1121,71 +1082,68 @@ db_disasm(loc, altfmt)
*/
prefix = TRUE;
do {
switch (inst) {
case 0x66: /* data16 */
size = WORD;
break;
case 0x67:
short_addr = TRUE;
break;
case 0x26:
seg = "%es";
break;
case 0x36:
seg = "%ss";
break;
case 0x2e:
seg = "%cs";
break;
case 0x3e:
seg = "%ds";
break;
case 0x64:
seg = "%fs";
break;
case 0x65:
seg = "%gs";
break;
case 0xf0:
db_printf("lock ");
break;
case 0xf2:
db_printf("repne ");
break;
case 0xf3:
db_printf("repe "); /* XXX repe VS rep */
break;
default:
prefix = FALSE;
break;
}
if (prefix) {
get_value_inc(inst, loc, 1, FALSE);
}
switch (inst) {
case 0x66: /* data16 */
size = WORD;
break;
case 0x67:
short_addr = TRUE;
break;
case 0x26:
seg = "%es";
break;
case 0x36:
seg = "%ss";
break;
case 0x2e:
seg = "%cs";
break;
case 0x3e:
seg = "%ds";
break;
case 0x64:
seg = "%fs";
break;
case 0x65:
seg = "%gs";
break;
case 0xf0:
db_printf("lock ");
break;
case 0xf2:
db_printf("repne ");
break;
case 0xf3:
db_printf("repe "); /* XXX repe VS rep */
break;
default:
prefix = FALSE;
break;
}
if (prefix)
get_value_inc(inst, loc, 1, FALSE);
} while (prefix);
if (inst >= 0xd8 && inst <= 0xdf) {
loc = db_disasm_esc(loc, inst, short_addr, size, seg);
db_printf("\n");
return (loc);
loc = db_disasm_esc(loc, inst, short_addr, size, seg);
db_printf("\n");
return (loc);
}
if (inst == 0x0f) {
get_value_inc(inst, loc, 1, FALSE);
ip = db_inst_0f[inst>>4];
if (ip == 0) {
ip = &db_bad_inst;
}
else {
ip = &ip[inst&0xf];
}
get_value_inc(inst, loc, 1, FALSE);
ip = db_inst_0f[inst>>4];
if (ip == 0)
ip = &db_bad_inst;
else
ip = &ip[inst&0xf];
} else {
ip = &db_inst_table[inst];
}
else
ip = &db_inst_table[inst];
if (ip->i_has_modrm) {
get_value_inc(regmodrm, loc, 1, FALSE);
loc = db_read_address(loc, short_addr, regmodrm, &address);
get_value_inc(regmodrm, loc, 1, FALSE);
loc = db_read_address(loc, short_addr, regmodrm, &address);
}
i_name = ip->i_name;
@ -1197,213 +1155,173 @@ db_disasm(loc, altfmt)
ip->i_extra == (char *)db_Grp6 ||
ip->i_extra == (char *)db_Grp7 ||
ip->i_extra == (char *)db_Grp8) {
i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
}
else if (ip->i_extra == (char *)db_Grp3) {
ip = (struct inst *)ip->i_extra;
ip = &ip[f_reg(regmodrm)];
i_name = ip->i_name;
i_mode = ip->i_mode;
}
else if (ip->i_extra == (char *)db_Grp4 ||
ip->i_extra == (char *)db_Grp5) {
ip = (struct inst *)ip->i_extra;
ip = &ip[f_reg(regmodrm)];
i_name = ip->i_name;
i_mode = ip->i_mode;
i_size = ip->i_size;
i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
} else if (ip->i_extra == (char *)db_Grp3) {
ip = (struct inst *)ip->i_extra;
ip = &ip[f_reg(regmodrm)];
i_name = ip->i_name;
i_mode = ip->i_mode;
} else if (ip->i_extra == (char *)db_Grp4 ||
ip->i_extra == (char *)db_Grp5) {
ip = (struct inst *)ip->i_extra;
ip = &ip[f_reg(regmodrm)];
i_name = ip->i_name;
i_mode = ip->i_mode;
i_size = ip->i_size;
}
if (i_size == SDEP) {
if (size == WORD)
db_printf(i_name);
else
db_printf(ip->i_extra);
}
else {
db_printf(i_name);
if (i_size != NONE) {
if (i_size == BYTE) {
db_printf("b");
size = BYTE;
}
else if (i_size == WORD) {
db_printf("w");
size = WORD;
}
else if (size == WORD)
db_printf("w");
if (size == WORD)
db_printf(i_name);
else
db_printf("l");
}
db_printf(ip->i_extra);
} else {
db_printf(i_name);
if (i_size != NONE) {
if (i_size == BYTE) {
db_printf("b");
size = BYTE;
} else if (i_size == WORD) {
db_printf("w");
size = WORD;
} else if (size == WORD) {
db_printf("w");
} else {
db_printf("l");
}
}
}
db_printf("\t");
for (first = TRUE;
i_mode != 0;
i_mode >>= 8, first = FALSE)
{
if (!first)
db_printf(",");
i_mode >>= 8, first = FALSE) {
if (!first)
db_printf(",");
switch (i_mode & 0xFF) {
case E:
db_print_address(seg, size, &address);
break;
case Eind:
db_printf("*");
db_print_address(seg, size, &address);
break;
case Ew:
db_print_address(seg, WORD, &address);
break;
case Eb:
db_print_address(seg, BYTE, &address);
break;
case R:
db_printf("%s", db_reg[size][f_reg(regmodrm)]);
break;
case Rw:
db_printf("%s", db_reg[WORD][f_reg(regmodrm)]);
break;
case Ri:
db_printf("%s", db_reg[size][f_rm(inst)]);
break;
case S:
db_printf("%s", db_seg_reg[f_reg(regmodrm)]);
break;
case Si:
db_printf("%s", db_seg_reg[f_reg(inst)]);
break;
case A:
db_printf("%s", db_reg[size][0]); /* acc */
break;
case BX:
if (seg)
db_printf("%s:", seg);
db_printf("(%s)", short_addr ? "%bx" : "%ebx");
break;
case CL:
db_printf("%%cl");
break;
case DX:
db_printf("%%dx");
break;
case SI:
if (seg)
db_printf("%s:", seg);
db_printf("(%s)", short_addr ? "%si" : "%esi");
break;
case DI:
db_printf("%%es:(%s)", short_addr ? "%di" : "%edi");
break;
case CR:
db_printf("%%cr%d", f_reg(regmodrm));
break;
case DR:
db_printf("%%dr%d", f_reg(regmodrm));
break;
case TR:
db_printf("%%tr%d", f_reg(regmodrm));
break;
case I:
len = db_lengths[size];
get_value_inc(imm, loc, len, FALSE);/* unsigned */
db_printf("$%#n", imm);
break;
case Is:
len = db_lengths[size];
get_value_inc(imm, loc, len, TRUE); /* signed */
db_printf("$%#r", imm);
break;
case Ib:
get_value_inc(imm, loc, 1, FALSE); /* unsigned */
db_printf("$%#n", imm);
break;
case Ibs:
get_value_inc(imm, loc, 1, TRUE); /* signed */
db_printf("$%#r", imm);
break;
case Iw:
get_value_inc(imm, loc, 2, FALSE); /* unsigned */
db_printf("$%#n", imm);
break;
case Il:
get_value_inc(imm, loc, 4, FALSE);
db_printf("$%#n", imm);
break;
case O:
if (short_addr) {
get_value_inc(displ, loc, 2, TRUE);
}
else {
switch (i_mode & 0xFF) {
case E:
db_print_address(seg, size, &address);
break;
case Eind:
db_printf("*");
db_print_address(seg, size, &address);
break;
case Ew:
db_print_address(seg, WORD, &address);
break;
case Eb:
db_print_address(seg, BYTE, &address);
break;
case R:
db_printf("%s", db_reg[size][f_reg(regmodrm)]);
break;
case Rw:
db_printf("%s", db_reg[WORD][f_reg(regmodrm)]);
break;
case Ri:
db_printf("%s", db_reg[size][f_rm(inst)]);
break;
case S:
db_printf("%s", db_seg_reg[f_reg(regmodrm)]);
break;
case Si:
db_printf("%s", db_seg_reg[f_reg(inst)]);
break;
case A:
db_printf("%s", db_reg[size][0]); /* acc */
break;
case BX:
if (seg)
db_printf("%s:", seg);
db_printf("(%s)", short_addr ? "%bx" : "%ebx");
break;
case CL:
db_printf("%%cl");
break;
case DX:
db_printf("%%dx");
break;
case SI:
if (seg)
db_printf("%s:", seg);
db_printf("(%s)", short_addr ? "%si" : "%esi");
break;
case DI:
db_printf("%%es:(%s)", short_addr ? "%di" : "%edi");
break;
case CR:
db_printf("%%cr%d", f_reg(regmodrm));
break;
case DR:
db_printf("%%dr%d", f_reg(regmodrm));
break;
case TR:
db_printf("%%tr%d", f_reg(regmodrm));
break;
case I:
len = db_lengths[size];
get_value_inc(imm, loc, len, FALSE);/* unsigned */
db_printf("$%#n", imm);
break;
case Is:
len = db_lengths[size];
get_value_inc(imm, loc, len, TRUE); /* signed */
db_printf("$%#r", imm);
break;
case Ib:
get_value_inc(imm, loc, 1, FALSE); /* unsigned */
db_printf("$%#n", imm);
break;
case Ibs:
get_value_inc(imm, loc, 1, TRUE); /* signed */
db_printf("$%#r", imm);
break;
case Iw:
get_value_inc(imm, loc, 2, FALSE); /* unsigned */
db_printf("$%#n", imm);
break;
case Il:
get_value_inc(imm, loc, 4, FALSE);
db_printf("$%#n", imm);
break;
case O:
if (short_addr)
get_value_inc(displ, loc, 2, TRUE);
else
get_value_inc(displ, loc, 4, TRUE);
if (seg)
db_printf("%s:%#r",seg, displ);
else
db_printsym((db_addr_t)displ, DB_STGY_ANY);
break;
case Db:
get_value_inc(displ, loc, 1, TRUE);
db_printsym((db_addr_t)(displ + loc), DB_STGY_XTRN);
break;
case Dl:
get_value_inc(displ, loc, 4, TRUE);
}
if (seg)
db_printf("%s:%#r",seg, displ);
else
db_printsym((db_addr_t)displ, DB_STGY_ANY);
break;
case Db:
get_value_inc(displ, loc, 1, TRUE);
db_printsym((db_addr_t)(displ + loc), DB_STGY_XTRN);
break;
case Dl:
get_value_inc(displ, loc, 4, TRUE);
db_printsym((db_addr_t)(displ + loc), DB_STGY_XTRN);
break;
case o1:
db_printf("$1");
break;
case o3:
db_printf("$3");
break;
case OS:
get_value_inc(imm, loc, 4, FALSE); /* offset */
get_value_inc(imm2, loc, 2, FALSE); /* segment */
db_printf("$%#n,%#n", imm2, imm);
break;
}
db_printsym((db_addr_t)(displ + loc), DB_STGY_XTRN);
break;
case o1:
db_printf("$1");
break;
case o3:
db_printf("$3");
break;
case OS:
get_value_inc(imm, loc, 4, FALSE); /* offset */
get_value_inc(imm2, loc, 2, FALSE); /* segment */
db_printf("$%#n,%#n", imm2, imm);
break;
}
}
if (altfmt == 0) {
if (inst == 0xe9 || inst == 0xeb) {
if (altfmt == 0 && (inst == 0xe9 || inst == 0xeb)) {
/*
* GAS pads to longword boundary after unconditional jumps.
*/
loc = (loc + (4-1)) & ~(4-1);
}
}
db_printf("\n");
return (loc);
}

View File

@ -23,44 +23,8 @@
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*
* $Id: db_interface.c,v 1.4 1993/07/22 13:04:45 brezak Exp $
*/
/*
* HISTORY
* $Log: db_interface.c,v $
* Revision 1.4 1993/07/22 13:04:45 brezak
* Allow one to fault in DDB and survive.
*
* Revision 1.3 1993/06/27 06:02:50 andrew
* ANSIfications - removed all implicit function return types and argument
* definitions. Ensured that all files include "systm.h" to gain access to
* general prototypes. Casts where necessary.
*
* Revision 1.2 1993/05/22 07:59:44 cgd
* add rcsids to everything and clean up headers
*
* Revision 1.1.1.1 1993/03/21 09:45:52 cgd
* initial import of 386bsd-0.1 sources
*
* Revision 1.1 1992/03/25 21:42:03 pace
* Initial revision
*
* Revision 2.4 91/02/05 17:11:13 mrt
* Changed to new Mach copyright
* [91/02/01 17:31:17 mrt]
*
* Revision 2.3 90/12/04 14:45:55 jsb
* Changes for merged intel/pmap.{c,h}.
* [90/12/04 11:14:41 jsb]
*
* Revision 2.2 90/10/25 14:44:43 rwd
* Added watchpoint support.
* [90/10/18 rpd]
*
* Created.
* [90/07/25 dbg]
*
*
* From: db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU)
* $Id: db_interface.c,v 1.5 1993/12/19 03:41:33 mycroft Exp $
*/
/*
@ -68,6 +32,7 @@
*/
#include "param.h"
#include "proc.h"
#include <machine/cpufunc.h>
#include <machine/db_machdep.h>
#include <sys/reboot.h>
@ -86,8 +51,8 @@ kdb_kbd_trap(regs)
struct i386_saved_state *regs;
{
if (db_active == 0 && (boothowto & RB_KDB)) {
printf("\n\nkernel: keyboard interrupt\n");
kdb_trap(-1, 0, regs);
printf("\n\nkernel: keyboard interrupt\n");
kdb_trap(-1, 0, regs);
}
}
@ -103,30 +68,28 @@ kdb_trap(type, code, regs)
{
#if 0
if ((boothowto&RB_KDB) == 0)
return(0);
return(0);
#endif
switch (type) {
case T_BPTFLT /* T_INT3 */: /* breakpoint */
case T_KDBTRAP /* T_WATCHPOINT */: /* watchpoint */
case T_PRIVINFLT /* T_DEBUG */: /* single_step */
case T_BPTFLT: /* breakpoint */
case T_TRCTRAP: /* single_step */
case -1: /* keyboard interrupt */
case -1: /* keyboard interrupt */
break;
default:
kdbprinttrap(type, code);
if (db_nofault) {
jmp_buf *no_fault = db_nofault;
db_nofault = 0;
longjmp(*no_fault, 1);
jmp_buf *no_fault = db_nofault;
db_nofault = 0;
longjmp(*no_fault, 1);
} else if (db_active) {
db_printf("Faulted in DDB; continuing...\n");
db_flush_lex();
longjmp(db_jmpbuf, 1);
}
else if (db_active) {
db_printf("Faulted in DDB; continuing...\n");
db_flush_lex();
longjmp(db_jmpbuf, 1);
}
}
/* Should switch to kdb`s own stack here. */
@ -134,17 +97,17 @@ kdb_trap(type, code, regs)
ddb_regs = *regs;
if ((regs->tf_cs & 0x3) == 0) {
/*
* Kernel mode - esp and ss not saved
*/
ddb_regs.tf_esp = (int)&regs->tf_esp; /* kernel stack pointer */
/*
* Kernel mode - esp and ss not saved
*/
ddb_regs.tf_esp = (int)&regs->tf_esp; /* kernel stack pointer */
#if 0
ddb_regs.ss = KERNEL_DS;
ddb_regs.ss = KERNEL_DS;
#endif
asm(" movw %%ss,%%ax; movl %%eax,%0 "
: "=g" (ddb_regs.tf_ss)
:
: "ax");
asm(" movw %%ss,%%ax; movl %%eax,%0 "
: "=g" (ddb_regs.tf_ss)
:
: "ax");
}
db_active++;
@ -153,28 +116,28 @@ kdb_trap(type, code, regs)
cnpollc(FALSE);
db_active--;
regs->tf_eip = ddb_regs.tf_eip;
regs->tf_eip = ddb_regs.tf_eip;
regs->tf_eflags = ddb_regs.tf_eflags;
regs->tf_eax = ddb_regs.tf_eax;
regs->tf_ecx = ddb_regs.tf_ecx;
regs->tf_edx = ddb_regs.tf_edx;
regs->tf_ebx = ddb_regs.tf_ebx;
regs->tf_eax = ddb_regs.tf_eax;
regs->tf_ecx = ddb_regs.tf_ecx;
regs->tf_edx = ddb_regs.tf_edx;
regs->tf_ebx = ddb_regs.tf_ebx;
if (regs->tf_cs & 0x3) {
/*
* user mode - saved esp and ss valid
*/
regs->tf_esp = ddb_regs.tf_esp; /* user stack pointer */
regs->tf_ss = ddb_regs.tf_ss & 0xffff; /* user stack segment */
/*
* user mode - saved esp and ss valid
*/
regs->tf_esp = ddb_regs.tf_esp; /* user stack pointer */
regs->tf_ss = ddb_regs.tf_ss & 0xffff; /* user stack segment */
}
regs->tf_ebp = ddb_regs.tf_ebp;
regs->tf_esi = ddb_regs.tf_esi;
regs->tf_edi = ddb_regs.tf_edi;
regs->tf_es = ddb_regs.tf_es & 0xffff;
regs->tf_cs = ddb_regs.tf_cs & 0xffff;
regs->tf_ds = ddb_regs.tf_ds & 0xffff;
regs->tf_ebp = ddb_regs.tf_ebp;
regs->tf_esi = ddb_regs.tf_esi;
regs->tf_edi = ddb_regs.tf_edi;
regs->tf_es = ddb_regs.tf_es & 0xffff;
regs->tf_cs = ddb_regs.tf_cs & 0xffff;
regs->tf_ds = ddb_regs.tf_ds & 0xffff;
#if 0
regs->tf_fs = ddb_regs.tf_fs & 0xffff;
regs->tf_gs = ddb_regs.tf_gs & 0xffff;
regs->tf_fs = ddb_regs.tf_fs & 0xffff;
regs->tf_gs = ddb_regs.tf_gs & 0xffff;
#endif
return (1);
@ -206,7 +169,7 @@ db_read_bytes(addr, size, data)
src = (char *)addr;
while (--size >= 0)
*data++ = *src++;
*data++ = *src++;
db_nofault = 0;
}
@ -234,36 +197,33 @@ db_write_bytes(addr, size, data)
db_nofault = &db_jmpbuf;
if (addr >= VM_MIN_KERNEL_ADDRESS &&
addr <= (vm_offset_t)&etext)
{
ptep0 = pmap_pte(kernel_pmap, addr);
oldmap0 = *ptep0;
*(int *)ptep0 |= /* INTEL_PTE_WRITE */ PG_RW;
addr <= (vm_offset_t)&etext) {
ptep0 = pmap_pte(kernel_pmap, addr);
oldmap0 = *ptep0;
*(int *)ptep0 |= /* INTEL_PTE_WRITE */ PG_RW;
addr1 = i386_trunc_page(addr + size - 1);
if (i386_trunc_page(addr) != addr1) {
/* data crosses a page boundary */
ptep1 = pmap_pte(kernel_pmap, addr1);
oldmap1 = *ptep1;
*(int *)ptep1 |= /* INTEL_PTE_WRITE */ PG_RW;
}
tlbflush();
addr1 = i386_trunc_page(addr + size - 1);
if (i386_trunc_page(addr) != addr1) {
/* data crosses a page boundary */
ptep1 = pmap_pte(kernel_pmap, addr1);
oldmap1 = *ptep1;
*(int *)ptep1 |= /* INTEL_PTE_WRITE */ PG_RW;
}
tlbflush();
}
dst = (char *)addr;
while (--size >= 0)
*dst++ = *data++;
*dst++ = *data++;
db_nofault = 0;
if (ptep0) {
*ptep0 = oldmap0;
if (ptep1) {
*ptep1 = oldmap1;
}
tlbflush();
*ptep0 = oldmap0;
if (ptep1)
*ptep1 = oldmap1;
tlbflush();
}
}

View File

@ -23,7 +23,7 @@
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*
* $Id: db_trace.c,v 1.5 1993/09/16 03:24:34 brezak Exp $
* $Id: db_trace.c,v 1.6 1993/12/19 03:41:34 mycroft Exp $
*/
#include "param.h"
@ -83,12 +83,13 @@ void
db_find_trace_symbols()
{
db_expr_t value;
if (db_value_of_name("_trap", &value))
db_trap_symbol_value = (db_addr_t) value;
db_trap_symbol_value = (db_addr_t) value;
if (db_value_of_name("_kdintr", &value))
db_kdintr_symbol_value = (db_addr_t) value;
db_kdintr_symbol_value = (db_addr_t) value;
if (db_value_of_name("_syscall", &value))
db_syscall_symbol_value = (db_addr_t) value;
db_syscall_symbol_value = (db_addr_t) value;
db_trace_symbols_found = TRUE;
}
@ -105,16 +106,16 @@ db_numargs(fp)
extern char etext[];
argp = (int *)db_get_value((int)&fp->f_retaddr, 4, FALSE);
if (argp < (int *)VM_MIN_KERNEL_ADDRESS || argp > (int *)etext)
args = 5;
else {
inst = db_get_value((int)argp, 4, FALSE);
if ((inst & 0xff) == 0x59) /* popl %ecx */
args = 1;
else if ((inst & 0xffff) == 0xc483) /* addl %n, %esp */
args = ((inst >> 16) & 0xff) / 4;
else
if (argp < (int *)VM_MIN_KERNEL_ADDRESS || argp > (int *)etext) {
args = 5;
} else {
inst = db_get_value((int)argp, 4, FALSE);
if ((inst & 0xff) == 0x59) /* popl %ecx */
args = 1;
else if ((inst & 0xffff) == 0xc483) /* addl %n, %esp */
args = ((inst >> 16) & 0xff) / 4;
else
args = 5;
}
return (args);
}
@ -139,41 +140,41 @@ db_nextframe(fp, ip, argp, is_trap)
struct i386_saved_state *saved_regs;
switch (is_trap) {
case 0:
*ip = (db_addr_t)
case 0:
*ip = (db_addr_t)
db_get_value((int) &(*fp)->f_retaddr, 4, FALSE);
*fp = (struct i386_frame *)
*fp = (struct i386_frame *)
db_get_value((int) &(*fp)->f_frame, 4, FALSE);
break;
case TRAP:
default:
/*
* We know that trap() has 1 argument and we know that
* it is an (int *).
*/
break;
case TRAP:
default:
/*
* We know that trap() has 1 argument and we know that
* it is an (int *).
*/
#if 0
saved_regs = (struct i386_saved_state *)
db_get_value((int)argp, 4, FALSE);
saved_regs = (struct i386_saved_state *)
db_get_value((int)argp, 4, FALSE);
#endif
saved_regs = (struct i386_saved_state *)argp;
db_printf("--- trap (number %d) ---\n",
saved_regs->tf_trapno & 0xffff);
db_printsym(saved_regs->tf_eip, DB_STGY_XTRN);
db_printf(":\n");
*fp = (struct i386_frame *)saved_regs->tf_ebp;
*ip = (db_addr_t)saved_regs->tf_eip;
break;
saved_regs = (struct i386_saved_state *)argp;
db_printf("--- trap (number %d) ---\n",
saved_regs->tf_trapno & 0xffff);
db_printsym(saved_regs->tf_eip, DB_STGY_XTRN);
db_printf(":\n");
*fp = (struct i386_frame *)saved_regs->tf_ebp;
*ip = (db_addr_t)saved_regs->tf_eip;
break;
case SYSCALL: {
struct trapframe *saved_regs = (struct trapframe *)argp;
case SYSCALL: {
struct trapframe *saved_regs = (struct trapframe *)argp;
db_printf("--- syscall (number %d) ---\n", saved_regs->tf_eax);
db_printsym(saved_regs->tf_eip, DB_STGY_XTRN);
db_printf(":\n");
*fp = (struct i386_frame *)saved_regs->tf_ebp;
*ip = (db_addr_t)saved_regs->tf_eip;
db_printf("--- syscall (number %d) ---\n", saved_regs->tf_eax);
db_printsym(saved_regs->tf_eip, DB_STGY_XTRN);
db_printf(":\n");
*fp = (struct i386_frame *)saved_regs->tf_ebp;
*ip = (db_addr_t)saved_regs->tf_eip;
break;
}
break;
}
}
@ -193,141 +194,135 @@ db_stack_trace_cmd(addr, have_addr, count, modif)
#if 0
if (!db_trace_symbols_found)
db_find_trace_symbols();
db_find_trace_symbols();
#endif
{
register char *cp = modif;
register char c;
register char *cp = modif;
register char c;
while ((c = *cp++) != 0) {
if (c == 't')
trace_thread = TRUE;
if (c == 'u')
kernel_only = FALSE;
}
while ((c = *cp++) != 0) {
if (c == 't')
trace_thread = TRUE;
if (c == 'u')
kernel_only = FALSE;
}
}
if (count == -1)
count = 65535;
count = 65535;
if (!have_addr) {
frame = (struct i386_frame *)ddb_regs.tf_ebp;
callpc = (db_addr_t)ddb_regs.tf_eip;
}
else if (trace_thread) {
frame = (struct i386_frame *)ddb_regs.tf_ebp;
callpc = (db_addr_t)ddb_regs.tf_eip;
} else if (trace_thread) {
printf ("db_trace.c: can't trace thread\n");
}
else {
frame = (struct i386_frame *)addr;
callpc = (db_addr_t)db_get_value((int)&frame->f_retaddr, 4, FALSE);
} else {
frame = (struct i386_frame *)addr;
callpc = (db_addr_t)
db_get_value((int)&frame->f_retaddr, 4, FALSE);
}
lastframe = 0;
while (count-- && frame != 0) {
int narg;
char * name;
db_expr_t offset;
db_sym_t sym;
int narg;
char * name;
db_expr_t offset;
db_sym_t sym;
#define MAXNARG 16
char *argnames[MAXNARG], **argnp = NULL;
char *argnames[MAXNARG], **argnp = NULL;
sym = db_search_symbol(callpc, DB_STGY_ANY, &offset);
db_symbol_values(sym, &name, NULL);
sym = db_search_symbol(callpc, DB_STGY_ANY, &offset);
db_symbol_values(sym, &name, NULL);
if (lastframe == 0 && sym == NULL) {
/* Symbol not found, peek at code */
int instr = db_get_value(callpc, 4, FALSE);
if (lastframe == 0 && sym == NULL) {
/* Symbol not found, peek at code */
int instr = db_get_value(callpc, 4, FALSE);
offset = 1;
if ((instr & 0x00ffffff) == 0x00e58955 ||
/* enter: pushl %ebp, movl %esp, %ebp */
(instr & 0x0000ffff) == 0x0000e589
/* enter+1: movl %esp, %ebp */ ) {
offset = 0;
offset = 1;
if ((instr & 0x00ffffff) == 0x00e58955 ||
/* enter: pushl %ebp, movl %esp, %ebp */
(instr & 0x0000ffff) == 0x0000e589
/* enter+1: movl %esp, %ebp */) {
offset = 0;
}
}
}
#define STRCMP(s1,s2) ((s1) && (s2) && strcmp((s1), (s2)) == 0)
if (INKERNEL((int)frame) && STRCMP(name, "_trap")) {
narg = 1;
is_trap = TRAP;
}
else
if (INKERNEL((int)frame) && STRCMP(name, "_kdintr")) {
is_trap = INTERRUPT;
narg = 0;
}
else
if (INKERNEL((int)frame) && STRCMP(name, "_syscall")) {
is_trap = SYSCALL;
narg = 0;
}
#undef STRCMP
else {
is_trap = 0;
narg = MAXNARG;
if (db_sym_numargs(sym, &narg, argnames)) {
argnp = argnames;
if (INKERNEL((int)frame) && STRCMP(name, "_trap")) {
narg = 1;
is_trap = TRAP;
} else if (INKERNEL((int)frame) && STRCMP(name, "_kdintr")) {
is_trap = INTERRUPT;
narg = 0;
} else if (INKERNEL((int)frame) && STRCMP(name, "_syscall")) {
is_trap = SYSCALL;
narg = 0;
} else {
narg = db_numargs(frame);
#undef STRCMP
is_trap = 0;
narg = MAXNARG;
if (db_sym_numargs(sym, &narg, argnames))
argnp = argnames;
else
narg = db_numargs(frame);
}
}
db_printf("%s(", name);
db_printf("%s(", name);
if (lastframe == 0 && offset == 0 && !have_addr) {
/*
* We have a breakpoint before the frame is set up
* Use %esp instead
*/
argp = &((struct i386_frame *)(ddb_regs.tf_esp-4))->f_arg0;
} else
argp = &frame->f_arg0;
while (narg) {
if (argnp)
db_printf("%s=", *argnp++);
db_printf("%x", db_get_value((int)argp, 4, FALSE));
argp++;
if (--narg != 0)
db_printf(",");
}
db_printf(") at ");
db_printsym(callpc, DB_STGY_PROC);
db_printf("\n");
if (lastframe == 0 && offset == 0 && !have_addr) {
/* Frame really belongs to next callpc */
lastframe = (struct i386_frame *)(ddb_regs.tf_esp-4);
callpc = (db_addr_t)db_get_value((int)&lastframe->f_retaddr, 4, FALSE);
continue;
}
lastframe = frame;
db_nextframe(&frame, &callpc, &frame->f_arg0, is_trap);
if (frame == 0) {
/* end of chain */
break;
}
if (INKERNEL((int)frame)) {
/* staying in kernel */
if (frame <= lastframe) {
db_printf("Bad frame pointer: 0x%x\n", frame);
break;
if (lastframe == 0 && offset == 0 && !have_addr) {
/*
* We have a breakpoint before the frame is set up
* Use %esp instead
*/
argp = &((struct i386_frame *)(ddb_regs.tf_esp-4))->f_arg0;
} else {
argp = &frame->f_arg0;
}
}
else if (INKERNEL((int)lastframe)) {
/* switch from user to kernel */
if (kernel_only)
break; /* kernel stack only */
}
else {
/* in user */
if (frame <= lastframe) {
db_printf("Bad user frame pointer: 0x%x\n", frame);
break;
while (narg) {
if (argnp)
db_printf("%s=", *argnp++);
db_printf("%x", db_get_value((int)argp, 4, FALSE));
argp++;
if (--narg != 0)
db_printf(",");
}
db_printf(") at ");
db_printsym(callpc, DB_STGY_PROC);
db_printf("\n");
if (lastframe == 0 && offset == 0 && !have_addr) {
/* Frame really belongs to next callpc */
lastframe = (struct i386_frame *)(ddb_regs.tf_esp-4);
callpc = (db_addr_t)
db_get_value((int)&lastframe->f_retaddr, 4, FALSE);
continue;
}
lastframe = frame;
db_nextframe(&frame, &callpc, &frame->f_arg0, is_trap);
if (frame == 0) {
/* end of chain */
break;
}
if (INKERNEL((int)frame)) {
/* staying in kernel */
if (frame <= lastframe) {
db_printf("Bad frame pointer: 0x%x\n", frame);
break;
}
} else if (INKERNEL((int)lastframe)) {
/* switch from user to kernel */
if (kernel_only)
break; /* kernel stack only */
} else {
/* in user */
if (frame <= lastframe) {
db_printf("Bad user frame pointer: 0x%x\n",
frame);
break;
}
}
}
}
}

View File

@ -23,49 +23,7 @@
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*
* $Id: db_machdep.h,v 1.2 1993/05/22 08:00:12 cgd Exp $
*/
/*
* HISTORY
* $Log: db_machdep.h,v $
* Revision 1.2 1993/05/22 08:00:12 cgd
* add rcsids to everything and clean up headers
*
* Revision 1.1.1.1 1993/03/21 09:45:47 cgd
* initial import of 386bsd-0.1 sources
*
* Revision 2.8 92/02/19 15:07:56 elf
* Added db_thread_fp_used.
* [92/02/19 rpd]
*
* Revision 2.7 91/10/09 16:06:28 af
* Revision 2.6.3.1 91/10/05 13:10:32 jeffreyh
* Added access and task name macros.
* [91/08/29 tak]
*
* Revision 2.6.3.1 91/10/05 13:10:32 jeffreyh
* Added access and task name macros.
* [91/08/29 tak]
*
* Revision 2.6 91/05/14 16:05:58 mrt
* Correcting copyright
*
* Revision 2.5 91/02/05 17:11:17 mrt
* Changed to new Mach copyright
* [91/02/01 17:31:24 mrt]
*
* Revision 2.4 91/01/08 15:10:16 rpd
* Added dummy inst_load/inst_store macros.
* [90/12/11 rpd]
*
* Revision 2.3 90/10/25 14:44:49 rwd
* Added watchpoint support.
* [90/10/18 rpd]
*
* Revision 2.2 90/08/27 21:56:15 dbg
* Created.
* [90/07/25 dbg]
*
* $Id: db_machdep.h,v 1.3 1993/12/19 03:41:51 mycroft Exp $
*/
#ifndef _I386_DB_MACHDEP_H_
@ -76,17 +34,12 @@
*/
/* #include <mach/i386/vm_types.h> */
/* #include <mach/i386/vm_param.h> */
#include <vm/vm_prot.h>
#include <vm/vm_param.h>
#include <vm/vm_inherit.h>
#include <vm/lock.h>
/* #include <i386/thread.h> */ /* for thread_status */
#include <machine/frame.h> /* for struct trapframe */
/* #include <i386/eflags.h> */
#include <machine/eflags.h> /* from Mach... */
/* #include <i386/trap.h> */
#include <machine/frame.h>
#include <machine/psl.h>
#include <machine/trap.h>
#define i386_saved_state trapframe
@ -107,14 +60,11 @@ db_regs_t ddb_regs; /* register state */
#define FIXUP_PC_AFTER_BREAK ddb_regs.tf_eip -= 1;
#define db_clear_single_step(regs) ((regs)->tf_eflags &= ~EFL_TF)
#define db_set_single_step(regs) ((regs)->tf_eflags |= EFL_TF)
#define db_clear_single_step(regs) ((regs)->tf_eflags &= ~PSL_T)
#define db_set_single_step(regs) ((regs)->tf_eflags |= PSL_T)
/* #define IS_BREAKPOINT_TRAP(type, code) ((type) == T_INT3) */
/* #define IS_WATCHPOINT_TRAP(type, code) ((type) == T_WATCHPOINT) */
/* using the 386bsd values, rather than the Mach ones: */
#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT)
#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_KDBTRAP)
#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15)
#define I_CALL 0xe8
#define I_CALLI 0xff
@ -141,7 +91,7 @@ db_regs_t ddb_regs; /* register state */
(addr) < VM_MAX_KERNEL_ADDRESS)
#define DB_VALID_ADDRESS(addr,user) \
((!(user) && DB_VALID_KERN_ADDR(addr)) || \
((user) && (addr) < VM_MIN_KERNEL_ADDRESS))
((user) && (addr) < VM_MAX_ADDRESS))
boolean_t db_check_access(/* vm_offset_t, int, task_t */);
boolean_t db_phys_eq(/* task_t, vm_offset_t, task_t, vm_offset_t */);