Bugfix causing erroneous address displaying.

This commit is contained in:
ragge 1996-07-20 18:17:29 +00:00
parent fd3f596fa3
commit 1abb214901

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_disasm.c,v 1.6 1996/04/08 18:32:32 ragge Exp $ */
/* $NetBSD: db_disasm.c,v 1.7 1996/07/20 18:17:29 ragge Exp $ */
/*
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
* All rights reserved.
@ -16,8 +16,8 @@
* 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 at Ludd, University of
* Lule}, Sweden and its contributors.
* This product includes software developed at Ludd, University of
* Lule}, Sweden and its contributors.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
@ -35,34 +35,33 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <machine/db_machdep.h>
#include <ddb/db_sym.h>
#include <ddb/db_output.h>
#include <ddb/db_interface.h>
#include <ddb/db_variables.h>
#include <vax/vax/db_disasm.h>
#ifdef VMS_MODE
#define DEFERRED '@'
#define LITERAL '#'
#define LITERAL '#'
#else
#define DEFERRED '*'
#define LITERAL '$'
#define LITERAL '$'
#endif
/*
* disassembling vax instructions works as follows:
*
* - get first byte as opcode (check for two-byte opcodes!)
* - evaluate (variable length) argument list
* - for each argument get type (byte, long, address etc.)
* - evaluate addressing mode for this argument
* - db_printf the opcode and the (value of the) arguments
* - return the start of the next instruction
* 1. get first byte as opcode (check for two-byte opcodes!)
* 2. lookup in op-table for mnemonic and operand-list
* 2.a store the mnemonic
* 3. for each operand in list: get the size/type
* 3.a evaluate addressing mode for this operand
* 3.b store each operand(s)
* 4. db_printf the opcode and the (value of the) operands
* 5. return the start of the next instruction
*
* - if jump/branch calculate (and display) the target-address
*/
@ -70,63 +69,63 @@
/*
#define BROKEN_DB_REGS
*/
#ifdef BROKEN_DB_REGS
struct { /* Due to order and contents of db_regs[], we can't */
char *name; /* use this array to extract register-names. */
void *valuep; /* eg. "psl" vs "pc", "pc" vs "sp" */
#ifdef BROKEN_DB_REGS
struct { /* Due to order and contents of db_regs[], we can't */
char *name; /* use this array to extract register-names. */
void *valuep; /* eg. "psl" vs "pc", "pc" vs "sp" */
} my_db_regs[16] = {
{ "r0", NULL },
{ "r1", NULL },
{ "r2", NULL },
{ "r3", NULL },
{ "r4", NULL },
{ "r5", NULL },
{ "r6", NULL },
{ "r7", NULL },
{ "r8", NULL },
{ "r9", NULL },
{ "r10", NULL },
{ "r11", NULL },
{ "ap", NULL }, /* aka "r12" */
{ "fp", NULL }, /* aka "r13" */
{ "sp", NULL }, /* aka "r14" */
{ "pc", NULL }, /* aka "r15" */
{ "r0", NULL },
{ "r1", NULL },
{ "r2", NULL },
{ "r3", NULL },
{ "r4", NULL },
{ "r5", NULL },
{ "r6", NULL },
{ "r7", NULL },
{ "r8", NULL },
{ "r9", NULL },
{ "r10", NULL },
{ "r11", NULL },
{ "ap", NULL }, /* aka "r12" */
{ "fp", NULL }, /* aka "r13" */
{ "sp", NULL }, /* aka "r14" */
{ "pc", NULL }, /* aka "r15" */
};
#else
#define my_db_regs db_regs
#endif
typedef struct {
char dasm[256]; /* disassebled instruction as text */
char *curp; /* pointer into result */
char *ppc; /* pseudo PC */
int opc; /* op-code */
char *argp; /* pointer into argument-list */
int itype; /* instruction-type, eg. branch, call, unspec */
int atype; /* argument-type, eg. byte, long, address */
int off; /* offset specified by last argument */
int addr; /* address specified by last argument */
} inst_buffer;
char dasm[256]; /* disassebled instruction as text */
char *curp; /* pointer into result */
char *ppc; /* pseudo PC */
int opc; /* op-code */
char *argp; /* pointer into argument-list */
int itype; /* instruction-type, eg. branch, call, unspec */
int atype; /* argument-type, eg. byte, long, address */
int off; /* offset specified by last argument */
int addr; /* address specified by last argument */
} inst_buffer;
#define ITYPE_INVALID -1
#define ITYPE_UNSPEC 0
#define ITYPE_BRANCH 1
#define ITYPE_CALL 2
#define ITYPE_UNSPEC 0
#define ITYPE_BRANCH 1
#define ITYPE_CALL 2
int get_byte __P((inst_buffer * ib));
int get_word __P((inst_buffer * ib));
int get_long __P((inst_buffer * ib));
int get_byte __P((inst_buffer * ib));
int get_word __P((inst_buffer * ib));
int get_long __P((inst_buffer * ib));
int get_opcode __P((inst_buffer * ib));
int get_opcode __P((inst_buffer * ib));
int get_operands __P((inst_buffer * ib));
int get_operand __P((inst_buffer * ib, int size));
void add_char __P((inst_buffer * ib, int c));
void add_str __P((inst_buffer * ib, char *s));
void add_int __P((inst_buffer * ib, int i));
void add_xint __P((inst_buffer * ib, int i));
void add_sym __P((inst_buffer * ib, int i));
void add_off __P((inst_buffer * ib, int i));
void add_char __P((inst_buffer * ib, int c));
void add_str __P((inst_buffer * ib, char *s));
void add_int __P((inst_buffer * ib, int i));
void add_xint __P((inst_buffer * ib, int i));
void add_sym __P((inst_buffer * ib, int i));
void add_off __P((inst_buffer * ib, int i));
#define err_print printf
@ -141,14 +140,14 @@ void add_off __P((inst_buffer * ib, int i));
*/
db_addr_t
db_disasm(loc, altfmt)
db_addr_t loc;
boolean_t altfmt;
db_addr_t loc;
boolean_t altfmt;
{
db_expr_t diff;
db_sym_t sym;
char *symname;
db_expr_t diff;
db_sym_t sym;
char *symname;
inst_buffer ib;
inst_buffer ib;
bzero(&ib, sizeof(ib));
ib.ppc = (void *) loc;
@ -160,7 +159,7 @@ db_disasm(loc, altfmt)
sym = db_search_symbol(loc, DB_STGY_PROC, &diff);
db_symbol_values(sym, &symname, 0);
if (symname && !diff) { /* symbol at loc */
if (symname && !diff) { /* symbol at loc */
db_printf("function \"%s()\", entry-mask 0x%x\n\t\t",
symname, (unsigned short) get_word(&ib));
ib.ppc += 2;
@ -210,8 +209,8 @@ int
get_operands(ib)
inst_buffer *ib;
{
int aa = 0; /* absolute address mode ? */
int size;
int aa = 0; /* absolute address mode ? */
int size;
if (ib->opc < 0 || ib->opc > 0xFF) {
/* invalid or two-byte opcode */
@ -243,7 +242,7 @@ get_operands(ib)
break;
case 'a': /* absolute adressing mode */
aa = 1; /* do not break here ! */
aa = 1; /* do not break here ! */
default:
switch (*(++ib->argp)) {
@ -301,14 +300,14 @@ get_operands(ib)
int
get_operand(ib, size)
inst_buffer *ib;
int size;
int size;
{
int c = get_byte(ib);
int mode = c >> 4;
int reg = c & 0x0F;
int lit = c & 0x3F;
int tmp = 0;
char buf[16];
int c = get_byte(ib);
int mode = c >> 4;
int reg = c & 0x0F;
int lit = c & 0x3F;
int tmp = 0;
char buf[16];
switch (mode) {
case 0: /* literal */
@ -348,6 +347,15 @@ get_operand(ib, size)
case 9: /* autoincrement deferred */
add_char(ib, DEFERRED);
if (reg == 0x0F) { /* pc: immediate deferred */
/*
* addresses are always longwords!
*/
tmp = get_long(ib);
add_off(ib, tmp);
break;
}
/* fall through */
case 8: /* autoincrement */
if (reg == 0x0F) { /* pc: immediate ==> special syntax */
switch (size) {
@ -439,8 +447,8 @@ int
get_word(ib)
inst_buffer *ib;
{
int tmp;
char *p = (void *) &tmp;
int tmp;
char *p = (void *) &tmp;
*p++ = get_byte(ib);
*p++ = get_byte(ib);
return (tmp);
@ -450,8 +458,8 @@ int
get_long(ib)
inst_buffer *ib;
{
int tmp;
char *p = (void *) &tmp;
int tmp;
char *p = (void *) &tmp;
*p++ = get_byte(ib);
*p++ = get_byte(ib);
*p++ = get_byte(ib);
@ -462,7 +470,7 @@ get_long(ib)
void
add_char(ib, c)
inst_buffer *ib;
int c;
int c;
{
*ib->curp++ = c;
}
@ -470,18 +478,18 @@ add_char(ib, c)
void
add_str(ib, s)
inst_buffer *ib;
char *s;
char *s;
{
while ((*ib->curp++ = *s++));
while (*ib->curp++ = *s++);
*--ib->curp = '\0';
}
void
add_int(ib, i)
inst_buffer *ib;
int i;
int i;
{
char buf[32];
char buf[32];
if (i < 100 && i > -100)
sprintf(buf, "%d", i);
else
@ -492,9 +500,9 @@ add_int(ib, i)
void
add_xint(ib, val)
inst_buffer *ib;
int val;
int val;
{
char buf[32];
char buf[32];
sprintf(buf, "0x%x", val);
add_str(ib, buf);
}
@ -502,11 +510,11 @@ add_xint(ib, val)
void
add_sym(ib, loc)
inst_buffer *ib;
int loc;
int loc;
{
db_expr_t diff;
db_sym_t sym;
char *symname;
db_expr_t diff;
db_sym_t sym;
char *symname;
if (! loc)
return;
@ -528,11 +536,11 @@ add_sym(ib, loc)
void
add_off(ib, loc)
inst_buffer *ib;
int loc;
int loc;
{
db_expr_t diff;
db_sym_t sym;
char *symname;
db_expr_t diff;
db_sym_t sym;
char *symname;
if (!loc)
return;