GDB (API)
/home/stan/gdb/src/gdb/microblaze-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for Xilinx MicroBlaze.
00002 
00003    Copyright (C) 2009-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "arch-utils.h"
00022 #include "dis-asm.h"
00023 #include "frame.h"
00024 #include "trad-frame.h"
00025 #include "symtab.h"
00026 #include "value.h"
00027 #include "gdbcmd.h"
00028 #include "breakpoint.h"
00029 #include "inferior.h"
00030 #include "regcache.h"
00031 #include "target.h"
00032 #include "frame.h"
00033 #include "frame-base.h"
00034 #include "frame-unwind.h"
00035 #include "dwarf2-frame.h"
00036 #include "osabi.h"
00037 
00038 #include "gdb_assert.h"
00039 #include "gdb_string.h"
00040 #include "target-descriptions.h"
00041 #include "opcodes/microblaze-opcm.h"
00042 #include "opcodes/microblaze-dis.h"
00043 #include "microblaze-tdep.h"
00044 
00045 /* Instruction macros used for analyzing the prologue.  */
00046 /* This set of instruction macros need to be changed whenever the
00047    prologue generated by the compiler could have more instructions or
00048    different type of instructions.
00049    This set also needs to be verified if it is complete.  */
00050 #define IS_RETURN(op) (op == rtsd || op == rtid)
00051 #define IS_UPDATE_SP(op, rd, ra) \
00052   ((op == addik || op == addi) && rd == REG_SP && ra == REG_SP)
00053 #define IS_SPILL_SP(op, rd, ra) \
00054   ((op == swi || op == sw) && rd == REG_SP && ra == REG_SP)
00055 #define IS_SPILL_REG(op, rd, ra) \
00056   ((op == swi || op == sw) && rd != REG_SP && ra == REG_SP)
00057 #define IS_ALSO_SPILL_REG(op, rd, ra, rb) \
00058   ((op == swi || op == sw) && rd != REG_SP && ra == 0 && rb == REG_SP)
00059 #define IS_SETUP_FP(op, ra, rb) \
00060   ((op == add || op == addik || op == addk) && ra == REG_SP && rb == 0)
00061 #define IS_SPILL_REG_FP(op, rd, ra, fpregnum) \
00062   ((op == swi || op == sw) && rd != REG_SP && ra == fpregnum && ra != 0)
00063 #define IS_SAVE_HIDDEN_PTR(op, rd, ra, rb) \
00064   ((op == add || op == addik) && ra == MICROBLAZE_FIRST_ARGREG && rb == 0)
00065 
00066 /* The registers of the Xilinx microblaze processor.  */
00067 
00068 static const char *microblaze_register_names[] =
00069 {
00070   "r0",   "r1",  "r2",    "r3",   "r4",   "r5",   "r6",   "r7",
00071   "r8",   "r9",  "r10",   "r11",  "r12",  "r13",  "r14",  "r15",
00072   "r16",  "r17", "r18",   "r19",  "r20",  "r21",  "r22",  "r23",
00073   "r24",  "r25", "r26",   "r27",  "r28",  "r29",  "r30",  "r31",
00074   "rpc",  "rmsr", "rear", "resr", "rfsr", "rbtr",
00075   "rpvr0", "rpvr1", "rpvr2", "rpvr3", "rpvr4", "rpvr5", "rpvr6",
00076   "rpvr7", "rpvr8", "rpvr9", "rpvr10", "rpvr11",
00077   "redr", "rpid", "rzpr", "rtlbx", "rtlbsx", "rtlblo", "rtlbhi"
00078 };
00079 
00080 #define MICROBLAZE_NUM_REGS ARRAY_SIZE (microblaze_register_names)
00081 
00082 static unsigned int microblaze_debug_flag = 0;
00083 
00084 static void
00085 microblaze_debug (const char *fmt, ...)
00086 { 
00087   if (microblaze_debug_flag)
00088     {
00089        va_list args;
00090 
00091        va_start (args, fmt);
00092        printf_unfiltered ("MICROBLAZE: ");
00093        vprintf_unfiltered (fmt, args);
00094        va_end (args);
00095     }
00096 }
00097 
00098 /* Return the name of register REGNUM.  */
00099 
00100 static const char *
00101 microblaze_register_name (struct gdbarch *gdbarch, int regnum)
00102 {
00103   if (regnum >= 0 && regnum < MICROBLAZE_NUM_REGS)
00104     return microblaze_register_names[regnum];
00105   return NULL;
00106 }
00107 
00108 static struct type *
00109 microblaze_register_type (struct gdbarch *gdbarch, int regnum)
00110 {
00111   if (regnum == MICROBLAZE_SP_REGNUM)
00112     return builtin_type (gdbarch)->builtin_data_ptr;
00113 
00114   if (regnum == MICROBLAZE_PC_REGNUM)
00115     return builtin_type (gdbarch)->builtin_func_ptr;
00116 
00117   return builtin_type (gdbarch)->builtin_int;
00118 }
00119 
00120 
00121 /* Fetch the instruction at PC.  */
00122 
00123 static unsigned long
00124 microblaze_fetch_instruction (CORE_ADDR pc)
00125 {
00126   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
00127   gdb_byte buf[4];
00128 
00129   /* If we can't read the instruction at PC, return zero.  */
00130   if (target_read_memory (pc, buf, sizeof (buf)))
00131     return 0;
00132 
00133   return extract_unsigned_integer (buf, 4, byte_order);
00134 }
00135 
00136 
00137 static CORE_ADDR
00138 microblaze_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
00139                             CORE_ADDR funcaddr,
00140                             struct value **args, int nargs,
00141                             struct type *value_type,
00142                             CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
00143                             struct regcache *regcache)
00144 {
00145   error (_("push_dummy_code not implemented"));
00146   return sp;
00147 }
00148 
00149 
00150 static CORE_ADDR
00151 microblaze_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
00152                             struct regcache *regcache, CORE_ADDR bp_addr,
00153                             int nargs, struct value **args, CORE_ADDR sp,
00154                             int struct_return, CORE_ADDR struct_addr)
00155 {
00156   error (_("store_arguments not implemented"));
00157   return sp;
00158 }
00159 
00160 static const gdb_byte *
00161 microblaze_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, 
00162                                int *len)
00163 {
00164   static gdb_byte break_insn[] = MICROBLAZE_BREAKPOINT;
00165 
00166   *len = sizeof (break_insn);
00167   return break_insn;
00168 }
00169 
00170 /* Allocate and initialize a frame cache.  */
00171 
00172 static struct microblaze_frame_cache *
00173 microblaze_alloc_frame_cache (void)
00174 {
00175   struct microblaze_frame_cache *cache;
00176 
00177   cache = FRAME_OBSTACK_ZALLOC (struct microblaze_frame_cache);
00178 
00179   /* Base address.  */
00180   cache->base = 0;
00181   cache->pc = 0;
00182 
00183   /* Frameless until proven otherwise.  */
00184   cache->frameless_p = 1;
00185 
00186   return cache;
00187 }
00188 
00189 /* The base of the current frame is actually in the stack pointer.
00190    This happens when there is no frame pointer (microblaze ABI does not
00191    require a frame pointer) or when we're stopped in the prologue or
00192    epilogue itself.  In these cases, microblaze_analyze_prologue will need
00193    to update fi->frame before returning or analyzing the register
00194    save instructions.  */
00195 #define MICROBLAZE_MY_FRAME_IN_SP 0x1
00196 
00197 /* The base of the current frame is in a frame pointer register.
00198    This register is noted in frame_extra_info->fp_regnum.
00199 
00200    Note that the existance of an FP might also indicate that the
00201    function has called alloca.  */
00202 #define MICROBLAZE_MY_FRAME_IN_FP 0x2
00203 
00204 /* Function prologues on the Xilinx microblaze processors consist of:
00205 
00206    - adjustments to the stack pointer (r1) (addi r1, r1, imm)
00207    - making a copy of r1 into another register (a "frame" pointer)
00208      (add r?, r1, r0)
00209    - store word/multiples that use r1 or the frame pointer as the
00210      base address (swi r?, r1, imm OR swi r?, fp, imm)
00211 
00212    Note that microblaze really doesn't have a real frame pointer.
00213    Instead, the compiler may copy the SP into a register (usually
00214    r19) to act as an arg pointer.  For our target-dependent purposes,
00215    the frame info's "frame" member will be the beginning of the
00216    frame.  The SP could, in fact, point below this.
00217 
00218    The prologue ends when an instruction fails to meet either of
00219    these criteria.  */
00220 
00221 /* Analyze the prologue to determine where registers are saved,
00222    the end of the prologue, etc.  Return the address of the first line
00223    of "real" code (i.e., the end of the prologue).  */
00224 
00225 static CORE_ADDR
00226 microblaze_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, 
00227                              CORE_ADDR current_pc,
00228                              struct microblaze_frame_cache *cache)
00229 {
00230   const char *name;
00231   CORE_ADDR func_addr, func_end, addr, stop, prologue_end_addr = 0;
00232   unsigned long insn;
00233   int rd, ra, rb, imm;
00234   enum microblaze_instr op;
00235   int flags = 0;
00236   int save_hidden_pointer_found = 0;
00237   int non_stack_instruction_found = 0;
00238 
00239   /* Find the start of this function.  */
00240   find_pc_partial_function (pc, &name, &func_addr, &func_end);
00241   if (func_addr < pc)
00242     pc = func_addr;
00243 
00244   if (current_pc < pc)
00245     return current_pc;
00246 
00247    /* Initialize info about frame.  */
00248    cache->framesize = 0;
00249    cache->fp_regnum = MICROBLAZE_SP_REGNUM;
00250    cache->frameless_p = 1;
00251 
00252   /* Start decoding the prologue.  We start by checking two special cases:
00253 
00254      1. We're about to return
00255      2. We're at the first insn of the prologue.
00256 
00257      If we're about to return, our frame has already been deallocated.
00258      If we are stopped at the first instruction of a prologue,
00259      then our frame has not yet been set up.  */
00260 
00261   /* Get the first insn from memory.  */
00262 
00263   insn = microblaze_fetch_instruction (pc);
00264   op = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm);
00265 
00266   if (IS_RETURN(op))
00267     return pc;
00268 
00269   /* Start at beginning of function and analyze until we get to the
00270      current pc, or the end of the function, whichever is first.  */
00271   stop = (current_pc < func_end ? current_pc : func_end);
00272 
00273   microblaze_debug ("Scanning prologue: name=%s, func_addr=%s, stop=%s\n", 
00274                     name, paddress (gdbarch, func_addr), 
00275                     paddress (gdbarch, stop));
00276 
00277   for (addr = func_addr; addr < stop; addr += INST_WORD_SIZE)
00278     {
00279       insn = microblaze_fetch_instruction (addr);
00280       op = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm);
00281       microblaze_debug ("%s %08lx\n", paddress (gdbarch, pc), insn);
00282 
00283       /* This code is very sensitive to what functions are present in the
00284          prologue.  It assumes that the (addi, addik, swi, sw) can be the 
00285          only instructions in the prologue.  */
00286       if (IS_UPDATE_SP(op, rd, ra))
00287         {
00288           microblaze_debug ("got addi r1,r1,%d; contnuing\n", imm);
00289           if (cache->framesize)
00290             break;      /* break if framesize already computed.  */
00291           cache->framesize = -imm; /* stack grows towards low memory.  */
00292           cache->frameless_p = 0; /* Frame found.  */
00293           save_hidden_pointer_found = 0;
00294           non_stack_instruction_found = 0;
00295           continue;
00296         }
00297       else if (IS_SPILL_SP(op, rd, ra))
00298         {
00299           /* Spill stack pointer.  */
00300           cache->register_offsets[rd] = imm; /* SP spilled before updating.  */
00301 
00302           microblaze_debug ("swi r1 r1 %d, continuing\n", imm);
00303           save_hidden_pointer_found = 0;
00304           if (!cache->framesize)
00305             non_stack_instruction_found = 0;
00306           continue;
00307         }
00308       else if (IS_SPILL_REG(op, rd, ra))
00309         {
00310           /* Spill register.  */
00311           cache->register_offsets[rd] = imm - cache->framesize;
00312 
00313           microblaze_debug ("swi %d r1 %d, continuing\n", rd, imm);
00314           save_hidden_pointer_found = 0;
00315           if (!cache->framesize)
00316             non_stack_instruction_found = 0;
00317           continue;
00318         }
00319       else if (IS_ALSO_SPILL_REG(op, rd, ra, rb))
00320         {
00321           /* Spill register.  */
00322           cache->register_offsets[rd] = 0 - cache->framesize;
00323 
00324           microblaze_debug ("sw %d r0 r1, continuing\n", rd);
00325           save_hidden_pointer_found = 0;
00326           if (!cache->framesize)
00327             non_stack_instruction_found = 0;
00328           continue;
00329         }
00330       else if (IS_SETUP_FP(op, ra, rb))
00331         {
00332           /* We have a frame pointer.  Note the register which is 
00333              acting as the frame pointer.  */
00334           flags |= MICROBLAZE_MY_FRAME_IN_FP;
00335           flags &= ~MICROBLAZE_MY_FRAME_IN_SP;
00336           cache->fp_regnum = rd;
00337           microblaze_debug ("Found a frame pointer: r%d\n", cache->fp_regnum);
00338           save_hidden_pointer_found = 0;
00339           if (!cache->framesize)
00340             non_stack_instruction_found = 0;
00341           continue;
00342         }
00343       else if (IS_SPILL_REG_FP(op, rd, ra, cache->fp_regnum))
00344         {
00345           /* reg spilled after updating.  */
00346           cache->register_offsets[rd] = imm - cache->framesize;
00347 
00348           microblaze_debug ("swi %d %d %d, continuing\n", rd, ra, imm);
00349           save_hidden_pointer_found = 0;
00350           if (!cache->framesize)
00351             non_stack_instruction_found = 0;
00352           continue;
00353         }
00354       else if (IS_SAVE_HIDDEN_PTR(op, rd, ra, rb))
00355         {
00356           /* If the first argument is a hidden pointer to the area where the
00357              return structure is to be saved, then it is saved as part of the
00358              prologue.  */
00359 
00360           microblaze_debug ("add %d %d %d, continuing\n", rd, ra, rb);
00361           save_hidden_pointer_found = 1;
00362           if (!cache->framesize)
00363             non_stack_instruction_found = 0;
00364           continue;
00365         }
00366 
00367       /* As a result of the modification in the next step where we continue
00368          to analyze the prologue till we reach a control flow instruction,
00369          we need another variable to store when exactly a non-stack
00370          instruction was encountered, which is the current definition
00371          of a prologue.  */
00372       if (!non_stack_instruction_found)
00373         prologue_end_addr = addr;
00374       non_stack_instruction_found = 1;
00375 
00376       /* When optimizations are enabled, it is not guaranteed that prologue
00377          instructions are not mixed in with other instructions from the
00378          program.  Some programs show this behavior at -O2.  This can be
00379          avoided by adding -fno-schedule-insns2 switch as of now (edk 8.1)
00380          In such cases, we scan the function until we see the first control
00381          instruction.  */
00382 
00383       {
00384         unsigned op = (unsigned)insn >> 26;
00385 
00386         /* continue if not control flow (branch, return).  */
00387         if (op != 0x26 && op != 0x27 && op != 0x2d && op != 0x2e && op != 0x2f)
00388           continue;
00389         else if (op == 0x2c)
00390           continue;    /* continue if imm.  */
00391       }
00392 
00393       /* This is not a prologue insn, so stop here.  */
00394       microblaze_debug ("insn is not a prologue insn -- ending scan\n");
00395       break;
00396     }
00397 
00398   microblaze_debug ("done analyzing prologue\n");
00399   microblaze_debug ("prologue end = 0x%x\n", (int) addr);
00400 
00401   /* If the last instruction was an add rd, r5, r0 then don't count it as
00402      part of the prologue.  */
00403   if (save_hidden_pointer_found)
00404     prologue_end_addr -= INST_WORD_SIZE;
00405 
00406   return prologue_end_addr;
00407 }
00408 
00409 static CORE_ADDR
00410 microblaze_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
00411 {
00412   gdb_byte buf[4];
00413   CORE_ADDR pc;
00414 
00415   frame_unwind_register (next_frame, MICROBLAZE_PC_REGNUM, buf);
00416   pc = extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
00417   /* For sentinel frame, return address is actual PC.  For other frames,
00418      return address is pc+8.  This is a workaround because gcc does not
00419      generate correct return address in CIE.  */
00420   if (frame_relative_level (next_frame) >= 0)
00421     pc += 8;
00422   return pc;
00423 }
00424 
00425 /* Return PC of first real instruction of the function starting at
00426    START_PC.  */
00427 
00428 static CORE_ADDR
00429 microblaze_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
00430 {
00431   struct symtab_and_line sal;
00432   CORE_ADDR func_start, func_end, ostart_pc;
00433   struct microblaze_frame_cache cache;
00434 
00435   /* This is the preferred method, find the end of the prologue by
00436      using the debugging information.  Debugging info does not always
00437      give the right answer since parameters are stored on stack after this.
00438      Always analyze the prologue.  */
00439   if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end))
00440     {
00441       sal = find_pc_line (func_start, 0);
00442 
00443       if (sal.end < func_end
00444           && start_pc <= sal.end)
00445         start_pc = sal.end;
00446     }
00447 
00448   ostart_pc = microblaze_analyze_prologue (gdbarch, func_start, 0xffffffffUL, 
00449                                            &cache);
00450 
00451   if (ostart_pc > start_pc)
00452     return ostart_pc;
00453   return start_pc;
00454 }
00455 
00456 /* Normal frames.  */
00457 
00458 static struct microblaze_frame_cache *
00459 microblaze_frame_cache (struct frame_info *next_frame, void **this_cache)
00460 {
00461   struct microblaze_frame_cache *cache;
00462   struct gdbarch *gdbarch = get_frame_arch (next_frame);
00463   CORE_ADDR func;
00464   int rn;
00465 
00466   if (*this_cache)
00467     return *this_cache;
00468 
00469   cache = microblaze_alloc_frame_cache ();
00470   *this_cache = cache;
00471   cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
00472 
00473   /* Clear offsets to saved regs in frame.  */
00474   for (rn = 0; rn < gdbarch_num_regs (gdbarch); rn++)
00475     cache->register_offsets[rn] = -1;
00476 
00477   func = get_frame_func (next_frame);
00478 
00479   cache->pc = get_frame_address_in_block (next_frame);
00480 
00481   return cache;
00482 }
00483 
00484 static void
00485 microblaze_frame_this_id (struct frame_info *next_frame, void **this_cache,
00486                        struct frame_id *this_id)
00487 {
00488   struct microblaze_frame_cache *cache =
00489     microblaze_frame_cache (next_frame, this_cache);
00490 
00491   /* This marks the outermost frame.  */
00492   if (cache->base == 0)
00493     return;
00494 
00495   (*this_id) = frame_id_build (cache->base, cache->pc);
00496 }
00497 
00498 static struct value *
00499 microblaze_frame_prev_register (struct frame_info *this_frame,
00500                                  void **this_cache, int regnum)
00501 {
00502   struct microblaze_frame_cache *cache =
00503     microblaze_frame_cache (this_frame, this_cache);
00504 
00505   if (cache->frameless_p)
00506     {
00507       if (regnum == MICROBLAZE_PC_REGNUM)
00508         regnum = 15;
00509       if (regnum == MICROBLAZE_SP_REGNUM)
00510         regnum = 1;
00511       return trad_frame_get_prev_register (this_frame,
00512                                            cache->saved_regs, regnum);
00513     }
00514   else
00515     return trad_frame_get_prev_register (this_frame, cache->saved_regs,
00516                                          regnum);
00517 
00518 }
00519 
00520 static const struct frame_unwind microblaze_frame_unwind =
00521 {
00522   NORMAL_FRAME,
00523   default_frame_unwind_stop_reason,
00524   microblaze_frame_this_id,
00525   microblaze_frame_prev_register,
00526   NULL,
00527   default_frame_sniffer
00528 };
00529 
00530 static CORE_ADDR
00531 microblaze_frame_base_address (struct frame_info *next_frame,
00532                                void **this_cache)
00533 {
00534   struct microblaze_frame_cache *cache =
00535     microblaze_frame_cache (next_frame, this_cache);
00536 
00537   return cache->base;
00538 }
00539 
00540 static const struct frame_base microblaze_frame_base =
00541 {
00542   &microblaze_frame_unwind,
00543   microblaze_frame_base_address,
00544   microblaze_frame_base_address,
00545   microblaze_frame_base_address
00546 };
00547 
00548 /* Extract from an array REGBUF containing the (raw) register state, a
00549    function return value of TYPE, and copy that into VALBUF.  */
00550 static void
00551 microblaze_extract_return_value (struct type *type, struct regcache *regcache,
00552                                  gdb_byte *valbuf)
00553 {
00554   gdb_byte buf[8];
00555 
00556   /* Copy the return value (starting) in RETVAL_REGNUM to VALBUF.  */
00557   switch (TYPE_LENGTH (type))
00558     {
00559       case 1:   /* return last byte in the register.  */
00560         regcache_cooked_read (regcache, MICROBLAZE_RETVAL_REGNUM, buf);
00561         memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 1, 1);
00562         return;
00563       case 2:   /* return last 2 bytes in register.  */
00564         regcache_cooked_read (regcache, MICROBLAZE_RETVAL_REGNUM, buf);
00565         memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 2, 2);
00566         return;
00567       case 4:   /* for sizes 4 or 8, copy the required length.  */
00568       case 8:
00569         regcache_cooked_read (regcache, MICROBLAZE_RETVAL_REGNUM, buf);
00570         regcache_cooked_read (regcache, MICROBLAZE_RETVAL_REGNUM+1, buf+4);
00571         memcpy (valbuf, buf, TYPE_LENGTH (type));
00572         return;
00573       default:
00574         internal_error (__FILE__, __LINE__, 
00575                         _("Unsupported return value size requested"));
00576     }
00577 }
00578 
00579 /* Store the return value in VALBUF (of type TYPE) where the caller
00580    expects to see it.
00581 
00582    Integers up to four bytes are stored in r3.
00583 
00584    Longs are stored in r3 (most significant word) and r4 (least
00585    significant word).
00586 
00587    Small structures are always returned on stack.  */
00588 
00589 static void
00590 microblaze_store_return_value (struct type *type, struct regcache *regcache,
00591                                const gdb_byte *valbuf)
00592 {
00593   int len = TYPE_LENGTH (type);
00594   gdb_byte buf[8];
00595 
00596   memset (buf, 0, sizeof(buf));
00597 
00598   /* Integral and pointer return values.  */
00599 
00600   if (len > 4)
00601     {
00602        gdb_assert (len == 8);
00603        memcpy (buf, valbuf, 8);
00604        regcache_cooked_write (regcache, MICROBLAZE_RETVAL_REGNUM+1, buf + 4);
00605     }
00606   else
00607     /* ??? Do we need to do any sign-extension here?  */
00608     memcpy (buf + 4 - len, valbuf, len);
00609 
00610   regcache_cooked_write (regcache, MICROBLAZE_RETVAL_REGNUM, buf);
00611 }
00612 
00613 static enum return_value_convention
00614 microblaze_return_value (struct gdbarch *gdbarch, struct value *function,
00615                          struct type *type, struct regcache *regcache,
00616                          gdb_byte *readbuf, const gdb_byte *writebuf)
00617 {
00618   if (readbuf)
00619     microblaze_extract_return_value (type, regcache, readbuf);
00620   if (writebuf)
00621     microblaze_store_return_value (type, regcache, writebuf);
00622 
00623   return RETURN_VALUE_REGISTER_CONVENTION;
00624 }
00625 
00626 static int
00627 microblaze_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
00628 {
00629   return (TYPE_LENGTH (type) == 16);
00630 }
00631 
00632 static void
00633 microblaze_write_pc (struct regcache *regcache, CORE_ADDR pc)
00634 {
00635   regcache_cooked_write_unsigned (regcache, MICROBLAZE_PC_REGNUM, pc);
00636 }
00637 
00638 static int dwarf2_to_reg_map[78] =
00639 { 0  /* r0  */,   1  /* r1  */,   2  /* r2  */,   3  /* r3  */,  /*  0- 3 */
00640   4  /* r4  */,   5  /* r5  */,   6  /* r6  */,   7  /* r7  */,  /*  4- 7 */
00641   8  /* r8  */,   9  /* r9  */,  10  /* r10 */,  11  /* r11 */,  /*  8-11 */
00642   12 /* r12 */,  13  /* r13 */,  14  /* r14 */,  15  /* r15 */,  /* 12-15 */
00643   16 /* r16 */,  17  /* r17 */,  18  /* r18 */,  19  /* r19 */,  /* 16-19 */
00644   20 /* r20 */,  21  /* r21 */,  22  /* r22 */,  23  /* r23 */,  /* 20-23 */
00645   24 /* r24 */,  25  /* r25 */,  26  /* r26 */,  27  /* r27 */,  /* 24-25 */
00646   28 /* r28 */,  29  /* r29 */,  30  /* r30 */,  31  /* r31 */,  /* 28-31 */
00647   -1 /* $f0 */,  -1  /* $f1 */,  -1  /* $f2 */,  -1  /* $f3 */,  /* 32-35 */
00648   -1 /* $f4 */,  -1  /* $f5 */,  -1  /* $f6 */,  -1  /* $f7 */,  /* 36-39 */
00649   -1 /* $f8 */,  -1  /* $f9 */,  -1  /* $f10 */, -1  /* $f11 */, /* 40-43 */
00650   -1 /* $f12 */, -1  /* $f13 */, -1  /* $f14 */, -1  /* $f15 */, /* 44-47 */
00651   -1 /* $f16 */, -1  /* $f17 */, -1  /* $f18 */, -1  /* $f19 */, /* 48-51 */
00652   -1 /* $f20 */, -1  /* $f21 */, -1  /* $f22 */, -1  /* $f23 */, /* 52-55 */
00653   -1 /* $f24 */, -1  /* $f25 */, -1  /* $f26 */, -1  /* $f27 */, /* 56-59 */
00654   -1 /* $f28 */, -1  /* $f29 */, -1  /* $f30 */, -1  /* $f31 */, /* 60-63 */
00655   -1 /* hi   */, -1  /* lo   */, -1  /* accum*/, 33  /* rmsr */, /* 64-67 */
00656   -1 /* $fcc1*/, -1  /* $fcc2*/, -1  /* $fcc3*/, -1  /* $fcc4*/, /* 68-71 */
00657   -1 /* $fcc5*/, -1  /* $fcc6*/, -1  /* $fcc7*/, -1  /* $ap  */, /* 72-75 */
00658   -1 /* $rap */, -1  /* $frp */                                  /* 76-77 */
00659 };
00660 
00661 static int
00662 microblaze_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
00663 {
00664   gdb_assert (reg < sizeof (dwarf2_to_reg_map));
00665   return dwarf2_to_reg_map[reg];
00666 }
00667 
00668 static struct gdbarch *
00669 microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
00670 {
00671   struct gdbarch_tdep *tdep;
00672   struct gdbarch *gdbarch;
00673 
00674   /* If there is already a candidate, use it.  */
00675   arches = gdbarch_list_lookup_by_info (arches, &info);
00676   if (arches != NULL)
00677     return arches->gdbarch;
00678 
00679   /* Allocate space for the new architecture.  */
00680   tdep = XMALLOC (struct gdbarch_tdep);
00681   gdbarch = gdbarch_alloc (&info, tdep);
00682 
00683   set_gdbarch_long_double_bit (gdbarch, 128);
00684 
00685   set_gdbarch_num_regs (gdbarch, MICROBLAZE_NUM_REGS);
00686   set_gdbarch_register_name (gdbarch, microblaze_register_name);
00687   set_gdbarch_register_type (gdbarch, microblaze_register_type);
00688 
00689   /* Register numbers of various important registers.  */
00690   set_gdbarch_sp_regnum (gdbarch, MICROBLAZE_SP_REGNUM); 
00691   set_gdbarch_pc_regnum (gdbarch, MICROBLAZE_PC_REGNUM); 
00692 
00693   /* Map Dwarf2 registers to GDB registers.  */
00694   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, microblaze_dwarf2_reg_to_regnum);
00695 
00696   /* Call dummy code.  */
00697   set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
00698   set_gdbarch_push_dummy_code (gdbarch, microblaze_push_dummy_code);
00699   set_gdbarch_push_dummy_call (gdbarch, microblaze_push_dummy_call);
00700 
00701   set_gdbarch_return_value (gdbarch, microblaze_return_value);
00702   set_gdbarch_stabs_argument_has_addr
00703     (gdbarch, microblaze_stabs_argument_has_addr);
00704 
00705   set_gdbarch_skip_prologue (gdbarch, microblaze_skip_prologue);
00706 
00707   /* Stack grows downward.  */
00708   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
00709 
00710   set_gdbarch_breakpoint_from_pc (gdbarch, microblaze_breakpoint_from_pc);
00711 
00712   set_gdbarch_frame_args_skip (gdbarch, 8);
00713 
00714   set_gdbarch_print_insn (gdbarch, print_insn_microblaze);
00715 
00716   set_gdbarch_write_pc (gdbarch, microblaze_write_pc);
00717 
00718   set_gdbarch_unwind_pc (gdbarch, microblaze_unwind_pc);
00719 
00720   frame_base_set_default (gdbarch, &microblaze_frame_base);
00721 
00722   /* Hook in ABI-specific overrides, if they have been registered.  */
00723   gdbarch_init_osabi (info, gdbarch);
00724 
00725   /* Unwind the frame.  */
00726   dwarf2_append_unwinders (gdbarch);
00727   frame_unwind_append_unwinder (gdbarch, &microblaze_frame_unwind);
00728   frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
00729 
00730   return gdbarch;
00731 }
00732 
00733 /* Provide a prototype to silence -Wmissing-prototypes.  */
00734 void _initialize_microblaze_tdep (void);
00735 
00736 void
00737 _initialize_microblaze_tdep (void)
00738 {
00739   register_gdbarch_init (bfd_arch_microblaze, microblaze_gdbarch_init);
00740 
00741   /* Debug this files internals.  */
00742   add_setshow_zuinteger_cmd ("microblaze", class_maintenance,
00743                              &microblaze_debug_flag, _("\
00744 Set microblaze debugging."), _("\
00745 Show microblaze debugging."), _("\
00746 When non-zero, microblaze specific debugging is enabled."),
00747                              NULL,
00748                              NULL,
00749                              &setdebuglist, &showdebuglist);
00750 
00751 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines