2012-05-07 Sergio Durigan Junior <sergiodj@redhat.com>
[binutils-gdb.git] / gdb / moxie-tdep.c
index 3ce9b406ee2df35cc267964f76c8b4374704cdea..1f5f33f2428bfc90d948f920fd5aad545aa74b30 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for Moxie.
 
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -145,10 +145,9 @@ moxie_store_return_value (struct type *type, struct regcache *regcache,
 
 static CORE_ADDR
 moxie_analyze_prologue (CORE_ADDR start_addr, CORE_ADDR end_addr,
-                     struct moxie_frame_cache *cache,
-                     struct frame_info *this_frame)
+                       struct moxie_frame_cache *cache,
+                       struct gdbarch *gdbarch)
 {
-  struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR next_addr;
   ULONGEST inst, inst2;
@@ -175,23 +174,39 @@ moxie_analyze_prologue (CORE_ADDR start_addr, CORE_ADDR end_addr,
          cache->saved_regs[regnum] = cache->framesize;
          next_addr += 2;
        }
+      else
+       break;
+    }
 
-      /* Optional stack allocation for args and local vars <= 4
-        byte.  */
-      else if (inst == 0x01f0)           /* ldi.l $r12, X */
-       {
-         offset = read_memory_integer (next_addr + 2, 4, byte_order);
-         inst2 = read_memory_unsigned_integer (next_addr + 6, 2, byte_order);
+  inst = read_memory_unsigned_integer (next_addr, 2, byte_order);
 
-         if (inst2 == 0x051f)           /* add.l $sp, $r12 */
-           {
-             cache->framesize += offset;
-           }
+  /* Optional stack allocation for args and local vars <= 4
+     byte.  */
+  if (inst == 0x0170)           /* ldi.l $r5, X */
+    {
+      offset = read_memory_integer (next_addr + 2, 4, byte_order);
+      inst2 = read_memory_unsigned_integer (next_addr + 6, 2, byte_order);
+      
+      if (inst2 == 0x0517)           /* add.l $sp, $r5 */
+       {
+         cache->framesize += offset;
+       }
+      
+      return (next_addr + 8);
+    }
+  else if ((inst & 0xff00) == 0x91)   /* dec $sp, X */
+    {
+      cache->framesize += (inst & 0x00ff);
+      next_addr += 2;
 
-         return (next_addr + 8);
+      while (next_addr < end_addr)
+       {
+         inst = read_memory_unsigned_integer (next_addr, 2, byte_order);
+         if ((inst & 0xff00) != 0x91) /* no more dec $sp, X */
+           break;
+         cache->framesize += (inst & 0x00ff);
+         next_addr += 2;
        }
-      else  /* This is not a prologue instruction.  */
-       break;
     }
 
   return next_addr;
@@ -203,7 +218,7 @@ static CORE_ADDR
 moxie_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   CORE_ADDR func_addr = 0, func_end = 0;
-  char *func_name;
+  const char *func_name;
 
   /* See if we can determine the end of the prologue via the symbol table.
      If so, then return either PC, or the PC after the prologue, whichever
@@ -226,11 +241,11 @@ moxie_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
          memset (&cache, 0, sizeof cache);
          
          plg_end = moxie_analyze_prologue (func_addr, 
-                                           func_end, &cache, NULL);
+                                           func_end, &cache, gdbarch);
          /* Found a function.  */
          sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL);
          /* Don't use line number debug info for assembly source
-            files. */
+            files.  */
          if (sym && SYMBOL_LANGUAGE (sym) != language_asm)
            {
              sal = find_pc_line (func_addr, 0);
@@ -384,7 +399,10 @@ moxie_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache->pc = get_frame_func (this_frame);
   current_pc = get_frame_pc (this_frame);
   if (cache->pc)
-    moxie_analyze_prologue (cache->pc, current_pc, cache, this_frame);
+    {
+      struct gdbarch *gdbarch = get_frame_arch (this_frame);
+      moxie_analyze_prologue (cache->pc, current_pc, cache, gdbarch);
+    }
 
   cache->saved_sp = cache->base - cache->framesize;
 
@@ -443,6 +461,7 @@ moxie_frame_prev_register (struct frame_info *this_frame,
 
 static const struct frame_unwind moxie_frame_unwind = {
   NORMAL_FRAME,
+  default_frame_unwind_stop_reason,
   moxie_frame_this_id,
   moxie_frame_prev_register,
   NULL,
@@ -495,9 +514,9 @@ moxie_process_readu (CORE_ADDR addr, char *buf,
 
 /* Parse the current instruction and record the values of the registers and
    memory that will be changed in current instruction to "record_arch_list".
-   Return -1 if something wrong. */
+   Return -1 if something wrong.  */
 
-int
+static int
 moxie_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
                      CORE_ADDR addr)
 {
@@ -830,7 +849,7 @@ moxie_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
                  ptr = extract_unsigned_integer ((gdb_byte *) & ptr, 
                                                  4, byte_order);
 
-                 /* String length is at 0x12($fp) */
+                 /* String length is at 0x12($fp) */
                  regcache_raw_read (regcache, 
                                     MOXIE_FP_REGNUM, (gdb_byte *) & tmpu32);
                  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,