1 /* Target-dependent code for Morpho mt processor, for GDB.
3 Copyright (C) 2005 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Contributed by Michael Snyder, msnyder@redhat.com. */
26 #include "frame-unwind.h"
27 #include "frame-base.h"
30 #include "arch-utils.h"
32 #include "gdb_string.h"
34 #include "reggroups.h"
36 #include "trad-frame.h"
38 #include "dwarf2-frame.h"
40 #include "gdb_assert.h"
42 enum mt_arch_constants
44 MT_MAX_STRUCT_SIZE
= 16
49 MT_R0_REGNUM
, /* 32 bit regs. */
51 MT_1ST_ARGREG
= MT_R1_REGNUM
,
55 MT_LAST_ARGREG
= MT_R4_REGNUM
,
64 MT_FP_REGNUM
= MT_R12_REGNUM
,
66 MT_SP_REGNUM
= MT_R13_REGNUM
,
68 MT_RA_REGNUM
= MT_R14_REGNUM
,
70 MT_IRA_REGNUM
= MT_R15_REGNUM
,
73 /* Interrupt Enable pseudo-register, exported by SID. */
75 /* End of CPU regs. */
79 /* Co-processor registers. */
80 MT_COPRO_REGNUM
= MT_NUM_CPU_REGS
, /* 16 bit regs. */
97 MT_BYPA_REGNUM
, /* 32 bit regs. */
101 MT_CONTEXT_REGNUM
, /* 38 bits (treat as array of
103 MT_MAC_REGNUM
, /* 32 bits. */
104 MT_Z1_REGNUM
, /* 16 bits. */
105 MT_Z2_REGNUM
, /* 16 bits. */
106 MT_ICHANNEL_REGNUM
, /* 32 bits. */
107 MT_ISCRAMB_REGNUM
, /* 32 bits. */
108 MT_QSCRAMB_REGNUM
, /* 32 bits. */
109 MT_OUT_REGNUM
, /* 16 bits. */
110 MT_EXMAC_REGNUM
, /* 32 bits (8 used). */
111 MT_QCHANNEL_REGNUM
, /* 32 bits. */
113 /* Number of real registers. */
116 /* Pseudo-registers. */
117 MT_COPRO_PSEUDOREG_REGNUM
= MT_NUM_REGS
,
118 MT_MAC_PSEUDOREG_REGNUM
,
120 /* Two pseudo-regs ('coprocessor' and 'mac'). */
121 MT_NUM_PSEUDO_REGS
= 2
124 /* Return name of register number specified by REGNUM. */
127 mt_register_name (int regnum
)
129 static const char *const register_names
[] = {
131 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
132 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
134 /* Co-processor regs. */
135 "", /* copro register. */
136 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
137 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
138 "bypa", "bypb", "bypc", "flag", "context", "" /* mac. */ , "z1", "z2",
139 "Ichannel", "Iscramb", "Qscramb", "out", "" /* ex-mac. */ , "Qchannel",
140 /* Pseudo-registers. */
144 gdb_assert (regnum
>= 0 && regnum
< ARRAY_SIZE (register_names
));
145 return register_names
[regnum
];
148 /* Given ARCH and a register number specified by REGNUM, return the
149 type of that register. */
152 mt_register_type (struct gdbarch
*arch
, int regnum
)
154 static struct type
*void_func_ptr
= NULL
;
155 static struct type
*void_ptr
= NULL
;
156 static struct type
*copro_type
;
158 if (regnum
>= 0 && regnum
< MT_NUM_REGS
+ MT_NUM_PSEUDO_REGS
)
160 if (void_func_ptr
== NULL
)
164 void_ptr
= lookup_pointer_type (builtin_type_void
);
166 lookup_pointer_type (lookup_function_type (builtin_type_void
));
167 temp
= create_range_type (NULL
, builtin_type_unsigned_int
, 0, 1);
168 copro_type
= create_array_type (NULL
, builtin_type_int16
, temp
);
175 return void_func_ptr
;
179 case MT_INT_ENABLE_REGNUM
:
180 case MT_ICHANNEL_REGNUM
:
181 case MT_QCHANNEL_REGNUM
:
182 case MT_ISCRAMB_REGNUM
:
183 case MT_QSCRAMB_REGNUM
:
184 return builtin_type_int32
;
185 case MT_EXMAC_REGNUM
:
187 return builtin_type_uint32
;
194 return builtin_type_int16
;
195 case MT_CONTEXT_REGNUM
:
196 return builtin_type_long_long
;
197 case MT_COPRO_REGNUM
:
198 case MT_COPRO_PSEUDOREG_REGNUM
:
200 case MT_MAC_PSEUDOREG_REGNUM
:
201 if (gdbarch_bfd_arch_info (arch
)->mach
== bfd_mach_mrisc2
202 || gdbarch_bfd_arch_info (arch
)->mach
== bfd_mach_ms2
)
203 return builtin_type_uint64
;
205 return builtin_type_uint32
;
207 return builtin_type_unsigned_char
;
209 if (regnum
>= MT_R0_REGNUM
&& regnum
<= MT_R15_REGNUM
)
210 return builtin_type_int32
;
211 else if (regnum
>= MT_CPR0_REGNUM
&& regnum
<= MT_CPR15_REGNUM
)
212 return builtin_type_int16
;
215 internal_error (__FILE__
, __LINE__
,
216 _("mt_register_type: illegal register number %d"), regnum
);
219 /* Return true if register REGNUM is a member of the register group
220 specified by GROUP. */
223 mt_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
224 struct reggroup
*group
)
226 /* Groups of registers that can be displayed via "info reg". */
227 if (group
== all_reggroup
)
229 && regnum
< MT_NUM_REGS
+ MT_NUM_PSEUDO_REGS
230 && mt_register_name (regnum
)[0] != '\0');
232 if (group
== general_reggroup
)
233 return (regnum
>= MT_R0_REGNUM
&& regnum
<= MT_R15_REGNUM
);
235 if (group
== float_reggroup
)
236 return 0; /* No float regs. */
238 if (group
== vector_reggroup
)
239 return 0; /* No vector regs. */
241 /* For any that are not handled above. */
242 return default_register_reggroup_p (gdbarch
, regnum
, group
);
245 /* Return the return value convention used for a given type TYPE.
246 Optionally, fetch or set the return value via READBUF or
247 WRITEBUF respectively using REGCACHE for the register
250 static enum return_value_convention
251 mt_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
252 struct regcache
*regcache
, gdb_byte
*readbuf
,
253 const gdb_byte
*writebuf
)
255 if (TYPE_LENGTH (type
) > 4)
257 /* Return values > 4 bytes are returned in memory,
258 pointed to by R11. */
263 regcache_cooked_read_unsigned (regcache
, MT_R11_REGNUM
, &addr
);
264 read_memory (addr
, readbuf
, TYPE_LENGTH (type
));
271 regcache_cooked_read_unsigned (regcache
, MT_R11_REGNUM
, &addr
);
272 write_memory (addr
, writebuf
, TYPE_LENGTH (type
));
275 return RETURN_VALUE_ABI_RETURNS_ADDRESS
;
283 /* Return values of <= 4 bytes are returned in R11. */
284 regcache_cooked_read_unsigned (regcache
, MT_R11_REGNUM
, &temp
);
285 store_unsigned_integer (readbuf
, TYPE_LENGTH (type
), temp
);
290 if (TYPE_LENGTH (type
) < 4)
293 /* Add leading zeros to the value. */
294 memset (buf
, 0, sizeof (buf
));
295 memcpy (buf
+ sizeof (buf
) - TYPE_LENGTH (type
),
296 writebuf
, TYPE_LENGTH (type
));
297 regcache_cooked_write (regcache
, MT_R11_REGNUM
, buf
);
299 else /* (TYPE_LENGTH (type) == 4 */
300 regcache_cooked_write (regcache
, MT_R11_REGNUM
, writebuf
);
303 return RETURN_VALUE_REGISTER_CONVENTION
;
307 /* If the input address, PC, is in a function prologue, return the
308 address of the end of the prologue, otherwise return the input
311 Note: PC is likely to be the function start, since this function
312 is mainly used for advancing a breakpoint to the first line, or
313 stepping to the first line when we have stepped into a function
317 mt_skip_prologue (CORE_ADDR pc
)
319 CORE_ADDR func_addr
= 0, func_end
= 0;
323 if (find_pc_partial_function (pc
, &func_name
, &func_addr
, &func_end
))
325 struct symtab_and_line sal
;
328 /* Found a function. */
329 sym
= lookup_symbol (func_name
, NULL
, VAR_DOMAIN
, NULL
, NULL
);
330 if (sym
&& SYMBOL_LANGUAGE (sym
) != language_asm
)
332 /* Don't use this trick for assembly source files. */
333 sal
= find_pc_line (func_addr
, 0);
335 if (sal
.end
&& sal
.end
< func_end
)
337 /* Found a line number, use it as end of prologue. */
343 /* No function symbol, or no line symbol. Use prologue scanning method. */
346 instr
= read_memory_unsigned_integer (pc
, 4);
347 if (instr
== 0x12000000) /* nop */
349 if (instr
== 0x12ddc000) /* copy sp into fp */
352 if (instr
== 0x05dd) /* subi sp, sp, imm */
354 if (instr
>= 0x43c0 && instr
<= 0x43df) /* push */
356 /* Not an obvious prologue instruction. */
363 /* The breakpoint instruction must be the same size as the smallest
364 instruction in the instruction set.
366 The BP for ms1 is defined as 0x68000000 (BREAK).
367 The BP for ms2 is defined as 0x69000000 (illegal) */
369 static const gdb_byte
*
370 mt_breakpoint_from_pc (CORE_ADDR
*bp_addr
, int *bp_size
)
372 static gdb_byte ms1_breakpoint
[] = { 0x68, 0, 0, 0 };
373 static gdb_byte ms2_breakpoint
[] = { 0x69, 0, 0, 0 };
376 if (gdbarch_bfd_arch_info (current_gdbarch
)->mach
== bfd_mach_ms2
)
377 return ms2_breakpoint
;
379 return ms1_breakpoint
;
382 /* Fetch the pseudo registers:
384 There are two pseudo-registers:
385 1) The 'coprocessor' pseudo-register (which mirrors the
386 "real" coprocessor register sent by the target), and
387 2) The 'MAC' pseudo-register (which represents the union
388 of the original 32 bit target MAC register and the new
389 8-bit extended-MAC register). */
392 mt_pseudo_register_read (struct gdbarch
*gdbarch
,
393 struct regcache
*regcache
, int regno
, gdb_byte
*buf
)
397 case MT_COPRO_REGNUM
:
398 case MT_COPRO_PSEUDOREG_REGNUM
:
399 regcache_raw_read (regcache
, MT_COPRO_REGNUM
, buf
);
402 case MT_MAC_PSEUDOREG_REGNUM
:
403 if (gdbarch_bfd_arch_info (gdbarch
)->mach
== bfd_mach_mrisc2
404 || gdbarch_bfd_arch_info (gdbarch
)->mach
== bfd_mach_ms2
)
406 ULONGEST oldmac
= 0, ext_mac
= 0;
409 regcache_cooked_read_unsigned (regcache
, MT_MAC_REGNUM
, &oldmac
);
410 regcache_cooked_read_unsigned (regcache
, MT_EXMAC_REGNUM
, &ext_mac
);
412 (oldmac
& 0xffffffff) | ((long long) (ext_mac
& 0xff) << 32);
413 store_signed_integer (buf
, 8, newmac
);
416 regcache_raw_read (regcache
, MT_MAC_REGNUM
, buf
);
419 internal_error (__FILE__
, __LINE__
,
420 _("mt_pseudo_register_read: bad reg # (%d)"), regno
);
425 /* Write the pseudo registers:
427 Mt pseudo-registers are stored directly to the target. The
428 'coprocessor' register is special, because when it is modified, all
429 the other coprocessor regs must be flushed from the reg cache. */
432 mt_pseudo_register_write (struct gdbarch
*gdbarch
,
433 struct regcache
*regcache
,
434 int regno
, const gdb_byte
*buf
)
440 case MT_COPRO_REGNUM
:
441 case MT_COPRO_PSEUDOREG_REGNUM
:
442 regcache_raw_write (regcache
, MT_COPRO_REGNUM
, buf
);
443 for (i
= MT_NUM_CPU_REGS
; i
< MT_NUM_REGS
; i
++)
444 set_register_cached (i
, 0);
447 case MT_MAC_PSEUDOREG_REGNUM
:
448 if (gdbarch_bfd_arch_info (gdbarch
)->mach
== bfd_mach_mrisc2
449 || gdbarch_bfd_arch_info (gdbarch
)->mach
== bfd_mach_ms2
)
451 /* The 8-byte MAC pseudo-register must be broken down into two
452 32-byte registers. */
453 unsigned int oldmac
, ext_mac
;
456 newmac
= extract_unsigned_integer (buf
, 8);
457 oldmac
= newmac
& 0xffffffff;
458 ext_mac
= (newmac
>> 32) & 0xff;
459 regcache_cooked_write_unsigned (regcache
, MT_MAC_REGNUM
, oldmac
);
460 regcache_cooked_write_unsigned (regcache
, MT_EXMAC_REGNUM
, ext_mac
);
463 regcache_raw_write (regcache
, MT_MAC_REGNUM
, buf
);
466 internal_error (__FILE__
, __LINE__
,
467 _("mt_pseudo_register_write: bad reg # (%d)"), regno
);
473 mt_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
475 /* Register size is 4 bytes. */
476 return align_down (sp
, 4);
479 /* Implements the "info registers" command. When ``all'' is non-zero,
480 the coprocessor registers will be printed in addition to the rest
484 mt_registers_info (struct gdbarch
*gdbarch
,
485 struct ui_file
*file
,
486 struct frame_info
*frame
, int regnum
, int all
)
492 lim
= all
? MT_NUM_REGS
: MT_NUM_CPU_REGS
;
494 for (regnum
= 0; regnum
< lim
; regnum
++)
496 /* Don't display the Qchannel register since it will be displayed
497 along with Ichannel. (See below.) */
498 if (regnum
== MT_QCHANNEL_REGNUM
)
501 mt_registers_info (gdbarch
, file
, frame
, regnum
, all
);
503 /* Display the Qchannel register immediately after Ichannel. */
504 if (regnum
== MT_ICHANNEL_REGNUM
)
505 mt_registers_info (gdbarch
, file
, frame
, MT_QCHANNEL_REGNUM
, all
);
510 if (regnum
== MT_EXMAC_REGNUM
)
512 else if (regnum
== MT_CONTEXT_REGNUM
)
514 /* Special output handling for 38-bit context register. */
516 unsigned int *bytes
, i
, regsize
;
518 regsize
= register_size (gdbarch
, regnum
);
520 buff
= alloca (regsize
);
521 bytes
= alloca (regsize
* sizeof (*bytes
));
523 frame_register_read (frame
, regnum
, buff
);
525 fputs_filtered (REGISTER_NAME (regnum
), file
);
526 print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum
)), file
);
527 fputs_filtered ("0x", file
);
529 for (i
= 0; i
< regsize
; i
++)
530 fprintf_filtered (file
, "%02x", (unsigned int)
531 extract_unsigned_integer (buff
+ i
, 1));
532 fputs_filtered ("\t", file
);
533 print_longest (file
, 'd', 0,
534 extract_unsigned_integer (buff
, regsize
));
535 fputs_filtered ("\n", file
);
537 else if (regnum
== MT_COPRO_REGNUM
538 || regnum
== MT_COPRO_PSEUDOREG_REGNUM
)
540 /* Special output handling for the 'coprocessor' register. */
543 buf
= alloca (register_size (gdbarch
, MT_COPRO_REGNUM
));
544 frame_register_read (frame
, MT_COPRO_REGNUM
, buf
);
546 regnum
= MT_COPRO_PSEUDOREG_REGNUM
;
547 fputs_filtered (REGISTER_NAME (regnum
), file
);
548 print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum
)), file
);
549 val_print (register_type (gdbarch
, regnum
), buf
,
550 0, 0, file
, 0, 1, 0, Val_no_prettyprint
);
551 fputs_filtered ("\n", file
);
553 else if (regnum
== MT_MAC_REGNUM
|| regnum
== MT_MAC_PSEUDOREG_REGNUM
)
555 ULONGEST oldmac
, ext_mac
, newmac
;
556 gdb_byte buf
[3 * sizeof (LONGEST
)];
558 /* Get the two "real" mac registers. */
559 frame_register_read (frame
, MT_MAC_REGNUM
, buf
);
560 oldmac
= extract_unsigned_integer
561 (buf
, register_size (gdbarch
, MT_MAC_REGNUM
));
562 if (gdbarch_bfd_arch_info (gdbarch
)->mach
== bfd_mach_mrisc2
563 || gdbarch_bfd_arch_info (gdbarch
)->mach
== bfd_mach_ms2
)
565 frame_register_read (frame
, MT_EXMAC_REGNUM
, buf
);
566 ext_mac
= extract_unsigned_integer
567 (buf
, register_size (gdbarch
, MT_EXMAC_REGNUM
));
572 /* Add them together. */
573 newmac
= (oldmac
& 0xffffffff) + ((ext_mac
& 0xff) << 32);
576 regnum
= MT_MAC_PSEUDOREG_REGNUM
;
577 fputs_filtered (REGISTER_NAME (regnum
), file
);
578 print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum
)), file
);
579 fputs_filtered ("0x", file
);
580 print_longest (file
, 'x', 0, newmac
);
581 fputs_filtered ("\t", file
);
582 print_longest (file
, 'u', 0, newmac
);
583 fputs_filtered ("\n", file
);
586 default_print_registers_info (gdbarch
, file
, frame
, regnum
, all
);
590 /* Set up the callee's arguments for an inferior function call. The
591 arguments are pushed on the stack or are placed in registers as
592 appropriate. It also sets up the return address (which points to
593 the call dummy breakpoint).
595 Returns the updated (and aligned) stack pointer. */
598 mt_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
599 struct regcache
*regcache
, CORE_ADDR bp_addr
,
600 int nargs
, struct value
**args
, CORE_ADDR sp
,
601 int struct_return
, CORE_ADDR struct_addr
)
604 gdb_byte buf
[MT_MAX_STRUCT_SIZE
];
605 int argreg
= MT_1ST_ARGREG
;
606 int split_param_len
= 0;
612 /* First handle however many args we can fit into MT_1ST_ARGREG thru
614 for (i
= 0; i
< nargs
&& argreg
<= MT_LAST_ARGREG
; i
++)
617 typelen
= TYPE_LENGTH (value_type (args
[i
]));
624 regcache_cooked_write_unsigned (regcache
, argreg
++,
625 extract_unsigned_integer
626 (value_contents (args
[i
]),
632 val
= value_contents (args
[i
]);
635 if (argreg
<= MT_LAST_ARGREG
)
637 /* This word of the argument is passed in a register. */
638 regcache_cooked_write_unsigned (regcache
, argreg
++,
639 extract_unsigned_integer
646 /* Remainder of this arg must be passed on the stack
647 (deferred to do later). */
648 split_param_len
= typelen
;
649 memcpy (buf
, val
, typelen
);
650 break; /* No more args can be handled in regs. */
655 /* By reverse engineering of gcc output, args bigger than
656 16 bytes go on the stack, and their address is passed
658 stack_dest
-= typelen
;
659 write_memory (stack_dest
, value_contents (args
[i
]), typelen
);
660 regcache_cooked_write_unsigned (regcache
, argreg
++, stack_dest
);
665 /* Next, the rest of the arguments go onto the stack, in reverse order. */
666 for (j
= nargs
- 1; j
>= i
; j
--)
670 /* Right-justify the value in an aligned-length buffer. */
671 typelen
= TYPE_LENGTH (value_type (args
[j
]));
672 slacklen
= (wordsize
- (typelen
% wordsize
)) % wordsize
;
673 val
= alloca (typelen
+ slacklen
);
674 memcpy (val
, value_contents (args
[j
]), typelen
);
675 memset (val
+ typelen
, 0, slacklen
);
676 /* Now write this data to the stack. */
677 stack_dest
-= typelen
+ slacklen
;
678 write_memory (stack_dest
, val
, typelen
+ slacklen
);
681 /* Finally, if a param needs to be split between registers and stack,
682 write the second half to the stack now. */
683 if (split_param_len
!= 0)
685 stack_dest
-= split_param_len
;
686 write_memory (stack_dest
, buf
, split_param_len
);
689 /* Set up return address (provided to us as bp_addr). */
690 regcache_cooked_write_unsigned (regcache
, MT_RA_REGNUM
, bp_addr
);
692 /* Store struct return address, if given. */
693 if (struct_return
&& struct_addr
!= 0)
694 regcache_cooked_write_unsigned (regcache
, MT_R11_REGNUM
, struct_addr
);
696 /* Set aside 16 bytes for the callee to save regs 1-4. */
699 /* Update the stack pointer. */
700 regcache_cooked_write_unsigned (regcache
, MT_SP_REGNUM
, stack_dest
);
702 /* And that should do it. Return the new stack pointer. */
707 /* The 'unwind_cache' data structure. */
709 struct mt_unwind_cache
711 /* The previous frame's inner most stack address.
712 Used as this frame ID's stack_addr. */
714 CORE_ADDR frame_base
;
718 /* Table indicating the location of each and every register. */
719 struct trad_frame_saved_reg
*saved_regs
;
722 /* Initialize an unwind_cache. Build up the saved_regs table etc. for
725 static struct mt_unwind_cache
*
726 mt_frame_unwind_cache (struct frame_info
*next_frame
,
727 void **this_prologue_cache
)
729 struct gdbarch
*gdbarch
;
730 struct mt_unwind_cache
*info
;
731 CORE_ADDR next_addr
, start_addr
, end_addr
, prologue_end_addr
;
732 unsigned long instr
, upper_half
, delayed_store
= 0;
736 if ((*this_prologue_cache
))
737 return (*this_prologue_cache
);
739 gdbarch
= get_frame_arch (next_frame
);
740 info
= FRAME_OBSTACK_ZALLOC (struct mt_unwind_cache
);
741 (*this_prologue_cache
) = info
;
745 info
->frame_base
= 0;
746 info
->frameless_p
= 1;
747 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
749 /* Grab the frame-relative values of SP and FP, needed below.
750 The frame_saved_register function will find them on the
751 stack or in the registers as appropriate. */
752 frame_unwind_unsigned_register (next_frame
, MT_SP_REGNUM
, &sp
);
753 frame_unwind_unsigned_register (next_frame
, MT_FP_REGNUM
, &fp
);
755 start_addr
= frame_func_unwind (next_frame
);
757 /* Return early if GDB couldn't find the function. */
761 end_addr
= frame_pc_unwind (next_frame
);
762 prologue_end_addr
= skip_prologue_using_sal (start_addr
);
764 for (next_addr
= start_addr
; next_addr
< end_addr
; next_addr
+= 4)
766 instr
= get_frame_memory_unsigned (next_frame
, next_addr
, 4);
767 if (delayed_store
) /* previous instr was a push */
769 upper_half
= delayed_store
>> 16;
770 regnum
= upper_half
& 0xf;
771 offset
= delayed_store
& 0xffff;
772 switch (upper_half
& 0xfff0)
774 case 0x43c0: /* push using frame pointer */
775 info
->saved_regs
[regnum
].addr
= offset
;
777 case 0x43d0: /* push using stack pointer */
778 info
->saved_regs
[regnum
].addr
= offset
;
788 case 0x12000000: /* NO-OP */
790 case 0x12ddc000: /* copy sp into fp */
791 info
->frameless_p
= 0; /* Record that the frame pointer is in use. */
794 upper_half
= instr
>> 16;
795 if (upper_half
== 0x05dd || /* subi sp, sp, imm */
796 upper_half
== 0x07dd) /* subui sp, sp, imm */
798 /* Record the frame size. */
799 info
->framesize
= instr
& 0xffff;
802 if ((upper_half
& 0xfff0) == 0x43c0 || /* frame push */
803 (upper_half
& 0xfff0) == 0x43d0) /* stack push */
805 /* Save this instruction, but don't record the
806 pushed register as 'saved' until we see the
807 next instruction. That's because of deferred stores
808 on this target -- GDB won't be able to read the register
809 from the stack until one instruction later. */
810 delayed_store
= instr
;
813 /* Not a prologue instruction. Is this the end of the prologue?
814 This is the most difficult decision; when to stop scanning.
816 If we have no line symbol, then the best thing we can do
817 is to stop scanning when we encounter an instruction that
818 is not likely to be a part of the prologue.
820 But if we do have a line symbol, then we should
821 keep scanning until we reach it (or we reach end_addr). */
823 if (prologue_end_addr
&& (prologue_end_addr
> (next_addr
+ 4)))
824 continue; /* Keep scanning, recording saved_regs etc. */
826 break; /* Quit scanning: breakpoint can be set here. */
830 /* Special handling for the "saved" address of the SP:
831 The SP is of course never saved on the stack at all, so
832 by convention what we put here is simply the previous
833 _value_ of the SP (as opposed to an address where the
834 previous value would have been pushed). This will also
835 give us the frame base address. */
837 if (info
->frameless_p
)
839 info
->frame_base
= sp
+ info
->framesize
;
840 info
->prev_sp
= sp
+ info
->framesize
;
844 info
->frame_base
= fp
+ info
->framesize
;
845 info
->prev_sp
= fp
+ info
->framesize
;
847 /* Save prev_sp in saved_regs as a value, not as an address. */
848 trad_frame_set_value (info
->saved_regs
, MT_SP_REGNUM
, info
->prev_sp
);
850 /* Now convert frame offsets to actual addresses (not offsets). */
851 for (regnum
= 0; regnum
< MT_NUM_REGS
; regnum
++)
852 if (trad_frame_addr_p (info
->saved_regs
, regnum
))
853 info
->saved_regs
[regnum
].addr
+= info
->frame_base
- info
->framesize
;
855 /* The call instruction moves the caller's PC in the callee's RA reg.
856 Since this is an unwind, do the reverse. Copy the location of RA
857 into PC (the address / regnum) so that a request for PC will be
858 converted into a request for the RA. */
859 info
->saved_regs
[MT_PC_REGNUM
] = info
->saved_regs
[MT_RA_REGNUM
];
865 mt_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
869 frame_unwind_unsigned_register (next_frame
, MT_PC_REGNUM
, &pc
);
874 mt_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
878 frame_unwind_unsigned_register (next_frame
, MT_SP_REGNUM
, &sp
);
882 /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
883 dummy frame. The frame ID's base needs to match the TOS value
884 saved by save_dummy_frame_tos(), and the PC match the dummy frame's
887 static struct frame_id
888 mt_unwind_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
890 return frame_id_build (mt_unwind_sp (gdbarch
, next_frame
),
891 frame_pc_unwind (next_frame
));
894 /* Given a GDB frame, determine the address of the calling function's
895 frame. This will be used to create a new GDB frame struct. */
898 mt_frame_this_id (struct frame_info
*next_frame
,
899 void **this_prologue_cache
, struct frame_id
*this_id
)
901 struct mt_unwind_cache
*info
=
902 mt_frame_unwind_cache (next_frame
, this_prologue_cache
);
904 if (!(info
== NULL
|| info
->prev_sp
== 0))
906 (*this_id
) = frame_id_build (info
->prev_sp
,
907 frame_func_unwind (next_frame
));
913 mt_frame_prev_register (struct frame_info
*next_frame
,
914 void **this_prologue_cache
,
915 int regnum
, int *optimizedp
,
916 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
917 int *realnump
, gdb_byte
*bufferp
)
919 struct mt_unwind_cache
*info
=
920 mt_frame_unwind_cache (next_frame
, this_prologue_cache
);
922 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
923 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
927 mt_frame_base_address (struct frame_info
*next_frame
,
928 void **this_prologue_cache
)
930 struct mt_unwind_cache
*info
=
931 mt_frame_unwind_cache (next_frame
, this_prologue_cache
);
933 return info
->frame_base
;
936 /* This is a shared interface: the 'frame_unwind' object is what's
937 returned by the 'sniffer' function, and in turn specifies how to
938 get a frame's ID and prev_regs.
940 This exports the 'prev_register' and 'this_id' methods. */
942 static const struct frame_unwind mt_frame_unwind
= {
945 mt_frame_prev_register
948 /* The sniffer is a registered function that identifies our family of
949 frame unwind functions (this_id and prev_register). */
951 static const struct frame_unwind
*
952 mt_frame_sniffer (struct frame_info
*next_frame
)
954 return &mt_frame_unwind
;
957 /* Another shared interface: the 'frame_base' object specifies how to
958 unwind a frame and secure the base addresses for frame objects
961 static struct frame_base mt_frame_base
= {
963 mt_frame_base_address
,
964 mt_frame_base_address
,
965 mt_frame_base_address
968 static struct gdbarch
*
969 mt_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
971 struct gdbarch
*gdbarch
;
973 /* Find a candidate among the list of pre-declared architectures. */
974 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
976 return arches
->gdbarch
;
978 /* None found, create a new architecture from the information
980 gdbarch
= gdbarch_alloc (&info
, NULL
);
982 switch (info
.byte_order
)
985 set_gdbarch_float_format (gdbarch
, &floatformat_ieee_single_big
);
986 set_gdbarch_double_format (gdbarch
, &floatformat_ieee_double_big
);
987 set_gdbarch_long_double_format (gdbarch
, &floatformat_ieee_double_big
);
989 case BFD_ENDIAN_LITTLE
:
990 set_gdbarch_float_format (gdbarch
, &floatformat_ieee_single_little
);
991 set_gdbarch_double_format (gdbarch
, &floatformat_ieee_double_little
);
992 set_gdbarch_long_double_format (gdbarch
,
993 &floatformat_ieee_double_little
);
996 internal_error (__FILE__
, __LINE__
,
997 _("mt_gdbarch_init: bad byte order for float format"));
1000 set_gdbarch_register_name (gdbarch
, mt_register_name
);
1001 set_gdbarch_num_regs (gdbarch
, MT_NUM_REGS
);
1002 set_gdbarch_num_pseudo_regs (gdbarch
, MT_NUM_PSEUDO_REGS
);
1003 set_gdbarch_pc_regnum (gdbarch
, MT_PC_REGNUM
);
1004 set_gdbarch_sp_regnum (gdbarch
, MT_SP_REGNUM
);
1005 set_gdbarch_pseudo_register_read (gdbarch
, mt_pseudo_register_read
);
1006 set_gdbarch_pseudo_register_write (gdbarch
, mt_pseudo_register_write
);
1007 set_gdbarch_skip_prologue (gdbarch
, mt_skip_prologue
);
1008 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1009 set_gdbarch_breakpoint_from_pc (gdbarch
, mt_breakpoint_from_pc
);
1010 set_gdbarch_decr_pc_after_break (gdbarch
, 0);
1011 set_gdbarch_frame_args_skip (gdbarch
, 0);
1012 set_gdbarch_print_insn (gdbarch
, print_insn_mt
);
1013 set_gdbarch_register_type (gdbarch
, mt_register_type
);
1014 set_gdbarch_register_reggroup_p (gdbarch
, mt_register_reggroup_p
);
1016 set_gdbarch_return_value (gdbarch
, mt_return_value
);
1017 set_gdbarch_sp_regnum (gdbarch
, MT_SP_REGNUM
);
1019 set_gdbarch_frame_align (gdbarch
, mt_frame_align
);
1021 set_gdbarch_print_registers_info (gdbarch
, mt_registers_info
);
1023 set_gdbarch_push_dummy_call (gdbarch
, mt_push_dummy_call
);
1025 /* Target builtin data types. */
1026 set_gdbarch_short_bit (gdbarch
, 16);
1027 set_gdbarch_int_bit (gdbarch
, 32);
1028 set_gdbarch_long_bit (gdbarch
, 32);
1029 set_gdbarch_long_long_bit (gdbarch
, 64);
1030 set_gdbarch_float_bit (gdbarch
, 32);
1031 set_gdbarch_double_bit (gdbarch
, 64);
1032 set_gdbarch_long_double_bit (gdbarch
, 64);
1033 set_gdbarch_ptr_bit (gdbarch
, 32);
1035 /* Register the DWARF 2 sniffer first, and then the traditional prologue
1037 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
1038 frame_unwind_append_sniffer (gdbarch
, mt_frame_sniffer
);
1039 frame_base_set_default (gdbarch
, &mt_frame_base
);
1041 /* Register the 'unwind_pc' method. */
1042 set_gdbarch_unwind_pc (gdbarch
, mt_unwind_pc
);
1043 set_gdbarch_unwind_sp (gdbarch
, mt_unwind_sp
);
1045 /* Methods for saving / extracting a dummy frame's ID.
1046 The ID's stack address must match the SP value returned by
1047 PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */
1048 set_gdbarch_unwind_dummy_id (gdbarch
, mt_unwind_dummy_id
);
1054 _initialize_mt_tdep (void)
1056 register_gdbarch_init (bfd_arch_mt
, mt_gdbarch_init
);