GDB (API)
/home/stan/gdb/src/gdb/tilegx-linux-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for GNU/Linux on Tilera TILE-Gx processors.
00002 
00003    Copyright (C) 2012-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 "osabi.h"
00022 #include "linux-tdep.h"
00023 #include "glibc-tdep.h"
00024 #include "solib-svr4.h"
00025 #include "symtab.h"
00026 #include "regcache.h"
00027 #include "regset.h"
00028 #include "tramp-frame.h"
00029 #include "trad-frame.h"
00030 #include "tilegx-tdep.h"
00031 
00032 /* Signal trampoline support.  */
00033 
00034 static void
00035 tilegx_linux_sigframe_init (const struct tramp_frame *self,
00036                             struct frame_info *this_frame,
00037                             struct trad_frame_cache *this_cache,
00038                             CORE_ADDR func)
00039 {
00040   CORE_ADDR pc = get_frame_register_unsigned (this_frame, 64);
00041   CORE_ADDR sp = get_frame_register_unsigned (this_frame, 54);
00042 
00043   /* Base address of register save area.  */
00044   CORE_ADDR base = sp
00045                    + 16    /* Skip ABI_SAVE_AREA.  */
00046                    + 128   /* Skip SIGINFO.  */
00047                    + 40;   /* Skip UCONTEXT.  */
00048 
00049   /* Address of saved LR register (R56) which holds previous PC.  */
00050   CORE_ADDR prev_pc = base + 56 * 8;
00051 
00052   int i;
00053 
00054   for (i = 0; i < 56; i++)
00055     trad_frame_set_reg_addr (this_cache, i, base + i * 8);
00056 
00057   trad_frame_set_reg_value (this_cache, 64,
00058                             get_frame_memory_unsigned (this_frame, prev_pc, 8));
00059 
00060   /* Save a frame ID.  */
00061   trad_frame_set_id (this_cache, frame_id_build (base, func));
00062 }
00063 
00064 static const struct tramp_frame tilegx_linux_rt_sigframe =
00065 {
00066   SIGTRAMP_FRAME,
00067   8,
00068   {
00069     { 0x00045fe551483000ULL, -1 }, /* { moveli r10, 139 } */
00070     { 0x286b180051485000ULL, -1 }, /* { swint1 } */
00071     { TRAMP_SENTINEL_INSN, -1 }
00072   },
00073   tilegx_linux_sigframe_init
00074 };
00075 
00076 /* Supply raw registers from REGCACHE to REGS.  */
00077 
00078 static void
00079 tilegx_linux_supply_regset (const struct regset *regset,
00080                             struct regcache *regcache,
00081                             int regnum, const void *regs, size_t len)
00082 {
00083   struct gdbarch *arch = get_regcache_arch (regcache);
00084   const char *ptr = regs;
00085   int i;
00086 
00087   /* This logic must match that of struct pt_regs in "ptrace.h".  */
00088   for (i = 0; i < TILEGX_NUM_EASY_REGS + 2; i++, ptr += tilegx_reg_size)
00089     {
00090       int gri = (i < TILEGX_NUM_EASY_REGS)
00091                  ? i : (i == TILEGX_NUM_EASY_REGS)
00092                         ? TILEGX_PC_REGNUM : TILEGX_FAULTNUM_REGNUM;
00093 
00094       if (regnum == gri || regnum == -1)
00095         regcache_raw_supply (regcache, gri, ptr);
00096     }
00097 }
00098 
00099 /* TILE-Gx Linux kernel register set.  */
00100 static struct regset tilegx_linux_regset =
00101 {
00102   NULL,
00103   tilegx_linux_supply_regset
00104 };
00105 
00106 static const struct regset *
00107 tilegx_regset_from_core_section (struct gdbarch *gdbarch,
00108                                  const char *sect_name,
00109                                  size_t sect_size)
00110 {
00111   if (strcmp (sect_name, ".reg") == 0)
00112     return &tilegx_linux_regset;
00113 
00114   return NULL;
00115 }
00116 
00117 /* OS specific initialization of gdbarch.  */
00118 
00119 static void
00120 tilegx_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00121 {
00122   int arch_size = gdbarch_addr_bit (gdbarch);
00123 
00124   linux_init_abi (info, gdbarch);
00125 
00126   tramp_frame_prepend_unwinder (gdbarch, &tilegx_linux_rt_sigframe);
00127 
00128   set_gdbarch_regset_from_core_section (gdbarch,
00129                                         tilegx_regset_from_core_section);
00130 
00131   /* GNU/Linux uses SVR4-style shared libraries.  */
00132   if (arch_size == 32)
00133     set_solib_svr4_fetch_link_map_offsets (gdbarch,
00134                                            svr4_ilp32_fetch_link_map_offsets);
00135   else
00136     set_solib_svr4_fetch_link_map_offsets (gdbarch,
00137                                            svr4_lp64_fetch_link_map_offsets);
00138 
00139   /* Enable TLS support.  */
00140   set_gdbarch_fetch_tls_load_module_address (gdbarch,
00141                                              svr4_fetch_objfile_link_map);
00142 
00143   /* Shared library handling.  */
00144   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
00145   set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
00146 
00147   set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
00148 }
00149 
00150 /* Provide a prototype to silence -Wmissing-prototypes.  */
00151 extern initialize_file_ftype _initialize_tilegx_linux_tdep;
00152 
00153 void
00154 _initialize_tilegx_linux_tdep (void)
00155 {
00156   gdbarch_register_osabi (bfd_arch_tilegx, bfd_mach_tilegx, GDB_OSABI_LINUX,
00157                           tilegx_linux_init_abi);
00158 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines