]>
Commit | Line | Data |
---|---|---|
ca557f44 AC |
1 | /* Functions specific to running gdb native on IA-64 running |
2 | GNU/Linux. | |
3 | ||
b811d2c2 | 4 | Copyright (C) 1999-2020 Free Software Foundation, Inc. |
16461d7d KB |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
16461d7d KB |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
16461d7d KB |
20 | |
21 | #include "defs.h" | |
22 | #include "inferior.h" | |
23 | #include "target.h" | |
f9b11e6b | 24 | #include "gdbarch.h" |
16461d7d | 25 | #include "gdbcore.h" |
4e052eda | 26 | #include "regcache.h" |
949df321 | 27 | #include "ia64-tdep.h" |
10d6c8cd | 28 | #include "linux-nat.h" |
16461d7d KB |
29 | |
30 | #include <signal.h> | |
5826e159 | 31 | #include "nat/gdb_ptrace.h" |
268a13a5 | 32 | #include "gdbsupport/gdb_wait.h" |
16461d7d KB |
33 | #ifdef HAVE_SYS_REG_H |
34 | #include <sys/reg.h> | |
35 | #endif | |
287a334e | 36 | #include <sys/syscall.h> |
16461d7d KB |
37 | #include <sys/user.h> |
38 | ||
39 | #include <asm/ptrace_offsets.h> | |
40 | #include <sys/procfs.h> | |
41 | ||
1777feb0 | 42 | /* Prototypes for supply_gregset etc. */ |
c60c0f5f MS |
43 | #include "gregset.h" |
44 | ||
bcc0c096 SM |
45 | #include "inf-ptrace.h" |
46 | ||
f6ac5f3d PA |
47 | class ia64_linux_nat_target final : public linux_nat_target |
48 | { | |
49 | public: | |
50 | /* Add our register access methods. */ | |
51 | void fetch_registers (struct regcache *, int) override; | |
52 | void store_registers (struct regcache *, int) override; | |
53 | ||
54 | enum target_xfer_status xfer_partial (enum target_object object, | |
55 | const char *annex, | |
56 | gdb_byte *readbuf, | |
57 | const gdb_byte *writebuf, | |
58 | ULONGEST offset, ULONGEST len, | |
59 | ULONGEST *xfered_len) override; | |
60 | ||
f6ac5f3d PA |
61 | /* Override watchpoint routines. */ |
62 | ||
63 | /* The IA-64 architecture can step over a watch point (without | |
64 | triggering it again) if the "dd" (data debug fault disable) bit | |
65 | in the processor status word is set. | |
66 | ||
67 | This PSR bit is set in | |
68 | ia64_linux_nat_target::stopped_by_watchpoint when the code there | |
69 | has determined that a hardware watchpoint has indeed been hit. | |
70 | The CPU will then be able to execute one instruction without | |
71 | triggering a watchpoint. */ | |
c2a6c5da | 72 | bool have_steppable_watchpoint () override { return true; } |
f6ac5f3d PA |
73 | |
74 | int can_use_hw_breakpoint (enum bptype, int, int) override; | |
57810aa7 PA |
75 | bool stopped_by_watchpoint () override; |
76 | bool stopped_data_address (CORE_ADDR *) override; | |
f6ac5f3d PA |
77 | int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type, |
78 | struct expression *) override; | |
79 | int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type, | |
80 | struct expression *) override; | |
135340af PA |
81 | /* Override linux_nat_target low methods. */ |
82 | void low_new_thread (struct lwp_info *lp) override; | |
83 | bool low_status_is_event (int status) override; | |
9bf058f0 PA |
84 | |
85 | void enable_watchpoints_in_psr (ptid_t ptid); | |
f6ac5f3d PA |
86 | }; |
87 | ||
88 | static ia64_linux_nat_target the_ia64_linux_nat_target; | |
89 | ||
16461d7d KB |
90 | /* These must match the order of the register names. |
91 | ||
92 | Some sort of lookup table is needed because the offsets associated | |
93 | with the registers are all over the board. */ | |
94 | ||
95 | static int u_offsets[] = | |
96 | { | |
97 | /* general registers */ | |
1777feb0 | 98 | -1, /* gr0 not available; i.e, it's always zero. */ |
16461d7d KB |
99 | PT_R1, |
100 | PT_R2, | |
101 | PT_R3, | |
102 | PT_R4, | |
103 | PT_R5, | |
104 | PT_R6, | |
105 | PT_R7, | |
106 | PT_R8, | |
107 | PT_R9, | |
108 | PT_R10, | |
109 | PT_R11, | |
110 | PT_R12, | |
111 | PT_R13, | |
112 | PT_R14, | |
113 | PT_R15, | |
114 | PT_R16, | |
115 | PT_R17, | |
116 | PT_R18, | |
117 | PT_R19, | |
118 | PT_R20, | |
119 | PT_R21, | |
120 | PT_R22, | |
121 | PT_R23, | |
122 | PT_R24, | |
123 | PT_R25, | |
124 | PT_R26, | |
125 | PT_R27, | |
126 | PT_R28, | |
127 | PT_R29, | |
128 | PT_R30, | |
129 | PT_R31, | |
1777feb0 | 130 | /* gr32 through gr127 not directly available via the ptrace interface. */ |
16461d7d KB |
131 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
132 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
133 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
134 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
135 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
136 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
137 | /* Floating point registers */ | |
1777feb0 | 138 | -1, -1, /* f0 and f1 not available (f0 is +0.0 and f1 is +1.0). */ |
16461d7d KB |
139 | PT_F2, |
140 | PT_F3, | |
141 | PT_F4, | |
142 | PT_F5, | |
143 | PT_F6, | |
144 | PT_F7, | |
145 | PT_F8, | |
146 | PT_F9, | |
147 | PT_F10, | |
148 | PT_F11, | |
149 | PT_F12, | |
150 | PT_F13, | |
151 | PT_F14, | |
152 | PT_F15, | |
153 | PT_F16, | |
154 | PT_F17, | |
155 | PT_F18, | |
156 | PT_F19, | |
157 | PT_F20, | |
158 | PT_F21, | |
159 | PT_F22, | |
160 | PT_F23, | |
161 | PT_F24, | |
162 | PT_F25, | |
163 | PT_F26, | |
164 | PT_F27, | |
165 | PT_F28, | |
166 | PT_F29, | |
167 | PT_F30, | |
168 | PT_F31, | |
169 | PT_F32, | |
170 | PT_F33, | |
171 | PT_F34, | |
172 | PT_F35, | |
173 | PT_F36, | |
174 | PT_F37, | |
175 | PT_F38, | |
176 | PT_F39, | |
177 | PT_F40, | |
178 | PT_F41, | |
179 | PT_F42, | |
180 | PT_F43, | |
181 | PT_F44, | |
182 | PT_F45, | |
183 | PT_F46, | |
184 | PT_F47, | |
185 | PT_F48, | |
186 | PT_F49, | |
187 | PT_F50, | |
188 | PT_F51, | |
189 | PT_F52, | |
190 | PT_F53, | |
191 | PT_F54, | |
192 | PT_F55, | |
193 | PT_F56, | |
194 | PT_F57, | |
195 | PT_F58, | |
196 | PT_F59, | |
197 | PT_F60, | |
198 | PT_F61, | |
199 | PT_F62, | |
200 | PT_F63, | |
201 | PT_F64, | |
202 | PT_F65, | |
203 | PT_F66, | |
204 | PT_F67, | |
205 | PT_F68, | |
206 | PT_F69, | |
207 | PT_F70, | |
208 | PT_F71, | |
209 | PT_F72, | |
210 | PT_F73, | |
211 | PT_F74, | |
212 | PT_F75, | |
213 | PT_F76, | |
214 | PT_F77, | |
215 | PT_F78, | |
216 | PT_F79, | |
217 | PT_F80, | |
218 | PT_F81, | |
219 | PT_F82, | |
220 | PT_F83, | |
221 | PT_F84, | |
222 | PT_F85, | |
223 | PT_F86, | |
224 | PT_F87, | |
225 | PT_F88, | |
226 | PT_F89, | |
227 | PT_F90, | |
228 | PT_F91, | |
229 | PT_F92, | |
230 | PT_F93, | |
231 | PT_F94, | |
232 | PT_F95, | |
233 | PT_F96, | |
234 | PT_F97, | |
235 | PT_F98, | |
236 | PT_F99, | |
237 | PT_F100, | |
238 | PT_F101, | |
239 | PT_F102, | |
240 | PT_F103, | |
241 | PT_F104, | |
242 | PT_F105, | |
243 | PT_F106, | |
244 | PT_F107, | |
245 | PT_F108, | |
246 | PT_F109, | |
247 | PT_F110, | |
248 | PT_F111, | |
249 | PT_F112, | |
250 | PT_F113, | |
251 | PT_F114, | |
252 | PT_F115, | |
253 | PT_F116, | |
254 | PT_F117, | |
255 | PT_F118, | |
256 | PT_F119, | |
257 | PT_F120, | |
258 | PT_F121, | |
259 | PT_F122, | |
260 | PT_F123, | |
261 | PT_F124, | |
262 | PT_F125, | |
263 | PT_F126, | |
264 | PT_F127, | |
1777feb0 | 265 | /* Predicate registers - we don't fetch these individually. */ |
16461d7d KB |
266 | -1, -1, -1, -1, -1, -1, -1, -1, |
267 | -1, -1, -1, -1, -1, -1, -1, -1, | |
268 | -1, -1, -1, -1, -1, -1, -1, -1, | |
269 | -1, -1, -1, -1, -1, -1, -1, -1, | |
270 | -1, -1, -1, -1, -1, -1, -1, -1, | |
271 | -1, -1, -1, -1, -1, -1, -1, -1, | |
272 | -1, -1, -1, -1, -1, -1, -1, -1, | |
273 | -1, -1, -1, -1, -1, -1, -1, -1, | |
274 | /* branch registers */ | |
275 | PT_B0, | |
276 | PT_B1, | |
277 | PT_B2, | |
278 | PT_B3, | |
279 | PT_B4, | |
280 | PT_B5, | |
281 | PT_B6, | |
282 | PT_B7, | |
1777feb0 | 283 | /* Virtual frame pointer and virtual return address pointer. */ |
16461d7d KB |
284 | -1, -1, |
285 | /* other registers */ | |
286 | PT_PR, | |
287 | PT_CR_IIP, /* ip */ | |
288 | PT_CR_IPSR, /* psr */ | |
9ac12c35 | 289 | PT_CFM, /* cfm */ |
1777feb0 | 290 | /* kernel registers not visible via ptrace interface (?) */ |
16461d7d KB |
291 | -1, -1, -1, -1, -1, -1, -1, -1, |
292 | /* hole */ | |
293 | -1, -1, -1, -1, -1, -1, -1, -1, | |
294 | PT_AR_RSC, | |
295 | PT_AR_BSP, | |
296 | PT_AR_BSPSTORE, | |
297 | PT_AR_RNAT, | |
298 | -1, | |
1777feb0 | 299 | -1, /* Not available: FCR, IA32 floating control register. */ |
16461d7d KB |
300 | -1, -1, |
301 | -1, /* Not available: EFLAG */ | |
302 | -1, /* Not available: CSD */ | |
303 | -1, /* Not available: SSD */ | |
304 | -1, /* Not available: CFLG */ | |
305 | -1, /* Not available: FSR */ | |
306 | -1, /* Not available: FIR */ | |
307 | -1, /* Not available: FDR */ | |
308 | -1, | |
309 | PT_AR_CCV, | |
310 | -1, -1, -1, | |
311 | PT_AR_UNAT, | |
312 | -1, -1, -1, | |
313 | PT_AR_FPSR, | |
314 | -1, -1, -1, | |
315 | -1, /* Not available: ITC */ | |
316 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
317 | -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
318 | PT_AR_PFS, | |
319 | PT_AR_LC, | |
4a6510ba | 320 | PT_AR_EC, |
16461d7d KB |
321 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
322 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
323 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
324 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
325 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
326 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
327 | -1, | |
328 | /* nat bits - not fetched directly; instead we obtain these bits from | |
1777feb0 | 329 | either rnat or unat or from memory. */ |
16461d7d KB |
330 | -1, -1, -1, -1, -1, -1, -1, -1, |
331 | -1, -1, -1, -1, -1, -1, -1, -1, | |
332 | -1, -1, -1, -1, -1, -1, -1, -1, | |
333 | -1, -1, -1, -1, -1, -1, -1, -1, | |
334 | -1, -1, -1, -1, -1, -1, -1, -1, | |
335 | -1, -1, -1, -1, -1, -1, -1, -1, | |
336 | -1, -1, -1, -1, -1, -1, -1, -1, | |
337 | -1, -1, -1, -1, -1, -1, -1, -1, | |
338 | -1, -1, -1, -1, -1, -1, -1, -1, | |
339 | -1, -1, -1, -1, -1, -1, -1, -1, | |
340 | -1, -1, -1, -1, -1, -1, -1, -1, | |
341 | -1, -1, -1, -1, -1, -1, -1, -1, | |
342 | -1, -1, -1, -1, -1, -1, -1, -1, | |
343 | -1, -1, -1, -1, -1, -1, -1, -1, | |
344 | -1, -1, -1, -1, -1, -1, -1, -1, | |
345 | -1, -1, -1, -1, -1, -1, -1, -1, | |
346 | }; | |
347 | ||
74174d2e | 348 | static CORE_ADDR |
2685572f | 349 | ia64_register_addr (struct gdbarch *gdbarch, int regno) |
16461d7d KB |
350 | { |
351 | CORE_ADDR addr; | |
352 | ||
2685572f | 353 | if (regno < 0 || regno >= gdbarch_num_regs (gdbarch)) |
8a3fe4f8 | 354 | error (_("Invalid register number %d."), regno); |
16461d7d KB |
355 | |
356 | if (u_offsets[regno] == -1) | |
357 | addr = 0; | |
358 | else | |
359 | addr = (CORE_ADDR) u_offsets[regno]; | |
360 | ||
361 | return addr; | |
362 | } | |
363 | ||
74174d2e | 364 | static int |
2685572f | 365 | ia64_cannot_fetch_register (struct gdbarch *gdbarch, int regno) |
16461d7d | 366 | { |
f57d151a | 367 | return regno < 0 |
2685572f | 368 | || regno >= gdbarch_num_regs (gdbarch) |
f57d151a | 369 | || u_offsets[regno] == -1; |
16461d7d KB |
370 | } |
371 | ||
74174d2e | 372 | static int |
2685572f | 373 | ia64_cannot_store_register (struct gdbarch *gdbarch, int regno) |
16461d7d KB |
374 | { |
375 | /* Rationale behind not permitting stores to bspstore... | |
376 | ||
377 | The IA-64 architecture provides bspstore and bsp which refer | |
378 | memory locations in the RSE's backing store. bspstore is the | |
379 | next location which will be written when the RSE needs to write | |
380 | to memory. bsp is the address at which r32 in the current frame | |
381 | would be found if it were written to the backing store. | |
382 | ||
383 | The IA-64 architecture provides read-only access to bsp and | |
384 | read/write access to bspstore (but only when the RSE is in | |
385 | the enforced lazy mode). It should be noted that stores | |
386 | to bspstore also affect the value of bsp. Changing bspstore | |
387 | does not affect the number of dirty entries between bspstore | |
388 | and bsp, so changing bspstore by N words will also cause bsp | |
389 | to be changed by (roughly) N as well. (It could be N-1 or N+1 | |
390 | depending upon where the NaT collection bits fall.) | |
391 | ||
92362027 | 392 | OTOH, the Linux kernel provides read/write access to bsp (and |
16461d7d KB |
393 | currently read/write access to bspstore as well). But it |
394 | is definitely the case that if you change one, the other | |
395 | will change at the same time. It is more useful to gdb to | |
396 | be able to change bsp. So in order to prevent strange and | |
397 | undesirable things from happening when a dummy stack frame | |
398 | is popped (after calling an inferior function), we allow | |
399 | bspstore to be read, but not written. (Note that popping | |
400 | a (generic) dummy stack frame causes all registers that | |
401 | were previously read from the inferior process to be written | |
402 | back.) */ | |
403 | ||
f57d151a | 404 | return regno < 0 |
2685572f | 405 | || regno >= gdbarch_num_regs (gdbarch) |
f57d151a | 406 | || u_offsets[regno] == -1 |
dda83cd7 | 407 | || regno == IA64_BSPSTORE_REGNUM; |
16461d7d KB |
408 | } |
409 | ||
410 | void | |
7f7fe91e | 411 | supply_gregset (struct regcache *regcache, const gregset_t *gregsetp) |
16461d7d KB |
412 | { |
413 | int regi; | |
7f7fe91e | 414 | const greg_t *regp = (const greg_t *) gregsetp; |
16461d7d KB |
415 | |
416 | for (regi = IA64_GR0_REGNUM; regi <= IA64_GR31_REGNUM; regi++) | |
417 | { | |
73e1c03f | 418 | regcache->raw_supply (regi, regp + (regi - IA64_GR0_REGNUM)); |
16461d7d KB |
419 | } |
420 | ||
421 | /* FIXME: NAT collection bits are at index 32; gotta deal with these | |
1777feb0 | 422 | somehow... */ |
16461d7d | 423 | |
73e1c03f | 424 | regcache->raw_supply (IA64_PR_REGNUM, regp + 33); |
16461d7d KB |
425 | |
426 | for (regi = IA64_BR0_REGNUM; regi <= IA64_BR7_REGNUM; regi++) | |
427 | { | |
73e1c03f | 428 | regcache->raw_supply (regi, regp + 34 + (regi - IA64_BR0_REGNUM)); |
16461d7d KB |
429 | } |
430 | ||
73e1c03f SM |
431 | regcache->raw_supply (IA64_IP_REGNUM, regp + 42); |
432 | regcache->raw_supply (IA64_CFM_REGNUM, regp + 43); | |
433 | regcache->raw_supply (IA64_PSR_REGNUM, regp + 44); | |
434 | regcache->raw_supply (IA64_RSC_REGNUM, regp + 45); | |
435 | regcache->raw_supply (IA64_BSP_REGNUM, regp + 46); | |
436 | regcache->raw_supply (IA64_BSPSTORE_REGNUM, regp + 47); | |
437 | regcache->raw_supply (IA64_RNAT_REGNUM, regp + 48); | |
438 | regcache->raw_supply (IA64_CCV_REGNUM, regp + 49); | |
439 | regcache->raw_supply (IA64_UNAT_REGNUM, regp + 50); | |
440 | regcache->raw_supply (IA64_FPSR_REGNUM, regp + 51); | |
441 | regcache->raw_supply (IA64_PFS_REGNUM, regp + 52); | |
442 | regcache->raw_supply (IA64_LC_REGNUM, regp + 53); | |
443 | regcache->raw_supply (IA64_EC_REGNUM, regp + 54); | |
16461d7d KB |
444 | } |
445 | ||
446 | void | |
7f7fe91e | 447 | fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno) |
16461d7d | 448 | { |
76d689a6 KB |
449 | int regi; |
450 | greg_t *regp = (greg_t *) gregsetp; | |
451 | ||
452 | #define COPY_REG(_idx_,_regi_) \ | |
453 | if ((regno == -1) || regno == _regi_) \ | |
34a79281 | 454 | regcache->raw_collect (_regi_, regp + _idx_) |
76d689a6 KB |
455 | |
456 | for (regi = IA64_GR0_REGNUM; regi <= IA64_GR31_REGNUM; regi++) | |
457 | { | |
458 | COPY_REG (regi - IA64_GR0_REGNUM, regi); | |
459 | } | |
460 | ||
1777feb0 | 461 | /* FIXME: NAT collection bits at index 32? */ |
76d689a6 KB |
462 | |
463 | COPY_REG (33, IA64_PR_REGNUM); | |
464 | ||
465 | for (regi = IA64_BR0_REGNUM; regi <= IA64_BR7_REGNUM; regi++) | |
466 | { | |
467 | COPY_REG (34 + (regi - IA64_BR0_REGNUM), regi); | |
468 | } | |
469 | ||
470 | COPY_REG (42, IA64_IP_REGNUM); | |
471 | COPY_REG (43, IA64_CFM_REGNUM); | |
472 | COPY_REG (44, IA64_PSR_REGNUM); | |
473 | COPY_REG (45, IA64_RSC_REGNUM); | |
474 | COPY_REG (46, IA64_BSP_REGNUM); | |
475 | COPY_REG (47, IA64_BSPSTORE_REGNUM); | |
476 | COPY_REG (48, IA64_RNAT_REGNUM); | |
477 | COPY_REG (49, IA64_CCV_REGNUM); | |
478 | COPY_REG (50, IA64_UNAT_REGNUM); | |
479 | COPY_REG (51, IA64_FPSR_REGNUM); | |
480 | COPY_REG (52, IA64_PFS_REGNUM); | |
481 | COPY_REG (53, IA64_LC_REGNUM); | |
482 | COPY_REG (54, IA64_EC_REGNUM); | |
483 | } | |
484 | ||
485 | /* Given a pointer to a floating point register set in /proc format | |
486 | (fpregset_t *), unpack the register contents and supply them as gdb's | |
1777feb0 | 487 | idea of the current floating point register values. */ |
76d689a6 KB |
488 | |
489 | void | |
7f7fe91e | 490 | supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp) |
76d689a6 | 491 | { |
52f0bd74 | 492 | int regi; |
7f7fe91e | 493 | const char *from; |
ca9b8b9c PA |
494 | const gdb_byte f_zero[16] = { 0 }; |
495 | const gdb_byte f_one[16] = | |
496 | { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0xff, 0, 0, 0, 0, 0, 0 }; | |
76d689a6 | 497 | |
ca9b8b9c PA |
498 | /* Kernel generated cores have fr1==0 instead of 1.0. Older GDBs |
499 | did the same. So ignore whatever might be recorded in fpregset_t | |
500 | for fr0/fr1 and always supply their expected values. */ | |
501 | ||
502 | /* fr0 is always read as zero. */ | |
73e1c03f | 503 | regcache->raw_supply (IA64_FR0_REGNUM, f_zero); |
ca9b8b9c | 504 | /* fr1 is always read as one (1.0). */ |
73e1c03f | 505 | regcache->raw_supply (IA64_FR1_REGNUM, f_one); |
ca9b8b9c PA |
506 | |
507 | for (regi = IA64_FR2_REGNUM; regi <= IA64_FR127_REGNUM; regi++) | |
76d689a6 | 508 | { |
7f7fe91e | 509 | from = (const char *) &((*fpregsetp)[regi - IA64_FR0_REGNUM]); |
73e1c03f | 510 | regcache->raw_supply (regi, from); |
76d689a6 KB |
511 | } |
512 | } | |
513 | ||
514 | /* Given a pointer to a floating point register set in /proc format | |
515 | (fpregset_t *), update the register specified by REGNO from gdb's idea | |
516 | of the current floating point register set. If REGNO is -1, update | |
1777feb0 | 517 | them all. */ |
76d689a6 KB |
518 | |
519 | void | |
7f7fe91e UW |
520 | fill_fpregset (const struct regcache *regcache, |
521 | fpregset_t *fpregsetp, int regno) | |
76d689a6 KB |
522 | { |
523 | int regi; | |
76d689a6 KB |
524 | |
525 | for (regi = IA64_FR0_REGNUM; regi <= IA64_FR127_REGNUM; regi++) | |
526 | { | |
527 | if ((regno == -1) || (regno == regi)) | |
34a79281 | 528 | regcache->raw_collect (regi, &((*fpregsetp)[regi - IA64_FR0_REGNUM])); |
76d689a6 | 529 | } |
16461d7d | 530 | } |
acf7b9e1 KB |
531 | |
532 | #define IA64_PSR_DB (1UL << 24) | |
533 | #define IA64_PSR_DD (1UL << 39) | |
534 | ||
9bf058f0 PA |
535 | void |
536 | ia64_linux_nat_target::enable_watchpoints_in_psr (ptid_t ptid) | |
acf7b9e1 | 537 | { |
9bf058f0 | 538 | struct regcache *regcache = get_thread_regcache (this, ptid); |
7b86a1b8 | 539 | ULONGEST psr; |
acf7b9e1 | 540 | |
7b86a1b8 | 541 | regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr); |
acf7b9e1 KB |
542 | if (!(psr & IA64_PSR_DB)) |
543 | { | |
544 | psr |= IA64_PSR_DB; /* Set the db bit - this enables hardware | |
dda83cd7 | 545 | watchpoints and breakpoints. */ |
7b86a1b8 | 546 | regcache_cooked_write_unsigned (regcache, IA64_PSR_REGNUM, psr); |
acf7b9e1 KB |
547 | } |
548 | } | |
549 | ||
9f0bdab8 | 550 | static long debug_registers[8]; |
acf7b9e1 KB |
551 | |
552 | static void | |
39f77062 | 553 | store_debug_register (ptid_t ptid, int idx, long val) |
acf7b9e1 KB |
554 | { |
555 | int tid; | |
556 | ||
e38504b3 | 557 | tid = ptid.lwp (); |
acf7b9e1 | 558 | if (tid == 0) |
e99b03dc | 559 | tid = ptid.pid (); |
acf7b9e1 | 560 | |
c5fa4245 | 561 | (void) ptrace (PT_WRITE_U, tid, (PTRACE_TYPE_ARG3) (PT_DBR + 8 * idx), val); |
acf7b9e1 KB |
562 | } |
563 | ||
acf7b9e1 | 564 | static void |
1777feb0 MS |
565 | store_debug_register_pair (ptid_t ptid, int idx, long *dbr_addr, |
566 | long *dbr_mask) | |
acf7b9e1 KB |
567 | { |
568 | if (dbr_addr) | |
39f77062 | 569 | store_debug_register (ptid, 2 * idx, *dbr_addr); |
acf7b9e1 | 570 | if (dbr_mask) |
39f77062 | 571 | store_debug_register (ptid, 2 * idx + 1, *dbr_mask); |
acf7b9e1 KB |
572 | } |
573 | ||
574 | static int | |
575 | is_power_of_2 (int val) | |
576 | { | |
577 | int i, onecount; | |
578 | ||
579 | onecount = 0; | |
580 | for (i = 0; i < 8 * sizeof (val); i++) | |
581 | if (val & (1 << i)) | |
582 | onecount++; | |
583 | ||
584 | return onecount <= 1; | |
585 | } | |
586 | ||
f6ac5f3d PA |
587 | int |
588 | ia64_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len, | |
589 | enum target_hw_bp_type type, | |
590 | struct expression *cond) | |
acf7b9e1 | 591 | { |
9f0bdab8 | 592 | struct lwp_info *lp; |
acf7b9e1 KB |
593 | int idx; |
594 | long dbr_addr, dbr_mask; | |
595 | int max_watchpoints = 4; | |
596 | ||
597 | if (len <= 0 || !is_power_of_2 (len)) | |
598 | return -1; | |
599 | ||
600 | for (idx = 0; idx < max_watchpoints; idx++) | |
601 | { | |
9f0bdab8 | 602 | dbr_mask = debug_registers[idx * 2 + 1]; |
acf7b9e1 KB |
603 | if ((dbr_mask & (0x3UL << 62)) == 0) |
604 | { | |
1777feb0 | 605 | /* Exit loop if both r and w bits clear. */ |
acf7b9e1 KB |
606 | break; |
607 | } | |
608 | } | |
609 | ||
610 | if (idx == max_watchpoints) | |
611 | return -1; | |
612 | ||
613 | dbr_addr = (long) addr; | |
614 | dbr_mask = (~(len - 1) & 0x00ffffffffffffffL); /* construct mask to match */ | |
615 | dbr_mask |= 0x0800000000000000L; /* Only match privilege level 3 */ | |
f486487f | 616 | switch (type) |
acf7b9e1 KB |
617 | { |
618 | case hw_write: | |
619 | dbr_mask |= (1L << 62); /* Set w bit */ | |
620 | break; | |
621 | case hw_read: | |
622 | dbr_mask |= (1L << 63); /* Set r bit */ | |
623 | break; | |
624 | case hw_access: | |
625 | dbr_mask |= (3L << 62); /* Set both r and w bits */ | |
626 | break; | |
627 | default: | |
628 | return -1; | |
629 | } | |
630 | ||
9f0bdab8 DJ |
631 | debug_registers[2 * idx] = dbr_addr; |
632 | debug_registers[2 * idx + 1] = dbr_mask; | |
4c38200f | 633 | ALL_LWPS (lp) |
9f0bdab8 | 634 | { |
4c38200f PA |
635 | store_debug_register_pair (lp->ptid, idx, &dbr_addr, &dbr_mask); |
636 | enable_watchpoints_in_psr (lp->ptid); | |
9f0bdab8 | 637 | } |
acf7b9e1 KB |
638 | |
639 | return 0; | |
640 | } | |
641 | ||
f6ac5f3d PA |
642 | int |
643 | ia64_linux_nat_target::remove_watchpoint (CORE_ADDR addr, int len, | |
644 | enum target_hw_bp_type type, | |
645 | struct expression *cond) | |
acf7b9e1 KB |
646 | { |
647 | int idx; | |
648 | long dbr_addr, dbr_mask; | |
649 | int max_watchpoints = 4; | |
650 | ||
651 | if (len <= 0 || !is_power_of_2 (len)) | |
652 | return -1; | |
653 | ||
654 | for (idx = 0; idx < max_watchpoints; idx++) | |
655 | { | |
9f0bdab8 DJ |
656 | dbr_addr = debug_registers[2 * idx]; |
657 | dbr_mask = debug_registers[2 * idx + 1]; | |
acf7b9e1 KB |
658 | if ((dbr_mask & (0x3UL << 62)) && addr == (CORE_ADDR) dbr_addr) |
659 | { | |
9f0bdab8 | 660 | struct lwp_info *lp; |
9f0bdab8 DJ |
661 | |
662 | debug_registers[2 * idx] = 0; | |
663 | debug_registers[2 * idx + 1] = 0; | |
acf7b9e1 KB |
664 | dbr_addr = 0; |
665 | dbr_mask = 0; | |
9f0bdab8 | 666 | |
4c38200f PA |
667 | ALL_LWPS (lp) |
668 | store_debug_register_pair (lp->ptid, idx, &dbr_addr, &dbr_mask); | |
9f0bdab8 | 669 | |
acf7b9e1 KB |
670 | return 0; |
671 | } | |
672 | } | |
673 | return -1; | |
674 | } | |
675 | ||
c2a6c5da TT |
676 | void |
677 | ia64_linux_nat_target::low_new_thread (struct lwp_info *lp) | |
9f0bdab8 DJ |
678 | { |
679 | int i, any; | |
680 | ||
681 | any = 0; | |
682 | for (i = 0; i < 8; i++) | |
683 | { | |
684 | if (debug_registers[i] != 0) | |
685 | any = 1; | |
7b50312a | 686 | store_debug_register (lp->ptid, i, debug_registers[i]); |
9f0bdab8 DJ |
687 | } |
688 | ||
689 | if (any) | |
7b50312a | 690 | enable_watchpoints_in_psr (lp->ptid); |
9f0bdab8 DJ |
691 | } |
692 | ||
57810aa7 | 693 | bool |
f6ac5f3d | 694 | ia64_linux_nat_target::stopped_data_address (CORE_ADDR *addr_p) |
acf7b9e1 KB |
695 | { |
696 | CORE_ADDR psr; | |
f865ee35 | 697 | siginfo_t siginfo; |
594f7785 | 698 | struct regcache *regcache = get_current_regcache (); |
acf7b9e1 | 699 | |
f865ee35 | 700 | if (!linux_nat_get_siginfo (inferior_ptid, &siginfo)) |
57810aa7 | 701 | return false; |
acf7b9e1 | 702 | |
f865ee35 JK |
703 | if (siginfo.si_signo != SIGTRAP |
704 | || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */) | |
57810aa7 | 705 | return false; |
acf7b9e1 | 706 | |
7b86a1b8 | 707 | regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr); |
acf7b9e1 | 708 | psr |= IA64_PSR_DD; /* Set the dd bit - this will disable the watchpoint |
dda83cd7 | 709 | for the next instruction. */ |
7b86a1b8 | 710 | regcache_cooked_write_unsigned (regcache, IA64_PSR_REGNUM, psr); |
acf7b9e1 | 711 | |
f865ee35 | 712 | *addr_p = (CORE_ADDR) siginfo.si_addr; |
57810aa7 | 713 | return true; |
4aa7a7f5 JJ |
714 | } |
715 | ||
57810aa7 | 716 | bool |
f6ac5f3d | 717 | ia64_linux_nat_target::stopped_by_watchpoint () |
4aa7a7f5 JJ |
718 | { |
719 | CORE_ADDR addr; | |
f6ac5f3d | 720 | return stopped_data_address (&addr); |
74174d2e UW |
721 | } |
722 | ||
c2a6c5da TT |
723 | int |
724 | ia64_linux_nat_target::can_use_hw_breakpoint (enum bptype type, | |
725 | int cnt, int othertype) | |
74174d2e UW |
726 | { |
727 | return 1; | |
728 | } | |
729 | ||
730 | ||
731 | /* Fetch register REGNUM from the inferior. */ | |
732 | ||
733 | static void | |
56be3814 | 734 | ia64_linux_fetch_register (struct regcache *regcache, int regnum) |
74174d2e | 735 | { |
ac7936df | 736 | struct gdbarch *gdbarch = regcache->arch (); |
74174d2e UW |
737 | CORE_ADDR addr; |
738 | size_t size; | |
739 | PTRACE_TYPE_RET *buf; | |
bcc0c096 SM |
740 | pid_t pid; |
741 | int i; | |
74174d2e | 742 | |
5a75128f JB |
743 | /* r0 cannot be fetched but is always zero. */ |
744 | if (regnum == IA64_GR0_REGNUM) | |
745 | { | |
746 | const gdb_byte zero[8] = { 0 }; | |
747 | ||
748 | gdb_assert (sizeof (zero) == register_size (gdbarch, regnum)); | |
73e1c03f | 749 | regcache->raw_supply (regnum, zero); |
5a75128f JB |
750 | return; |
751 | } | |
752 | ||
ca9b8b9c PA |
753 | /* fr0 cannot be fetched but is always zero. */ |
754 | if (regnum == IA64_FR0_REGNUM) | |
755 | { | |
756 | const gdb_byte f_zero[16] = { 0 }; | |
757 | ||
758 | gdb_assert (sizeof (f_zero) == register_size (gdbarch, regnum)); | |
73e1c03f | 759 | regcache->raw_supply (regnum, f_zero); |
ca9b8b9c PA |
760 | return; |
761 | } | |
762 | ||
763 | /* fr1 cannot be fetched but is always one (1.0). */ | |
764 | if (regnum == IA64_FR1_REGNUM) | |
765 | { | |
766 | const gdb_byte f_one[16] = | |
767 | { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0xff, 0, 0, 0, 0, 0, 0 }; | |
768 | ||
769 | gdb_assert (sizeof (f_one) == register_size (gdbarch, regnum)); | |
73e1c03f | 770 | regcache->raw_supply (regnum, f_one); |
ca9b8b9c PA |
771 | return; |
772 | } | |
773 | ||
2685572f | 774 | if (ia64_cannot_fetch_register (gdbarch, regnum)) |
74174d2e | 775 | { |
73e1c03f | 776 | regcache->raw_supply (regnum, NULL); |
74174d2e UW |
777 | return; |
778 | } | |
779 | ||
222312d3 | 780 | pid = get_ptrace_pid (regcache->ptid ()); |
74174d2e UW |
781 | |
782 | /* This isn't really an address, but ptrace thinks of it as one. */ | |
2685572f | 783 | addr = ia64_register_addr (gdbarch, regnum); |
088568da | 784 | size = register_size (gdbarch, regnum); |
74174d2e UW |
785 | |
786 | gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0); | |
bfb0d950 | 787 | buf = (PTRACE_TYPE_RET *) alloca (size); |
74174d2e UW |
788 | |
789 | /* Read the register contents from the inferior a chunk at a time. */ | |
790 | for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++) | |
791 | { | |
792 | errno = 0; | |
793 | buf[i] = ptrace (PT_READ_U, pid, (PTRACE_TYPE_ARG3)addr, 0); | |
794 | if (errno != 0) | |
795 | error (_("Couldn't read register %s (#%d): %s."), | |
088568da | 796 | gdbarch_register_name (gdbarch, regnum), |
c9f4d572 | 797 | regnum, safe_strerror (errno)); |
74174d2e UW |
798 | |
799 | addr += sizeof (PTRACE_TYPE_RET); | |
800 | } | |
73e1c03f | 801 | regcache->raw_supply (regnum, buf); |
74174d2e UW |
802 | } |
803 | ||
804 | /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this | |
805 | for all registers. */ | |
806 | ||
f6ac5f3d PA |
807 | void |
808 | ia64_linux_nat_target::fetch_registers (struct regcache *regcache, int regnum) | |
74174d2e UW |
809 | { |
810 | if (regnum == -1) | |
088568da | 811 | for (regnum = 0; |
ac7936df | 812 | regnum < gdbarch_num_regs (regcache->arch ()); |
088568da | 813 | regnum++) |
56be3814 | 814 | ia64_linux_fetch_register (regcache, regnum); |
74174d2e | 815 | else |
56be3814 | 816 | ia64_linux_fetch_register (regcache, regnum); |
74174d2e UW |
817 | } |
818 | ||
819 | /* Store register REGNUM into the inferior. */ | |
820 | ||
821 | static void | |
56be3814 | 822 | ia64_linux_store_register (const struct regcache *regcache, int regnum) |
74174d2e | 823 | { |
ac7936df | 824 | struct gdbarch *gdbarch = regcache->arch (); |
74174d2e UW |
825 | CORE_ADDR addr; |
826 | size_t size; | |
827 | PTRACE_TYPE_RET *buf; | |
bcc0c096 SM |
828 | pid_t pid; |
829 | int i; | |
74174d2e | 830 | |
2685572f | 831 | if (ia64_cannot_store_register (gdbarch, regnum)) |
74174d2e UW |
832 | return; |
833 | ||
222312d3 | 834 | pid = get_ptrace_pid (regcache->ptid ()); |
74174d2e UW |
835 | |
836 | /* This isn't really an address, but ptrace thinks of it as one. */ | |
2685572f | 837 | addr = ia64_register_addr (gdbarch, regnum); |
088568da | 838 | size = register_size (gdbarch, regnum); |
74174d2e UW |
839 | |
840 | gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0); | |
bfb0d950 | 841 | buf = (PTRACE_TYPE_RET *) alloca (size); |
74174d2e UW |
842 | |
843 | /* Write the register contents into the inferior a chunk at a time. */ | |
34a79281 | 844 | regcache->raw_collect (regnum, buf); |
74174d2e UW |
845 | for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++) |
846 | { | |
847 | errno = 0; | |
848 | ptrace (PT_WRITE_U, pid, (PTRACE_TYPE_ARG3)addr, buf[i]); | |
849 | if (errno != 0) | |
850 | error (_("Couldn't write register %s (#%d): %s."), | |
088568da | 851 | gdbarch_register_name (gdbarch, regnum), |
c9f4d572 | 852 | regnum, safe_strerror (errno)); |
74174d2e UW |
853 | |
854 | addr += sizeof (PTRACE_TYPE_RET); | |
855 | } | |
acf7b9e1 | 856 | } |
287a334e | 857 | |
74174d2e UW |
858 | /* Store register REGNUM back into the inferior. If REGNUM is -1, do |
859 | this for all registers. */ | |
860 | ||
f6ac5f3d PA |
861 | void |
862 | ia64_linux_nat_target::store_registers (struct regcache *regcache, int regnum) | |
74174d2e UW |
863 | { |
864 | if (regnum == -1) | |
088568da | 865 | for (regnum = 0; |
ac7936df | 866 | regnum < gdbarch_num_regs (regcache->arch ()); |
088568da | 867 | regnum++) |
56be3814 | 868 | ia64_linux_store_register (regcache, regnum); |
74174d2e | 869 | else |
56be3814 | 870 | ia64_linux_store_register (regcache, regnum); |
74174d2e UW |
871 | } |
872 | ||
f6ac5f3d | 873 | /* Implement the xfer_partial target_ops method. */ |
74174d2e | 874 | |
f6ac5f3d PA |
875 | enum target_xfer_status |
876 | ia64_linux_nat_target::xfer_partial (enum target_object object, | |
877 | const char *annex, | |
878 | gdb_byte *readbuf, const gdb_byte *writebuf, | |
879 | ULONGEST offset, ULONGEST len, | |
880 | ULONGEST *xfered_len) | |
10d6c8cd | 881 | { |
475109d8 JB |
882 | if (object == TARGET_OBJECT_UNWIND_TABLE && readbuf != NULL) |
883 | { | |
d16461ae PA |
884 | static long gate_table_size; |
885 | gdb_byte *tmp_buf; | |
886 | long res; | |
887 | ||
888 | /* Probe for the table size once. */ | |
889 | if (gate_table_size == 0) | |
dda83cd7 | 890 | gate_table_size = syscall (__NR_getunwind, NULL, 0); |
d16461ae | 891 | if (gate_table_size < 0) |
475109d8 | 892 | return TARGET_XFER_E_IO; |
d16461ae PA |
893 | |
894 | if (offset >= gate_table_size) | |
475109d8 | 895 | return TARGET_XFER_EOF; |
d16461ae | 896 | |
bfb0d950 | 897 | tmp_buf = (gdb_byte *) alloca (gate_table_size); |
d16461ae PA |
898 | res = syscall (__NR_getunwind, tmp_buf, gate_table_size); |
899 | if (res < 0) | |
900 | return TARGET_XFER_E_IO; | |
901 | gdb_assert (res == gate_table_size); | |
902 | ||
903 | if (offset + len > gate_table_size) | |
904 | len = gate_table_size - offset; | |
905 | ||
906 | memcpy (readbuf, tmp_buf + offset, len); | |
907 | *xfered_len = len; | |
908 | return TARGET_XFER_OK; | |
475109d8 | 909 | } |
10d6c8cd | 910 | |
f6ac5f3d PA |
911 | return linux_nat_target::xfer_partial (object, annex, readbuf, writebuf, |
912 | offset, len, xfered_len); | |
10d6c8cd DJ |
913 | } |
914 | ||
26ab7092 JK |
915 | /* For break.b instruction ia64 CPU forgets the immediate value and generates |
916 | SIGILL with ILL_ILLOPC instead of more common SIGTRAP with TRAP_BRKPT. | |
917 | ia64 does not use gdbarch_decr_pc_after_break so we do not have to make any | |
918 | difference for the signals here. */ | |
919 | ||
135340af PA |
920 | bool |
921 | ia64_linux_nat_target::low_status_is_event (int status) | |
26ab7092 JK |
922 | { |
923 | return WIFSTOPPED (status) && (WSTOPSIG (status) == SIGTRAP | |
924 | || WSTOPSIG (status) == SIGILL); | |
925 | } | |
926 | ||
6c265988 | 927 | void _initialize_ia64_linux_nat (); |
10d6c8cd | 928 | void |
6c265988 | 929 | _initialize_ia64_linux_nat () |
287a334e | 930 | { |
10d6c8cd | 931 | /* Register the target. */ |
f6ac5f3d | 932 | linux_target = &the_ia64_linux_nat_target; |
d9f719f1 | 933 | add_inf_child_target (&the_ia64_linux_nat_target); |
287a334e | 934 | } |