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
49 h8300_max_reg_size
= 4,
51 #define BINWORD (h8300hmode ? h8300h_reg_size : h8300_reg_size)
55 E_R0_REGNUM
, E_ER0_REGNUM
= E_R0_REGNUM
, E_ARG0_REGNUM
= E_R0_REGNUM
,
56 E_RET0_REGNUM
= E_R0_REGNUM
,
57 E_R1_REGNUM
, E_ER1_REGNUM
= E_R1_REGNUM
, E_RET1_REGNUM
= E_R1_REGNUM
,
58 E_R2_REGNUM
, E_ER2_REGNUM
= E_R2_REGNUM
, E_ARGLAST_REGNUM
= E_R2_REGNUM
,
59 E_R3_REGNUM
, E_ER3_REGNUM
= E_R3_REGNUM
,
60 E_R4_REGNUM
, E_ER4_REGNUM
= E_R4_REGNUM
,
61 E_R5_REGNUM
, E_ER5_REGNUM
= E_R5_REGNUM
,
62 E_R6_REGNUM
, E_ER6_REGNUM
= E_R6_REGNUM
, E_FP_REGNUM
= E_R6_REGNUM
,
67 E_TICK_REGNUM
, E_EXR_REGNUM
= E_TICK_REGNUM
,
68 E_INST_REGNUM
, E_TICKS_REGNUM
= E_INST_REGNUM
,
76 #define E_PSEUDO_CCR_REGNUM (NUM_REGS)
77 #define E_PSEUDO_EXR_REGNUM (NUM_REGS+1)
79 #define UNSIGNED_SHORT(X) ((X) & 0xffff)
81 #define IS_PUSH(x) ((x & 0xfff0)==0x6df0)
82 #define IS_PUSH_FP(x) (x == 0x6df6)
83 #define IS_MOVE_FP(x) (x == 0x0d76 || x == 0x0ff6)
84 #define IS_MOV_SP_FP(x) (x == 0x0d76 || x == 0x0ff6)
85 #define IS_SUB2_SP(x) (x==0x1b87)
86 #define IS_SUB4_SP(x) (x==0x1b97)
87 #define IS_SUBL_SP(x) (x==0x7a37)
88 #define IS_MOVK_R5(x) (x==0x7905)
89 #define IS_SUB_R5SP(x) (x==0x1957)
91 /* If the instruction at PC is an argument register spill, return its
92 length. Otherwise, return zero.
94 An argument register spill is an instruction that moves an argument
95 from the register in which it was passed to the stack slot in which
96 it really lives. It is a byte, word, or longword move from an
97 argument register to a negative offset from the frame pointer.
99 CV, 2003-06-16: Or, in optimized code or when the `register' qualifier
100 is used, it could be a byte, word or long move to registers r3-r5. */
103 h8300_is_argument_spill (CORE_ADDR pc
)
105 int w
= read_memory_unsigned_integer (pc
, 2);
107 if (((w
& 0xff88) == 0x0c88 /* mov.b Rsl, Rdl */
108 || (w
& 0xff88) == 0x0d00 /* mov.w Rs, Rd */
109 || (w
& 0xff88) == 0x0f80) /* mov.l Rs, Rd */
110 && (w
& 0x70) <= 0x20 /* Rs is R0, R1 or R2 */
111 && (w
& 0x7) >= 0x3 && (w
& 0x7) <= 0x5)/* Rd is R3, R4 or R5 */
114 if ((w
& 0xfff0) == 0x6ee0 /* mov.b Rs,@(d:16,er6) */
115 && 8 <= (w
& 0xf) && (w
& 0xf) <= 10) /* Rs is R0L, R1L, or R2L */
117 int w2
= read_memory_integer (pc
+ 2, 2);
119 /* ... and d:16 is negative. */
123 else if (w
== 0x7860)
125 int w2
= read_memory_integer (pc
+ 2, 2);
127 if ((w2
& 0xfff0) == 0x6aa0) /* mov.b Rs, @(d:24,er6) */
129 LONGEST disp
= read_memory_integer (pc
+ 4, 4);
131 /* ... and d:24 is negative. */
132 if (disp
< 0 && disp
> 0xffffff)
136 else if ((w
& 0xfff0) == 0x6fe0 /* mov.w Rs,@(d:16,er6) */
137 && (w
& 0xf) <= 2) /* Rs is R0, R1, or R2 */
139 int w2
= read_memory_integer (pc
+ 2, 2);
141 /* ... and d:16 is negative. */
145 else if (w
== 0x78e0)
147 int w2
= read_memory_integer (pc
+ 2, 2);
149 if ((w2
& 0xfff0) == 0x6ba0) /* mov.b Rs, @(d:24,er6) */
151 LONGEST disp
= read_memory_integer (pc
+ 4, 4);
153 /* ... and d:24 is negative. */
154 if (disp
< 0 && disp
> 0xffffff)
158 else if (w
== 0x0100)
160 int w2
= read_memory_integer (pc
+ 2, 2);
162 if ((w2
& 0xfff0) == 0x6fe0 /* mov.l Rs,@(d:16,er6) */
163 && (w2
& 0xf) <= 2) /* Rs is ER0, ER1, or ER2 */
165 int w3
= read_memory_integer (pc
+ 4, 2);
167 /* ... and d:16 is negative. */
171 else if (w2
== 0x78e0)
173 int w3
= read_memory_integer (pc
+ 4, 2);
175 if ((w3
& 0xfff0) == 0x6ba0) /* mov.l Rs, @(d:24,er6) */
177 LONGEST disp
= read_memory_integer (pc
+ 6, 4);
179 /* ... and d:24 is negative. */
180 if (disp
< 0 && disp
> 0xffffff)
190 h8300_skip_prologue (CORE_ADDR start_pc
)
195 /* Skip past all push and stm insns. */
198 w
= read_memory_unsigned_integer (start_pc
, 2);
199 /* First look for push insns. */
200 if (w
== 0x0100 || w
== 0x0110 || w
== 0x0120 || w
== 0x0130)
202 w
= read_memory_unsigned_integer (start_pc
+ 2, 2);
208 start_pc
+= 2 + adjust
;
209 w
= read_memory_unsigned_integer (start_pc
, 2);
216 /* Skip past a move to FP, either word or long sized */
217 w
= read_memory_unsigned_integer (start_pc
, 2);
220 w
= read_memory_unsigned_integer (start_pc
+ 2, 2);
226 start_pc
+= 2 + adjust
;
227 w
= read_memory_unsigned_integer (start_pc
, 2);
230 /* Check for loading either a word constant into r5;
231 long versions are handled by the SUBL_SP below. */
235 w
= read_memory_unsigned_integer (start_pc
, 2);
238 /* Now check for subtracting r5 from sp, word sized only. */
241 start_pc
+= 2 + adjust
;
242 w
= read_memory_unsigned_integer (start_pc
, 2);
245 /* Check for subs #2 and subs #4. */
246 while (IS_SUB2_SP (w
) || IS_SUB4_SP (w
))
248 start_pc
+= 2 + adjust
;
249 w
= read_memory_unsigned_integer (start_pc
, 2);
252 /* Check for a 32bit subtract. */
254 start_pc
+= 6 + adjust
;
256 /* Skip past another possible stm insn for registers R3 to R5 (possibly used
257 for register qualified arguments. */
258 w
= read_memory_unsigned_integer (start_pc
, 2);
259 /* First look for push insns. */
260 if (w
== 0x0110 || w
== 0x0120 || w
== 0x0130)
262 w
= read_memory_unsigned_integer (start_pc
+ 2, 2);
263 if (IS_PUSH (w
) && (w
& 0xf) >= 0x3 && (w
& 0xf) <= 0x5)
267 /* Check for spilling an argument register to the stack frame.
268 This could also be an initializing store from non-prologue code,
269 but I don't think there's any harm in skipping that. */
272 int spill_size
= h8300_is_argument_spill (start_pc
);
275 start_pc
+= spill_size
;
281 /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
282 is not the address of a valid instruction, the address of the next
283 instruction beyond ADDR otherwise. *PWORD1 receives the first word
284 of the instruction. */
287 h8300_next_prologue_insn (CORE_ADDR addr
,
289 unsigned short* pword1
)
294 read_memory (addr
, buf
, 2);
295 *pword1
= extract_signed_integer (buf
, 2);
302 /* Examine the prologue of a function. `ip' points to the first instruction.
303 `limit' is the limit of the prologue (e.g. the addr of the first
304 linenumber, or perhaps the program counter if we're stepping through).
305 `frame_sp' is the stack pointer value in use in this frame.
306 `fsr' is a pointer to a frame_saved_regs structure into which we put
307 info about the registers saved by this frame.
308 `fi' is a struct frame_info pointer; we fill in various fields in it
309 to reflect the offsets of the arg pointer and the locals pointer. */
311 /* Any function with a frame looks like this
317 SAVED FP <-FP POINTS HERE
319 LOCALS1 <-SP POINTS HERE
323 h8300_examine_prologue (register CORE_ADDR ip
, register CORE_ADDR limit
,
324 CORE_ADDR after_prolog_fp
, CORE_ADDR
*fsr
,
325 struct frame_info
*fi
)
327 register CORE_ADDR next_ip
;
330 unsigned short insn_word
;
331 /* Number of things pushed onto stack, starts at 2/4, 'cause the
332 PC is already there */
333 unsigned int reg_save_depth
= BINWORD
;
335 unsigned int auto_depth
= 0; /* Number of bytes of autos */
337 char in_frame
[11]; /* One for each reg */
341 memset (in_frame
, 1, 11);
342 for (r
= 0; r
< 8; r
++)
346 if (after_prolog_fp
== 0)
348 after_prolog_fp
= read_register (E_SP_REGNUM
);
351 /* If the PC isn't valid, quit now. */
352 if (ip
== 0 || ip
& (h8300hmode
? ~0xffffff : ~0xffff))
355 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
357 if (insn_word
== 0x0100) /* mov.l */
359 insn_word
= read_memory_unsigned_integer (ip
+ 2, 2);
363 /* Skip over any fp push instructions */
364 fsr
[E_FP_REGNUM
] = after_prolog_fp
;
365 while (next_ip
&& IS_PUSH_FP (insn_word
))
367 ip
= next_ip
+ adjust
;
369 in_frame
[insn_word
& 0x7] = reg_save_depth
;
370 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
371 reg_save_depth
+= 2 + adjust
;
374 /* Is this a move into the fp */
375 if (next_ip
&& IS_MOV_SP_FP (insn_word
))
378 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
382 /* Skip over any stack adjustment, happens either with a number of
383 sub#2,sp or a mov #x,r5 sub r5,sp */
385 if (next_ip
&& (IS_SUB2_SP (insn_word
) || IS_SUB4_SP (insn_word
)))
387 while (next_ip
&& (IS_SUB2_SP (insn_word
) || IS_SUB4_SP (insn_word
)))
389 auto_depth
+= IS_SUB2_SP (insn_word
) ? 2 : 4;
391 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
396 if (next_ip
&& IS_MOVK_R5 (insn_word
))
399 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
400 auto_depth
+= insn_word
;
402 next_ip
= h8300_next_prologue_insn (next_ip
, limit
, &insn_word
);
403 auto_depth
+= insn_word
;
405 if (next_ip
&& IS_SUBL_SP (insn_word
))
408 auto_depth
+= read_memory_unsigned_integer (ip
, 4);
411 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
415 /* Now examine the push insns to determine where everything lives
423 if (insn_word
== 0x0100)
426 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
430 if (IS_PUSH (insn_word
))
432 auto_depth
+= 2 + adjust
;
433 fsr
[insn_word
& 0x7] = after_prolog_fp
- auto_depth
;
435 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
439 /* Now check for push multiple insns. */
440 if (insn_word
== 0x0110 || insn_word
== 0x0120 || insn_word
== 0x0130)
442 int count
= ((insn_word
>> 4) & 0xf) + 1;
446 next_ip
= h8300_next_prologue_insn (ip
, limit
, &insn_word
);
447 start
= insn_word
& 0x7;
449 for (i
= start
; i
< start
+ count
; i
++)
452 fsr
[i
] = after_prolog_fp
- auto_depth
;
458 /* The PC is at a known place */
459 get_frame_extra_info (fi
)->from_pc
=
460 read_memory_unsigned_integer (after_prolog_fp
+ BINWORD
, BINWORD
);
462 /* Rememeber any others too */
463 in_frame
[E_PC_REGNUM
] = 0;
466 /* We keep the old FP in the SP spot */
467 fsr
[E_SP_REGNUM
] = read_memory_unsigned_integer (fsr
[E_FP_REGNUM
],
470 fsr
[E_SP_REGNUM
] = after_prolog_fp
+ auto_depth
;
476 h8300_frame_init_saved_regs (struct frame_info
*fi
)
478 CORE_ADDR func_addr
, func_end
;
480 if (!get_frame_saved_regs (fi
))
482 frame_saved_regs_zalloc (fi
);
484 /* Find the beginning of this function, so we can analyze its
486 if (find_pc_partial_function (get_frame_pc (fi
), NULL
,
487 &func_addr
, &func_end
))
489 struct symtab_and_line sal
= find_pc_line (func_addr
, 0);
490 CORE_ADDR limit
= (sal
.end
&& sal
.end
< get_frame_pc (fi
))
491 ? sal
.end
: get_frame_pc (fi
);
492 /* This will fill in fields in fi. */
493 h8300_examine_prologue (func_addr
, limit
, get_frame_base (fi
),
494 get_frame_saved_regs (fi
), fi
);
496 /* Else we're out of luck (can't debug completely stripped code).
501 /* Given a GDB frame, determine the address of the calling function's
502 frame. This will be used to create a new GDB frame struct, and
503 then DEPRECATED_INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC
504 will be called for the new frame.
506 For us, the frame address is its stack pointer value, so we look up
507 the function prologue to determine the caller's sp value, and
511 h8300_frame_chain (struct frame_info
*thisframe
)
513 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (thisframe
),
514 get_frame_base (thisframe
),
515 get_frame_base (thisframe
)))
516 { /* initialize the from_pc now */
517 get_frame_extra_info (thisframe
)->from_pc
=
518 deprecated_read_register_dummy (get_frame_pc (thisframe
),
519 get_frame_base (thisframe
),
521 return get_frame_base (thisframe
);
523 return get_frame_saved_regs (thisframe
)[E_SP_REGNUM
];
526 /* Return the saved PC from this frame.
528 If the frame has a memory copy of SRP_REGNUM, use that. If not,
529 just use the register SRP_REGNUM itself. */
532 h8300_frame_saved_pc (struct frame_info
*frame
)
534 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame
),
535 get_frame_base (frame
),
536 get_frame_base (frame
)))
537 return deprecated_read_register_dummy (get_frame_pc (frame
),
538 get_frame_base (frame
),
541 return get_frame_extra_info (frame
)->from_pc
;
545 h8300_init_extra_frame_info (int fromleaf
, struct frame_info
*fi
)
547 if (!get_frame_extra_info (fi
))
549 frame_extra_info_zalloc (fi
, sizeof (struct frame_extra_info
));
550 get_frame_extra_info (fi
)->from_pc
= 0;
552 if (!get_frame_pc (fi
))
554 if (get_next_frame (fi
))
555 deprecated_update_frame_pc_hack (fi
, h8300_frame_saved_pc (get_next_frame (fi
)));
557 h8300_frame_init_saved_regs (fi
);
561 /* Round N up or down to the nearest multiple of UNIT.
562 Evaluate N only once, UNIT several times.
563 UNIT must be a power of two. */
564 #define round_up(n, unit) (((n) + (unit) - 1) & -(unit))
565 #define round_down(n, unit) ((n) & -(unit))
567 /* Function: push_dummy_call
568 Setup the function arguments for calling a function in the inferior.
569 In this discussion, a `word' is 16 bits on the H8/300s, and 32 bits
572 There are actually two ABI's here: -mquickcall (the default) and
573 -mno-quickcall. With -mno-quickcall, all arguments are passed on
574 the stack after the return address, word-aligned. With
575 -mquickcall, GCC tries to use r0 -- r2 to pass registers. Since
576 GCC doesn't indicate in the object file which ABI was used to
577 compile it, GDB only supports the default --- -mquickcall.
579 Here are the rules for -mquickcall, in detail:
581 Each argument, whether scalar or aggregate, is padded to occupy a
582 whole number of words. Arguments smaller than a word are padded at
583 the most significant end; those larger than a word are padded at
584 the least significant end.
586 The initial arguments are passed in r0 -- r2. Earlier arguments go in
587 lower-numbered registers. Multi-word arguments are passed in
588 consecutive registers, with the most significant end in the
589 lower-numbered register.
591 If an argument doesn't fit entirely in the remaining registers, it
592 is passed entirely on the stack. Stack arguments begin just after
593 the return address. Once an argument has overflowed onto the stack
594 this way, all subsequent arguments are passed on the stack.
596 The above rule has odd consequences. For example, on the h8/300s,
597 if a function takes two longs and an int as arguments:
598 - the first long will be passed in r0/r1,
599 - the second long will be passed entirely on the stack, since it
601 - and the int will be passed on the stack, even though it could fit
604 A weird exception: if an argument is larger than a word, but not a
605 whole number of words in length (before padding), it is passed on
606 the stack following the rules for stack arguments above, even if
607 there are sufficient registers available to hold it. Stranger
608 still, the argument registers are still `used up' --- even though
609 there's nothing in them.
611 So, for example, on the h8/300s, if a function expects a three-byte
612 structure and an int, the structure will go on the stack, and the
613 int will go in r2, not r0.
615 If the function returns an aggregate type (struct, union, or class)
616 by value, the caller must allocate space to hold the return value,
617 and pass the callee a pointer to this space as an invisible first
620 For varargs functions, the last fixed argument and all the variable
621 arguments are always passed on the stack. This means that calls to
622 varargs functions don't work properly unless there is a prototype
625 Basically, this ABI is not good, for the following reasons:
626 - You can't call vararg functions properly unless a prototype is in scope.
627 - Structure passing is inconsistent, to no purpose I can see.
628 - It often wastes argument registers, of which there are only three
632 h8300_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
633 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
634 struct value
**args
, CORE_ADDR sp
, int struct_return
,
635 CORE_ADDR struct_addr
)
637 int stack_alloc
= 0, stack_offset
= 0;
638 int wordsize
= BINWORD
;
639 int reg
= E_ARG0_REGNUM
;
642 /* First, make sure the stack is properly aligned. */
643 sp
= round_down (sp
, wordsize
);
645 /* Now make sure there's space on the stack for the arguments. We
646 may over-allocate a little here, but that won't hurt anything. */
647 for (argument
= 0; argument
< nargs
; argument
++)
648 stack_alloc
+= round_up (TYPE_LENGTH (VALUE_TYPE (args
[argument
])),
652 /* Now load as many arguments as possible into registers, and push
653 the rest onto the stack.
654 If we're returning a structure by value, then we must pass a
655 pointer to the buffer for the return value as an invisible first
658 regcache_cooked_write_unsigned (regcache
, reg
++, struct_addr
);
660 for (argument
= 0; argument
< nargs
; argument
++)
662 struct type
*type
= VALUE_TYPE (args
[argument
]);
663 int len
= TYPE_LENGTH (type
);
664 char *contents
= (char *) VALUE_CONTENTS (args
[argument
]);
666 /* Pad the argument appropriately. */
667 int padded_len
= round_up (len
, wordsize
);
668 char *padded
= alloca (padded_len
);
670 memset (padded
, 0, padded_len
);
671 memcpy (len
< wordsize
? padded
+ padded_len
- len
: padded
,
674 /* Could the argument fit in the remaining registers? */
675 if (padded_len
<= (E_ARGLAST_REGNUM
- reg
+ 1) * wordsize
)
677 /* Are we going to pass it on the stack anyway, for no good
679 if (len
> wordsize
&& len
% wordsize
)
681 /* I feel so unclean. */
682 write_memory (sp
+ stack_offset
, padded
, padded_len
);
683 stack_offset
+= padded_len
;
685 /* That's right --- even though we passed the argument
686 on the stack, we consume the registers anyway! Love
688 reg
+= padded_len
/ wordsize
;
692 /* Heavens to Betsy --- it's really going in registers!
693 It would be nice if we could use write_register_bytes
694 here, but on the h8/300s, there are gaps between
695 the registers in the register file. */
698 for (offset
= 0; offset
< padded_len
; offset
+= wordsize
)
700 ULONGEST word
= extract_unsigned_integer (padded
+ offset
,
702 regcache_cooked_write_unsigned (regcache
, reg
++, word
);
708 /* It doesn't fit in registers! Onto the stack it goes. */
709 write_memory (sp
+ stack_offset
, padded
, padded_len
);
710 stack_offset
+= padded_len
;
712 /* Once one argument has spilled onto the stack, all
713 subsequent arguments go on the stack. */
714 reg
= E_ARGLAST_REGNUM
+ 1;
718 /* Store return address. */
720 write_memory_unsigned_integer (sp
, wordsize
, bp_addr
);
722 /* Update stack pointer. */
723 regcache_cooked_write_unsigned (regcache
, E_SP_REGNUM
, sp
);
728 /* Function: h8300_pop_frame
729 Restore the machine to the state it had before the current frame
730 was created. Usually used either by the "RETURN" command, or by
731 call_function_by_hand after the dummy_frame is finished. */
734 h8300_pop_frame (void)
737 struct frame_info
*frame
= get_current_frame ();
739 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame
),
740 get_frame_base (frame
),
741 get_frame_base (frame
)))
743 generic_pop_dummy_frame ();
747 for (regno
= 0; regno
< 8; regno
++)
749 /* Don't forget E_SP_REGNUM is a frame_saved_regs struct is the
750 actual value we want, not the address of the value we want. */
751 if (get_frame_saved_regs (frame
)[regno
] && regno
!= E_SP_REGNUM
)
752 write_register (regno
,
754 (get_frame_saved_regs (frame
)[regno
], BINWORD
));
755 else if (get_frame_saved_regs (frame
)[regno
] && regno
== E_SP_REGNUM
)
756 write_register (regno
, get_frame_base (frame
) + 2 * BINWORD
);
759 /* Don't forget to update the PC too! */
760 write_register (E_PC_REGNUM
, get_frame_extra_info (frame
)->from_pc
);
762 flush_cached_frames ();
765 /* Function: extract_return_value
766 Figure out where in REGBUF the called function has left its return value.
767 Copy that into VALBUF. Be sure to account for CPU type. */
770 h8300_extract_return_value (struct type
*type
, struct regcache
*regcache
,
773 int len
= TYPE_LENGTH (type
);
780 regcache_cooked_read_unsigned (regcache
, E_RET0_REGNUM
, &c
);
781 store_unsigned_integer (valbuf
, len
, c
);
783 case 4: /* Needs two registers on plain H8/300 */
784 regcache_cooked_read_unsigned (regcache
, E_RET0_REGNUM
, &c
);
785 store_unsigned_integer (valbuf
, 2, c
);
786 regcache_cooked_read_unsigned (regcache
, E_RET1_REGNUM
, &c
);
787 store_unsigned_integer ((void*)((char *)valbuf
+ 2), 2, c
);
789 case 8: /* long long is now 8 bytes. */
790 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
792 regcache_cooked_read_unsigned (regcache
, E_RET0_REGNUM
, &addr
);
793 c
= read_memory_unsigned_integer ((CORE_ADDR
) addr
, len
);
794 store_unsigned_integer (valbuf
, len
, c
);
798 error ("I don't know how this 8 byte value is returned.");
805 h8300h_extract_return_value (struct type
*type
, struct regcache
*regcache
,
808 int len
= TYPE_LENGTH (type
);
816 regcache_cooked_read_unsigned (regcache
, E_RET0_REGNUM
, &c
);
817 store_unsigned_integer (valbuf
, len
, c
);
819 case 8: /* long long is now 8 bytes. */
820 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
822 regcache_cooked_read_unsigned (regcache
, E_RET0_REGNUM
, &addr
);
823 c
= read_memory_unsigned_integer ((CORE_ADDR
) addr
, len
);
824 store_unsigned_integer (valbuf
, len
, c
);
828 error ("I don't know how this 8 byte value is returned.");
835 /* Function: store_return_value
836 Place the appropriate value in the appropriate registers.
837 Primarily used by the RETURN command. */
840 h8300_store_return_value (struct type
*type
, struct regcache
*regcache
,
843 int len
= TYPE_LENGTH (type
);
849 case 2: /* short... */
850 val
= extract_unsigned_integer (valbuf
, len
);
851 regcache_cooked_write_unsigned (regcache
, E_RET0_REGNUM
, val
);
853 case 4: /* long, float */
854 val
= extract_unsigned_integer (valbuf
, len
);
855 regcache_cooked_write_unsigned (regcache
, E_RET0_REGNUM
,
856 (val
>> 16) &0xffff);
857 regcache_cooked_write_unsigned (regcache
, E_RET1_REGNUM
, val
& 0xffff);
859 case 8: /* long long, double and long double are all defined
860 as 4 byte types so far so this shouldn't happen. */
861 error ("I don't know how to return an 8 byte value.");
867 h8300h_store_return_value (struct type
*type
, struct regcache
*regcache
,
870 int len
= TYPE_LENGTH (type
);
877 case 4: /* long, float */
878 val
= extract_unsigned_integer (valbuf
, len
);
879 regcache_cooked_write_unsigned (regcache
, E_RET0_REGNUM
, val
);
881 case 8: /* long long, double and long double are all defined
882 as 4 byte types so far so this shouldn't happen. */
883 error ("I don't know how to return an 8 byte value.");
888 static struct cmd_list_element
*setmachinelist
;
891 h8300_register_name (int regno
)
893 /* The register names change depending on which h8300 processor
895 static char *register_names
[] = {
896 "r0", "r1", "r2", "r3", "r4", "r5", "r6",
897 "sp", "","pc","cycles", "tick", "inst",
898 "ccr", /* pseudo register */
901 || regno
>= (sizeof (register_names
) / sizeof (*register_names
)))
902 internal_error (__FILE__
, __LINE__
,
903 "h8300_register_name: illegal register number %d", regno
);
905 return register_names
[regno
];
909 h8300s_register_name (int regno
)
911 static char *register_names
[] = {
912 "er0", "er1", "er2", "er3", "er4", "er5", "er6",
913 "sp", "", "pc", "cycles", "", "tick", "inst",
915 "ccr", "exr" /* pseudo registers */
918 || regno
>= (sizeof (register_names
) / sizeof (*register_names
)))
919 internal_error (__FILE__
, __LINE__
,
920 "h8300s_register_name: illegal register number %d", regno
);
922 return register_names
[regno
];
926 h8300sx_register_name (int regno
)
928 static char *register_names
[] = {
929 "er0", "er1", "er2", "er3", "er4", "er5", "er6",
930 "sp", "", "pc", "cycles", "", "tick", "inst",
931 "mach", "macl", "sbr", "vbr",
932 "ccr", "exr" /* pseudo registers */
935 || regno
>= (sizeof (register_names
) / sizeof (*register_names
)))
936 internal_error (__FILE__
, __LINE__
,
937 "h8300sx_register_name: illegal register number %d", regno
);
939 return register_names
[regno
];
943 h8300_print_register (struct gdbarch
*gdbarch
, struct ui_file
*file
,
944 struct frame_info
*frame
, int regno
)
947 const char *name
= gdbarch_register_name (gdbarch
, regno
);
952 frame_read_signed_register (frame
, regno
, &rval
);
954 fprintf_filtered (file
, "%-14s ", name
);
955 if (regno
== E_PSEUDO_CCR_REGNUM
|| (regno
== E_PSEUDO_EXR_REGNUM
&& h8300smode
))
957 fprintf_filtered (file
, "0x%02x ", (unsigned char)rval
);
958 print_longest (file
, 'u', 1, rval
);
962 fprintf_filtered (file
, "0x%s ", phex ((ULONGEST
)rval
, BINWORD
));
963 print_longest (file
, 'd', 1, rval
);
965 if (regno
== E_PSEUDO_CCR_REGNUM
)
969 unsigned char l
= rval
& 0xff;
970 fprintf_filtered (file
, "\t");
971 fprintf_filtered (file
, "I-%d ", (l
& 0x80) != 0);
972 fprintf_filtered (file
, "UI-%d ", (l
& 0x40) != 0);
973 fprintf_filtered (file
, "H-%d ", (l
& 0x20) != 0);
974 fprintf_filtered (file
, "U-%d ", (l
& 0x10) != 0);
979 fprintf_filtered (file
, "N-%d ", N
);
980 fprintf_filtered (file
, "Z-%d ", Z
);
981 fprintf_filtered (file
, "V-%d ", V
);
982 fprintf_filtered (file
, "C-%d ", C
);
984 fprintf_filtered (file
, "u> ");
986 fprintf_filtered (file
, "u<= ");
988 fprintf_filtered (file
, "u>= ");
990 fprintf_filtered (file
, "u< ");
992 fprintf_filtered (file
, "!= ");
994 fprintf_filtered (file
, "== ");
996 fprintf_filtered (file
, ">= ");
998 fprintf_filtered (file
, "< ");
999 if ((Z
| (N
^ V
)) == 0)
1000 fprintf_filtered (file
, "> ");
1001 if ((Z
| (N
^ V
)) == 1)
1002 fprintf_filtered (file
, "<= ");
1004 else if (regno
== E_PSEUDO_EXR_REGNUM
&& h8300smode
)
1007 unsigned char l
= rval
& 0xff;
1008 fprintf_filtered (file
, "\t");
1009 fprintf_filtered (file
, "T-%d - - - ", (l
& 0x80) != 0);
1010 fprintf_filtered (file
, "I2-%d ", (l
& 4) != 0);
1011 fprintf_filtered (file
, "I1-%d ", (l
& 2) != 0);
1012 fprintf_filtered (file
, "I0-%d", (l
& 1) != 0);
1014 fprintf_filtered (file
, "\n");
1018 h8300_print_registers_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1019 struct frame_info
*frame
, int regno
, int cpregs
)
1023 for (regno
= E_R0_REGNUM
; regno
<= E_SP_REGNUM
; ++regno
)
1024 h8300_print_register (gdbarch
, file
, frame
, regno
);
1025 h8300_print_register (gdbarch
, file
, frame
, E_PSEUDO_CCR_REGNUM
);
1026 h8300_print_register (gdbarch
, file
, frame
, E_PC_REGNUM
);
1029 h8300_print_register (gdbarch
, file
, frame
, E_PSEUDO_EXR_REGNUM
);
1032 h8300_print_register (gdbarch
, file
, frame
, E_SBR_REGNUM
);
1033 h8300_print_register (gdbarch
, file
, frame
, E_VBR_REGNUM
);
1035 h8300_print_register (gdbarch
, file
, frame
, E_MACH_REGNUM
);
1036 h8300_print_register (gdbarch
, file
, frame
, E_MACL_REGNUM
);
1037 h8300_print_register (gdbarch
, file
, frame
, E_CYCLES_REGNUM
);
1038 h8300_print_register (gdbarch
, file
, frame
, E_TICKS_REGNUM
);
1039 h8300_print_register (gdbarch
, file
, frame
, E_INSTS_REGNUM
);
1043 h8300_print_register (gdbarch
, file
, frame
, E_CYCLES_REGNUM
);
1044 h8300_print_register (gdbarch
, file
, frame
, E_TICK_REGNUM
);
1045 h8300_print_register (gdbarch
, file
, frame
, E_INST_REGNUM
);
1050 if (regno
== E_CCR_REGNUM
)
1051 h8300_print_register (gdbarch
, file
, frame
, E_PSEUDO_CCR_REGNUM
);
1052 else if (regno
== E_PSEUDO_EXR_REGNUM
&& h8300smode
)
1053 h8300_print_register (gdbarch
, file
, frame
, E_PSEUDO_EXR_REGNUM
);
1055 h8300_print_register (gdbarch
, file
, frame
, regno
);
1060 h8300_saved_pc_after_call (struct frame_info
*ignore
)
1062 return read_memory_unsigned_integer (read_register (E_SP_REGNUM
), BINWORD
);
1065 static struct type
*
1066 h8300_register_type (struct gdbarch
*gdbarch
, int regno
)
1068 if (regno
< 0 || regno
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
1069 internal_error (__FILE__
, __LINE__
,
1070 "h8300_register_type: illegal register number %d",
1077 return builtin_type_void_func_ptr
;
1080 return builtin_type_void_data_ptr
;
1082 if (regno
== E_PSEUDO_CCR_REGNUM
)
1083 return builtin_type_uint8
;
1084 else if (regno
== E_PSEUDO_EXR_REGNUM
)
1085 return builtin_type_uint8
;
1086 else if (h8300hmode
)
1087 return builtin_type_int32
;
1089 return builtin_type_int16
;
1095 h8300_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1096 int regno
, void *buf
)
1098 if (regno
== E_PSEUDO_CCR_REGNUM
)
1099 regcache_raw_read (regcache
, E_CCR_REGNUM
, buf
);
1100 else if (regno
== E_PSEUDO_EXR_REGNUM
)
1101 regcache_raw_read (regcache
, E_EXR_REGNUM
, buf
);
1103 regcache_raw_read (regcache
, regno
, buf
);
1107 h8300_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1108 int regno
, const void *buf
)
1110 if (regno
== E_PSEUDO_CCR_REGNUM
)
1111 regcache_raw_write (regcache
, E_CCR_REGNUM
, buf
);
1112 else if (regno
== E_PSEUDO_EXR_REGNUM
)
1113 regcache_raw_write (regcache
, E_EXR_REGNUM
, buf
);
1115 regcache_raw_write (regcache
, regno
, buf
);
1119 h8300_dbg_reg_to_regnum (int regno
)
1121 if (regno
== E_CCR_REGNUM
)
1122 return E_PSEUDO_CCR_REGNUM
;
1127 h8300s_dbg_reg_to_regnum (int regno
)
1129 if (regno
== E_CCR_REGNUM
)
1130 return E_PSEUDO_CCR_REGNUM
;
1131 if (regno
== E_EXR_REGNUM
)
1132 return E_PSEUDO_EXR_REGNUM
;
1137 h8300_extract_struct_value_address (struct regcache
*regcache
)
1140 regcache_cooked_read_unsigned (regcache
, E_RET0_REGNUM
, &addr
);
1144 const static unsigned char *
1145 h8300_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
1147 /*static unsigned char breakpoint[] = { 0x7A, 0xFF };*/ /* ??? */
1148 static unsigned char breakpoint
[] = { 0x01, 0x80 }; /* Sleep */
1150 *lenptr
= sizeof (breakpoint
);
1155 h8300_push_dummy_code (struct gdbarch
*gdbarch
,
1156 CORE_ADDR sp
, CORE_ADDR funaddr
, int using_gcc
,
1157 struct value
**args
, int nargs
,
1158 struct type
*value_type
,
1159 CORE_ADDR
*real_pc
, CORE_ADDR
*bp_addr
)
1161 /* Allocate space sufficient for a breakpoint. */
1163 /* Store the address of that breakpoint */
1165 /* h8300 always starts the call at the callee's entry point. */
1171 h8300_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1172 struct frame_info
*frame
, const char *args
)
1174 fprintf_filtered (file
, "\
1175 No floating-point info available for this processor.\n");
1178 static struct gdbarch
*
1179 h8300_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1181 struct gdbarch_tdep
*tdep
= NULL
;
1182 struct gdbarch
*gdbarch
;
1184 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1186 return arches
->gdbarch
;
1189 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
1192 if (info
.bfd_arch_info
->arch
!= bfd_arch_h8300
)
1195 gdbarch
= gdbarch_alloc (&info
, 0);
1197 switch (info
.bfd_arch_info
->mach
)
1199 case bfd_mach_h8300
:
1203 set_gdbarch_num_regs (gdbarch
, 13);
1204 set_gdbarch_num_pseudo_regs (gdbarch
, 1);
1205 set_gdbarch_ecoff_reg_to_regnum (gdbarch
, h8300_dbg_reg_to_regnum
);
1206 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, h8300_dbg_reg_to_regnum
);
1207 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, h8300_dbg_reg_to_regnum
);
1208 set_gdbarch_stab_reg_to_regnum (gdbarch
, h8300_dbg_reg_to_regnum
);
1209 set_gdbarch_register_name (gdbarch
, h8300_register_name
);
1210 set_gdbarch_ptr_bit (gdbarch
, 2 * TARGET_CHAR_BIT
);
1211 set_gdbarch_addr_bit (gdbarch
, 2 * TARGET_CHAR_BIT
);
1212 set_gdbarch_extract_return_value (gdbarch
, h8300_extract_return_value
);
1213 set_gdbarch_store_return_value (gdbarch
, h8300_store_return_value
);
1214 set_gdbarch_print_insn (gdbarch
, print_insn_h8300
);
1216 case bfd_mach_h8300h
:
1217 case bfd_mach_h8300hn
:
1221 set_gdbarch_num_regs (gdbarch
, 13);
1222 set_gdbarch_num_pseudo_regs (gdbarch
, 1);
1223 set_gdbarch_ecoff_reg_to_regnum (gdbarch
, h8300_dbg_reg_to_regnum
);
1224 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, h8300_dbg_reg_to_regnum
);
1225 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, h8300_dbg_reg_to_regnum
);
1226 set_gdbarch_stab_reg_to_regnum (gdbarch
, h8300_dbg_reg_to_regnum
);
1227 set_gdbarch_register_name (gdbarch
, h8300_register_name
);
1228 set_gdbarch_ptr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1229 set_gdbarch_addr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1230 set_gdbarch_extract_return_value (gdbarch
, h8300h_extract_return_value
);
1231 set_gdbarch_store_return_value (gdbarch
, h8300h_store_return_value
);
1232 set_gdbarch_print_insn (gdbarch
, print_insn_h8300h
);
1234 case bfd_mach_h8300s
:
1235 case bfd_mach_h8300sn
:
1239 set_gdbarch_num_regs (gdbarch
, 16);
1240 set_gdbarch_num_pseudo_regs (gdbarch
, 2);
1241 set_gdbarch_ecoff_reg_to_regnum (gdbarch
, h8300s_dbg_reg_to_regnum
);
1242 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, h8300s_dbg_reg_to_regnum
);
1243 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, h8300s_dbg_reg_to_regnum
);
1244 set_gdbarch_stab_reg_to_regnum (gdbarch
, h8300s_dbg_reg_to_regnum
);
1245 set_gdbarch_register_name (gdbarch
, h8300s_register_name
);
1246 set_gdbarch_ptr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1247 set_gdbarch_addr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1248 set_gdbarch_extract_return_value (gdbarch
, h8300h_extract_return_value
);
1249 set_gdbarch_store_return_value (gdbarch
, h8300h_store_return_value
);
1250 set_gdbarch_print_insn (gdbarch
, print_insn_h8300s
);
1252 case bfd_mach_h8300sx
:
1253 case bfd_mach_h8300sxn
:
1257 set_gdbarch_num_regs (gdbarch
, 18);
1258 set_gdbarch_num_pseudo_regs (gdbarch
, 2);
1259 set_gdbarch_ecoff_reg_to_regnum (gdbarch
, h8300s_dbg_reg_to_regnum
);
1260 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, h8300s_dbg_reg_to_regnum
);
1261 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, h8300s_dbg_reg_to_regnum
);
1262 set_gdbarch_stab_reg_to_regnum (gdbarch
, h8300s_dbg_reg_to_regnum
);
1263 set_gdbarch_register_name (gdbarch
, h8300sx_register_name
);
1264 set_gdbarch_ptr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1265 set_gdbarch_addr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1266 set_gdbarch_extract_return_value (gdbarch
, h8300h_extract_return_value
);
1267 set_gdbarch_store_return_value (gdbarch
, h8300h_store_return_value
);
1268 set_gdbarch_print_insn (gdbarch
, print_insn_h8300s
);
1272 set_gdbarch_pseudo_register_read (gdbarch
, h8300_pseudo_register_read
);
1273 set_gdbarch_pseudo_register_write (gdbarch
, h8300_pseudo_register_write
);
1275 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
1276 ready to unwind the PC first (see frame.c:get_prev_frame()). */
1277 set_gdbarch_deprecated_init_frame_pc (gdbarch
, init_frame_pc_default
);
1280 * Basic register fields and methods.
1283 set_gdbarch_sp_regnum (gdbarch
, E_SP_REGNUM
);
1284 set_gdbarch_deprecated_fp_regnum (gdbarch
, E_FP_REGNUM
);
1285 set_gdbarch_pc_regnum (gdbarch
, E_PC_REGNUM
);
1286 set_gdbarch_register_type (gdbarch
, h8300_register_type
);
1287 set_gdbarch_print_registers_info (gdbarch
, h8300_print_registers_info
);
1288 set_gdbarch_print_float_info (gdbarch
, h8300_print_float_info
);
1293 set_gdbarch_skip_prologue (gdbarch
, h8300_skip_prologue
);
1295 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
,
1296 h8300_frame_init_saved_regs
);
1297 set_gdbarch_deprecated_init_extra_frame_info (gdbarch
,
1298 h8300_init_extra_frame_info
);
1299 set_gdbarch_deprecated_frame_chain (gdbarch
, h8300_frame_chain
);
1300 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
,
1301 h8300_saved_pc_after_call
);
1302 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, h8300_frame_saved_pc
);
1303 set_gdbarch_deprecated_pop_frame (gdbarch
, h8300_pop_frame
);
1308 /* Stack grows up. */
1309 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1310 /* PC stops zero byte after a trap instruction
1311 (which means: exactly on trap instruction). */
1312 set_gdbarch_decr_pc_after_break (gdbarch
, 0);
1313 /* This value is almost never non-zero... */
1314 set_gdbarch_function_start_offset (gdbarch
, 0);
1315 /* This value is almost never non-zero... */
1316 set_gdbarch_frame_args_skip (gdbarch
, 0);
1317 set_gdbarch_frameless_function_invocation (gdbarch
,
1318 frameless_look_for_prologue
);
1320 set_gdbarch_extract_struct_value_address (gdbarch
,
1321 h8300_extract_struct_value_address
);
1322 set_gdbarch_use_struct_convention (gdbarch
, always_use_struct_convention
);
1323 set_gdbarch_breakpoint_from_pc (gdbarch
, h8300_breakpoint_from_pc
);
1324 set_gdbarch_push_dummy_code (gdbarch
, h8300_push_dummy_code
);
1325 set_gdbarch_push_dummy_call (gdbarch
, h8300_push_dummy_call
);
1327 set_gdbarch_int_bit (gdbarch
, 2 * TARGET_CHAR_BIT
);
1328 set_gdbarch_long_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1329 set_gdbarch_long_long_bit (gdbarch
, 8 * TARGET_CHAR_BIT
);
1330 set_gdbarch_double_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1331 set_gdbarch_long_double_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
1333 /* set_gdbarch_stack_align (gdbarch, SOME_stack_align); */
1334 set_gdbarch_believe_pcc_promotion (gdbarch
, 1);
1336 /* Char is unsigned. */
1337 set_gdbarch_char_signed (gdbarch
, 0);
1342 extern initialize_file_ftype _initialize_h8300_tdep
; /* -Wmissing-prototypes */
1345 _initialize_h8300_tdep (void)
1347 register_gdbarch_init (bfd_arch_h8300
, h8300_gdbarch_init
);