GDB (API)
/home/stan/gdb/src/gdb/rx-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for the Renesas RX for GDB, the GNU debugger.
00002 
00003    Copyright (C) 2008-2013 Free Software Foundation, Inc.
00004 
00005    Contributed by Red Hat, Inc.
00006 
00007    This file is part of GDB.
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 3 of the License, or
00012    (at your option) any later version.
00013 
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00021 
00022 #include "defs.h"
00023 #include "arch-utils.h"
00024 #include "prologue-value.h"
00025 #include "target.h"
00026 #include "regcache.h"
00027 #include "opcode/rx.h"
00028 #include "dis-asm.h"
00029 #include "gdbtypes.h"
00030 #include "frame.h"
00031 #include "frame-unwind.h"
00032 #include "frame-base.h"
00033 #include "value.h"
00034 #include "gdbcore.h"
00035 #include "dwarf2-frame.h"
00036 
00037 #include "elf/rx.h"
00038 #include "elf-bfd.h"
00039 
00040 /* Certain important register numbers.  */
00041 enum
00042 {
00043   RX_SP_REGNUM = 0,
00044   RX_R1_REGNUM = 1,
00045   RX_R4_REGNUM = 4,
00046   RX_FP_REGNUM = 6,
00047   RX_R15_REGNUM = 15,
00048   RX_PC_REGNUM = 19,
00049   RX_ACC_REGNUM = 25,
00050   RX_NUM_REGS = 26
00051 };
00052 
00053 /* Architecture specific data.  */
00054 struct gdbarch_tdep
00055 {
00056   /* The ELF header flags specify the multilib used.  */
00057   int elf_flags;
00058 };
00059 
00060 /* This structure holds the results of a prologue analysis.  */
00061 struct rx_prologue
00062 {
00063   /* The offset from the frame base to the stack pointer --- always
00064      zero or negative.
00065 
00066      Calling this a "size" is a bit misleading, but given that the
00067      stack grows downwards, using offsets for everything keeps one
00068      from going completely sign-crazy: you never change anything's
00069      sign for an ADD instruction; always change the second operand's
00070      sign for a SUB instruction; and everything takes care of
00071      itself.  */
00072   int frame_size;
00073 
00074   /* Non-zero if this function has initialized the frame pointer from
00075      the stack pointer, zero otherwise.  */
00076   int has_frame_ptr;
00077 
00078   /* If has_frame_ptr is non-zero, this is the offset from the frame
00079      base to where the frame pointer points.  This is always zero or
00080      negative.  */
00081   int frame_ptr_offset;
00082 
00083   /* The address of the first instruction at which the frame has been
00084      set up and the arguments are where the debug info says they are
00085      --- as best as we can tell.  */
00086   CORE_ADDR prologue_end;
00087 
00088   /* reg_offset[R] is the offset from the CFA at which register R is
00089      saved, or 1 if register R has not been saved.  (Real values are
00090      always zero or negative.)  */
00091   int reg_offset[RX_NUM_REGS];
00092 };
00093 
00094 /* Implement the "register_name" gdbarch method.  */
00095 static const char *
00096 rx_register_name (struct gdbarch *gdbarch, int regnr)
00097 {
00098   static const char *const reg_names[] = {
00099     "r0",
00100     "r1",
00101     "r2",
00102     "r3",
00103     "r4",
00104     "r5",
00105     "r6",
00106     "r7",
00107     "r8",
00108     "r9",
00109     "r10",
00110     "r11",
00111     "r12",
00112     "r13",
00113     "r14",
00114     "r15",
00115     "usp",
00116     "isp",
00117     "psw",
00118     "pc",
00119     "intb",
00120     "bpsw",
00121     "bpc",
00122     "fintv",
00123     "fpsw",
00124     "acc"
00125   };
00126 
00127   return reg_names[regnr];
00128 }
00129 
00130 /* Implement the "register_type" gdbarch method.  */
00131 static struct type *
00132 rx_register_type (struct gdbarch *gdbarch, int reg_nr)
00133 {
00134   if (reg_nr == RX_PC_REGNUM)
00135     return builtin_type (gdbarch)->builtin_func_ptr;
00136   else if (reg_nr == RX_ACC_REGNUM)
00137     return builtin_type (gdbarch)->builtin_unsigned_long_long;
00138   else
00139     return builtin_type (gdbarch)->builtin_unsigned_long;
00140 }
00141 
00142 
00143 /* Function for finding saved registers in a 'struct pv_area'; this
00144    function is passed to pv_area_scan.
00145 
00146    If VALUE is a saved register, ADDR says it was saved at a constant
00147    offset from the frame base, and SIZE indicates that the whole
00148    register was saved, record its offset.  */
00149 static void
00150 check_for_saved (void *result_untyped, pv_t addr, CORE_ADDR size, pv_t value)
00151 {
00152   struct rx_prologue *result = (struct rx_prologue *) result_untyped;
00153 
00154   if (value.kind == pvk_register
00155       && value.k == 0
00156       && pv_is_register (addr, RX_SP_REGNUM)
00157       && size == register_size (target_gdbarch (), value.reg))
00158     result->reg_offset[value.reg] = addr.k;
00159 }
00160 
00161 /* Define a "handle" struct for fetching the next opcode.  */
00162 struct rx_get_opcode_byte_handle
00163 {
00164   CORE_ADDR pc;
00165 };
00166 
00167 /* Fetch a byte on behalf of the opcode decoder.  HANDLE contains
00168    the memory address of the next byte to fetch.  If successful,
00169    the address in the handle is updated and the byte fetched is
00170    returned as the value of the function.  If not successful, -1
00171    is returned.  */
00172 static int
00173 rx_get_opcode_byte (void *handle)
00174 {
00175   struct rx_get_opcode_byte_handle *opcdata = handle;
00176   int status;
00177   gdb_byte byte;
00178 
00179   status = target_read_memory (opcdata->pc, &byte, 1);
00180   if (status == 0)
00181     {
00182       opcdata->pc += 1;
00183       return byte;
00184     }
00185   else
00186     return -1;
00187 }
00188 
00189 /* Analyze a prologue starting at START_PC, going no further than
00190    LIMIT_PC.  Fill in RESULT as appropriate.  */
00191 static void
00192 rx_analyze_prologue (CORE_ADDR start_pc,
00193                      CORE_ADDR limit_pc, struct rx_prologue *result)
00194 {
00195   CORE_ADDR pc, next_pc;
00196   int rn;
00197   pv_t reg[RX_NUM_REGS];
00198   struct pv_area *stack;
00199   struct cleanup *back_to;
00200   CORE_ADDR after_last_frame_setup_insn = start_pc;
00201 
00202   memset (result, 0, sizeof (*result));
00203 
00204   for (rn = 0; rn < RX_NUM_REGS; rn++)
00205     {
00206       reg[rn] = pv_register (rn, 0);
00207       result->reg_offset[rn] = 1;
00208     }
00209 
00210   stack = make_pv_area (RX_SP_REGNUM, gdbarch_addr_bit (target_gdbarch ()));
00211   back_to = make_cleanup_free_pv_area (stack);
00212 
00213   /* The call instruction has saved the return address on the stack.  */
00214   reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
00215   pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[RX_PC_REGNUM]);
00216 
00217   pc = start_pc;
00218   while (pc < limit_pc)
00219     {
00220       int bytes_read;
00221       struct rx_get_opcode_byte_handle opcode_handle;
00222       RX_Opcode_Decoded opc;
00223 
00224       opcode_handle.pc = pc;
00225       bytes_read = rx_decode_opcode (pc, &opc, rx_get_opcode_byte,
00226                                      &opcode_handle);
00227       next_pc = pc + bytes_read;
00228 
00229       if (opc.id == RXO_pushm   /* pushm r1, r2 */
00230           && opc.op[1].type == RX_Operand_Register
00231           && opc.op[2].type == RX_Operand_Register)
00232         {
00233           int r1, r2;
00234           int r;
00235 
00236           r1 = opc.op[1].reg;
00237           r2 = opc.op[2].reg;
00238           for (r = r2; r >= r1; r--)
00239             {
00240               reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
00241               pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[r]);
00242             }
00243           after_last_frame_setup_insn = next_pc;
00244         }
00245       else if (opc.id == RXO_mov        /* mov.l rdst, rsrc */
00246                && opc.op[0].type == RX_Operand_Register
00247                && opc.op[1].type == RX_Operand_Register
00248                && opc.size == RX_Long)
00249         {
00250           int rdst, rsrc;
00251 
00252           rdst = opc.op[0].reg;
00253           rsrc = opc.op[1].reg;
00254           reg[rdst] = reg[rsrc];
00255           if (rdst == RX_FP_REGNUM && rsrc == RX_SP_REGNUM)
00256             after_last_frame_setup_insn = next_pc;
00257         }
00258       else if (opc.id == RXO_mov        /* mov.l rsrc, [-SP] */
00259                && opc.op[0].type == RX_Operand_Predec
00260                && opc.op[0].reg == RX_SP_REGNUM
00261                && opc.op[1].type == RX_Operand_Register
00262                && opc.size == RX_Long)
00263         {
00264           int rsrc;
00265 
00266           rsrc = opc.op[1].reg;
00267           reg[RX_SP_REGNUM] = pv_add_constant (reg[RX_SP_REGNUM], -4);
00268           pv_area_store (stack, reg[RX_SP_REGNUM], 4, reg[rsrc]);
00269           after_last_frame_setup_insn = next_pc;
00270         }
00271       else if (opc.id == RXO_add        /* add #const, rsrc, rdst */
00272                && opc.op[0].type == RX_Operand_Register
00273                && opc.op[1].type == RX_Operand_Immediate
00274                && opc.op[2].type == RX_Operand_Register)
00275         {
00276           int rdst = opc.op[0].reg;
00277           int addend = opc.op[1].addend;
00278           int rsrc = opc.op[2].reg;
00279           reg[rdst] = pv_add_constant (reg[rsrc], addend);
00280           /* Negative adjustments to the stack pointer or frame pointer
00281              are (most likely) part of the prologue.  */
00282           if ((rdst == RX_SP_REGNUM || rdst == RX_FP_REGNUM) && addend < 0)
00283             after_last_frame_setup_insn = next_pc;
00284         }
00285       else if (opc.id == RXO_mov
00286                && opc.op[0].type == RX_Operand_Indirect
00287                && opc.op[1].type == RX_Operand_Register
00288                && opc.size == RX_Long
00289                && (opc.op[0].reg == RX_SP_REGNUM
00290                    || opc.op[0].reg == RX_FP_REGNUM)
00291                && (RX_R1_REGNUM <= opc.op[1].reg
00292                    && opc.op[1].reg <= RX_R4_REGNUM))
00293         {
00294           /* This moves an argument register to the stack.  Don't
00295              record it, but allow it to be a part of the prologue.  */
00296         }
00297       else if (opc.id == RXO_branch
00298                && opc.op[0].type == RX_Operand_Immediate
00299                && next_pc < opc.op[0].addend)
00300         {
00301           /* When a loop appears as the first statement of a function
00302              body, gcc 4.x will use a BRA instruction to branch to the
00303              loop condition checking code.  This BRA instruction is
00304              marked as part of the prologue.  We therefore set next_pc
00305              to this branch target and also stop the prologue scan.
00306              The instructions at and beyond the branch target should
00307              no longer be associated with the prologue.
00308 
00309              Note that we only consider forward branches here.  We
00310              presume that a forward branch is being used to skip over
00311              a loop body.
00312 
00313              A backwards branch is covered by the default case below.
00314              If we were to encounter a backwards branch, that would
00315              most likely mean that we've scanned through a loop body.
00316              We definitely want to stop the prologue scan when this
00317              happens and that is precisely what is done by the default
00318              case below.  */
00319 
00320           after_last_frame_setup_insn = opc.op[0].addend;
00321           break;                /* Scan no further if we hit this case.  */
00322         }
00323       else
00324         {
00325           /* Terminate the prologue scan.  */
00326           break;
00327         }
00328 
00329       pc = next_pc;
00330     }
00331 
00332   /* Is the frame size (offset, really) a known constant?  */
00333   if (pv_is_register (reg[RX_SP_REGNUM], RX_SP_REGNUM))
00334     result->frame_size = reg[RX_SP_REGNUM].k;
00335 
00336   /* Was the frame pointer initialized?  */
00337   if (pv_is_register (reg[RX_FP_REGNUM], RX_SP_REGNUM))
00338     {
00339       result->has_frame_ptr = 1;
00340       result->frame_ptr_offset = reg[RX_FP_REGNUM].k;
00341     }
00342 
00343   /* Record where all the registers were saved.  */
00344   pv_area_scan (stack, check_for_saved, (void *) result);
00345 
00346   result->prologue_end = after_last_frame_setup_insn;
00347 
00348   do_cleanups (back_to);
00349 }
00350 
00351 
00352 /* Implement the "skip_prologue" gdbarch method.  */
00353 static CORE_ADDR
00354 rx_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
00355 {
00356   const char *name;
00357   CORE_ADDR func_addr, func_end;
00358   struct rx_prologue p;
00359 
00360   /* Try to find the extent of the function that contains PC.  */
00361   if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
00362     return pc;
00363 
00364   rx_analyze_prologue (pc, func_end, &p);
00365   return p.prologue_end;
00366 }
00367 
00368 /* Given a frame described by THIS_FRAME, decode the prologue of its
00369    associated function if there is not cache entry as specified by
00370    THIS_PROLOGUE_CACHE.  Save the decoded prologue in the cache and
00371    return that struct as the value of this function.  */
00372 static struct rx_prologue *
00373 rx_analyze_frame_prologue (struct frame_info *this_frame,
00374                            void **this_prologue_cache)
00375 {
00376   if (!*this_prologue_cache)
00377     {
00378       CORE_ADDR func_start, stop_addr;
00379 
00380       *this_prologue_cache = FRAME_OBSTACK_ZALLOC (struct rx_prologue);
00381 
00382       func_start = get_frame_func (this_frame);
00383       stop_addr = get_frame_pc (this_frame);
00384 
00385       /* If we couldn't find any function containing the PC, then
00386          just initialize the prologue cache, but don't do anything.  */
00387       if (!func_start)
00388         stop_addr = func_start;
00389 
00390       rx_analyze_prologue (func_start, stop_addr, *this_prologue_cache);
00391     }
00392 
00393   return *this_prologue_cache;
00394 }
00395 
00396 /* Given the next frame and a prologue cache, return this frame's
00397    base.  */
00398 static CORE_ADDR
00399 rx_frame_base (struct frame_info *this_frame, void **this_prologue_cache)
00400 {
00401   struct rx_prologue *p
00402     = rx_analyze_frame_prologue (this_frame, this_prologue_cache);
00403 
00404   /* In functions that use alloca, the distance between the stack
00405      pointer and the frame base varies dynamically, so we can't use
00406      the SP plus static information like prologue analysis to find the
00407      frame base.  However, such functions must have a frame pointer,
00408      to be able to restore the SP on exit.  So whenever we do have a
00409      frame pointer, use that to find the base.  */
00410   if (p->has_frame_ptr)
00411     {
00412       CORE_ADDR fp = get_frame_register_unsigned (this_frame, RX_FP_REGNUM);
00413       return fp - p->frame_ptr_offset;
00414     }
00415   else
00416     {
00417       CORE_ADDR sp = get_frame_register_unsigned (this_frame, RX_SP_REGNUM);
00418       return sp - p->frame_size;
00419     }
00420 }
00421 
00422 /* Implement the "frame_this_id" method for unwinding frames.  */
00423 static void
00424 rx_frame_this_id (struct frame_info *this_frame,
00425                   void **this_prologue_cache, struct frame_id *this_id)
00426 {
00427   *this_id = frame_id_build (rx_frame_base (this_frame, this_prologue_cache),
00428                              get_frame_func (this_frame));
00429 }
00430 
00431 /* Implement the "frame_prev_register" method for unwinding frames.  */
00432 static struct value *
00433 rx_frame_prev_register (struct frame_info *this_frame,
00434                         void **this_prologue_cache, int regnum)
00435 {
00436   struct rx_prologue *p
00437     = rx_analyze_frame_prologue (this_frame, this_prologue_cache);
00438   CORE_ADDR frame_base = rx_frame_base (this_frame, this_prologue_cache);
00439   int reg_size = register_size (get_frame_arch (this_frame), regnum);
00440 
00441   if (regnum == RX_SP_REGNUM)
00442     return frame_unwind_got_constant (this_frame, regnum, frame_base);
00443 
00444   /* If prologue analysis says we saved this register somewhere,
00445      return a description of the stack slot holding it.  */
00446   else if (p->reg_offset[regnum] != 1)
00447     return frame_unwind_got_memory (this_frame, regnum,
00448                                     frame_base + p->reg_offset[regnum]);
00449 
00450   /* Otherwise, presume we haven't changed the value of this
00451      register, and get it from the next frame.  */
00452   else
00453     return frame_unwind_got_register (this_frame, regnum, regnum);
00454 }
00455 
00456 static const struct frame_unwind rx_frame_unwind = {
00457   NORMAL_FRAME,
00458   default_frame_unwind_stop_reason,
00459   rx_frame_this_id,
00460   rx_frame_prev_register,
00461   NULL,
00462   default_frame_sniffer
00463 };
00464 
00465 /* Implement the "unwind_pc" gdbarch method.  */
00466 static CORE_ADDR
00467 rx_unwind_pc (struct gdbarch *gdbarch, struct frame_info *this_frame)
00468 {
00469   ULONGEST pc;
00470 
00471   pc = frame_unwind_register_unsigned (this_frame, RX_PC_REGNUM);
00472   return pc;
00473 }
00474 
00475 /* Implement the "unwind_sp" gdbarch method.  */
00476 static CORE_ADDR
00477 rx_unwind_sp (struct gdbarch *gdbarch, struct frame_info *this_frame)
00478 {
00479   ULONGEST sp;
00480 
00481   sp = frame_unwind_register_unsigned (this_frame, RX_SP_REGNUM);
00482   return sp;
00483 }
00484 
00485 /* Implement the "dummy_id" gdbarch method.  */
00486 static struct frame_id
00487 rx_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
00488 {
00489   return
00490     frame_id_build (get_frame_register_unsigned (this_frame, RX_SP_REGNUM),
00491                     get_frame_pc (this_frame));
00492 }
00493 
00494 /* Implement the "push_dummy_call" gdbarch method.  */
00495 static CORE_ADDR
00496 rx_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
00497                     struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
00498                     struct value **args, CORE_ADDR sp, int struct_return,
00499                     CORE_ADDR struct_addr)
00500 {
00501   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00502   int write_pass;
00503   int sp_off = 0;
00504   CORE_ADDR cfa;
00505   int num_register_candidate_args;
00506 
00507   struct type *func_type = value_type (function);
00508 
00509   /* Dereference function pointer types.  */
00510   while (TYPE_CODE (func_type) == TYPE_CODE_PTR)
00511     func_type = TYPE_TARGET_TYPE (func_type);
00512 
00513   /* The end result had better be a function or a method.  */
00514   gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC
00515               || TYPE_CODE (func_type) == TYPE_CODE_METHOD);
00516 
00517   /* Functions with a variable number of arguments have all of their
00518      variable arguments and the last non-variable argument passed
00519      on the stack.
00520 
00521      Otherwise, we can pass up to four arguments on the stack.
00522 
00523      Once computed, we leave this value alone.  I.e. we don't update
00524      it in case of a struct return going in a register or an argument
00525      requiring multiple registers, etc.  We rely instead on the value
00526      of the ``arg_reg'' variable to get these other details correct.  */
00527 
00528   if (TYPE_VARARGS (func_type))
00529     num_register_candidate_args = TYPE_NFIELDS (func_type) - 1;
00530   else
00531     num_register_candidate_args = 4;
00532 
00533   /* We make two passes; the first does the stack allocation,
00534      the second actually stores the arguments.  */
00535   for (write_pass = 0; write_pass <= 1; write_pass++)
00536     {
00537       int i;
00538       int arg_reg = RX_R1_REGNUM;
00539 
00540       if (write_pass)
00541         sp = align_down (sp - sp_off, 4);
00542       sp_off = 0;
00543 
00544       if (struct_return)
00545         {
00546           struct type *return_type = TYPE_TARGET_TYPE (func_type);
00547 
00548           gdb_assert (TYPE_CODE (return_type) == TYPE_CODE_STRUCT
00549                       || TYPE_CODE (func_type) == TYPE_CODE_UNION);
00550 
00551           if (TYPE_LENGTH (return_type) > 16
00552               || TYPE_LENGTH (return_type) % 4 != 0)
00553             {
00554               if (write_pass)
00555                 regcache_cooked_write_unsigned (regcache, RX_R15_REGNUM,
00556                                                 struct_addr);
00557             }
00558         }
00559 
00560       /* Push the arguments.  */
00561       for (i = 0; i < nargs; i++)
00562         {
00563           struct value *arg = args[i];
00564           const gdb_byte *arg_bits = value_contents_all (arg);
00565           struct type *arg_type = check_typedef (value_type (arg));
00566           ULONGEST arg_size = TYPE_LENGTH (arg_type);
00567 
00568           if (i == 0 && struct_addr != 0 && !struct_return
00569               && TYPE_CODE (arg_type) == TYPE_CODE_PTR
00570               && extract_unsigned_integer (arg_bits, 4,
00571                                            byte_order) == struct_addr)
00572             {
00573               /* This argument represents the address at which C++ (and
00574                  possibly other languages) store their return value.
00575                  Put this value in R15.  */
00576               if (write_pass)
00577                 regcache_cooked_write_unsigned (regcache, RX_R15_REGNUM,
00578                                                 struct_addr);
00579             }
00580           else if (TYPE_CODE (arg_type) != TYPE_CODE_STRUCT
00581                    && TYPE_CODE (arg_type) != TYPE_CODE_UNION)
00582             {
00583               /* Argument is a scalar.  */
00584               if (arg_size == 8)
00585                 {
00586                   if (i < num_register_candidate_args
00587                       && arg_reg <= RX_R4_REGNUM - 1)
00588                     {
00589                       /* If argument registers are going to be used to pass
00590                          an 8 byte scalar, the ABI specifies that two registers
00591                          must be available.  */
00592                       if (write_pass)
00593                         {
00594                           regcache_cooked_write_unsigned (regcache, arg_reg,
00595                                                           extract_unsigned_integer
00596                                                           (arg_bits, 4,
00597                                                            byte_order));
00598                           regcache_cooked_write_unsigned (regcache,
00599                                                           arg_reg + 1,
00600                                                           extract_unsigned_integer
00601                                                           (arg_bits + 4, 4,
00602                                                            byte_order));
00603                         }
00604                       arg_reg += 2;
00605                     }
00606                   else
00607                     {
00608                       sp_off = align_up (sp_off, 4);
00609                       /* Otherwise, pass the 8 byte scalar on the stack.  */
00610                       if (write_pass)
00611                         write_memory (sp + sp_off, arg_bits, 8);
00612                       sp_off += 8;
00613                     }
00614                 }
00615               else
00616                 {
00617                   ULONGEST u;
00618 
00619                   gdb_assert (arg_size <= 4);
00620 
00621                   u =
00622                     extract_unsigned_integer (arg_bits, arg_size, byte_order);
00623 
00624                   if (i < num_register_candidate_args
00625                       && arg_reg <= RX_R4_REGNUM)
00626                     {
00627                       if (write_pass)
00628                         regcache_cooked_write_unsigned (regcache, arg_reg, u);
00629                       arg_reg += 1;
00630                     }
00631                   else
00632                     {
00633                       int p_arg_size = 4;
00634 
00635                       if (TYPE_PROTOTYPED (func_type)
00636                           && i < TYPE_NFIELDS (func_type))
00637                         {
00638                           struct type *p_arg_type =
00639                             TYPE_FIELD_TYPE (func_type, i);
00640                           p_arg_size = TYPE_LENGTH (p_arg_type);
00641                         }
00642 
00643                       sp_off = align_up (sp_off, p_arg_size);
00644 
00645                       if (write_pass)
00646                         write_memory_unsigned_integer (sp + sp_off,
00647                                                        p_arg_size, byte_order,
00648                                                        u);
00649                       sp_off += p_arg_size;
00650                     }
00651                 }
00652             }
00653           else
00654             {
00655               /* Argument is a struct or union.  Pass as much of the struct
00656                  in registers, if possible.  Pass the rest on the stack.  */
00657               while (arg_size > 0)
00658                 {
00659                   if (i < num_register_candidate_args
00660                       && arg_reg <= RX_R4_REGNUM
00661                       && arg_size <= 4 * (RX_R4_REGNUM - arg_reg + 1)
00662                       && arg_size % 4 == 0)
00663                     {
00664                       int len = min (arg_size, 4);
00665 
00666                       if (write_pass)
00667                         regcache_cooked_write_unsigned (regcache, arg_reg,
00668                                                         extract_unsigned_integer
00669                                                         (arg_bits, len,
00670                                                          byte_order));
00671                       arg_bits += len;
00672                       arg_size -= len;
00673                       arg_reg++;
00674                     }
00675                   else
00676                     {
00677                       sp_off = align_up (sp_off, 4);
00678                       if (write_pass)
00679                         write_memory (sp + sp_off, arg_bits, arg_size);
00680                       sp_off += align_up (arg_size, 4);
00681                       arg_size = 0;
00682                     }
00683                 }
00684             }
00685         }
00686     }
00687 
00688   /* Keep track of the stack address prior to pushing the return address.
00689      This is the value that we'll return.  */
00690   cfa = sp;
00691 
00692   /* Push the return address.  */
00693   sp = sp - 4;
00694   write_memory_unsigned_integer (sp, 4, byte_order, bp_addr);
00695 
00696   /* Update the stack pointer.  */
00697   regcache_cooked_write_unsigned (regcache, RX_SP_REGNUM, sp);
00698 
00699   return cfa;
00700 }
00701 
00702 /* Implement the "return_value" gdbarch method.  */
00703 static enum return_value_convention
00704 rx_return_value (struct gdbarch *gdbarch,
00705                  struct value *function,
00706                  struct type *valtype,
00707                  struct regcache *regcache,
00708                  gdb_byte *readbuf, const gdb_byte *writebuf)
00709 {
00710   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00711   ULONGEST valtype_len = TYPE_LENGTH (valtype);
00712 
00713   if (TYPE_LENGTH (valtype) > 16
00714       || ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
00715            || TYPE_CODE (valtype) == TYPE_CODE_UNION)
00716           && TYPE_LENGTH (valtype) % 4 != 0))
00717     return RETURN_VALUE_STRUCT_CONVENTION;
00718 
00719   if (readbuf)
00720     {
00721       ULONGEST u;
00722       int argreg = RX_R1_REGNUM;
00723       int offset = 0;
00724 
00725       while (valtype_len > 0)
00726         {
00727           int len = min (valtype_len, 4);
00728 
00729           regcache_cooked_read_unsigned (regcache, argreg, &u);
00730           store_unsigned_integer (readbuf + offset, len, byte_order, u);
00731           valtype_len -= len;
00732           offset += len;
00733           argreg++;
00734         }
00735     }
00736 
00737   if (writebuf)
00738     {
00739       ULONGEST u;
00740       int argreg = RX_R1_REGNUM;
00741       int offset = 0;
00742 
00743       while (valtype_len > 0)
00744         {
00745           int len = min (valtype_len, 4);
00746 
00747           u = extract_unsigned_integer (writebuf + offset, len, byte_order);
00748           regcache_cooked_write_unsigned (regcache, argreg, u);
00749           valtype_len -= len;
00750           offset += len;
00751           argreg++;
00752         }
00753     }
00754 
00755   return RETURN_VALUE_REGISTER_CONVENTION;
00756 }
00757 
00758 /* Implement the "breakpoint_from_pc" gdbarch method.  */
00759 static const gdb_byte *
00760 rx_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
00761 {
00762   static gdb_byte breakpoint[] = { 0x00 };
00763   *lenptr = sizeof breakpoint;
00764   return breakpoint;
00765 }
00766 
00767 /* Allocate and initialize a gdbarch object.  */
00768 static struct gdbarch *
00769 rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
00770 {
00771   struct gdbarch *gdbarch;
00772   struct gdbarch_tdep *tdep;
00773   int elf_flags;
00774 
00775   /* Extract the elf_flags if available.  */
00776   if (info.abfd != NULL
00777       && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
00778     elf_flags = elf_elfheader (info.abfd)->e_flags;
00779   else
00780     elf_flags = 0;
00781 
00782 
00783   /* Try to find the architecture in the list of already defined
00784      architectures.  */
00785   for (arches = gdbarch_list_lookup_by_info (arches, &info);
00786        arches != NULL;
00787        arches = gdbarch_list_lookup_by_info (arches->next, &info))
00788     {
00789       if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
00790         continue;
00791 
00792       return arches->gdbarch;
00793     }
00794 
00795   /* None found, create a new architecture from the information
00796      provided.  */
00797   tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
00798   gdbarch = gdbarch_alloc (&info, tdep);
00799   tdep->elf_flags = elf_flags;
00800 
00801   set_gdbarch_num_regs (gdbarch, RX_NUM_REGS);
00802   set_gdbarch_num_pseudo_regs (gdbarch, 0);
00803   set_gdbarch_register_name (gdbarch, rx_register_name);
00804   set_gdbarch_register_type (gdbarch, rx_register_type);
00805   set_gdbarch_pc_regnum (gdbarch, RX_PC_REGNUM);
00806   set_gdbarch_sp_regnum (gdbarch, RX_SP_REGNUM);
00807   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
00808   set_gdbarch_decr_pc_after_break (gdbarch, 1);
00809   set_gdbarch_breakpoint_from_pc (gdbarch, rx_breakpoint_from_pc);
00810   set_gdbarch_skip_prologue (gdbarch, rx_skip_prologue);
00811 
00812   set_gdbarch_print_insn (gdbarch, print_insn_rx);
00813 
00814   set_gdbarch_unwind_pc (gdbarch, rx_unwind_pc);
00815   set_gdbarch_unwind_sp (gdbarch, rx_unwind_sp);
00816 
00817   /* Target builtin data types.  */
00818   set_gdbarch_char_signed (gdbarch, 0);
00819   set_gdbarch_short_bit (gdbarch, 16);
00820   set_gdbarch_int_bit (gdbarch, 32);
00821   set_gdbarch_long_bit (gdbarch, 32);
00822   set_gdbarch_long_long_bit (gdbarch, 64);
00823   set_gdbarch_ptr_bit (gdbarch, 32);
00824   set_gdbarch_float_bit (gdbarch, 32);
00825   set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
00826   if (elf_flags & E_FLAG_RX_64BIT_DOUBLES)
00827     {
00828       set_gdbarch_double_bit (gdbarch, 64);
00829       set_gdbarch_long_double_bit (gdbarch, 64);
00830       set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
00831       set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
00832     }
00833   else
00834     {
00835       set_gdbarch_double_bit (gdbarch, 32);
00836       set_gdbarch_long_double_bit (gdbarch, 32);
00837       set_gdbarch_double_format (gdbarch, floatformats_ieee_single);
00838       set_gdbarch_long_double_format (gdbarch, floatformats_ieee_single);
00839     }
00840 
00841   /* Frame unwinding.  */
00842 #if 0
00843   /* Note: The test results are better with the dwarf2 unwinder disabled,
00844      so it's turned off for now.  */
00845   dwarf2_append_unwinders (gdbarch);
00846 #endif
00847   frame_unwind_append_unwinder (gdbarch, &rx_frame_unwind);
00848 
00849   /* Methods for saving / extracting a dummy frame's ID.
00850      The ID's stack address must match the SP value returned by
00851      PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos.  */
00852   set_gdbarch_dummy_id (gdbarch, rx_dummy_id);
00853   set_gdbarch_push_dummy_call (gdbarch, rx_push_dummy_call);
00854   set_gdbarch_return_value (gdbarch, rx_return_value);
00855 
00856   /* Virtual tables.  */
00857   set_gdbarch_vbit_in_delta (gdbarch, 1);
00858 
00859   return gdbarch;
00860 }
00861 
00862 /* -Wmissing-prototypes */
00863 extern initialize_file_ftype _initialize_rx_tdep;
00864 
00865 /* Register the above initialization routine.  */
00866 
00867 void
00868 _initialize_rx_tdep (void)
00869 {
00870   register_gdbarch_init (bfd_arch_rx, rx_gdbarch_init);
00871 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines