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