1 /* Target-dependent code for the IQ2000 architecture, for GDB, the GNU
4 Copyright (C) 2000, 2004, 2005, 2007 Free Software Foundation, Inc.
6 Contributed by Red Hat.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "frame-base.h"
26 #include "frame-unwind.h"
27 #include "dwarf2-frame.h"
31 #include "gdb_string.h"
32 #include "arch-utils.h"
39 E_R0_REGNUM
, E_R1_REGNUM
, E_R2_REGNUM
, E_R3_REGNUM
,
40 E_R4_REGNUM
, E_R5_REGNUM
, E_R6_REGNUM
, E_R7_REGNUM
,
41 E_R8_REGNUM
, E_R9_REGNUM
, E_R10_REGNUM
, E_R11_REGNUM
,
42 E_R12_REGNUM
, E_R13_REGNUM
, E_R14_REGNUM
, E_R15_REGNUM
,
43 E_R16_REGNUM
, E_R17_REGNUM
, E_R18_REGNUM
, E_R19_REGNUM
,
44 E_R20_REGNUM
, E_R21_REGNUM
, E_R22_REGNUM
, E_R23_REGNUM
,
45 E_R24_REGNUM
, E_R25_REGNUM
, E_R26_REGNUM
, E_R27_REGNUM
,
46 E_R28_REGNUM
, E_R29_REGNUM
, E_R30_REGNUM
, E_R31_REGNUM
,
48 E_LR_REGNUM
= E_R31_REGNUM
, /* Link register. */
49 E_SP_REGNUM
= E_R29_REGNUM
, /* Stack pointer. */
50 E_FP_REGNUM
= E_R27_REGNUM
, /* Frame pointer. */
51 E_FN_RETURN_REGNUM
= E_R2_REGNUM
, /* Function return value register. */
52 E_1ST_ARGREG
= E_R4_REGNUM
, /* 1st function arg register. */
53 E_LAST_ARGREG
= E_R11_REGNUM
, /* Last function arg register. */
54 E_NUM_REGS
= E_PC_REGNUM
+ 1
57 /* Use an invalid address value as 'not available' marker. */
58 enum { REG_UNAVAIL
= (CORE_ADDR
) -1 };
60 struct iq2000_frame_cache
68 CORE_ADDR saved_regs
[E_NUM_REGS
];
71 /* Harvard methods: */
74 insn_ptr_from_addr (CORE_ADDR addr
) /* CORE_ADDR to target pointer. */
76 return addr
& 0x7fffffffL
;
80 insn_addr_from_ptr (CORE_ADDR ptr
) /* target_pointer to CORE_ADDR. */
82 return (ptr
& 0x7fffffffL
) | 0x80000000L
;
85 /* Function: pointer_to_address
86 Convert a target pointer to an address in host (CORE_ADDR) format. */
89 iq2000_pointer_to_address (struct type
* type
, const void * buf
)
91 enum type_code target
= TYPE_CODE (TYPE_TARGET_TYPE (type
));
92 CORE_ADDR addr
= extract_unsigned_integer (buf
, TYPE_LENGTH (type
));
94 if (target
== TYPE_CODE_FUNC
95 || target
== TYPE_CODE_METHOD
96 || (TYPE_FLAGS (TYPE_TARGET_TYPE (type
)) & TYPE_FLAG_CODE_SPACE
) != 0)
97 addr
= insn_addr_from_ptr (addr
);
102 /* Function: address_to_pointer
103 Convert a host-format address (CORE_ADDR) into a target pointer. */
106 iq2000_address_to_pointer (struct type
*type
, void *buf
, CORE_ADDR addr
)
108 enum type_code target
= TYPE_CODE (TYPE_TARGET_TYPE (type
));
110 if (target
== TYPE_CODE_FUNC
|| target
== TYPE_CODE_METHOD
)
111 addr
= insn_ptr_from_addr (addr
);
112 store_unsigned_integer (buf
, TYPE_LENGTH (type
), addr
);
115 /* Real register methods: */
117 /* Function: register_name
118 Returns the name of the iq2000 register number N. */
121 iq2000_register_name (int regnum
)
123 static const char * names
[E_NUM_REGS
] =
125 "r0", "r1", "r2", "r3", "r4",
126 "r5", "r6", "r7", "r8", "r9",
127 "r10", "r11", "r12", "r13", "r14",
128 "r15", "r16", "r17", "r18", "r19",
129 "r20", "r21", "r22", "r23", "r24",
130 "r25", "r26", "r27", "r28", "r29",
134 if (regnum
< 0 || regnum
>= E_NUM_REGS
)
136 return names
[regnum
];
139 /* Prologue analysis methods: */
141 /* ADDIU insn (001001 rs(5) rt(5) imm(16)). */
142 #define INSN_IS_ADDIU(X) (((X) & 0xfc000000) == 0x24000000)
143 #define ADDIU_REG_SRC(X) (((X) & 0x03e00000) >> 21)
144 #define ADDIU_REG_TGT(X) (((X) & 0x001f0000) >> 16)
145 #define ADDIU_IMMEDIATE(X) ((signed short) ((X) & 0x0000ffff))
147 /* "MOVE" (OR) insn (000000 rs(5) rt(5) rd(5) 00000 100101). */
148 #define INSN_IS_MOVE(X) (((X) & 0xffe007ff) == 0x00000025)
149 #define MOVE_REG_SRC(X) (((X) & 0x001f0000) >> 16)
150 #define MOVE_REG_TGT(X) (((X) & 0x0000f800) >> 11)
152 /* STORE WORD insn (101011 rs(5) rt(5) offset(16)). */
153 #define INSN_IS_STORE_WORD(X) (((X) & 0xfc000000) == 0xac000000)
154 #define SW_REG_INDEX(X) (((X) & 0x03e00000) >> 21)
155 #define SW_REG_SRC(X) (((X) & 0x001f0000) >> 16)
156 #define SW_OFFSET(X) ((signed short) ((X) & 0x0000ffff))
158 /* Function: find_last_line_symbol
160 Given an address range, first find a line symbol corresponding to
161 the starting address. Then find the last line symbol within the
162 range that has a line number less than or equal to the first line.
164 For optimized code with code motion, this finds the last address
165 for the lowest-numbered line within the address range. */
167 static struct symtab_and_line
168 find_last_line_symbol (CORE_ADDR start
, CORE_ADDR end
, int notcurrent
)
170 struct symtab_and_line sal
= find_pc_line (start
, notcurrent
);
171 struct symtab_and_line best_sal
= sal
;
173 if (sal
.pc
== 0 || sal
.line
== 0 || sal
.end
== 0)
178 if (sal
.line
&& sal
.line
<= best_sal
.line
)
180 sal
= find_pc_line (sal
.end
, notcurrent
);
182 while (sal
.pc
&& sal
.pc
< end
);
187 /* Function: scan_prologue
188 Decode the instructions within the given address range.
189 Decide when we must have reached the end of the function prologue.
190 If a frame_info pointer is provided, fill in its prologue information.
192 Returns the address of the first instruction after the prologue. */
195 iq2000_scan_prologue (CORE_ADDR scan_start
,
197 struct frame_info
*fi
,
198 struct iq2000_frame_cache
*cache
)
200 struct symtab_and_line sal
;
203 int found_store_lr
= 0;
204 int found_decr_sp
= 0;
209 if (scan_end
== (CORE_ADDR
) 0)
211 loop_end
= scan_start
+ 100;
212 sal
.end
= sal
.pc
= 0;
218 sal
= find_last_line_symbol (scan_start
, scan_end
, 0);
222 We first have to save the saved register's offset, and
223 only later do we compute its actual address. Since the
224 offset can be zero, we must first initialize all the
225 saved regs to minus one (so we can later distinguish
226 between one that's not saved, and one that's saved at zero). */
227 for (srcreg
= 0; srcreg
< E_NUM_REGS
; srcreg
++)
228 cache
->saved_regs
[srcreg
] = -1;
230 cache
->framesize
= 0;
232 for (pc
= scan_start
; pc
< loop_end
; pc
+= 4)
234 LONGEST insn
= read_memory_unsigned_integer (pc
, 4);
235 /* Skip any instructions writing to (sp) or decrementing the
237 if ((insn
& 0xffe00000) == 0xac200000)
239 /* sw using SP/%1 as base. */
240 /* LEGACY -- from assembly-only port. */
241 tgtreg
= ((insn
>> 16) & 0x1f);
242 if (tgtreg
>= 0 && tgtreg
< E_NUM_REGS
)
243 cache
->saved_regs
[tgtreg
] = -((signed short) (insn
& 0xffff));
245 if (tgtreg
== E_LR_REGNUM
)
250 if ((insn
& 0xffff8000) == 0x20218000)
252 /* addi %1, %1, -N == addi %sp, %sp, -N */
253 /* LEGACY -- from assembly-only port */
255 cache
->framesize
= -((signed short) (insn
& 0xffff));
259 if (INSN_IS_ADDIU (insn
))
261 srcreg
= ADDIU_REG_SRC (insn
);
262 tgtreg
= ADDIU_REG_TGT (insn
);
263 offset
= ADDIU_IMMEDIATE (insn
);
264 if (srcreg
== E_SP_REGNUM
&& tgtreg
== E_SP_REGNUM
)
265 cache
->framesize
= -offset
;
269 if (INSN_IS_STORE_WORD (insn
))
271 srcreg
= SW_REG_SRC (insn
);
272 tgtreg
= SW_REG_INDEX (insn
);
273 offset
= SW_OFFSET (insn
);
275 if (tgtreg
== E_SP_REGNUM
|| tgtreg
== E_FP_REGNUM
)
277 /* "push" to stack (via SP or FP reg) */
278 if (cache
->saved_regs
[srcreg
] == -1) /* Don't save twice. */
279 cache
->saved_regs
[srcreg
] = offset
;
284 if (INSN_IS_MOVE (insn
))
286 srcreg
= MOVE_REG_SRC (insn
);
287 tgtreg
= MOVE_REG_TGT (insn
);
289 if (srcreg
== E_SP_REGNUM
&& tgtreg
== E_FP_REGNUM
)
297 /* Unknown instruction encountered in frame. Bail out?
298 1) If we have a subsequent line symbol, we can keep going.
299 2) If not, we need to bail out and quit scanning instructions. */
301 if (fi
&& sal
.end
&& (pc
< sal
.end
)) /* Keep scanning. */
311 iq2000_init_frame_cache (struct iq2000_frame_cache
*cache
)
316 cache
->framesize
= 0;
319 for (i
= 0; i
< E_NUM_REGS
; i
++)
320 cache
->saved_regs
[i
] = -1;
323 /* Function: iq2000_skip_prologue
324 If the input address is in a function prologue,
325 returns the address of the end of the prologue;
326 else returns the input address.
328 Note: the input address is likely to be the function start,
329 since this function is mainly used for advancing a breakpoint
330 to the first line, or stepping to the first line when we have
331 stepped into a function call. */
334 iq2000_skip_prologue (CORE_ADDR pc
)
336 CORE_ADDR func_addr
= 0 , func_end
= 0;
338 if (find_pc_partial_function (pc
, NULL
, & func_addr
, & func_end
))
340 struct symtab_and_line sal
;
341 struct iq2000_frame_cache cache
;
343 /* Found a function. */
344 sal
= find_pc_line (func_addr
, 0);
345 if (sal
.end
&& sal
.end
< func_end
)
346 /* Found a line number, use it as end of prologue. */
349 /* No useable line symbol. Use prologue parsing method. */
350 iq2000_init_frame_cache (&cache
);
351 return iq2000_scan_prologue (func_addr
, func_end
, NULL
, &cache
);
354 /* No function symbol -- just return the PC. */
355 return (CORE_ADDR
) pc
;
358 static struct iq2000_frame_cache
*
359 iq2000_frame_cache (struct frame_info
*next_frame
, void **this_cache
)
361 struct iq2000_frame_cache
*cache
;
362 CORE_ADDR current_pc
;
368 cache
= FRAME_OBSTACK_ZALLOC (struct iq2000_frame_cache
);
369 iq2000_init_frame_cache (cache
);
372 cache
->base
= frame_unwind_register_unsigned (next_frame
, E_FP_REGNUM
);
373 //if (cache->base == 0)
376 current_pc
= frame_pc_unwind (next_frame
);
377 find_pc_partial_function (current_pc
, NULL
, &cache
->pc
, NULL
);
379 iq2000_scan_prologue (cache
->pc
, current_pc
, next_frame
, cache
);
380 if (!cache
->using_fp
)
381 cache
->base
= frame_unwind_register_unsigned (next_frame
, E_SP_REGNUM
);
383 cache
->saved_sp
= cache
->base
+ cache
->framesize
;
385 for (i
= 0; i
< E_NUM_REGS
; i
++)
386 if (cache
->saved_regs
[i
] != -1)
387 cache
->saved_regs
[i
] += cache
->base
;
393 iq2000_frame_prev_register (struct frame_info
*next_frame
, void **this_cache
,
394 int regnum
, int *optimizedp
,
395 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
396 int *realnump
, void *valuep
)
398 struct iq2000_frame_cache
*cache
= iq2000_frame_cache (next_frame
, this_cache
);
399 if (regnum
== E_SP_REGNUM
&& cache
->saved_sp
)
406 store_unsigned_integer (valuep
, 4, cache
->saved_sp
);
410 if (regnum
== E_PC_REGNUM
)
411 regnum
= E_LR_REGNUM
;
413 if (regnum
< E_NUM_REGS
&& cache
->saved_regs
[regnum
] != -1)
416 *lvalp
= lval_memory
;
417 *addrp
= cache
->saved_regs
[regnum
];
420 read_memory (*addrp
, valuep
, register_size (current_gdbarch
, regnum
));
425 *lvalp
= lval_register
;
429 frame_unwind_register (next_frame
, (*realnump
), valuep
);
433 iq2000_frame_this_id (struct frame_info
*next_frame
, void **this_cache
,
434 struct frame_id
*this_id
)
436 struct iq2000_frame_cache
*cache
= iq2000_frame_cache (next_frame
, this_cache
);
438 /* This marks the outermost frame. */
439 if (cache
->base
== 0)
442 *this_id
= frame_id_build (cache
->saved_sp
, cache
->pc
);
445 static const struct frame_unwind iq2000_frame_unwind
= {
447 iq2000_frame_this_id
,
448 iq2000_frame_prev_register
451 static const struct frame_unwind
*
452 iq2000_frame_sniffer (struct frame_info
*next_frame
)
454 return &iq2000_frame_unwind
;
458 iq2000_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
460 return frame_unwind_register_unsigned (next_frame
, E_SP_REGNUM
);
464 iq2000_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
466 return frame_unwind_register_unsigned (next_frame
, E_PC_REGNUM
);
469 static struct frame_id
470 iq2000_unwind_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
472 return frame_id_build (iq2000_unwind_sp (gdbarch
, next_frame
),
473 frame_pc_unwind (next_frame
));
477 iq2000_frame_base_address (struct frame_info
*next_frame
, void **this_cache
)
479 struct iq2000_frame_cache
*cache
= iq2000_frame_cache (next_frame
, this_cache
);
484 static const struct frame_base iq2000_frame_base
= {
485 &iq2000_frame_unwind
,
486 iq2000_frame_base_address
,
487 iq2000_frame_base_address
,
488 iq2000_frame_base_address
491 static const unsigned char *
492 iq2000_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
494 static const unsigned char big_breakpoint
[] = { 0x00, 0x00, 0x00, 0x0d };
495 static const unsigned char little_breakpoint
[] = { 0x0d, 0x00, 0x00, 0x00 };
497 if ((*pcptr
& 3) != 0)
498 error ("breakpoint_from_pc: invalid breakpoint address 0x%lx",
502 return (gdbarch_byte_order (current_gdbarch
)
503 == BFD_ENDIAN_BIG
) ? big_breakpoint
507 /* Target function return value methods: */
509 /* Function: store_return_value
510 Copy the function return value from VALBUF into the
511 proper location for a function return. */
514 iq2000_store_return_value (struct type
*type
, struct regcache
*regcache
,
517 int len
= TYPE_LENGTH (type
);
518 int regno
= E_FN_RETURN_REGNUM
;
523 int size
= len
% 4 ?: 4;
526 memcpy (buf
+ 4 - size
, valbuf
, size
);
527 regcache_raw_write (regcache
, regno
++, buf
);
529 valbuf
= ((char *) valbuf
) + size
;
533 /* Function: use_struct_convention
534 Returns non-zero if the given struct type will be returned using
535 a special convention, rather than the normal function return method. */
538 iq2000_use_struct_convention (struct type
*type
)
540 return ((TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
541 || (TYPE_CODE (type
) == TYPE_CODE_UNION
))
542 && TYPE_LENGTH (type
) > 8;
545 /* Function: extract_return_value
546 Copy the function's return value into VALBUF.
547 This function is called only in the context of "target function calls",
548 ie. when the debugger forces a function to be called in the child, and
549 when the debugger forces a function to return prematurely via the
553 iq2000_extract_return_value (struct type
*type
, struct regcache
*regcache
,
556 /* If the function's return value is 8 bytes or less, it is
557 returned in a register, and if larger than 8 bytes, it is
558 returned in a stack location which is pointed to by the same
560 CORE_ADDR return_buffer
;
561 int len
= TYPE_LENGTH (type
);
565 int regno
= E_FN_RETURN_REGNUM
;
567 /* Return values of <= 8 bytes are returned in
572 int size
= len
% 4 ?: 4;
574 /* By using store_unsigned_integer we avoid having to
575 do anything special for small big-endian values. */
576 regcache_cooked_read_unsigned (regcache
, regno
++, &tmp
);
577 store_unsigned_integer (valbuf
, size
, tmp
);
579 valbuf
= ((char *) valbuf
) + size
;
584 /* Return values > 8 bytes are returned in memory,
585 pointed to by FN_RETURN_REGNUM. */
586 regcache_cooked_read (regcache
, E_FN_RETURN_REGNUM
, & return_buffer
);
587 read_memory (return_buffer
, valbuf
, TYPE_LENGTH (type
));
591 static enum return_value_convention
592 iq2000_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
593 struct regcache
*regcache
,
594 void *readbuf
, const void *writebuf
)
596 if (iq2000_use_struct_convention (type
))
597 return RETURN_VALUE_STRUCT_CONVENTION
;
599 iq2000_store_return_value (type
, regcache
, writebuf
);
601 iq2000_extract_return_value (type
, regcache
, readbuf
);
602 return RETURN_VALUE_REGISTER_CONVENTION
;
605 /* Function: register_virtual_type
606 Returns the default type for register N. */
609 iq2000_register_type (struct gdbarch
*gdbarch
, int regnum
)
611 return builtin_type_int32
;
615 iq2000_frame_align (struct gdbarch
*ignore
, CORE_ADDR sp
)
617 /* This is the same frame alignment used by gcc. */
618 return ((sp
+ 7) & ~7);
621 /* Convenience function to check 8-byte types for being a scalar type
622 or a struct with only one long long or double member. */
624 iq2000_pass_8bytetype_by_address (struct type
*type
)
629 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
630 type
= TYPE_TARGET_TYPE (type
);
631 /* Non-struct and non-union types are always passed by value. */
632 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
633 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
635 /* Structs with more than 1 field are always passed by address. */
636 if (TYPE_NFIELDS (type
) != 1)
638 /* Get field type. */
639 ftype
= (TYPE_FIELDS (type
))[0].type
;
640 /* The field type must have size 8, otherwise pass by address. */
641 if (TYPE_LENGTH (ftype
) != 8)
643 /* Skip typedefs of field type. */
644 while (TYPE_CODE (ftype
) == TYPE_CODE_TYPEDEF
)
645 ftype
= TYPE_TARGET_TYPE (ftype
);
646 /* If field is int or float, pass by value. */
647 if (TYPE_CODE (ftype
) == TYPE_CODE_FLT
648 || TYPE_CODE (ftype
) == TYPE_CODE_INT
)
650 /* Everything else, pass by address. */
655 iq2000_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
656 struct regcache
*regcache
, CORE_ADDR bp_addr
,
657 int nargs
, struct value
**args
, CORE_ADDR sp
,
658 int struct_return
, CORE_ADDR struct_addr
)
663 int i
, argreg
, typelen
, slacklen
;
665 /* Used to copy struct arguments into the stack. */
666 CORE_ADDR struct_ptr
;
668 /* First determine how much stack space we will need. */
669 for (i
= 0, argreg
= E_1ST_ARGREG
+ (struct_return
!= 0); i
< nargs
; i
++)
671 type
= value_type (args
[i
]);
672 typelen
= TYPE_LENGTH (type
);
675 /* Scalars of up to 4 bytes,
676 structs of up to 4 bytes, and
678 if (argreg
<= E_LAST_ARGREG
)
683 else if (typelen
== 8 && !iq2000_pass_8bytetype_by_address (type
))
687 structs with a single field of long long or double. */
688 if (argreg
<= E_LAST_ARGREG
- 1)
690 /* 8-byte arg goes into a register pair
691 (must start with an even-numbered reg) */
692 if (((argreg
- E_1ST_ARGREG
) % 2) != 0)
698 argreg
= E_LAST_ARGREG
+ 1; /* no more argregs. */
699 /* 8-byte arg goes on stack, must be 8-byte aligned. */
700 stackspace
= ((stackspace
+ 7) & ~7);
706 /* Structs are passed as pointer to a copy of the struct.
707 So we need room on the stack for a copy of the struct
708 plus for the argument pointer. */
709 if (argreg
<= E_LAST_ARGREG
)
713 /* Care for 8-byte alignment of structs saved on stack. */
714 stackspace
+= ((typelen
+ 7) & ~7);
718 /* Now copy params, in ascending order, into their assigned location
719 (either in a register or on the stack). */
721 sp
-= (sp
% 8); /* align */
724 sp
-= (sp
% 8); /* align again */
727 argreg
= E_1ST_ARGREG
;
730 /* A function that returns a struct will consume one argreg to do so.
732 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_addr
);
735 for (i
= 0; i
< nargs
; i
++)
737 type
= value_type (args
[i
]);
738 typelen
= TYPE_LENGTH (type
);
739 val
= value_contents (args
[i
]);
742 /* Char, short, int, float, pointer, and structs <= four bytes. */
743 slacklen
= (4 - (typelen
% 4)) % 4;
744 memset (buf
, 0, sizeof (buf
));
745 memcpy (buf
+ slacklen
, val
, typelen
);
746 if (argreg
<= E_LAST_ARGREG
)
748 /* Passed in a register. */
749 regcache_raw_write (regcache
, argreg
++, buf
);
753 /* Passed on the stack. */
754 write_memory (sp
+ stackspace
, buf
, 4);
758 else if (typelen
== 8 && !iq2000_pass_8bytetype_by_address (type
))
760 /* (long long), (double), or struct consisting of
761 a single (long long) or (double). */
762 if (argreg
<= E_LAST_ARGREG
- 1)
764 /* 8-byte arg goes into a register pair
765 (must start with an even-numbered reg) */
766 if (((argreg
- E_1ST_ARGREG
) % 2) != 0)
768 regcache_raw_write (regcache
, argreg
++, val
);
769 regcache_raw_write (regcache
, argreg
++, val
+ 4);
773 /* 8-byte arg goes on stack, must be 8-byte aligned. */
774 argreg
= E_LAST_ARGREG
+ 1; /* no more argregs. */
775 stackspace
= ((stackspace
+ 7) & ~7);
776 write_memory (sp
+ stackspace
, val
, typelen
);
782 /* Store struct beginning at the upper end of the previously
783 computed stack space. Then store the address of the struct
784 using the usual rules for a 4 byte value. */
785 struct_ptr
-= ((typelen
+ 7) & ~7);
786 write_memory (struct_ptr
, val
, typelen
);
787 if (argreg
<= E_LAST_ARGREG
)
788 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_ptr
);
791 store_unsigned_integer (buf
, 4, struct_ptr
);
792 write_memory (sp
+ stackspace
, buf
, 4);
798 /* Store return address. */
799 regcache_cooked_write_unsigned (regcache
, E_LR_REGNUM
, bp_addr
);
801 /* Update stack pointer. */
802 regcache_cooked_write_unsigned (regcache
, E_SP_REGNUM
, sp
);
804 /* And that should do it. Return the new stack pointer. */
808 /* Function: gdbarch_init
809 Initializer function for the iq2000 gdbarch vector.
810 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
812 static struct gdbarch
*
813 iq2000_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
815 struct gdbarch
*gdbarch
;
817 /* Look up list for candidates - only one. */
818 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
820 return arches
->gdbarch
;
822 gdbarch
= gdbarch_alloc (&info
, NULL
);
824 set_gdbarch_num_regs (gdbarch
, E_NUM_REGS
);
825 set_gdbarch_num_pseudo_regs (gdbarch
, 0);
826 set_gdbarch_sp_regnum (gdbarch
, E_SP_REGNUM
);
827 set_gdbarch_pc_regnum (gdbarch
, E_PC_REGNUM
);
828 set_gdbarch_register_name (gdbarch
, iq2000_register_name
);
829 set_gdbarch_address_to_pointer (gdbarch
, iq2000_address_to_pointer
);
830 set_gdbarch_pointer_to_address (gdbarch
, iq2000_pointer_to_address
);
831 set_gdbarch_ptr_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
832 set_gdbarch_short_bit (gdbarch
, 2 * TARGET_CHAR_BIT
);
833 set_gdbarch_int_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
834 set_gdbarch_long_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
835 set_gdbarch_long_long_bit (gdbarch
, 8 * TARGET_CHAR_BIT
);
836 set_gdbarch_float_bit (gdbarch
, 4 * TARGET_CHAR_BIT
);
837 set_gdbarch_double_bit (gdbarch
, 8 * TARGET_CHAR_BIT
);
838 set_gdbarch_long_double_bit (gdbarch
, 8 * TARGET_CHAR_BIT
);
839 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
840 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
841 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_double
);
842 set_gdbarch_return_value (gdbarch
, iq2000_return_value
);
843 set_gdbarch_breakpoint_from_pc (gdbarch
, iq2000_breakpoint_from_pc
);
844 set_gdbarch_frame_args_skip (gdbarch
, 0);
845 set_gdbarch_skip_prologue (gdbarch
, iq2000_skip_prologue
);
846 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
847 set_gdbarch_print_insn (gdbarch
, print_insn_iq2000
);
848 set_gdbarch_register_type (gdbarch
, iq2000_register_type
);
849 set_gdbarch_frame_align (gdbarch
, iq2000_frame_align
);
850 set_gdbarch_unwind_sp (gdbarch
, iq2000_unwind_sp
);
851 set_gdbarch_unwind_pc (gdbarch
, iq2000_unwind_pc
);
852 set_gdbarch_unwind_dummy_id (gdbarch
, iq2000_unwind_dummy_id
);
853 frame_base_set_default (gdbarch
, &iq2000_frame_base
);
854 set_gdbarch_push_dummy_call (gdbarch
, iq2000_push_dummy_call
);
856 gdbarch_init_osabi (info
, gdbarch
);
858 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
859 frame_unwind_append_sniffer (gdbarch
, iq2000_frame_sniffer
);
864 /* Function: _initialize_iq2000_tdep
865 Initializer function for the iq2000 module.
866 Called by gdb at start-up. */
869 _initialize_iq2000_tdep (void)
871 register_gdbarch_init (bfd_arch_iq2000
, iq2000_gdbarch_init
);