1 /* Target-dependent code for the Texas Instruments MSP430 for GDB, the
4 Copyright (C) 2012-2016 Free Software Foundation, Inc.
6 Contributed by Red Hat, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "arch-utils.h"
25 #include "prologue-value.h"
31 #include "frame-unwind.h"
32 #include "frame-base.h"
35 #include "dwarf2-frame.h"
36 #include "reggroups.h"
38 #include "elf/msp430.h"
39 #include "opcode/msp430-decode.h"
42 /* Register Numbers. */
56 MSP430_R10_RAW_REGNUM
,
57 MSP430_R11_RAW_REGNUM
,
58 MSP430_R12_RAW_REGNUM
,
59 MSP430_R13_RAW_REGNUM
,
60 MSP430_R14_RAW_REGNUM
,
61 MSP430_R15_RAW_REGNUM
,
65 MSP430_PC_REGNUM
= MSP430_NUM_REGS
,
82 MSP430_NUM_TOTAL_REGS
,
83 MSP430_NUM_PSEUDO_REGS
= MSP430_NUM_TOTAL_REGS
- MSP430_NUM_REGS
88 /* TI MSP430 Architecture. */
91 /* TI MSP430X Architecture. */
97 /* The small code model limits code addresses to 16 bits. */
100 /* The large code model uses 20 bit addresses for function
101 pointers. These are stored in memory using four bytes (32 bits). */
105 /* Architecture specific data. */
109 /* The ELF header flags specify the multilib used. */
112 /* One of MSP_ISA_MSP430 or MSP_ISA_MSP430X. */
115 /* One of MSP_SMALL_CODE_MODEL or MSP_LARGE_CODE_MODEL. If, at
116 some point, we support different data models too, we'll probably
117 structure things so that we can combine values using logical
122 /* This structure holds the results of a prologue analysis. */
124 struct msp430_prologue
126 /* The offset from the frame base to the stack pointer --- always
129 Calling this a "size" is a bit misleading, but given that the
130 stack grows downwards, using offsets for everything keeps one
131 from going completely sign-crazy: you never change anything's
132 sign for an ADD instruction; always change the second operand's
133 sign for a SUB instruction; and everything takes care of
137 /* Non-zero if this function has initialized the frame pointer from
138 the stack pointer, zero otherwise. */
141 /* If has_frame_ptr is non-zero, this is the offset from the frame
142 base to where the frame pointer points. This is always zero or
144 int frame_ptr_offset
;
146 /* The address of the first instruction at which the frame has been
147 set up and the arguments are where the debug info says they are
148 --- as best as we can tell. */
149 CORE_ADDR prologue_end
;
151 /* reg_offset[R] is the offset from the CFA at which register R is
152 saved, or 1 if register R has not been saved. (Real values are
153 always zero or negative.) */
154 int reg_offset
[MSP430_NUM_TOTAL_REGS
];
157 /* Implement the "register_type" gdbarch method. */
160 msp430_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
162 if (reg_nr
< MSP430_NUM_REGS
)
163 return builtin_type (gdbarch
)->builtin_uint32
;
164 else if (reg_nr
== MSP430_PC_REGNUM
)
165 return builtin_type (gdbarch
)->builtin_func_ptr
;
167 return builtin_type (gdbarch
)->builtin_uint16
;
170 /* Implement another version of the "register_type" gdbarch method
174 msp430x_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
176 if (reg_nr
< MSP430_NUM_REGS
)
177 return builtin_type (gdbarch
)->builtin_uint32
;
178 else if (reg_nr
== MSP430_PC_REGNUM
)
179 return builtin_type (gdbarch
)->builtin_func_ptr
;
181 return builtin_type (gdbarch
)->builtin_uint32
;
184 /* Implement the "register_name" gdbarch method. */
187 msp430_register_name (struct gdbarch
*gdbarch
, int regnr
)
189 static const char *const reg_names
[] = {
191 "", "", "", "", "", "", "", "",
192 "", "", "", "", "", "", "", "",
193 /* Pseudo registers. */
194 "pc", "sp", "sr", "cg", "r4", "r5", "r6", "r7",
195 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
198 return reg_names
[regnr
];
201 /* Implement the "register_reggroup_p" gdbarch method. */
204 msp430_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
205 struct reggroup
*group
)
207 if (group
== all_reggroup
)
210 /* All other registers are saved and restored. */
211 if (group
== save_reggroup
|| group
== restore_reggroup
)
212 return (MSP430_NUM_REGS
<= regnum
&& regnum
< MSP430_NUM_TOTAL_REGS
);
214 return group
== general_reggroup
;
217 /* Implement the "pseudo_register_read" gdbarch method. */
219 static enum register_status
220 msp430_pseudo_register_read (struct gdbarch
*gdbarch
,
221 struct regcache
*regcache
,
222 int regnum
, gdb_byte
*buffer
)
224 enum register_status status
= REG_UNKNOWN
;
226 if (MSP430_NUM_REGS
<= regnum
&& regnum
< MSP430_NUM_TOTAL_REGS
)
229 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
230 int regsize
= register_size (gdbarch
, regnum
);
231 int raw_regnum
= regnum
- MSP430_NUM_REGS
;
233 status
= regcache_raw_read_unsigned (regcache
, raw_regnum
, &val
);
234 if (status
== REG_VALID
)
235 store_unsigned_integer (buffer
, regsize
, byte_order
, val
);
239 gdb_assert_not_reached ("invalid pseudo register number");
244 /* Implement the "pseudo_register_write" gdbarch method. */
247 msp430_pseudo_register_write (struct gdbarch
*gdbarch
,
248 struct regcache
*regcache
,
249 int regnum
, const gdb_byte
*buffer
)
251 if (MSP430_NUM_REGS
<= regnum
&& regnum
< MSP430_NUM_TOTAL_REGS
)
255 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
256 int regsize
= register_size (gdbarch
, regnum
);
257 int raw_regnum
= regnum
- MSP430_NUM_REGS
;
259 val
= extract_unsigned_integer (buffer
, regsize
, byte_order
);
260 regcache_raw_write_unsigned (regcache
, raw_regnum
, val
);
264 gdb_assert_not_reached ("invalid pseudo register number");
267 /* Implement the `register_sim_regno' gdbarch method. */
270 msp430_register_sim_regno (struct gdbarch
*gdbarch
, int regnum
)
272 gdb_assert (regnum
< MSP430_NUM_REGS
);
274 /* So long as regnum is in [0, RL78_NUM_REGS), it's valid. We
275 just want to override the default here which disallows register
276 numbers which have no names. */
280 /* Implement the "breakpoint_from_pc" gdbarch method. */
282 static const gdb_byte
*
283 msp430_breakpoint_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
*pcptr
,
286 static gdb_byte breakpoint
[] = { 0x43, 0x43 };
288 *lenptr
= sizeof breakpoint
;
292 /* Define a "handle" struct for fetching the next opcode. */
294 struct msp430_get_opcode_byte_handle
299 /* Fetch a byte on behalf of the opcode decoder. HANDLE contains
300 the memory address of the next byte to fetch. If successful,
301 the address in the handle is updated and the byte fetched is
302 returned as the value of the function. If not successful, -1
306 msp430_get_opcode_byte (void *handle
)
308 struct msp430_get_opcode_byte_handle
*opcdata
309 = (struct msp430_get_opcode_byte_handle
*) handle
;
313 status
= target_read_memory (opcdata
->pc
, &byte
, 1);
323 /* Function for finding saved registers in a 'struct pv_area'; this
324 function is passed to pv_area_scan.
326 If VALUE is a saved register, ADDR says it was saved at a constant
327 offset from the frame base, and SIZE indicates that the whole
328 register was saved, record its offset. */
331 check_for_saved (void *result_untyped
, pv_t addr
, CORE_ADDR size
, pv_t value
)
333 struct msp430_prologue
*result
= (struct msp430_prologue
*) result_untyped
;
335 if (value
.kind
== pvk_register
337 && pv_is_register (addr
, MSP430_SP_REGNUM
)
338 && size
== register_size (target_gdbarch (), value
.reg
))
339 result
->reg_offset
[value
.reg
] = addr
.k
;
342 /* Analyze a prologue starting at START_PC, going no further than
343 LIMIT_PC. Fill in RESULT as appropriate. */
346 msp430_analyze_prologue (struct gdbarch
*gdbarch
, CORE_ADDR start_pc
,
347 CORE_ADDR limit_pc
, struct msp430_prologue
*result
)
349 CORE_ADDR pc
, next_pc
;
351 pv_t reg
[MSP430_NUM_TOTAL_REGS
];
352 struct pv_area
*stack
;
353 struct cleanup
*back_to
;
354 CORE_ADDR after_last_frame_setup_insn
= start_pc
;
355 int code_model
= gdbarch_tdep (gdbarch
)->code_model
;
358 memset (result
, 0, sizeof (*result
));
360 for (rn
= 0; rn
< MSP430_NUM_TOTAL_REGS
; rn
++)
362 reg
[rn
] = pv_register (rn
, 0);
363 result
->reg_offset
[rn
] = 1;
366 stack
= make_pv_area (MSP430_SP_REGNUM
, gdbarch_addr_bit (gdbarch
));
367 back_to
= make_cleanup_free_pv_area (stack
);
369 /* The call instruction has saved the return address on the stack. */
370 sz
= code_model
== MSP_LARGE_CODE_MODEL
? 4 : 2;
371 reg
[MSP430_SP_REGNUM
] = pv_add_constant (reg
[MSP430_SP_REGNUM
], -sz
);
372 pv_area_store (stack
, reg
[MSP430_SP_REGNUM
], sz
, reg
[MSP430_PC_REGNUM
]);
375 while (pc
< limit_pc
)
378 struct msp430_get_opcode_byte_handle opcode_handle
;
379 MSP430_Opcode_Decoded opc
;
381 opcode_handle
.pc
= pc
;
382 bytes_read
= msp430_decode_opcode (pc
, &opc
, msp430_get_opcode_byte
,
384 next_pc
= pc
+ bytes_read
;
386 if (opc
.id
== MSO_push
&& opc
.op
[0].type
== MSP430_Operand_Register
)
388 int rsrc
= opc
.op
[0].reg
;
390 reg
[MSP430_SP_REGNUM
] = pv_add_constant (reg
[MSP430_SP_REGNUM
], -2);
391 pv_area_store (stack
, reg
[MSP430_SP_REGNUM
], 2, reg
[rsrc
]);
392 after_last_frame_setup_insn
= next_pc
;
394 else if (opc
.id
== MSO_push
/* PUSHM */
395 && opc
.op
[0].type
== MSP430_Operand_None
396 && opc
.op
[1].type
== MSP430_Operand_Register
)
398 int rsrc
= opc
.op
[1].reg
;
399 int count
= opc
.repeats
+ 1;
400 int size
= opc
.size
== 16 ? 2 : 4;
404 reg
[MSP430_SP_REGNUM
]
405 = pv_add_constant (reg
[MSP430_SP_REGNUM
], -size
);
406 pv_area_store (stack
, reg
[MSP430_SP_REGNUM
], size
, reg
[rsrc
]);
410 after_last_frame_setup_insn
= next_pc
;
412 else if (opc
.id
== MSO_sub
413 && opc
.op
[0].type
== MSP430_Operand_Register
414 && opc
.op
[0].reg
== MSR_SP
415 && opc
.op
[1].type
== MSP430_Operand_Immediate
)
417 int addend
= opc
.op
[1].addend
;
419 reg
[MSP430_SP_REGNUM
] = pv_add_constant (reg
[MSP430_SP_REGNUM
],
421 after_last_frame_setup_insn
= next_pc
;
423 else if (opc
.id
== MSO_mov
424 && opc
.op
[0].type
== MSP430_Operand_Immediate
425 && 12 <= opc
.op
[0].reg
&& opc
.op
[0].reg
<= 15)
426 after_last_frame_setup_insn
= next_pc
;
429 /* Terminate the prologue scan. */
436 /* Is the frame size (offset, really) a known constant? */
437 if (pv_is_register (reg
[MSP430_SP_REGNUM
], MSP430_SP_REGNUM
))
438 result
->frame_size
= reg
[MSP430_SP_REGNUM
].k
;
440 /* Record where all the registers were saved. */
441 pv_area_scan (stack
, check_for_saved
, result
);
443 result
->prologue_end
= after_last_frame_setup_insn
;
445 do_cleanups (back_to
);
448 /* Implement the "skip_prologue" gdbarch method. */
451 msp430_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
454 CORE_ADDR func_addr
, func_end
;
455 struct msp430_prologue p
;
457 /* Try to find the extent of the function that contains PC. */
458 if (!find_pc_partial_function (pc
, &name
, &func_addr
, &func_end
))
461 msp430_analyze_prologue (gdbarch
, pc
, func_end
, &p
);
462 return p
.prologue_end
;
465 /* Implement the "unwind_pc" gdbarch method. */
468 msp430_unwind_pc (struct gdbarch
*arch
, struct frame_info
*next_frame
)
470 return frame_unwind_register_unsigned (next_frame
, MSP430_PC_REGNUM
);
473 /* Implement the "unwind_sp" gdbarch method. */
476 msp430_unwind_sp (struct gdbarch
*arch
, struct frame_info
*next_frame
)
478 return frame_unwind_register_unsigned (next_frame
, MSP430_SP_REGNUM
);
481 /* Given a frame described by THIS_FRAME, decode the prologue of its
482 associated function if there is not cache entry as specified by
483 THIS_PROLOGUE_CACHE. Save the decoded prologue in the cache and
484 return that struct as the value of this function. */
486 static struct msp430_prologue
*
487 msp430_analyze_frame_prologue (struct frame_info
*this_frame
,
488 void **this_prologue_cache
)
490 if (!*this_prologue_cache
)
492 CORE_ADDR func_start
, stop_addr
;
494 *this_prologue_cache
= FRAME_OBSTACK_ZALLOC (struct msp430_prologue
);
496 func_start
= get_frame_func (this_frame
);
497 stop_addr
= get_frame_pc (this_frame
);
499 /* If we couldn't find any function containing the PC, then
500 just initialize the prologue cache, but don't do anything. */
502 stop_addr
= func_start
;
504 msp430_analyze_prologue (get_frame_arch (this_frame
), func_start
,
506 (struct msp430_prologue
*) *this_prologue_cache
);
509 return (struct msp430_prologue
*) *this_prologue_cache
;
512 /* Given a frame and a prologue cache, return this frame's base. */
515 msp430_frame_base (struct frame_info
*this_frame
, void **this_prologue_cache
)
517 struct msp430_prologue
*p
518 = msp430_analyze_frame_prologue (this_frame
, this_prologue_cache
);
519 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, MSP430_SP_REGNUM
);
521 return sp
- p
->frame_size
;
524 /* Implement the "frame_this_id" method for unwinding frames. */
527 msp430_this_id (struct frame_info
*this_frame
,
528 void **this_prologue_cache
, struct frame_id
*this_id
)
530 *this_id
= frame_id_build (msp430_frame_base (this_frame
,
531 this_prologue_cache
),
532 get_frame_func (this_frame
));
535 /* Implement the "frame_prev_register" method for unwinding frames. */
537 static struct value
*
538 msp430_prev_register (struct frame_info
*this_frame
,
539 void **this_prologue_cache
, int regnum
)
541 struct msp430_prologue
*p
542 = msp430_analyze_frame_prologue (this_frame
, this_prologue_cache
);
543 CORE_ADDR frame_base
= msp430_frame_base (this_frame
, this_prologue_cache
);
545 if (regnum
== MSP430_SP_REGNUM
)
546 return frame_unwind_got_constant (this_frame
, regnum
, frame_base
);
548 /* If prologue analysis says we saved this register somewhere,
549 return a description of the stack slot holding it. */
550 else if (p
->reg_offset
[regnum
] != 1)
552 struct value
*rv
= frame_unwind_got_memory (this_frame
, regnum
,
554 p
->reg_offset
[regnum
]);
556 if (regnum
== MSP430_PC_REGNUM
)
558 ULONGEST pc
= value_as_long (rv
);
560 return frame_unwind_got_constant (this_frame
, regnum
, pc
);
565 /* Otherwise, presume we haven't changed the value of this
566 register, and get it from the next frame. */
568 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
571 static const struct frame_unwind msp430_unwind
= {
573 default_frame_unwind_stop_reason
,
575 msp430_prev_register
,
577 default_frame_sniffer
580 /* Implement the "dwarf2_reg_to_regnum" gdbarch method. */
583 msp430_dwarf2_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
585 if (reg
>= 0 && reg
< MSP430_NUM_REGS
)
586 return reg
+ MSP430_NUM_REGS
;
590 /* Implement the "return_value" gdbarch method. */
592 static enum return_value_convention
593 msp430_return_value (struct gdbarch
*gdbarch
,
594 struct value
*function
,
595 struct type
*valtype
,
596 struct regcache
*regcache
,
597 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
599 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
600 LONGEST valtype_len
= TYPE_LENGTH (valtype
);
601 int code_model
= gdbarch_tdep (gdbarch
)->code_model
;
603 if (TYPE_LENGTH (valtype
) > 8
604 || TYPE_CODE (valtype
) == TYPE_CODE_STRUCT
605 || TYPE_CODE (valtype
) == TYPE_CODE_UNION
)
606 return RETURN_VALUE_STRUCT_CONVENTION
;
611 int argreg
= MSP430_R12_REGNUM
;
614 while (valtype_len
> 0)
618 if (code_model
== MSP_LARGE_CODE_MODEL
619 && TYPE_CODE (valtype
) == TYPE_CODE_PTR
)
624 regcache_cooked_read_unsigned (regcache
, argreg
, &u
);
625 store_unsigned_integer (readbuf
+ offset
, size
, byte_order
, u
);
635 int argreg
= MSP430_R12_REGNUM
;
638 while (valtype_len
> 0)
642 if (code_model
== MSP_LARGE_CODE_MODEL
643 && TYPE_CODE (valtype
) == TYPE_CODE_PTR
)
648 u
= extract_unsigned_integer (writebuf
+ offset
, size
, byte_order
);
649 regcache_cooked_write_unsigned (regcache
, argreg
, u
);
656 return RETURN_VALUE_REGISTER_CONVENTION
;
660 /* Implement the "frame_align" gdbarch method. */
663 msp430_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
665 return align_down (sp
, 2);
669 /* Implement the "dummy_id" gdbarch method. */
671 static struct frame_id
672 msp430_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
675 frame_id_build (get_frame_register_unsigned
676 (this_frame
, MSP430_SP_REGNUM
),
677 get_frame_pc (this_frame
));
681 /* Implement the "push_dummy_call" gdbarch method. */
684 msp430_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
685 struct regcache
*regcache
, CORE_ADDR bp_addr
,
686 int nargs
, struct value
**args
, CORE_ADDR sp
,
687 int struct_return
, CORE_ADDR struct_addr
)
689 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
693 int code_model
= gdbarch_tdep (gdbarch
)->code_model
;
695 struct type
*func_type
= value_type (function
);
697 /* Dereference function pointer types. */
698 while (TYPE_CODE (func_type
) == TYPE_CODE_PTR
)
699 func_type
= TYPE_TARGET_TYPE (func_type
);
701 /* The end result had better be a function or a method. */
702 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
703 || TYPE_CODE (func_type
) == TYPE_CODE_METHOD
);
705 /* We make two passes; the first does the stack allocation,
706 the second actually stores the arguments. */
707 for (write_pass
= 0; write_pass
<= 1; write_pass
++)
710 int arg_reg
= MSP430_R12_REGNUM
;
711 int args_on_stack
= 0;
714 sp
= align_down (sp
- sp_off
, 4);
720 regcache_cooked_write_unsigned (regcache
, arg_reg
, struct_addr
);
724 /* Push the arguments. */
725 for (i
= 0; i
< nargs
; i
++)
727 struct value
*arg
= args
[i
];
728 const gdb_byte
*arg_bits
= value_contents_all (arg
);
729 struct type
*arg_type
= check_typedef (value_type (arg
));
730 ULONGEST arg_size
= TYPE_LENGTH (arg_type
);
732 int current_arg_on_stack
;
734 current_arg_on_stack
= 0;
736 if (TYPE_CODE (arg_type
) == TYPE_CODE_STRUCT
737 || TYPE_CODE (arg_type
) == TYPE_CODE_UNION
)
739 /* Aggregates of any size are passed by reference. */
740 gdb_byte struct_addr
[4];
742 store_unsigned_integer (struct_addr
, 4, byte_order
,
743 value_address (arg
));
744 arg_bits
= struct_addr
;
745 arg_size
= (code_model
== MSP_LARGE_CODE_MODEL
) ? 4 : 2;
749 /* Scalars bigger than 8 bytes such as complex doubles are passed
752 current_arg_on_stack
= 1;
756 for (offset
= 0; offset
< arg_size
; offset
+= 2)
758 /* The condition below prevents 8 byte scalars from being split
759 between registers and memory (stack). It also prevents other
760 splits once the stack has been written to. */
761 if (!current_arg_on_stack
763 + ((arg_size
== 8 || args_on_stack
)
764 ? ((arg_size
- offset
) / 2 - 1)
765 : 0) <= MSP430_R15_REGNUM
))
769 if (code_model
== MSP_LARGE_CODE_MODEL
770 && (TYPE_CODE (arg_type
) == TYPE_CODE_PTR
771 || TYPE_CODE (arg_type
) == TYPE_CODE_REF
772 || TYPE_CODE (arg_type
) == TYPE_CODE_STRUCT
773 || TYPE_CODE (arg_type
) == TYPE_CODE_UNION
))
775 /* When using the large memory model, pointer,
776 reference, struct, and union arguments are
777 passed using the entire register. (As noted
778 earlier, aggregates are always passed by
786 regcache_cooked_write_unsigned (regcache
, arg_reg
,
787 extract_unsigned_integer
788 (arg_bits
+ offset
, size
,
796 write_memory (sp
+ sp_off
, arg_bits
+ offset
, 2);
800 current_arg_on_stack
= 1;
806 /* Keep track of the stack address prior to pushing the return address.
807 This is the value that we'll return. */
810 /* Push the return address. */
812 int sz
= (gdbarch_tdep (gdbarch
)->code_model
== MSP_SMALL_CODE_MODEL
)
815 write_memory_unsigned_integer (sp
, sz
, byte_order
, bp_addr
);
818 /* Update the stack pointer. */
819 regcache_cooked_write_unsigned (regcache
, MSP430_SP_REGNUM
, sp
);
824 /* In order to keep code size small, the compiler may create epilogue
825 code through which more than one function epilogue is routed. I.e.
826 the epilogue and return may just be a branch to some common piece of
827 code which is responsible for tearing down the frame and performing
828 the return. These epilog (label) names will have the common prefix
831 static const char msp430_epilog_name_prefix
[] = "__mspabi_func_epilog_";
833 /* Implement the "in_return_stub" gdbarch method. */
836 msp430_in_return_stub (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
840 && startswith (name
, msp430_epilog_name_prefix
));
843 /* Implement the "skip_trampoline_code" gdbarch method. */
845 msp430_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
847 struct bound_minimal_symbol bms
;
848 const char *stub_name
;
849 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
851 bms
= lookup_minimal_symbol_by_pc (pc
);
855 stub_name
= MSYMBOL_LINKAGE_NAME (bms
.minsym
);
857 if (gdbarch_tdep (gdbarch
)->code_model
== MSP_SMALL_CODE_MODEL
858 && msp430_in_return_stub (gdbarch
, pc
, stub_name
))
860 CORE_ADDR sp
= get_frame_register_unsigned (frame
, MSP430_SP_REGNUM
);
862 return read_memory_integer
863 (sp
+ 2 * (stub_name
[strlen (msp430_epilog_name_prefix
)] - '0'),
864 2, gdbarch_byte_order (gdbarch
));
870 /* Allocate and initialize a gdbarch object. */
872 static struct gdbarch
*
873 msp430_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
875 struct gdbarch
*gdbarch
;
876 struct gdbarch_tdep
*tdep
;
877 int elf_flags
, isa
, code_model
;
879 /* Extract the elf_flags if available. */
880 if (info
.abfd
!= NULL
881 && bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
882 elf_flags
= elf_elfheader (info
.abfd
)->e_flags
;
886 if (info
.abfd
!= NULL
)
887 switch (bfd_elf_get_obj_attr_int (info
.abfd
, OBJ_ATTR_PROC
,
888 OFBA_MSPABI_Tag_ISA
))
891 isa
= MSP_ISA_MSP430
;
892 code_model
= MSP_SMALL_CODE_MODEL
;
895 isa
= MSP_ISA_MSP430X
;
896 switch (bfd_elf_get_obj_attr_int (info
.abfd
, OBJ_ATTR_PROC
,
897 OFBA_MSPABI_Tag_Code_Model
))
900 code_model
= MSP_SMALL_CODE_MODEL
;
903 code_model
= MSP_LARGE_CODE_MODEL
;
906 internal_error (__FILE__
, __LINE__
,
907 _("Unknown msp430x code memory model"));
912 /* This can happen when loading a previously dumped data structure.
913 Use the ISA and code model from the current architecture, provided
916 struct gdbarch
*ca
= get_current_arch ();
917 if (ca
&& gdbarch_bfd_arch_info (ca
)->arch
== bfd_arch_msp430
)
919 struct gdbarch_tdep
*ca_tdep
= gdbarch_tdep (ca
);
921 elf_flags
= ca_tdep
->elf_flags
;
923 code_model
= ca_tdep
->code_model
;
926 /* Otherwise, fall through... */
929 error (_("Unknown msp430 isa"));
934 isa
= MSP_ISA_MSP430
;
935 code_model
= MSP_SMALL_CODE_MODEL
;
939 /* Try to find the architecture in the list of already defined
941 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
943 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
945 struct gdbarch_tdep
*candidate_tdep
= gdbarch_tdep (arches
->gdbarch
);
947 if (candidate_tdep
->elf_flags
!= elf_flags
948 || candidate_tdep
->isa
!= isa
949 || candidate_tdep
->code_model
!= code_model
)
952 return arches
->gdbarch
;
955 /* None found, create a new architecture from the information
957 tdep
= XNEW (struct gdbarch_tdep
);
958 gdbarch
= gdbarch_alloc (&info
, tdep
);
959 tdep
->elf_flags
= elf_flags
;
961 tdep
->code_model
= code_model
;
964 set_gdbarch_num_regs (gdbarch
, MSP430_NUM_REGS
);
965 set_gdbarch_num_pseudo_regs (gdbarch
, MSP430_NUM_PSEUDO_REGS
);
966 set_gdbarch_register_name (gdbarch
, msp430_register_name
);
967 if (isa
== MSP_ISA_MSP430
)
968 set_gdbarch_register_type (gdbarch
, msp430_register_type
);
970 set_gdbarch_register_type (gdbarch
, msp430x_register_type
);
971 set_gdbarch_pc_regnum (gdbarch
, MSP430_PC_REGNUM
);
972 set_gdbarch_sp_regnum (gdbarch
, MSP430_SP_REGNUM
);
973 set_gdbarch_register_reggroup_p (gdbarch
, msp430_register_reggroup_p
);
974 set_gdbarch_pseudo_register_read (gdbarch
, msp430_pseudo_register_read
);
975 set_gdbarch_pseudo_register_write (gdbarch
, msp430_pseudo_register_write
);
976 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, msp430_dwarf2_reg_to_regnum
);
977 set_gdbarch_register_sim_regno (gdbarch
, msp430_register_sim_regno
);
980 set_gdbarch_char_signed (gdbarch
, 0);
981 set_gdbarch_short_bit (gdbarch
, 16);
982 set_gdbarch_int_bit (gdbarch
, 16);
983 set_gdbarch_long_bit (gdbarch
, 32);
984 set_gdbarch_long_long_bit (gdbarch
, 64);
985 if (code_model
== MSP_SMALL_CODE_MODEL
)
987 set_gdbarch_ptr_bit (gdbarch
, 16);
988 set_gdbarch_addr_bit (gdbarch
, 16);
990 else /* MSP_LARGE_CODE_MODEL */
992 set_gdbarch_ptr_bit (gdbarch
, 32);
993 set_gdbarch_addr_bit (gdbarch
, 32);
995 set_gdbarch_dwarf2_addr_size (gdbarch
, 4);
996 set_gdbarch_float_bit (gdbarch
, 32);
997 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
998 set_gdbarch_double_bit (gdbarch
, 64);
999 set_gdbarch_long_double_bit (gdbarch
, 64);
1000 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
1001 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_double
);
1004 set_gdbarch_breakpoint_from_pc (gdbarch
, msp430_breakpoint_from_pc
);
1005 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
1008 set_gdbarch_print_insn (gdbarch
, print_insn_msp430
);
1010 /* Frames, prologues, etc. */
1011 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1012 set_gdbarch_skip_prologue (gdbarch
, msp430_skip_prologue
);
1013 set_gdbarch_unwind_pc (gdbarch
, msp430_unwind_pc
);
1014 set_gdbarch_unwind_sp (gdbarch
, msp430_unwind_sp
);
1015 set_gdbarch_frame_align (gdbarch
, msp430_frame_align
);
1016 dwarf2_append_unwinders (gdbarch
);
1017 frame_unwind_append_unwinder (gdbarch
, &msp430_unwind
);
1019 /* Dummy frames, return values. */
1020 set_gdbarch_dummy_id (gdbarch
, msp430_dummy_id
);
1021 set_gdbarch_push_dummy_call (gdbarch
, msp430_push_dummy_call
);
1022 set_gdbarch_return_value (gdbarch
, msp430_return_value
);
1025 set_gdbarch_in_solib_return_trampoline (gdbarch
, msp430_in_return_stub
);
1026 set_gdbarch_skip_trampoline_code (gdbarch
, msp430_skip_trampoline_code
);
1028 /* Virtual tables. */
1029 set_gdbarch_vbit_in_delta (gdbarch
, 0);
1034 /* -Wmissing-prototypes */
1035 extern initialize_file_ftype _initialize_msp430_tdep
;
1037 /* Register the initialization routine. */
1040 _initialize_msp430_tdep (void)
1042 register_gdbarch_init (bfd_arch_msp430
, msp430_gdbarch_init
);