1 /* Target-machine dependent code for Renesas 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"
40 /* Extra info which is saved in each frame_info. */
41 struct frame_extra_info
50 h8300_max_reg_size = 4,
52 #define BINWORD (h8300hmode && !h8300_normal_mode ? h8300h_reg_size : h8300_reg_size)
56 E_R0_REGNUM, E_ER0_REGNUM = E_R0_REGNUM, E_ARG0_REGNUM = E_R0_REGNUM,
57 E_RET0_REGNUM = E_R0_REGNUM,
58 E_R1_REGNUM, E_ER1_REGNUM = E_R1_REGNUM, E_RET1_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 E_PSEUDO_CCR_REGNUM (NUM_REGS)
78 #define E_PSEUDO_EXR_REGNUM (NUM_REGS+1)
80 #define UNSIGNED_SHORT(X) ((X) & 0xffff)
82 #define IS_PUSH(x) ((x & 0xfff0)==0x6df0)
83 #define IS_PUSH_FP(x) (x == 0x6df6)
84 #define IS_MOVE_FP(x) (x == 0x0d76 || x == 0x0ff6)
85 #define IS_MOV_SP_FP(x) (x == 0x0d76 || x == 0x0ff6)
86 #define IS_SUB2_SP(x) (x==0x1b87)
87 #define IS_SUB4_SP(x) (x==0x1b97)
88 #define IS_SUBL_SP(x) (x==0x7a37)
89 #define IS_MOVK_R5(x) (x==0x7905)
90 #define IS_SUB_R5SP(x) (x==0x1957)
92 /* If the instruction at PC is an argument register spill, return its
93 length. Otherwise, return zero.
95 An argument register spill is an instruction that moves an argument
96 from the register in which it was passed to the stack slot in which
97 it really lives. It is a byte, word, or longword move from an
98 argument register to a negative offset from the frame pointer.
100 CV, 2003-06-16: Or, in optimized code or when the `register' qualifier
101 is used, it could be a byte, word or long move to registers r3-r5. */
104 h8300_is_argument_spill (CORE_ADDR pc)
106 int w = read_memory_unsigned_integer (pc, 2);
108 if (((w & 0xff88) == 0x0c88 /* mov.b Rsl, Rdl */
109 || (w & 0xff88) == 0x0d00 /* mov.w Rs, Rd */
110 || (w & 0xff88) == 0x0f80) /* mov.l Rs, Rd */
111 && (w & 0x70) <= 0x20 /* Rs is R0, R1 or R2 */
112 && (w & 0x7) >= 0x3 && (w & 0x7) <= 0x5)/* Rd is R3, R4 or R5 */
115 if ((w & 0xfff0) == 0x6ee0 /* mov.b Rs,@(d:16,er6) */
116 && 8 <= (w & 0xf) && (w & 0xf) <= 10) /* Rs is R0L, R1L, or R2L */
118 int w2 = read_memory_integer (pc + 2, 2);
120 /* ... and d:16 is negative. */
124 else if (w == 0x7860)
126 int w2 = read_memory_integer (pc + 2, 2);
128 if ((w2 & 0xfff0) == 0x6aa0) /* mov.b Rs, @(d:24,er6) */
130 LONGEST disp = read_memory_integer (pc + 4, 4);
132 /* ... and d:24 is negative. */
133 if (disp < 0 && disp > 0xffffff)
137 else if ((w & 0xfff0) == 0x6fe0 /* mov.w Rs,@(d:16,er6) */
138 && (w & 0xf) <= 2) /* Rs is R0, R1, or R2 */
140 int w2 = read_memory_integer (pc + 2, 2);
142 /* ... and d:16 is negative. */
146 else if (w == 0x78e0)
148 int w2 = read_memory_integer (pc + 2, 2);
150 if ((w2 & 0xfff0) == 0x6ba0) /* mov.b Rs, @(d:24,er6) */
152 LONGEST disp = read_memory_integer (pc + 4, 4);
154 /* ... and d:24 is negative. */
155 if (disp < 0 && disp > 0xffffff)
159 else if (w == 0x0100)
161 int w2 = read_memory_integer (pc + 2, 2);
163 if ((w2 & 0xfff0) == 0x6fe0 /* mov.l Rs,@(d:16,er6) */
164 && (w2 & 0xf) <= 2) /* Rs is ER0, ER1, or ER2 */
166 int w3 = read_memory_integer (pc + 4, 2);
168 /* ... and d:16 is negative. */
172 else if (w2 == 0x78e0)
174 int w3 = read_memory_integer (pc + 4, 2);
176 if ((w3 & 0xfff0) == 0x6ba0) /* mov.l Rs, @(d:24,er6) */
178 LONGEST disp = read_memory_integer (pc + 6, 4);
180 /* ... and d:24 is negative. */
181 if (disp < 0 && disp > 0xffffff)
191 h8300_skip_prologue (CORE_ADDR start_pc)
196 /* Skip past all push and stm insns. */
199 w = read_memory_unsigned_integer (start_pc, 2);
200 /* First look for push insns. */
201 if (w == 0x0100 || w == 0x0110 || w == 0x0120 || w == 0x0130)
203 w = read_memory_unsigned_integer (start_pc + 2, 2);
209 start_pc += 2 + adjust;
210 w = read_memory_unsigned_integer (start_pc, 2);
217 /* Skip past a move to FP, either word or long sized */
218 w = read_memory_unsigned_integer (start_pc, 2);
221 w = read_memory_unsigned_integer (start_pc + 2, 2);
227 start_pc += 2 + adjust;
228 w = read_memory_unsigned_integer (start_pc, 2);
231 /* Check for loading either a word constant into r5;
232 long versions are handled by the SUBL_SP below. */
236 w = read_memory_unsigned_integer (start_pc, 2);
239 /* Now check for subtracting r5 from sp, word sized only. */
242 start_pc += 2 + adjust;
243 w = read_memory_unsigned_integer (start_pc, 2);
246 /* Check for subs #2 and subs #4. */
247 while (IS_SUB2_SP (w) || IS_SUB4_SP (w))
249 start_pc += 2 + adjust;
250 w = read_memory_unsigned_integer (start_pc, 2);
253 /* Check for a 32bit subtract. */
255 start_pc += 6 + adjust;
257 /* Skip past another possible stm insn for registers R3 to R5 (possibly used
258 for register qualified arguments. */
259 w = read_memory_unsigned_integer (start_pc, 2);
260 /* First look for push insns. */
261 if (w == 0x0110 || w == 0x0120 || w == 0x0130)
263 w = read_memory_unsigned_integer (start_pc + 2, 2);
264 if (IS_PUSH (w) && (w & 0xf) >= 0x3 && (w & 0xf) <= 0x5)
268 /* Check for spilling an argument register to the stack frame.
269 This could also be an initializing store from non-prologue code,
270 but I don't think there's any harm in skipping that. */
273 int spill_size = h8300_is_argument_spill (start_pc);
276 start_pc += spill_size;
282 /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
283 is not the address of a valid instruction, the address of the next
284 instruction beyond ADDR otherwise. *PWORD1 receives the first word
285 of the instruction. */
288 h8300_next_prologue_insn (CORE_ADDR addr,
290 unsigned short* pword1)
295 read_memory (addr, buf, 2);
296 *pword1 = extract_signed_integer (buf, 2);
303 /* Examine the prologue of a function. `ip' points to the first instruction.
304 `limit' is the limit of the prologue (e.g. the addr of the first
305 linenumber, or perhaps the program counter if we're stepping through).
306 `frame_sp' is the stack pointer value in use in this frame.
307 `fsr' is a pointer to a frame_saved_regs structure into which we put
308 info about the registers saved by this frame.
309 `fi' is a struct frame_info pointer; we fill in various fields in it
310 to reflect the offsets of the arg pointer and the locals pointer. */
312 /* Any function with a frame looks like this
318 SAVED FP <-FP POINTS HERE
320 LOCALS1 <-SP POINTS HERE
324 h8300_examine_prologue (CORE_ADDR ip, CORE_ADDR limit,
325 CORE_ADDR after_prolog_fp, CORE_ADDR *fsr,
326 struct frame_info *fi)
331 unsigned short insn_word;
332 /* Number of things pushed onto stack, starts at 2/4, 'cause the
333 PC is already there */
334 unsigned int reg_save_depth = BINWORD;
336 unsigned int auto_depth = 0; /* Number of bytes of autos */
338 char in_frame[11]; /* One for each reg */
342 memset (in_frame, 1, 11);
343 for (r = 0; r < 8; r++)
347 if (after_prolog_fp == 0)
349 after_prolog_fp = read_register (E_SP_REGNUM);
352 /* If the PC isn't valid, quit now. */
353 if (ip == 0 || ip & (h8300hmode && !h8300_normal_mode ? ~0xffffff : ~0xffff))
356 next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
358 if (insn_word == 0x0100) /* mov.l */
360 insn_word = read_memory_unsigned_integer (ip + 2, 2);
364 /* Skip over any fp push instructions */
365 fsr[E_FP_REGNUM] = after_prolog_fp;
366 while (next_ip && IS_PUSH_FP (insn_word))
368 ip = next_ip + adjust;
370 in_frame[insn_word & 0x7] = reg_save_depth;
371 next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
372 reg_save_depth += 2 + adjust;
375 /* Is this a move into the fp */
376 if (next_ip && IS_MOV_SP_FP (insn_word))
379 next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
383 /* Skip over any stack adjustment, happens either with a number of
384 sub#2,sp or a mov #x,r5 sub r5,sp */
386 if (next_ip && (IS_SUB2_SP (insn_word) || IS_SUB4_SP (insn_word)))
388 while (next_ip && (IS_SUB2_SP (insn_word) || IS_SUB4_SP (insn_word)))
390 auto_depth += IS_SUB2_SP (insn_word) ? 2 : 4;
392 next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
397 if (next_ip && IS_MOVK_R5 (insn_word))
400 next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
401 auto_depth += insn_word;
403 next_ip = h8300_next_prologue_insn (next_ip, limit, &insn_word);
404 auto_depth += insn_word;
406 if (next_ip && IS_SUBL_SP (insn_word))
409 auto_depth += read_memory_unsigned_integer (ip, 4);
412 next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
416 /* Now examine the push insns to determine where everything lives
424 if (insn_word == 0x0100)
427 next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
431 if (IS_PUSH (insn_word))
433 auto_depth += 2 + adjust;
434 fsr[insn_word & 0x7] = after_prolog_fp - auto_depth;
436 next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
440 /* Now check for push multiple insns. */
441 if (insn_word == 0x0110 || insn_word == 0x0120 || insn_word == 0x0130)
443 int count = ((insn_word >> 4) & 0xf) + 1;
447 next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
448 start = insn_word & 0x7;
450 for (i = start; i < start + count; i++)
453 fsr[i] = after_prolog_fp - auto_depth;
459 /* The PC is at a known place */
460 get_frame_extra_info (fi)->from_pc =
461 read_memory_unsigned_integer (after_prolog_fp + BINWORD, BINWORD);
463 /* Rememeber any others too */
464 in_frame[E_PC_REGNUM] = 0;
467 /* We keep the old FP in the SP spot */
468 fsr[E_SP_REGNUM] = read_memory_unsigned_integer (fsr[E_FP_REGNUM],
471 fsr[E_SP_REGNUM] = after_prolog_fp + auto_depth;
477 h8300_frame_init_saved_regs (struct frame_info *fi)
479 CORE_ADDR func_addr, func_end;
481 if (!deprecated_get_frame_saved_regs (fi))
483 frame_saved_regs_zalloc (fi);
485 /* Find the beginning of this function, so we can analyze its
487 if (find_pc_partial_function (get_frame_pc (fi), NULL,
488 &func_addr, &func_end))
490 struct symtab_and_line sal = find_pc_line (func_addr, 0);
491 CORE_ADDR limit = (sal.end && sal.end < get_frame_pc (fi))
492 ? sal.end : get_frame_pc (fi);
493 /* This will fill in fields in fi. */
494 h8300_examine_prologue (func_addr, limit, get_frame_base (fi),
495 deprecated_get_frame_saved_regs (fi), fi);
497 /* Else we're out of luck (can't debug completely stripped code).
502 /* Given a GDB frame, determine the address of the calling function's
503 frame. This will be used to create a new GDB frame struct, and
504 then DEPRECATED_INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC
505 will be called for the new frame.
507 For us, the frame address is its stack pointer value, so we look up
508 the function prologue to determine the caller's sp value, and
512 h8300_frame_chain (struct frame_info *thisframe)
514 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (thisframe),
515 get_frame_base (thisframe),
516 get_frame_base (thisframe)))
517 { /* initialize the from_pc now */
518 get_frame_extra_info (thisframe)->from_pc =
519 deprecated_read_register_dummy (get_frame_pc (thisframe),
520 get_frame_base (thisframe),
522 return get_frame_base (thisframe);
524 return deprecated_get_frame_saved_regs (thisframe)[E_SP_REGNUM];
527 /* Return the saved PC from this frame.
529 If the frame has a memory copy of SRP_REGNUM, use that. If not,
530 just use the register SRP_REGNUM itself. */
533 h8300_frame_saved_pc (struct frame_info *frame)
535 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame),
536 get_frame_base (frame),
537 get_frame_base (frame)))
538 return deprecated_read_register_dummy (get_frame_pc (frame),
539 get_frame_base (frame),
542 return get_frame_extra_info (frame)->from_pc;
546 h8300_init_extra_frame_info (int fromleaf, struct frame_info *fi)
548 if (!get_frame_extra_info (fi))
550 frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
551 get_frame_extra_info (fi)->from_pc = 0;
553 if (!get_frame_pc (fi))
555 if (get_next_frame (fi))
556 deprecated_update_frame_pc_hack (fi, h8300_frame_saved_pc (get_next_frame (fi)));
558 h8300_frame_init_saved_regs (fi);
562 /* Function: push_dummy_call
563 Setup the function arguments for calling a function in the inferior.
564 In this discussion, a `word' is 16 bits on the H8/300s, and 32 bits
567 There are actually two ABI's here: -mquickcall (the default) and
568 -mno-quickcall. With -mno-quickcall, all arguments are passed on
569 the stack after the return address, word-aligned. With
570 -mquickcall, GCC tries to use r0 -- r2 to pass registers. Since
571 GCC doesn't indicate in the object file which ABI was used to
572 compile it, GDB only supports the default --- -mquickcall.
574 Here are the rules for -mquickcall, in detail:
576 Each argument, whether scalar or aggregate, is padded to occupy a
577 whole number of words. Arguments smaller than a word are padded at
578 the most significant end; those larger than a word are padded at
579 the least significant end.
581 The initial arguments are passed in r0 -- r2. Earlier arguments go in
582 lower-numbered registers. Multi-word arguments are passed in
583 consecutive registers, with the most significant end in the
584 lower-numbered register.
586 If an argument doesn't fit entirely in the remaining registers, it
587 is passed entirely on the stack. Stack arguments begin just after
588 the return address. Once an argument has overflowed onto the stack
589 this way, all subsequent arguments are passed on the stack.
591 The above rule has odd consequences. For example, on the h8/300s,
592 if a function takes two longs and an int as arguments:
593 - the first long will be passed in r0/r1,
594 - the second long will be passed entirely on the stack, since it
596 - and the int will be passed on the stack, even though it could fit
599 A weird exception: if an argument is larger than a word, but not a
600 whole number of words in length (before padding), it is passed on
601 the stack following the rules for stack arguments above, even if
602 there are sufficient registers available to hold it. Stranger
603 still, the argument registers are still `used up' --- even though
604 there's nothing in them.
606 So, for example, on the h8/300s, if a function expects a three-byte
607 structure and an int, the structure will go on the stack, and the
608 int will go in r2, not r0.
610 If the function returns an aggregate type (struct, union, or class)
611 by value, the caller must allocate space to hold the return value,
612 and pass the callee a pointer to this space as an invisible first
615 For varargs functions, the last fixed argument and all the variable
616 arguments are always passed on the stack. This means that calls to
617 varargs functions don't work properly unless there is a prototype
620 Basically, this ABI is not good, for the following reasons:
621 - You can't call vararg functions properly unless a prototype is in scope.
622 - Structure passing is inconsistent, to no purpose I can see.
623 - It often wastes argument registers, of which there are only three
627 h8300_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
628 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
629 struct value **args, CORE_ADDR sp, int struct_return,
630 CORE_ADDR struct_addr)
632 int stack_alloc = 0, stack_offset = 0;
633 int wordsize = BINWORD;
634 int reg = E_ARG0_REGNUM;
637 /* First, make sure the stack is properly aligned. */
638 sp = align_down (sp, wordsize);
640 /* Now make sure there's space on the stack for the arguments. We
641 may over-allocate a little here, but that won't hurt anything. */
642 for (argument = 0; argument < nargs; argument++)
643 stack_alloc += align_up (TYPE_LENGTH (VALUE_TYPE (args[argument])),
647 /* Now load as many arguments as possible into registers, and push
648 the rest onto the stack.
649 If we're returning a structure by value, then we must pass a
650 pointer to the buffer for the return value as an invisible first
653 regcache_cooked_write_unsigned (regcache, reg++, struct_addr);
655 for (argument = 0; argument < nargs; argument++)
657 struct type *type = VALUE_TYPE (args[argument]);
658 int len = TYPE_LENGTH (type);
659 char *contents = (char *) VALUE_CONTENTS (args[argument]);
661 /* Pad the argument appropriately. */
662 int padded_len = align_up (len, wordsize);
663 char *padded = alloca (padded_len);
665 memset (padded, 0, padded_len);
666 memcpy (len < wordsize ? padded + padded_len - len : padded,
669 /* Could the argument fit in the remaining registers? */
670 if (padded_len <= (E_ARGLAST_REGNUM - reg + 1) * wordsize)
672 /* Are we going to pass it on the stack anyway, for no good
674 if (len > wordsize && len % wordsize)
676 /* I feel so unclean. */
677 write_memory (sp + stack_offset, padded, padded_len);
678 stack_offset += padded_len;
680 /* That's right --- even though we passed the argument
681 on the stack, we consume the registers anyway! Love
683 reg += padded_len / wordsize;
687 /* Heavens to Betsy --- it's really going in registers!
688 It would be nice if we could use write_register_bytes
689 here, but on the h8/300s, there are gaps between
690 the registers in the register file. */
693 for (offset = 0; offset < padded_len; offset += wordsize)
695 ULONGEST word = extract_unsigned_integer (padded + offset,
697 regcache_cooked_write_unsigned (regcache, reg++, word);
703 /* It doesn't fit in registers! Onto the stack it goes. */
704 write_memory (sp + stack_offset, padded, padded_len);
705 stack_offset += padded_len;
707 /* Once one argument has spilled onto the stack, all
708 subsequent arguments go on the stack. */
709 reg = E_ARGLAST_REGNUM + 1;
713 /* Store return address. */
715 write_memory_unsigned_integer (sp, wordsize, bp_addr);
717 /* Update stack pointer. */
718 regcache_cooked_write_unsigned (regcache, E_SP_REGNUM, sp);
723 /* Function: h8300_pop_frame
724 Restore the machine to the state it had before the current frame
725 was created. Usually used either by the "RETURN" command, or by
726 call_function_by_hand after the dummy_frame is finished. */
729 h8300_pop_frame (void)
732 struct frame_info *frame = get_current_frame ();
734 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame),
735 get_frame_base (frame),
736 get_frame_base (frame)))
738 generic_pop_dummy_frame ();
742 for (regno = 0; regno < 8; regno++)
744 /* Don't forget E_SP_REGNUM is a frame_saved_regs struct is the
745 actual value we want, not the address of the value we want. */
746 if (deprecated_get_frame_saved_regs (frame)[regno] && regno != E_SP_REGNUM)
747 write_register (regno,
749 (deprecated_get_frame_saved_regs (frame)[regno], BINWORD));
750 else if (deprecated_get_frame_saved_regs (frame)[regno] && regno == E_SP_REGNUM)
751 write_register (regno, get_frame_base (frame) + 2 * BINWORD);
754 /* Don't forget to update the PC too! */
755 write_register (E_PC_REGNUM, get_frame_extra_info (frame)->from_pc);
757 flush_cached_frames ();
760 /* Function: extract_return_value
761 Figure out where in REGBUF the called function has left its return value.
762 Copy that into VALBUF. Be sure to account for CPU type. */
765 h8300_extract_return_value (struct type *type, struct regcache *regcache,
768 int len = TYPE_LENGTH (type);
775 regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &c);
776 store_unsigned_integer (valbuf, len, c);
778 case 4: /* Needs two registers on plain H8/300 */
779 regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &c);
780 store_unsigned_integer (valbuf, 2, c);
781 regcache_cooked_read_unsigned (regcache, E_RET1_REGNUM, &c);
782 store_unsigned_integer ((void*)((char *)valbuf + 2), 2, c);
784 case 8: /* long long is now 8 bytes. */
785 if (TYPE_CODE (type) == TYPE_CODE_INT)
787 regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &addr);
788 c = read_memory_unsigned_integer ((CORE_ADDR) addr, len);
789 store_unsigned_integer (valbuf, len, c);
793 error ("I don't know how this 8 byte value is returned.");
800 h8300h_extract_return_value (struct type *type, struct regcache *regcache,
803 int len = TYPE_LENGTH (type);
811 regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &c);
812 store_unsigned_integer (valbuf, len, c);
814 case 8: /* long long is now 8 bytes. */
815 if (TYPE_CODE (type) == TYPE_CODE_INT)
817 regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &addr);
818 c = read_memory_unsigned_integer ((CORE_ADDR) addr, len);
819 store_unsigned_integer (valbuf, len, c);
823 error ("I don't know how this 8 byte value is returned.");
830 /* Function: store_return_value
831 Place the appropriate value in the appropriate registers.
832 Primarily used by the RETURN command. */
835 h8300_store_return_value (struct type *type, struct regcache *regcache,
838 int len = TYPE_LENGTH (type);
844 case 2: /* short... */
845 val = extract_unsigned_integer (valbuf, len);
846 regcache_cooked_write_unsigned (regcache, E_RET0_REGNUM, val);
848 case 4: /* long, float */
849 val = extract_unsigned_integer (valbuf, len);
850 regcache_cooked_write_unsigned (regcache, E_RET0_REGNUM,
851 (val >> 16) &0xffff);
852 regcache_cooked_write_unsigned (regcache, E_RET1_REGNUM, val & 0xffff);
854 case 8: /* long long, double and long double are all defined
855 as 4 byte types so far so this shouldn't happen. */
856 error ("I don't know how to return an 8 byte value.");
862 h8300h_store_return_value (struct type *type, struct regcache *regcache,
865 int len = TYPE_LENGTH (type);
872 case 4: /* long, float */
873 val = extract_unsigned_integer (valbuf, len);
874 regcache_cooked_write_unsigned (regcache, E_RET0_REGNUM, val);
876 case 8: /* long long, double and long double are all defined
877 as 4 byte types so far so this shouldn't happen. */
878 error ("I don't know how to return an 8 byte value.");
883 static struct cmd_list_element *setmachinelist;
886 h8300_register_name (int regno)
888 /* The register names change depending on which h8300 processor
890 static char *register_names[] = {
891 "r0", "r1", "r2", "r3", "r4", "r5", "r6",
892 "sp", "","pc","cycles", "tick", "inst",
893 "ccr", /* pseudo register */
896 || regno >= (sizeof (register_names) / sizeof (*register_names)))
897 internal_error (__FILE__, __LINE__,
898 "h8300_register_name: illegal register number %d", regno);
900 return register_names[regno];
904 h8300s_register_name (int regno)
906 static char *register_names[] = {
907 "er0", "er1", "er2", "er3", "er4", "er5", "er6",
908 "sp", "", "pc", "cycles", "", "tick", "inst",
910 "ccr", "exr" /* pseudo registers */
913 || regno >= (sizeof (register_names) / sizeof (*register_names)))
914 internal_error (__FILE__, __LINE__,
915 "h8300s_register_name: illegal register number %d", regno);
917 return register_names[regno];
921 h8300sx_register_name (int regno)
923 static char *register_names[] = {
924 "er0", "er1", "er2", "er3", "er4", "er5", "er6",
925 "sp", "", "pc", "cycles", "", "tick", "inst",
926 "mach", "macl", "sbr", "vbr",
927 "ccr", "exr" /* pseudo registers */
930 || regno >= (sizeof (register_names) / sizeof (*register_names)))
931 internal_error (__FILE__, __LINE__,
932 "h8300sx_register_name: illegal register number %d", regno);
934 return register_names[regno];
938 h8300_print_register (struct gdbarch *gdbarch, struct ui_file *file,
939 struct frame_info *frame, int regno)
942 const char *name = gdbarch_register_name (gdbarch, regno);
947 rval = get_frame_register_signed (frame, regno);
949 fprintf_filtered (file, "%-14s ", name);
950 if (regno == E_PSEUDO_CCR_REGNUM || (regno == E_PSEUDO_EXR_REGNUM && h8300smode))
952 fprintf_filtered (file, "0x%02x ", (unsigned char)rval);
953 print_longest (file, 'u', 1, rval);
957 fprintf_filtered (file, "0x%s ", phex ((ULONGEST)rval, BINWORD));
958 print_longest (file, 'd', 1, rval);
960 if (regno == E_PSEUDO_CCR_REGNUM)
964 unsigned char l = rval & 0xff;
965 fprintf_filtered (file, "\t");
966 fprintf_filtered (file, "I-%d ", (l & 0x80) != 0);
967 fprintf_filtered (file, "UI-%d ", (l & 0x40) != 0);
968 fprintf_filtered (file, "H-%d ", (l & 0x20) != 0);
969 fprintf_filtered (file, "U-%d ", (l & 0x10) != 0);
974 fprintf_filtered (file, "N-%d ", N);
975 fprintf_filtered (file, "Z-%d ", Z);
976 fprintf_filtered (file, "V-%d ", V);
977 fprintf_filtered (file, "C-%d ", C);
979 fprintf_filtered (file, "u> ");
981 fprintf_filtered (file, "u<= ");
983 fprintf_filtered (file, "u>= ");
985 fprintf_filtered (file, "u< ");
987 fprintf_filtered (file, "!= ");
989 fprintf_filtered (file, "== ");
991 fprintf_filtered (file, ">= ");
993 fprintf_filtered (file, "< ");
994 if ((Z | (N ^ V)) == 0)
995 fprintf_filtered (file, "> ");
996 if ((Z | (N ^ V)) == 1)
997 fprintf_filtered (file, "<= ");
999 else if (regno == E_PSEUDO_EXR_REGNUM && h8300smode)
1002 unsigned char l = rval & 0xff;
1003 fprintf_filtered (file, "\t");
1004 fprintf_filtered (file, "T-%d - - - ", (l & 0x80) != 0);
1005 fprintf_filtered (file, "I2-%d ", (l & 4) != 0);
1006 fprintf_filtered (file, "I1-%d ", (l & 2) != 0);
1007 fprintf_filtered (file, "I0-%d", (l & 1) != 0);
1009 fprintf_filtered (file, "\n");
1013 h8300_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
1014 struct frame_info *frame, int regno, int cpregs)
1018 for (regno = E_R0_REGNUM; regno <= E_SP_REGNUM; ++regno)
1019 h8300_print_register (gdbarch, file, frame, regno);
1020 h8300_print_register (gdbarch, file, frame, E_PSEUDO_CCR_REGNUM);
1021 h8300_print_register (gdbarch, file, frame, E_PC_REGNUM);
1024 h8300_print_register (gdbarch, file, frame, E_PSEUDO_EXR_REGNUM);
1027 h8300_print_register (gdbarch, file, frame, E_SBR_REGNUM);
1028 h8300_print_register (gdbarch, file, frame, E_VBR_REGNUM);
1030 h8300_print_register (gdbarch, file, frame, E_MACH_REGNUM);
1031 h8300_print_register (gdbarch, file, frame, E_MACL_REGNUM);
1032 h8300_print_register (gdbarch, file, frame, E_CYCLES_REGNUM);
1033 h8300_print_register (gdbarch, file, frame, E_TICKS_REGNUM);
1034 h8300_print_register (gdbarch, file, frame, E_INSTS_REGNUM);
1038 h8300_print_register (gdbarch, file, frame, E_CYCLES_REGNUM);
1039 h8300_print_register (gdbarch, file, frame, E_TICK_REGNUM);
1040 h8300_print_register (gdbarch, file, frame, E_INST_REGNUM);
1045 if (regno == E_CCR_REGNUM)
1046 h8300_print_register (gdbarch, file, frame, E_PSEUDO_CCR_REGNUM);
1047 else if (regno == E_PSEUDO_EXR_REGNUM && h8300smode)
1048 h8300_print_register (gdbarch, file, frame, E_PSEUDO_EXR_REGNUM);
1050 h8300_print_register (gdbarch, file, frame, regno);
1055 h8300_saved_pc_after_call (struct frame_info *ignore)
1057 return read_memory_unsigned_integer (read_register (E_SP_REGNUM), BINWORD);
1060 static struct type *
1061 h8300_register_type (struct gdbarch *gdbarch, int regno)
1063 if (regno < 0 || regno >= NUM_REGS + NUM_PSEUDO_REGS)
1064 internal_error (__FILE__, __LINE__,
1065 "h8300_register_type: illegal register number %d",
1072 return builtin_type_void_func_ptr;
1075 return builtin_type_void_data_ptr;
1077 if (regno == E_PSEUDO_CCR_REGNUM)
1078 return builtin_type_uint8;
1079 else if (regno == E_PSEUDO_EXR_REGNUM)
1080 return builtin_type_uint8;
1081 else if (h8300hmode)
1082 return builtin_type_int32;
1084 return builtin_type_int16;
1090 h8300_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
1091 int regno, void *buf)
1093 if (regno == E_PSEUDO_CCR_REGNUM)
1094 regcache_raw_read (regcache, E_CCR_REGNUM, buf);
1095 else if (regno == E_PSEUDO_EXR_REGNUM)
1096 regcache_raw_read (regcache, E_EXR_REGNUM, buf);
1098 regcache_raw_read (regcache, regno, buf);
1102 h8300_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
1103 int regno, const void *buf)
1105 if (regno == E_PSEUDO_CCR_REGNUM)
1106 regcache_raw_write (regcache, E_CCR_REGNUM, buf);
1107 else if (regno == E_PSEUDO_EXR_REGNUM)
1108 regcache_raw_write (regcache, E_EXR_REGNUM, buf);
1110 regcache_raw_write (regcache, regno, buf);
1114 h8300_dbg_reg_to_regnum (int regno)
1116 if (regno == E_CCR_REGNUM)
1117 return E_PSEUDO_CCR_REGNUM;
1122 h8300s_dbg_reg_to_regnum (int regno)
1124 if (regno == E_CCR_REGNUM)
1125 return E_PSEUDO_CCR_REGNUM;
1126 if (regno == E_EXR_REGNUM)
1127 return E_PSEUDO_EXR_REGNUM;
1132 h8300_extract_struct_value_address (struct regcache *regcache)
1135 regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &addr);
1139 const static unsigned char *
1140 h8300_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
1142 /*static unsigned char breakpoint[] = { 0x7A, 0xFF };*/ /* ??? */
1143 static unsigned char breakpoint[] = { 0x01, 0x80 }; /* Sleep */
1145 *lenptr = sizeof (breakpoint);
1150 h8300_push_dummy_code (struct gdbarch *gdbarch,
1151 CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc,
1152 struct value **args, int nargs,
1153 struct type *value_type,
1154 CORE_ADDR *real_pc, CORE_ADDR *bp_addr)
1156 /* Allocate space sufficient for a breakpoint. */
1158 /* Store the address of that breakpoint */
1160 /* h8300 always starts the call at the callee's entry point. */
1166 h8300_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
1167 struct frame_info *frame, const char *args)
1169 fprintf_filtered (file, "\
1170 No floating-point info available for this processor.\n");
1173 static struct gdbarch *
1174 h8300_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1176 struct gdbarch_tdep *tdep = NULL;
1177 struct gdbarch *gdbarch;
1179 arches = gdbarch_list_lookup_by_info (arches, &info);
1181 return arches->gdbarch;
1184 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
1187 if (info.bfd_arch_info->arch != bfd_arch_h8300)
1190 gdbarch = gdbarch_alloc (&info, 0);
1192 switch (info.bfd_arch_info->mach)
1194 case bfd_mach_h8300:
1198 set_gdbarch_num_regs (gdbarch, 13);
1199 set_gdbarch_num_pseudo_regs (gdbarch, 1);
1200 set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
1201 set_gdbarch_dwarf_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
1202 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
1203 set_gdbarch_stab_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
1204 set_gdbarch_register_name (gdbarch, h8300_register_name);
1205 set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1206 set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1207 set_gdbarch_extract_return_value (gdbarch, h8300_extract_return_value);
1208 set_gdbarch_store_return_value (gdbarch, h8300_store_return_value);
1209 set_gdbarch_print_insn (gdbarch, print_insn_h8300);
1211 case bfd_mach_h8300h:
1212 case bfd_mach_h8300hn:
1216 set_gdbarch_num_regs (gdbarch, 13);
1217 set_gdbarch_num_pseudo_regs (gdbarch, 1);
1218 set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
1219 set_gdbarch_dwarf_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
1220 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
1221 set_gdbarch_stab_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
1222 set_gdbarch_register_name (gdbarch, h8300_register_name);
1223 if(info.bfd_arch_info->mach != bfd_mach_h8300hn)
1225 h8300_normal_mode = 0;
1226 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1227 set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1231 h8300_normal_mode = 1;
1232 set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1233 set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1235 set_gdbarch_extract_return_value (gdbarch, h8300h_extract_return_value);
1236 set_gdbarch_store_return_value (gdbarch, h8300h_store_return_value);
1237 set_gdbarch_print_insn (gdbarch, print_insn_h8300h);
1239 case bfd_mach_h8300s:
1240 case bfd_mach_h8300sn:
1244 set_gdbarch_num_regs (gdbarch, 16);
1245 set_gdbarch_num_pseudo_regs (gdbarch, 2);
1246 set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
1247 set_gdbarch_dwarf_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
1248 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
1249 set_gdbarch_stab_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
1250 set_gdbarch_register_name (gdbarch, h8300s_register_name);
1251 if(info.bfd_arch_info->mach != bfd_mach_h8300sn)
1253 h8300_normal_mode = 0;
1254 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1255 set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1259 h8300_normal_mode = 1;
1260 set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1261 set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1263 set_gdbarch_extract_return_value (gdbarch, h8300h_extract_return_value);
1264 set_gdbarch_store_return_value (gdbarch, h8300h_store_return_value);
1265 set_gdbarch_print_insn (gdbarch, print_insn_h8300s);
1267 case bfd_mach_h8300sx:
1268 case bfd_mach_h8300sxn:
1272 set_gdbarch_num_regs (gdbarch, 18);
1273 set_gdbarch_num_pseudo_regs (gdbarch, 2);
1274 set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
1275 set_gdbarch_dwarf_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
1276 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
1277 set_gdbarch_stab_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
1278 set_gdbarch_register_name (gdbarch, h8300sx_register_name);
1279 if(info.bfd_arch_info->mach != bfd_mach_h8300sxn)
1281 h8300_normal_mode = 0;
1282 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1283 set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1287 h8300_normal_mode = 1;
1288 set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1289 set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1291 set_gdbarch_extract_return_value (gdbarch, h8300h_extract_return_value);
1292 set_gdbarch_store_return_value (gdbarch, h8300h_store_return_value);
1293 set_gdbarch_print_insn (gdbarch, print_insn_h8300s);
1297 set_gdbarch_pseudo_register_read (gdbarch, h8300_pseudo_register_read);
1298 set_gdbarch_pseudo_register_write (gdbarch, h8300_pseudo_register_write);
1300 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
1301 ready to unwind the PC first (see frame.c:get_prev_frame()). */
1302 set_gdbarch_deprecated_init_frame_pc (gdbarch, deprecated_init_frame_pc_default);
1305 * Basic register fields and methods.
1308 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
1309 set_gdbarch_deprecated_fp_regnum (gdbarch, E_FP_REGNUM);
1310 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
1311 set_gdbarch_register_type (gdbarch, h8300_register_type);
1312 set_gdbarch_print_registers_info (gdbarch, h8300_print_registers_info);
1313 set_gdbarch_print_float_info (gdbarch, h8300_print_float_info);
1318 set_gdbarch_skip_prologue (gdbarch, h8300_skip_prologue);
1320 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch,
1321 h8300_frame_init_saved_regs);
1322 set_gdbarch_deprecated_init_extra_frame_info (gdbarch,
1323 h8300_init_extra_frame_info);
1324 set_gdbarch_deprecated_frame_chain (gdbarch, h8300_frame_chain);
1325 set_gdbarch_deprecated_saved_pc_after_call (gdbarch,
1326 h8300_saved_pc_after_call);
1327 set_gdbarch_deprecated_frame_saved_pc (gdbarch, h8300_frame_saved_pc);
1328 set_gdbarch_deprecated_pop_frame (gdbarch, h8300_pop_frame);
1333 /* Stack grows up. */
1334 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1335 /* PC stops zero byte after a trap instruction
1336 (which means: exactly on trap instruction). */
1337 set_gdbarch_decr_pc_after_break (gdbarch, 0);
1338 /* This value is almost never non-zero... */
1339 set_gdbarch_function_start_offset (gdbarch, 0);
1340 /* This value is almost never non-zero... */
1341 set_gdbarch_frame_args_skip (gdbarch, 0);
1342 set_gdbarch_frameless_function_invocation (gdbarch,
1343 frameless_look_for_prologue);
1345 set_gdbarch_extract_struct_value_address (gdbarch,
1346 h8300_extract_struct_value_address);
1347 set_gdbarch_use_struct_convention (gdbarch, always_use_struct_convention);
1348 set_gdbarch_breakpoint_from_pc (gdbarch, h8300_breakpoint_from_pc);
1349 set_gdbarch_push_dummy_code (gdbarch, h8300_push_dummy_code);
1350 set_gdbarch_push_dummy_call (gdbarch, h8300_push_dummy_call);
1352 set_gdbarch_int_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1353 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1354 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
1355 set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1356 set_gdbarch_long_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1358 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
1360 /* Char is unsigned. */
1361 set_gdbarch_char_signed (gdbarch, 0);
1366 extern initialize_file_ftype _initialize_h8300_tdep; /* -Wmissing-prototypes */
1369 _initialize_h8300_tdep (void)
1371 register_gdbarch_init (bfd_arch_h8300, h8300_gdbarch_init);