Add translations for various sub-directories
[binutils-gdb.git] / gdb / iq2000-tdep.c
blob094f627e37bd1b511c6181c9f04113c5e1678784
1 /* Target-dependent code for the IQ2000 architecture, for GDB, the GNU
2 Debugger.
4 Copyright (C) 2000-2024 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/>. */
23 #include "extract-store-integer.h"
24 #include "frame.h"
25 #include "frame-base.h"
26 #include "frame-unwind.h"
27 #include "dwarf2/frame.h"
28 #include "gdbtypes.h"
29 #include "value.h"
30 #include "dis-asm.h"
31 #include "arch-utils.h"
32 #include "regcache.h"
33 #include "osabi.h"
34 #include "gdbcore.h"
36 enum gdb_regnum
38 E_R0_REGNUM, E_R1_REGNUM, E_R2_REGNUM, E_R3_REGNUM,
39 E_R4_REGNUM, E_R5_REGNUM, E_R6_REGNUM, E_R7_REGNUM,
40 E_R8_REGNUM, E_R9_REGNUM, E_R10_REGNUM, E_R11_REGNUM,
41 E_R12_REGNUM, E_R13_REGNUM, E_R14_REGNUM, E_R15_REGNUM,
42 E_R16_REGNUM, E_R17_REGNUM, E_R18_REGNUM, E_R19_REGNUM,
43 E_R20_REGNUM, E_R21_REGNUM, E_R22_REGNUM, E_R23_REGNUM,
44 E_R24_REGNUM, E_R25_REGNUM, E_R26_REGNUM, E_R27_REGNUM,
45 E_R28_REGNUM, E_R29_REGNUM, E_R30_REGNUM, E_R31_REGNUM,
46 E_PC_REGNUM,
47 E_LR_REGNUM = E_R31_REGNUM, /* Link register. */
48 E_SP_REGNUM = E_R29_REGNUM, /* Stack pointer. */
49 E_FP_REGNUM = E_R27_REGNUM, /* Frame pointer. */
50 E_FN_RETURN_REGNUM = E_R2_REGNUM, /* Function return value register. */
51 E_1ST_ARGREG = E_R4_REGNUM, /* 1st function arg register. */
52 E_LAST_ARGREG = E_R11_REGNUM, /* Last function arg register. */
53 E_NUM_REGS = E_PC_REGNUM + 1
56 /* Use an invalid address value as 'not available' marker. */
57 enum { REG_UNAVAIL = (CORE_ADDR) -1 };
59 struct iq2000_frame_cache
61 /* Base address. */
62 CORE_ADDR base;
63 CORE_ADDR pc;
64 LONGEST framesize;
65 int using_fp;
66 CORE_ADDR saved_sp;
67 CORE_ADDR saved_regs [E_NUM_REGS];
70 /* Harvard methods: */
72 static CORE_ADDR
73 insn_ptr_from_addr (CORE_ADDR addr) /* CORE_ADDR to target pointer. */
75 return addr & 0x7fffffffL;
78 static CORE_ADDR
79 insn_addr_from_ptr (CORE_ADDR ptr) /* target_pointer to CORE_ADDR. */
81 return (ptr & 0x7fffffffL) | 0x80000000L;
84 /* Function: pointer_to_address
85 Convert a target pointer to an address in host (CORE_ADDR) format. */
87 static CORE_ADDR
88 iq2000_pointer_to_address (struct gdbarch *gdbarch,
89 struct type * type, const gdb_byte * buf)
91 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
92 enum type_code target = type->target_type ()->code ();
93 CORE_ADDR addr
94 = extract_unsigned_integer (buf, type->length (), byte_order);
96 if (target == TYPE_CODE_FUNC
97 || target == TYPE_CODE_METHOD
98 || TYPE_CODE_SPACE (type->target_type ()))
99 addr = insn_addr_from_ptr (addr);
101 return addr;
104 /* Function: address_to_pointer
105 Convert a host-format address (CORE_ADDR) into a target pointer. */
107 static void
108 iq2000_address_to_pointer (struct gdbarch *gdbarch,
109 struct type *type, gdb_byte *buf, CORE_ADDR addr)
111 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
112 enum type_code target = type->target_type ()->code ();
114 if (target == TYPE_CODE_FUNC || target == TYPE_CODE_METHOD)
115 addr = insn_ptr_from_addr (addr);
116 store_unsigned_integer (buf, type->length (), byte_order, addr);
119 /* Real register methods: */
121 /* Function: register_name
122 Returns the name of the iq2000 register number N. */
124 static const char *
125 iq2000_register_name (struct gdbarch *gdbarch, int regnum)
127 static const char * names[E_NUM_REGS] =
129 "r0", "r1", "r2", "r3", "r4",
130 "r5", "r6", "r7", "r8", "r9",
131 "r10", "r11", "r12", "r13", "r14",
132 "r15", "r16", "r17", "r18", "r19",
133 "r20", "r21", "r22", "r23", "r24",
134 "r25", "r26", "r27", "r28", "r29",
135 "r30", "r31",
136 "pc"
138 static_assert (ARRAY_SIZE (names) == E_NUM_REGS);
139 return names[regnum];
142 /* Prologue analysis methods: */
144 /* ADDIU insn (001001 rs(5) rt(5) imm(16)). */
145 #define INSN_IS_ADDIU(X) (((X) & 0xfc000000) == 0x24000000)
146 #define ADDIU_REG_SRC(X) (((X) & 0x03e00000) >> 21)
147 #define ADDIU_REG_TGT(X) (((X) & 0x001f0000) >> 16)
148 #define ADDIU_IMMEDIATE(X) ((signed short) ((X) & 0x0000ffff))
150 /* "MOVE" (OR) insn (000000 rs(5) rt(5) rd(5) 00000 100101). */
151 #define INSN_IS_MOVE(X) (((X) & 0xffe007ff) == 0x00000025)
152 #define MOVE_REG_SRC(X) (((X) & 0x001f0000) >> 16)
153 #define MOVE_REG_TGT(X) (((X) & 0x0000f800) >> 11)
155 /* STORE WORD insn (101011 rs(5) rt(5) offset(16)). */
156 #define INSN_IS_STORE_WORD(X) (((X) & 0xfc000000) == 0xac000000)
157 #define SW_REG_INDEX(X) (((X) & 0x03e00000) >> 21)
158 #define SW_REG_SRC(X) (((X) & 0x001f0000) >> 16)
159 #define SW_OFFSET(X) ((signed short) ((X) & 0x0000ffff))
161 /* Function: find_last_line_symbol
163 Given an address range, first find a line symbol corresponding to
164 the starting address. Then find the last line symbol within the
165 range that has a line number less than or equal to the first line.
167 For optimized code with code motion, this finds the last address
168 for the lowest-numbered line within the address range. */
170 static struct symtab_and_line
171 find_last_line_symbol (CORE_ADDR start, CORE_ADDR end, int notcurrent)
173 struct symtab_and_line sal = find_pc_line (start, notcurrent);
174 struct symtab_and_line best_sal = sal;
176 if (sal.pc == 0 || sal.line == 0 || sal.end == 0)
177 return sal;
181 if (sal.line && sal.line <= best_sal.line)
182 best_sal = sal;
183 sal = find_pc_line (sal.end, notcurrent);
185 while (sal.pc && sal.pc < end);
187 return best_sal;
190 /* Function: scan_prologue
191 Decode the instructions within the given address range.
192 Decide when we must have reached the end of the function prologue.
193 If a frame_info pointer is provided, fill in its prologue information.
195 Returns the address of the first instruction after the prologue. */
197 static CORE_ADDR
198 iq2000_scan_prologue (struct gdbarch *gdbarch,
199 CORE_ADDR scan_start,
200 CORE_ADDR scan_end,
201 const frame_info_ptr &fi,
202 struct iq2000_frame_cache *cache)
204 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
205 struct symtab_and_line sal;
206 CORE_ADDR pc;
207 CORE_ADDR loop_end;
208 int srcreg;
209 int tgtreg;
210 signed short offset;
212 if (scan_end == (CORE_ADDR) 0)
214 loop_end = scan_start + 100;
215 sal.end = sal.pc = 0;
217 else
219 loop_end = scan_end;
220 if (fi)
221 sal = find_last_line_symbol (scan_start, scan_end, 0);
222 else
223 sal.end = 0; /* Avoid GCC false warning. */
226 /* Saved registers:
227 We first have to save the saved register's offset, and
228 only later do we compute its actual address. Since the
229 offset can be zero, we must first initialize all the
230 saved regs to minus one (so we can later distinguish
231 between one that's not saved, and one that's saved at zero). */
232 for (srcreg = 0; srcreg < E_NUM_REGS; srcreg ++)
233 cache->saved_regs[srcreg] = -1;
234 cache->using_fp = 0;
235 cache->framesize = 0;
237 for (pc = scan_start; pc < loop_end; pc += 4)
239 LONGEST insn = read_memory_unsigned_integer (pc, 4, byte_order);
240 /* Skip any instructions writing to (sp) or decrementing the
241 SP. */
242 if ((insn & 0xffe00000) == 0xac200000)
244 /* sw using SP/%1 as base. */
245 /* LEGACY -- from assembly-only port. */
246 tgtreg = ((insn >> 16) & 0x1f);
247 if (tgtreg >= 0 && tgtreg < E_NUM_REGS)
248 cache->saved_regs[tgtreg] = -((signed short) (insn & 0xffff));
250 continue;
253 if ((insn & 0xffff8000) == 0x20218000)
255 /* addi %1, %1, -N == addi %sp, %sp, -N */
256 /* LEGACY -- from assembly-only port. */
257 cache->framesize = -((signed short) (insn & 0xffff));
258 continue;
261 if (INSN_IS_ADDIU (insn))
263 srcreg = ADDIU_REG_SRC (insn);
264 tgtreg = ADDIU_REG_TGT (insn);
265 offset = ADDIU_IMMEDIATE (insn);
266 if (srcreg == E_SP_REGNUM && tgtreg == E_SP_REGNUM)
267 cache->framesize = -offset;
268 continue;
271 if (INSN_IS_STORE_WORD (insn))
273 srcreg = SW_REG_SRC (insn);
274 tgtreg = SW_REG_INDEX (insn);
275 offset = SW_OFFSET (insn);
277 if (tgtreg == E_SP_REGNUM || tgtreg == E_FP_REGNUM)
279 /* "push" to stack (via SP or FP reg). */
280 if (cache->saved_regs[srcreg] == -1) /* Don't save twice. */
281 cache->saved_regs[srcreg] = offset;
282 continue;
286 if (INSN_IS_MOVE (insn))
288 srcreg = MOVE_REG_SRC (insn);
289 tgtreg = MOVE_REG_TGT (insn);
291 if (srcreg == E_SP_REGNUM && tgtreg == E_FP_REGNUM)
293 /* Copy sp to fp. */
294 cache->using_fp = 1;
295 continue;
299 /* Unknown instruction encountered in frame. Bail out?
300 1) If we have a subsequent line symbol, we can keep going.
301 2) If not, we need to bail out and quit scanning instructions. */
303 if (fi && sal.end && (pc < sal.end)) /* Keep scanning. */
304 continue;
305 else /* bail */
306 break;
309 return pc;
312 static void
313 iq2000_init_frame_cache (struct iq2000_frame_cache *cache)
315 int i;
317 cache->base = 0;
318 cache->framesize = 0;
319 cache->using_fp = 0;
320 cache->saved_sp = 0;
321 for (i = 0; i < E_NUM_REGS; i++)
322 cache->saved_regs[i] = -1;
325 /* Function: iq2000_skip_prologue
326 If the input address is in a function prologue,
327 returns the address of the end of the prologue;
328 else returns the input address.
330 Note: the input address is likely to be the function start,
331 since this function is mainly used for advancing a breakpoint
332 to the first line, or stepping to the first line when we have
333 stepped into a function call. */
335 static CORE_ADDR
336 iq2000_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
338 CORE_ADDR func_addr = 0 , func_end = 0;
340 if (find_pc_partial_function (pc, NULL, & func_addr, & func_end))
342 struct symtab_and_line sal;
343 struct iq2000_frame_cache cache;
345 /* Found a function. */
346 sal = find_pc_line (func_addr, 0);
347 if (sal.end && sal.end < func_end)
348 /* Found a line number, use it as end of prologue. */
349 return sal.end;
351 /* No useable line symbol. Use prologue parsing method. */
352 iq2000_init_frame_cache (&cache);
353 return iq2000_scan_prologue (gdbarch, func_addr, func_end, NULL, &cache);
356 /* No function symbol -- just return the PC. */
357 return (CORE_ADDR) pc;
360 static struct iq2000_frame_cache *
361 iq2000_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
363 struct gdbarch *gdbarch = get_frame_arch (this_frame);
364 struct iq2000_frame_cache *cache;
365 CORE_ADDR current_pc;
366 int i;
368 if (*this_cache)
369 return (struct iq2000_frame_cache *) *this_cache;
371 cache = FRAME_OBSTACK_ZALLOC (struct iq2000_frame_cache);
372 iq2000_init_frame_cache (cache);
373 *this_cache = cache;
375 cache->base = get_frame_register_unsigned (this_frame, E_FP_REGNUM);
377 current_pc = get_frame_pc (this_frame);
378 find_pc_partial_function (current_pc, NULL, &cache->pc, NULL);
379 if (cache->pc != 0)
380 iq2000_scan_prologue (gdbarch, cache->pc, current_pc, this_frame, cache);
381 if (!cache->using_fp)
382 cache->base = get_frame_register_unsigned (this_frame, E_SP_REGNUM);
384 cache->saved_sp = cache->base + cache->framesize;
386 for (i = 0; i < E_NUM_REGS; i++)
387 if (cache->saved_regs[i] != -1)
388 cache->saved_regs[i] += cache->base;
390 return cache;
393 static struct value *
394 iq2000_frame_prev_register (const frame_info_ptr &this_frame, void **this_cache,
395 int regnum)
397 struct iq2000_frame_cache *cache = iq2000_frame_cache (this_frame,
398 this_cache);
400 if (regnum == E_SP_REGNUM && cache->saved_sp)
401 return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
403 if (regnum == E_PC_REGNUM)
404 regnum = E_LR_REGNUM;
406 if (regnum < E_NUM_REGS && cache->saved_regs[regnum] != -1)
407 return frame_unwind_got_memory (this_frame, regnum,
408 cache->saved_regs[regnum]);
410 return frame_unwind_got_register (this_frame, regnum, regnum);
413 static void
414 iq2000_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
415 struct frame_id *this_id)
417 struct iq2000_frame_cache *cache = iq2000_frame_cache (this_frame,
418 this_cache);
420 /* This marks the outermost frame. */
421 if (cache->base == 0)
422 return;
424 *this_id = frame_id_build (cache->saved_sp, cache->pc);
427 static const struct frame_unwind_legacy iq2000_frame_unwind (
428 "iq2000 prologue",
429 NORMAL_FRAME,
430 FRAME_UNWIND_ARCH,
431 default_frame_unwind_stop_reason,
432 iq2000_frame_this_id,
433 iq2000_frame_prev_register,
434 NULL,
435 default_frame_sniffer
438 static CORE_ADDR
439 iq2000_frame_base_address (const frame_info_ptr &this_frame, void **this_cache)
441 struct iq2000_frame_cache *cache = iq2000_frame_cache (this_frame,
442 this_cache);
444 return cache->base;
447 static const struct frame_base iq2000_frame_base = {
448 &iq2000_frame_unwind,
449 iq2000_frame_base_address,
450 iq2000_frame_base_address,
451 iq2000_frame_base_address
454 static int
455 iq2000_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
457 if ((*pcptr & 3) != 0)
458 error (_("breakpoint_from_pc: invalid breakpoint address 0x%lx"),
459 (long) *pcptr);
461 return 4;
464 static const gdb_byte *
465 iq2000_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
467 static const unsigned char big_breakpoint[] = { 0x00, 0x00, 0x00, 0x0d };
468 static const unsigned char little_breakpoint[] = { 0x0d, 0x00, 0x00, 0x00 };
469 *size = kind;
471 return (gdbarch_byte_order (gdbarch)
472 == BFD_ENDIAN_BIG) ? big_breakpoint : little_breakpoint;
475 /* Target function return value methods: */
477 /* Function: store_return_value
478 Copy the function return value from VALBUF into the
479 proper location for a function return. */
481 static void
482 iq2000_store_return_value (struct type *type, struct regcache *regcache,
483 const void *valbuf)
485 int len = type->length ();
486 int regno = E_FN_RETURN_REGNUM;
488 while (len > 0)
490 gdb_byte buf[4];
491 int size = len % 4 ?: 4;
493 memset (buf, 0, 4);
494 memcpy (buf + 4 - size, valbuf, size);
495 regcache->raw_write (regno++, buf);
496 len -= size;
497 valbuf = ((char *) valbuf) + size;
501 /* Function: use_struct_convention
502 Returns non-zero if the given struct type will be returned using
503 a special convention, rather than the normal function return method. */
505 static int
506 iq2000_use_struct_convention (struct type *type)
508 return ((type->code () == TYPE_CODE_STRUCT)
509 || (type->code () == TYPE_CODE_UNION))
510 && type->length () > 8;
513 /* Function: extract_return_value
514 Copy the function's return value into VALBUF.
515 This function is called only in the context of "target function calls",
516 ie. when the debugger forces a function to be called in the child, and
517 when the debugger forces a function to return prematurely via the
518 "return" command. */
520 static void
521 iq2000_extract_return_value (struct type *type, struct regcache *regcache,
522 gdb_byte *valbuf)
524 struct gdbarch *gdbarch = regcache->arch ();
525 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
527 /* If the function's return value is 8 bytes or less, it is
528 returned in a register, and if larger than 8 bytes, it is
529 returned in a stack location which is pointed to by the same
530 register. */
531 int len = type->length ();
533 if (len <= (2 * 4))
535 int regno = E_FN_RETURN_REGNUM;
537 /* Return values of <= 8 bytes are returned in
538 FN_RETURN_REGNUM. */
539 while (len > 0)
541 ULONGEST tmp;
542 int size = len % 4 ?: 4;
544 /* By using store_unsigned_integer we avoid having to
545 do anything special for small big-endian values. */
546 regcache_cooked_read_unsigned (regcache, regno++, &tmp);
547 store_unsigned_integer (valbuf, size, byte_order, tmp);
548 len -= size;
549 valbuf += size;
552 else
554 /* Return values > 8 bytes are returned in memory,
555 pointed to by FN_RETURN_REGNUM. */
556 ULONGEST return_buffer;
557 regcache_cooked_read_unsigned (regcache, E_FN_RETURN_REGNUM,
558 &return_buffer);
559 read_memory (return_buffer, valbuf, type->length ());
563 static enum return_value_convention
564 iq2000_return_value (struct gdbarch *gdbarch, struct value *function,
565 struct type *type, struct regcache *regcache,
566 gdb_byte *readbuf, const gdb_byte *writebuf)
568 if (iq2000_use_struct_convention (type))
569 return RETURN_VALUE_STRUCT_CONVENTION;
570 if (writebuf)
571 iq2000_store_return_value (type, regcache, writebuf);
572 else if (readbuf)
573 iq2000_extract_return_value (type, regcache, readbuf);
574 return RETURN_VALUE_REGISTER_CONVENTION;
577 /* Function: register_virtual_type
578 Returns the default type for register N. */
580 static struct type *
581 iq2000_register_type (struct gdbarch *gdbarch, int regnum)
583 return builtin_type (gdbarch)->builtin_int32;
586 static CORE_ADDR
587 iq2000_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
589 /* This is the same frame alignment used by gcc. */
590 return ((sp + 7) & ~7);
593 /* Convenience function to check 8-byte types for being a scalar type
594 or a struct with only one long long or double member. */
595 static int
596 iq2000_pass_8bytetype_by_address (struct type *type)
598 struct type *ftype;
600 /* Skip typedefs. */
601 while (type->code () == TYPE_CODE_TYPEDEF)
602 type = type->target_type ();
603 /* Non-struct and non-union types are always passed by value. */
604 if (type->code () != TYPE_CODE_STRUCT
605 && type->code () != TYPE_CODE_UNION)
606 return 0;
607 /* Structs with more than 1 field are always passed by address. */
608 if (type->num_fields () != 1)
609 return 1;
610 /* Get field type. */
611 ftype = type->field (0).type ();
612 /* The field type must have size 8, otherwise pass by address. */
613 if (ftype->length () != 8)
614 return 1;
615 /* Skip typedefs of field type. */
616 while (ftype->code () == TYPE_CODE_TYPEDEF)
617 ftype = ftype->target_type ();
618 /* If field is int or float, pass by value. */
619 if (ftype->code () == TYPE_CODE_FLT
620 || ftype->code () == TYPE_CODE_INT)
621 return 0;
622 /* Everything else, pass by address. */
623 return 1;
626 static CORE_ADDR
627 iq2000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
628 struct regcache *regcache, CORE_ADDR bp_addr,
629 int nargs, struct value **args, CORE_ADDR sp,
630 function_call_return_method return_method,
631 CORE_ADDR struct_addr)
633 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
634 const bfd_byte *val;
635 bfd_byte buf[4];
636 struct type *type;
637 int i, argreg, typelen, slacklen;
638 int stackspace = 0;
639 /* Used to copy struct arguments into the stack. */
640 CORE_ADDR struct_ptr;
642 /* First determine how much stack space we will need. */
643 for (i = 0, argreg = E_1ST_ARGREG + (return_method == return_method_struct);
644 i < nargs;
645 i++)
647 type = args[i]->type ();
648 typelen = type->length ();
649 if (typelen <= 4)
651 /* Scalars of up to 4 bytes,
652 structs of up to 4 bytes, and
653 pointers. */
654 if (argreg <= E_LAST_ARGREG)
655 argreg++;
656 else
657 stackspace += 4;
659 else if (typelen == 8 && !iq2000_pass_8bytetype_by_address (type))
661 /* long long,
662 double, and possibly
663 structs with a single field of long long or double. */
664 if (argreg <= E_LAST_ARGREG - 1)
666 /* 8-byte arg goes into a register pair
667 (must start with an even-numbered reg). */
668 if (((argreg - E_1ST_ARGREG) % 2) != 0)
669 argreg ++;
670 argreg += 2;
672 else
674 argreg = E_LAST_ARGREG + 1; /* no more argregs. */
675 /* 8-byte arg goes on stack, must be 8-byte aligned. */
676 stackspace = ((stackspace + 7) & ~7);
677 stackspace += 8;
680 else
682 /* Structs are passed as pointer to a copy of the struct.
683 So we need room on the stack for a copy of the struct
684 plus for the argument pointer. */
685 if (argreg <= E_LAST_ARGREG)
686 argreg++;
687 else
688 stackspace += 4;
689 /* Care for 8-byte alignment of structs saved on stack. */
690 stackspace += ((typelen + 7) & ~7);
694 /* Now copy params, in ascending order, into their assigned location
695 (either in a register or on the stack). */
697 sp -= (sp % 8); /* align */
698 struct_ptr = sp;
699 sp -= stackspace;
700 sp -= (sp % 8); /* align again */
701 stackspace = 0;
703 argreg = E_1ST_ARGREG;
704 if (return_method == return_method_struct)
706 /* A function that returns a struct will consume one argreg to do so.
708 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
711 for (i = 0; i < nargs; i++)
713 type = args[i]->type ();
714 typelen = type->length ();
715 val = args[i]->contents ().data ();
716 if (typelen <= 4)
718 /* Char, short, int, float, pointer, and structs <= four bytes. */
719 slacklen = (4 - (typelen % 4)) % 4;
720 memset (buf, 0, sizeof (buf));
721 memcpy (buf + slacklen, val, typelen);
722 if (argreg <= E_LAST_ARGREG)
724 /* Passed in a register. */
725 regcache->raw_write (argreg++, buf);
727 else
729 /* Passed on the stack. */
730 write_memory (sp + stackspace, buf, 4);
731 stackspace += 4;
734 else if (typelen == 8 && !iq2000_pass_8bytetype_by_address (type))
736 /* (long long), (double), or struct consisting of
737 a single (long long) or (double). */
738 if (argreg <= E_LAST_ARGREG - 1)
740 /* 8-byte arg goes into a register pair
741 (must start with an even-numbered reg). */
742 if (((argreg - E_1ST_ARGREG) % 2) != 0)
743 argreg++;
744 regcache->raw_write (argreg++, val);
745 regcache->raw_write (argreg++, val + 4);
747 else
749 /* 8-byte arg goes on stack, must be 8-byte aligned. */
750 argreg = E_LAST_ARGREG + 1; /* no more argregs. */
751 stackspace = ((stackspace + 7) & ~7);
752 write_memory (sp + stackspace, val, typelen);
753 stackspace += 8;
756 else
758 /* Store struct beginning at the upper end of the previously
759 computed stack space. Then store the address of the struct
760 using the usual rules for a 4 byte value. */
761 struct_ptr -= ((typelen + 7) & ~7);
762 write_memory (struct_ptr, val, typelen);
763 if (argreg <= E_LAST_ARGREG)
764 regcache_cooked_write_unsigned (regcache, argreg++, struct_ptr);
765 else
767 store_unsigned_integer (buf, 4, byte_order, struct_ptr);
768 write_memory (sp + stackspace, buf, 4);
769 stackspace += 4;
774 /* Store return address. */
775 regcache_cooked_write_unsigned (regcache, E_LR_REGNUM, bp_addr);
777 /* Update stack pointer. */
778 regcache_cooked_write_unsigned (regcache, E_SP_REGNUM, sp);
780 /* And that should do it. Return the new stack pointer. */
781 return sp;
784 /* Function: gdbarch_init
785 Initializer function for the iq2000 gdbarch vector.
786 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
788 static struct gdbarch *
789 iq2000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
791 struct gdbarch *gdbarch;
793 /* Look up list for candidates - only one. */
794 arches = gdbarch_list_lookup_by_info (arches, &info);
795 if (arches != NULL)
796 return arches->gdbarch;
798 gdbarch = gdbarch_alloc (&info, NULL);
800 set_gdbarch_num_regs (gdbarch, E_NUM_REGS);
801 set_gdbarch_num_pseudo_regs (gdbarch, 0);
802 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
803 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
804 set_gdbarch_register_name (gdbarch, iq2000_register_name);
805 set_gdbarch_address_to_pointer (gdbarch, iq2000_address_to_pointer);
806 set_gdbarch_pointer_to_address (gdbarch, iq2000_pointer_to_address);
807 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
808 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
809 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
810 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
811 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
812 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
813 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
814 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
815 set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
816 set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
817 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
818 set_gdbarch_return_value (gdbarch, iq2000_return_value);
819 set_gdbarch_breakpoint_kind_from_pc (gdbarch,
820 iq2000_breakpoint_kind_from_pc);
821 set_gdbarch_sw_breakpoint_from_kind (gdbarch,
822 iq2000_sw_breakpoint_from_kind);
823 set_gdbarch_frame_args_skip (gdbarch, 0);
824 set_gdbarch_skip_prologue (gdbarch, iq2000_skip_prologue);
825 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
826 set_gdbarch_register_type (gdbarch, iq2000_register_type);
827 set_gdbarch_frame_align (gdbarch, iq2000_frame_align);
828 frame_base_set_default (gdbarch, &iq2000_frame_base);
829 set_gdbarch_push_dummy_call (gdbarch, iq2000_push_dummy_call);
831 gdbarch_init_osabi (info, gdbarch);
833 dwarf2_append_unwinders (gdbarch);
834 frame_unwind_append_unwinder (gdbarch, &iq2000_frame_unwind);
836 return gdbarch;
839 /* Function: _initialize_iq2000_tdep
840 Initializer function for the iq2000 module.
841 Called by gdb at start-up. */
843 void _initialize_iq2000_tdep ();
844 void
845 _initialize_iq2000_tdep ()
847 gdbarch_register (bfd_arch_iq2000, iq2000_gdbarch_init);