summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/binutils/gdb/gould-tdep.c
blob: 79575e087c5d91a4ea74a419b98e6e6cdf4172a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* GOULD RISC target-dependent code for GDB, the GNU debugger.
   Copyright 1986, 1987, 1989, 1991 Free Software Foundation, Inc.

This file is part of GDB.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

#include "defs.h"
#include "symtab.h"
#include "frame.h"
#include "gdbcore.h"
#if defined GOULD_PN
#include "opcode/pn.h"
#else
#include "opcode/np1.h"
#endif

/* GOULD RISC instructions are never longer than this many bytes.  */
#define MAXLEN 4

/* Number of elements in the opcode table.  */
#define NOPCODES (sizeof gld_opcodes / sizeof gld_opcodes[0])


/* Print the GOULD instruction at address MEMADDR in debugged memory,
   on STREAM.  Returns length of the instruction, in bytes.  */

int
gould_print_insn (memaddr, stream)
     CORE_ADDR memaddr;
     FILE *stream;
{
	unsigned char buffer[MAXLEN];
	register int i;
	register char *d;
	register int bestmask;
	unsigned best;
	int temp, index, bestlen;

	read_memory (memaddr, buffer, MAXLEN);

	bestmask = 0;
	index = -1;
	best = 0xffffffff;
	for (i = 0; i < NOPCODES; i++)
	{
		register unsigned int opcode = gld_opcodes[i].opcode;
		register unsigned int mask = gld_opcodes[i].mask;
		register unsigned int len = gld_opcodes[i].length;
		register unsigned int test;

		/* Get possible opcode bytes into integer */
		test = buffer[0] << 24;
		test |= buffer[1] << 16;
		test |= buffer[2] << 8;
		test |= buffer[3];

		/* Mask with opcode and see if match */
		if ((opcode & mask) == (test & mask))
		{
			/* See if second or third match */
			if (index >= 0)
			{
				/* Take new one if it looks good */
				if (bestlen == MAXLEN && len == MAXLEN)
				{
					/* See if lower bits matched */
					if (((bestmask & 3) == 0) &&
					    ((mask & 3) != 0))
					{
						bestmask = mask;
						bestlen = len;
						best = test;
						index = i;
					}
				}
			}
			else
			{
				/* First match, save it */
				bestmask = mask;
				bestlen = len;
				best = test;
				index = i;
			}
		}
	}

	/* Handle undefined instructions.  */
	if (index < 0)
	{
		fprintf (stream, "undefined   0%o",(buffer[0]<<8)+buffer[1]);
		return 2;
	}

	/* Print instruction name */
	fprintf (stream, "%-12s", gld_opcodes[index].name);

	/* Adjust if short instruction */
	if (gld_opcodes[index].length < 4)
	{
		best >>= 16;
		i = 0;
	}
	else
	{
		i = 16;
	}

	/* Dump out instruction arguments */
  	for (d = gld_opcodes[index].args; *d; ++d)
	{
	    switch (*d)
	    {
		case 'f':
		    fprintf (stream, "%d",  (best >> (7 + i)) & 7);
		    break;
		case 'r':
		    fprintf (stream, "r%d", (best >> (7 + i)) & 7);
		    break;
		case 'R':
		    fprintf (stream, "r%d", (best >> (4 + i)) & 7);
		    break;
		case 'b':
		    fprintf (stream, "b%d", (best >> (7 + i)) & 7);
		    break;
		case 'B':
		    fprintf (stream, "b%d", (best >> (4 + i)) & 7);
		    break;
		case 'v':
		    fprintf (stream, "b%d", (best >> (7 + i)) & 7);
		    break;
		case 'V':
		    fprintf (stream, "b%d", (best >> (4 + i)) & 7);
		    break;
		case 'X':
		    temp = (best >> 20) & 7;
		    if (temp)
			fprintf (stream, "r%d", temp);
		    else
			putc ('0', stream);
		    break;
		case 'A':
		    temp = (best >> 16) & 7;
		    if (temp)
			fprintf (stream, "(b%d)", temp);
		    break;
		case 'S':
		    fprintf (stream, "#%d", best & 0x1f);
		    break;
		case 'I':
		    fprintf (stream, "#%x", best & 0xffff);
		    break;
		case 'O':
		    fprintf (stream, "%x", best & 0xffff);
		    break;
		case 'h':
		    fprintf (stream, "%d", best & 0xfffe);
		    break;
		case 'd':
		    fprintf (stream, "%d", best & 0xfffc);
		    break;
		case 'T':
		    fprintf (stream, "%d", (best >> 8) & 0xff);
		    break;
		case 'N':
		    fprintf (stream, "%d", best & 0xff);
		    break;
		default:
		    putc (*d, stream);
		    break;
	    }
	}

	/* Return length of instruction */
  	return (gld_opcodes[index].length);
}

/*
 * Find the number of arguments to a function.
 */
findarg(frame)
	struct frame_info *frame;
{
	register struct symbol *func;
	register unsigned pc;

#ifdef notdef
	/* find starting address of frame function */
	pc = get_pc_function_start (frame->pc);

	/* find function symbol info */
	func = find_pc_function (pc);

	/* call blockframe code to look for match */
	if (func != NULL)
                return (func->value.block->nsyms / sizeof(int));
#endif

        return (-1);
} 

/*
 * In the case of the NPL, the frame's norminal address is Br2 and the 
 * previous routines frame is up the stack X bytes.  Finding out what
 * 'X' is can be tricky.
 *
 *    1.) stored in the code function header xA(Br1).
 *    2.) must be careful of recurssion.
 */
CORE_ADDR
findframe(thisframe)
    struct frame_info *thisframe;
{
    register CORE_ADDR pointer;
    CORE_ADDR framechain();
#if 0    
    struct frame_info *frame;

    /* Setup toplevel frame structure */
    frame->pc = read_pc();
    frame->next_frame = 0;
    frame->frame = read_register (SP_REGNUM);	/* Br2 */

    /* Search for this frame (start at current Br2) */
    do
    {
	pointer = framechain(frame);
	frame->next_frame = frame->frame;
	frame->frame = pointer;
	frame->pc = FRAME_SAVED_PC(frame);
    }
    while (frame->next_frame != thisframe);
#endif

    pointer = framechain (thisframe);

    /* stop gap for now, end at __base3 */
    if (thisframe->pc == 0)
	return 0;

    return pointer;
}

/*
 * Gdb front-end and internal framechain routine.
 * Go back up stack one level.  Tricky...
 */
CORE_ADDR
framechain(frame)
    register struct frame_info *frame;
{
    register CORE_ADDR func, prevsp;
    register unsigned value;

    /* Get real function start address from internal frame address */
    func = get_pc_function_start(frame->pc);

    /* If no stack given, read register Br1 "(sp)" */
    if (!frame->frame)
	prevsp = read_register (SP_REGNUM);
    else
	prevsp = frame->frame;

    /* Check function header, case #2 */
    value = read_memory_integer (func, 4);
    if (value)
    {
	/* 32bit call push value stored in function header */
	prevsp += value;
    }
    else
    {
	/* read half-word from suabr at start of function */
	prevsp += read_memory_integer (func + 10, 2);
    }

    return (prevsp);
}