1 /* Target-machine dependent code for Hitachi H8/300, for GDB.
3 Copyright 1988, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
4 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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,
21 Boston, MA 02111-1307, USA. */
24 Contributed by Steve Chamberlain
32 #include "arch-utils.h"
37 #include "gdb_assert.h"
39 /* Extra info which is saved in each frame_info. */
40 struct frame_extra_info
43 CORE_ADDR args_pointer
;
44 CORE_ADDR locals_pointer
;
51 h8300_max_reg_size
= 4,
53 #define BINWORD (h8300hmode ? h8300h_reg_size : h8300_reg_size)
57 E_R0_REGNUM
, E_ER0_REGNUM
= E_R0_REGNUM
, E_ARG0_REGNUM
= E_R0_REGNUM
,
58 E_R1_REGNUM
, E_ER1_REGNUM
= E_R1_REGNUM
,
59 E_R2_REGNUM
, E_ER2_REGNUM
= E_R2_REGNUM
, E_ARGLAST_REGNUM
= E_R2_REGNUM
,
60 E_R3_REGNUM
, E_ER3_REGNUM
= E_R3_REGNUM
,
61 E_R4_REGNUM
, E_ER4_REGNUM
= E_R4_REGNUM
,
62 E_R5_REGNUM
, E_ER5_REGNUM
= E_R5_REGNUM
,
63 E_R6_REGNUM
, E_ER6_REGNUM
= E_R6_REGNUM
, E_FP_REGNUM
= E_R6_REGNUM
,
68 E_TICK_REGNUM
, E_EXR_REGNUM
= E_TICK_REGNUM
,
69 E_INST_REGNUM
, E_TICKS_REGNUM
= E_INST_REGNUM
,
77 #define UNSIGNED_SHORT(X) ((X) & 0xffff)
79 #define IS_PUSH(x) ((x & 0xfff0)==0x6df0)
80 #define IS_PUSH_FP(x) (x == 0x6df6)
81 #define IS_MOVE_FP(x) (x == 0x0d76 || x == 0x0ff6)
82 #define IS_MOV_SP_FP(x) (x == 0x0d76 || x == 0x0ff6)
83 #define IS_SUB2_SP(x) (x==0x1b87)
84 #define IS_SUB4_SP(x) (x==0x1b97)
85 #define IS_SUBL_SP(x) (x==0x7a37)
86 #define IS_MOVK_R5(x) (x==0x7905)
87 #define IS_SUB_R5SP(x) (x==0x1957)
89 /* If the instruction at PC is an argument register spill, return its
90 length. Otherwise, return zero.
92 An argument register spill is an instruction that moves an argument
93 from the register in which it was passed to the stack slot in which
94 it really lives. It is a byte, word, or longword move from an
95 argument register to a negative offset from the frame pointer. */
98 h8300_is_argument_spill (CORE_ADDR pc
)
100 int w
= read_memory_unsigned_integer (pc
, 2);
102 if ((w
& 0xfff0) == 0x6ee0 /* mov.b Rs,@(d:16,er6) */
103 && 8 <= (w
& 0xf) && (w
& 0xf) <= 10) /* Rs is R0L, R1L, or R2L */
105 int w2
= read_memory_integer (pc
+ 2, 2);
107 /* ... and d:16 is negative. */
111 else if (w
== 0x7860)
113 int w2
= read_memory_integer (pc
+ 2, 2);
115 if ((w2
& 0xfff0) == 0x6aa0) /* mov.b Rs, @(d:24,er6) */
117 LONGEST disp
= read_memory_integer (pc
+ 4, 4);
119 /* ... and d:24 is negative. */
120 if (disp
< 0 && disp
> 0xffffff)
124 else if ((w
& 0xfff0) == 0x6fe0 /* mov.w Rs,@(d:16,er6) */
125 && (w
& 0xf) <= 2) /* Rs is R0, R1, or R2 */
127 int w2
= read_memory_integer (pc
+ 2, 2);
129 /* ... and d:16 is negative. */
133 else if (w
== 0x78e0)
135 int w2
= read_memory_integer (pc
+ 2, 2);
137 if ((w2
& 0xfff0) == 0x6ba0) /* mov.b Rs, @(d:24,er6) */
139 LONGEST disp
= read_memory_integer (pc
+ 4, 4);
141 /* ... and d:24 is negative. */
142 if (disp
< 0 && disp
> 0xffffff)
146 else if (w
== 0x0100)
148 int w2
= read_memory_integer (pc
+ 2, 2);
150 if ((w2
& 0xfff0) == 0x6fe0 /* mov.l Rs,@(d:16,er6) */
151 && (w2
& 0xf) <= 2) /* Rs is ER0, ER1, or ER2 */
153 int w3
= read_memory_integer (pc
+ 4, 2);
155 /* ... and d:16 is negative. */
159 else if (w2
== 0x78e0)
161 int w3
= read_memory_integer (pc
+ 4, 2);
163 if ((w3
& 0xfff0) == 0x6ba0) /* mov.l Rs, @(d:24,er6) */
165 LONGEST disp
= read_memory_integer (pc
+ 6, 4);
167 /* ... and d:24 is negative. */
168 if (disp
< 0 && disp
> 0xffffff)
178 h8300_skip_prologue (CORE_ADDR start_pc
)
183 /* Skip past all push and stm insns. */
186 w
= read_memory_unsigned_integer (start_pc
, 2);
187 /* First look for push insns. */
188 if (w
== 0x0100 || w
== 0x0110 || w
== 0x0120 || w
== 0x0130)
190 w
= read_memory_unsigned_integer (start_pc
+ 2, 2);
196 start_pc
+= 2 + adjust
;
197 w
= read_memory_unsigned_integer (start_pc
, 2);
204 /* Skip past a move to FP, either word or long sized */
205 w
= read_memory_unsigned_integer (start_pc
, 2);
208 w
= read_memory_unsigned_integer (start_pc
+ 2, 2);
214 start_pc
+= 2 + adjust
;
215 w
= read_memory_unsigned_integer (start_pc
, 2);
218 /* Check for loading either a word constant into r5;
219 long versions are handled by the SUBL_SP below. */
223 w
= read_memory_unsigned_integer (start_pc
, 2);
226 /* Now check for subtracting r5 from sp, word sized only. */
229 start_pc
+= 2 + adjust
;
230 w
= read_memory_unsigned_integer (start_pc
, 2);
233 /* Check for subs #2 and subs #4. */
234 while (IS_SUB2_SP (w
) || IS_SUB4_SP (w
))
236 start_pc
+= 2 + adjust
;
237 w
= read_memory_unsigned_integer (start_pc
, 2);
240 /* Check for a 32bit subtract. */
242 start_pc
+= 6 + adjust
;
244 /* Check for spilling an argument register to the stack frame.
245 This could also be an initializing store from non-prologue code,
246 but I don't think there's any harm in skipping that. */
249 int spill_size
= h8300_is_argument_spill (start_pc
);
252 start_pc
+= spill_size
;
259 gdb_print_insn_h8300 (bfd_vma memaddr
, disassemble_info
* info
)
262 return print_insn_h8300s (memaddr
, info
);
264 return print_insn_h8300h (memaddr
, info
);
266 return print_insn_h8300 (memaddr
, info
);
269 /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
270 is not the address of a valid instruction, the address of the next
271 instruction beyond ADDR otherwise. *PWORD1 receives the first word
272 of the instruction. */
275 h8300_next_prologue_insn (CORE_ADDR addr
,
277 unsigned short* pword1
)
282 read_memory (addr
, buf
, 2);
283 *pword1
= extract_signed_integer (buf
, 2);
290 /* Examine the prologue of a function. `ip' points to the first instruction.
291 `limit' is the limit of the prologue (e.g. the addr of the first
292 linenumber, or perhaps the program counter if we're stepping through).
293 `frame_sp' is the stack pointer value in use in this frame.
294 `fsr' is a pointer to a frame_saved_regs structure into which we put
295 info about the registers saved by this frame.
296 `fi' is a struct frame_info pointer; we fill in various fields in it
297 to reflect the offsets of the arg pointer and the locals pointer. */
299 /* Any function with a frame looks like this
305 SAVED FP <-FP POINTS HERE
307 LOCALS1 <-SP POINTS HERE
311 h8300_examine_prologue (register CORE_ADDR ip
, register CORE_ADDR limit
,
312 CORE_ADDR after_prolog_fp
, CORE_ADDR
*fsr
,
313 struct frame_info
*fi
)
315 register CORE_ADDR next_ip
;
318 unsigned short insn_word
;
319 /* Number of things pushed onto stack, starts at 2/4, 'cause the
320 PC is already there */
321 unsigned int reg_save_depth
= BINWORD
;
323 unsigned int auto_depth
= 0; /* Number of bytes of autos */
325 char in_frame
[11]; /* One for each reg */
329 memset (in_frame
, 1, 11);
330 for (r
= 0; r
< 8; r
++)
334 if (after_prolog_fp
== 0)
336 after_prolog_fp
= read_register (E_SP_REGNUM
);
339 /* If the PC isn't valid, quit now. */
340 if (ip
== 0 || ip
& (h8300hmode
? ~0xffffff : ~0xffff))
343 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
345 if (insn_word
== 0x0100)
347 insn_word
= read_memory_unsigned_integer (ip
+ 2, 2);
351 /* Skip over any fp push instructions */
352 fsr
[E_FP_REGNUM
] = after_prolog_fp
;
353 while (next_ip
&& IS_PUSH_FP (insn_word
))
355 ip
= next_ip
+ adjust
;
357 in_frame
[insn_word
& 0x7] = reg_save_depth
;
358 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
359 reg_save_depth
+= 2 + adjust
;
362 /* Is this a move into the fp */
363 if (next_ip
&& IS_MOV_SP_FP (insn_word
))
366 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
370 /* Skip over any stack adjustment, happens either with a number of
371 sub#2,sp or a mov #x,r5 sub r5,sp */
373 if (next_ip
&& (IS_SUB2_SP (insn_word
) || IS_SUB4_SP (insn_word
)))
375 while (next_ip
&& (IS_SUB2_SP (insn_word
) || IS_SUB4_SP (insn_word
)))
377 auto_depth
+= IS_SUB2_SP (insn_word
) ? 2 : 4;
379 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
384 if (next_ip
&& IS_MOVK_R5 (insn_word
))
387 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
388 auto_depth
+= insn_word
;
390 next_ip
= h8300_next_prologue_insn (next_ip
, limit
, &insn_word
);
391 auto_depth
+= insn_word
;
393 if (next_ip
&& IS_SUBL_SP (insn_word
))
396 auto_depth
+= read_memory_unsigned_integer (ip
, 4);
399 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
403 /* Now examine the push insns to determine where everything lives
411 if (insn_word
== 0x0100)
414 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
418 if (IS_PUSH (insn_word
))
420 auto_depth
+= 2 + adjust
;
421 fsr
[insn_word
& 0x7] = after_prolog_fp
- auto_depth
;
423 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
427 /* Now check for push multiple insns. */
428 if (insn_word
== 0x0110 || insn_word
== 0x0120 || insn_word
== 0x0130)
430 int count
= ((insn_word
>> 4) & 0xf) + 1;
434 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
435 start
= insn_word
& 0x7;
437 for (i
= start
; i
< start
+ count
; i
++)
440 fsr
[i
] = after_prolog_fp
- auto_depth
;
446 /* The args are always reffed based from the stack pointer */
447 get_frame_extra_info (fi
)->args_pointer
= after_prolog_fp
;
448 /* Locals are always reffed based from the fp */
449 get_frame_extra_info (fi
)->locals_pointer
= after_prolog_fp
;
450 /* The PC is at a known place */
451 get_frame_extra_info (fi
)->from_pc
=
452 read_memory_unsigned_integer (after_prolog_fp
+ BINWORD
, BINWORD
);
454 /* Rememeber any others too */
455 in_frame
[E_PC_REGNUM
] = 0;
458 /* We keep the old FP in the SP spot */
459 fsr
[E_SP_REGNUM
] = read_memory_unsigned_integer (fsr
[E_FP_REGNUM
],
462 fsr
[E_SP_REGNUM
] = after_prolog_fp
+ auto_depth
;
468 h8300_frame_init_saved_regs (struct frame_info
*fi
)
470 CORE_ADDR func_addr
, func_end
;
472 if (!get_frame_saved_regs (fi
))
474 frame_saved_regs_zalloc (fi
);
476 /* Find the beginning of this function, so we can analyze its
478 if (find_pc_partial_function (get_frame_pc (fi
), NULL
,
479 &func_addr
, &func_end
))
481 struct symtab_and_line sal
= find_pc_line (func_addr
, 0);
482 CORE_ADDR limit
= (sal
.end
&& sal
.end
< get_frame_pc (fi
))
483 ? sal
.end
: get_frame_pc (fi
);
484 /* This will fill in fields in fi. */
485 h8300_examine_prologue (func_addr
, limit
, get_frame_base (fi
),
486 get_frame_saved_regs (fi
), fi
);
488 /* Else we're out of luck (can't debug completely stripped code).
493 /* Given a GDB frame, determine the address of the calling function's
494 frame. This will be used to create a new GDB frame struct, and
495 then DEPRECATED_INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC
496 will be called for the new frame.
498 For us, the frame address is its stack pointer value, so we look up
499 the function prologue to determine the caller's sp value, and
503 h8300_frame_chain (struct frame_info
*thisframe
)
505 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (thisframe
),
506 get_frame_base (thisframe
),
507 get_frame_base (thisframe
)))
508 { /* initialize the from_pc now */
509 get_frame_extra_info (thisframe
)->from_pc
=
510 deprecated_read_register_dummy (get_frame_pc (thisframe
),
511 get_frame_base (thisframe
),
513 return get_frame_base (thisframe
);
515 return get_frame_saved_regs (thisframe
)[E_SP_REGNUM
];
518 /* Return the saved PC from this frame.
520 If the frame has a memory copy of SRP_REGNUM, use that. If not,
521 just use the register SRP_REGNUM itself. */
524 h8300_frame_saved_pc (struct frame_info
*frame
)
526 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame
),
527 get_frame_base (frame
),
528 get_frame_base (frame
)))
529 return deprecated_read_register_dummy (get_frame_pc (frame
),
530 get_frame_base (frame
),
533 return get_frame_extra_info (frame
)->from_pc
;
537 h8300_init_extra_frame_info (int fromleaf
, struct frame_info
*fi
)
539 if (!get_frame_extra_info (fi
))
541 frame_extra_info_zalloc (fi
, sizeof (struct frame_extra_info
));
542 get_frame_extra_info (fi
)->from_pc
= 0;
543 get_frame_extra_info (fi
)->args_pointer
= 0; /* Unknown */
544 get_frame_extra_info (fi
)->locals_pointer
= 0; /* Unknown */
546 if (!get_frame_pc (fi
))
548 if (get_next_frame (fi
))
549 deprecated_update_frame_pc_hack (fi
, h8300_frame_saved_pc (get_next_frame (fi
)));
551 h8300_frame_init_saved_regs (fi
);
556 h8300_frame_locals_address (struct frame_info
*fi
)
558 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
), get_frame_base (fi
),
559 get_frame_base (fi
)))
560 return (CORE_ADDR
) 0; /* Not sure what else to do... */
561 return get_frame_extra_info (fi
)->locals_pointer
;
564 /* Return the address of the argument block for the frame
565 described by FI. Returns 0 if the address is unknown. */
568 h8300_frame_args_address (struct frame_info
*fi
)
570 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi
), get_frame_base (fi
),
571 get_frame_base (fi
)))
572 return (CORE_ADDR
) 0; /* Not sure what else to do... */
573 return get_frame_extra_info (fi
)->args_pointer
;
576 /* Round N up or down to the nearest multiple of UNIT.
577 Evaluate N only once, UNIT several times.
578 UNIT must be a power of two. */
579 #define round_up(n, unit) (((n) + (unit) - 1) & -(unit))
580 #define round_down(n, unit) ((n) & -(unit))
582 /* Function: push_arguments
583 Setup the function arguments for calling a function in the inferior.
584 In this discussion, a `word' is 16 bits on the H8/300s, and 32 bits
587 There are actually two ABI's here: -mquickcall (the default) and
588 -mno-quickcall. With -mno-quickcall, all arguments are passed on
589 the stack after the return address, word-aligned. With
590 -mquickcall, GCC tries to use r0 -- r2 to pass registers. Since
591 GCC doesn't indicate in the object file which ABI was used to
592 compile it, GDB only supports the default --- -mquickcall.
594 Here are the rules for -mquickcall, in detail:
596 Each argument, whether scalar or aggregate, is padded to occupy a
597 whole number of words. Arguments smaller than a word are padded at
598 the most significant end; those larger than a word are padded at
599 the least significant end.
601 The initial arguments are passed in r0 -- r2. Earlier arguments go in
602 lower-numbered registers. Multi-word arguments are passed in
603 consecutive registers, with the most significant end in the
604 lower-numbered register.
606 If an argument doesn't fit entirely in the remaining registers, it
607 is passed entirely on the stack. Stack arguments begin just after
608 the return address. Once an argument has overflowed onto the stack
609 this way, all subsequent arguments are passed on the stack.
611 The above rule has odd consequences. For example, on the h8/300s,
612 if a function takes two longs and an int as arguments:
613 - the first long will be passed in r0/r1,
614 - the second long will be passed entirely on the stack, since it
616 - and the int will be passed on the stack, even though it could fit
619 A weird exception: if an argument is larger than a word, but not a
620 whole number of words in length (before padding), it is passed on
621 the stack following the rules for stack arguments above, even if
622 there are sufficient registers available to hold it. Stranger
623 still, the argument registers are still `used up' --- even though
624 there's nothing in them.
626 So, for example, on the h8/300s, if a function expects a three-byte
627 structure and an int, the structure will go on the stack, and the
628 int will go in r2, not r0.
630 If the function returns an aggregate type (struct, union, or class)
631 by value, the caller must allocate space to hold the return value,
632 and pass the callee a pointer to this space as an invisible first
635 For varargs functions, the last fixed argument and all the variable
636 arguments are always passed on the stack. This means that calls to
637 varargs functions don't work properly unless there is a prototype
640 Basically, this ABI is not good, for the following reasons:
641 - You can't call vararg functions properly unless a prototype is in scope.
642 - Structure passing is inconsistent, to no purpose I can see.
643 - It often wastes argument registers, of which there are only three
647 h8300_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
648 int struct_return
, CORE_ADDR struct_addr
)
650 int stack_align
, stack_alloc
, stack_offset
;
651 int wordsize
= BINWORD
;
655 /* First, make sure the stack is properly aligned. */
656 sp
= round_down (sp
, wordsize
);
658 /* Now make sure there's space on the stack for the arguments. We
659 may over-allocate a little here, but that won't hurt anything. */
661 for (argument
= 0; argument
< nargs
; argument
++)
662 stack_alloc
+= round_up (TYPE_LENGTH (VALUE_TYPE (args
[argument
])),
666 /* Now load as many arguments as possible into registers, and push
667 the rest onto the stack. */
671 /* If we're returning a structure by value, then we must pass a
672 pointer to the buffer for the return value as an invisible first
675 write_register (reg
++, struct_addr
);
677 for (argument
= 0; argument
< nargs
; argument
++)
679 struct type
*type
= VALUE_TYPE (args
[argument
]);
680 int len
= TYPE_LENGTH (type
);
681 char *contents
= (char *) VALUE_CONTENTS (args
[argument
]);
683 /* Pad the argument appropriately. */
684 int padded_len
= round_up (len
, wordsize
);
685 char *padded
= alloca (padded_len
);
687 memset (padded
, 0, padded_len
);
688 memcpy (len
< wordsize
? padded
+ padded_len
- len
: padded
,
691 /* Could the argument fit in the remaining registers? */
692 if (padded_len
<= (E_ARGLAST_REGNUM
- reg
+ 1) * wordsize
)
694 /* Are we going to pass it on the stack anyway, for no good
696 if (len
> wordsize
&& len
% wordsize
)
698 /* I feel so unclean. */
699 write_memory (sp
+ stack_offset
, padded
, padded_len
);
700 stack_offset
+= padded_len
;
702 /* That's right --- even though we passed the argument
703 on the stack, we consume the registers anyway! Love
705 reg
+= padded_len
/ wordsize
;
709 /* Heavens to Betsy --- it's really going in registers!
710 It would be nice if we could use write_register_bytes
711 here, but on the h8/300s, there are gaps between
712 the registers in the register file. */
715 for (offset
= 0; offset
< padded_len
; offset
+= wordsize
)
717 ULONGEST word
= extract_unsigned_integer (padded
+ offset
,
719 write_register (reg
++, word
);
725 /* It doesn't fit in registers! Onto the stack it goes. */
726 write_memory (sp
+ stack_offset
, padded
, padded_len
);
727 stack_offset
+= padded_len
;
729 /* Once one argument has spilled onto the stack, all
730 subsequent arguments go on the stack. */
731 reg
= E_ARGLAST_REGNUM
+ 1;
738 /* Function: push_return_address
739 Setup the return address for a dummy frame, as called by
740 call_function_by_hand. Only necessary when you are using an
741 empty CALL_DUMMY, ie. the target will not actually be executing
742 a JSR/BSR instruction. */
745 h8300_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
747 unsigned char buf
[4];
748 int wordsize
= BINWORD
;
751 store_unsigned_integer (buf
, wordsize
, CALL_DUMMY_ADDRESS ());
752 write_memory (sp
, buf
, wordsize
);
756 /* Function: h8300_pop_frame
757 Restore the machine to the state it had before the current frame
758 was created. Usually used either by the "RETURN" command, or by
759 call_function_by_hand after the dummy_frame is finished. */
762 h8300_pop_frame (void)
765 struct frame_info
*frame
= get_current_frame ();
767 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame
),
768 get_frame_base (frame
),
769 get_frame_base (frame
)))
771 generic_pop_dummy_frame ();
775 for (regno
= 0; regno
< 8; regno
++)
777 /* Don't forget E_SP_REGNUM is a frame_saved_regs struct is the
778 actual value we want, not the address of the value we want. */
779 if (get_frame_saved_regs (frame
)[regno
] && regno
!= E_SP_REGNUM
)
780 write_register (regno
,
782 (get_frame_saved_regs (frame
)[regno
], BINWORD
));
783 else if (get_frame_saved_regs (frame
)[regno
] && regno
== E_SP_REGNUM
)
784 write_register (regno
, get_frame_base (frame
) + 2 * BINWORD
);
787 /* Don't forget to update the PC too! */
788 write_register (E_PC_REGNUM
, get_frame_extra_info (frame
)->from_pc
);
790 flush_cached_frames ();
793 /* Function: extract_return_value
794 Figure out where in REGBUF the called function has left its return value.
795 Copy that into VALBUF. Be sure to account for CPU type. */
798 h8300_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
800 int wordsize
= BINWORD
;
801 int len
= TYPE_LENGTH (type
);
806 case 2: /* (short), (int) */
807 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (0) + (wordsize
- len
), len
);
809 case 4: /* (long), (float) */
812 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (0), 4);
816 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (0), 2);
817 memcpy (valbuf
+ 2, regbuf
+ REGISTER_BYTE (1), 2);
820 case 8: /* (double) (doesn't seem to happen, which is good,
821 because this almost certainly isn't right.
822 FIXME: it will happen for h8sx... */
823 error ("I don't know how a double is returned.");
828 /* Function: store_return_value
829 Place the appropriate value in the appropriate registers.
830 Primarily used by the RETURN command. */
833 h8300_store_return_value (struct type
*type
, char *valbuf
)
836 int wordsize
= BINWORD
;
837 int len
= TYPE_LENGTH (type
);
842 case 2: /* short, int */
843 regval
= extract_unsigned_integer (valbuf
, len
);
844 write_register (0, regval
);
846 case 4: /* long, float */
847 regval
= extract_unsigned_integer (valbuf
, len
);
850 write_register (0, regval
);
854 write_register (0, regval
>> 16);
855 write_register (1, regval
& 0xffff);
858 case 8: /* presumeably double, but doesn't seem to happen */
859 error ("I don't know how to return a double.");
864 static struct cmd_list_element
*setmachinelist
;
867 h8300_register_name (int regno
)
869 /* The register names change depending on which h8300 processor
871 static char *register_names
[] = {
872 "r0", "r1", "r2", "r3", "r4", "r5", "r6",
873 "sp", "ccr","pc","cycles", "tick", "inst", ""
876 || regno
>= (sizeof (register_names
) / sizeof (*register_names
)))
877 internal_error (__FILE__
, __LINE__
,
878 "h8300_register_name: illegal register number %d", regno
);
880 return register_names
[regno
];
884 h8300s_register_name (int regno
)
886 static char *register_names
[] = {
887 "er0", "er1", "er2", "er3", "er4", "er5", "er6",
888 "sp", "ccr", "pc", "cycles", "exr", "tick", "inst"
891 || regno
>= (sizeof (register_names
) / sizeof (*register_names
)))
892 internal_error (__FILE__
, __LINE__
,
893 "h8300s_register_name: illegal register number %d", regno
);
895 return register_names
[regno
];
899 h8300sx_register_name (int regno
)
901 static char *register_names
[] = {
902 "er0", "er1", "er2", "er3", "er4", "er5", "er6",
903 "sp", "ccr", "pc", "cycles", "exr", "tick", "inst",
904 "mach", "macl", "sbr", "vbr"
907 || regno
>= (sizeof (register_names
) / sizeof (*register_names
)))
908 internal_error (__FILE__
, __LINE__
,
909 "h8300sx_register_name: illegal register number %d", regno
);
911 return register_names
[regno
];
915 h8300_print_register (struct gdbarch
*gdbarch
, struct ui_file
*file
,
916 struct frame_info
*frame
, int regno
)
919 const char *name
= gdbarch_register_name (gdbarch
, regno
);
924 frame_read_signed_register (frame
, regno
, &rval
);
926 fprintf_filtered (file
, "%-14s ", name
);
927 if (regno
== E_CCR_REGNUM
|| (regno
== E_EXR_REGNUM
&& h8300smode
))
929 fprintf_filtered (file
, "0x%02x ", (unsigned char)rval
);
930 print_longest (file
, 'u', 1, rval
);
934 fprintf_filtered (file
, "0x%s ", phex ((ULONGEST
)rval
, BINWORD
));
935 print_longest (file
, 'd', 1, rval
);
937 if (regno
== E_CCR_REGNUM
)
941 unsigned char l
= rval
& 0xff;
942 fprintf_filtered (file
, "\t");
943 fprintf_filtered (file
, "I-%d ", (l
& 0x80) != 0);
944 fprintf_filtered (file
, "UI-%d ", (l
& 0x40) != 0);
945 fprintf_filtered (file
, "H-%d ", (l
& 0x20) != 0);
946 fprintf_filtered (file
, "U-%d ", (l
& 0x10) != 0);
951 fprintf_filtered (file
, "N-%d ", N
);
952 fprintf_filtered (file
, "Z-%d ", Z
);
953 fprintf_filtered (file
, "V-%d ", V
);
954 fprintf_filtered (file
, "C-%d ", C
);
956 fprintf_filtered (file
, "u> ");
958 fprintf_filtered (file
, "u<= ");
960 fprintf_filtered (file
, "u>= ");
962 fprintf_filtered (file
, "u< ");
964 fprintf_filtered (file
, "!= ");
966 fprintf_filtered (file
, "== ");
968 fprintf_filtered (file
, ">= ");
970 fprintf_filtered (file
, "< ");
971 if ((Z
| (N
^ V
)) == 0)
972 fprintf_filtered (file
, "> ");
973 if ((Z
| (N
^ V
)) == 1)
974 fprintf_filtered (file
, "<= ");
976 else if (regno
== E_EXR_REGNUM
&& h8300smode
)
979 unsigned char l
= rval
& 0xff;
980 fprintf_filtered (file
, "\t");
981 fprintf_filtered (file
, "T-%d - - - ", (l
& 0x80) != 0);
982 fprintf_filtered (file
, "I2-%d ", (l
& 4) != 0);
983 fprintf_filtered (file
, "I1-%d ", (l
& 2) != 0);
984 fprintf_filtered (file
, "I0-%d", (l
& 1) != 0);
986 fprintf_filtered (file
, "\n");
990 h8300_print_registers_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
991 struct frame_info
*frame
, int regno
, int cpregs
)
994 for (regno
= 0; regno
< NUM_REGS
; ++regno
)
995 h8300_print_register (gdbarch
, file
, frame
, regno
);
997 h8300_print_register (gdbarch
, file
, frame
, regno
);
1001 h8300_saved_pc_after_call (struct frame_info
*ignore
)
1003 return read_memory_unsigned_integer (read_register (E_SP_REGNUM
), BINWORD
);
1007 h8300_register_byte (int regno
)
1009 if (regno
< 0 || regno
>= NUM_REGS
)
1010 internal_error (__FILE__
, __LINE__
,
1011 "h8300_register_byte: illegal register number %d", regno
);
1013 return regno
* h8300_reg_size
;
1017 h8300h_register_byte (int regno
)
1019 if (regno
< 0 || regno
>= NUM_REGS
)
1020 internal_error (__FILE__
, __LINE__
,
1021 "h8300_register_byte: illegal register number %d", regno
);
1023 return regno
* h8300h_reg_size
;
1026 static struct type
*
1027 h8300_register_virtual_type (int regno
)
1029 if (regno
< 0 || regno
>= NUM_REGS
)
1030 internal_error (__FILE__
, __LINE__
,
1031 "h8300_register_virtual_type: illegal register number %d",
1038 return builtin_type_void_func_ptr
;
1041 return builtin_type_void_data_ptr
;
1043 return builtin_type_uint8
;
1046 return builtin_type_uint8
;
1049 return h8300hmode
? builtin_type_int32
1050 : builtin_type_int16
;
1056 h8300_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
1058 write_register (0, addr
);
1062 h8300_extract_struct_value_address (char *regbuf
)
1065 extract_unsigned_integer (regbuf
+ h8300_register_byte (E_ARG0_REGNUM
),
1070 h8300h_extract_struct_value_address (char *regbuf
)
1073 extract_unsigned_integer (regbuf
+ h8300_register_byte (E_ARG0_REGNUM
),
1077 const static unsigned char *
1078 h8300_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
1080 /*static unsigned char breakpoint[] = { 0x7A, 0xFF };*/ /* ??? */
1081 static unsigned char breakpoint
[] = { 0x01, 0x80 }; /* Sleep */
1083 *lenptr
= sizeof (breakpoint
);
1088 h8300_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1089 struct frame_info
*frame
, const char *args
)
1091 fprintf_filtered (file
, "\
1092 No floating-point info available for this processor.\n");
1095 static struct gdbarch
*
1096 h8300_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1098 static LONGEST call_dummy_words
[1] = { 0 };
1099 struct gdbarch_tdep
*tdep
= NULL
;
1100 struct gdbarch
*gdbarch
;
1102 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1104 return arches
->gdbarch
;
1107 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
1110 if (info
.bfd_arch_info
->arch
!= bfd_arch_h8300
)
1113 gdbarch
= gdbarch_alloc (&info
, 0);
1115 switch (info
.bfd_arch_info
->mach
)
1117 case bfd_mach_h8300
:
1121 set_gdbarch_num_regs (gdbarch
, 13);
1122 set_gdbarch_register_name (gdbarch
, h8300_register_name
);
1123 set_gdbarch_register_byte (gdbarch
, h8300_register_byte
);
1124 set_gdbarch_ptr_bit (gdbarch
, 2 * TARGET_CHAR_BIT
);
1125 set_gdbarch_addr_bit (gdbarch
, 2 * TARGET_CHAR_BIT
);
1127 case bfd_mach_h8300h
:
1128 case bfd_mach_h8300hn
:
1132 set_gdbarch_num_regs (gdbarch
, 13);
1133 set_gdbarch_register_name (gdbarch
, h8300_register_name
);
1134 set_gdbarch_register_byte (gdbarch
, h8300h_register_byte
);
1135 set_gdbarch_ptr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1136 set_gdbarch_addr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1138 case bfd_mach_h8300s
:
1139 case bfd_mach_h8300sn
:
1143 set_gdbarch_num_regs (gdbarch
, 14);
1144 set_gdbarch_register_name (gdbarch
, h8300s_register_name
);
1145 set_gdbarch_register_byte (gdbarch
, h8300h_register_byte
);
1146 set_gdbarch_ptr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1147 set_gdbarch_addr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1149 case bfd_mach_h8300sx
:
1150 case bfd_mach_h8300sxn
:
1154 set_gdbarch_num_regs (gdbarch
, 18);
1155 set_gdbarch_register_name (gdbarch
, h8300sx_register_name
);
1156 set_gdbarch_register_byte (gdbarch
, h8300h_register_byte
);
1157 set_gdbarch_ptr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1158 set_gdbarch_addr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1162 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
1163 ready to unwind the PC first (see frame.c:get_prev_frame()). */
1164 set_gdbarch_deprecated_init_frame_pc (gdbarch
, init_frame_pc_default
);
1167 * Basic register fields and methods.
1170 set_gdbarch_num_pseudo_regs (gdbarch
, 0);
1171 set_gdbarch_sp_regnum (gdbarch
, E_SP_REGNUM
);
1172 set_gdbarch_deprecated_fp_regnum (gdbarch
, E_FP_REGNUM
);
1173 set_gdbarch_pc_regnum (gdbarch
, E_PC_REGNUM
);
1174 set_gdbarch_register_virtual_type (gdbarch
, h8300_register_virtual_type
);
1175 set_gdbarch_print_registers_info (gdbarch
, h8300_print_registers_info
);
1176 set_gdbarch_print_float_info (gdbarch
, h8300_print_float_info
);
1181 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
,
1182 h8300_frame_init_saved_regs
);
1183 set_gdbarch_deprecated_init_extra_frame_info (gdbarch
,
1184 h8300_init_extra_frame_info
);
1185 set_gdbarch_deprecated_frame_chain (gdbarch
, h8300_frame_chain
);
1186 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
,
1187 h8300_saved_pc_after_call
);
1188 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, h8300_frame_saved_pc
);
1189 set_gdbarch_skip_prologue (gdbarch
, h8300_skip_prologue
);
1190 set_gdbarch_frame_args_address (gdbarch
, h8300_frame_args_address
);
1191 set_gdbarch_frame_locals_address (gdbarch
, h8300_frame_locals_address
);
1196 /* Stack grows up. */
1197 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1198 /* PC stops zero byte after a trap instruction
1199 (which means: exactly on trap instruction). */
1200 set_gdbarch_decr_pc_after_break (gdbarch
, 0);
1201 /* This value is almost never non-zero... */
1202 set_gdbarch_function_start_offset (gdbarch
, 0);
1203 /* This value is almost never non-zero... */
1204 set_gdbarch_frame_args_skip (gdbarch
, 0);
1205 set_gdbarch_frameless_function_invocation (gdbarch
,
1206 frameless_look_for_prologue
);
1211 * These values and methods are used when gdb calls a target function. */
1212 set_gdbarch_deprecated_push_return_address (gdbarch
,
1213 h8300_push_return_address
);
1214 set_gdbarch_deprecated_extract_return_value (gdbarch
,
1215 h8300_extract_return_value
);
1216 set_gdbarch_deprecated_push_arguments (gdbarch
, h8300_push_arguments
);
1217 set_gdbarch_deprecated_pop_frame (gdbarch
, h8300_pop_frame
);
1218 set_gdbarch_deprecated_store_struct_return (gdbarch
,
1219 h8300_store_struct_return
);
1220 set_gdbarch_deprecated_store_return_value (gdbarch
,
1221 h8300_store_return_value
);
1222 set_gdbarch_deprecated_extract_struct_value_address
1223 (gdbarch
, h8300_extract_struct_value_address
);
1224 set_gdbarch_use_struct_convention (gdbarch
, always_use_struct_convention
);
1225 set_gdbarch_deprecated_call_dummy_words (gdbarch
, call_dummy_words
);
1226 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch
, 0);
1227 set_gdbarch_breakpoint_from_pc (gdbarch
, h8300_breakpoint_from_pc
);
1229 set_gdbarch_int_bit (gdbarch
, 2 * TARGET_CHAR_BIT
);
1230 set_gdbarch_long_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1231 set_gdbarch_long_long_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1232 set_gdbarch_double_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1233 set_gdbarch_long_double_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1235 /* set_gdbarch_stack_align (gdbarch, SOME_stack_align); */
1236 set_gdbarch_believe_pcc_promotion (gdbarch
, 1);
1238 /* Should be using push_dummy_call. */
1239 set_gdbarch_deprecated_dummy_write_sp (gdbarch
, deprecated_write_sp
);
1244 extern initialize_file_ftype _initialize_h8300_tdep
; /* -Wmissing-prototypes */
1247 _initialize_h8300_tdep (void)
1249 deprecated_tm_print_insn
= gdb_print_insn_h8300
;
1250 register_gdbarch_init (bfd_arch_h8300
, h8300_gdbarch_init
);