GDBserver
|
00001 /* Target dependent code for GDB on TI C6x systems. 00002 00003 Copyright (C) 2010-2013 Free Software Foundation, Inc. 00004 Contributed by Andrew Jenner <andrew@codesourcery.com> 00005 Contributed by Yao Qi <yao@codesourcery.com> 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 "server.h" 00023 #include "linux-low.h" 00024 00025 #include <sys/ptrace.h> 00026 #include <endian.h> 00027 00028 #include "gdb_proc_service.h" 00029 00030 #ifndef PTRACE_GET_THREAD_AREA 00031 #define PTRACE_GET_THREAD_AREA 25 00032 #endif 00033 00034 /* There are at most 69 registers accessible in ptrace. */ 00035 #define TIC6X_NUM_REGS 69 00036 00037 #include <asm/ptrace.h> 00038 00039 /* Defined in auto-generated file tic6x-c64xp-linux.c. */ 00040 void init_registers_tic6x_c64xp_linux (void); 00041 extern const struct target_desc *tdesc_tic6x_c64xp_linux; 00042 00043 /* Defined in auto-generated file tic6x-c64x-linux.c. */ 00044 void init_registers_tic6x_c64x_linux (void); 00045 extern const struct target_desc *tdesc_tic6x_c64x_linux; 00046 00047 /* Defined in auto-generated file tic62x-c6xp-linux.c. */ 00048 void init_registers_tic6x_c62x_linux (void); 00049 extern const struct target_desc *tdesc_tic6x_c62x_linux; 00050 00051 union tic6x_register 00052 { 00053 unsigned char buf[4]; 00054 00055 int reg32; 00056 }; 00057 00058 /* Return the ptrace ``address'' of register REGNO. */ 00059 00060 #if __BYTE_ORDER == __BIG_ENDIAN 00061 static int tic6x_regmap_c64xp[] = { 00062 /* A0 - A15 */ 00063 53, 52, 55, 54, 57, 56, 59, 58, 00064 61, 60, 63, 62, 65, 64, 67, 66, 00065 /* B0 - B15 */ 00066 23, 22, 25, 24, 27, 26, 29, 28, 00067 31, 30, 33, 32, 35, 34, 69, 68, 00068 /* CSR PC */ 00069 5, 4, 00070 /* A16 - A31 */ 00071 37, 36, 39, 38, 41, 40, 43, 42, 00072 45, 44, 47, 46, 49, 48, 51, 50, 00073 /* B16 - B31 */ 00074 7, 6, 9, 8, 11, 10, 13, 12, 00075 15, 14, 17, 16, 19, 18, 21, 20, 00076 /* TSR, ILC, RILC */ 00077 1, 2, 3 00078 }; 00079 00080 static int tic6x_regmap_c64x[] = { 00081 /* A0 - A15 */ 00082 51, 50, 53, 52, 55, 54, 57, 56, 00083 59, 58, 61, 60, 63, 62, 65, 64, 00084 /* B0 - B15 */ 00085 21, 20, 23, 22, 25, 24, 27, 26, 00086 29, 28, 31, 30, 33, 32, 67, 66, 00087 /* CSR PC */ 00088 3, 2, 00089 /* A16 - A31 */ 00090 35, 34, 37, 36, 39, 38, 41, 40, 00091 43, 42, 45, 44, 47, 46, 49, 48, 00092 /* B16 - B31 */ 00093 5, 4, 7, 6, 9, 8, 11, 10, 00094 13, 12, 15, 14, 17, 16, 19, 18, 00095 -1, -1, -1 00096 }; 00097 00098 static int tic6x_regmap_c62x[] = { 00099 /* A0 - A15 */ 00100 19, 18, 21, 20, 23, 22, 25, 24, 00101 27, 26, 29, 28, 31, 30, 33, 32, 00102 /* B0 - B15 */ 00103 5, 4, 7, 6, 9, 8, 11, 10, 00104 13, 12, 15, 14, 17, 16, 35, 34, 00105 /* CSR, PC */ 00106 3, 2, 00107 -1, -1, -1, -1, -1, -1, -1, -1, 00108 -1, -1, -1, -1, -1, -1, -1, -1, 00109 -1, -1, -1, -1, -1, -1, -1, -1, 00110 -1, -1, -1, -1, -1, -1, -1, -1, 00111 -1, -1, -1 00112 }; 00113 00114 #else 00115 static int tic6x_regmap_c64xp[] = { 00116 /* A0 - A15 */ 00117 52, 53, 54, 55, 56, 57, 58, 59, 00118 60, 61, 62, 63, 64, 65, 66, 67, 00119 /* B0 - B15 */ 00120 22, 23, 24, 25, 26, 27, 28, 29, 00121 30, 31, 32, 33, 34, 35, 68, 69, 00122 /* CSR PC */ 00123 4, 5, 00124 /* A16 - A31 */ 00125 36, 37, 38, 39, 40, 41, 42, 43, 00126 44, 45, 46, 47, 48, 49, 50, 51, 00127 /* B16 -B31 */ 00128 6, 7, 8, 9, 10, 11, 12, 13, 00129 14, 15, 16, 17, 18, 19, 20, 31, 00130 /* TSR, ILC, RILC */ 00131 0, 3, 2 00132 }; 00133 00134 static int tic6x_regmap_c64x[] = { 00135 /* A0 - A15 */ 00136 50, 51, 52, 53, 54, 55, 56, 57, 00137 58, 59, 60, 61, 62, 63, 64, 65, 00138 /* B0 - B15 */ 00139 20, 21, 22, 23, 24, 25, 26, 27, 00140 28, 29, 30, 31, 32, 33, 66, 67, 00141 /* CSR PC */ 00142 2, 3, 00143 /* A16 - A31 */ 00144 34, 35, 36, 37, 38, 39, 40, 41, 00145 42, 43, 44, 45, 46, 47, 48, 49, 00146 /* B16 - B31 */ 00147 4, 5, 6, 7, 8, 9, 10, 11, 00148 12, 13, 14, 15, 16, 17, 18, 19, 00149 -1, -1, -1 00150 }; 00151 00152 static int tic6x_regmap_c62x[] = { 00153 /* A0 - A15 */ 00154 18, 19, 20, 21, 22, 23, 24, 25, 00155 26, 27, 28, 29, 30, 31, 32, 33, 00156 /* B0 - B15 */ 00157 4, 5, 6, 7, 8, 9, 10, 11, 00158 12, 13, 14, 15, 16, 17, 34, 35, 00159 /* CSR PC */ 00160 2, 3, 00161 -1, -1, -1, -1, -1, -1, -1, -1, 00162 -1, -1, -1, -1, -1, -1, -1, -1, 00163 -1, -1, -1, -1, -1, -1, -1, -1, 00164 -1, -1, -1, -1, -1, -1, -1, -1, 00165 -1, -1, -1 00166 }; 00167 00168 #endif 00169 00170 extern struct linux_target_ops the_low_target; 00171 00172 static int *tic6x_regmap; 00173 static unsigned int tic6x_breakpoint; 00174 00175 /* Forward definition. */ 00176 static struct usrregs_info tic6x_usrregs_info; 00177 00178 static const struct target_desc * 00179 tic6x_read_description (void) 00180 { 00181 register unsigned int csr asm ("B2"); 00182 unsigned int cpuid; 00183 const struct target_desc *tdesc; 00184 00185 /* Determine the CPU we're running on to find the register order. */ 00186 __asm__ ("MVC .S2 CSR,%0" : "=r" (csr) :); 00187 cpuid = csr >> 24; 00188 switch (cpuid) 00189 { 00190 case 0x00: /* C62x */ 00191 case 0x02: /* C67x */ 00192 tic6x_regmap = tic6x_regmap_c62x; 00193 tic6x_breakpoint = 0x0000a122; /* BNOP .S2 0,5 */ 00194 tdesc = tdesc_tic6x_c62x_linux; 00195 break; 00196 case 0x03: /* C67x+ */ 00197 tic6x_regmap = tic6x_regmap_c64x; 00198 tic6x_breakpoint = 0x0000a122; /* BNOP .S2 0,5 */ 00199 tdesc = tdesc_tic6x_c64x_linux; 00200 break; 00201 case 0x0c: /* C64x */ 00202 tic6x_regmap = tic6x_regmap_c64x; 00203 tic6x_breakpoint = 0x0000a122; /* BNOP .S2 0,5 */ 00204 tdesc = tdesc_tic6x_c64x_linux; 00205 break; 00206 case 0x10: /* C64x+ */ 00207 case 0x14: /* C674x */ 00208 case 0x15: /* C66x */ 00209 tic6x_regmap = tic6x_regmap_c64xp; 00210 tic6x_breakpoint = 0x56454314; /* illegal opcode */ 00211 tdesc = tdesc_tic6x_c64xp_linux; 00212 break; 00213 default: 00214 error ("Unknown CPU ID 0x%02x", cpuid); 00215 } 00216 tic6x_usrregs_info.regmap = tic6x_regmap; 00217 return tdesc; 00218 } 00219 00220 static int 00221 tic6x_cannot_fetch_register (int regno) 00222 { 00223 return (tic6x_regmap[regno] == -1); 00224 } 00225 00226 static int 00227 tic6x_cannot_store_register (int regno) 00228 { 00229 return (tic6x_regmap[regno] == -1); 00230 } 00231 00232 static CORE_ADDR 00233 tic6x_get_pc (struct regcache *regcache) 00234 { 00235 union tic6x_register pc; 00236 00237 collect_register_by_name (regcache, "PC", pc.buf); 00238 return pc.reg32; 00239 } 00240 00241 static void 00242 tic6x_set_pc (struct regcache *regcache, CORE_ADDR pc) 00243 { 00244 union tic6x_register newpc; 00245 00246 newpc.reg32 = pc; 00247 supply_register_by_name (regcache, "PC", newpc.buf); 00248 } 00249 00250 #define tic6x_breakpoint_len 4 00251 00252 static int 00253 tic6x_breakpoint_at (CORE_ADDR where) 00254 { 00255 unsigned int insn; 00256 00257 (*the_target->read_memory) (where, (unsigned char *) &insn, 4); 00258 if (insn == tic6x_breakpoint) 00259 return 1; 00260 00261 /* If necessary, recognize more trap instructions here. GDB only uses the 00262 one. */ 00263 return 0; 00264 } 00265 00266 /* Fetch the thread-local storage pointer for libthread_db. */ 00267 00268 ps_err_e 00269 ps_get_thread_area (const struct ps_prochandle *ph, 00270 lwpid_t lwpid, int idx, void **base) 00271 { 00272 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0) 00273 return PS_ERR; 00274 00275 /* IDX is the bias from the thread pointer to the beginning of the 00276 thread descriptor. It has to be subtracted due to implementation 00277 quirks in libthread_db. */ 00278 *base = (void *) ((char *) *base - idx); 00279 00280 return PS_OK; 00281 } 00282 00283 static void 00284 tic6x_collect_register (struct regcache *regcache, int regno, 00285 union tic6x_register *reg) 00286 { 00287 union tic6x_register tmp_reg; 00288 00289 collect_register (regcache, regno, &tmp_reg.reg32); 00290 reg->reg32 = tmp_reg.reg32; 00291 } 00292 00293 static void 00294 tic6x_supply_register (struct regcache *regcache, int regno, 00295 const union tic6x_register *reg) 00296 { 00297 int offset = 0; 00298 00299 supply_register (regcache, regno, reg->buf + offset); 00300 } 00301 00302 static void 00303 tic6x_fill_gregset (struct regcache *regcache, void *buf) 00304 { 00305 union tic6x_register *regset = buf; 00306 int i; 00307 00308 for (i = 0; i < TIC6X_NUM_REGS; i++) 00309 if (tic6x_regmap[i] != -1) 00310 tic6x_collect_register (regcache, i, regset + tic6x_regmap[i]); 00311 } 00312 00313 static void 00314 tic6x_store_gregset (struct regcache *regcache, const void *buf) 00315 { 00316 const union tic6x_register *regset = buf; 00317 int i; 00318 00319 for (i = 0; i < TIC6X_NUM_REGS; i++) 00320 if (tic6x_regmap[i] != -1) 00321 tic6x_supply_register (regcache, i, regset + tic6x_regmap[i]); 00322 } 00323 00324 static struct regset_info tic6x_regsets[] = { 00325 { PTRACE_GETREGS, PTRACE_SETREGS, 0, TIC6X_NUM_REGS * 4, GENERAL_REGS, 00326 tic6x_fill_gregset, tic6x_store_gregset }, 00327 { 0, 0, 0, -1, -1, NULL, NULL } 00328 }; 00329 00330 static void 00331 tic6x_arch_setup (void) 00332 { 00333 current_process ()->tdesc = tic6x_read_description (); 00334 } 00335 00336 static struct regsets_info tic6x_regsets_info = 00337 { 00338 tic6x_regsets, /* regsets */ 00339 0, /* num_regsets */ 00340 NULL, /* disabled_regsets */ 00341 }; 00342 00343 static struct usrregs_info tic6x_usrregs_info = 00344 { 00345 TIC6X_NUM_REGS, 00346 NULL, /* Set in tic6x_read_description. */ 00347 }; 00348 00349 static struct regs_info regs_info = 00350 { 00351 NULL, /* regset_bitmap */ 00352 &tic6x_usrregs_info, 00353 &tic6x_regsets_info 00354 }; 00355 00356 static const struct regs_info * 00357 tic6x_regs_info (void) 00358 { 00359 return ®s_info; 00360 } 00361 00362 struct linux_target_ops the_low_target = { 00363 tic6x_arch_setup, 00364 tic6x_regs_info, 00365 tic6x_cannot_fetch_register, 00366 tic6x_cannot_store_register, 00367 NULL, /* fetch_register */ 00368 tic6x_get_pc, 00369 tic6x_set_pc, 00370 (const unsigned char *) &tic6x_breakpoint, 00371 tic6x_breakpoint_len, 00372 NULL, 00373 0, 00374 tic6x_breakpoint_at, 00375 }; 00376 00377 void 00378 initialize_low_arch (void) 00379 { 00380 /* Initialize the Linux target descriptions. */ 00381 init_registers_tic6x_c64xp_linux (); 00382 init_registers_tic6x_c64x_linux (); 00383 init_registers_tic6x_c62x_linux (); 00384 00385 initialize_regsets_info (&tic6x_regsets_info); 00386 }