GDB (API)
|
00001 /* Native-dependent code for GNU/Linux m32r. 00002 00003 Copyright (C) 2004-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 "inferior.h" 00022 #include "gdbcore.h" 00023 #include "regcache.h" 00024 #include "linux-nat.h" 00025 #include "target.h" 00026 00027 #include "gdb_assert.h" 00028 #include "gdb_string.h" 00029 #include <sys/ptrace.h> 00030 #include <sys/user.h> 00031 #include <sys/procfs.h> 00032 00033 /* Prototypes for supply_gregset etc. */ 00034 #include "gregset.h" 00035 00036 #include "m32r-tdep.h" 00037 00038 00039 00040 00041 /* Since EVB register is not available for native debug, we reduce 00042 the number of registers. */ 00043 #define M32R_LINUX_NUM_REGS (M32R_NUM_REGS - 1) 00044 00045 /* Mapping between the general-purpose registers in `struct user' 00046 format and GDB's register array layout. */ 00047 static int regmap[] = { 00048 4, 5, 6, 7, 0, 1, 2, 8, 00049 9, 10, 11, 12, 13, 24, 25, 23, 00050 19, 19, 26, 23, 22, 20, 16, 15 00051 }; 00052 00053 #define PSW_REGMAP 19 00054 #define BBPSW_REGMAP 21 00055 #define SPU_REGMAP 23 00056 #define SPI_REGMAP 26 00057 00058 /* Doee (??) apply to the corresponding SET requests as well. */ 00059 #define GETREGS_SUPPLIES(regno) (0 <= (regno) \ 00060 && (regno) <= M32R_LINUX_NUM_REGS) 00061 00062 00063 00064 /* Transfering the general-purpose registers between GDB, inferiors 00065 and core files. */ 00066 00067 /* Fill GDB's register array with the general-purpose register values 00068 in *GREGSETP. */ 00069 00070 void 00071 supply_gregset (struct regcache *regcache, const elf_gregset_t * gregsetp) 00072 { 00073 const elf_greg_t *regp = (const elf_greg_t *) gregsetp; 00074 int i; 00075 unsigned long psw, bbpsw; 00076 00077 psw = *(regp + PSW_REGMAP); 00078 bbpsw = *(regp + BBPSW_REGMAP); 00079 00080 for (i = 0; i < M32R_LINUX_NUM_REGS; i++) 00081 { 00082 elf_greg_t regval; 00083 00084 switch (i) 00085 { 00086 case PSW_REGNUM: 00087 regval = ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8); 00088 break; 00089 case CBR_REGNUM: 00090 regval = ((psw >> 8) & 1); 00091 break; 00092 default: 00093 regval = *(regp + regmap[i]); 00094 break; 00095 } 00096 00097 if (i != M32R_SP_REGNUM) 00098 regcache_raw_supply (regcache, i, ®val); 00099 else if (psw & 0x8000) 00100 regcache_raw_supply (regcache, i, regp + SPU_REGMAP); 00101 else 00102 regcache_raw_supply (regcache, i, regp + SPI_REGMAP); 00103 } 00104 } 00105 00106 /* Fetch all general-purpose registers from process/thread TID and 00107 store their values in GDB's register array. */ 00108 00109 static void 00110 fetch_regs (struct regcache *regcache, int tid) 00111 { 00112 elf_gregset_t regs; 00113 00114 if (ptrace (PTRACE_GETREGS, tid, 0, (int) ®s) < 0) 00115 perror_with_name (_("Couldn't get registers")); 00116 00117 supply_gregset (regcache, (const elf_gregset_t *) ®s); 00118 } 00119 00120 /* Fill register REGNO (if it is a general-purpose register) in 00121 *GREGSETPS with the value in GDB's register array. If REGNO is -1, 00122 do this for all registers. */ 00123 00124 void 00125 fill_gregset (const struct regcache *regcache, 00126 elf_gregset_t * gregsetp, int regno) 00127 { 00128 elf_greg_t *regp = (elf_greg_t *) gregsetp; 00129 int i; 00130 unsigned long psw, bbpsw, tmp; 00131 00132 psw = *(regp + PSW_REGMAP); 00133 bbpsw = *(regp + BBPSW_REGMAP); 00134 00135 for (i = 0; i < M32R_LINUX_NUM_REGS; i++) 00136 { 00137 if (regno != -1 && regno != i) 00138 continue; 00139 00140 if (i == CBR_REGNUM || i == PSW_REGNUM) 00141 continue; 00142 00143 if (i == SPU_REGNUM || i == SPI_REGNUM) 00144 continue; 00145 00146 if (i != M32R_SP_REGNUM) 00147 regcache_raw_collect (regcache, i, regp + regmap[i]); 00148 else if (psw & 0x8000) 00149 regcache_raw_collect (regcache, i, regp + SPU_REGMAP); 00150 else 00151 regcache_raw_collect (regcache, i, regp + SPI_REGMAP); 00152 } 00153 } 00154 00155 /* Store all valid general-purpose registers in GDB's register array 00156 into the process/thread specified by TID. */ 00157 00158 static void 00159 store_regs (const struct regcache *regcache, int tid, int regno) 00160 { 00161 elf_gregset_t regs; 00162 00163 if (ptrace (PTRACE_GETREGS, tid, 0, (int) ®s) < 0) 00164 perror_with_name (_("Couldn't get registers")); 00165 00166 fill_gregset (regcache, ®s, regno); 00167 00168 if (ptrace (PTRACE_SETREGS, tid, 0, (int) ®s) < 0) 00169 perror_with_name (_("Couldn't write registers")); 00170 } 00171 00172 00173 00174 /* Transfering floating-point registers between GDB, inferiors and cores. 00175 Since M32R has no floating-point registers, these functions do nothing. */ 00176 00177 void 00178 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregs) 00179 { 00180 } 00181 00182 void 00183 fill_fpregset (const struct regcache *regcache, 00184 gdb_fpregset_t *fpregs, int regno) 00185 { 00186 } 00187 00188 00189 00190 /* Transferring arbitrary registers between GDB and inferior. */ 00191 00192 /* Fetch register REGNO from the child process. If REGNO is -1, do 00193 this for all registers (including the floating point and SSE 00194 registers). */ 00195 00196 static void 00197 m32r_linux_fetch_inferior_registers (struct target_ops *ops, 00198 struct regcache *regcache, int regno) 00199 { 00200 int tid; 00201 00202 /* GNU/Linux LWP ID's are process ID's. */ 00203 tid = ptid_get_lwp (inferior_ptid); 00204 if (tid == 0) 00205 tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */ 00206 00207 /* Use the PTRACE_GETREGS request whenever possible, since it 00208 transfers more registers in one system call, and we'll cache the 00209 results. */ 00210 if (regno == -1 || GETREGS_SUPPLIES (regno)) 00211 { 00212 fetch_regs (regcache, tid); 00213 return; 00214 } 00215 00216 internal_error (__FILE__, __LINE__, 00217 _("Got request for bad register number %d."), regno); 00218 } 00219 00220 /* Store register REGNO back into the child process. If REGNO is -1, 00221 do this for all registers (including the floating point and SSE 00222 registers). */ 00223 static void 00224 m32r_linux_store_inferior_registers (struct target_ops *ops, 00225 struct regcache *regcache, int regno) 00226 { 00227 int tid; 00228 00229 /* GNU/Linux LWP ID's are process ID's. */ 00230 if ((tid = ptid_get_lwp (inferior_ptid)) == 0) 00231 tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */ 00232 00233 /* Use the PTRACE_SETREGS request whenever possible, since it 00234 transfers more registers in one system call. */ 00235 if (regno == -1 || GETREGS_SUPPLIES (regno)) 00236 { 00237 store_regs (regcache, tid, regno); 00238 return; 00239 } 00240 00241 internal_error (__FILE__, __LINE__, 00242 _("Got request to store bad register number %d."), regno); 00243 } 00244 00245 void _initialize_m32r_linux_nat (void); 00246 00247 void 00248 _initialize_m32r_linux_nat (void) 00249 { 00250 struct target_ops *t; 00251 00252 /* Fill in the generic GNU/Linux methods. */ 00253 t = linux_target (); 00254 00255 /* Add our register access methods. */ 00256 t->to_fetch_registers = m32r_linux_fetch_inferior_registers; 00257 t->to_store_registers = m32r_linux_store_inferior_registers; 00258 00259 /* Register the target. */ 00260 linux_nat_add_target (t); 00261 }