1 |
1181 |
sfurman |
/* Target dependent code for CRIS, for GDB, the GNU debugger.
|
2 |
|
|
Copyright 2001 Free Software Foundation, Inc.
|
3 |
|
|
Contributed by Axis Communications AB.
|
4 |
|
|
Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg.
|
5 |
|
|
|
6 |
|
|
This file is part of GDB.
|
7 |
|
|
|
8 |
|
|
This program is free software; you can redistribute it and/or modify
|
9 |
|
|
it under the terms of the GNU General Public License as published by
|
10 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
11 |
|
|
(at your option) any later version.
|
12 |
|
|
|
13 |
|
|
This program is distributed in the hope that it will be useful,
|
14 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
GNU General Public License for more details.
|
17 |
|
|
|
18 |
|
|
You should have received a copy of the GNU General Public License
|
19 |
|
|
along with this program; if not, write to the Free Software
|
20 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
21 |
|
|
|
22 |
|
|
#include "defs.h"
|
23 |
|
|
#include "frame.h"
|
24 |
|
|
#include "symtab.h"
|
25 |
|
|
#include "inferior.h"
|
26 |
|
|
#include "gdbtypes.h"
|
27 |
|
|
#include "gdbcore.h"
|
28 |
|
|
#include "gdbcmd.h"
|
29 |
|
|
#include "target.h"
|
30 |
|
|
#include "value.h"
|
31 |
|
|
#include "opcode/cris.h"
|
32 |
|
|
#include "arch-utils.h"
|
33 |
|
|
#include "regcache.h"
|
34 |
|
|
#include "gdb_string.h"
|
35 |
|
|
|
36 |
|
|
/* To get entry_point_address. */
|
37 |
|
|
#include "symfile.h"
|
38 |
|
|
|
39 |
|
|
#include "solib.h" /* Support for shared libraries. */
|
40 |
|
|
#include "solib-svr4.h" /* For struct link_map_offsets. */
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
enum cris_num_regs
|
44 |
|
|
{
|
45 |
|
|
/* There are no floating point registers. Used in gdbserver low-linux.c. */
|
46 |
|
|
NUM_FREGS = 0,
|
47 |
|
|
|
48 |
|
|
/* There are 16 general registers. */
|
49 |
|
|
NUM_GENREGS = 16,
|
50 |
|
|
|
51 |
|
|
/* There are 16 special registers. */
|
52 |
|
|
NUM_SPECREGS = 16
|
53 |
|
|
};
|
54 |
|
|
|
55 |
|
|
/* Register numbers of various important registers.
|
56 |
|
|
FP_REGNUM Contains address of executing stack frame.
|
57 |
|
|
STR_REGNUM Contains the address of structure return values.
|
58 |
|
|
RET_REGNUM Contains the return value when shorter than or equal to 32 bits
|
59 |
|
|
ARG1_REGNUM Contains the first parameter to a function.
|
60 |
|
|
ARG2_REGNUM Contains the second parameter to a function.
|
61 |
|
|
ARG3_REGNUM Contains the third parameter to a function.
|
62 |
|
|
ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack.
|
63 |
|
|
SP_REGNUM Contains address of top of stack.
|
64 |
|
|
PC_REGNUM Contains address of next instruction.
|
65 |
|
|
SRP_REGNUM Subroutine return pointer register.
|
66 |
|
|
BRP_REGNUM Breakpoint return pointer register. */
|
67 |
|
|
|
68 |
|
|
/* FP_REGNUM = 8, SP_REGNUM = 14, and PC_REGNUM = 15 have been incorporated
|
69 |
|
|
into the multi-arch framework. */
|
70 |
|
|
|
71 |
|
|
enum cris_regnums
|
72 |
|
|
{
|
73 |
|
|
/* Enums with respect to the general registers, valid for all
|
74 |
|
|
CRIS versions. */
|
75 |
|
|
STR_REGNUM = 9,
|
76 |
|
|
RET_REGNUM = 10,
|
77 |
|
|
ARG1_REGNUM = 10,
|
78 |
|
|
ARG2_REGNUM = 11,
|
79 |
|
|
ARG3_REGNUM = 12,
|
80 |
|
|
ARG4_REGNUM = 13,
|
81 |
|
|
|
82 |
|
|
/* Enums with respect to the special registers, some of which may not be
|
83 |
|
|
applicable to all CRIS versions. */
|
84 |
|
|
P0_REGNUM = 16,
|
85 |
|
|
VR_REGNUM = 17,
|
86 |
|
|
P2_REGNUM = 18,
|
87 |
|
|
P3_REGNUM = 19,
|
88 |
|
|
P4_REGNUM = 20,
|
89 |
|
|
CCR_REGNUM = 21,
|
90 |
|
|
MOF_REGNUM = 23,
|
91 |
|
|
P8_REGNUM = 24,
|
92 |
|
|
IBR_REGNUM = 25,
|
93 |
|
|
IRP_REGNUM = 26,
|
94 |
|
|
SRP_REGNUM = 27,
|
95 |
|
|
BAR_REGNUM = 28,
|
96 |
|
|
DCCR_REGNUM = 29,
|
97 |
|
|
BRP_REGNUM = 30,
|
98 |
|
|
USP_REGNUM = 31
|
99 |
|
|
};
|
100 |
|
|
|
101 |
|
|
extern const struct cris_spec_reg cris_spec_regs[];
|
102 |
|
|
|
103 |
|
|
/* CRIS version, set via the user command 'set cris-version'. Affects
|
104 |
|
|
register names and sizes.*/
|
105 |
|
|
static int usr_cmd_cris_version;
|
106 |
|
|
|
107 |
|
|
/* Indicates whether to trust the above variable. */
|
108 |
|
|
static int usr_cmd_cris_version_valid = 0;
|
109 |
|
|
|
110 |
|
|
/* CRIS mode, set via the user command 'set cris-mode'. Affects availability
|
111 |
|
|
of some registers. */
|
112 |
|
|
static const char *usr_cmd_cris_mode;
|
113 |
|
|
|
114 |
|
|
/* Indicates whether to trust the above variable. */
|
115 |
|
|
static int usr_cmd_cris_mode_valid = 0;
|
116 |
|
|
|
117 |
|
|
static const char CRIS_MODE_USER[] = "CRIS_MODE_USER";
|
118 |
|
|
static const char CRIS_MODE_SUPERVISOR[] = "CRIS_MODE_SUPERVISOR";
|
119 |
|
|
static const char *cris_mode_enums[] =
|
120 |
|
|
{
|
121 |
|
|
CRIS_MODE_USER,
|
122 |
|
|
CRIS_MODE_SUPERVISOR,
|
123 |
|
|
|
124 |
|
|
};
|
125 |
|
|
|
126 |
|
|
/* CRIS ABI, set via the user command 'set cris-abi'.
|
127 |
|
|
There are two flavours:
|
128 |
|
|
1. Original ABI with 32-bit doubles, where arguments <= 4 bytes are
|
129 |
|
|
passed by value.
|
130 |
|
|
2. New ABI with 64-bit doubles, where arguments <= 8 bytes are passed by
|
131 |
|
|
value. */
|
132 |
|
|
static const char *usr_cmd_cris_abi;
|
133 |
|
|
|
134 |
|
|
/* Indicates whether to trust the above variable. */
|
135 |
|
|
static int usr_cmd_cris_abi_valid = 0;
|
136 |
|
|
|
137 |
|
|
/* These variables are strings instead of enums to make them usable as
|
138 |
|
|
parameters to add_set_enum_cmd. */
|
139 |
|
|
static const char CRIS_ABI_ORIGINAL[] = "CRIS_ABI_ORIGINAL";
|
140 |
|
|
static const char CRIS_ABI_V2[] = "CRIS_ABI_V2";
|
141 |
|
|
static const char CRIS_ABI_SYMBOL[] = ".$CRIS_ABI_V2";
|
142 |
|
|
static const char *cris_abi_enums[] =
|
143 |
|
|
{
|
144 |
|
|
CRIS_ABI_ORIGINAL,
|
145 |
|
|
CRIS_ABI_V2,
|
146 |
|
|
|
147 |
|
|
};
|
148 |
|
|
|
149 |
|
|
/* CRIS architecture specific information. */
|
150 |
|
|
struct gdbarch_tdep
|
151 |
|
|
{
|
152 |
|
|
int cris_version;
|
153 |
|
|
const char *cris_mode;
|
154 |
|
|
const char *cris_abi;
|
155 |
|
|
};
|
156 |
|
|
|
157 |
|
|
/* Functions for accessing target dependent data. */
|
158 |
|
|
|
159 |
|
|
static int
|
160 |
|
|
cris_version (void)
|
161 |
|
|
{
|
162 |
|
|
return (gdbarch_tdep (current_gdbarch)->cris_version);
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
static const char *
|
166 |
|
|
cris_mode (void)
|
167 |
|
|
{
|
168 |
|
|
return (gdbarch_tdep (current_gdbarch)->cris_mode);
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
static const char *
|
172 |
|
|
cris_abi (void)
|
173 |
|
|
{
|
174 |
|
|
return (gdbarch_tdep (current_gdbarch)->cris_abi);
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
/* For saving call-clobbered contents in R9 when returning structs. */
|
178 |
|
|
static CORE_ADDR struct_return_address;
|
179 |
|
|
|
180 |
|
|
struct frame_extra_info
|
181 |
|
|
{
|
182 |
|
|
CORE_ADDR return_pc;
|
183 |
|
|
int leaf_function;
|
184 |
|
|
};
|
185 |
|
|
|
186 |
|
|
/* The instruction environment needed to find single-step breakpoints. */
|
187 |
|
|
typedef
|
188 |
|
|
struct instruction_environment
|
189 |
|
|
{
|
190 |
|
|
unsigned long reg[NUM_GENREGS];
|
191 |
|
|
unsigned long preg[NUM_SPECREGS];
|
192 |
|
|
unsigned long branch_break_address;
|
193 |
|
|
unsigned long delay_slot_pc;
|
194 |
|
|
unsigned long prefix_value;
|
195 |
|
|
int branch_found;
|
196 |
|
|
int prefix_found;
|
197 |
|
|
int invalid;
|
198 |
|
|
int slot_needed;
|
199 |
|
|
int delay_slot_pc_active;
|
200 |
|
|
int xflag_found;
|
201 |
|
|
int disable_interrupt;
|
202 |
|
|
} inst_env_type;
|
203 |
|
|
|
204 |
|
|
/* Save old breakpoints in order to restore the state before a single_step.
|
205 |
|
|
At most, two breakpoints will have to be remembered. */
|
206 |
|
|
typedef
|
207 |
|
|
char binsn_quantum[BREAKPOINT_MAX];
|
208 |
|
|
static binsn_quantum break_mem[2];
|
209 |
|
|
static CORE_ADDR next_pc = 0;
|
210 |
|
|
static CORE_ADDR branch_target_address = 0;
|
211 |
|
|
static unsigned char branch_break_inserted = 0;
|
212 |
|
|
|
213 |
|
|
/* Machine-dependencies in CRIS for opcodes. */
|
214 |
|
|
|
215 |
|
|
/* Instruction sizes. */
|
216 |
|
|
enum cris_instruction_sizes
|
217 |
|
|
{
|
218 |
|
|
INST_BYTE_SIZE = 0,
|
219 |
|
|
INST_WORD_SIZE = 1,
|
220 |
|
|
INST_DWORD_SIZE = 2
|
221 |
|
|
};
|
222 |
|
|
|
223 |
|
|
/* Addressing modes. */
|
224 |
|
|
enum cris_addressing_modes
|
225 |
|
|
{
|
226 |
|
|
REGISTER_MODE = 1,
|
227 |
|
|
INDIRECT_MODE = 2,
|
228 |
|
|
AUTOINC_MODE = 3
|
229 |
|
|
};
|
230 |
|
|
|
231 |
|
|
/* Prefix addressing modes. */
|
232 |
|
|
enum cris_prefix_addressing_modes
|
233 |
|
|
{
|
234 |
|
|
PREFIX_INDEX_MODE = 2,
|
235 |
|
|
PREFIX_ASSIGN_MODE = 3,
|
236 |
|
|
|
237 |
|
|
/* Handle immediate byte offset addressing mode prefix format. */
|
238 |
|
|
PREFIX_OFFSET_MODE = 2
|
239 |
|
|
};
|
240 |
|
|
|
241 |
|
|
/* Masks for opcodes. */
|
242 |
|
|
enum cris_opcode_masks
|
243 |
|
|
{
|
244 |
|
|
BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1,
|
245 |
|
|
SIGNED_EXTEND_BIT_MASK = 0x2,
|
246 |
|
|
SIGNED_BYTE_MASK = 0x80,
|
247 |
|
|
SIGNED_BYTE_EXTEND_MASK = 0xFFFFFF00,
|
248 |
|
|
SIGNED_WORD_MASK = 0x8000,
|
249 |
|
|
SIGNED_WORD_EXTEND_MASK = 0xFFFF0000,
|
250 |
|
|
SIGNED_DWORD_MASK = 0x80000000,
|
251 |
|
|
SIGNED_QUICK_VALUE_MASK = 0x20,
|
252 |
|
|
SIGNED_QUICK_VALUE_EXTEND_MASK = 0xFFFFFFC0
|
253 |
|
|
};
|
254 |
|
|
|
255 |
|
|
/* Functions for opcodes. The general form of the ETRAX 16-bit instruction:
|
256 |
|
|
Bit 15 - 12 Operand2
|
257 |
|
|
11 - 10 Mode
|
258 |
|
|
9 - 6 Opcode
|
259 |
|
|
5 - 4 Size
|
260 |
|
|
3 - 0 Operand1 */
|
261 |
|
|
|
262 |
|
|
static int
|
263 |
|
|
cris_get_operand2 (unsigned short insn)
|
264 |
|
|
{
|
265 |
|
|
return ((insn & 0xF000) >> 12);
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
static int
|
269 |
|
|
cris_get_mode (unsigned short insn)
|
270 |
|
|
{
|
271 |
|
|
return ((insn & 0x0C00) >> 10);
|
272 |
|
|
}
|
273 |
|
|
|
274 |
|
|
static int
|
275 |
|
|
cris_get_opcode (unsigned short insn)
|
276 |
|
|
{
|
277 |
|
|
return ((insn & 0x03C0) >> 6);
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
static int
|
281 |
|
|
cris_get_size (unsigned short insn)
|
282 |
|
|
{
|
283 |
|
|
return ((insn & 0x0030) >> 4);
|
284 |
|
|
}
|
285 |
|
|
|
286 |
|
|
static int
|
287 |
|
|
cris_get_operand1 (unsigned short insn)
|
288 |
|
|
{
|
289 |
|
|
return (insn & 0x000F);
|
290 |
|
|
}
|
291 |
|
|
|
292 |
|
|
/* Additional functions in order to handle opcodes. */
|
293 |
|
|
|
294 |
|
|
static int
|
295 |
|
|
cris_get_wide_opcode (unsigned short insn)
|
296 |
|
|
{
|
297 |
|
|
return ((insn & 0x03E0) >> 5);
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
static int
|
301 |
|
|
cris_get_short_size (unsigned short insn)
|
302 |
|
|
{
|
303 |
|
|
return ((insn & 0x0010) >> 4);
|
304 |
|
|
}
|
305 |
|
|
|
306 |
|
|
static int
|
307 |
|
|
cris_get_quick_value (unsigned short insn)
|
308 |
|
|
{
|
309 |
|
|
return (insn & 0x003F);
|
310 |
|
|
}
|
311 |
|
|
|
312 |
|
|
static int
|
313 |
|
|
cris_get_bdap_quick_offset (unsigned short insn)
|
314 |
|
|
{
|
315 |
|
|
return (insn & 0x00FF);
|
316 |
|
|
}
|
317 |
|
|
|
318 |
|
|
static int
|
319 |
|
|
cris_get_branch_short_offset (unsigned short insn)
|
320 |
|
|
{
|
321 |
|
|
return (insn & 0x00FF);
|
322 |
|
|
}
|
323 |
|
|
|
324 |
|
|
static int
|
325 |
|
|
cris_get_asr_shift_steps (unsigned long value)
|
326 |
|
|
{
|
327 |
|
|
return (value & 0x3F);
|
328 |
|
|
}
|
329 |
|
|
|
330 |
|
|
static int
|
331 |
|
|
cris_get_asr_quick_shift_steps (unsigned short insn)
|
332 |
|
|
{
|
333 |
|
|
return (insn & 0x1F);
|
334 |
|
|
}
|
335 |
|
|
|
336 |
|
|
static int
|
337 |
|
|
cris_get_clear_size (unsigned short insn)
|
338 |
|
|
{
|
339 |
|
|
return ((insn) & 0xC000);
|
340 |
|
|
}
|
341 |
|
|
|
342 |
|
|
static int
|
343 |
|
|
cris_is_signed_extend_bit_on (unsigned short insn)
|
344 |
|
|
{
|
345 |
|
|
return (((insn) & 0x20) == 0x20);
|
346 |
|
|
}
|
347 |
|
|
|
348 |
|
|
static int
|
349 |
|
|
cris_is_xflag_bit_on (unsigned short insn)
|
350 |
|
|
{
|
351 |
|
|
return (((insn) & 0x1000) == 0x1000);
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
static void
|
355 |
|
|
cris_set_size_to_dword (unsigned short *insn)
|
356 |
|
|
{
|
357 |
|
|
*insn &= 0xFFCF;
|
358 |
|
|
*insn |= 0x20;
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
static signed char
|
362 |
|
|
cris_get_signed_offset (unsigned short insn)
|
363 |
|
|
{
|
364 |
|
|
return ((signed char) (insn & 0x00FF));
|
365 |
|
|
}
|
366 |
|
|
|
367 |
|
|
/* Calls an op function given the op-type, working on the insn and the
|
368 |
|
|
inst_env. */
|
369 |
|
|
static void cris_gdb_func (enum cris_op_type, unsigned short, inst_env_type *);
|
370 |
|
|
|
371 |
|
|
static CORE_ADDR cris_skip_prologue_main (CORE_ADDR pc, int frameless_p);
|
372 |
|
|
|
373 |
|
|
static struct gdbarch *cris_gdbarch_init (struct gdbarch_info,
|
374 |
|
|
struct gdbarch_list *);
|
375 |
|
|
|
376 |
|
|
static int cris_delayed_get_disassembler (bfd_vma, disassemble_info *);
|
377 |
|
|
|
378 |
|
|
static void cris_dump_tdep (struct gdbarch *, struct ui_file *);
|
379 |
|
|
|
380 |
|
|
static void cris_version_update (char *ignore_args, int from_tty,
|
381 |
|
|
struct cmd_list_element *c);
|
382 |
|
|
|
383 |
|
|
static void cris_mode_update (char *ignore_args, int from_tty,
|
384 |
|
|
struct cmd_list_element *c);
|
385 |
|
|
|
386 |
|
|
static void cris_abi_update (char *ignore_args, int from_tty,
|
387 |
|
|
struct cmd_list_element *c);
|
388 |
|
|
|
389 |
|
|
static CORE_ADDR bfd_lookup_symbol (bfd *, const char *);
|
390 |
|
|
|
391 |
|
|
/* Frames information. The definition of the struct frame_info is
|
392 |
|
|
|
393 |
|
|
CORE_ADDR frame
|
394 |
|
|
CORE_ADDR pc
|
395 |
|
|
int signal_handler_caller
|
396 |
|
|
CORE_ADDR return_pc
|
397 |
|
|
int leaf_function
|
398 |
|
|
|
399 |
|
|
If the compilation option -fno-omit-frame-pointer is present the
|
400 |
|
|
variable frame will be set to the content of R8 which is the frame
|
401 |
|
|
pointer register.
|
402 |
|
|
|
403 |
|
|
The variable pc contains the address where execution is performed
|
404 |
|
|
in the present frame. The innermost frame contains the current content
|
405 |
|
|
of the register PC. All other frames contain the content of the
|
406 |
|
|
register PC in the next frame.
|
407 |
|
|
|
408 |
|
|
The variable signal_handler_caller is non-zero when the frame is
|
409 |
|
|
associated with the call of a signal handler.
|
410 |
|
|
|
411 |
|
|
The variable return_pc contains the address where execution should be
|
412 |
|
|
resumed when the present frame has finished, the return address.
|
413 |
|
|
|
414 |
|
|
The variable leaf_function is 1 if the return address is in the register
|
415 |
|
|
SRP, and 0 if it is on the stack.
|
416 |
|
|
|
417 |
|
|
Prologue instructions C-code.
|
418 |
|
|
The prologue may consist of (-fno-omit-frame-pointer)
|
419 |
|
|
1) 2)
|
420 |
|
|
push srp
|
421 |
|
|
push r8 push r8
|
422 |
|
|
move.d sp,r8 move.d sp,r8
|
423 |
|
|
subq X,sp subq X,sp
|
424 |
|
|
movem rY,[sp] movem rY,[sp]
|
425 |
|
|
move.S rZ,[r8-U] move.S rZ,[r8-U]
|
426 |
|
|
|
427 |
|
|
where 1 is a non-terminal function, and 2 is a leaf-function.
|
428 |
|
|
|
429 |
|
|
Note that this assumption is extremely brittle, and will break at the
|
430 |
|
|
slightest change in GCC's prologue.
|
431 |
|
|
|
432 |
|
|
If local variables are declared or register contents are saved on stack
|
433 |
|
|
the subq-instruction will be present with X as the number of bytes
|
434 |
|
|
needed for storage. The reshuffle with respect to r8 may be performed
|
435 |
|
|
with any size S (b, w, d) and any of the general registers Z={0..13}.
|
436 |
|
|
The offset U should be representable by a signed 8-bit value in all cases.
|
437 |
|
|
Thus, the prefix word is assumed to be immediate byte offset mode followed
|
438 |
|
|
by another word containing the instruction.
|
439 |
|
|
|
440 |
|
|
Degenerate cases:
|
441 |
|
|
3)
|
442 |
|
|
push r8
|
443 |
|
|
move.d sp,r8
|
444 |
|
|
move.d r8,sp
|
445 |
|
|
pop r8
|
446 |
|
|
|
447 |
|
|
Prologue instructions C++-code.
|
448 |
|
|
Case 1) and 2) in the C-code may be followed by
|
449 |
|
|
|
450 |
|
|
move.d r10,rS ; this
|
451 |
|
|
move.d r11,rT ; P1
|
452 |
|
|
move.d r12,rU ; P2
|
453 |
|
|
move.d r13,rV ; P3
|
454 |
|
|
move.S [r8+U],rZ ; P4
|
455 |
|
|
|
456 |
|
|
if any of the call parameters are stored. The host expects these
|
457 |
|
|
instructions to be executed in order to get the call parameters right. */
|
458 |
|
|
|
459 |
|
|
/* Examine the prologue of a function. The variable ip is the address of
|
460 |
|
|
the first instruction of the prologue. The variable limit is the address
|
461 |
|
|
of the first instruction after the prologue. The variable fi contains the
|
462 |
|
|
information in struct frame_info. The variable frameless_p controls whether
|
463 |
|
|
the entire prologue is examined (0) or just enough instructions to
|
464 |
|
|
determine that it is a prologue (1). */
|
465 |
|
|
|
466 |
|
|
CORE_ADDR
|
467 |
|
|
cris_examine (CORE_ADDR ip, CORE_ADDR limit, struct frame_info *fi,
|
468 |
|
|
int frameless_p)
|
469 |
|
|
{
|
470 |
|
|
/* Present instruction. */
|
471 |
|
|
unsigned short insn;
|
472 |
|
|
|
473 |
|
|
/* Next instruction, lookahead. */
|
474 |
|
|
unsigned short insn_next;
|
475 |
|
|
int regno;
|
476 |
|
|
|
477 |
|
|
/* Is there a push fp? */
|
478 |
|
|
int have_fp;
|
479 |
|
|
|
480 |
|
|
/* Number of byte on stack used for local variables and movem. */
|
481 |
|
|
int val;
|
482 |
|
|
|
483 |
|
|
/* Highest register number in a movem. */
|
484 |
|
|
int regsave;
|
485 |
|
|
|
486 |
|
|
/* move.d r<source_register>,rS */
|
487 |
|
|
short source_register;
|
488 |
|
|
|
489 |
|
|
/* This frame is with respect to a leaf until a push srp is found. */
|
490 |
|
|
fi->extra_info->leaf_function = 1;
|
491 |
|
|
|
492 |
|
|
/* This frame is without the FP until a push fp is found. */
|
493 |
|
|
have_fp = 0;
|
494 |
|
|
|
495 |
|
|
/* Assume nothing on stack. */
|
496 |
|
|
val = 0;
|
497 |
|
|
regsave = -1;
|
498 |
|
|
|
499 |
|
|
/* No information about register contents so far. */
|
500 |
|
|
|
501 |
|
|
/* We only want to know the end of the prologue when fi->saved_regs == 0.
|
502 |
|
|
When the saved registers are allocated full information is required. */
|
503 |
|
|
if (fi->saved_regs)
|
504 |
|
|
{
|
505 |
|
|
for (regno = 0; regno < NUM_REGS; regno++)
|
506 |
|
|
fi->saved_regs[regno] = 0;
|
507 |
|
|
}
|
508 |
|
|
|
509 |
|
|
/* Find the prologue instructions. */
|
510 |
|
|
do
|
511 |
|
|
{
|
512 |
|
|
insn = read_memory_unsigned_integer (ip, sizeof (short));
|
513 |
|
|
ip += sizeof (short);
|
514 |
|
|
if (insn == 0xE1FC)
|
515 |
|
|
{
|
516 |
|
|
/* push <reg> 32 bit instruction */
|
517 |
|
|
insn_next = read_memory_unsigned_integer (ip, sizeof (short));
|
518 |
|
|
ip += sizeof (short);
|
519 |
|
|
regno = cris_get_operand2 (insn_next);
|
520 |
|
|
|
521 |
|
|
/* This check, meant to recognize srp, used to be regno ==
|
522 |
|
|
(SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
|
523 |
|
|
if (insn_next == 0xBE7E)
|
524 |
|
|
{
|
525 |
|
|
if (frameless_p)
|
526 |
|
|
{
|
527 |
|
|
return ip;
|
528 |
|
|
}
|
529 |
|
|
fi->extra_info->leaf_function = 0;
|
530 |
|
|
}
|
531 |
|
|
else if (regno == FP_REGNUM)
|
532 |
|
|
{
|
533 |
|
|
have_fp = 1;
|
534 |
|
|
}
|
535 |
|
|
}
|
536 |
|
|
else if (insn == 0x866E)
|
537 |
|
|
{
|
538 |
|
|
/* move.d sp,r8 */
|
539 |
|
|
if (frameless_p)
|
540 |
|
|
{
|
541 |
|
|
return ip;
|
542 |
|
|
}
|
543 |
|
|
continue;
|
544 |
|
|
}
|
545 |
|
|
else if (cris_get_operand2 (insn) == SP_REGNUM
|
546 |
|
|
&& cris_get_mode (insn) == 0x0000
|
547 |
|
|
&& cris_get_opcode (insn) == 0x000A)
|
548 |
|
|
{
|
549 |
|
|
/* subq <val>,sp */
|
550 |
|
|
val = cris_get_quick_value (insn);
|
551 |
|
|
}
|
552 |
|
|
else if (cris_get_mode (insn) == 0x0002
|
553 |
|
|
&& cris_get_opcode (insn) == 0x000F
|
554 |
|
|
&& cris_get_size (insn) == 0x0003
|
555 |
|
|
&& cris_get_operand1 (insn) == SP_REGNUM)
|
556 |
|
|
{
|
557 |
|
|
/* movem r<regsave>,[sp] */
|
558 |
|
|
if (frameless_p)
|
559 |
|
|
{
|
560 |
|
|
return ip;
|
561 |
|
|
}
|
562 |
|
|
regsave = cris_get_operand2 (insn);
|
563 |
|
|
}
|
564 |
|
|
else if (cris_get_operand2 (insn) == SP_REGNUM
|
565 |
|
|
&& ((insn & 0x0F00) >> 8) == 0x0001
|
566 |
|
|
&& (cris_get_signed_offset (insn) < 0))
|
567 |
|
|
{
|
568 |
|
|
/* Immediate byte offset addressing prefix word with sp as base
|
569 |
|
|
register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
|
570 |
|
|
is between 64 and 128.
|
571 |
|
|
movem r<regsave>,[sp=sp-<val>] */
|
572 |
|
|
val = -cris_get_signed_offset (insn);
|
573 |
|
|
insn_next = read_memory_unsigned_integer (ip, sizeof (short));
|
574 |
|
|
ip += sizeof (short);
|
575 |
|
|
if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
|
576 |
|
|
&& cris_get_opcode (insn_next) == 0x000F
|
577 |
|
|
&& cris_get_size (insn_next) == 0x0003
|
578 |
|
|
&& cris_get_operand1 (insn_next) == SP_REGNUM)
|
579 |
|
|
{
|
580 |
|
|
if (frameless_p)
|
581 |
|
|
{
|
582 |
|
|
return ip;
|
583 |
|
|
}
|
584 |
|
|
regsave = cris_get_operand2 (insn_next);
|
585 |
|
|
}
|
586 |
|
|
else
|
587 |
|
|
{
|
588 |
|
|
/* The prologue ended before the limit was reached. */
|
589 |
|
|
ip -= 2 * sizeof (short);
|
590 |
|
|
break;
|
591 |
|
|
}
|
592 |
|
|
}
|
593 |
|
|
else if (cris_get_mode (insn) == 0x0001
|
594 |
|
|
&& cris_get_opcode (insn) == 0x0009
|
595 |
|
|
&& cris_get_size (insn) == 0x0002)
|
596 |
|
|
{
|
597 |
|
|
/* move.d r<10..13>,r<0..15> */
|
598 |
|
|
if (frameless_p)
|
599 |
|
|
{
|
600 |
|
|
return ip;
|
601 |
|
|
}
|
602 |
|
|
source_register = cris_get_operand1 (insn);
|
603 |
|
|
|
604 |
|
|
/* FIXME? In the glibc solibs, the prologue might contain something
|
605 |
|
|
like (this example taken from relocate_doit):
|
606 |
|
|
move.d $pc,$r0
|
607 |
|
|
sub.d 0xfffef426,$r0
|
608 |
|
|
which isn't covered by the source_register check below. Question
|
609 |
|
|
is whether to add a check for this combo, or make better use of
|
610 |
|
|
the limit variable instead. */
|
611 |
|
|
if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
|
612 |
|
|
{
|
613 |
|
|
/* The prologue ended before the limit was reached. */
|
614 |
|
|
ip -= sizeof (short);
|
615 |
|
|
break;
|
616 |
|
|
}
|
617 |
|
|
}
|
618 |
|
|
else if (cris_get_operand2 (insn) == FP_REGNUM
|
619 |
|
|
/* The size is a fixed-size. */
|
620 |
|
|
&& ((insn & 0x0F00) >> 8) == 0x0001
|
621 |
|
|
/* A negative offset. */
|
622 |
|
|
&& (cris_get_signed_offset (insn) < 0))
|
623 |
|
|
{
|
624 |
|
|
/* move.S rZ,[r8-U] (?) */
|
625 |
|
|
insn_next = read_memory_unsigned_integer (ip, sizeof (short));
|
626 |
|
|
ip += sizeof (short);
|
627 |
|
|
regno = cris_get_operand2 (insn_next);
|
628 |
|
|
if ((regno >= 0 && regno < SP_REGNUM)
|
629 |
|
|
&& cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
|
630 |
|
|
&& cris_get_opcode (insn_next) == 0x000F)
|
631 |
|
|
{
|
632 |
|
|
/* move.S rZ,[r8-U] */
|
633 |
|
|
continue;
|
634 |
|
|
}
|
635 |
|
|
else
|
636 |
|
|
{
|
637 |
|
|
/* The prologue ended before the limit was reached. */
|
638 |
|
|
ip -= 2 * sizeof (short);
|
639 |
|
|
break;
|
640 |
|
|
}
|
641 |
|
|
}
|
642 |
|
|
else if (cris_get_operand2 (insn) == FP_REGNUM
|
643 |
|
|
/* The size is a fixed-size. */
|
644 |
|
|
&& ((insn & 0x0F00) >> 8) == 0x0001
|
645 |
|
|
/* A positive offset. */
|
646 |
|
|
&& (cris_get_signed_offset (insn) > 0))
|
647 |
|
|
{
|
648 |
|
|
/* move.S [r8+U],rZ (?) */
|
649 |
|
|
insn_next = read_memory_unsigned_integer (ip, sizeof (short));
|
650 |
|
|
ip += sizeof (short);
|
651 |
|
|
regno = cris_get_operand2 (insn_next);
|
652 |
|
|
if ((regno >= 0 && regno < SP_REGNUM)
|
653 |
|
|
&& cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
|
654 |
|
|
&& cris_get_opcode (insn_next) == 0x0009
|
655 |
|
|
&& cris_get_operand1 (insn_next) == regno)
|
656 |
|
|
{
|
657 |
|
|
/* move.S [r8+U],rZ */
|
658 |
|
|
continue;
|
659 |
|
|
}
|
660 |
|
|
else
|
661 |
|
|
{
|
662 |
|
|
/* The prologue ended before the limit was reached. */
|
663 |
|
|
ip -= 2 * sizeof (short);
|
664 |
|
|
break;
|
665 |
|
|
}
|
666 |
|
|
}
|
667 |
|
|
else
|
668 |
|
|
{
|
669 |
|
|
/* The prologue ended before the limit was reached. */
|
670 |
|
|
ip -= sizeof (short);
|
671 |
|
|
break;
|
672 |
|
|
}
|
673 |
|
|
}
|
674 |
|
|
while (ip < limit);
|
675 |
|
|
|
676 |
|
|
/* We only want to know the end of the prologue when
|
677 |
|
|
fi->saved_regs == 0. */
|
678 |
|
|
if (!fi->saved_regs)
|
679 |
|
|
return ip;
|
680 |
|
|
|
681 |
|
|
if (have_fp)
|
682 |
|
|
{
|
683 |
|
|
fi->saved_regs[FP_REGNUM] = FRAME_FP (fi);
|
684 |
|
|
|
685 |
|
|
/* Calculate the addresses. */
|
686 |
|
|
for (regno = regsave; regno >= 0; regno--)
|
687 |
|
|
{
|
688 |
|
|
fi->saved_regs[regno] = FRAME_FP (fi) - val;
|
689 |
|
|
val -= 4;
|
690 |
|
|
}
|
691 |
|
|
if (fi->extra_info->leaf_function)
|
692 |
|
|
{
|
693 |
|
|
/* Set the register SP to contain the stack pointer of
|
694 |
|
|
the caller. */
|
695 |
|
|
fi->saved_regs[SP_REGNUM] = FRAME_FP (fi) + 4;
|
696 |
|
|
}
|
697 |
|
|
else
|
698 |
|
|
{
|
699 |
|
|
/* Set the register SP to contain the stack pointer of
|
700 |
|
|
the caller. */
|
701 |
|
|
fi->saved_regs[SP_REGNUM] = FRAME_FP (fi) + 8;
|
702 |
|
|
|
703 |
|
|
/* Set the register SRP to contain the return address of
|
704 |
|
|
the caller. */
|
705 |
|
|
fi->saved_regs[SRP_REGNUM] = FRAME_FP (fi) + 4;
|
706 |
|
|
}
|
707 |
|
|
}
|
708 |
|
|
return ip;
|
709 |
|
|
}
|
710 |
|
|
|
711 |
|
|
/* Advance pc beyond any function entry prologue instructions at pc
|
712 |
|
|
to reach some "real" code. */
|
713 |
|
|
|
714 |
|
|
CORE_ADDR
|
715 |
|
|
cris_skip_prologue (CORE_ADDR pc)
|
716 |
|
|
{
|
717 |
|
|
return cris_skip_prologue_main (pc, 0);
|
718 |
|
|
}
|
719 |
|
|
|
720 |
|
|
/* As cris_skip_prologue, but stops as soon as it knows that the function
|
721 |
|
|
has a frame. Its result is equal to its input pc if the function is
|
722 |
|
|
frameless, unequal otherwise. */
|
723 |
|
|
|
724 |
|
|
CORE_ADDR
|
725 |
|
|
cris_skip_prologue_frameless_p (CORE_ADDR pc)
|
726 |
|
|
{
|
727 |
|
|
return cris_skip_prologue_main (pc, 1);
|
728 |
|
|
}
|
729 |
|
|
|
730 |
|
|
/* Given a PC value corresponding to the start of a function, return the PC
|
731 |
|
|
of the first instruction after the function prologue. */
|
732 |
|
|
|
733 |
|
|
CORE_ADDR
|
734 |
|
|
cris_skip_prologue_main (CORE_ADDR pc, int frameless_p)
|
735 |
|
|
{
|
736 |
|
|
struct frame_info fi;
|
737 |
|
|
static struct frame_extra_info fei;
|
738 |
|
|
struct symtab_and_line sal = find_pc_line (pc, 0);
|
739 |
|
|
int best_limit;
|
740 |
|
|
CORE_ADDR pc_after_prologue;
|
741 |
|
|
|
742 |
|
|
/* frame_info now contains dynamic memory. Since fi is a dummy here,
|
743 |
|
|
I use static memory for extra_info, and don't bother allocating
|
744 |
|
|
memory for saved_regs. */
|
745 |
|
|
fi.saved_regs = 0;
|
746 |
|
|
fi.extra_info = &fei;
|
747 |
|
|
|
748 |
|
|
/* If there is no symbol information then sal.end == 0, and we end up
|
749 |
|
|
examining only the first instruction in the function prologue.
|
750 |
|
|
Exaggerating the limit seems to be harmless. */
|
751 |
|
|
if (sal.end > 0)
|
752 |
|
|
best_limit = sal.end;
|
753 |
|
|
else
|
754 |
|
|
best_limit = pc + 100;
|
755 |
|
|
|
756 |
|
|
pc_after_prologue = cris_examine (pc, best_limit, &fi, frameless_p);
|
757 |
|
|
return pc_after_prologue;
|
758 |
|
|
}
|
759 |
|
|
|
760 |
|
|
/* Use the program counter to determine the contents and size of a breakpoint
|
761 |
|
|
instruction. It returns a pointer to a string of bytes that encode a
|
762 |
|
|
breakpoint instruction, stores the length of the string to *lenptr, and
|
763 |
|
|
adjusts pcptr (if necessary) to point to the actual memory location where
|
764 |
|
|
the breakpoint should be inserted. */
|
765 |
|
|
|
766 |
|
|
const unsigned char *
|
767 |
|
|
cris_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
|
768 |
|
|
{
|
769 |
|
|
static unsigned char break_insn[] = {0x38, 0xe9};
|
770 |
|
|
*lenptr = 2;
|
771 |
|
|
|
772 |
|
|
return break_insn;
|
773 |
|
|
}
|
774 |
|
|
|
775 |
|
|
/* Returns the register SRP (subroutine return pointer) which must contain
|
776 |
|
|
the content of the register PC after a function call. */
|
777 |
|
|
|
778 |
|
|
static CORE_ADDR
|
779 |
|
|
cris_saved_pc_after_call (struct frame_info *frame)
|
780 |
|
|
{
|
781 |
|
|
return read_register (SRP_REGNUM);
|
782 |
|
|
}
|
783 |
|
|
|
784 |
|
|
/* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version,
|
785 |
|
|
|
786 |
|
|
|
787 |
|
|
int
|
788 |
|
|
cris_spec_reg_applicable (struct cris_spec_reg spec_reg)
|
789 |
|
|
{
|
790 |
|
|
int version = cris_version ();
|
791 |
|
|
|
792 |
|
|
switch (spec_reg.applicable_version)
|
793 |
|
|
{
|
794 |
|
|
case cris_ver_version_all:
|
795 |
|
|
return 1;
|
796 |
|
|
case cris_ver_warning:
|
797 |
|
|
/* Indeterminate/obsolete. */
|
798 |
|
|
return 0;
|
799 |
|
|
case cris_ver_sim:
|
800 |
|
|
/* Simulator only. */
|
801 |
|
|
return 0;
|
802 |
|
|
case cris_ver_v0_3:
|
803 |
|
|
return (version >= 0 && version <= 3);
|
804 |
|
|
case cris_ver_v3p:
|
805 |
|
|
return (version >= 3);
|
806 |
|
|
case cris_ver_v8:
|
807 |
|
|
return (version == 8 || version == 9);
|
808 |
|
|
case cris_ver_v8p:
|
809 |
|
|
return (version >= 8);
|
810 |
|
|
case cris_ver_v10p:
|
811 |
|
|
return (version >= 10);
|
812 |
|
|
default:
|
813 |
|
|
/* Invalid cris version. */
|
814 |
|
|
return 0;
|
815 |
|
|
}
|
816 |
|
|
}
|
817 |
|
|
|
818 |
|
|
/* Returns the register size in unit byte. Returns 0 for an unimplemented
|
819 |
|
|
register, -1 for an invalid register. */
|
820 |
|
|
|
821 |
|
|
int
|
822 |
|
|
cris_register_size (int regno)
|
823 |
|
|
{
|
824 |
|
|
int i;
|
825 |
|
|
int spec_regno;
|
826 |
|
|
|
827 |
|
|
if (regno >= 0 && regno < NUM_GENREGS)
|
828 |
|
|
{
|
829 |
|
|
/* General registers (R0 - R15) are 32 bits. */
|
830 |
|
|
return 4;
|
831 |
|
|
}
|
832 |
|
|
else if (regno >= NUM_GENREGS && regno < NUM_REGS)
|
833 |
|
|
{
|
834 |
|
|
/* Special register (R16 - R31). cris_spec_regs is zero-based.
|
835 |
|
|
Adjust regno accordingly. */
|
836 |
|
|
spec_regno = regno - NUM_GENREGS;
|
837 |
|
|
|
838 |
|
|
/* The entries in cris_spec_regs are stored in register number order,
|
839 |
|
|
which means we can shortcut into the array when searching it. */
|
840 |
|
|
for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
|
841 |
|
|
{
|
842 |
|
|
if (cris_spec_regs[i].number == spec_regno
|
843 |
|
|
&& cris_spec_reg_applicable (cris_spec_regs[i]))
|
844 |
|
|
/* Go with the first applicable register. */
|
845 |
|
|
return cris_spec_regs[i].reg_size;
|
846 |
|
|
}
|
847 |
|
|
/* Special register not applicable to this CRIS version. */
|
848 |
|
|
return 0;
|
849 |
|
|
}
|
850 |
|
|
else
|
851 |
|
|
{
|
852 |
|
|
/* Invalid register. */
|
853 |
|
|
return -1;
|
854 |
|
|
}
|
855 |
|
|
}
|
856 |
|
|
|
857 |
|
|
/* Nonzero if regno should not be fetched from the target. This is the case
|
858 |
|
|
for unimplemented (size 0) and non-existant registers. */
|
859 |
|
|
|
860 |
|
|
int
|
861 |
|
|
cris_cannot_fetch_register (int regno)
|
862 |
|
|
{
|
863 |
|
|
return ((regno < 0 || regno >= NUM_REGS)
|
864 |
|
|
|| (cris_register_size (regno) == 0));
|
865 |
|
|
}
|
866 |
|
|
|
867 |
|
|
/* Nonzero if regno should not be written to the target, for various
|
868 |
|
|
reasons. */
|
869 |
|
|
|
870 |
|
|
int
|
871 |
|
|
cris_cannot_store_register (int regno)
|
872 |
|
|
{
|
873 |
|
|
/* There are three kinds of registers we refuse to write to.
|
874 |
|
|
1. Those that not implemented.
|
875 |
|
|
2. Those that are read-only (depends on the processor mode).
|
876 |
|
|
3. Those registers to which a write has no effect.
|
877 |
|
|
*/
|
878 |
|
|
|
879 |
|
|
if (regno < 0 || regno >= NUM_REGS || cris_register_size (regno) == 0)
|
880 |
|
|
/* Not implemented. */
|
881 |
|
|
return 1;
|
882 |
|
|
|
883 |
|
|
else if (regno == VR_REGNUM)
|
884 |
|
|
/* Read-only. */
|
885 |
|
|
return 1;
|
886 |
|
|
|
887 |
|
|
else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM)
|
888 |
|
|
/* Writing has no effect. */
|
889 |
|
|
return 1;
|
890 |
|
|
|
891 |
|
|
else if (cris_mode () == CRIS_MODE_USER)
|
892 |
|
|
{
|
893 |
|
|
if (regno == IBR_REGNUM || regno == BAR_REGNUM || regno == BRP_REGNUM
|
894 |
|
|
|| regno == IRP_REGNUM)
|
895 |
|
|
/* Read-only in user mode. */
|
896 |
|
|
return 1;
|
897 |
|
|
}
|
898 |
|
|
|
899 |
|
|
return 0;
|
900 |
|
|
}
|
901 |
|
|
|
902 |
|
|
/* Returns the register offset for the first byte of register regno's space
|
903 |
|
|
in the saved register state. Returns -1 for an invalid or unimplemented
|
904 |
|
|
register. */
|
905 |
|
|
|
906 |
|
|
int
|
907 |
|
|
cris_register_offset (int regno)
|
908 |
|
|
{
|
909 |
|
|
int i;
|
910 |
|
|
int reg_size;
|
911 |
|
|
int offset = 0;
|
912 |
|
|
|
913 |
|
|
if (regno >= 0 && regno < NUM_REGS)
|
914 |
|
|
{
|
915 |
|
|
/* FIXME: The offsets should be cached and calculated only once,
|
916 |
|
|
when the architecture being debugged has changed. */
|
917 |
|
|
for (i = 0; i < regno; i++)
|
918 |
|
|
offset += cris_register_size (i);
|
919 |
|
|
|
920 |
|
|
return offset;
|
921 |
|
|
}
|
922 |
|
|
else
|
923 |
|
|
{
|
924 |
|
|
/* Invalid register. */
|
925 |
|
|
return -1;
|
926 |
|
|
}
|
927 |
|
|
}
|
928 |
|
|
|
929 |
|
|
/* Return the GDB type (defined in gdbtypes.c) for the "standard" data type
|
930 |
|
|
of data in register regno. */
|
931 |
|
|
|
932 |
|
|
struct type *
|
933 |
|
|
cris_register_virtual_type (int regno)
|
934 |
|
|
{
|
935 |
|
|
if (regno == SP_REGNUM || regno == PC_REGNUM
|
936 |
|
|
|| (regno > P8_REGNUM && regno < USP_REGNUM))
|
937 |
|
|
{
|
938 |
|
|
/* SP, PC, IBR, IRP, SRP, BAR, DCCR, BRP */
|
939 |
|
|
return lookup_pointer_type (builtin_type_void);
|
940 |
|
|
}
|
941 |
|
|
else if (regno == P8_REGNUM || regno == USP_REGNUM
|
942 |
|
|
|| (regno >= 0 && regno < SP_REGNUM))
|
943 |
|
|
{
|
944 |
|
|
/* R0 - R13, P8, P15 */
|
945 |
|
|
return builtin_type_unsigned_long;
|
946 |
|
|
}
|
947 |
|
|
else if (regno > P3_REGNUM && regno < P8_REGNUM)
|
948 |
|
|
{
|
949 |
|
|
/* P4, CCR, DCR0, DCR1 */
|
950 |
|
|
return builtin_type_unsigned_short;
|
951 |
|
|
}
|
952 |
|
|
else if (regno > PC_REGNUM && regno < P4_REGNUM)
|
953 |
|
|
{
|
954 |
|
|
/* P0, P1, P2, P3 */
|
955 |
|
|
return builtin_type_unsigned_char;
|
956 |
|
|
}
|
957 |
|
|
else
|
958 |
|
|
{
|
959 |
|
|
/* Invalid register. */
|
960 |
|
|
return builtin_type_void;
|
961 |
|
|
}
|
962 |
|
|
}
|
963 |
|
|
|
964 |
|
|
/* Stores a function return value of type type, where valbuf is the address
|
965 |
|
|
of the value to be stored. */
|
966 |
|
|
|
967 |
|
|
/* In the original CRIS ABI, R10 is used to store return values. */
|
968 |
|
|
|
969 |
|
|
void
|
970 |
|
|
cris_abi_original_store_return_value (struct type *type, char *valbuf)
|
971 |
|
|
{
|
972 |
|
|
int len = TYPE_LENGTH (type);
|
973 |
|
|
|
974 |
|
|
if (len <= REGISTER_SIZE)
|
975 |
|
|
write_register_bytes (REGISTER_BYTE (RET_REGNUM), valbuf, len);
|
976 |
|
|
else
|
977 |
|
|
internal_error (__FILE__, __LINE__, "cris_abi_original_store_return_value: type length too large.");
|
978 |
|
|
}
|
979 |
|
|
|
980 |
|
|
/* In the CRIS ABI V2, R10 and R11 are used to store return values. */
|
981 |
|
|
|
982 |
|
|
void
|
983 |
|
|
cris_abi_v2_store_return_value (struct type *type, char *valbuf)
|
984 |
|
|
{
|
985 |
|
|
int len = TYPE_LENGTH (type);
|
986 |
|
|
|
987 |
|
|
if (len <= 2 * REGISTER_SIZE)
|
988 |
|
|
{
|
989 |
|
|
/* Note that this works since R10 and R11 are consecutive registers. */
|
990 |
|
|
write_register_bytes (REGISTER_BYTE (RET_REGNUM), valbuf, len);
|
991 |
|
|
}
|
992 |
|
|
else
|
993 |
|
|
internal_error (__FILE__, __LINE__, "cris_abi_v2_store_return_value: type length too large.");
|
994 |
|
|
}
|
995 |
|
|
|
996 |
|
|
/* Return the name of register regno as a string. Return NULL for an invalid or
|
997 |
|
|
unimplemented register. */
|
998 |
|
|
|
999 |
|
|
const char *
|
1000 |
|
|
cris_register_name (int regno)
|
1001 |
|
|
{
|
1002 |
|
|
static char *cris_genreg_names[] =
|
1003 |
|
|
{ "r0", "r1", "r2", "r3", \
|
1004 |
|
|
"r4", "r5", "r6", "r7", \
|
1005 |
|
|
"r8", "r9", "r10", "r11", \
|
1006 |
|
|
"r12", "r13", "sp", "pc" };
|
1007 |
|
|
|
1008 |
|
|
int i;
|
1009 |
|
|
int spec_regno;
|
1010 |
|
|
|
1011 |
|
|
if (regno >= 0 && regno < NUM_GENREGS)
|
1012 |
|
|
{
|
1013 |
|
|
/* General register. */
|
1014 |
|
|
return cris_genreg_names[regno];
|
1015 |
|
|
}
|
1016 |
|
|
else if (regno >= NUM_GENREGS && regno < NUM_REGS)
|
1017 |
|
|
{
|
1018 |
|
|
/* Special register (R16 - R31). cris_spec_regs is zero-based.
|
1019 |
|
|
Adjust regno accordingly. */
|
1020 |
|
|
spec_regno = regno - NUM_GENREGS;
|
1021 |
|
|
|
1022 |
|
|
/* The entries in cris_spec_regs are stored in register number order,
|
1023 |
|
|
which means we can shortcut into the array when searching it. */
|
1024 |
|
|
for (i = spec_regno; cris_spec_regs[i].name != NULL; i++)
|
1025 |
|
|
{
|
1026 |
|
|
if (cris_spec_regs[i].number == spec_regno
|
1027 |
|
|
&& cris_spec_reg_applicable (cris_spec_regs[i]))
|
1028 |
|
|
/* Go with the first applicable register. */
|
1029 |
|
|
return cris_spec_regs[i].name;
|
1030 |
|
|
}
|
1031 |
|
|
/* Special register not applicable to this CRIS version. */
|
1032 |
|
|
return NULL;
|
1033 |
|
|
}
|
1034 |
|
|
else
|
1035 |
|
|
{
|
1036 |
|
|
/* Invalid register. */
|
1037 |
|
|
return NULL;
|
1038 |
|
|
}
|
1039 |
|
|
}
|
1040 |
|
|
|
1041 |
|
|
int
|
1042 |
|
|
cris_register_bytes_ok (long bytes)
|
1043 |
|
|
{
|
1044 |
|
|
return (bytes == REGISTER_BYTES);
|
1045 |
|
|
}
|
1046 |
|
|
|
1047 |
|
|
/* Extract from an array regbuf containing the raw register state a function
|
1048 |
|
|
return value of type type, and copy that, in virtual format, into
|
1049 |
|
|
valbuf. */
|
1050 |
|
|
|
1051 |
|
|
/* In the original CRIS ABI, R10 is used to return values. */
|
1052 |
|
|
|
1053 |
|
|
void
|
1054 |
|
|
cris_abi_original_extract_return_value (struct type *type, char *regbuf,
|
1055 |
|
|
char *valbuf)
|
1056 |
|
|
{
|
1057 |
|
|
int len = TYPE_LENGTH (type);
|
1058 |
|
|
|
1059 |
|
|
if (len <= REGISTER_SIZE)
|
1060 |
|
|
memcpy (valbuf, regbuf + REGISTER_BYTE (RET_REGNUM), len);
|
1061 |
|
|
else
|
1062 |
|
|
internal_error (__FILE__, __LINE__, "cris_abi_original_extract_return_value: type length too large");
|
1063 |
|
|
}
|
1064 |
|
|
|
1065 |
|
|
/* In the CRIS ABI V2, R10 and R11 are used to store return values. */
|
1066 |
|
|
|
1067 |
|
|
void
|
1068 |
|
|
cris_abi_v2_extract_return_value (struct type *type, char *regbuf,
|
1069 |
|
|
char *valbuf)
|
1070 |
|
|
{
|
1071 |
|
|
int len = TYPE_LENGTH (type);
|
1072 |
|
|
|
1073 |
|
|
if (len <= 2 * REGISTER_SIZE)
|
1074 |
|
|
memcpy (valbuf, regbuf + REGISTER_BYTE (RET_REGNUM), len);
|
1075 |
|
|
else
|
1076 |
|
|
internal_error (__FILE__, __LINE__, "cris_abi_v2_extract_return_value: type length too large");
|
1077 |
|
|
}
|
1078 |
|
|
|
1079 |
|
|
/* Store the address of the place in which to copy the structure the
|
1080 |
|
|
subroutine will return. In the CRIS ABI, R9 is used in order to pass
|
1081 |
|
|
the address of the allocated area where a structure return value must
|
1082 |
|
|
be stored. R9 is call-clobbered, which means we must save it here for
|
1083 |
|
|
later use. */
|
1084 |
|
|
|
1085 |
|
|
void
|
1086 |
|
|
cris_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
|
1087 |
|
|
{
|
1088 |
|
|
write_register (STR_REGNUM, addr);
|
1089 |
|
|
struct_return_address = addr;
|
1090 |
|
|
}
|
1091 |
|
|
|
1092 |
|
|
/* Extract from regbuf the address where a function should return a
|
1093 |
|
|
structure value. It's not there in the CRIS ABI, so we must do it another
|
1094 |
|
|
way. */
|
1095 |
|
|
|
1096 |
|
|
CORE_ADDR
|
1097 |
|
|
cris_extract_struct_value_address (char *regbuf)
|
1098 |
|
|
{
|
1099 |
|
|
return struct_return_address;
|
1100 |
|
|
}
|
1101 |
|
|
|
1102 |
|
|
/* Returns 1 if a value of the given type being returned from a function
|
1103 |
|
|
must have space allocated for it on the stack. gcc_p is true if the
|
1104 |
|
|
function being considered is known to have been compiled by GCC.
|
1105 |
|
|
In the CRIS ABI, structure return values are passed to the called
|
1106 |
|
|
function by reference in register R9 to a caller-allocated area, so
|
1107 |
|
|
this is always true. */
|
1108 |
|
|
|
1109 |
|
|
int
|
1110 |
|
|
cris_use_struct_convention (int gcc_p, struct type *type)
|
1111 |
|
|
{
|
1112 |
|
|
return 1;
|
1113 |
|
|
}
|
1114 |
|
|
|
1115 |
|
|
/* Returns 1 if the given type will be passed by pointer rather than
|
1116 |
|
|
directly. */
|
1117 |
|
|
|
1118 |
|
|
/* In the original CRIS ABI, arguments shorter than or equal to 32 bits are
|
1119 |
|
|
passed by value. */
|
1120 |
|
|
|
1121 |
|
|
int
|
1122 |
|
|
cris_abi_original_reg_struct_has_addr (int gcc_p, struct type *type)
|
1123 |
|
|
{
|
1124 |
|
|
return (TYPE_LENGTH (type) > 4);
|
1125 |
|
|
}
|
1126 |
|
|
|
1127 |
|
|
/* In the CRIS ABI V2, arguments shorter than or equal to 64 bits are passed
|
1128 |
|
|
by value. */
|
1129 |
|
|
|
1130 |
|
|
int
|
1131 |
|
|
cris_abi_v2_reg_struct_has_addr (int gcc_p, struct type *type)
|
1132 |
|
|
{
|
1133 |
|
|
return (TYPE_LENGTH (type) > 8);
|
1134 |
|
|
}
|
1135 |
|
|
|
1136 |
|
|
/* Returns 1 if the function invocation represented by fi does not have a
|
1137 |
|
|
stack frame associated with it. Otherwise return 0. */
|
1138 |
|
|
|
1139 |
|
|
int
|
1140 |
|
|
cris_frameless_function_invocation (struct frame_info *fi)
|
1141 |
|
|
{
|
1142 |
|
|
if (fi->signal_handler_caller)
|
1143 |
|
|
return 0;
|
1144 |
|
|
else
|
1145 |
|
|
return frameless_look_for_prologue (fi);
|
1146 |
|
|
}
|
1147 |
|
|
|
1148 |
|
|
/* See frame.h. Determines the address of all registers in the current stack
|
1149 |
|
|
frame storing each in frame->saved_regs. Space for frame->saved_regs shall
|
1150 |
|
|
be allocated by FRAME_INIT_SAVED_REGS using either frame_saved_regs_zalloc
|
1151 |
|
|
or frame_obstack_alloc. */
|
1152 |
|
|
|
1153 |
|
|
void
|
1154 |
|
|
cris_frame_init_saved_regs (struct frame_info *fi)
|
1155 |
|
|
{
|
1156 |
|
|
CORE_ADDR ip;
|
1157 |
|
|
struct symtab_and_line sal;
|
1158 |
|
|
int best_limit;
|
1159 |
|
|
char *dummy_regs = deprecated_generic_find_dummy_frame (fi->pc, fi->frame);
|
1160 |
|
|
|
1161 |
|
|
/* Examine the entire prologue. */
|
1162 |
|
|
register int frameless_p = 0;
|
1163 |
|
|
|
1164 |
|
|
/* Has this frame's registers already been initialized? */
|
1165 |
|
|
if (fi->saved_regs)
|
1166 |
|
|
return;
|
1167 |
|
|
|
1168 |
|
|
frame_saved_regs_zalloc (fi);
|
1169 |
|
|
|
1170 |
|
|
if (dummy_regs)
|
1171 |
|
|
{
|
1172 |
|
|
/* I don't see this ever happening, considering the context in which
|
1173 |
|
|
cris_frame_init_saved_regs is called (always when we're not in
|
1174 |
|
|
a dummy frame). */
|
1175 |
|
|
memcpy (&fi->saved_regs, dummy_regs, sizeof (fi->saved_regs));
|
1176 |
|
|
}
|
1177 |
|
|
else
|
1178 |
|
|
{
|
1179 |
|
|
ip = get_pc_function_start (fi->pc);
|
1180 |
|
|
sal = find_pc_line (ip, 0);
|
1181 |
|
|
|
1182 |
|
|
/* If there is no symbol information then sal.end == 0, and we end up
|
1183 |
|
|
examining only the first instruction in the function prologue.
|
1184 |
|
|
Exaggerating the limit seems to be harmless. */
|
1185 |
|
|
if (sal.end > 0)
|
1186 |
|
|
best_limit = sal.end;
|
1187 |
|
|
else
|
1188 |
|
|
best_limit = ip + 100;
|
1189 |
|
|
|
1190 |
|
|
cris_examine (ip, best_limit, fi, frameless_p);
|
1191 |
|
|
}
|
1192 |
|
|
}
|
1193 |
|
|
|
1194 |
|
|
/* Initialises the extra frame information at the creation of a new frame.
|
1195 |
|
|
The inparameter fromleaf is 0 when the call is from create_new_frame.
|
1196 |
|
|
When the call is from get_prev_frame_info, fromleaf is determined by
|
1197 |
|
|
cris_frameless_function_invocation. */
|
1198 |
|
|
|
1199 |
|
|
void
|
1200 |
|
|
cris_init_extra_frame_info (int fromleaf, struct frame_info *fi)
|
1201 |
|
|
{
|
1202 |
|
|
if (fi->next)
|
1203 |
|
|
{
|
1204 |
|
|
/* Called from get_prev_frame. */
|
1205 |
|
|
fi->pc = FRAME_SAVED_PC (fi->next);
|
1206 |
|
|
}
|
1207 |
|
|
|
1208 |
|
|
fi->extra_info = (struct frame_extra_info *)
|
1209 |
|
|
frame_obstack_alloc (sizeof (struct frame_extra_info));
|
1210 |
|
|
|
1211 |
|
|
fi->extra_info->return_pc = 0;
|
1212 |
|
|
fi->extra_info->leaf_function = 0;
|
1213 |
|
|
|
1214 |
|
|
if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
|
1215 |
|
|
{
|
1216 |
|
|
/* We need to setup fi->frame here because run_stack_dummy gets it wrong
|
1217 |
|
|
by assuming it's always FP. */
|
1218 |
|
|
fi->frame = generic_read_register_dummy (fi->pc, fi->frame, SP_REGNUM);
|
1219 |
|
|
fi->extra_info->return_pc =
|
1220 |
|
|
generic_read_register_dummy (fi->pc, fi->frame, PC_REGNUM);
|
1221 |
|
|
|
1222 |
|
|
/* FIXME: Is this necessarily true? */
|
1223 |
|
|
fi->extra_info->leaf_function = 0;
|
1224 |
|
|
}
|
1225 |
|
|
else
|
1226 |
|
|
{
|
1227 |
|
|
cris_frame_init_saved_regs (fi);
|
1228 |
|
|
|
1229 |
|
|
/* Check fromleaf/frameless_function_invocation. (FIXME) */
|
1230 |
|
|
|
1231 |
|
|
if (fi->saved_regs[SRP_REGNUM] != 0)
|
1232 |
|
|
{
|
1233 |
|
|
/* SRP was saved on the stack; non-leaf function. */
|
1234 |
|
|
fi->extra_info->return_pc =
|
1235 |
|
|
read_memory_integer (fi->saved_regs[SRP_REGNUM],
|
1236 |
|
|
REGISTER_RAW_SIZE (SRP_REGNUM));
|
1237 |
|
|
}
|
1238 |
|
|
else
|
1239 |
|
|
{
|
1240 |
|
|
/* SRP is still in a register; leaf function. */
|
1241 |
|
|
fi->extra_info->return_pc = read_register (SRP_REGNUM);
|
1242 |
|
|
/* FIXME: Should leaf_function be set to 1 here? */
|
1243 |
|
|
fi->extra_info->leaf_function = 1;
|
1244 |
|
|
}
|
1245 |
|
|
}
|
1246 |
|
|
}
|
1247 |
|
|
|
1248 |
|
|
/* Return the content of the frame pointer in the present frame. In other
|
1249 |
|
|
words, determine the address of the calling function's frame. */
|
1250 |
|
|
|
1251 |
|
|
CORE_ADDR
|
1252 |
|
|
cris_frame_chain (struct frame_info *fi)
|
1253 |
|
|
{
|
1254 |
|
|
if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
|
1255 |
|
|
{
|
1256 |
|
|
return fi->frame;
|
1257 |
|
|
}
|
1258 |
|
|
else if (!inside_entry_file (fi->pc))
|
1259 |
|
|
{
|
1260 |
|
|
return read_memory_unsigned_integer (FRAME_FP (fi), 4);
|
1261 |
|
|
}
|
1262 |
|
|
else
|
1263 |
|
|
{
|
1264 |
|
|
return 0;
|
1265 |
|
|
}
|
1266 |
|
|
}
|
1267 |
|
|
|
1268 |
|
|
/* Return the saved PC (which equals the return address) of this frame. */
|
1269 |
|
|
|
1270 |
|
|
CORE_ADDR
|
1271 |
|
|
cris_frame_saved_pc (struct frame_info *fi)
|
1272 |
|
|
{
|
1273 |
|
|
return fi->extra_info->return_pc;
|
1274 |
|
|
}
|
1275 |
|
|
|
1276 |
|
|
/* Return the address of the argument block for the frame described
|
1277 |
|
|
by struct frame_info. */
|
1278 |
|
|
|
1279 |
|
|
CORE_ADDR
|
1280 |
|
|
cris_frame_args_address (struct frame_info *fi)
|
1281 |
|
|
{
|
1282 |
|
|
return FRAME_FP (fi);
|
1283 |
|
|
}
|
1284 |
|
|
|
1285 |
|
|
/* Return the address of the locals block for the frame
|
1286 |
|
|
described by struct frame_info. */
|
1287 |
|
|
|
1288 |
|
|
CORE_ADDR
|
1289 |
|
|
cris_frame_locals_address (struct frame_info *fi)
|
1290 |
|
|
{
|
1291 |
|
|
return FRAME_FP (fi);
|
1292 |
|
|
}
|
1293 |
|
|
|
1294 |
|
|
/* Setup the function arguments for calling a function in the inferior. */
|
1295 |
|
|
|
1296 |
|
|
CORE_ADDR
|
1297 |
|
|
cris_abi_original_push_arguments (int nargs, struct value **args,
|
1298 |
|
|
CORE_ADDR sp, int struct_return,
|
1299 |
|
|
CORE_ADDR struct_addr)
|
1300 |
|
|
{
|
1301 |
|
|
int stack_alloc;
|
1302 |
|
|
int stack_offset;
|
1303 |
|
|
int argreg;
|
1304 |
|
|
int argnum;
|
1305 |
|
|
struct type *type;
|
1306 |
|
|
int len;
|
1307 |
|
|
CORE_ADDR regval;
|
1308 |
|
|
char *val;
|
1309 |
|
|
|
1310 |
|
|
/* Data and parameters reside in different areas on the stack.
|
1311 |
|
|
Both frame pointers grow toward higher addresses. */
|
1312 |
|
|
CORE_ADDR fp_params;
|
1313 |
|
|
CORE_ADDR fp_data;
|
1314 |
|
|
|
1315 |
|
|
/* Are we returning a value using a structure return or a normal value
|
1316 |
|
|
return? struct_addr is the address of the reserved space for the return
|
1317 |
|
|
structure to be written on the stack. */
|
1318 |
|
|
if (struct_return)
|
1319 |
|
|
{
|
1320 |
|
|
write_register (STR_REGNUM, struct_addr);
|
1321 |
|
|
}
|
1322 |
|
|
|
1323 |
|
|
/* Make sure there's space on the stack. Allocate space for data and a
|
1324 |
|
|
parameter to refer to that data. */
|
1325 |
|
|
for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
|
1326 |
|
|
stack_alloc += (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + REGISTER_SIZE);
|
1327 |
|
|
sp -= stack_alloc;
|
1328 |
|
|
/* We may over-allocate a little here, but that won't hurt anything. */
|
1329 |
|
|
|
1330 |
|
|
/* Initialize stack frame pointers. */
|
1331 |
|
|
fp_params = sp;
|
1332 |
|
|
fp_data = sp + (nargs * REGISTER_SIZE);
|
1333 |
|
|
|
1334 |
|
|
/* Now load as many as possible of the first arguments into
|
1335 |
|
|
registers, and push the rest onto the stack. */
|
1336 |
|
|
argreg = ARG1_REGNUM;
|
1337 |
|
|
stack_offset = 0;
|
1338 |
|
|
|
1339 |
|
|
for (argnum = 0; argnum < nargs; argnum++)
|
1340 |
|
|
{
|
1341 |
|
|
type = VALUE_TYPE (args[argnum]);
|
1342 |
|
|
len = TYPE_LENGTH (type);
|
1343 |
|
|
val = (char *) VALUE_CONTENTS (args[argnum]);
|
1344 |
|
|
|
1345 |
|
|
if (len <= REGISTER_SIZE && argreg <= ARG4_REGNUM)
|
1346 |
|
|
{
|
1347 |
|
|
/* Data fits in a register; put it in the first available
|
1348 |
|
|
register. */
|
1349 |
|
|
write_register (argreg, *(unsigned long *) val);
|
1350 |
|
|
argreg++;
|
1351 |
|
|
}
|
1352 |
|
|
else if (len > REGISTER_SIZE && argreg <= ARG4_REGNUM)
|
1353 |
|
|
{
|
1354 |
|
|
/* Data does not fit in register; pass it on the stack and
|
1355 |
|
|
put its address in the first available register. */
|
1356 |
|
|
write_memory (fp_data, val, len);
|
1357 |
|
|
write_register (argreg, fp_data);
|
1358 |
|
|
fp_data += len;
|
1359 |
|
|
argreg++;
|
1360 |
|
|
}
|
1361 |
|
|
else if (len > REGISTER_SIZE)
|
1362 |
|
|
{
|
1363 |
|
|
/* Data does not fit in register; put both data and
|
1364 |
|
|
parameter on the stack. */
|
1365 |
|
|
write_memory (fp_data, val, len);
|
1366 |
|
|
write_memory (fp_params, (char *) (&fp_data), REGISTER_SIZE);
|
1367 |
|
|
fp_data += len;
|
1368 |
|
|
fp_params += REGISTER_SIZE;
|
1369 |
|
|
}
|
1370 |
|
|
else
|
1371 |
|
|
{
|
1372 |
|
|
/* Data fits in a register, but we are out of registers;
|
1373 |
|
|
put the parameter on the stack. */
|
1374 |
|
|
write_memory (fp_params, val, REGISTER_SIZE);
|
1375 |
|
|
fp_params += REGISTER_SIZE;
|
1376 |
|
|
}
|
1377 |
|
|
}
|
1378 |
|
|
|
1379 |
|
|
return sp;
|
1380 |
|
|
}
|
1381 |
|
|
|
1382 |
|
|
CORE_ADDR
|
1383 |
|
|
cris_abi_v2_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
|
1384 |
|
|
int struct_return, CORE_ADDR struct_addr)
|
1385 |
|
|
{
|
1386 |
|
|
int stack_alloc;
|
1387 |
|
|
int stack_offset;
|
1388 |
|
|
int argreg;
|
1389 |
|
|
int argnum;
|
1390 |
|
|
|
1391 |
|
|
CORE_ADDR regval;
|
1392 |
|
|
|
1393 |
|
|
/* The function's arguments and memory allocated by gdb for the arguments to
|
1394 |
|
|
point at reside in separate areas on the stack.
|
1395 |
|
|
Both frame pointers grow toward higher addresses. */
|
1396 |
|
|
CORE_ADDR fp_arg;
|
1397 |
|
|
CORE_ADDR fp_mem;
|
1398 |
|
|
|
1399 |
|
|
/* Are we returning a value using a structure return or a normal value
|
1400 |
|
|
return? struct_addr is the address of the reserved space for the return
|
1401 |
|
|
structure to be written on the stack. */
|
1402 |
|
|
if (struct_return)
|
1403 |
|
|
{
|
1404 |
|
|
write_register (STR_REGNUM, struct_addr);
|
1405 |
|
|
}
|
1406 |
|
|
|
1407 |
|
|
/* Allocate enough to keep things word-aligned on both parts of the
|
1408 |
|
|
stack. */
|
1409 |
|
|
stack_alloc = 0;
|
1410 |
|
|
for (argnum = 0; argnum < nargs; argnum++)
|
1411 |
|
|
{
|
1412 |
|
|
int len;
|
1413 |
|
|
int reg_demand;
|
1414 |
|
|
|
1415 |
|
|
len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
|
1416 |
|
|
reg_demand = (len / REGISTER_SIZE) + (len % REGISTER_SIZE != 0 ? 1 : 0);
|
1417 |
|
|
|
1418 |
|
|
/* reg_demand * REGISTER_SIZE is the amount of memory we might need to
|
1419 |
|
|
allocate for this argument. 2 * REGISTER_SIZE is the amount of stack
|
1420 |
|
|
space we might need to pass the argument itself (either by value or by
|
1421 |
|
|
reference). */
|
1422 |
|
|
stack_alloc += (reg_demand * REGISTER_SIZE + 2 * REGISTER_SIZE);
|
1423 |
|
|
}
|
1424 |
|
|
sp -= stack_alloc;
|
1425 |
|
|
/* We may over-allocate a little here, but that won't hurt anything. */
|
1426 |
|
|
|
1427 |
|
|
/* Initialize frame pointers. */
|
1428 |
|
|
fp_arg = sp;
|
1429 |
|
|
fp_mem = sp + (nargs * (2 * REGISTER_SIZE));
|
1430 |
|
|
|
1431 |
|
|
/* Now load as many as possible of the first arguments into registers,
|
1432 |
|
|
and push the rest onto the stack. */
|
1433 |
|
|
argreg = ARG1_REGNUM;
|
1434 |
|
|
stack_offset = 0;
|
1435 |
|
|
|
1436 |
|
|
for (argnum = 0; argnum < nargs; argnum++)
|
1437 |
|
|
{
|
1438 |
|
|
int len;
|
1439 |
|
|
char *val;
|
1440 |
|
|
int reg_demand;
|
1441 |
|
|
int i;
|
1442 |
|
|
|
1443 |
|
|
len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
|
1444 |
|
|
val = (char *) VALUE_CONTENTS (args[argnum]);
|
1445 |
|
|
|
1446 |
|
|
/* How may registers worth of storage do we need for this argument? */
|
1447 |
|
|
reg_demand = (len / REGISTER_SIZE) + (len % REGISTER_SIZE != 0 ? 1 : 0);
|
1448 |
|
|
|
1449 |
|
|
if (len <= (2 * REGISTER_SIZE)
|
1450 |
|
|
&& (argreg + reg_demand - 1 <= ARG4_REGNUM))
|
1451 |
|
|
{
|
1452 |
|
|
/* Data passed by value. Fits in available register(s). */
|
1453 |
|
|
for (i = 0; i < reg_demand; i++)
|
1454 |
|
|
{
|
1455 |
|
|
write_register (argreg, *(unsigned long *) val);
|
1456 |
|
|
argreg++;
|
1457 |
|
|
val += REGISTER_SIZE;
|
1458 |
|
|
}
|
1459 |
|
|
}
|
1460 |
|
|
else if (len <= (2 * REGISTER_SIZE) && argreg <= ARG4_REGNUM)
|
1461 |
|
|
{
|
1462 |
|
|
/* Data passed by value. Does not fit in available register(s).
|
1463 |
|
|
Use the register(s) first, then the stack. */
|
1464 |
|
|
for (i = 0; i < reg_demand; i++)
|
1465 |
|
|
{
|
1466 |
|
|
if (argreg <= ARG4_REGNUM)
|
1467 |
|
|
{
|
1468 |
|
|
write_register (argreg, *(unsigned long *) val);
|
1469 |
|
|
argreg++;
|
1470 |
|
|
val += REGISTER_SIZE;
|
1471 |
|
|
}
|
1472 |
|
|
else
|
1473 |
|
|
{
|
1474 |
|
|
/* I guess this memory write could write the remaining data
|
1475 |
|
|
all at once instead of in REGISTER_SIZE chunks. */
|
1476 |
|
|
write_memory (fp_arg, val, REGISTER_SIZE);
|
1477 |
|
|
fp_arg += REGISTER_SIZE;
|
1478 |
|
|
val += REGISTER_SIZE;
|
1479 |
|
|
}
|
1480 |
|
|
}
|
1481 |
|
|
}
|
1482 |
|
|
else if (len > (2 * REGISTER_SIZE))
|
1483 |
|
|
{
|
1484 |
|
|
/* Data passed by reference. Put it on the stack. */
|
1485 |
|
|
write_memory (fp_mem, val, len);
|
1486 |
|
|
write_memory (fp_arg, (char *) (&fp_mem), REGISTER_SIZE);
|
1487 |
|
|
|
1488 |
|
|
/* fp_mem need not be word-aligned since it's just a chunk of
|
1489 |
|
|
memory being pointed at. That is, += len would do. */
|
1490 |
|
|
fp_mem += reg_demand * REGISTER_SIZE;
|
1491 |
|
|
fp_arg += REGISTER_SIZE;
|
1492 |
|
|
}
|
1493 |
|
|
else
|
1494 |
|
|
{
|
1495 |
|
|
/* Data passed by value. No available registers. Put it on
|
1496 |
|
|
the stack. */
|
1497 |
|
|
write_memory (fp_arg, val, len);
|
1498 |
|
|
|
1499 |
|
|
/* fp_arg must be word-aligned (i.e., don't += len) to match
|
1500 |
|
|
the function prologue. */
|
1501 |
|
|
fp_arg += reg_demand * REGISTER_SIZE;
|
1502 |
|
|
}
|
1503 |
|
|
}
|
1504 |
|
|
|
1505 |
|
|
return sp;
|
1506 |
|
|
}
|
1507 |
|
|
|
1508 |
|
|
/* Never put the return address on the stack. The register SRP is pushed
|
1509 |
|
|
by the called function unless it is a leaf-function. Due to the BRP
|
1510 |
|
|
register the PC will change when continue is sent. */
|
1511 |
|
|
|
1512 |
|
|
CORE_ADDR
|
1513 |
|
|
cris_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
|
1514 |
|
|
{
|
1515 |
|
|
write_register (SRP_REGNUM, CALL_DUMMY_ADDRESS ());
|
1516 |
|
|
return sp;
|
1517 |
|
|
}
|
1518 |
|
|
|
1519 |
|
|
/* Restore the machine to the state it had before the current frame
|
1520 |
|
|
was created. Discard the innermost frame from the stack and restore
|
1521 |
|
|
all saved registers. */
|
1522 |
|
|
|
1523 |
|
|
void
|
1524 |
|
|
cris_pop_frame (void)
|
1525 |
|
|
{
|
1526 |
|
|
register struct frame_info *fi = get_current_frame ();
|
1527 |
|
|
register int regno;
|
1528 |
|
|
register int stack_offset = 0;
|
1529 |
|
|
|
1530 |
|
|
if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
|
1531 |
|
|
{
|
1532 |
|
|
/* This happens when we hit a breakpoint set at the entry point,
|
1533 |
|
|
when returning from a dummy frame. */
|
1534 |
|
|
generic_pop_dummy_frame ();
|
1535 |
|
|
}
|
1536 |
|
|
else
|
1537 |
|
|
{
|
1538 |
|
|
cris_frame_init_saved_regs (fi);
|
1539 |
|
|
|
1540 |
|
|
/* For each register, the address of where it was saved on entry to
|
1541 |
|
|
the frame now lies in fi->saved_regs[regno], or zero if it was not
|
1542 |
|
|
saved. This includes special registers such as PC and FP saved in
|
1543 |
|
|
special ways in the stack frame. The SP_REGNUM is even more
|
1544 |
|
|
special, the address here is the SP for the next frame, not the
|
1545 |
|
|
address where the SP was saved. */
|
1546 |
|
|
|
1547 |
|
|
/* Restore general registers R0 - R7. They were pushed on the stack
|
1548 |
|
|
after SP was saved. */
|
1549 |
|
|
for (regno = 0; regno < FP_REGNUM; regno++)
|
1550 |
|
|
{
|
1551 |
|
|
if (fi->saved_regs[regno])
|
1552 |
|
|
{
|
1553 |
|
|
write_register (regno,
|
1554 |
|
|
read_memory_integer (fi->saved_regs[regno], 4));
|
1555 |
|
|
}
|
1556 |
|
|
}
|
1557 |
|
|
|
1558 |
|
|
if (fi->saved_regs[FP_REGNUM])
|
1559 |
|
|
{
|
1560 |
|
|
/* Pop the frame pointer (R8). It was pushed before SP
|
1561 |
|
|
was saved. */
|
1562 |
|
|
write_register (FP_REGNUM,
|
1563 |
|
|
read_memory_integer (fi->saved_regs[FP_REGNUM], 4));
|
1564 |
|
|
stack_offset += 4;
|
1565 |
|
|
|
1566 |
|
|
/* Not a leaf function. */
|
1567 |
|
|
if (fi->saved_regs[SRP_REGNUM])
|
1568 |
|
|
{
|
1569 |
|
|
/* SRP was pushed before SP was saved. */
|
1570 |
|
|
stack_offset += 4;
|
1571 |
|
|
}
|
1572 |
|
|
|
1573 |
|
|
/* Restore the SP and adjust for R8 and (possibly) SRP. */
|
1574 |
|
|
write_register (SP_REGNUM, fi->saved_regs[FP_REGNUM] + stack_offset);
|
1575 |
|
|
}
|
1576 |
|
|
else
|
1577 |
|
|
{
|
1578 |
|
|
/* Currently, we can't get the correct info into fi->saved_regs
|
1579 |
|
|
without a frame pointer. */
|
1580 |
|
|
}
|
1581 |
|
|
|
1582 |
|
|
/* Restore the PC. */
|
1583 |
|
|
write_register (PC_REGNUM, fi->extra_info->return_pc);
|
1584 |
|
|
}
|
1585 |
|
|
flush_cached_frames ();
|
1586 |
|
|
}
|
1587 |
|
|
|
1588 |
|
|
/* Calculates a value that measures how good inst_args constraints an
|
1589 |
|
|
instruction. It stems from cris_constraint, found in cris-dis.c. */
|
1590 |
|
|
|
1591 |
|
|
static int
|
1592 |
|
|
constraint (unsigned int insn, const signed char *inst_args,
|
1593 |
|
|
inst_env_type *inst_env)
|
1594 |
|
|
{
|
1595 |
|
|
int retval = 0;
|
1596 |
|
|
int tmp, i;
|
1597 |
|
|
|
1598 |
|
|
const char *s = inst_args;
|
1599 |
|
|
|
1600 |
|
|
for (; *s; s++)
|
1601 |
|
|
switch (*s)
|
1602 |
|
|
{
|
1603 |
|
|
case 'm':
|
1604 |
|
|
if ((insn & 0x30) == 0x30)
|
1605 |
|
|
return -1;
|
1606 |
|
|
break;
|
1607 |
|
|
|
1608 |
|
|
case 'S':
|
1609 |
|
|
/* A prefix operand. */
|
1610 |
|
|
if (inst_env->prefix_found)
|
1611 |
|
|
break;
|
1612 |
|
|
else
|
1613 |
|
|
return -1;
|
1614 |
|
|
|
1615 |
|
|
case 'B':
|
1616 |
|
|
/* A "push" prefix. (This check was REMOVED by san 970921.) Check for
|
1617 |
|
|
valid "push" size. In case of special register, it may be != 4. */
|
1618 |
|
|
if (inst_env->prefix_found)
|
1619 |
|
|
break;
|
1620 |
|
|
else
|
1621 |
|
|
return -1;
|
1622 |
|
|
|
1623 |
|
|
case 'D':
|
1624 |
|
|
retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
|
1625 |
|
|
if (!retval)
|
1626 |
|
|
return -1;
|
1627 |
|
|
else
|
1628 |
|
|
retval += 4;
|
1629 |
|
|
break;
|
1630 |
|
|
|
1631 |
|
|
case 'P':
|
1632 |
|
|
tmp = (insn >> 0xC) & 0xF;
|
1633 |
|
|
|
1634 |
|
|
for (i = 0; cris_spec_regs[i].name != NULL; i++)
|
1635 |
|
|
{
|
1636 |
|
|
/* Since we match four bits, we will give a value of
|
1637 |
|
|
4 - 1 = 3 in a match. If there is a corresponding
|
1638 |
|
|
exact match of a special register in another pattern, it
|
1639 |
|
|
will get a value of 4, which will be higher. This should
|
1640 |
|
|
be correct in that an exact pattern would match better that
|
1641 |
|
|
a general pattern.
|
1642 |
|
|
Note that there is a reason for not returning zero; the
|
1643 |
|
|
pattern for "clear" is partly matched in the bit-pattern
|
1644 |
|
|
(the two lower bits must be zero), while the bit-pattern
|
1645 |
|
|
for a move from a special register is matched in the
|
1646 |
|
|
register constraint.
|
1647 |
|
|
This also means we will will have a race condition if
|
1648 |
|
|
there is a partly match in three bits in the bit pattern. */
|
1649 |
|
|
if (tmp == cris_spec_regs[i].number)
|
1650 |
|
|
{
|
1651 |
|
|
retval += 3;
|
1652 |
|
|
break;
|
1653 |
|
|
}
|
1654 |
|
|
}
|
1655 |
|
|
|
1656 |
|
|
if (cris_spec_regs[i].name == NULL)
|
1657 |
|
|
return -1;
|
1658 |
|
|
break;
|
1659 |
|
|
}
|
1660 |
|
|
return retval;
|
1661 |
|
|
}
|
1662 |
|
|
|
1663 |
|
|
/* Returns the number of bits set in the variable value. */
|
1664 |
|
|
|
1665 |
|
|
static int
|
1666 |
|
|
number_of_bits (unsigned int value)
|
1667 |
|
|
{
|
1668 |
|
|
int number_of_bits = 0;
|
1669 |
|
|
|
1670 |
|
|
while (value != 0)
|
1671 |
|
|
{
|
1672 |
|
|
number_of_bits += 1;
|
1673 |
|
|
value &= (value - 1);
|
1674 |
|
|
}
|
1675 |
|
|
return number_of_bits;
|
1676 |
|
|
}
|
1677 |
|
|
|
1678 |
|
|
/* Finds the address that should contain the single step breakpoint(s).
|
1679 |
|
|
It stems from code in cris-dis.c. */
|
1680 |
|
|
|
1681 |
|
|
static int
|
1682 |
|
|
find_cris_op (unsigned short insn, inst_env_type *inst_env)
|
1683 |
|
|
{
|
1684 |
|
|
int i;
|
1685 |
|
|
int max_level_of_match = -1;
|
1686 |
|
|
int max_matched = -1;
|
1687 |
|
|
int level_of_match;
|
1688 |
|
|
|
1689 |
|
|
for (i = 0; cris_opcodes[i].name != NULL; i++)
|
1690 |
|
|
{
|
1691 |
|
|
if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
|
1692 |
|
|
&& ((cris_opcodes[i].lose & insn) == 0))
|
1693 |
|
|
{
|
1694 |
|
|
level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
|
1695 |
|
|
if (level_of_match >= 0)
|
1696 |
|
|
{
|
1697 |
|
|
level_of_match +=
|
1698 |
|
|
number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
|
1699 |
|
|
if (level_of_match > max_level_of_match)
|
1700 |
|
|
{
|
1701 |
|
|
max_matched = i;
|
1702 |
|
|
max_level_of_match = level_of_match;
|
1703 |
|
|
if (level_of_match == 16)
|
1704 |
|
|
{
|
1705 |
|
|
/* All bits matched, cannot find better. */
|
1706 |
|
|
break;
|
1707 |
|
|
}
|
1708 |
|
|
}
|
1709 |
|
|
}
|
1710 |
|
|
}
|
1711 |
|
|
}
|
1712 |
|
|
return max_matched;
|
1713 |
|
|
}
|
1714 |
|
|
|
1715 |
|
|
/* Attempts to find single-step breakpoints. Returns -1 on failure which is
|
1716 |
|
|
actually an internal error. */
|
1717 |
|
|
|
1718 |
|
|
static int
|
1719 |
|
|
find_step_target (inst_env_type *inst_env)
|
1720 |
|
|
{
|
1721 |
|
|
int i;
|
1722 |
|
|
int offset;
|
1723 |
|
|
unsigned short insn;
|
1724 |
|
|
|
1725 |
|
|
/* Create a local register image and set the initial state. */
|
1726 |
|
|
for (i = 0; i < NUM_GENREGS; i++)
|
1727 |
|
|
{
|
1728 |
|
|
inst_env->reg[i] = (unsigned long) read_register (i);
|
1729 |
|
|
}
|
1730 |
|
|
offset = NUM_GENREGS;
|
1731 |
|
|
for (i = 0; i < NUM_SPECREGS; i++)
|
1732 |
|
|
{
|
1733 |
|
|
inst_env->preg[i] = (unsigned long) read_register (offset + i);
|
1734 |
|
|
}
|
1735 |
|
|
inst_env->branch_found = 0;
|
1736 |
|
|
inst_env->slot_needed = 0;
|
1737 |
|
|
inst_env->delay_slot_pc_active = 0;
|
1738 |
|
|
inst_env->prefix_found = 0;
|
1739 |
|
|
inst_env->invalid = 0;
|
1740 |
|
|
inst_env->xflag_found = 0;
|
1741 |
|
|
inst_env->disable_interrupt = 0;
|
1742 |
|
|
|
1743 |
|
|
/* Look for a step target. */
|
1744 |
|
|
do
|
1745 |
|
|
{
|
1746 |
|
|
/* Read an instruction from the client. */
|
1747 |
|
|
insn = read_memory_unsigned_integer (inst_env->reg[PC_REGNUM], 2);
|
1748 |
|
|
|
1749 |
|
|
/* If the instruction is not in a delay slot the new content of the
|
1750 |
|
|
PC is [PC] + 2. If the instruction is in a delay slot it is not
|
1751 |
|
|
that simple. Since a instruction in a delay slot cannot change
|
1752 |
|
|
the content of the PC, it does not matter what value PC will have.
|
1753 |
|
|
Just make sure it is a valid instruction. */
|
1754 |
|
|
if (!inst_env->delay_slot_pc_active)
|
1755 |
|
|
{
|
1756 |
|
|
inst_env->reg[PC_REGNUM] += 2;
|
1757 |
|
|
}
|
1758 |
|
|
else
|
1759 |
|
|
{
|
1760 |
|
|
inst_env->delay_slot_pc_active = 0;
|
1761 |
|
|
inst_env->reg[PC_REGNUM] = inst_env->delay_slot_pc;
|
1762 |
|
|
}
|
1763 |
|
|
/* Analyse the present instruction. */
|
1764 |
|
|
i = find_cris_op (insn, inst_env);
|
1765 |
|
|
if (i == -1)
|
1766 |
|
|
{
|
1767 |
|
|
inst_env->invalid = 1;
|
1768 |
|
|
}
|
1769 |
|
|
else
|
1770 |
|
|
{
|
1771 |
|
|
cris_gdb_func (cris_opcodes[i].op, insn, inst_env);
|
1772 |
|
|
}
|
1773 |
|
|
} while (!inst_env->invalid
|
1774 |
|
|
&& (inst_env->prefix_found || inst_env->xflag_found
|
1775 |
|
|
|| inst_env->slot_needed));
|
1776 |
|
|
return i;
|
1777 |
|
|
}
|
1778 |
|
|
|
1779 |
|
|
/* There is no hardware single-step support. The function find_step_target
|
1780 |
|
|
digs through the opcodes in order to find all possible targets.
|
1781 |
|
|
Either one ordinary target or two targets for branches may be found. */
|
1782 |
|
|
|
1783 |
|
|
void
|
1784 |
|
|
cris_software_single_step (enum target_signal ignore, int insert_breakpoints)
|
1785 |
|
|
{
|
1786 |
|
|
inst_env_type inst_env;
|
1787 |
|
|
|
1788 |
|
|
if (insert_breakpoints)
|
1789 |
|
|
{
|
1790 |
|
|
/* Analyse the present instruction environment and insert
|
1791 |
|
|
breakpoints. */
|
1792 |
|
|
int status = find_step_target (&inst_env);
|
1793 |
|
|
if (status == -1)
|
1794 |
|
|
{
|
1795 |
|
|
/* Could not find a target. FIXME: Should do something. */
|
1796 |
|
|
}
|
1797 |
|
|
else
|
1798 |
|
|
{
|
1799 |
|
|
/* Insert at most two breakpoints. One for the next PC content
|
1800 |
|
|
and possibly another one for a branch, jump, etc. */
|
1801 |
|
|
next_pc = (CORE_ADDR) inst_env.reg[PC_REGNUM];
|
1802 |
|
|
target_insert_breakpoint (next_pc, break_mem[0]);
|
1803 |
|
|
if (inst_env.branch_found
|
1804 |
|
|
&& (CORE_ADDR) inst_env.branch_break_address != next_pc)
|
1805 |
|
|
{
|
1806 |
|
|
branch_target_address =
|
1807 |
|
|
(CORE_ADDR) inst_env.branch_break_address;
|
1808 |
|
|
target_insert_breakpoint (branch_target_address, break_mem[1]);
|
1809 |
|
|
branch_break_inserted = 1;
|
1810 |
|
|
}
|
1811 |
|
|
}
|
1812 |
|
|
}
|
1813 |
|
|
else
|
1814 |
|
|
{
|
1815 |
|
|
/* Remove breakpoints. */
|
1816 |
|
|
target_remove_breakpoint (next_pc, break_mem[0]);
|
1817 |
|
|
if (branch_break_inserted)
|
1818 |
|
|
{
|
1819 |
|
|
target_remove_breakpoint (branch_target_address, break_mem[1]);
|
1820 |
|
|
branch_break_inserted = 0;
|
1821 |
|
|
}
|
1822 |
|
|
}
|
1823 |
|
|
}
|
1824 |
|
|
|
1825 |
|
|
/* Calculates the prefix value for quick offset addressing mode. */
|
1826 |
|
|
|
1827 |
|
|
void
|
1828 |
|
|
quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
|
1829 |
|
|
{
|
1830 |
|
|
/* It's invalid to be in a delay slot. You can't have a prefix to this
|
1831 |
|
|
instruction (not 100% sure). */
|
1832 |
|
|
if (inst_env->slot_needed || inst_env->prefix_found)
|
1833 |
|
|
{
|
1834 |
|
|
inst_env->invalid = 1;
|
1835 |
|
|
return;
|
1836 |
|
|
}
|
1837 |
|
|
|
1838 |
|
|
inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
|
1839 |
|
|
inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
|
1840 |
|
|
|
1841 |
|
|
/* A prefix doesn't change the xflag_found. But the rest of the flags
|
1842 |
|
|
need updating. */
|
1843 |
|
|
inst_env->slot_needed = 0;
|
1844 |
|
|
inst_env->prefix_found = 1;
|
1845 |
|
|
}
|
1846 |
|
|
|
1847 |
|
|
/* Updates the autoincrement register. The size of the increment is derived
|
1848 |
|
|
from the size of the operation. The PC is always kept aligned on even
|
1849 |
|
|
word addresses. */
|
1850 |
|
|
|
1851 |
|
|
void
|
1852 |
|
|
process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
|
1853 |
|
|
{
|
1854 |
|
|
if (size == INST_BYTE_SIZE)
|
1855 |
|
|
{
|
1856 |
|
|
inst_env->reg[cris_get_operand1 (inst)] += 1;
|
1857 |
|
|
|
1858 |
|
|
/* The PC must be word aligned, so increase the PC with one
|
1859 |
|
|
word even if the size is byte. */
|
1860 |
|
|
if (cris_get_operand1 (inst) == REG_PC)
|
1861 |
|
|
{
|
1862 |
|
|
inst_env->reg[REG_PC] += 1;
|
1863 |
|
|
}
|
1864 |
|
|
}
|
1865 |
|
|
else if (size == INST_WORD_SIZE)
|
1866 |
|
|
{
|
1867 |
|
|
inst_env->reg[cris_get_operand1 (inst)] += 2;
|
1868 |
|
|
}
|
1869 |
|
|
else if (size == INST_DWORD_SIZE)
|
1870 |
|
|
{
|
1871 |
|
|
inst_env->reg[cris_get_operand1 (inst)] += 4;
|
1872 |
|
|
}
|
1873 |
|
|
else
|
1874 |
|
|
{
|
1875 |
|
|
/* Invalid size. */
|
1876 |
|
|
inst_env->invalid = 1;
|
1877 |
|
|
}
|
1878 |
|
|
}
|
1879 |
|
|
|
1880 |
|
|
/* Just a forward declaration. */
|
1881 |
|
|
|
1882 |
|
|
unsigned long
|
1883 |
|
|
get_data_from_address (unsigned short *inst, CORE_ADDR address);
|
1884 |
|
|
|
1885 |
|
|
/* Calculates the prefix value for the general case of offset addressing
|
1886 |
|
|
mode. */
|
1887 |
|
|
|
1888 |
|
|
void
|
1889 |
|
|
bdap_prefix (unsigned short inst, inst_env_type *inst_env)
|
1890 |
|
|
{
|
1891 |
|
|
|
1892 |
|
|
long offset;
|
1893 |
|
|
|
1894 |
|
|
/* It's invalid to be in a delay slot. */
|
1895 |
|
|
if (inst_env->slot_needed || inst_env->prefix_found)
|
1896 |
|
|
{
|
1897 |
|
|
inst_env->invalid = 1;
|
1898 |
|
|
return;
|
1899 |
|
|
}
|
1900 |
|
|
|
1901 |
|
|
/* The calculation of prefix_value used to be after process_autoincrement,
|
1902 |
|
|
but that fails for an instruction such as jsr [$r0+12] which is encoded
|
1903 |
|
|
as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
|
1904 |
|
|
mustn't be incremented until we have read it and what it points at. */
|
1905 |
|
|
inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
|
1906 |
|
|
|
1907 |
|
|
/* The offset is an indirection of the contents of the operand1 register. */
|
1908 |
|
|
inst_env->prefix_value +=
|
1909 |
|
|
get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)]);
|
1910 |
|
|
|
1911 |
|
|
if (cris_get_mode (inst) == AUTOINC_MODE)
|
1912 |
|
|
{
|
1913 |
|
|
process_autoincrement (cris_get_size (inst), inst, inst_env);
|
1914 |
|
|
}
|
1915 |
|
|
|
1916 |
|
|
/* A prefix doesn't change the xflag_found. But the rest of the flags
|
1917 |
|
|
need updating. */
|
1918 |
|
|
inst_env->slot_needed = 0;
|
1919 |
|
|
inst_env->prefix_found = 1;
|
1920 |
|
|
}
|
1921 |
|
|
|
1922 |
|
|
/* Calculates the prefix value for the index addressing mode. */
|
1923 |
|
|
|
1924 |
|
|
void
|
1925 |
|
|
biap_prefix (unsigned short inst, inst_env_type *inst_env)
|
1926 |
|
|
{
|
1927 |
|
|
/* It's invalid to be in a delay slot. I can't see that it's possible to
|
1928 |
|
|
have a prefix to this instruction. So I will treat this as invalid. */
|
1929 |
|
|
if (inst_env->slot_needed || inst_env->prefix_found)
|
1930 |
|
|
{
|
1931 |
|
|
inst_env->invalid = 1;
|
1932 |
|
|
return;
|
1933 |
|
|
}
|
1934 |
|
|
|
1935 |
|
|
inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
|
1936 |
|
|
|
1937 |
|
|
/* The offset is the operand2 value shifted the size of the instruction
|
1938 |
|
|
to the left. */
|
1939 |
|
|
inst_env->prefix_value +=
|
1940 |
|
|
inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
|
1941 |
|
|
|
1942 |
|
|
/* If the PC is operand1 (base) the address used is the address after
|
1943 |
|
|
the main instruction, i.e. address + 2 (the PC is already compensated
|
1944 |
|
|
for the prefix operation). */
|
1945 |
|
|
if (cris_get_operand1 (inst) == REG_PC)
|
1946 |
|
|
{
|
1947 |
|
|
inst_env->prefix_value += 2;
|
1948 |
|
|
}
|
1949 |
|
|
|
1950 |
|
|
/* A prefix doesn't change the xflag_found. But the rest of the flags
|
1951 |
|
|
need updating. */
|
1952 |
|
|
inst_env->slot_needed = 0;
|
1953 |
|
|
inst_env->xflag_found = 0;
|
1954 |
|
|
inst_env->prefix_found = 1;
|
1955 |
|
|
}
|
1956 |
|
|
|
1957 |
|
|
/* Calculates the prefix value for the double indirect addressing mode. */
|
1958 |
|
|
|
1959 |
|
|
void
|
1960 |
|
|
dip_prefix (unsigned short inst, inst_env_type *inst_env)
|
1961 |
|
|
{
|
1962 |
|
|
|
1963 |
|
|
CORE_ADDR address;
|
1964 |
|
|
|
1965 |
|
|
/* It's invalid to be in a delay slot. */
|
1966 |
|
|
if (inst_env->slot_needed || inst_env->prefix_found)
|
1967 |
|
|
{
|
1968 |
|
|
inst_env->invalid = 1;
|
1969 |
|
|
return;
|
1970 |
|
|
}
|
1971 |
|
|
|
1972 |
|
|
/* The prefix value is one dereference of the contents of the operand1
|
1973 |
|
|
register. */
|
1974 |
|
|
address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
|
1975 |
|
|
inst_env->prefix_value = read_memory_unsigned_integer (address, 4);
|
1976 |
|
|
|
1977 |
|
|
/* Check if the mode is autoincrement. */
|
1978 |
|
|
if (cris_get_mode (inst) == AUTOINC_MODE)
|
1979 |
|
|
{
|
1980 |
|
|
inst_env->reg[cris_get_operand1 (inst)] += 4;
|
1981 |
|
|
}
|
1982 |
|
|
|
1983 |
|
|
/* A prefix doesn't change the xflag_found. But the rest of the flags
|
1984 |
|
|
need updating. */
|
1985 |
|
|
inst_env->slot_needed = 0;
|
1986 |
|
|
inst_env->xflag_found = 0;
|
1987 |
|
|
inst_env->prefix_found = 1;
|
1988 |
|
|
}
|
1989 |
|
|
|
1990 |
|
|
/* Finds the destination for a branch with 8-bits offset. */
|
1991 |
|
|
|
1992 |
|
|
void
|
1993 |
|
|
eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
|
1994 |
|
|
{
|
1995 |
|
|
|
1996 |
|
|
short offset;
|
1997 |
|
|
|
1998 |
|
|
/* If we have a prefix or are in a delay slot it's bad. */
|
1999 |
|
|
if (inst_env->slot_needed || inst_env->prefix_found)
|
2000 |
|
|
{
|
2001 |
|
|
inst_env->invalid = 1;
|
2002 |
|
|
return;
|
2003 |
|
|
}
|
2004 |
|
|
|
2005 |
|
|
/* We have a branch, find out where the branch will land. */
|
2006 |
|
|
offset = cris_get_branch_short_offset (inst);
|
2007 |
|
|
|
2008 |
|
|
/* Check if the offset is signed. */
|
2009 |
|
|
if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
|
2010 |
|
|
{
|
2011 |
|
|
offset |= 0xFF00;
|
2012 |
|
|
}
|
2013 |
|
|
|
2014 |
|
|
/* The offset ends with the sign bit, set it to zero. The address
|
2015 |
|
|
should always be word aligned. */
|
2016 |
|
|
offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
|
2017 |
|
|
|
2018 |
|
|
inst_env->branch_found = 1;
|
2019 |
|
|
inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
|
2020 |
|
|
|
2021 |
|
|
inst_env->slot_needed = 1;
|
2022 |
|
|
inst_env->prefix_found = 0;
|
2023 |
|
|
inst_env->xflag_found = 0;
|
2024 |
|
|
inst_env->disable_interrupt = 1;
|
2025 |
|
|
}
|
2026 |
|
|
|
2027 |
|
|
/* Finds the destination for a branch with 16-bits offset. */
|
2028 |
|
|
|
2029 |
|
|
void
|
2030 |
|
|
sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
|
2031 |
|
|
{
|
2032 |
|
|
short offset;
|
2033 |
|
|
|
2034 |
|
|
/* If we have a prefix or is in a delay slot it's bad. */
|
2035 |
|
|
if (inst_env->slot_needed || inst_env->prefix_found)
|
2036 |
|
|
{
|
2037 |
|
|
inst_env->invalid = 1;
|
2038 |
|
|
return;
|
2039 |
|
|
}
|
2040 |
|
|
|
2041 |
|
|
/* We have a branch, find out the offset for the branch. */
|
2042 |
|
|
offset = read_memory_integer (inst_env->reg[REG_PC], 2);
|
2043 |
|
|
|
2044 |
|
|
/* The instruction is one word longer than normal, so add one word
|
2045 |
|
|
to the PC. */
|
2046 |
|
|
inst_env->reg[REG_PC] += 2;
|
2047 |
|
|
|
2048 |
|
|
inst_env->branch_found = 1;
|
2049 |
|
|
inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
|
2050 |
|
|
|
2051 |
|
|
|
2052 |
|
|
inst_env->slot_needed = 1;
|
2053 |
|
|
inst_env->prefix_found = 0;
|
2054 |
|
|
inst_env->xflag_found = 0;
|
2055 |
|
|
inst_env->disable_interrupt = 1;
|
2056 |
|
|
}
|
2057 |
|
|
|
2058 |
|
|
/* Handles the ABS instruction. */
|
2059 |
|
|
|
2060 |
|
|
void
|
2061 |
|
|
abs_op (unsigned short inst, inst_env_type *inst_env)
|
2062 |
|
|
{
|
2063 |
|
|
|
2064 |
|
|
long value;
|
2065 |
|
|
|
2066 |
|
|
/* ABS can't have a prefix, so it's bad if it does. */
|
2067 |
|
|
if (inst_env->prefix_found)
|
2068 |
|
|
{
|
2069 |
|
|
inst_env->invalid = 1;
|
2070 |
|
|
return;
|
2071 |
|
|
}
|
2072 |
|
|
|
2073 |
|
|
/* Check if the operation affects the PC. */
|
2074 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2075 |
|
|
{
|
2076 |
|
|
|
2077 |
|
|
/* It's invalid to change to the PC if we are in a delay slot. */
|
2078 |
|
|
if (inst_env->slot_needed)
|
2079 |
|
|
{
|
2080 |
|
|
inst_env->invalid = 1;
|
2081 |
|
|
return;
|
2082 |
|
|
}
|
2083 |
|
|
|
2084 |
|
|
value = (long) inst_env->reg[REG_PC];
|
2085 |
|
|
|
2086 |
|
|
/* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
|
2087 |
|
|
if (value != SIGNED_DWORD_MASK)
|
2088 |
|
|
{
|
2089 |
|
|
value = -value;
|
2090 |
|
|
inst_env->reg[REG_PC] = (long) value;
|
2091 |
|
|
}
|
2092 |
|
|
}
|
2093 |
|
|
|
2094 |
|
|
inst_env->slot_needed = 0;
|
2095 |
|
|
inst_env->prefix_found = 0;
|
2096 |
|
|
inst_env->xflag_found = 0;
|
2097 |
|
|
inst_env->disable_interrupt = 0;
|
2098 |
|
|
}
|
2099 |
|
|
|
2100 |
|
|
/* Handles the ADDI instruction. */
|
2101 |
|
|
|
2102 |
|
|
void
|
2103 |
|
|
addi_op (unsigned short inst, inst_env_type *inst_env)
|
2104 |
|
|
{
|
2105 |
|
|
/* It's invalid to have the PC as base register. And ADDI can't have
|
2106 |
|
|
a prefix. */
|
2107 |
|
|
if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
|
2108 |
|
|
{
|
2109 |
|
|
inst_env->invalid = 1;
|
2110 |
|
|
return;
|
2111 |
|
|
}
|
2112 |
|
|
|
2113 |
|
|
inst_env->slot_needed = 0;
|
2114 |
|
|
inst_env->prefix_found = 0;
|
2115 |
|
|
inst_env->xflag_found = 0;
|
2116 |
|
|
inst_env->disable_interrupt = 0;
|
2117 |
|
|
}
|
2118 |
|
|
|
2119 |
|
|
/* Handles the ASR instruction. */
|
2120 |
|
|
|
2121 |
|
|
void
|
2122 |
|
|
asr_op (unsigned short inst, inst_env_type *inst_env)
|
2123 |
|
|
{
|
2124 |
|
|
int shift_steps;
|
2125 |
|
|
unsigned long value;
|
2126 |
|
|
unsigned long signed_extend_mask = 0;
|
2127 |
|
|
|
2128 |
|
|
/* ASR can't have a prefix, so check that it doesn't. */
|
2129 |
|
|
if (inst_env->prefix_found)
|
2130 |
|
|
{
|
2131 |
|
|
inst_env->invalid = 1;
|
2132 |
|
|
return;
|
2133 |
|
|
}
|
2134 |
|
|
|
2135 |
|
|
/* Check if the PC is the target register. */
|
2136 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2137 |
|
|
{
|
2138 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2139 |
|
|
if (inst_env->slot_needed)
|
2140 |
|
|
{
|
2141 |
|
|
inst_env->invalid = 1;
|
2142 |
|
|
return;
|
2143 |
|
|
}
|
2144 |
|
|
/* Get the number of bits to shift. */
|
2145 |
|
|
shift_steps = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
|
2146 |
|
|
value = inst_env->reg[REG_PC];
|
2147 |
|
|
|
2148 |
|
|
/* Find out how many bits the operation should apply to. */
|
2149 |
|
|
if (cris_get_size (inst) == INST_BYTE_SIZE)
|
2150 |
|
|
{
|
2151 |
|
|
if (value & SIGNED_BYTE_MASK)
|
2152 |
|
|
{
|
2153 |
|
|
signed_extend_mask = 0xFF;
|
2154 |
|
|
signed_extend_mask = signed_extend_mask >> shift_steps;
|
2155 |
|
|
signed_extend_mask = ~signed_extend_mask;
|
2156 |
|
|
}
|
2157 |
|
|
value = value >> shift_steps;
|
2158 |
|
|
value |= signed_extend_mask;
|
2159 |
|
|
value &= 0xFF;
|
2160 |
|
|
inst_env->reg[REG_PC] &= 0xFFFFFF00;
|
2161 |
|
|
inst_env->reg[REG_PC] |= value;
|
2162 |
|
|
}
|
2163 |
|
|
else if (cris_get_size (inst) == INST_WORD_SIZE)
|
2164 |
|
|
{
|
2165 |
|
|
if (value & SIGNED_WORD_MASK)
|
2166 |
|
|
{
|
2167 |
|
|
signed_extend_mask = 0xFFFF;
|
2168 |
|
|
signed_extend_mask = signed_extend_mask >> shift_steps;
|
2169 |
|
|
signed_extend_mask = ~signed_extend_mask;
|
2170 |
|
|
}
|
2171 |
|
|
value = value >> shift_steps;
|
2172 |
|
|
value |= signed_extend_mask;
|
2173 |
|
|
value &= 0xFFFF;
|
2174 |
|
|
inst_env->reg[REG_PC] &= 0xFFFF0000;
|
2175 |
|
|
inst_env->reg[REG_PC] |= value;
|
2176 |
|
|
}
|
2177 |
|
|
else if (cris_get_size (inst) == INST_DWORD_SIZE)
|
2178 |
|
|
{
|
2179 |
|
|
if (value & SIGNED_DWORD_MASK)
|
2180 |
|
|
{
|
2181 |
|
|
signed_extend_mask = 0xFFFFFFFF;
|
2182 |
|
|
signed_extend_mask = signed_extend_mask >> shift_steps;
|
2183 |
|
|
signed_extend_mask = ~signed_extend_mask;
|
2184 |
|
|
}
|
2185 |
|
|
value = value >> shift_steps;
|
2186 |
|
|
value |= signed_extend_mask;
|
2187 |
|
|
inst_env->reg[REG_PC] = value;
|
2188 |
|
|
}
|
2189 |
|
|
}
|
2190 |
|
|
inst_env->slot_needed = 0;
|
2191 |
|
|
inst_env->prefix_found = 0;
|
2192 |
|
|
inst_env->xflag_found = 0;
|
2193 |
|
|
inst_env->disable_interrupt = 0;
|
2194 |
|
|
}
|
2195 |
|
|
|
2196 |
|
|
/* Handles the ASRQ instruction. */
|
2197 |
|
|
|
2198 |
|
|
void
|
2199 |
|
|
asrq_op (unsigned short inst, inst_env_type *inst_env)
|
2200 |
|
|
{
|
2201 |
|
|
|
2202 |
|
|
int shift_steps;
|
2203 |
|
|
unsigned long value;
|
2204 |
|
|
unsigned long signed_extend_mask = 0;
|
2205 |
|
|
|
2206 |
|
|
/* ASRQ can't have a prefix, so check that it doesn't. */
|
2207 |
|
|
if (inst_env->prefix_found)
|
2208 |
|
|
{
|
2209 |
|
|
inst_env->invalid = 1;
|
2210 |
|
|
return;
|
2211 |
|
|
}
|
2212 |
|
|
|
2213 |
|
|
/* Check if the PC is the target register. */
|
2214 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2215 |
|
|
{
|
2216 |
|
|
|
2217 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2218 |
|
|
if (inst_env->slot_needed)
|
2219 |
|
|
{
|
2220 |
|
|
inst_env->invalid = 1;
|
2221 |
|
|
return;
|
2222 |
|
|
}
|
2223 |
|
|
/* The shift size is given as a 5 bit quick value, i.e. we don't
|
2224 |
|
|
want the the sign bit of the quick value. */
|
2225 |
|
|
shift_steps = cris_get_asr_shift_steps (inst);
|
2226 |
|
|
value = inst_env->reg[REG_PC];
|
2227 |
|
|
if (value & SIGNED_DWORD_MASK)
|
2228 |
|
|
{
|
2229 |
|
|
signed_extend_mask = 0xFFFFFFFF;
|
2230 |
|
|
signed_extend_mask = signed_extend_mask >> shift_steps;
|
2231 |
|
|
signed_extend_mask = ~signed_extend_mask;
|
2232 |
|
|
}
|
2233 |
|
|
value = value >> shift_steps;
|
2234 |
|
|
value |= signed_extend_mask;
|
2235 |
|
|
inst_env->reg[REG_PC] = value;
|
2236 |
|
|
}
|
2237 |
|
|
inst_env->slot_needed = 0;
|
2238 |
|
|
inst_env->prefix_found = 0;
|
2239 |
|
|
inst_env->xflag_found = 0;
|
2240 |
|
|
inst_env->disable_interrupt = 0;
|
2241 |
|
|
}
|
2242 |
|
|
|
2243 |
|
|
/* Handles the AX, EI and SETF instruction. */
|
2244 |
|
|
|
2245 |
|
|
void
|
2246 |
|
|
ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
|
2247 |
|
|
{
|
2248 |
|
|
if (inst_env->prefix_found)
|
2249 |
|
|
{
|
2250 |
|
|
inst_env->invalid = 1;
|
2251 |
|
|
return;
|
2252 |
|
|
}
|
2253 |
|
|
/* Check if the instruction is setting the X flag. */
|
2254 |
|
|
if (cris_is_xflag_bit_on (inst))
|
2255 |
|
|
{
|
2256 |
|
|
inst_env->xflag_found = 1;
|
2257 |
|
|
}
|
2258 |
|
|
else
|
2259 |
|
|
{
|
2260 |
|
|
inst_env->xflag_found = 0;
|
2261 |
|
|
}
|
2262 |
|
|
inst_env->slot_needed = 0;
|
2263 |
|
|
inst_env->prefix_found = 0;
|
2264 |
|
|
inst_env->disable_interrupt = 1;
|
2265 |
|
|
}
|
2266 |
|
|
|
2267 |
|
|
/* Checks if the instruction is in assign mode. If so, it updates the assign
|
2268 |
|
|
register. Note that check_assign assumes that the caller has checked that
|
2269 |
|
|
there is a prefix to this instruction. The mode check depends on this. */
|
2270 |
|
|
|
2271 |
|
|
void
|
2272 |
|
|
check_assign (unsigned short inst, inst_env_type *inst_env)
|
2273 |
|
|
{
|
2274 |
|
|
/* Check if it's an assign addressing mode. */
|
2275 |
|
|
if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
|
2276 |
|
|
{
|
2277 |
|
|
/* Assign the prefix value to operand 1. */
|
2278 |
|
|
inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
|
2279 |
|
|
}
|
2280 |
|
|
}
|
2281 |
|
|
|
2282 |
|
|
/* Handles the 2-operand BOUND instruction. */
|
2283 |
|
|
|
2284 |
|
|
void
|
2285 |
|
|
two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
|
2286 |
|
|
{
|
2287 |
|
|
/* It's invalid to have the PC as the index operand. */
|
2288 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2289 |
|
|
{
|
2290 |
|
|
inst_env->invalid = 1;
|
2291 |
|
|
return;
|
2292 |
|
|
}
|
2293 |
|
|
/* Check if we have a prefix. */
|
2294 |
|
|
if (inst_env->prefix_found)
|
2295 |
|
|
{
|
2296 |
|
|
check_assign (inst, inst_env);
|
2297 |
|
|
}
|
2298 |
|
|
/* Check if this is an autoincrement mode. */
|
2299 |
|
|
else if (cris_get_mode (inst) == AUTOINC_MODE)
|
2300 |
|
|
{
|
2301 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2302 |
|
|
if (inst_env->slot_needed)
|
2303 |
|
|
{
|
2304 |
|
|
inst_env->invalid = 1;
|
2305 |
|
|
return;
|
2306 |
|
|
}
|
2307 |
|
|
process_autoincrement (cris_get_size (inst), inst, inst_env);
|
2308 |
|
|
}
|
2309 |
|
|
inst_env->slot_needed = 0;
|
2310 |
|
|
inst_env->prefix_found = 0;
|
2311 |
|
|
inst_env->xflag_found = 0;
|
2312 |
|
|
inst_env->disable_interrupt = 0;
|
2313 |
|
|
}
|
2314 |
|
|
|
2315 |
|
|
/* Handles the 3-operand BOUND instruction. */
|
2316 |
|
|
|
2317 |
|
|
void
|
2318 |
|
|
three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
|
2319 |
|
|
{
|
2320 |
|
|
/* It's an error if we haven't got a prefix. And it's also an error
|
2321 |
|
|
if the PC is the destination register. */
|
2322 |
|
|
if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
|
2323 |
|
|
{
|
2324 |
|
|
inst_env->invalid = 1;
|
2325 |
|
|
return;
|
2326 |
|
|
}
|
2327 |
|
|
inst_env->slot_needed = 0;
|
2328 |
|
|
inst_env->prefix_found = 0;
|
2329 |
|
|
inst_env->xflag_found = 0;
|
2330 |
|
|
inst_env->disable_interrupt = 0;
|
2331 |
|
|
}
|
2332 |
|
|
|
2333 |
|
|
/* Clears the status flags in inst_env. */
|
2334 |
|
|
|
2335 |
|
|
void
|
2336 |
|
|
btst_nop_op (unsigned short inst, inst_env_type *inst_env)
|
2337 |
|
|
{
|
2338 |
|
|
/* It's an error if we have got a prefix. */
|
2339 |
|
|
if (inst_env->prefix_found)
|
2340 |
|
|
{
|
2341 |
|
|
inst_env->invalid = 1;
|
2342 |
|
|
return;
|
2343 |
|
|
}
|
2344 |
|
|
|
2345 |
|
|
inst_env->slot_needed = 0;
|
2346 |
|
|
inst_env->prefix_found = 0;
|
2347 |
|
|
inst_env->xflag_found = 0;
|
2348 |
|
|
inst_env->disable_interrupt = 0;
|
2349 |
|
|
}
|
2350 |
|
|
|
2351 |
|
|
/* Clears the status flags in inst_env. */
|
2352 |
|
|
|
2353 |
|
|
void
|
2354 |
|
|
clearf_di_op (unsigned short inst, inst_env_type *inst_env)
|
2355 |
|
|
{
|
2356 |
|
|
/* It's an error if we have got a prefix. */
|
2357 |
|
|
if (inst_env->prefix_found)
|
2358 |
|
|
{
|
2359 |
|
|
inst_env->invalid = 1;
|
2360 |
|
|
return;
|
2361 |
|
|
}
|
2362 |
|
|
|
2363 |
|
|
inst_env->slot_needed = 0;
|
2364 |
|
|
inst_env->prefix_found = 0;
|
2365 |
|
|
inst_env->xflag_found = 0;
|
2366 |
|
|
inst_env->disable_interrupt = 1;
|
2367 |
|
|
}
|
2368 |
|
|
|
2369 |
|
|
/* Handles the CLEAR instruction if it's in register mode. */
|
2370 |
|
|
|
2371 |
|
|
void
|
2372 |
|
|
reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
|
2373 |
|
|
{
|
2374 |
|
|
/* Check if the target is the PC. */
|
2375 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2376 |
|
|
{
|
2377 |
|
|
/* The instruction will clear the instruction's size bits. */
|
2378 |
|
|
int clear_size = cris_get_clear_size (inst);
|
2379 |
|
|
if (clear_size == INST_BYTE_SIZE)
|
2380 |
|
|
{
|
2381 |
|
|
inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
|
2382 |
|
|
}
|
2383 |
|
|
if (clear_size == INST_WORD_SIZE)
|
2384 |
|
|
{
|
2385 |
|
|
inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
|
2386 |
|
|
}
|
2387 |
|
|
if (clear_size == INST_DWORD_SIZE)
|
2388 |
|
|
{
|
2389 |
|
|
inst_env->delay_slot_pc = 0x0;
|
2390 |
|
|
}
|
2391 |
|
|
/* The jump will be delayed with one delay slot. So we need a delay
|
2392 |
|
|
slot. */
|
2393 |
|
|
inst_env->slot_needed = 1;
|
2394 |
|
|
inst_env->delay_slot_pc_active = 1;
|
2395 |
|
|
}
|
2396 |
|
|
else
|
2397 |
|
|
{
|
2398 |
|
|
/* The PC will not change => no delay slot. */
|
2399 |
|
|
inst_env->slot_needed = 0;
|
2400 |
|
|
}
|
2401 |
|
|
inst_env->prefix_found = 0;
|
2402 |
|
|
inst_env->xflag_found = 0;
|
2403 |
|
|
inst_env->disable_interrupt = 0;
|
2404 |
|
|
}
|
2405 |
|
|
|
2406 |
|
|
/* Handles the TEST instruction if it's in register mode. */
|
2407 |
|
|
|
2408 |
|
|
void
|
2409 |
|
|
reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
|
2410 |
|
|
{
|
2411 |
|
|
/* It's an error if we have got a prefix. */
|
2412 |
|
|
if (inst_env->prefix_found)
|
2413 |
|
|
{
|
2414 |
|
|
inst_env->invalid = 1;
|
2415 |
|
|
return;
|
2416 |
|
|
}
|
2417 |
|
|
inst_env->slot_needed = 0;
|
2418 |
|
|
inst_env->prefix_found = 0;
|
2419 |
|
|
inst_env->xflag_found = 0;
|
2420 |
|
|
inst_env->disable_interrupt = 0;
|
2421 |
|
|
|
2422 |
|
|
}
|
2423 |
|
|
|
2424 |
|
|
/* Handles the CLEAR and TEST instruction if the instruction isn't
|
2425 |
|
|
in register mode. */
|
2426 |
|
|
|
2427 |
|
|
void
|
2428 |
|
|
none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
|
2429 |
|
|
{
|
2430 |
|
|
/* Check if we are in a prefix mode. */
|
2431 |
|
|
if (inst_env->prefix_found)
|
2432 |
|
|
{
|
2433 |
|
|
/* The only way the PC can change is if this instruction is in
|
2434 |
|
|
assign addressing mode. */
|
2435 |
|
|
check_assign (inst, inst_env);
|
2436 |
|
|
}
|
2437 |
|
|
/* Indirect mode can't change the PC so just check if the mode is
|
2438 |
|
|
autoincrement. */
|
2439 |
|
|
else if (cris_get_mode (inst) == AUTOINC_MODE)
|
2440 |
|
|
{
|
2441 |
|
|
process_autoincrement (cris_get_size (inst), inst, inst_env);
|
2442 |
|
|
}
|
2443 |
|
|
inst_env->slot_needed = 0;
|
2444 |
|
|
inst_env->prefix_found = 0;
|
2445 |
|
|
inst_env->xflag_found = 0;
|
2446 |
|
|
inst_env->disable_interrupt = 0;
|
2447 |
|
|
}
|
2448 |
|
|
|
2449 |
|
|
/* Checks that the PC isn't the destination register or the instructions has
|
2450 |
|
|
a prefix. */
|
2451 |
|
|
|
2452 |
|
|
void
|
2453 |
|
|
dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
|
2454 |
|
|
{
|
2455 |
|
|
/* It's invalid to have the PC as the destination. The instruction can't
|
2456 |
|
|
have a prefix. */
|
2457 |
|
|
if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
|
2458 |
|
|
{
|
2459 |
|
|
inst_env->invalid = 1;
|
2460 |
|
|
return;
|
2461 |
|
|
}
|
2462 |
|
|
|
2463 |
|
|
inst_env->slot_needed = 0;
|
2464 |
|
|
inst_env->prefix_found = 0;
|
2465 |
|
|
inst_env->xflag_found = 0;
|
2466 |
|
|
inst_env->disable_interrupt = 0;
|
2467 |
|
|
}
|
2468 |
|
|
|
2469 |
|
|
/* Checks that the instruction doesn't have a prefix. */
|
2470 |
|
|
|
2471 |
|
|
void
|
2472 |
|
|
break_op (unsigned short inst, inst_env_type *inst_env)
|
2473 |
|
|
{
|
2474 |
|
|
/* The instruction can't have a prefix. */
|
2475 |
|
|
if (inst_env->prefix_found)
|
2476 |
|
|
{
|
2477 |
|
|
inst_env->invalid = 1;
|
2478 |
|
|
return;
|
2479 |
|
|
}
|
2480 |
|
|
|
2481 |
|
|
inst_env->slot_needed = 0;
|
2482 |
|
|
inst_env->prefix_found = 0;
|
2483 |
|
|
inst_env->xflag_found = 0;
|
2484 |
|
|
inst_env->disable_interrupt = 1;
|
2485 |
|
|
}
|
2486 |
|
|
|
2487 |
|
|
/* Checks that the PC isn't the destination register and that the instruction
|
2488 |
|
|
doesn't have a prefix. */
|
2489 |
|
|
|
2490 |
|
|
void
|
2491 |
|
|
scc_op (unsigned short inst, inst_env_type *inst_env)
|
2492 |
|
|
{
|
2493 |
|
|
/* It's invalid to have the PC as the destination. The instruction can't
|
2494 |
|
|
have a prefix. */
|
2495 |
|
|
if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
|
2496 |
|
|
{
|
2497 |
|
|
inst_env->invalid = 1;
|
2498 |
|
|
return;
|
2499 |
|
|
}
|
2500 |
|
|
|
2501 |
|
|
inst_env->slot_needed = 0;
|
2502 |
|
|
inst_env->prefix_found = 0;
|
2503 |
|
|
inst_env->xflag_found = 0;
|
2504 |
|
|
inst_env->disable_interrupt = 1;
|
2505 |
|
|
}
|
2506 |
|
|
|
2507 |
|
|
/* Handles the register mode JUMP instruction. */
|
2508 |
|
|
|
2509 |
|
|
void
|
2510 |
|
|
reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
|
2511 |
|
|
{
|
2512 |
|
|
/* It's invalid to do a JUMP in a delay slot. The mode is register, so
|
2513 |
|
|
you can't have a prefix. */
|
2514 |
|
|
if ((inst_env->slot_needed) || (inst_env->prefix_found))
|
2515 |
|
|
{
|
2516 |
|
|
inst_env->invalid = 1;
|
2517 |
|
|
return;
|
2518 |
|
|
}
|
2519 |
|
|
|
2520 |
|
|
/* Just change the PC. */
|
2521 |
|
|
inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
|
2522 |
|
|
inst_env->slot_needed = 0;
|
2523 |
|
|
inst_env->prefix_found = 0;
|
2524 |
|
|
inst_env->xflag_found = 0;
|
2525 |
|
|
inst_env->disable_interrupt = 1;
|
2526 |
|
|
}
|
2527 |
|
|
|
2528 |
|
|
/* Handles the JUMP instruction for all modes except register. */
|
2529 |
|
|
|
2530 |
|
|
void none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
|
2531 |
|
|
{
|
2532 |
|
|
unsigned long newpc;
|
2533 |
|
|
CORE_ADDR address;
|
2534 |
|
|
|
2535 |
|
|
/* It's invalid to do a JUMP in a delay slot. */
|
2536 |
|
|
if (inst_env->slot_needed)
|
2537 |
|
|
{
|
2538 |
|
|
inst_env->invalid = 1;
|
2539 |
|
|
}
|
2540 |
|
|
else
|
2541 |
|
|
{
|
2542 |
|
|
/* Check if we have a prefix. */
|
2543 |
|
|
if (inst_env->prefix_found)
|
2544 |
|
|
{
|
2545 |
|
|
check_assign (inst, inst_env);
|
2546 |
|
|
|
2547 |
|
|
/* Get the new value for the the PC. */
|
2548 |
|
|
newpc =
|
2549 |
|
|
read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
|
2550 |
|
|
4);
|
2551 |
|
|
}
|
2552 |
|
|
else
|
2553 |
|
|
{
|
2554 |
|
|
/* Get the new value for the PC. */
|
2555 |
|
|
address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
|
2556 |
|
|
newpc = read_memory_unsigned_integer (address, 4);
|
2557 |
|
|
|
2558 |
|
|
/* Check if we should increment a register. */
|
2559 |
|
|
if (cris_get_mode (inst) == AUTOINC_MODE)
|
2560 |
|
|
{
|
2561 |
|
|
inst_env->reg[cris_get_operand1 (inst)] += 4;
|
2562 |
|
|
}
|
2563 |
|
|
}
|
2564 |
|
|
inst_env->reg[REG_PC] = newpc;
|
2565 |
|
|
}
|
2566 |
|
|
inst_env->slot_needed = 0;
|
2567 |
|
|
inst_env->prefix_found = 0;
|
2568 |
|
|
inst_env->xflag_found = 0;
|
2569 |
|
|
inst_env->disable_interrupt = 1;
|
2570 |
|
|
}
|
2571 |
|
|
|
2572 |
|
|
/* Handles moves to special registers (aka P-register) for all modes. */
|
2573 |
|
|
|
2574 |
|
|
void
|
2575 |
|
|
move_to_preg_op (unsigned short inst, inst_env_type *inst_env)
|
2576 |
|
|
{
|
2577 |
|
|
if (inst_env->prefix_found)
|
2578 |
|
|
{
|
2579 |
|
|
/* The instruction has a prefix that means we are only interested if
|
2580 |
|
|
the instruction is in assign mode. */
|
2581 |
|
|
if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
|
2582 |
|
|
{
|
2583 |
|
|
/* The prefix handles the problem if we are in a delay slot. */
|
2584 |
|
|
if (cris_get_operand1 (inst) == REG_PC)
|
2585 |
|
|
{
|
2586 |
|
|
/* Just take care of the assign. */
|
2587 |
|
|
check_assign (inst, inst_env);
|
2588 |
|
|
}
|
2589 |
|
|
}
|
2590 |
|
|
}
|
2591 |
|
|
else if (cris_get_mode (inst) == AUTOINC_MODE)
|
2592 |
|
|
{
|
2593 |
|
|
/* The instruction doesn't have a prefix, the only case left that we
|
2594 |
|
|
are interested in is the autoincrement mode. */
|
2595 |
|
|
if (cris_get_operand1 (inst) == REG_PC)
|
2596 |
|
|
{
|
2597 |
|
|
/* If the PC is to be incremented it's invalid to be in a
|
2598 |
|
|
delay slot. */
|
2599 |
|
|
if (inst_env->slot_needed)
|
2600 |
|
|
{
|
2601 |
|
|
inst_env->invalid = 1;
|
2602 |
|
|
return;
|
2603 |
|
|
}
|
2604 |
|
|
|
2605 |
|
|
/* The increment depends on the size of the special register. */
|
2606 |
|
|
if (cris_register_size (cris_get_operand2 (inst)) == 1)
|
2607 |
|
|
{
|
2608 |
|
|
process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
|
2609 |
|
|
}
|
2610 |
|
|
else if (cris_register_size (cris_get_operand2 (inst)) == 2)
|
2611 |
|
|
{
|
2612 |
|
|
process_autoincrement (INST_WORD_SIZE, inst, inst_env);
|
2613 |
|
|
}
|
2614 |
|
|
else
|
2615 |
|
|
{
|
2616 |
|
|
process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
|
2617 |
|
|
}
|
2618 |
|
|
}
|
2619 |
|
|
}
|
2620 |
|
|
inst_env->slot_needed = 0;
|
2621 |
|
|
inst_env->prefix_found = 0;
|
2622 |
|
|
inst_env->xflag_found = 0;
|
2623 |
|
|
inst_env->disable_interrupt = 1;
|
2624 |
|
|
}
|
2625 |
|
|
|
2626 |
|
|
/* Handles moves from special registers (aka P-register) for all modes
|
2627 |
|
|
except register. */
|
2628 |
|
|
|
2629 |
|
|
void
|
2630 |
|
|
none_reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
|
2631 |
|
|
{
|
2632 |
|
|
if (inst_env->prefix_found)
|
2633 |
|
|
{
|
2634 |
|
|
/* The instruction has a prefix that means we are only interested if
|
2635 |
|
|
the instruction is in assign mode. */
|
2636 |
|
|
if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
|
2637 |
|
|
{
|
2638 |
|
|
/* The prefix handles the problem if we are in a delay slot. */
|
2639 |
|
|
if (cris_get_operand1 (inst) == REG_PC)
|
2640 |
|
|
{
|
2641 |
|
|
/* Just take care of the assign. */
|
2642 |
|
|
check_assign (inst, inst_env);
|
2643 |
|
|
}
|
2644 |
|
|
}
|
2645 |
|
|
}
|
2646 |
|
|
/* The instruction doesn't have a prefix, the only case left that we
|
2647 |
|
|
are interested in is the autoincrement mode. */
|
2648 |
|
|
else if (cris_get_mode (inst) == AUTOINC_MODE)
|
2649 |
|
|
{
|
2650 |
|
|
if (cris_get_operand1 (inst) == REG_PC)
|
2651 |
|
|
{
|
2652 |
|
|
/* If the PC is to be incremented it's invalid to be in a
|
2653 |
|
|
delay slot. */
|
2654 |
|
|
if (inst_env->slot_needed)
|
2655 |
|
|
{
|
2656 |
|
|
inst_env->invalid = 1;
|
2657 |
|
|
return;
|
2658 |
|
|
}
|
2659 |
|
|
|
2660 |
|
|
/* The increment depends on the size of the special register. */
|
2661 |
|
|
if (cris_register_size (cris_get_operand2 (inst)) == 1)
|
2662 |
|
|
{
|
2663 |
|
|
process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
|
2664 |
|
|
}
|
2665 |
|
|
else if (cris_register_size (cris_get_operand2 (inst)) == 2)
|
2666 |
|
|
{
|
2667 |
|
|
process_autoincrement (INST_WORD_SIZE, inst, inst_env);
|
2668 |
|
|
}
|
2669 |
|
|
else
|
2670 |
|
|
{
|
2671 |
|
|
process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
|
2672 |
|
|
}
|
2673 |
|
|
}
|
2674 |
|
|
}
|
2675 |
|
|
inst_env->slot_needed = 0;
|
2676 |
|
|
inst_env->prefix_found = 0;
|
2677 |
|
|
inst_env->xflag_found = 0;
|
2678 |
|
|
inst_env->disable_interrupt = 1;
|
2679 |
|
|
}
|
2680 |
|
|
|
2681 |
|
|
/* Handles moves from special registers (aka P-register) when the mode
|
2682 |
|
|
is register. */
|
2683 |
|
|
|
2684 |
|
|
void
|
2685 |
|
|
reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
|
2686 |
|
|
{
|
2687 |
|
|
/* Register mode move from special register can't have a prefix. */
|
2688 |
|
|
if (inst_env->prefix_found)
|
2689 |
|
|
{
|
2690 |
|
|
inst_env->invalid = 1;
|
2691 |
|
|
return;
|
2692 |
|
|
}
|
2693 |
|
|
|
2694 |
|
|
if (cris_get_operand1 (inst) == REG_PC)
|
2695 |
|
|
{
|
2696 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2697 |
|
|
if (inst_env->slot_needed)
|
2698 |
|
|
{
|
2699 |
|
|
inst_env->invalid = 1;
|
2700 |
|
|
return;
|
2701 |
|
|
}
|
2702 |
|
|
/* The destination is the PC, the jump will have a delay slot. */
|
2703 |
|
|
inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
|
2704 |
|
|
inst_env->slot_needed = 1;
|
2705 |
|
|
inst_env->delay_slot_pc_active = 1;
|
2706 |
|
|
}
|
2707 |
|
|
else
|
2708 |
|
|
{
|
2709 |
|
|
/* If the destination isn't PC, there will be no jump. */
|
2710 |
|
|
inst_env->slot_needed = 0;
|
2711 |
|
|
}
|
2712 |
|
|
inst_env->prefix_found = 0;
|
2713 |
|
|
inst_env->xflag_found = 0;
|
2714 |
|
|
inst_env->disable_interrupt = 1;
|
2715 |
|
|
}
|
2716 |
|
|
|
2717 |
|
|
/* Handles the MOVEM from memory to general register instruction. */
|
2718 |
|
|
|
2719 |
|
|
void
|
2720 |
|
|
move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
|
2721 |
|
|
{
|
2722 |
|
|
if (inst_env->prefix_found)
|
2723 |
|
|
{
|
2724 |
|
|
/* The prefix handles the problem if we are in a delay slot. Is the
|
2725 |
|
|
MOVEM instruction going to change the PC? */
|
2726 |
|
|
if (cris_get_operand2 (inst) >= REG_PC)
|
2727 |
|
|
{
|
2728 |
|
|
inst_env->reg[REG_PC] =
|
2729 |
|
|
read_memory_unsigned_integer (inst_env->prefix_value, 4);
|
2730 |
|
|
}
|
2731 |
|
|
/* The assign value is the value after the increment. Normally, the
|
2732 |
|
|
assign value is the value before the increment. */
|
2733 |
|
|
if ((cris_get_operand1 (inst) == REG_PC)
|
2734 |
|
|
&& (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
|
2735 |
|
|
{
|
2736 |
|
|
inst_env->reg[REG_PC] = inst_env->prefix_value;
|
2737 |
|
|
inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
|
2738 |
|
|
}
|
2739 |
|
|
}
|
2740 |
|
|
else
|
2741 |
|
|
{
|
2742 |
|
|
/* Is the MOVEM instruction going to change the PC? */
|
2743 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2744 |
|
|
{
|
2745 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2746 |
|
|
if (inst_env->slot_needed)
|
2747 |
|
|
{
|
2748 |
|
|
inst_env->invalid = 1;
|
2749 |
|
|
return;
|
2750 |
|
|
}
|
2751 |
|
|
inst_env->reg[REG_PC] =
|
2752 |
|
|
read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
|
2753 |
|
|
4);
|
2754 |
|
|
}
|
2755 |
|
|
/* The increment is not depending on the size, instead it's depending
|
2756 |
|
|
on the number of registers loaded from memory. */
|
2757 |
|
|
if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
|
2758 |
|
|
{
|
2759 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2760 |
|
|
if (inst_env->slot_needed)
|
2761 |
|
|
{
|
2762 |
|
|
inst_env->invalid = 1;
|
2763 |
|
|
return;
|
2764 |
|
|
}
|
2765 |
|
|
inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
|
2766 |
|
|
}
|
2767 |
|
|
}
|
2768 |
|
|
inst_env->slot_needed = 0;
|
2769 |
|
|
inst_env->prefix_found = 0;
|
2770 |
|
|
inst_env->xflag_found = 0;
|
2771 |
|
|
inst_env->disable_interrupt = 0;
|
2772 |
|
|
}
|
2773 |
|
|
|
2774 |
|
|
/* Handles the MOVEM to memory from general register instruction. */
|
2775 |
|
|
|
2776 |
|
|
void
|
2777 |
|
|
move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
|
2778 |
|
|
{
|
2779 |
|
|
if (inst_env->prefix_found)
|
2780 |
|
|
{
|
2781 |
|
|
/* The assign value is the value after the increment. Normally, the
|
2782 |
|
|
assign value is the value before the increment. */
|
2783 |
|
|
if ((cris_get_operand1 (inst) == REG_PC) &&
|
2784 |
|
|
(cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
|
2785 |
|
|
{
|
2786 |
|
|
/* The prefix handles the problem if we are in a delay slot. */
|
2787 |
|
|
inst_env->reg[REG_PC] = inst_env->prefix_value;
|
2788 |
|
|
inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
|
2789 |
|
|
}
|
2790 |
|
|
}
|
2791 |
|
|
else
|
2792 |
|
|
{
|
2793 |
|
|
/* The increment is not depending on the size, instead it's depending
|
2794 |
|
|
on the number of registers loaded to memory. */
|
2795 |
|
|
if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
|
2796 |
|
|
{
|
2797 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2798 |
|
|
if (inst_env->slot_needed)
|
2799 |
|
|
{
|
2800 |
|
|
inst_env->invalid = 1;
|
2801 |
|
|
return;
|
2802 |
|
|
}
|
2803 |
|
|
inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
|
2804 |
|
|
}
|
2805 |
|
|
}
|
2806 |
|
|
inst_env->slot_needed = 0;
|
2807 |
|
|
inst_env->prefix_found = 0;
|
2808 |
|
|
inst_env->xflag_found = 0;
|
2809 |
|
|
inst_env->disable_interrupt = 0;
|
2810 |
|
|
}
|
2811 |
|
|
|
2812 |
|
|
/* Handles the pop instruction to a general register.
|
2813 |
|
|
POP is a assembler macro for MOVE.D [SP+], Rd. */
|
2814 |
|
|
|
2815 |
|
|
void
|
2816 |
|
|
reg_pop_op (unsigned short inst, inst_env_type *inst_env)
|
2817 |
|
|
{
|
2818 |
|
|
/* POP can't have a prefix. */
|
2819 |
|
|
if (inst_env->prefix_found)
|
2820 |
|
|
{
|
2821 |
|
|
inst_env->invalid = 1;
|
2822 |
|
|
return;
|
2823 |
|
|
}
|
2824 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2825 |
|
|
{
|
2826 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2827 |
|
|
if (inst_env->slot_needed)
|
2828 |
|
|
{
|
2829 |
|
|
inst_env->invalid = 1;
|
2830 |
|
|
return;
|
2831 |
|
|
}
|
2832 |
|
|
inst_env->reg[REG_PC] =
|
2833 |
|
|
read_memory_unsigned_integer (inst_env->reg[REG_SP], 4);
|
2834 |
|
|
}
|
2835 |
|
|
inst_env->slot_needed = 0;
|
2836 |
|
|
inst_env->prefix_found = 0;
|
2837 |
|
|
inst_env->xflag_found = 0;
|
2838 |
|
|
inst_env->disable_interrupt = 0;
|
2839 |
|
|
}
|
2840 |
|
|
|
2841 |
|
|
/* Handles moves from register to memory. */
|
2842 |
|
|
|
2843 |
|
|
void
|
2844 |
|
|
move_reg_to_mem_index_inc_op (unsigned short inst, inst_env_type *inst_env)
|
2845 |
|
|
{
|
2846 |
|
|
/* Check if we have a prefix. */
|
2847 |
|
|
if (inst_env->prefix_found)
|
2848 |
|
|
{
|
2849 |
|
|
/* The only thing that can change the PC is an assign. */
|
2850 |
|
|
check_assign (inst, inst_env);
|
2851 |
|
|
}
|
2852 |
|
|
else if ((cris_get_operand1 (inst) == REG_PC)
|
2853 |
|
|
&& (cris_get_mode (inst) == AUTOINC_MODE))
|
2854 |
|
|
{
|
2855 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2856 |
|
|
if (inst_env->slot_needed)
|
2857 |
|
|
{
|
2858 |
|
|
inst_env->invalid = 1;
|
2859 |
|
|
return;
|
2860 |
|
|
}
|
2861 |
|
|
process_autoincrement (cris_get_size (inst), inst, inst_env);
|
2862 |
|
|
}
|
2863 |
|
|
inst_env->slot_needed = 0;
|
2864 |
|
|
inst_env->prefix_found = 0;
|
2865 |
|
|
inst_env->xflag_found = 0;
|
2866 |
|
|
inst_env->disable_interrupt = 0;
|
2867 |
|
|
}
|
2868 |
|
|
|
2869 |
|
|
/* Handles the intructions that's not yet implemented, by setting
|
2870 |
|
|
inst_env->invalid to true. */
|
2871 |
|
|
|
2872 |
|
|
void
|
2873 |
|
|
not_implemented_op (unsigned short inst, inst_env_type *inst_env)
|
2874 |
|
|
{
|
2875 |
|
|
inst_env->invalid = 1;
|
2876 |
|
|
}
|
2877 |
|
|
|
2878 |
|
|
/* Handles the XOR instruction. */
|
2879 |
|
|
|
2880 |
|
|
void
|
2881 |
|
|
xor_op (unsigned short inst, inst_env_type *inst_env)
|
2882 |
|
|
{
|
2883 |
|
|
/* XOR can't have a prefix. */
|
2884 |
|
|
if (inst_env->prefix_found)
|
2885 |
|
|
{
|
2886 |
|
|
inst_env->invalid = 1;
|
2887 |
|
|
return;
|
2888 |
|
|
}
|
2889 |
|
|
|
2890 |
|
|
/* Check if the PC is the target. */
|
2891 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2892 |
|
|
{
|
2893 |
|
|
/* It's invalid to change the PC in a delay slot. */
|
2894 |
|
|
if (inst_env->slot_needed)
|
2895 |
|
|
{
|
2896 |
|
|
inst_env->invalid = 1;
|
2897 |
|
|
return;
|
2898 |
|
|
}
|
2899 |
|
|
inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
|
2900 |
|
|
}
|
2901 |
|
|
inst_env->slot_needed = 0;
|
2902 |
|
|
inst_env->prefix_found = 0;
|
2903 |
|
|
inst_env->xflag_found = 0;
|
2904 |
|
|
inst_env->disable_interrupt = 0;
|
2905 |
|
|
}
|
2906 |
|
|
|
2907 |
|
|
/* Handles the MULS instruction. */
|
2908 |
|
|
|
2909 |
|
|
void
|
2910 |
|
|
muls_op (unsigned short inst, inst_env_type *inst_env)
|
2911 |
|
|
{
|
2912 |
|
|
/* MULS/U can't have a prefix. */
|
2913 |
|
|
if (inst_env->prefix_found)
|
2914 |
|
|
{
|
2915 |
|
|
inst_env->invalid = 1;
|
2916 |
|
|
return;
|
2917 |
|
|
}
|
2918 |
|
|
|
2919 |
|
|
/* Consider it invalid if the PC is the target. */
|
2920 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2921 |
|
|
{
|
2922 |
|
|
inst_env->invalid = 1;
|
2923 |
|
|
return;
|
2924 |
|
|
}
|
2925 |
|
|
inst_env->slot_needed = 0;
|
2926 |
|
|
inst_env->prefix_found = 0;
|
2927 |
|
|
inst_env->xflag_found = 0;
|
2928 |
|
|
inst_env->disable_interrupt = 0;
|
2929 |
|
|
}
|
2930 |
|
|
|
2931 |
|
|
/* Handles the MULU instruction. */
|
2932 |
|
|
|
2933 |
|
|
void
|
2934 |
|
|
mulu_op (unsigned short inst, inst_env_type *inst_env)
|
2935 |
|
|
{
|
2936 |
|
|
/* MULS/U can't have a prefix. */
|
2937 |
|
|
if (inst_env->prefix_found)
|
2938 |
|
|
{
|
2939 |
|
|
inst_env->invalid = 1;
|
2940 |
|
|
return;
|
2941 |
|
|
}
|
2942 |
|
|
|
2943 |
|
|
/* Consider it invalid if the PC is the target. */
|
2944 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
2945 |
|
|
{
|
2946 |
|
|
inst_env->invalid = 1;
|
2947 |
|
|
return;
|
2948 |
|
|
}
|
2949 |
|
|
inst_env->slot_needed = 0;
|
2950 |
|
|
inst_env->prefix_found = 0;
|
2951 |
|
|
inst_env->xflag_found = 0;
|
2952 |
|
|
inst_env->disable_interrupt = 0;
|
2953 |
|
|
}
|
2954 |
|
|
|
2955 |
|
|
/* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
|
2956 |
|
|
The MOVE instruction is the move from source to register. */
|
2957 |
|
|
|
2958 |
|
|
void
|
2959 |
|
|
add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
|
2960 |
|
|
unsigned long source1, unsigned long source2)
|
2961 |
|
|
{
|
2962 |
|
|
unsigned long pc_mask;
|
2963 |
|
|
unsigned long operation_mask;
|
2964 |
|
|
|
2965 |
|
|
/* Find out how many bits the operation should apply to. */
|
2966 |
|
|
if (cris_get_size (inst) == INST_BYTE_SIZE)
|
2967 |
|
|
{
|
2968 |
|
|
pc_mask = 0xFFFFFF00;
|
2969 |
|
|
operation_mask = 0xFF;
|
2970 |
|
|
}
|
2971 |
|
|
else if (cris_get_size (inst) == INST_WORD_SIZE)
|
2972 |
|
|
{
|
2973 |
|
|
pc_mask = 0xFFFF0000;
|
2974 |
|
|
operation_mask = 0xFFFF;
|
2975 |
|
|
}
|
2976 |
|
|
else if (cris_get_size (inst) == INST_DWORD_SIZE)
|
2977 |
|
|
{
|
2978 |
|
|
pc_mask = 0x0;
|
2979 |
|
|
operation_mask = 0xFFFFFFFF;
|
2980 |
|
|
}
|
2981 |
|
|
else
|
2982 |
|
|
{
|
2983 |
|
|
/* The size is out of range. */
|
2984 |
|
|
inst_env->invalid = 1;
|
2985 |
|
|
return;
|
2986 |
|
|
}
|
2987 |
|
|
|
2988 |
|
|
/* The instruction just works on uw_operation_mask bits. */
|
2989 |
|
|
source2 &= operation_mask;
|
2990 |
|
|
source1 &= operation_mask;
|
2991 |
|
|
|
2992 |
|
|
/* Now calculate the result. The opcode's 3 first bits separates
|
2993 |
|
|
the different actions. */
|
2994 |
|
|
switch (cris_get_opcode (inst) & 7)
|
2995 |
|
|
{
|
2996 |
|
|
case 0: /* add */
|
2997 |
|
|
source1 += source2;
|
2998 |
|
|
break;
|
2999 |
|
|
|
3000 |
|
|
case 1: /* move */
|
3001 |
|
|
source1 = source2;
|
3002 |
|
|
break;
|
3003 |
|
|
|
3004 |
|
|
case 2: /* subtract */
|
3005 |
|
|
source1 -= source2;
|
3006 |
|
|
break;
|
3007 |
|
|
|
3008 |
|
|
case 3: /* compare */
|
3009 |
|
|
break;
|
3010 |
|
|
|
3011 |
|
|
case 4: /* and */
|
3012 |
|
|
source1 &= source2;
|
3013 |
|
|
break;
|
3014 |
|
|
|
3015 |
|
|
case 5: /* or */
|
3016 |
|
|
source1 |= source2;
|
3017 |
|
|
break;
|
3018 |
|
|
|
3019 |
|
|
default:
|
3020 |
|
|
inst_env->invalid = 1;
|
3021 |
|
|
return;
|
3022 |
|
|
|
3023 |
|
|
break;
|
3024 |
|
|
}
|
3025 |
|
|
|
3026 |
|
|
/* Make sure that the result doesn't contain more than the instruction
|
3027 |
|
|
size bits. */
|
3028 |
|
|
source2 &= operation_mask;
|
3029 |
|
|
|
3030 |
|
|
/* Calculate the new breakpoint address. */
|
3031 |
|
|
inst_env->reg[REG_PC] &= pc_mask;
|
3032 |
|
|
inst_env->reg[REG_PC] |= source1;
|
3033 |
|
|
|
3034 |
|
|
}
|
3035 |
|
|
|
3036 |
|
|
/* Extends the value from either byte or word size to a dword. If the mode
|
3037 |
|
|
is zero extend then the value is extended with zero. If instead the mode
|
3038 |
|
|
is signed extend the sign bit of the value is taken into consideration. */
|
3039 |
|
|
|
3040 |
|
|
unsigned long
|
3041 |
|
|
do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
|
3042 |
|
|
{
|
3043 |
|
|
/* The size can be either byte or word, check which one it is.
|
3044 |
|
|
Don't check the highest bit, it's indicating if it's a zero
|
3045 |
|
|
or sign extend. */
|
3046 |
|
|
if (cris_get_size (*inst) & INST_WORD_SIZE)
|
3047 |
|
|
{
|
3048 |
|
|
/* Word size. */
|
3049 |
|
|
value &= 0xFFFF;
|
3050 |
|
|
|
3051 |
|
|
/* Check if the instruction is signed extend. If so, check if value has
|
3052 |
|
|
the sign bit on. */
|
3053 |
|
|
if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
|
3054 |
|
|
{
|
3055 |
|
|
value |= SIGNED_WORD_EXTEND_MASK;
|
3056 |
|
|
}
|
3057 |
|
|
}
|
3058 |
|
|
else
|
3059 |
|
|
{
|
3060 |
|
|
/* Byte size. */
|
3061 |
|
|
value &= 0xFF;
|
3062 |
|
|
|
3063 |
|
|
/* Check if the instruction is signed extend. If so, check if value has
|
3064 |
|
|
the sign bit on. */
|
3065 |
|
|
if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
|
3066 |
|
|
{
|
3067 |
|
|
value |= SIGNED_BYTE_EXTEND_MASK;
|
3068 |
|
|
}
|
3069 |
|
|
}
|
3070 |
|
|
/* The size should now be dword. */
|
3071 |
|
|
cris_set_size_to_dword (inst);
|
3072 |
|
|
return value;
|
3073 |
|
|
}
|
3074 |
|
|
|
3075 |
|
|
/* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
|
3076 |
|
|
instruction. The MOVE instruction is the move from source to register. */
|
3077 |
|
|
|
3078 |
|
|
void
|
3079 |
|
|
reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
|
3080 |
|
|
inst_env_type *inst_env)
|
3081 |
|
|
{
|
3082 |
|
|
unsigned long operand1;
|
3083 |
|
|
unsigned long operand2;
|
3084 |
|
|
|
3085 |
|
|
/* It's invalid to have a prefix to the instruction. This is a register
|
3086 |
|
|
mode instruction and can't have a prefix. */
|
3087 |
|
|
if (inst_env->prefix_found)
|
3088 |
|
|
{
|
3089 |
|
|
inst_env->invalid = 1;
|
3090 |
|
|
return;
|
3091 |
|
|
}
|
3092 |
|
|
/* Check if the instruction has PC as its target. */
|
3093 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
3094 |
|
|
{
|
3095 |
|
|
if (inst_env->slot_needed)
|
3096 |
|
|
{
|
3097 |
|
|
inst_env->invalid = 1;
|
3098 |
|
|
return;
|
3099 |
|
|
}
|
3100 |
|
|
/* The instruction has the PC as its target register. */
|
3101 |
|
|
operand1 = inst_env->reg[cris_get_operand1 (inst)];
|
3102 |
|
|
operand2 = inst_env->reg[REG_PC];
|
3103 |
|
|
|
3104 |
|
|
/* Check if it's a extend, signed or zero instruction. */
|
3105 |
|
|
if (cris_get_opcode (inst) < 4)
|
3106 |
|
|
{
|
3107 |
|
|
operand1 = do_sign_or_zero_extend (operand1, &inst);
|
3108 |
|
|
}
|
3109 |
|
|
/* Calculate the PC value after the instruction, i.e. where the
|
3110 |
|
|
breakpoint should be. The order of the udw_operands is vital. */
|
3111 |
|
|
add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
|
3112 |
|
|
}
|
3113 |
|
|
inst_env->slot_needed = 0;
|
3114 |
|
|
inst_env->prefix_found = 0;
|
3115 |
|
|
inst_env->xflag_found = 0;
|
3116 |
|
|
inst_env->disable_interrupt = 0;
|
3117 |
|
|
}
|
3118 |
|
|
|
3119 |
|
|
/* Returns the data contained at address. The size of the data is derived from
|
3120 |
|
|
the size of the operation. If the instruction is a zero or signed
|
3121 |
|
|
extend instruction, the size field is changed in instruction. */
|
3122 |
|
|
|
3123 |
|
|
unsigned long
|
3124 |
|
|
get_data_from_address (unsigned short *inst, CORE_ADDR address)
|
3125 |
|
|
{
|
3126 |
|
|
int size = cris_get_size (*inst);
|
3127 |
|
|
unsigned long value;
|
3128 |
|
|
|
3129 |
|
|
/* If it's an extend instruction we don't want the signed extend bit,
|
3130 |
|
|
because it influences the size. */
|
3131 |
|
|
if (cris_get_opcode (*inst) < 4)
|
3132 |
|
|
{
|
3133 |
|
|
size &= ~SIGNED_EXTEND_BIT_MASK;
|
3134 |
|
|
}
|
3135 |
|
|
/* Is there a need for checking the size? Size should contain the number of
|
3136 |
|
|
bytes to read. */
|
3137 |
|
|
size = 1 << size;
|
3138 |
|
|
value = read_memory_unsigned_integer (address, size);
|
3139 |
|
|
|
3140 |
|
|
/* Check if it's an extend, signed or zero instruction. */
|
3141 |
|
|
if (cris_get_opcode (*inst) < 4)
|
3142 |
|
|
{
|
3143 |
|
|
value = do_sign_or_zero_extend (value, inst);
|
3144 |
|
|
}
|
3145 |
|
|
return value;
|
3146 |
|
|
}
|
3147 |
|
|
|
3148 |
|
|
/* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
|
3149 |
|
|
instructions. The MOVE instruction is the move from source to register. */
|
3150 |
|
|
|
3151 |
|
|
void
|
3152 |
|
|
handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
|
3153 |
|
|
inst_env_type *inst_env)
|
3154 |
|
|
{
|
3155 |
|
|
unsigned long operand2;
|
3156 |
|
|
unsigned long operand3;
|
3157 |
|
|
|
3158 |
|
|
check_assign (inst, inst_env);
|
3159 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
3160 |
|
|
{
|
3161 |
|
|
operand2 = inst_env->reg[REG_PC];
|
3162 |
|
|
|
3163 |
|
|
/* Get the value of the third operand. */
|
3164 |
|
|
operand3 = get_data_from_address (&inst, inst_env->prefix_value);
|
3165 |
|
|
|
3166 |
|
|
/* Calculate the PC value after the instruction, i.e. where the
|
3167 |
|
|
breakpoint should be. The order of the udw_operands is vital. */
|
3168 |
|
|
add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
|
3169 |
|
|
}
|
3170 |
|
|
inst_env->slot_needed = 0;
|
3171 |
|
|
inst_env->prefix_found = 0;
|
3172 |
|
|
inst_env->xflag_found = 0;
|
3173 |
|
|
inst_env->disable_interrupt = 0;
|
3174 |
|
|
}
|
3175 |
|
|
|
3176 |
|
|
/* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
|
3177 |
|
|
OR instructions. Note that for this to work as expected, the calling
|
3178 |
|
|
function must have made sure that there is a prefix to this instruction. */
|
3179 |
|
|
|
3180 |
|
|
void
|
3181 |
|
|
three_operand_add_sub_cmp_and_or_op (unsigned short inst,
|
3182 |
|
|
inst_env_type *inst_env)
|
3183 |
|
|
{
|
3184 |
|
|
unsigned long operand2;
|
3185 |
|
|
unsigned long operand3;
|
3186 |
|
|
|
3187 |
|
|
if (cris_get_operand1 (inst) == REG_PC)
|
3188 |
|
|
{
|
3189 |
|
|
/* The PC will be changed by the instruction. */
|
3190 |
|
|
operand2 = inst_env->reg[cris_get_operand2 (inst)];
|
3191 |
|
|
|
3192 |
|
|
/* Get the value of the third operand. */
|
3193 |
|
|
operand3 = get_data_from_address (&inst, inst_env->prefix_value);
|
3194 |
|
|
|
3195 |
|
|
/* Calculate the PC value after the instruction, i.e. where the
|
3196 |
|
|
breakpoint should be. */
|
3197 |
|
|
add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
|
3198 |
|
|
}
|
3199 |
|
|
inst_env->slot_needed = 0;
|
3200 |
|
|
inst_env->prefix_found = 0;
|
3201 |
|
|
inst_env->xflag_found = 0;
|
3202 |
|
|
inst_env->disable_interrupt = 0;
|
3203 |
|
|
}
|
3204 |
|
|
|
3205 |
|
|
/* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
|
3206 |
|
|
instructions. The MOVE instruction is the move from source to register. */
|
3207 |
|
|
|
3208 |
|
|
void
|
3209 |
|
|
handle_prefix_index_mode_for_aritm_op (unsigned short inst,
|
3210 |
|
|
inst_env_type *inst_env)
|
3211 |
|
|
{
|
3212 |
|
|
if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
|
3213 |
|
|
{
|
3214 |
|
|
/* If the instruction is MOVE it's invalid. If the instruction is ADD,
|
3215 |
|
|
SUB, AND or OR something weird is going on (if everything works these
|
3216 |
|
|
instructions should end up in the three operand version). */
|
3217 |
|
|
inst_env->invalid = 1;
|
3218 |
|
|
return;
|
3219 |
|
|
}
|
3220 |
|
|
else
|
3221 |
|
|
{
|
3222 |
|
|
/* three_operand_add_sub_cmp_and_or does the same as we should do here
|
3223 |
|
|
so use it. */
|
3224 |
|
|
three_operand_add_sub_cmp_and_or_op (inst, inst_env);
|
3225 |
|
|
}
|
3226 |
|
|
inst_env->slot_needed = 0;
|
3227 |
|
|
inst_env->prefix_found = 0;
|
3228 |
|
|
inst_env->xflag_found = 0;
|
3229 |
|
|
inst_env->disable_interrupt = 0;
|
3230 |
|
|
}
|
3231 |
|
|
|
3232 |
|
|
/* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
|
3233 |
|
|
CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
|
3234 |
|
|
source to register. */
|
3235 |
|
|
|
3236 |
|
|
void
|
3237 |
|
|
handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
|
3238 |
|
|
inst_env_type *inst_env)
|
3239 |
|
|
{
|
3240 |
|
|
unsigned long operand1;
|
3241 |
|
|
unsigned long operand2;
|
3242 |
|
|
unsigned long operand3;
|
3243 |
|
|
int size;
|
3244 |
|
|
|
3245 |
|
|
/* The instruction is either an indirect or autoincrement addressing mode.
|
3246 |
|
|
Check if the destination register is the PC. */
|
3247 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
3248 |
|
|
{
|
3249 |
|
|
/* Must be done here, get_data_from_address may change the size
|
3250 |
|
|
field. */
|
3251 |
|
|
size = cris_get_size (inst);
|
3252 |
|
|
operand2 = inst_env->reg[REG_PC];
|
3253 |
|
|
|
3254 |
|
|
/* Get the value of the third operand, i.e. the indirect operand. */
|
3255 |
|
|
operand1 = inst_env->reg[cris_get_operand1 (inst)];
|
3256 |
|
|
operand3 = get_data_from_address (&inst, operand1);
|
3257 |
|
|
|
3258 |
|
|
/* Calculate the PC value after the instruction, i.e. where the
|
3259 |
|
|
breakpoint should be. The order of the udw_operands is vital. */
|
3260 |
|
|
add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
|
3261 |
|
|
}
|
3262 |
|
|
/* If this is an autoincrement addressing mode, check if the increment
|
3263 |
|
|
changes the PC. */
|
3264 |
|
|
if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
|
3265 |
|
|
{
|
3266 |
|
|
/* Get the size field. */
|
3267 |
|
|
size = cris_get_size (inst);
|
3268 |
|
|
|
3269 |
|
|
/* If it's an extend instruction we don't want the signed extend bit,
|
3270 |
|
|
because it influences the size. */
|
3271 |
|
|
if (cris_get_opcode (inst) < 4)
|
3272 |
|
|
{
|
3273 |
|
|
size &= ~SIGNED_EXTEND_BIT_MASK;
|
3274 |
|
|
}
|
3275 |
|
|
process_autoincrement (size, inst, inst_env);
|
3276 |
|
|
}
|
3277 |
|
|
inst_env->slot_needed = 0;
|
3278 |
|
|
inst_env->prefix_found = 0;
|
3279 |
|
|
inst_env->xflag_found = 0;
|
3280 |
|
|
inst_env->disable_interrupt = 0;
|
3281 |
|
|
}
|
3282 |
|
|
|
3283 |
|
|
/* Handles the two-operand addressing mode, all modes except register, for
|
3284 |
|
|
the ADD, SUB CMP, AND and OR instruction. */
|
3285 |
|
|
|
3286 |
|
|
void
|
3287 |
|
|
none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
|
3288 |
|
|
inst_env_type *inst_env)
|
3289 |
|
|
{
|
3290 |
|
|
if (inst_env->prefix_found)
|
3291 |
|
|
{
|
3292 |
|
|
if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
|
3293 |
|
|
{
|
3294 |
|
|
handle_prefix_index_mode_for_aritm_op (inst, inst_env);
|
3295 |
|
|
}
|
3296 |
|
|
else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
|
3297 |
|
|
{
|
3298 |
|
|
handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
|
3299 |
|
|
}
|
3300 |
|
|
else
|
3301 |
|
|
{
|
3302 |
|
|
/* The mode is invalid for a prefixed base instruction. */
|
3303 |
|
|
inst_env->invalid = 1;
|
3304 |
|
|
return;
|
3305 |
|
|
}
|
3306 |
|
|
}
|
3307 |
|
|
else
|
3308 |
|
|
{
|
3309 |
|
|
handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
|
3310 |
|
|
}
|
3311 |
|
|
}
|
3312 |
|
|
|
3313 |
|
|
/* Handles the quick addressing mode for the ADD and SUB instruction. */
|
3314 |
|
|
|
3315 |
|
|
void
|
3316 |
|
|
quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
|
3317 |
|
|
{
|
3318 |
|
|
unsigned long operand1;
|
3319 |
|
|
unsigned long operand2;
|
3320 |
|
|
|
3321 |
|
|
/* It's a bad idea to be in a prefix instruction now. This is a quick mode
|
3322 |
|
|
instruction and can't have a prefix. */
|
3323 |
|
|
if (inst_env->prefix_found)
|
3324 |
|
|
{
|
3325 |
|
|
inst_env->invalid = 1;
|
3326 |
|
|
return;
|
3327 |
|
|
}
|
3328 |
|
|
|
3329 |
|
|
/* Check if the instruction has PC as its target. */
|
3330 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
3331 |
|
|
{
|
3332 |
|
|
if (inst_env->slot_needed)
|
3333 |
|
|
{
|
3334 |
|
|
inst_env->invalid = 1;
|
3335 |
|
|
return;
|
3336 |
|
|
}
|
3337 |
|
|
operand1 = cris_get_quick_value (inst);
|
3338 |
|
|
operand2 = inst_env->reg[REG_PC];
|
3339 |
|
|
|
3340 |
|
|
/* The size should now be dword. */
|
3341 |
|
|
cris_set_size_to_dword (&inst);
|
3342 |
|
|
|
3343 |
|
|
/* Calculate the PC value after the instruction, i.e. where the
|
3344 |
|
|
breakpoint should be. */
|
3345 |
|
|
add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
|
3346 |
|
|
}
|
3347 |
|
|
inst_env->slot_needed = 0;
|
3348 |
|
|
inst_env->prefix_found = 0;
|
3349 |
|
|
inst_env->xflag_found = 0;
|
3350 |
|
|
inst_env->disable_interrupt = 0;
|
3351 |
|
|
}
|
3352 |
|
|
|
3353 |
|
|
/* Handles the quick addressing mode for the CMP, AND and OR instruction. */
|
3354 |
|
|
|
3355 |
|
|
void
|
3356 |
|
|
quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
|
3357 |
|
|
{
|
3358 |
|
|
unsigned long operand1;
|
3359 |
|
|
unsigned long operand2;
|
3360 |
|
|
|
3361 |
|
|
/* It's a bad idea to be in a prefix instruction now. This is a quick mode
|
3362 |
|
|
instruction and can't have a prefix. */
|
3363 |
|
|
if (inst_env->prefix_found)
|
3364 |
|
|
{
|
3365 |
|
|
inst_env->invalid = 1;
|
3366 |
|
|
return;
|
3367 |
|
|
}
|
3368 |
|
|
/* Check if the instruction has PC as its target. */
|
3369 |
|
|
if (cris_get_operand2 (inst) == REG_PC)
|
3370 |
|
|
{
|
3371 |
|
|
if (inst_env->slot_needed)
|
3372 |
|
|
{
|
3373 |
|
|
inst_env->invalid = 1;
|
3374 |
|
|
return;
|
3375 |
|
|
}
|
3376 |
|
|
/* The instruction has the PC as its target register. */
|
3377 |
|
|
operand1 = cris_get_quick_value (inst);
|
3378 |
|
|
operand2 = inst_env->reg[REG_PC];
|
3379 |
|
|
|
3380 |
|
|
/* The quick value is signed, so check if we must do a signed extend. */
|
3381 |
|
|
if (operand1 & SIGNED_QUICK_VALUE_MASK)
|
3382 |
|
|
{
|
3383 |
|
|
/* sign extend */
|
3384 |
|
|
operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
|
3385 |
|
|
}
|
3386 |
|
|
/* The size should now be dword. */
|
3387 |
|
|
cris_set_size_to_dword (&inst);
|
3388 |
|
|
|
3389 |
|
|
/* Calculate the PC value after the instruction, i.e. where the
|
3390 |
|
|
breakpoint should be. */
|
3391 |
|
|
add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
|
3392 |
|
|
}
|
3393 |
|
|
inst_env->slot_needed = 0;
|
3394 |
|
|
inst_env->prefix_found = 0;
|
3395 |
|
|
inst_env->xflag_found = 0;
|
3396 |
|
|
inst_env->disable_interrupt = 0;
|
3397 |
|
|
}
|
3398 |
|
|
|
3399 |
|
|
/* Translate op_type to a function and call it. */
|
3400 |
|
|
|
3401 |
|
|
static void cris_gdb_func (enum cris_op_type op_type, unsigned short inst,
|
3402 |
|
|
inst_env_type *inst_env)
|
3403 |
|
|
{
|
3404 |
|
|
switch (op_type)
|
3405 |
|
|
{
|
3406 |
|
|
case cris_not_implemented_op:
|
3407 |
|
|
not_implemented_op (inst, inst_env);
|
3408 |
|
|
break;
|
3409 |
|
|
|
3410 |
|
|
case cris_abs_op:
|
3411 |
|
|
abs_op (inst, inst_env);
|
3412 |
|
|
break;
|
3413 |
|
|
|
3414 |
|
|
case cris_addi_op:
|
3415 |
|
|
addi_op (inst, inst_env);
|
3416 |
|
|
break;
|
3417 |
|
|
|
3418 |
|
|
case cris_asr_op:
|
3419 |
|
|
asr_op (inst, inst_env);
|
3420 |
|
|
break;
|
3421 |
|
|
|
3422 |
|
|
case cris_asrq_op:
|
3423 |
|
|
asrq_op (inst, inst_env);
|
3424 |
|
|
break;
|
3425 |
|
|
|
3426 |
|
|
case cris_ax_ei_setf_op:
|
3427 |
|
|
ax_ei_setf_op (inst, inst_env);
|
3428 |
|
|
break;
|
3429 |
|
|
|
3430 |
|
|
case cris_bdap_prefix:
|
3431 |
|
|
bdap_prefix (inst, inst_env);
|
3432 |
|
|
break;
|
3433 |
|
|
|
3434 |
|
|
case cris_biap_prefix:
|
3435 |
|
|
biap_prefix (inst, inst_env);
|
3436 |
|
|
break;
|
3437 |
|
|
|
3438 |
|
|
case cris_break_op:
|
3439 |
|
|
break_op (inst, inst_env);
|
3440 |
|
|
break;
|
3441 |
|
|
|
3442 |
|
|
case cris_btst_nop_op:
|
3443 |
|
|
btst_nop_op (inst, inst_env);
|
3444 |
|
|
break;
|
3445 |
|
|
|
3446 |
|
|
case cris_clearf_di_op:
|
3447 |
|
|
clearf_di_op (inst, inst_env);
|
3448 |
|
|
break;
|
3449 |
|
|
|
3450 |
|
|
case cris_dip_prefix:
|
3451 |
|
|
dip_prefix (inst, inst_env);
|
3452 |
|
|
break;
|
3453 |
|
|
|
3454 |
|
|
case cris_dstep_logshift_mstep_neg_not_op:
|
3455 |
|
|
dstep_logshift_mstep_neg_not_op (inst, inst_env);
|
3456 |
|
|
break;
|
3457 |
|
|
|
3458 |
|
|
case cris_eight_bit_offset_branch_op:
|
3459 |
|
|
eight_bit_offset_branch_op (inst, inst_env);
|
3460 |
|
|
break;
|
3461 |
|
|
|
3462 |
|
|
case cris_move_mem_to_reg_movem_op:
|
3463 |
|
|
move_mem_to_reg_movem_op (inst, inst_env);
|
3464 |
|
|
break;
|
3465 |
|
|
|
3466 |
|
|
case cris_move_reg_to_mem_movem_op:
|
3467 |
|
|
move_reg_to_mem_movem_op (inst, inst_env);
|
3468 |
|
|
break;
|
3469 |
|
|
|
3470 |
|
|
case cris_move_to_preg_op:
|
3471 |
|
|
move_to_preg_op (inst, inst_env);
|
3472 |
|
|
break;
|
3473 |
|
|
|
3474 |
|
|
case cris_muls_op:
|
3475 |
|
|
muls_op (inst, inst_env);
|
3476 |
|
|
break;
|
3477 |
|
|
|
3478 |
|
|
case cris_mulu_op:
|
3479 |
|
|
mulu_op (inst, inst_env);
|
3480 |
|
|
break;
|
3481 |
|
|
|
3482 |
|
|
case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
|
3483 |
|
|
none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
|
3484 |
|
|
break;
|
3485 |
|
|
|
3486 |
|
|
case cris_none_reg_mode_clear_test_op:
|
3487 |
|
|
none_reg_mode_clear_test_op (inst, inst_env);
|
3488 |
|
|
break;
|
3489 |
|
|
|
3490 |
|
|
case cris_none_reg_mode_jump_op:
|
3491 |
|
|
none_reg_mode_jump_op (inst, inst_env);
|
3492 |
|
|
break;
|
3493 |
|
|
|
3494 |
|
|
case cris_none_reg_mode_move_from_preg_op:
|
3495 |
|
|
none_reg_mode_move_from_preg_op (inst, inst_env);
|
3496 |
|
|
break;
|
3497 |
|
|
|
3498 |
|
|
case cris_quick_mode_add_sub_op:
|
3499 |
|
|
quick_mode_add_sub_op (inst, inst_env);
|
3500 |
|
|
break;
|
3501 |
|
|
|
3502 |
|
|
case cris_quick_mode_and_cmp_move_or_op:
|
3503 |
|
|
quick_mode_and_cmp_move_or_op (inst, inst_env);
|
3504 |
|
|
break;
|
3505 |
|
|
|
3506 |
|
|
case cris_quick_mode_bdap_prefix:
|
3507 |
|
|
quick_mode_bdap_prefix (inst, inst_env);
|
3508 |
|
|
break;
|
3509 |
|
|
|
3510 |
|
|
case cris_reg_mode_add_sub_cmp_and_or_move_op:
|
3511 |
|
|
reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
|
3512 |
|
|
break;
|
3513 |
|
|
|
3514 |
|
|
case cris_reg_mode_clear_op:
|
3515 |
|
|
reg_mode_clear_op (inst, inst_env);
|
3516 |
|
|
break;
|
3517 |
|
|
|
3518 |
|
|
case cris_reg_mode_jump_op:
|
3519 |
|
|
reg_mode_jump_op (inst, inst_env);
|
3520 |
|
|
break;
|
3521 |
|
|
|
3522 |
|
|
case cris_reg_mode_move_from_preg_op:
|
3523 |
|
|
reg_mode_move_from_preg_op (inst, inst_env);
|
3524 |
|
|
break;
|
3525 |
|
|
|
3526 |
|
|
case cris_reg_mode_test_op:
|
3527 |
|
|
reg_mode_test_op (inst, inst_env);
|
3528 |
|
|
break;
|
3529 |
|
|
|
3530 |
|
|
case cris_scc_op:
|
3531 |
|
|
scc_op (inst, inst_env);
|
3532 |
|
|
break;
|
3533 |
|
|
|
3534 |
|
|
case cris_sixteen_bit_offset_branch_op:
|
3535 |
|
|
sixteen_bit_offset_branch_op (inst, inst_env);
|
3536 |
|
|
break;
|
3537 |
|
|
|
3538 |
|
|
case cris_three_operand_add_sub_cmp_and_or_op:
|
3539 |
|
|
three_operand_add_sub_cmp_and_or_op (inst, inst_env);
|
3540 |
|
|
break;
|
3541 |
|
|
|
3542 |
|
|
case cris_three_operand_bound_op:
|
3543 |
|
|
three_operand_bound_op (inst, inst_env);
|
3544 |
|
|
break;
|
3545 |
|
|
|
3546 |
|
|
case cris_two_operand_bound_op:
|
3547 |
|
|
two_operand_bound_op (inst, inst_env);
|
3548 |
|
|
break;
|
3549 |
|
|
|
3550 |
|
|
case cris_xor_op:
|
3551 |
|
|
xor_op (inst, inst_env);
|
3552 |
|
|
break;
|
3553 |
|
|
}
|
3554 |
|
|
}
|
3555 |
|
|
|
3556 |
|
|
/* This wrapper is to avoid cris_get_assembler being called before
|
3557 |
|
|
exec_bfd has been set. */
|
3558 |
|
|
|
3559 |
|
|
static int
|
3560 |
|
|
cris_delayed_get_disassembler (bfd_vma addr, disassemble_info *info)
|
3561 |
|
|
{
|
3562 |
|
|
tm_print_insn = cris_get_disassembler (exec_bfd);
|
3563 |
|
|
return TARGET_PRINT_INSN (addr, info);
|
3564 |
|
|
}
|
3565 |
|
|
|
3566 |
|
|
/* Copied from <asm/elf.h>. */
|
3567 |
|
|
typedef unsigned long elf_greg_t;
|
3568 |
|
|
|
3569 |
|
|
/* Same as user_regs_struct struct in <asm/user.h>. */
|
3570 |
|
|
typedef elf_greg_t elf_gregset_t[35];
|
3571 |
|
|
|
3572 |
|
|
/* Unpack an elf_gregset_t into GDB's register cache. */
|
3573 |
|
|
|
3574 |
|
|
void
|
3575 |
|
|
supply_gregset (elf_gregset_t *gregsetp)
|
3576 |
|
|
{
|
3577 |
|
|
int i;
|
3578 |
|
|
elf_greg_t *regp = *gregsetp;
|
3579 |
|
|
static char zerobuf[4] = {0};
|
3580 |
|
|
|
3581 |
|
|
/* The kernel dumps all 32 registers as unsigned longs, but supply_register
|
3582 |
|
|
knows about the actual size of each register so that's no problem. */
|
3583 |
|
|
for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
|
3584 |
|
|
{
|
3585 |
|
|
supply_register (i, (char *)®p[i]);
|
3586 |
|
|
}
|
3587 |
|
|
}
|
3588 |
|
|
|
3589 |
|
|
/* Use a local version of this function to get the correct types for
|
3590 |
|
|
regsets, until multi-arch core support is ready. */
|
3591 |
|
|
|
3592 |
|
|
static void
|
3593 |
|
|
fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
|
3594 |
|
|
int which, CORE_ADDR reg_addr)
|
3595 |
|
|
{
|
3596 |
|
|
elf_gregset_t gregset;
|
3597 |
|
|
|
3598 |
|
|
switch (which)
|
3599 |
|
|
{
|
3600 |
|
|
case 0:
|
3601 |
|
|
if (core_reg_size != sizeof (gregset))
|
3602 |
|
|
{
|
3603 |
|
|
warning ("wrong size gregset struct in core file");
|
3604 |
|
|
}
|
3605 |
|
|
else
|
3606 |
|
|
{
|
3607 |
|
|
memcpy (&gregset, core_reg_sect, sizeof (gregset));
|
3608 |
|
|
supply_gregset (&gregset);
|
3609 |
|
|
}
|
3610 |
|
|
|
3611 |
|
|
default:
|
3612 |
|
|
/* We've covered all the kinds of registers we know about here,
|
3613 |
|
|
so this must be something we wouldn't know what to do with
|
3614 |
|
|
anyway. Just ignore it. */
|
3615 |
|
|
break;
|
3616 |
|
|
}
|
3617 |
|
|
}
|
3618 |
|
|
|
3619 |
|
|
static struct core_fns cris_elf_core_fns =
|
3620 |
|
|
{
|
3621 |
|
|
bfd_target_elf_flavour, /* core_flavour */
|
3622 |
|
|
default_check_format, /* check_format */
|
3623 |
|
|
default_core_sniffer, /* core_sniffer */
|
3624 |
|
|
fetch_core_registers, /* core_read_registers */
|
3625 |
|
|
NULL /* next */
|
3626 |
|
|
};
|
3627 |
|
|
|
3628 |
|
|
/* Fetch (and possibly build) an appropriate link_map_offsets
|
3629 |
|
|
structure for native GNU/Linux CRIS targets using the struct
|
3630 |
|
|
offsets defined in link.h (but without actual reference to that
|
3631 |
|
|
file).
|
3632 |
|
|
|
3633 |
|
|
This makes it possible to access GNU/Linux CRIS shared libraries
|
3634 |
|
|
from a GDB that was not built on an GNU/Linux CRIS host (for cross
|
3635 |
|
|
debugging).
|
3636 |
|
|
|
3637 |
|
|
See gdb/solib-svr4.h for an explanation of these fields. */
|
3638 |
|
|
|
3639 |
|
|
struct link_map_offsets *
|
3640 |
|
|
cris_linux_svr4_fetch_link_map_offsets (void)
|
3641 |
|
|
{
|
3642 |
|
|
static struct link_map_offsets lmo;
|
3643 |
|
|
static struct link_map_offsets *lmp = NULL;
|
3644 |
|
|
|
3645 |
|
|
if (lmp == NULL)
|
3646 |
|
|
{
|
3647 |
|
|
lmp = &lmo;
|
3648 |
|
|
|
3649 |
|
|
lmo.r_debug_size = 8; /* The actual size is 20 bytes, but
|
3650 |
|
|
this is all we need. */
|
3651 |
|
|
lmo.r_map_offset = 4;
|
3652 |
|
|
lmo.r_map_size = 4;
|
3653 |
|
|
|
3654 |
|
|
lmo.link_map_size = 20;
|
3655 |
|
|
|
3656 |
|
|
lmo.l_addr_offset = 0;
|
3657 |
|
|
lmo.l_addr_size = 4;
|
3658 |
|
|
|
3659 |
|
|
lmo.l_name_offset = 4;
|
3660 |
|
|
lmo.l_name_size = 4;
|
3661 |
|
|
|
3662 |
|
|
lmo.l_next_offset = 12;
|
3663 |
|
|
lmo.l_next_size = 4;
|
3664 |
|
|
|
3665 |
|
|
lmo.l_prev_offset = 16;
|
3666 |
|
|
lmo.l_prev_size = 4;
|
3667 |
|
|
}
|
3668 |
|
|
|
3669 |
|
|
return lmp;
|
3670 |
|
|
}
|
3671 |
|
|
|
3672 |
|
|
static void
|
3673 |
|
|
cris_fpless_backtrace (char *noargs, int from_tty)
|
3674 |
|
|
{
|
3675 |
|
|
/* Points at the instruction after the jsr (except when in innermost frame
|
3676 |
|
|
where it points at the original pc). */
|
3677 |
|
|
CORE_ADDR pc = 0;
|
3678 |
|
|
|
3679 |
|
|
/* Temporary variable, used for parsing from the start of the function that
|
3680 |
|
|
the pc is in, up to the pc. */
|
3681 |
|
|
CORE_ADDR tmp_pc = 0;
|
3682 |
|
|
CORE_ADDR sp = 0;
|
3683 |
|
|
|
3684 |
|
|
/* Information about current frame. */
|
3685 |
|
|
struct symtab_and_line sal;
|
3686 |
|
|
char* func_name;
|
3687 |
|
|
|
3688 |
|
|
/* Present instruction. */
|
3689 |
|
|
unsigned short insn;
|
3690 |
|
|
|
3691 |
|
|
/* Next instruction, lookahead. */
|
3692 |
|
|
unsigned short insn_next;
|
3693 |
|
|
|
3694 |
|
|
/* This is to store the offset between sp at start of function and until we
|
3695 |
|
|
reach push srp (if any). */
|
3696 |
|
|
int sp_add_later = 0;
|
3697 |
|
|
int push_srp_found = 0;
|
3698 |
|
|
|
3699 |
|
|
int val = 0;
|
3700 |
|
|
|
3701 |
|
|
/* Frame counter. */
|
3702 |
|
|
int frame = 0;
|
3703 |
|
|
|
3704 |
|
|
/* For the innermost frame, we want to look at srp in case it's a leaf
|
3705 |
|
|
function (since there's no push srp in that case). */
|
3706 |
|
|
int innermost_frame = 1;
|
3707 |
|
|
|
3708 |
|
|
read_register_gen (PC_REGNUM, (char *) &pc);
|
3709 |
|
|
read_register_gen (SP_REGNUM, (char *) &sp);
|
3710 |
|
|
|
3711 |
|
|
/* We make an explicit return when we can't find an outer frame. */
|
3712 |
|
|
while (1)
|
3713 |
|
|
{
|
3714 |
|
|
/* Get file name and line number. */
|
3715 |
|
|
sal = find_pc_line (pc, 0);
|
3716 |
|
|
|
3717 |
|
|
/* Get function name. */
|
3718 |
|
|
find_pc_partial_function (pc, &func_name, (CORE_ADDR *) NULL,
|
3719 |
|
|
(CORE_ADDR *) NULL);
|
3720 |
|
|
|
3721 |
|
|
/* Print information about current frame. */
|
3722 |
|
|
printf_unfiltered ("#%i 0x%08lx in %s", frame++, pc, func_name);
|
3723 |
|
|
if (sal.symtab)
|
3724 |
|
|
{
|
3725 |
|
|
printf_unfiltered (" at %s:%i", sal.symtab->filename, sal.line);
|
3726 |
|
|
}
|
3727 |
|
|
printf_unfiltered ("\n");
|
3728 |
|
|
|
3729 |
|
|
/* Get the start address of this function. */
|
3730 |
|
|
tmp_pc = get_pc_function_start (pc);
|
3731 |
|
|
|
3732 |
|
|
/* Mini parser, only meant to find push sp and sub ...,sp from the start
|
3733 |
|
|
of the function, up to the pc. */
|
3734 |
|
|
while (tmp_pc < pc)
|
3735 |
|
|
{
|
3736 |
|
|
insn = read_memory_unsigned_integer (tmp_pc, sizeof (short));
|
3737 |
|
|
tmp_pc += sizeof (short);
|
3738 |
|
|
if (insn == 0xE1FC)
|
3739 |
|
|
{
|
3740 |
|
|
/* push <reg> 32 bit instruction */
|
3741 |
|
|
insn_next = read_memory_unsigned_integer (tmp_pc,
|
3742 |
|
|
sizeof (short));
|
3743 |
|
|
tmp_pc += sizeof (short);
|
3744 |
|
|
|
3745 |
|
|
/* Recognize srp. */
|
3746 |
|
|
if (insn_next == 0xBE7E)
|
3747 |
|
|
{
|
3748 |
|
|
/* For subsequent (not this one though) push or sub which
|
3749 |
|
|
affects sp, adjust sp immediately. */
|
3750 |
|
|
push_srp_found = 1;
|
3751 |
|
|
|
3752 |
|
|
/* Note: this will break if we ever encounter a
|
3753 |
|
|
push vr (1 byte) or push ccr (2 bytes). */
|
3754 |
|
|
sp_add_later += 4;
|
3755 |
|
|
}
|
3756 |
|
|
else
|
3757 |
|
|
{
|
3758 |
|
|
/* Some other register was pushed. */
|
3759 |
|
|
if (push_srp_found)
|
3760 |
|
|
{
|
3761 |
|
|
sp += 4;
|
3762 |
|
|
}
|
3763 |
|
|
else
|
3764 |
|
|
{
|
3765 |
|
|
sp_add_later += 4;
|
3766 |
|
|
}
|
3767 |
|
|
}
|
3768 |
|
|
}
|
3769 |
|
|
else if (cris_get_operand2 (insn) == SP_REGNUM
|
3770 |
|
|
&& cris_get_mode (insn) == 0x0000
|
3771 |
|
|
&& cris_get_opcode (insn) == 0x000A)
|
3772 |
|
|
{
|
3773 |
|
|
/* subq <val>,sp */
|
3774 |
|
|
val = cris_get_quick_value (insn);
|
3775 |
|
|
|
3776 |
|
|
if (push_srp_found)
|
3777 |
|
|
{
|
3778 |
|
|
sp += val;
|
3779 |
|
|
}
|
3780 |
|
|
else
|
3781 |
|
|
{
|
3782 |
|
|
sp_add_later += val;
|
3783 |
|
|
}
|
3784 |
|
|
|
3785 |
|
|
}
|
3786 |
|
|
else if (cris_get_operand2 (insn) == SP_REGNUM
|
3787 |
|
|
/* Autoincrement addressing mode. */
|
3788 |
|
|
&& cris_get_mode (insn) == 0x0003
|
3789 |
|
|
/* Opcode. */
|
3790 |
|
|
&& ((insn) & 0x03E0) >> 5 == 0x0004)
|
3791 |
|
|
{
|
3792 |
|
|
/* subu <val>,sp */
|
3793 |
|
|
val = get_data_from_address (&insn, tmp_pc);
|
3794 |
|
|
|
3795 |
|
|
if (push_srp_found)
|
3796 |
|
|
{
|
3797 |
|
|
sp += val;
|
3798 |
|
|
}
|
3799 |
|
|
else
|
3800 |
|
|
{
|
3801 |
|
|
sp_add_later += val;
|
3802 |
|
|
}
|
3803 |
|
|
}
|
3804 |
|
|
else if (cris_get_operand2 (insn) == SP_REGNUM
|
3805 |
|
|
&& ((insn & 0x0F00) >> 8) == 0x0001
|
3806 |
|
|
&& (cris_get_signed_offset (insn) < 0))
|
3807 |
|
|
{
|
3808 |
|
|
/* Immediate byte offset addressing prefix word with sp as base
|
3809 |
|
|
register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
|
3810 |
|
|
is between 64 and 128.
|
3811 |
|
|
movem r<regsave>,[sp=sp-<val>] */
|
3812 |
|
|
val = -cris_get_signed_offset (insn);
|
3813 |
|
|
insn_next = read_memory_unsigned_integer (tmp_pc,
|
3814 |
|
|
sizeof (short));
|
3815 |
|
|
tmp_pc += sizeof (short);
|
3816 |
|
|
|
3817 |
|
|
if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
|
3818 |
|
|
&& cris_get_opcode (insn_next) == 0x000F
|
3819 |
|
|
&& cris_get_size (insn_next) == 0x0003
|
3820 |
|
|
&& cris_get_operand1 (insn_next) == SP_REGNUM)
|
3821 |
|
|
{
|
3822 |
|
|
if (push_srp_found)
|
3823 |
|
|
{
|
3824 |
|
|
sp += val;
|
3825 |
|
|
}
|
3826 |
|
|
else
|
3827 |
|
|
{
|
3828 |
|
|
sp_add_later += val;
|
3829 |
|
|
}
|
3830 |
|
|
}
|
3831 |
|
|
}
|
3832 |
|
|
}
|
3833 |
|
|
|
3834 |
|
|
if (push_srp_found)
|
3835 |
|
|
{
|
3836 |
|
|
/* Reset flag. */
|
3837 |
|
|
push_srp_found = 0;
|
3838 |
|
|
|
3839 |
|
|
/* sp should now point at where srp is stored on the stack. Update
|
3840 |
|
|
the pc to the srp. */
|
3841 |
|
|
pc = read_memory_unsigned_integer (sp, 4);
|
3842 |
|
|
}
|
3843 |
|
|
else if (innermost_frame)
|
3844 |
|
|
{
|
3845 |
|
|
/* We couldn't find a push srp in the prologue, so this must be
|
3846 |
|
|
a leaf function, and thus we use the srp register directly.
|
3847 |
|
|
This should happen at most once, for the innermost function. */
|
3848 |
|
|
read_register_gen (SRP_REGNUM, (char *) &pc);
|
3849 |
|
|
}
|
3850 |
|
|
else
|
3851 |
|
|
{
|
3852 |
|
|
/* Couldn't find an outer frame. */
|
3853 |
|
|
return;
|
3854 |
|
|
}
|
3855 |
|
|
|
3856 |
|
|
/* Reset flag. (In case the innermost frame wasn't a leaf, we don't
|
3857 |
|
|
want to look at the srp register later either). */
|
3858 |
|
|
innermost_frame = 0;
|
3859 |
|
|
|
3860 |
|
|
/* Now, add the offset for everything up to, and including push srp,
|
3861 |
|
|
that was held back during the prologue parsing. */
|
3862 |
|
|
sp += sp_add_later;
|
3863 |
|
|
sp_add_later = 0;
|
3864 |
|
|
}
|
3865 |
|
|
}
|
3866 |
|
|
|
3867 |
|
|
void
|
3868 |
|
|
_initialize_cris_tdep (void)
|
3869 |
|
|
{
|
3870 |
|
|
struct cmd_list_element *c;
|
3871 |
|
|
|
3872 |
|
|
gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
|
3873 |
|
|
|
3874 |
|
|
/* Used in disassembly. */
|
3875 |
|
|
tm_print_insn = cris_delayed_get_disassembler;
|
3876 |
|
|
|
3877 |
|
|
/* CRIS-specific user-commands. */
|
3878 |
|
|
c = add_set_cmd ("cris-version", class_support, var_integer,
|
3879 |
|
|
(char *) &usr_cmd_cris_version,
|
3880 |
|
|
"Set the current CRIS version.", &setlist);
|
3881 |
|
|
set_cmd_sfunc (c, cris_version_update);
|
3882 |
|
|
add_show_from_set (c, &showlist);
|
3883 |
|
|
|
3884 |
|
|
c = add_set_enum_cmd ("cris-mode", class_support, cris_mode_enums,
|
3885 |
|
|
&usr_cmd_cris_mode,
|
3886 |
|
|
"Set the current CRIS mode.", &setlist);
|
3887 |
|
|
set_cmd_sfunc (c, cris_mode_update);
|
3888 |
|
|
add_show_from_set (c, &showlist);
|
3889 |
|
|
|
3890 |
|
|
c = add_set_enum_cmd ("cris-abi", class_support, cris_abi_enums,
|
3891 |
|
|
&usr_cmd_cris_abi,
|
3892 |
|
|
"Set the current CRIS ABI version.", &setlist);
|
3893 |
|
|
set_cmd_sfunc (c, cris_abi_update);
|
3894 |
|
|
add_show_from_set (c, &showlist);
|
3895 |
|
|
|
3896 |
|
|
c = add_cmd ("cris-fpless-backtrace", class_support, cris_fpless_backtrace,
|
3897 |
|
|
"Display call chain using the subroutine return pointer.\n"
|
3898 |
|
|
"Note that this displays the address after the jump to the "
|
3899 |
|
|
"subroutine.", &cmdlist);
|
3900 |
|
|
|
3901 |
|
|
add_core_fns (&cris_elf_core_fns);
|
3902 |
|
|
|
3903 |
|
|
}
|
3904 |
|
|
|
3905 |
|
|
/* Prints out all target specific values. */
|
3906 |
|
|
|
3907 |
|
|
static void
|
3908 |
|
|
cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
|
3909 |
|
|
{
|
3910 |
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
|
3911 |
|
|
if (tdep != NULL)
|
3912 |
|
|
{
|
3913 |
|
|
fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
|
3914 |
|
|
tdep->cris_version);
|
3915 |
|
|
fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
|
3916 |
|
|
tdep->cris_mode);
|
3917 |
|
|
fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_abi = %s\n",
|
3918 |
|
|
tdep->cris_abi);
|
3919 |
|
|
|
3920 |
|
|
}
|
3921 |
|
|
}
|
3922 |
|
|
|
3923 |
|
|
static void
|
3924 |
|
|
cris_version_update (char *ignore_args, int from_tty,
|
3925 |
|
|
struct cmd_list_element *c)
|
3926 |
|
|
{
|
3927 |
|
|
struct gdbarch_info info;
|
3928 |
|
|
|
3929 |
|
|
/* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
|
3930 |
|
|
the set command passed as a parameter. The clone operation will
|
3931 |
|
|
include (BUG?) any ``set'' command callback, if present.
|
3932 |
|
|
Commands like ``info set'' call all the ``show'' command
|
3933 |
|
|
callbacks. Unfortunatly, for ``show'' commands cloned from
|
3934 |
|
|
``set'', this includes callbacks belonging to ``set'' commands.
|
3935 |
|
|
Making this worse, this only occures if add_show_from_set() is
|
3936 |
|
|
called after add_cmd_sfunc() (BUG?). */
|
3937 |
|
|
|
3938 |
|
|
/* From here on, trust the user's CRIS version setting. */
|
3939 |
|
|
if (cmd_type (c) == set_cmd)
|
3940 |
|
|
{
|
3941 |
|
|
usr_cmd_cris_version_valid = 1;
|
3942 |
|
|
|
3943 |
|
|
/* Update the current architecture, if needed. */
|
3944 |
|
|
gdbarch_info_init (&info);
|
3945 |
|
|
if (!gdbarch_update_p (info))
|
3946 |
|
|
internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
|
3947 |
|
|
}
|
3948 |
|
|
}
|
3949 |
|
|
|
3950 |
|
|
static void
|
3951 |
|
|
cris_mode_update (char *ignore_args, int from_tty,
|
3952 |
|
|
struct cmd_list_element *c)
|
3953 |
|
|
{
|
3954 |
|
|
struct gdbarch_info info;
|
3955 |
|
|
|
3956 |
|
|
/* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
|
3957 |
|
|
the set command passed as a parameter. The clone operation will
|
3958 |
|
|
include (BUG?) any ``set'' command callback, if present.
|
3959 |
|
|
Commands like ``info set'' call all the ``show'' command
|
3960 |
|
|
callbacks. Unfortunatly, for ``show'' commands cloned from
|
3961 |
|
|
``set'', this includes callbacks belonging to ``set'' commands.
|
3962 |
|
|
Making this worse, this only occures if add_show_from_set() is
|
3963 |
|
|
called after add_cmd_sfunc() (BUG?). */
|
3964 |
|
|
|
3965 |
|
|
/* From here on, trust the user's CRIS mode setting. */
|
3966 |
|
|
if (cmd_type (c) == set_cmd)
|
3967 |
|
|
{
|
3968 |
|
|
usr_cmd_cris_mode_valid = 1;
|
3969 |
|
|
|
3970 |
|
|
/* Update the current architecture, if needed. */
|
3971 |
|
|
gdbarch_info_init (&info);
|
3972 |
|
|
if (!gdbarch_update_p (info))
|
3973 |
|
|
internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
|
3974 |
|
|
}
|
3975 |
|
|
}
|
3976 |
|
|
|
3977 |
|
|
static void
|
3978 |
|
|
cris_abi_update (char *ignore_args, int from_tty,
|
3979 |
|
|
struct cmd_list_element *c)
|
3980 |
|
|
{
|
3981 |
|
|
struct gdbarch_info info;
|
3982 |
|
|
|
3983 |
|
|
/* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
|
3984 |
|
|
the set command passed as a parameter. The clone operation will
|
3985 |
|
|
include (BUG?) any ``set'' command callback, if present.
|
3986 |
|
|
Commands like ``info set'' call all the ``show'' command
|
3987 |
|
|
callbacks. Unfortunatly, for ``show'' commands cloned from
|
3988 |
|
|
``set'', this includes callbacks belonging to ``set'' commands.
|
3989 |
|
|
Making this worse, this only occures if add_show_from_set() is
|
3990 |
|
|
called after add_cmd_sfunc() (BUG?). */
|
3991 |
|
|
|
3992 |
|
|
/* From here on, trust the user's CRIS ABI setting. */
|
3993 |
|
|
if (cmd_type (c) == set_cmd)
|
3994 |
|
|
{
|
3995 |
|
|
usr_cmd_cris_abi_valid = 1;
|
3996 |
|
|
|
3997 |
|
|
/* Update the current architecture, if needed. */
|
3998 |
|
|
gdbarch_info_init (&info);
|
3999 |
|
|
if (!gdbarch_update_p (info))
|
4000 |
|
|
internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
|
4001 |
|
|
}
|
4002 |
|
|
}
|
4003 |
|
|
|
4004 |
|
|
/* Copied from pa64solib.c, with a couple of minor changes. */
|
4005 |
|
|
|
4006 |
|
|
static CORE_ADDR
|
4007 |
|
|
bfd_lookup_symbol (bfd *abfd, const char *symname)
|
4008 |
|
|
{
|
4009 |
|
|
unsigned int storage_needed;
|
4010 |
|
|
asymbol *sym;
|
4011 |
|
|
asymbol **symbol_table;
|
4012 |
|
|
unsigned int number_of_symbols;
|
4013 |
|
|
unsigned int i;
|
4014 |
|
|
struct cleanup *back_to;
|
4015 |
|
|
CORE_ADDR symaddr = 0;
|
4016 |
|
|
|
4017 |
|
|
storage_needed = bfd_get_symtab_upper_bound (abfd);
|
4018 |
|
|
|
4019 |
|
|
if (storage_needed > 0)
|
4020 |
|
|
{
|
4021 |
|
|
symbol_table = (asymbol **) xmalloc (storage_needed);
|
4022 |
|
|
back_to = make_cleanup (free, (PTR) symbol_table);
|
4023 |
|
|
number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
|
4024 |
|
|
|
4025 |
|
|
for (i = 0; i < number_of_symbols; i++)
|
4026 |
|
|
{
|
4027 |
|
|
sym = *symbol_table++;
|
4028 |
|
|
if (!strcmp (sym->name, symname))
|
4029 |
|
|
{
|
4030 |
|
|
/* Bfd symbols are section relative. */
|
4031 |
|
|
symaddr = sym->value + sym->section->vma;
|
4032 |
|
|
break;
|
4033 |
|
|
}
|
4034 |
|
|
}
|
4035 |
|
|
do_cleanups (back_to);
|
4036 |
|
|
}
|
4037 |
|
|
return (symaddr);
|
4038 |
|
|
}
|
4039 |
|
|
|
4040 |
|
|
static struct gdbarch *
|
4041 |
|
|
cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
|
4042 |
|
|
{
|
4043 |
|
|
struct gdbarch *gdbarch;
|
4044 |
|
|
struct gdbarch_tdep *tdep;
|
4045 |
|
|
int cris_version;
|
4046 |
|
|
const char *cris_mode;
|
4047 |
|
|
const char *cris_abi;
|
4048 |
|
|
CORE_ADDR cris_abi_sym = 0;
|
4049 |
|
|
int register_bytes;
|
4050 |
|
|
|
4051 |
|
|
if (usr_cmd_cris_version_valid)
|
4052 |
|
|
{
|
4053 |
|
|
/* Trust the user's CRIS version setting. */
|
4054 |
|
|
cris_version = usr_cmd_cris_version;
|
4055 |
|
|
}
|
4056 |
|
|
else
|
4057 |
|
|
{
|
4058 |
|
|
/* Assume it's CRIS version 10. */
|
4059 |
|
|
cris_version = 10;
|
4060 |
|
|
}
|
4061 |
|
|
|
4062 |
|
|
if (usr_cmd_cris_mode_valid)
|
4063 |
|
|
{
|
4064 |
|
|
/* Trust the user's CRIS mode setting. */
|
4065 |
|
|
cris_mode = usr_cmd_cris_mode;
|
4066 |
|
|
}
|
4067 |
|
|
else if (cris_version == 10)
|
4068 |
|
|
{
|
4069 |
|
|
/* Assume CRIS version 10 is in user mode. */
|
4070 |
|
|
cris_mode = CRIS_MODE_USER;
|
4071 |
|
|
}
|
4072 |
|
|
else
|
4073 |
|
|
{
|
4074 |
|
|
/* Strictly speaking, older CRIS version don't have a supervisor mode,
|
4075 |
|
|
but we regard its only mode as supervisor mode. */
|
4076 |
|
|
cris_mode = CRIS_MODE_SUPERVISOR;
|
4077 |
|
|
}
|
4078 |
|
|
|
4079 |
|
|
if (usr_cmd_cris_abi_valid)
|
4080 |
|
|
{
|
4081 |
|
|
/* Trust the user's ABI setting. */
|
4082 |
|
|
cris_abi = usr_cmd_cris_abi;
|
4083 |
|
|
}
|
4084 |
|
|
else if (info.abfd)
|
4085 |
|
|
{
|
4086 |
|
|
if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
|
4087 |
|
|
{
|
4088 |
|
|
/* An elf target uses the new ABI. */
|
4089 |
|
|
cris_abi = CRIS_ABI_V2;
|
4090 |
|
|
}
|
4091 |
|
|
else if (bfd_get_flavour (info.abfd) == bfd_target_aout_flavour)
|
4092 |
|
|
{
|
4093 |
|
|
/* An a.out target may use either ABI. Look for hints in the
|
4094 |
|
|
symbol table. */
|
4095 |
|
|
cris_abi_sym = bfd_lookup_symbol (info.abfd, CRIS_ABI_SYMBOL);
|
4096 |
|
|
cris_abi = cris_abi_sym ? CRIS_ABI_V2 : CRIS_ABI_ORIGINAL;
|
4097 |
|
|
}
|
4098 |
|
|
else
|
4099 |
|
|
{
|
4100 |
|
|
/* Unknown bfd flavour. Assume it's the new ABI. */
|
4101 |
|
|
cris_abi = CRIS_ABI_V2;
|
4102 |
|
|
}
|
4103 |
|
|
}
|
4104 |
|
|
else if (arches != NULL)
|
4105 |
|
|
{
|
4106 |
|
|
/* No bfd available. Stick with the ABI from the most recently
|
4107 |
|
|
selected architecture of this same family (the head of arches
|
4108 |
|
|
always points to this). (This is to avoid changing the ABI
|
4109 |
|
|
when the user updates the architecture with the 'set
|
4110 |
|
|
cris-version' command.) */
|
4111 |
|
|
cris_abi = gdbarch_tdep (arches->gdbarch)->cris_abi;
|
4112 |
|
|
}
|
4113 |
|
|
else
|
4114 |
|
|
{
|
4115 |
|
|
/* No bfd, and no previously selected architecture available.
|
4116 |
|
|
Assume it's the new ABI. */
|
4117 |
|
|
cris_abi = CRIS_ABI_V2;
|
4118 |
|
|
}
|
4119 |
|
|
|
4120 |
|
|
/* Make the current settings visible to the user. */
|
4121 |
|
|
usr_cmd_cris_version = cris_version;
|
4122 |
|
|
usr_cmd_cris_mode = cris_mode;
|
4123 |
|
|
usr_cmd_cris_abi = cris_abi;
|
4124 |
|
|
|
4125 |
|
|
/* Find a candidate among the list of pre-declared architectures. Both
|
4126 |
|
|
CRIS version and ABI must match. */
|
4127 |
|
|
for (arches = gdbarch_list_lookup_by_info (arches, &info);
|
4128 |
|
|
arches != NULL;
|
4129 |
|
|
arches = gdbarch_list_lookup_by_info (arches->next, &info))
|
4130 |
|
|
{
|
4131 |
|
|
if ((gdbarch_tdep (arches->gdbarch)->cris_version == cris_version)
|
4132 |
|
|
&& (gdbarch_tdep (arches->gdbarch)->cris_mode == cris_mode)
|
4133 |
|
|
&& (gdbarch_tdep (arches->gdbarch)->cris_abi == cris_abi))
|
4134 |
|
|
return arches->gdbarch;
|
4135 |
|
|
}
|
4136 |
|
|
|
4137 |
|
|
/* No matching architecture was found. Create a new one. */
|
4138 |
|
|
tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
|
4139 |
|
|
gdbarch = gdbarch_alloc (&info, tdep);
|
4140 |
|
|
|
4141 |
|
|
tdep->cris_version = cris_version;
|
4142 |
|
|
tdep->cris_mode = cris_mode;
|
4143 |
|
|
tdep->cris_abi = cris_abi;
|
4144 |
|
|
|
4145 |
|
|
/* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
|
4146 |
|
|
switch (info.byte_order)
|
4147 |
|
|
{
|
4148 |
|
|
case BFD_ENDIAN_LITTLE:
|
4149 |
|
|
/* Ok. */
|
4150 |
|
|
break;
|
4151 |
|
|
|
4152 |
|
|
case BFD_ENDIAN_BIG:
|
4153 |
|
|
internal_error (__FILE__, __LINE__, "cris_gdbarch_init: big endian byte order in info");
|
4154 |
|
|
break;
|
4155 |
|
|
|
4156 |
|
|
default:
|
4157 |
|
|
internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown byte order in info");
|
4158 |
|
|
}
|
4159 |
|
|
|
4160 |
|
|
/* Initialize the ABI dependent things. */
|
4161 |
|
|
if (tdep->cris_abi == CRIS_ABI_ORIGINAL)
|
4162 |
|
|
{
|
4163 |
|
|
set_gdbarch_double_bit (gdbarch, 32);
|
4164 |
|
|
set_gdbarch_push_arguments (gdbarch, cris_abi_original_push_arguments);
|
4165 |
|
|
set_gdbarch_deprecated_store_return_value (gdbarch,
|
4166 |
|
|
cris_abi_original_store_return_value);
|
4167 |
|
|
set_gdbarch_deprecated_extract_return_value
|
4168 |
|
|
(gdbarch, cris_abi_original_extract_return_value);
|
4169 |
|
|
set_gdbarch_reg_struct_has_addr
|
4170 |
|
|
(gdbarch, cris_abi_original_reg_struct_has_addr);
|
4171 |
|
|
}
|
4172 |
|
|
else if (tdep->cris_abi == CRIS_ABI_V2)
|
4173 |
|
|
{
|
4174 |
|
|
set_gdbarch_double_bit (gdbarch, 64);
|
4175 |
|
|
set_gdbarch_push_arguments (gdbarch, cris_abi_v2_push_arguments);
|
4176 |
|
|
set_gdbarch_deprecated_store_return_value (gdbarch, cris_abi_v2_store_return_value);
|
4177 |
|
|
set_gdbarch_deprecated_extract_return_value
|
4178 |
|
|
(gdbarch, cris_abi_v2_extract_return_value);
|
4179 |
|
|
set_gdbarch_reg_struct_has_addr (gdbarch,
|
4180 |
|
|
cris_abi_v2_reg_struct_has_addr);
|
4181 |
|
|
}
|
4182 |
|
|
else
|
4183 |
|
|
internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS ABI");
|
4184 |
|
|
|
4185 |
|
|
/* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
|
4186 |
|
|
which means we have to set this explicitly. */
|
4187 |
|
|
set_gdbarch_long_double_bit (gdbarch, 64);
|
4188 |
|
|
|
4189 |
|
|
/* There are 32 registers (some of which may not be implemented). */
|
4190 |
|
|
set_gdbarch_num_regs (gdbarch, 32);
|
4191 |
|
|
set_gdbarch_sp_regnum (gdbarch, 14);
|
4192 |
|
|
set_gdbarch_fp_regnum (gdbarch, 8);
|
4193 |
|
|
set_gdbarch_pc_regnum (gdbarch, 15);
|
4194 |
|
|
|
4195 |
|
|
set_gdbarch_register_name (gdbarch, cris_register_name);
|
4196 |
|
|
|
4197 |
|
|
/* Length of ordinary registers used in push_word and a few other places.
|
4198 |
|
|
REGISTER_RAW_SIZE is the real way to know how big a register is. */
|
4199 |
|
|
set_gdbarch_register_size (gdbarch, 4);
|
4200 |
|
|
|
4201 |
|
|
/* NEW */
|
4202 |
|
|
set_gdbarch_register_bytes_ok (gdbarch, cris_register_bytes_ok);
|
4203 |
|
|
set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
|
4204 |
|
|
|
4205 |
|
|
|
4206 |
|
|
set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
|
4207 |
|
|
set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
|
4208 |
|
|
|
4209 |
|
|
|
4210 |
|
|
/* The total amount of space needed to store (in an array called registers)
|
4211 |
|
|
GDB's copy of the machine's register state. Note: We can not use
|
4212 |
|
|
cris_register_size at this point, since it relies on current_gdbarch
|
4213 |
|
|
being set. */
|
4214 |
|
|
switch (tdep->cris_version)
|
4215 |
|
|
{
|
4216 |
|
|
case 0:
|
4217 |
|
|
case 1:
|
4218 |
|
|
case 2:
|
4219 |
|
|
case 3:
|
4220 |
|
|
/* Support for these may be added later. */
|
4221 |
|
|
internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unsupported CRIS version");
|
4222 |
|
|
break;
|
4223 |
|
|
|
4224 |
|
|
case 8:
|
4225 |
|
|
case 9:
|
4226 |
|
|
/* CRIS v8 and v9, a.k.a. ETRAX 100. General registers R0 - R15
|
4227 |
|
|
(32 bits), special registers P0 - P1 (8 bits), P4 - P5 (16 bits),
|
4228 |
|
|
and P8 - P14 (32 bits). */
|
4229 |
|
|
register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (7 * 4);
|
4230 |
|
|
break;
|
4231 |
|
|
|
4232 |
|
|
case 10:
|
4233 |
|
|
case 11:
|
4234 |
|
|
/* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
|
4235 |
|
|
P7 (32 bits), and P15 (32 bits) have been implemented. */
|
4236 |
|
|
register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (9 * 4);
|
4237 |
|
|
break;
|
4238 |
|
|
|
4239 |
|
|
default:
|
4240 |
|
|
internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS version");
|
4241 |
|
|
}
|
4242 |
|
|
|
4243 |
|
|
set_gdbarch_register_bytes (gdbarch, register_bytes);
|
4244 |
|
|
|
4245 |
|
|
/* Returns the register offset for the first byte of register regno's space
|
4246 |
|
|
in the saved register state. */
|
4247 |
|
|
set_gdbarch_register_byte (gdbarch, cris_register_offset);
|
4248 |
|
|
|
4249 |
|
|
/* The length of the registers in the actual machine representation. */
|
4250 |
|
|
set_gdbarch_register_raw_size (gdbarch, cris_register_size);
|
4251 |
|
|
|
4252 |
|
|
/* The largest value REGISTER_RAW_SIZE can have. */
|
4253 |
|
|
set_gdbarch_max_register_raw_size (gdbarch, 32);
|
4254 |
|
|
|
4255 |
|
|
/* The length of the registers in the program's representation. */
|
4256 |
|
|
set_gdbarch_register_virtual_size (gdbarch, cris_register_size);
|
4257 |
|
|
|
4258 |
|
|
/* The largest value REGISTER_VIRTUAL_SIZE can have. */
|
4259 |
|
|
set_gdbarch_max_register_virtual_size (gdbarch, 32);
|
4260 |
|
|
|
4261 |
|
|
set_gdbarch_register_virtual_type (gdbarch, cris_register_virtual_type);
|
4262 |
|
|
|
4263 |
|
|
/* Use generic dummy frames. */
|
4264 |
|
|
set_gdbarch_use_generic_dummy_frames (gdbarch, 1);
|
4265 |
|
|
|
4266 |
|
|
/* Where to execute the call in the memory segments. */
|
4267 |
|
|
set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
|
4268 |
|
|
set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
|
4269 |
|
|
|
4270 |
|
|
/* Start execution at the beginning of dummy. */
|
4271 |
|
|
set_gdbarch_call_dummy_start_offset (gdbarch, 0);
|
4272 |
|
|
set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
|
4273 |
|
|
|
4274 |
|
|
/* Set to 1 since call_dummy_breakpoint_offset was defined. */
|
4275 |
|
|
set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
|
4276 |
|
|
|
4277 |
|
|
/* Read all about dummy frames in blockframe.c. */
|
4278 |
|
|
set_gdbarch_call_dummy_length (gdbarch, 0);
|
4279 |
|
|
set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_at_entry_point);
|
4280 |
|
|
|
4281 |
|
|
/* Defined to 1 to indicate that the target supports inferior function
|
4282 |
|
|
calls. */
|
4283 |
|
|
set_gdbarch_call_dummy_p (gdbarch, 1);
|
4284 |
|
|
set_gdbarch_call_dummy_words (gdbarch, 0);
|
4285 |
|
|
set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
|
4286 |
|
|
|
4287 |
|
|
/* No stack adjustment needed when peforming an inferior function call. */
|
4288 |
|
|
set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
|
4289 |
|
|
set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy);
|
4290 |
|
|
|
4291 |
|
|
set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register);
|
4292 |
|
|
|
4293 |
|
|
/* No register requires conversion from raw format to virtual format. */
|
4294 |
|
|
set_gdbarch_register_convertible (gdbarch, generic_register_convertible_not);
|
4295 |
|
|
|
4296 |
|
|
set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
|
4297 |
|
|
set_gdbarch_push_return_address (gdbarch, cris_push_return_address);
|
4298 |
|
|
set_gdbarch_pop_frame (gdbarch, cris_pop_frame);
|
4299 |
|
|
|
4300 |
|
|
set_gdbarch_store_struct_return (gdbarch, cris_store_struct_return);
|
4301 |
|
|
set_gdbarch_deprecated_extract_struct_value_address
|
4302 |
|
|
(gdbarch, cris_extract_struct_value_address);
|
4303 |
|
|
set_gdbarch_use_struct_convention (gdbarch, cris_use_struct_convention);
|
4304 |
|
|
|
4305 |
|
|
set_gdbarch_frame_init_saved_regs (gdbarch, cris_frame_init_saved_regs);
|
4306 |
|
|
set_gdbarch_init_extra_frame_info (gdbarch, cris_init_extra_frame_info);
|
4307 |
|
|
set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
|
4308 |
|
|
set_gdbarch_prologue_frameless_p (gdbarch, generic_prologue_frameless_p);
|
4309 |
|
|
|
4310 |
|
|
/* The stack grows downward. */
|
4311 |
|
|
set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
|
4312 |
|
|
|
4313 |
|
|
set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
|
4314 |
|
|
|
4315 |
|
|
/* The PC must not be decremented after a breakpoint. (The breakpoint
|
4316 |
|
|
handler takes care of that.) */
|
4317 |
|
|
set_gdbarch_decr_pc_after_break (gdbarch, 0);
|
4318 |
|
|
|
4319 |
|
|
/* Offset from address of function to start of its code. */
|
4320 |
|
|
set_gdbarch_function_start_offset (gdbarch, 0);
|
4321 |
|
|
|
4322 |
|
|
/* The number of bytes at the start of arglist that are not really args,
|
4323 |
|
|
|
4324 |
|
|
set_gdbarch_frame_args_skip (gdbarch, 0);
|
4325 |
|
|
set_gdbarch_frameless_function_invocation
|
4326 |
|
|
(gdbarch, cris_frameless_function_invocation);
|
4327 |
|
|
set_gdbarch_frame_chain (gdbarch, cris_frame_chain);
|
4328 |
|
|
set_gdbarch_frame_chain_valid (gdbarch, generic_file_frame_chain_valid);
|
4329 |
|
|
|
4330 |
|
|
set_gdbarch_frame_saved_pc (gdbarch, cris_frame_saved_pc);
|
4331 |
|
|
set_gdbarch_frame_args_address (gdbarch, cris_frame_args_address);
|
4332 |
|
|
set_gdbarch_frame_locals_address (gdbarch, cris_frame_locals_address);
|
4333 |
|
|
set_gdbarch_saved_pc_after_call (gdbarch, cris_saved_pc_after_call);
|
4334 |
|
|
|
4335 |
|
|
set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
|
4336 |
|
|
|
4337 |
|
|
/* No extra stack alignment needed. Set to 1 by default. */
|
4338 |
|
|
set_gdbarch_extra_stack_alignment_needed (gdbarch, 0);
|
4339 |
|
|
|
4340 |
|
|
/* Helpful for backtracing and returning in a call dummy. */
|
4341 |
|
|
set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
|
4342 |
|
|
|
4343 |
|
|
/* Use target_specific function to define link map offsets. */
|
4344 |
|
|
set_solib_svr4_fetch_link_map_offsets
|
4345 |
|
|
(gdbarch, cris_linux_svr4_fetch_link_map_offsets);
|
4346 |
|
|
|
4347 |
|
|
return gdbarch;
|
4348 |
|
|
}
|