GDB (API)
|
00001 /* Target-dependent code for the IQ2000 architecture, for GDB, the GNU 00002 Debugger. 00003 00004 Copyright (C) 2000-2013 Free Software Foundation, Inc. 00005 00006 Contributed by Red Hat. 00007 00008 This file is part of GDB. 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00022 00023 #include "defs.h" 00024 #include "frame.h" 00025 #include "frame-base.h" 00026 #include "frame-unwind.h" 00027 #include "dwarf2-frame.h" 00028 #include "gdbtypes.h" 00029 #include "value.h" 00030 #include "dis-asm.h" 00031 #include "gdb_string.h" 00032 #include "arch-utils.h" 00033 #include "regcache.h" 00034 #include "osabi.h" 00035 #include "gdbcore.h" 00036 00037 enum gdb_regnum 00038 { 00039 E_R0_REGNUM, E_R1_REGNUM, E_R2_REGNUM, E_R3_REGNUM, 00040 E_R4_REGNUM, E_R5_REGNUM, E_R6_REGNUM, E_R7_REGNUM, 00041 E_R8_REGNUM, E_R9_REGNUM, E_R10_REGNUM, E_R11_REGNUM, 00042 E_R12_REGNUM, E_R13_REGNUM, E_R14_REGNUM, E_R15_REGNUM, 00043 E_R16_REGNUM, E_R17_REGNUM, E_R18_REGNUM, E_R19_REGNUM, 00044 E_R20_REGNUM, E_R21_REGNUM, E_R22_REGNUM, E_R23_REGNUM, 00045 E_R24_REGNUM, E_R25_REGNUM, E_R26_REGNUM, E_R27_REGNUM, 00046 E_R28_REGNUM, E_R29_REGNUM, E_R30_REGNUM, E_R31_REGNUM, 00047 E_PC_REGNUM, 00048 E_LR_REGNUM = E_R31_REGNUM, /* Link register. */ 00049 E_SP_REGNUM = E_R29_REGNUM, /* Stack pointer. */ 00050 E_FP_REGNUM = E_R27_REGNUM, /* Frame pointer. */ 00051 E_FN_RETURN_REGNUM = E_R2_REGNUM, /* Function return value register. */ 00052 E_1ST_ARGREG = E_R4_REGNUM, /* 1st function arg register. */ 00053 E_LAST_ARGREG = E_R11_REGNUM, /* Last function arg register. */ 00054 E_NUM_REGS = E_PC_REGNUM + 1 00055 }; 00056 00057 /* Use an invalid address value as 'not available' marker. */ 00058 enum { REG_UNAVAIL = (CORE_ADDR) -1 }; 00059 00060 struct iq2000_frame_cache 00061 { 00062 /* Base address. */ 00063 CORE_ADDR base; 00064 CORE_ADDR pc; 00065 LONGEST framesize; 00066 int using_fp; 00067 CORE_ADDR saved_sp; 00068 CORE_ADDR saved_regs [E_NUM_REGS]; 00069 }; 00070 00071 /* Harvard methods: */ 00072 00073 static CORE_ADDR 00074 insn_ptr_from_addr (CORE_ADDR addr) /* CORE_ADDR to target pointer. */ 00075 { 00076 return addr & 0x7fffffffL; 00077 } 00078 00079 static CORE_ADDR 00080 insn_addr_from_ptr (CORE_ADDR ptr) /* target_pointer to CORE_ADDR. */ 00081 { 00082 return (ptr & 0x7fffffffL) | 0x80000000L; 00083 } 00084 00085 /* Function: pointer_to_address 00086 Convert a target pointer to an address in host (CORE_ADDR) format. */ 00087 00088 static CORE_ADDR 00089 iq2000_pointer_to_address (struct gdbarch *gdbarch, 00090 struct type * type, const gdb_byte * buf) 00091 { 00092 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00093 enum type_code target = TYPE_CODE (TYPE_TARGET_TYPE (type)); 00094 CORE_ADDR addr 00095 = extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order); 00096 00097 if (target == TYPE_CODE_FUNC 00098 || target == TYPE_CODE_METHOD 00099 || TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type))) 00100 addr = insn_addr_from_ptr (addr); 00101 00102 return addr; 00103 } 00104 00105 /* Function: address_to_pointer 00106 Convert a host-format address (CORE_ADDR) into a target pointer. */ 00107 00108 static void 00109 iq2000_address_to_pointer (struct gdbarch *gdbarch, 00110 struct type *type, gdb_byte *buf, CORE_ADDR addr) 00111 { 00112 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00113 enum type_code target = TYPE_CODE (TYPE_TARGET_TYPE (type)); 00114 00115 if (target == TYPE_CODE_FUNC || target == TYPE_CODE_METHOD) 00116 addr = insn_ptr_from_addr (addr); 00117 store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order, addr); 00118 } 00119 00120 /* Real register methods: */ 00121 00122 /* Function: register_name 00123 Returns the name of the iq2000 register number N. */ 00124 00125 static const char * 00126 iq2000_register_name (struct gdbarch *gdbarch, int regnum) 00127 { 00128 static const char * names[E_NUM_REGS] = 00129 { 00130 "r0", "r1", "r2", "r3", "r4", 00131 "r5", "r6", "r7", "r8", "r9", 00132 "r10", "r11", "r12", "r13", "r14", 00133 "r15", "r16", "r17", "r18", "r19", 00134 "r20", "r21", "r22", "r23", "r24", 00135 "r25", "r26", "r27", "r28", "r29", 00136 "r30", "r31", 00137 "pc" 00138 }; 00139 if (regnum < 0 || regnum >= E_NUM_REGS) 00140 return NULL; 00141 return names[regnum]; 00142 } 00143 00144 /* Prologue analysis methods: */ 00145 00146 /* ADDIU insn (001001 rs(5) rt(5) imm(16)). */ 00147 #define INSN_IS_ADDIU(X) (((X) & 0xfc000000) == 0x24000000) 00148 #define ADDIU_REG_SRC(X) (((X) & 0x03e00000) >> 21) 00149 #define ADDIU_REG_TGT(X) (((X) & 0x001f0000) >> 16) 00150 #define ADDIU_IMMEDIATE(X) ((signed short) ((X) & 0x0000ffff)) 00151 00152 /* "MOVE" (OR) insn (000000 rs(5) rt(5) rd(5) 00000 100101). */ 00153 #define INSN_IS_MOVE(X) (((X) & 0xffe007ff) == 0x00000025) 00154 #define MOVE_REG_SRC(X) (((X) & 0x001f0000) >> 16) 00155 #define MOVE_REG_TGT(X) (((X) & 0x0000f800) >> 11) 00156 00157 /* STORE WORD insn (101011 rs(5) rt(5) offset(16)). */ 00158 #define INSN_IS_STORE_WORD(X) (((X) & 0xfc000000) == 0xac000000) 00159 #define SW_REG_INDEX(X) (((X) & 0x03e00000) >> 21) 00160 #define SW_REG_SRC(X) (((X) & 0x001f0000) >> 16) 00161 #define SW_OFFSET(X) ((signed short) ((X) & 0x0000ffff)) 00162 00163 /* Function: find_last_line_symbol 00164 00165 Given an address range, first find a line symbol corresponding to 00166 the starting address. Then find the last line symbol within the 00167 range that has a line number less than or equal to the first line. 00168 00169 For optimized code with code motion, this finds the last address 00170 for the lowest-numbered line within the address range. */ 00171 00172 static struct symtab_and_line 00173 find_last_line_symbol (CORE_ADDR start, CORE_ADDR end, int notcurrent) 00174 { 00175 struct symtab_and_line sal = find_pc_line (start, notcurrent); 00176 struct symtab_and_line best_sal = sal; 00177 00178 if (sal.pc == 0 || sal.line == 0 || sal.end == 0) 00179 return sal; 00180 00181 do 00182 { 00183 if (sal.line && sal.line <= best_sal.line) 00184 best_sal = sal; 00185 sal = find_pc_line (sal.end, notcurrent); 00186 } 00187 while (sal.pc && sal.pc < end); 00188 00189 return best_sal; 00190 } 00191 00192 /* Function: scan_prologue 00193 Decode the instructions within the given address range. 00194 Decide when we must have reached the end of the function prologue. 00195 If a frame_info pointer is provided, fill in its prologue information. 00196 00197 Returns the address of the first instruction after the prologue. */ 00198 00199 static CORE_ADDR 00200 iq2000_scan_prologue (struct gdbarch *gdbarch, 00201 CORE_ADDR scan_start, 00202 CORE_ADDR scan_end, 00203 struct frame_info *fi, 00204 struct iq2000_frame_cache *cache) 00205 { 00206 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00207 struct symtab_and_line sal; 00208 CORE_ADDR pc; 00209 CORE_ADDR loop_end; 00210 int found_store_lr = 0; 00211 int found_decr_sp = 0; 00212 int srcreg; 00213 int tgtreg; 00214 signed short offset; 00215 00216 if (scan_end == (CORE_ADDR) 0) 00217 { 00218 loop_end = scan_start + 100; 00219 sal.end = sal.pc = 0; 00220 } 00221 else 00222 { 00223 loop_end = scan_end; 00224 if (fi) 00225 sal = find_last_line_symbol (scan_start, scan_end, 0); 00226 else 00227 sal.end = 0; /* Avoid GCC false warning. */ 00228 } 00229 00230 /* Saved registers: 00231 We first have to save the saved register's offset, and 00232 only later do we compute its actual address. Since the 00233 offset can be zero, we must first initialize all the 00234 saved regs to minus one (so we can later distinguish 00235 between one that's not saved, and one that's saved at zero). */ 00236 for (srcreg = 0; srcreg < E_NUM_REGS; srcreg ++) 00237 cache->saved_regs[srcreg] = -1; 00238 cache->using_fp = 0; 00239 cache->framesize = 0; 00240 00241 for (pc = scan_start; pc < loop_end; pc += 4) 00242 { 00243 LONGEST insn = read_memory_unsigned_integer (pc, 4, byte_order); 00244 /* Skip any instructions writing to (sp) or decrementing the 00245 SP. */ 00246 if ((insn & 0xffe00000) == 0xac200000) 00247 { 00248 /* sw using SP/%1 as base. */ 00249 /* LEGACY -- from assembly-only port. */ 00250 tgtreg = ((insn >> 16) & 0x1f); 00251 if (tgtreg >= 0 && tgtreg < E_NUM_REGS) 00252 cache->saved_regs[tgtreg] = -((signed short) (insn & 0xffff)); 00253 00254 if (tgtreg == E_LR_REGNUM) 00255 found_store_lr = 1; 00256 continue; 00257 } 00258 00259 if ((insn & 0xffff8000) == 0x20218000) 00260 { 00261 /* addi %1, %1, -N == addi %sp, %sp, -N */ 00262 /* LEGACY -- from assembly-only port. */ 00263 found_decr_sp = 1; 00264 cache->framesize = -((signed short) (insn & 0xffff)); 00265 continue; 00266 } 00267 00268 if (INSN_IS_ADDIU (insn)) 00269 { 00270 srcreg = ADDIU_REG_SRC (insn); 00271 tgtreg = ADDIU_REG_TGT (insn); 00272 offset = ADDIU_IMMEDIATE (insn); 00273 if (srcreg == E_SP_REGNUM && tgtreg == E_SP_REGNUM) 00274 cache->framesize = -offset; 00275 continue; 00276 } 00277 00278 if (INSN_IS_STORE_WORD (insn)) 00279 { 00280 srcreg = SW_REG_SRC (insn); 00281 tgtreg = SW_REG_INDEX (insn); 00282 offset = SW_OFFSET (insn); 00283 00284 if (tgtreg == E_SP_REGNUM || tgtreg == E_FP_REGNUM) 00285 { 00286 /* "push" to stack (via SP or FP reg). */ 00287 if (cache->saved_regs[srcreg] == -1) /* Don't save twice. */ 00288 cache->saved_regs[srcreg] = offset; 00289 continue; 00290 } 00291 } 00292 00293 if (INSN_IS_MOVE (insn)) 00294 { 00295 srcreg = MOVE_REG_SRC (insn); 00296 tgtreg = MOVE_REG_TGT (insn); 00297 00298 if (srcreg == E_SP_REGNUM && tgtreg == E_FP_REGNUM) 00299 { 00300 /* Copy sp to fp. */ 00301 cache->using_fp = 1; 00302 continue; 00303 } 00304 } 00305 00306 /* Unknown instruction encountered in frame. Bail out? 00307 1) If we have a subsequent line symbol, we can keep going. 00308 2) If not, we need to bail out and quit scanning instructions. */ 00309 00310 if (fi && sal.end && (pc < sal.end)) /* Keep scanning. */ 00311 continue; 00312 else /* bail */ 00313 break; 00314 } 00315 00316 return pc; 00317 } 00318 00319 static void 00320 iq2000_init_frame_cache (struct iq2000_frame_cache *cache) 00321 { 00322 int i; 00323 00324 cache->base = 0; 00325 cache->framesize = 0; 00326 cache->using_fp = 0; 00327 cache->saved_sp = 0; 00328 for (i = 0; i < E_NUM_REGS; i++) 00329 cache->saved_regs[i] = -1; 00330 } 00331 00332 /* Function: iq2000_skip_prologue 00333 If the input address is in a function prologue, 00334 returns the address of the end of the prologue; 00335 else returns the input address. 00336 00337 Note: the input address is likely to be the function start, 00338 since this function is mainly used for advancing a breakpoint 00339 to the first line, or stepping to the first line when we have 00340 stepped into a function call. */ 00341 00342 static CORE_ADDR 00343 iq2000_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 00344 { 00345 CORE_ADDR func_addr = 0 , func_end = 0; 00346 00347 if (find_pc_partial_function (pc, NULL, & func_addr, & func_end)) 00348 { 00349 struct symtab_and_line sal; 00350 struct iq2000_frame_cache cache; 00351 00352 /* Found a function. */ 00353 sal = find_pc_line (func_addr, 0); 00354 if (sal.end && sal.end < func_end) 00355 /* Found a line number, use it as end of prologue. */ 00356 return sal.end; 00357 00358 /* No useable line symbol. Use prologue parsing method. */ 00359 iq2000_init_frame_cache (&cache); 00360 return iq2000_scan_prologue (gdbarch, func_addr, func_end, NULL, &cache); 00361 } 00362 00363 /* No function symbol -- just return the PC. */ 00364 return (CORE_ADDR) pc; 00365 } 00366 00367 static struct iq2000_frame_cache * 00368 iq2000_frame_cache (struct frame_info *this_frame, void **this_cache) 00369 { 00370 struct gdbarch *gdbarch = get_frame_arch (this_frame); 00371 struct iq2000_frame_cache *cache; 00372 CORE_ADDR current_pc; 00373 int i; 00374 00375 if (*this_cache) 00376 return *this_cache; 00377 00378 cache = FRAME_OBSTACK_ZALLOC (struct iq2000_frame_cache); 00379 iq2000_init_frame_cache (cache); 00380 *this_cache = cache; 00381 00382 cache->base = get_frame_register_unsigned (this_frame, E_FP_REGNUM); 00383 //if (cache->base == 0) 00384 //return cache; 00385 00386 current_pc = get_frame_pc (this_frame); 00387 find_pc_partial_function (current_pc, NULL, &cache->pc, NULL); 00388 if (cache->pc != 0) 00389 iq2000_scan_prologue (gdbarch, cache->pc, current_pc, this_frame, cache); 00390 if (!cache->using_fp) 00391 cache->base = get_frame_register_unsigned (this_frame, E_SP_REGNUM); 00392 00393 cache->saved_sp = cache->base + cache->framesize; 00394 00395 for (i = 0; i < E_NUM_REGS; i++) 00396 if (cache->saved_regs[i] != -1) 00397 cache->saved_regs[i] += cache->base; 00398 00399 return cache; 00400 } 00401 00402 static struct value * 00403 iq2000_frame_prev_register (struct frame_info *this_frame, void **this_cache, 00404 int regnum) 00405 { 00406 struct iq2000_frame_cache *cache = iq2000_frame_cache (this_frame, 00407 this_cache); 00408 00409 if (regnum == E_SP_REGNUM && cache->saved_sp) 00410 return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp); 00411 00412 if (regnum == E_PC_REGNUM) 00413 regnum = E_LR_REGNUM; 00414 00415 if (regnum < E_NUM_REGS && cache->saved_regs[regnum] != -1) 00416 return frame_unwind_got_memory (this_frame, regnum, 00417 cache->saved_regs[regnum]); 00418 00419 return frame_unwind_got_register (this_frame, regnum, regnum); 00420 } 00421 00422 static void 00423 iq2000_frame_this_id (struct frame_info *this_frame, void **this_cache, 00424 struct frame_id *this_id) 00425 { 00426 struct iq2000_frame_cache *cache = iq2000_frame_cache (this_frame, 00427 this_cache); 00428 00429 /* This marks the outermost frame. */ 00430 if (cache->base == 0) 00431 return; 00432 00433 *this_id = frame_id_build (cache->saved_sp, cache->pc); 00434 } 00435 00436 static const struct frame_unwind iq2000_frame_unwind = { 00437 NORMAL_FRAME, 00438 default_frame_unwind_stop_reason, 00439 iq2000_frame_this_id, 00440 iq2000_frame_prev_register, 00441 NULL, 00442 default_frame_sniffer 00443 }; 00444 00445 static CORE_ADDR 00446 iq2000_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) 00447 { 00448 return frame_unwind_register_unsigned (next_frame, E_SP_REGNUM); 00449 } 00450 00451 static CORE_ADDR 00452 iq2000_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) 00453 { 00454 return frame_unwind_register_unsigned (next_frame, E_PC_REGNUM); 00455 } 00456 00457 static struct frame_id 00458 iq2000_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) 00459 { 00460 CORE_ADDR sp = get_frame_register_unsigned (this_frame, E_SP_REGNUM); 00461 return frame_id_build (sp, get_frame_pc (this_frame)); 00462 } 00463 00464 static CORE_ADDR 00465 iq2000_frame_base_address (struct frame_info *this_frame, void **this_cache) 00466 { 00467 struct iq2000_frame_cache *cache = iq2000_frame_cache (this_frame, 00468 this_cache); 00469 00470 return cache->base; 00471 } 00472 00473 static const struct frame_base iq2000_frame_base = { 00474 &iq2000_frame_unwind, 00475 iq2000_frame_base_address, 00476 iq2000_frame_base_address, 00477 iq2000_frame_base_address 00478 }; 00479 00480 static const unsigned char * 00481 iq2000_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, 00482 int *lenptr) 00483 { 00484 static const unsigned char big_breakpoint[] = { 0x00, 0x00, 0x00, 0x0d }; 00485 static const unsigned char little_breakpoint[] = { 0x0d, 0x00, 0x00, 0x00 }; 00486 00487 if ((*pcptr & 3) != 0) 00488 error (_("breakpoint_from_pc: invalid breakpoint address 0x%lx"), 00489 (long) *pcptr); 00490 00491 *lenptr = 4; 00492 return (gdbarch_byte_order (gdbarch) 00493 == BFD_ENDIAN_BIG) ? big_breakpoint : little_breakpoint; 00494 } 00495 00496 /* Target function return value methods: */ 00497 00498 /* Function: store_return_value 00499 Copy the function return value from VALBUF into the 00500 proper location for a function return. */ 00501 00502 static void 00503 iq2000_store_return_value (struct type *type, struct regcache *regcache, 00504 const void *valbuf) 00505 { 00506 int len = TYPE_LENGTH (type); 00507 int regno = E_FN_RETURN_REGNUM; 00508 00509 while (len > 0) 00510 { 00511 gdb_byte buf[4]; 00512 int size = len % 4 ?: 4; 00513 00514 memset (buf, 0, 4); 00515 memcpy (buf + 4 - size, valbuf, size); 00516 regcache_raw_write (regcache, regno++, buf); 00517 len -= size; 00518 valbuf = ((char *) valbuf) + size; 00519 } 00520 } 00521 00522 /* Function: use_struct_convention 00523 Returns non-zero if the given struct type will be returned using 00524 a special convention, rather than the normal function return method. */ 00525 00526 static int 00527 iq2000_use_struct_convention (struct type *type) 00528 { 00529 return ((TYPE_CODE (type) == TYPE_CODE_STRUCT) 00530 || (TYPE_CODE (type) == TYPE_CODE_UNION)) 00531 && TYPE_LENGTH (type) > 8; 00532 } 00533 00534 /* Function: extract_return_value 00535 Copy the function's return value into VALBUF. 00536 This function is called only in the context of "target function calls", 00537 ie. when the debugger forces a function to be called in the child, and 00538 when the debugger forces a function to return prematurely via the 00539 "return" command. */ 00540 00541 static void 00542 iq2000_extract_return_value (struct type *type, struct regcache *regcache, 00543 void *valbuf) 00544 { 00545 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00546 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00547 00548 /* If the function's return value is 8 bytes or less, it is 00549 returned in a register, and if larger than 8 bytes, it is 00550 returned in a stack location which is pointed to by the same 00551 register. */ 00552 int len = TYPE_LENGTH (type); 00553 00554 if (len <= (2 * 4)) 00555 { 00556 int regno = E_FN_RETURN_REGNUM; 00557 00558 /* Return values of <= 8 bytes are returned in 00559 FN_RETURN_REGNUM. */ 00560 while (len > 0) 00561 { 00562 ULONGEST tmp; 00563 int size = len % 4 ?: 4; 00564 00565 /* By using store_unsigned_integer we avoid having to 00566 do anything special for small big-endian values. */ 00567 regcache_cooked_read_unsigned (regcache, regno++, &tmp); 00568 store_unsigned_integer (valbuf, size, byte_order, tmp); 00569 len -= size; 00570 valbuf = ((char *) valbuf) + size; 00571 } 00572 } 00573 else 00574 { 00575 /* Return values > 8 bytes are returned in memory, 00576 pointed to by FN_RETURN_REGNUM. */ 00577 ULONGEST return_buffer; 00578 regcache_cooked_read_unsigned (regcache, E_FN_RETURN_REGNUM, 00579 &return_buffer); 00580 read_memory (return_buffer, valbuf, TYPE_LENGTH (type)); 00581 } 00582 } 00583 00584 static enum return_value_convention 00585 iq2000_return_value (struct gdbarch *gdbarch, struct value *function, 00586 struct type *type, struct regcache *regcache, 00587 gdb_byte *readbuf, const gdb_byte *writebuf) 00588 { 00589 if (iq2000_use_struct_convention (type)) 00590 return RETURN_VALUE_STRUCT_CONVENTION; 00591 if (writebuf) 00592 iq2000_store_return_value (type, regcache, writebuf); 00593 else if (readbuf) 00594 iq2000_extract_return_value (type, regcache, readbuf); 00595 return RETURN_VALUE_REGISTER_CONVENTION; 00596 } 00597 00598 /* Function: register_virtual_type 00599 Returns the default type for register N. */ 00600 00601 static struct type * 00602 iq2000_register_type (struct gdbarch *gdbarch, int regnum) 00603 { 00604 return builtin_type (gdbarch)->builtin_int32; 00605 } 00606 00607 static CORE_ADDR 00608 iq2000_frame_align (struct gdbarch *ignore, CORE_ADDR sp) 00609 { 00610 /* This is the same frame alignment used by gcc. */ 00611 return ((sp + 7) & ~7); 00612 } 00613 00614 /* Convenience function to check 8-byte types for being a scalar type 00615 or a struct with only one long long or double member. */ 00616 static int 00617 iq2000_pass_8bytetype_by_address (struct type *type) 00618 { 00619 struct type *ftype; 00620 00621 /* Skip typedefs. */ 00622 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) 00623 type = TYPE_TARGET_TYPE (type); 00624 /* Non-struct and non-union types are always passed by value. */ 00625 if (TYPE_CODE (type) != TYPE_CODE_STRUCT 00626 && TYPE_CODE (type) != TYPE_CODE_UNION) 00627 return 0; 00628 /* Structs with more than 1 field are always passed by address. */ 00629 if (TYPE_NFIELDS (type) != 1) 00630 return 1; 00631 /* Get field type. */ 00632 ftype = (TYPE_FIELDS (type))[0].type; 00633 /* The field type must have size 8, otherwise pass by address. */ 00634 if (TYPE_LENGTH (ftype) != 8) 00635 return 1; 00636 /* Skip typedefs of field type. */ 00637 while (TYPE_CODE (ftype) == TYPE_CODE_TYPEDEF) 00638 ftype = TYPE_TARGET_TYPE (ftype); 00639 /* If field is int or float, pass by value. */ 00640 if (TYPE_CODE (ftype) == TYPE_CODE_FLT 00641 || TYPE_CODE (ftype) == TYPE_CODE_INT) 00642 return 0; 00643 /* Everything else, pass by address. */ 00644 return 1; 00645 } 00646 00647 static CORE_ADDR 00648 iq2000_push_dummy_call (struct gdbarch *gdbarch, struct value *function, 00649 struct regcache *regcache, CORE_ADDR bp_addr, 00650 int nargs, struct value **args, CORE_ADDR sp, 00651 int struct_return, CORE_ADDR struct_addr) 00652 { 00653 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00654 const bfd_byte *val; 00655 bfd_byte buf[4]; 00656 struct type *type; 00657 int i, argreg, typelen, slacklen; 00658 int stackspace = 0; 00659 /* Used to copy struct arguments into the stack. */ 00660 CORE_ADDR struct_ptr; 00661 00662 /* First determine how much stack space we will need. */ 00663 for (i = 0, argreg = E_1ST_ARGREG + (struct_return != 0); i < nargs; i++) 00664 { 00665 type = value_type (args[i]); 00666 typelen = TYPE_LENGTH (type); 00667 if (typelen <= 4) 00668 { 00669 /* Scalars of up to 4 bytes, 00670 structs of up to 4 bytes, and 00671 pointers. */ 00672 if (argreg <= E_LAST_ARGREG) 00673 argreg++; 00674 else 00675 stackspace += 4; 00676 } 00677 else if (typelen == 8 && !iq2000_pass_8bytetype_by_address (type)) 00678 { 00679 /* long long, 00680 double, and possibly 00681 structs with a single field of long long or double. */ 00682 if (argreg <= E_LAST_ARGREG - 1) 00683 { 00684 /* 8-byte arg goes into a register pair 00685 (must start with an even-numbered reg). */ 00686 if (((argreg - E_1ST_ARGREG) % 2) != 0) 00687 argreg ++; 00688 argreg += 2; 00689 } 00690 else 00691 { 00692 argreg = E_LAST_ARGREG + 1; /* no more argregs. */ 00693 /* 8-byte arg goes on stack, must be 8-byte aligned. */ 00694 stackspace = ((stackspace + 7) & ~7); 00695 stackspace += 8; 00696 } 00697 } 00698 else 00699 { 00700 /* Structs are passed as pointer to a copy of the struct. 00701 So we need room on the stack for a copy of the struct 00702 plus for the argument pointer. */ 00703 if (argreg <= E_LAST_ARGREG) 00704 argreg++; 00705 else 00706 stackspace += 4; 00707 /* Care for 8-byte alignment of structs saved on stack. */ 00708 stackspace += ((typelen + 7) & ~7); 00709 } 00710 } 00711 00712 /* Now copy params, in ascending order, into their assigned location 00713 (either in a register or on the stack). */ 00714 00715 sp -= (sp % 8); /* align */ 00716 struct_ptr = sp; 00717 sp -= stackspace; 00718 sp -= (sp % 8); /* align again */ 00719 stackspace = 0; 00720 00721 argreg = E_1ST_ARGREG; 00722 if (struct_return) 00723 { 00724 /* A function that returns a struct will consume one argreg to do so. 00725 */ 00726 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); 00727 } 00728 00729 for (i = 0; i < nargs; i++) 00730 { 00731 type = value_type (args[i]); 00732 typelen = TYPE_LENGTH (type); 00733 val = value_contents (args[i]); 00734 if (typelen <= 4) 00735 { 00736 /* Char, short, int, float, pointer, and structs <= four bytes. */ 00737 slacklen = (4 - (typelen % 4)) % 4; 00738 memset (buf, 0, sizeof (buf)); 00739 memcpy (buf + slacklen, val, typelen); 00740 if (argreg <= E_LAST_ARGREG) 00741 { 00742 /* Passed in a register. */ 00743 regcache_raw_write (regcache, argreg++, buf); 00744 } 00745 else 00746 { 00747 /* Passed on the stack. */ 00748 write_memory (sp + stackspace, buf, 4); 00749 stackspace += 4; 00750 } 00751 } 00752 else if (typelen == 8 && !iq2000_pass_8bytetype_by_address (type)) 00753 { 00754 /* (long long), (double), or struct consisting of 00755 a single (long long) or (double). */ 00756 if (argreg <= E_LAST_ARGREG - 1) 00757 { 00758 /* 8-byte arg goes into a register pair 00759 (must start with an even-numbered reg). */ 00760 if (((argreg - E_1ST_ARGREG) % 2) != 0) 00761 argreg++; 00762 regcache_raw_write (regcache, argreg++, val); 00763 regcache_raw_write (regcache, argreg++, val + 4); 00764 } 00765 else 00766 { 00767 /* 8-byte arg goes on stack, must be 8-byte aligned. */ 00768 argreg = E_LAST_ARGREG + 1; /* no more argregs. */ 00769 stackspace = ((stackspace + 7) & ~7); 00770 write_memory (sp + stackspace, val, typelen); 00771 stackspace += 8; 00772 } 00773 } 00774 else 00775 { 00776 /* Store struct beginning at the upper end of the previously 00777 computed stack space. Then store the address of the struct 00778 using the usual rules for a 4 byte value. */ 00779 struct_ptr -= ((typelen + 7) & ~7); 00780 write_memory (struct_ptr, val, typelen); 00781 if (argreg <= E_LAST_ARGREG) 00782 regcache_cooked_write_unsigned (regcache, argreg++, struct_ptr); 00783 else 00784 { 00785 store_unsigned_integer (buf, 4, byte_order, struct_ptr); 00786 write_memory (sp + stackspace, buf, 4); 00787 stackspace += 4; 00788 } 00789 } 00790 } 00791 00792 /* Store return address. */ 00793 regcache_cooked_write_unsigned (regcache, E_LR_REGNUM, bp_addr); 00794 00795 /* Update stack pointer. */ 00796 regcache_cooked_write_unsigned (regcache, E_SP_REGNUM, sp); 00797 00798 /* And that should do it. Return the new stack pointer. */ 00799 return sp; 00800 } 00801 00802 /* Function: gdbarch_init 00803 Initializer function for the iq2000 gdbarch vector. 00804 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */ 00805 00806 static struct gdbarch * 00807 iq2000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) 00808 { 00809 struct gdbarch *gdbarch; 00810 00811 /* Look up list for candidates - only one. */ 00812 arches = gdbarch_list_lookup_by_info (arches, &info); 00813 if (arches != NULL) 00814 return arches->gdbarch; 00815 00816 gdbarch = gdbarch_alloc (&info, NULL); 00817 00818 set_gdbarch_num_regs (gdbarch, E_NUM_REGS); 00819 set_gdbarch_num_pseudo_regs (gdbarch, 0); 00820 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM); 00821 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM); 00822 set_gdbarch_register_name (gdbarch, iq2000_register_name); 00823 set_gdbarch_address_to_pointer (gdbarch, iq2000_address_to_pointer); 00824 set_gdbarch_pointer_to_address (gdbarch, iq2000_pointer_to_address); 00825 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT); 00826 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); 00827 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT); 00828 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT); 00829 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT); 00830 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT); 00831 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); 00832 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); 00833 set_gdbarch_float_format (gdbarch, floatformats_ieee_single); 00834 set_gdbarch_double_format (gdbarch, floatformats_ieee_double); 00835 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double); 00836 set_gdbarch_return_value (gdbarch, iq2000_return_value); 00837 set_gdbarch_breakpoint_from_pc (gdbarch, iq2000_breakpoint_from_pc); 00838 set_gdbarch_frame_args_skip (gdbarch, 0); 00839 set_gdbarch_skip_prologue (gdbarch, iq2000_skip_prologue); 00840 set_gdbarch_inner_than (gdbarch, core_addr_lessthan); 00841 set_gdbarch_print_insn (gdbarch, print_insn_iq2000); 00842 set_gdbarch_register_type (gdbarch, iq2000_register_type); 00843 set_gdbarch_frame_align (gdbarch, iq2000_frame_align); 00844 set_gdbarch_unwind_sp (gdbarch, iq2000_unwind_sp); 00845 set_gdbarch_unwind_pc (gdbarch, iq2000_unwind_pc); 00846 set_gdbarch_dummy_id (gdbarch, iq2000_dummy_id); 00847 frame_base_set_default (gdbarch, &iq2000_frame_base); 00848 set_gdbarch_push_dummy_call (gdbarch, iq2000_push_dummy_call); 00849 00850 gdbarch_init_osabi (info, gdbarch); 00851 00852 dwarf2_append_unwinders (gdbarch); 00853 frame_unwind_append_unwinder (gdbarch, &iq2000_frame_unwind); 00854 00855 return gdbarch; 00856 } 00857 00858 /* Function: _initialize_iq2000_tdep 00859 Initializer function for the iq2000 module. 00860 Called by gdb at start-up. */ 00861 00862 /* Provide a prototype to silence -Wmissing-prototypes. */ 00863 extern initialize_file_ftype _initialize_iq2000_tdep; 00864 00865 void 00866 _initialize_iq2000_tdep (void) 00867 { 00868 register_gdbarch_init (bfd_arch_iq2000, iq2000_gdbarch_init); 00869 }