/* Print 32000 instructions for GDB, the GNU debugger.
Copyright (C) 1986,1988 Free Software Foundation, Inc.
GDB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone
for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.
Refer to the GDB General Public License for full details.
Everyone is granted permission to copy, modify and redistribute GDB,
but only under the conditions described in the GDB General Public
License. A copy of this license is supposed to have been given to you
along with GDB so you can know your rights and responsibilities. It
should be in a file named COPYING. Among other things, the copyright
notice and this notice must be preserved on all copies.
In other words, go ahead and share GDB, but don't try to stop
anyone else from sharing it farther. Help stamp out software hoarding!
/* 32000 instructions are never longer than this. */
/* Number of elements in the opcode table. */
#define NOPCODES (sizeof notstrs / sizeof notstrs[0])
extern char *reg_names
[];
* extract "count" bits starting "offset" bits
bit_extract (buffer
, offset
, count
)
if ((*buffer
& (1 << offset
)))
fbit_extract (buffer
, offset
, count
)
foo
.ival
= bit_extract (buffer
, offset
, 32);
dbit_extract (buffer
, offset
, count
)
struct {int low
, high
; } ival
;
foo
.ival
.low
= bit_extract (buffer
, offset
, 32);
foo
.ival
.high
= bit_extract (buffer
, offset
+32, 32);
sign_extend (value
, bits
)
value
= value
& ((1 << bits
) - 1);
return (value
& (1 << (bits
-1))
? value
| (~((1 << bits
) - 1))
/* Given a character C, does it represent a general addressing mode? */
((c) == 'F' || (c) == 'L' || (c) == 'B' \
|| (c) == 'W' || (c) == 'D' || (c) == 'A')
#define Adrmod_index_byte 0x1c
#define Adrmod_index_word 0x1d
#define Adrmod_index_doubleword 0x1e
#define Adrmod_index_quadword 0x1f
/* Is MODE an indexed addressing mode? */
#define Adrmod_is_index(mode) \
(mode == Adrmod_index_byte \
|| mode == Adrmod_index_word \
|| mode == Adrmod_index_doubleword \
|| mode == Adrmod_index_quadword)
/* Print the 32000 instruction at address MEMADDR in debugged memory,
on STREAM. Returns length of the instruction, in bytes. */
print_insn (memaddr
, stream
)
unsigned char buffer
[MAXLEN
];
register unsigned char *p
;
unsigned short first_word
;
int ioffset
; /* bits into instruction */
int aoffset
; /* bits into arguments */
char arg_bufs
[MAX_ARGS
+1][ARG_LEN
];
read_memory (memaddr
, buffer
, MAXLEN
);
first_word
= *(unsigned short *) buffer
;
for (i
= 0; i
< NOPCODES
; i
++)
if ((first_word
& ((1 << notstrs
[i
].detail
.obits
) - 1))
== notstrs
[i
].detail
.code
)
/* Handle undefined instructions. */
fprintf (stream
, "0%o", buffer
[0]);
fprintf (stream
, "%s", notstrs
[i
].name
);
ioffset
= notstrs
[i
].detail
.ibits
;
aoffset
= notstrs
[i
].detail
.ibits
;
d
= notstrs
[i
].detail
.args
;
/* Offset in bits of the first thing beyond each index byte.
Element 0 is for operand A and element 1 is for operand B.
The rest are irrelevant, but we put them here so we don't
index outside the array. */
int index_offset
[MAX_ARGS
];
/* 0 for operand A, 1 for operand B, greater for other args. */
/* First we have to find and keep track of the index bytes,
if we are using scaled indexed addressing mode, since the index
bytes occur right after the basic instruction, not as part
of the addressing extension. */
int addr_mode
= bit_extract (buffer
, ioffset
- 5, 5);
if (Adrmod_is_index (addr_mode
))
index_offset
[0] = aoffset
;
if (d
[2] && Is_gen(d
[3]))
int addr_mode
= bit_extract (buffer
, ioffset
- 10, 5);
if (Adrmod_is_index (addr_mode
))
index_offset
[1] = aoffset
;
if (argnum
> maxarg
&& argnum
< MAX_ARGS
)
ioffset
= print_insn_arg (*d
, ioffset
, &aoffset
, buffer
,
memaddr
, arg_bufs
[argnum
],
for (argnum
= 0; argnum
<= maxarg
; argnum
++)
for (ch
= arg_bufs
[argnum
]; *ch
;)
print_address (addr
, stream
);
while (*ch
&& *ch
!= NEXT_IS_ADDR
)
/* Print an instruction operand of category given by d. IOFFSET is
the bit position below which small (<1 byte) parts of the operand can
be found (usually in the basic instruction, but for indexed
addressing it can be in the index byte). AOFFSETP is a pointer to the
bit position of the addressing extension. BUFFER contains the
instruction. ADDR is where BUFFER was read from. Put the disassembled
version of the operand in RESULT. INDEX_OFFSET is the bit position
of the index byte (it contains garbage if this operand is not a
general operand using scaled indexed addressing mode). */
print_insn_arg (d
, ioffset
, aoffsetp
, buffer
, addr
, result
, index_offset
)
addr_mode
= bit_extract (buffer
, ioffset
-5, 5);
case 0x0: case 0x1: case 0x2: case 0x3:
case 0x4: case 0x5: case 0x6: case 0x7:
sprintf (result
, "f%d", addr_mode
);
sprintf (result
, "r%d", addr_mode
);
case 0x8: case 0x9: case 0xa: case 0xb:
case 0xc: case 0xd: case 0xe: case 0xf:
disp1
= get_displacement (buffer
, aoffsetp
);
sprintf (result
, "%d(r%d)", disp1
, addr_mode
& 7);
disp1
= get_displacement (buffer
, aoffsetp
);
disp2
= get_displacement (buffer
, aoffsetp
);
sprintf (result
, "%d(%d(%s))", disp2
, disp1
,
addr_mode
==0x10?"fp":addr_mode
==0x11?"sp":"sb");
sprintf (result
, "reserved");
Ivalue
= bit_extract (buffer
, *aoffsetp
, 8);
Ivalue
= sign_extend (Ivalue
, 8);
sprintf (result
, "$%d", Ivalue
);
Ivalue
= bit_extract (buffer
, *aoffsetp
, 16);
Ivalue
= sign_extend (Ivalue
, 16);
sprintf (result
, "$%d", Ivalue
);
Ivalue
= bit_extract (buffer
, *aoffsetp
, 32);
sprintf (result
, "$%d", Ivalue
);
Ivalue
= bit_extract (buffer
, *aoffsetp
, 32);
sprintf (result
, "$|%d|", Ivalue
);
Fvalue
= fbit_extract (buffer
, *aoffsetp
, 32);
sprintf (result
, "$%g", Fvalue
);
Lvalue
= dbit_extract (buffer
, *aoffsetp
, 64);
sprintf (result
, "$%g", Lvalue
);
disp1
= get_displacement (buffer
, aoffsetp
);
sprintf (result
, "@|%d|", disp1
);
disp1
= get_displacement (buffer
, aoffsetp
);
disp2
= get_displacement (buffer
, aoffsetp
);
sprintf (result
, "EXT(%d) + %d", disp1
, disp2
);
disp1
= get_displacement (buffer
, aoffsetp
);
sprintf (result
, "%d(fp)", disp1
);
disp1
= get_displacement (buffer
, aoffsetp
);
sprintf (result
, "%d(sp)", disp1
);
disp1
= get_displacement (buffer
, aoffsetp
);
sprintf (result
, "%d(sb)", disp1
);
disp1
= get_displacement (buffer
, aoffsetp
);
sprintf (result
, "|%d|", addr
+ disp1
);
index
= bit_extract (buffer
, index_offset
- 8, 3);
print_insn_arg (d
, index_offset
, aoffsetp
, buffer
, addr
,
static char *ind
[] = {"b", "w", "d", "q"};
off
= result
+ strlen (result
);
sprintf (off
, "[r%d:%s]", index
,
Ivalue
= bit_extract (buffer
, ioffset
-4, 4);
Ivalue
= sign_extend (Ivalue
, 4);
sprintf (result
, "%d", Ivalue
);
Ivalue
= bit_extract (buffer
, ioffset
-3, 3);
sprintf (result
, "r%d", Ivalue
&7);
sprintf (result
, "%d", get_displacement (buffer
, aoffsetp
));
sprintf (result
, "%c%d%c", NEXT_IS_ADDR
,
addr
+ get_displacement (buffer
, aoffsetp
),
Ivalue
= bit_extract (buffer
, *aoffsetp
, 8);
sprintf (result
, "0x%x", Ivalue
);
get_displacement (buffer
, aoffsetp
)
Ivalue
= bit_extract (buffer
, *aoffsetp
, 8);
Ivalue
= sign_extend (Ivalue
, 7);
Ivalue
= bit_extract (buffer
, *aoffsetp
, 16);
Ivalue
= sign_extend (Ivalue
, 14);
Ivalue
= bit_extract (buffer
, *aoffsetp
, 32);
Ivalue
= sign_extend (Ivalue
, 30);
/* Return the number of locals in the current frame given a pc
pointing to the enter instruction. This is used in the macro
FRAME_FIND_SAVED_REGS. */
ns32k_localcount (enter_pc
)
localtype
= read_memory_integer (enter_pc
+2, 1);
if ((localtype
& 0x80) == 0)
else if ((localtype
& 0xc0) == 0x80)
localcount
= (((localtype
& 0x3f) << 8)
| (read_memory_integer (enter_pc
+3, 1) & 0xff));
localcount
= (((localtype
& 0x3f) << 24)
| ((read_memory_integer (enter_pc
+3, 1) & 0xff) << 16)
| ((read_memory_integer (enter_pc
+4, 1) & 0xff) << 8 )
| (read_memory_integer (enter_pc
+5, 1) & 0xff));
* Get the address of the enter opcode for the function
* containing PC, if there is an enter for the function,
* and if the pc is between the enter and exit.
* Returns positive address if pc is between enter/exit,
* 1 if pc before enter or after exit, 0 otherwise.
ns32k_get_enter_addr (pc
)
if (ABOUT_TO_RETURN (pc
))
return 1; /* after exit */
enter_addr
= get_pc_function_start (pc
);
return 1; /* before enter */
op
= read_memory_integer (enter_addr
, 1);
return 0; /* function has no enter/exit */
return enter_addr
; /* pc is between enter and exit */