* utils.c (query): Change syntax of query annotations to be
[deliverable/binutils-gdb.git] / gdb / sparc-tdep.c
1 /* Target-dependent code for the SPARC for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #include "defs.h"
22 #include "frame.h"
23 #include "inferior.h"
24 #include "obstack.h"
25 #include "target.h"
26 #include "value.h"
27
28 #include "symfile.h" /* for objfiles.h */
29 #include "objfiles.h" /* for find_pc_section */
30
31 #ifdef USE_PROC_FS
32 #include <sys/procfs.h>
33 #endif
34
35 #include "gdbcore.h"
36
37 /* From infrun.c */
38 extern int stop_after_trap;
39
40 /* We don't store all registers immediately when requested, since they
41 get sent over in large chunks anyway. Instead, we accumulate most
42 of the changes and send them over once. "deferred_stores" keeps
43 track of which sets of registers we have locally-changed copies of,
44 so we only need send the groups that have changed. */
45
46 int deferred_stores = 0; /* Cumulates stores we want to do eventually. */
47
48 typedef enum
49 {
50 Error, not_branch, bicc, bicca, ba, baa, ticc, ta
51 } branch_type;
52
53 /* Simulate single-step ptrace call for sun4. Code written by Gary
54 Beihl (beihl@mcc.com). */
55
56 /* npc4 and next_pc describe the situation at the time that the
57 step-breakpoint was set, not necessary the current value of NPC_REGNUM. */
58 static CORE_ADDR next_pc, npc4, target;
59 static int brknpc4, brktrg;
60 typedef char binsn_quantum[BREAKPOINT_MAX];
61 static binsn_quantum break_mem[3];
62
63 /* Non-zero if we just simulated a single-step ptrace call. This is
64 needed because we cannot remove the breakpoints in the inferior
65 process until after the `wait' in `wait_for_inferior'. Used for
66 sun4. */
67
68 int one_stepped;
69
70 /* single_step() is called just before we want to resume the inferior,
71 if we want to single-step it but there is no hardware or kernel single-step
72 support (as on all SPARCs). We find all the possible targets of the
73 coming instruction and breakpoint them.
74
75 single_step is also called just after the inferior stops. If we had
76 set up a simulated single-step, we undo our damage. */
77
78 void
79 single_step (ignore)
80 int ignore; /* pid, but we don't need it */
81 {
82 branch_type br, isannulled();
83 CORE_ADDR pc;
84 long pc_instruction;
85
86 if (!one_stepped)
87 {
88 /* Always set breakpoint for NPC. */
89 next_pc = read_register (NPC_REGNUM);
90 npc4 = next_pc + 4; /* branch not taken */
91
92 target_insert_breakpoint (next_pc, break_mem[0]);
93 /* printf_unfiltered ("set break at %x\n",next_pc); */
94
95 pc = read_register (PC_REGNUM);
96 pc_instruction = read_memory_integer (pc, sizeof(pc_instruction));
97 br = isannulled (pc_instruction, pc, &target);
98 brknpc4 = brktrg = 0;
99
100 if (br == bicca)
101 {
102 /* Conditional annulled branch will either end up at
103 npc (if taken) or at npc+4 (if not taken).
104 Trap npc+4. */
105 brknpc4 = 1;
106 target_insert_breakpoint (npc4, break_mem[1]);
107 }
108 else if (br == baa && target != next_pc)
109 {
110 /* Unconditional annulled branch will always end up at
111 the target. */
112 brktrg = 1;
113 target_insert_breakpoint (target, break_mem[2]);
114 }
115
116 /* We are ready to let it go */
117 one_stepped = 1;
118 return;
119 }
120 else
121 {
122 /* Remove breakpoints */
123 target_remove_breakpoint (next_pc, break_mem[0]);
124
125 if (brknpc4)
126 target_remove_breakpoint (npc4, break_mem[1]);
127
128 if (brktrg)
129 target_remove_breakpoint (target, break_mem[2]);
130
131 one_stepped = 0;
132 }
133 }
134 \f
135 CORE_ADDR
136 sparc_frame_chain (thisframe)
137 FRAME thisframe;
138 {
139 char buf[MAX_REGISTER_RAW_SIZE];
140 int err;
141 CORE_ADDR addr;
142
143 addr = thisframe->frame + FRAME_SAVED_I0 +
144 REGISTER_RAW_SIZE (FP_REGNUM) * (FP_REGNUM - I0_REGNUM);
145 err = target_read_memory (addr, buf, REGISTER_RAW_SIZE (FP_REGNUM));
146 if (err)
147 return 0;
148 return extract_address (buf, REGISTER_RAW_SIZE (FP_REGNUM));
149 }
150
151 CORE_ADDR
152 sparc_extract_struct_value_address (regbuf)
153 char regbuf[REGISTER_BYTES];
154 {
155 return read_memory_integer (((int *)(regbuf))[SP_REGNUM]+(16*4),
156 TARGET_PTR_BIT / TARGET_CHAR_BIT);
157 }
158
159 /* Find the pc saved in frame FRAME. */
160
161 CORE_ADDR
162 sparc_frame_saved_pc (frame)
163 FRAME frame;
164 {
165 char buf[MAX_REGISTER_RAW_SIZE];
166 CORE_ADDR addr;
167
168 if (frame->signal_handler_caller)
169 {
170 /* This is the signal trampoline frame.
171 Get the saved PC from the sigcontext structure. */
172
173 #ifndef SIGCONTEXT_PC_OFFSET
174 #define SIGCONTEXT_PC_OFFSET 12
175 #endif
176
177 CORE_ADDR sigcontext_addr;
178 char scbuf[TARGET_PTR_BIT / HOST_CHAR_BIT];
179 int saved_pc_offset = SIGCONTEXT_PC_OFFSET;
180 char *name = NULL;
181
182 /* Solaris2 ucbsigvechandler passes a pointer to a sigcontext
183 as the third parameter. The offset to the saved pc is 12. */
184 find_pc_partial_function (frame->pc, &name,
185 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
186 if (name && STREQ (name, "ucbsigvechandler"))
187 saved_pc_offset = 12;
188
189 /* The sigcontext address is contained in register O2. */
190 get_saved_register (buf, (int *)NULL, (CORE_ADDR *)NULL,
191 frame, O0_REGNUM + 2, (enum lval_type *)NULL);
192 sigcontext_addr = extract_address (buf, REGISTER_RAW_SIZE (O0_REGNUM));
193
194 /* Don't cause a memory_error when accessing sigcontext in case the
195 stack layout has changed or the stack is corrupt. */
196 target_read_memory (sigcontext_addr + saved_pc_offset,
197 scbuf, sizeof (scbuf));
198 return extract_address (scbuf, sizeof (scbuf));
199 }
200 addr = (frame->bottom + FRAME_SAVED_I0 +
201 REGISTER_RAW_SIZE (I7_REGNUM) * (I7_REGNUM - I0_REGNUM));
202 read_memory (addr, buf, REGISTER_RAW_SIZE (I7_REGNUM));
203 return PC_ADJUST (extract_address (buf, REGISTER_RAW_SIZE (I7_REGNUM)));
204 }
205
206 /*
207 * Since an individual frame in the frame cache is defined by two
208 * arguments (a frame pointer and a stack pointer), we need two
209 * arguments to get info for an arbitrary stack frame. This routine
210 * takes two arguments and makes the cached frames look as if these
211 * two arguments defined a frame on the cache. This allows the rest
212 * of info frame to extract the important arguments without
213 * difficulty.
214 */
215 FRAME
216 setup_arbitrary_frame (argc, argv)
217 int argc;
218 FRAME_ADDR *argv;
219 {
220 FRAME fid;
221
222 if (argc != 2)
223 error ("Sparc frame specifications require two arguments: fp and sp");
224
225 fid = create_new_frame (argv[0], 0);
226
227 if (!fid)
228 fatal ("internal: create_new_frame returned invalid frame id");
229
230 fid->bottom = argv[1];
231 fid->pc = FRAME_SAVED_PC (fid);
232 return fid;
233 }
234
235 /* Given a pc value, skip it forward past the function prologue by
236 disassembling instructions that appear to be a prologue.
237
238 If FRAMELESS_P is set, we are only testing to see if the function
239 is frameless. This allows a quicker answer.
240
241 This routine should be more specific in its actions; making sure
242 that it uses the same register in the initial prologue section. */
243 CORE_ADDR
244 skip_prologue (start_pc, frameless_p)
245 CORE_ADDR start_pc;
246 int frameless_p;
247 {
248 union
249 {
250 unsigned long int code;
251 struct
252 {
253 unsigned int op:2;
254 unsigned int rd:5;
255 unsigned int op2:3;
256 unsigned int imm22:22;
257 } sethi;
258 struct
259 {
260 unsigned int op:2;
261 unsigned int rd:5;
262 unsigned int op3:6;
263 unsigned int rs1:5;
264 unsigned int i:1;
265 unsigned int simm13:13;
266 } add;
267 int i;
268 } x;
269 int dest = -1;
270 CORE_ADDR pc = start_pc;
271
272 x.i = read_memory_integer (pc, 4);
273
274 /* Recognize the `sethi' insn and record its destination. */
275 if (x.sethi.op == 0 && x.sethi.op2 == 4)
276 {
277 dest = x.sethi.rd;
278 pc += 4;
279 x.i = read_memory_integer (pc, 4);
280 }
281
282 /* Recognize an add immediate value to register to either %g1 or
283 the destination register recorded above. Actually, this might
284 well recognize several different arithmetic operations.
285 It doesn't check that rs1 == rd because in theory "sub %g0, 5, %g1"
286 followed by "save %sp, %g1, %sp" is a valid prologue (Not that
287 I imagine any compiler really does that, however). */
288 if (x.add.op == 2 && x.add.i && (x.add.rd == 1 || x.add.rd == dest))
289 {
290 pc += 4;
291 x.i = read_memory_integer (pc, 4);
292 }
293
294 /* This recognizes any SAVE insn. But why do the XOR and then
295 the compare? That's identical to comparing against 60 (as long
296 as there isn't any sign extension). */
297 if (x.add.op == 2 && (x.add.op3 ^ 32) == 28)
298 {
299 pc += 4;
300 if (frameless_p) /* If the save is all we care about, */
301 return pc; /* return before doing more work */
302 x.i = read_memory_integer (pc, 4);
303 }
304 else
305 {
306 /* Without a save instruction, it's not a prologue. */
307 return start_pc;
308 }
309
310 /* Now we need to recognize stores into the frame from the input
311 registers. This recognizes all non alternate stores of input
312 register, into a location offset from the frame pointer. */
313 while (x.add.op == 3
314 && (x.add.op3 & 0x3c) == 4 /* Store, non-alternate. */
315 && (x.add.rd & 0x18) == 0x18 /* Input register. */
316 && x.add.i /* Immediate mode. */
317 && x.add.rs1 == 30 /* Off of frame pointer. */
318 /* Into reserved stack space. */
319 && x.add.simm13 >= 0x44
320 && x.add.simm13 < 0x5b)
321 {
322 pc += 4;
323 x.i = read_memory_integer (pc, 4);
324 }
325 return pc;
326 }
327
328 /* Check instruction at ADDR to see if it is an annulled branch.
329 All other instructions will go to NPC or will trap.
330 Set *TARGET if we find a canidate branch; set to zero if not. */
331
332 branch_type
333 isannulled (instruction, addr, target)
334 long instruction;
335 CORE_ADDR addr, *target;
336 {
337 branch_type val = not_branch;
338 long int offset; /* Must be signed for sign-extend. */
339 union
340 {
341 unsigned long int code;
342 struct
343 {
344 unsigned int op:2;
345 unsigned int a:1;
346 unsigned int cond:4;
347 unsigned int op2:3;
348 unsigned int disp22:22;
349 } b;
350 } insn;
351
352 *target = 0;
353 insn.code = instruction;
354
355 if (insn.b.op == 0
356 && (insn.b.op2 == 2 || insn.b.op2 == 6 || insn.b.op2 == 7))
357 {
358 if (insn.b.cond == 8)
359 val = insn.b.a ? baa : ba;
360 else
361 val = insn.b.a ? bicca : bicc;
362 offset = 4 * ((int) (insn.b.disp22 << 10) >> 10);
363 *target = addr + offset;
364 }
365
366 return val;
367 }
368
369 /* sparc_frame_find_saved_regs ()
370
371 Stores, into a struct frame_saved_regs,
372 the addresses of the saved registers of frame described by FRAME_INFO.
373 This includes special registers such as pc and fp saved in special
374 ways in the stack frame. sp is even more special:
375 the address we return for it IS the sp for the next frame.
376
377 Note that on register window machines, we are currently making the
378 assumption that window registers are being saved somewhere in the
379 frame in which they are being used. If they are stored in an
380 inferior frame, find_saved_register will break.
381
382 On the Sun 4, the only time all registers are saved is when
383 a dummy frame is involved. Otherwise, the only saved registers
384 are the LOCAL and IN registers which are saved as a result
385 of the "save/restore" opcodes. This condition is determined
386 by address rather than by value.
387
388 The "pc" is not stored in a frame on the SPARC. (What is stored
389 is a return address minus 8.) sparc_pop_frame knows how to
390 deal with that. Other routines might or might not.
391
392 See tm-sparc.h (PUSH_FRAME and friends) for CRITICAL information
393 about how this works. */
394
395 void
396 sparc_frame_find_saved_regs (fi, saved_regs_addr)
397 struct frame_info *fi;
398 struct frame_saved_regs *saved_regs_addr;
399 {
400 register int regnum;
401 FRAME_ADDR frame = FRAME_FP(fi);
402 FRAME fid = FRAME_INFO_ID (fi);
403
404 if (!fid)
405 fatal ("Bad frame info struct in FRAME_FIND_SAVED_REGS");
406
407 memset (saved_regs_addr, 0, sizeof (*saved_regs_addr));
408
409 if (fi->pc >= (fi->bottom ? fi->bottom :
410 read_register (SP_REGNUM))
411 && fi->pc <= FRAME_FP(fi))
412 {
413 /* Dummy frame. All but the window regs are in there somewhere. */
414 for (regnum = G1_REGNUM; regnum < G1_REGNUM+7; regnum++)
415 saved_regs_addr->regs[regnum] =
416 frame + (regnum - G0_REGNUM) * 4 - 0xa0;
417 for (regnum = I0_REGNUM; regnum < I0_REGNUM+8; regnum++)
418 saved_regs_addr->regs[regnum] =
419 frame + (regnum - I0_REGNUM) * 4 - 0xc0;
420 for (regnum = FP0_REGNUM; regnum < FP0_REGNUM + 32; regnum++)
421 saved_regs_addr->regs[regnum] =
422 frame + (regnum - FP0_REGNUM) * 4 - 0x80;
423 for (regnum = Y_REGNUM; regnum < NUM_REGS; regnum++)
424 saved_regs_addr->regs[regnum] =
425 frame + (regnum - Y_REGNUM) * 4 - 0xe0;
426 frame = fi->bottom ?
427 fi->bottom : read_register (SP_REGNUM);
428 }
429 else
430 {
431 /* Normal frame. Just Local and In registers */
432 frame = fi->bottom ?
433 fi->bottom : read_register (SP_REGNUM);
434 for (regnum = L0_REGNUM; regnum < L0_REGNUM+16; regnum++)
435 saved_regs_addr->regs[regnum] = frame + (regnum-L0_REGNUM) * 4;
436 }
437 if (fi->next)
438 {
439 /* Pull off either the next frame pointer or the stack pointer */
440 FRAME_ADDR next_next_frame =
441 (fi->next->bottom ?
442 fi->next->bottom :
443 read_register (SP_REGNUM));
444 for (regnum = O0_REGNUM; regnum < O0_REGNUM+8; regnum++)
445 saved_regs_addr->regs[regnum] = next_next_frame + regnum * 4;
446 }
447 /* Otherwise, whatever we would get from ptrace(GETREGS) is accurate */
448 saved_regs_addr->regs[SP_REGNUM] = FRAME_FP (fi);
449 }
450
451 /* Push an empty stack frame, and record in it the current PC, regs, etc.
452
453 We save the non-windowed registers and the ins. The locals and outs
454 are new; they don't need to be saved. The i's and l's of
455 the last frame were already saved on the stack. */
456
457 /* Definitely see tm-sparc.h for more doc of the frame format here. */
458
459 void
460 sparc_push_dummy_frame ()
461 {
462 CORE_ADDR sp, old_sp;
463 char register_temp[0x140];
464
465 old_sp = sp = read_register (SP_REGNUM);
466
467 /* Y, PS, WIM, TBR, PC, NPC, FPS, CPS regs */
468 read_register_bytes (REGISTER_BYTE (Y_REGNUM), &register_temp[0],
469 REGISTER_RAW_SIZE (Y_REGNUM) * 8);
470
471 read_register_bytes (REGISTER_BYTE (O0_REGNUM), &register_temp[8 * 4],
472 REGISTER_RAW_SIZE (O0_REGNUM) * 8);
473
474 read_register_bytes (REGISTER_BYTE (G0_REGNUM), &register_temp[16 * 4],
475 REGISTER_RAW_SIZE (G0_REGNUM) * 8);
476
477 read_register_bytes (REGISTER_BYTE (FP0_REGNUM), &register_temp[24 * 4],
478 REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
479
480 sp -= 0x140;
481
482 write_register (SP_REGNUM, sp);
483
484 write_memory (sp + 0x60, &register_temp[0], (8 + 8 + 8 + 32) * 4);
485
486 write_register (FP_REGNUM, old_sp);
487
488 /* Set return address register for the call dummy to the current PC. */
489 write_register (I7_REGNUM, read_pc() - 8);
490 }
491
492 /* Discard from the stack the innermost frame, restoring all saved registers.
493
494 Note that the values stored in fsr by get_frame_saved_regs are *in
495 the context of the called frame*. What this means is that the i
496 regs of fsr must be restored into the o regs of the (calling) frame that
497 we pop into. We don't care about the output regs of the calling frame,
498 since unless it's a dummy frame, it won't have any output regs in it.
499
500 We never have to bother with %l (local) regs, since the called routine's
501 locals get tossed, and the calling routine's locals are already saved
502 on its stack. */
503
504 /* Definitely see tm-sparc.h for more doc of the frame format here. */
505
506 void
507 sparc_pop_frame ()
508 {
509 register FRAME frame = get_current_frame ();
510 register CORE_ADDR pc;
511 struct frame_saved_regs fsr;
512 struct frame_info *fi;
513 char raw_buffer[REGISTER_BYTES];
514
515 fi = get_frame_info (frame);
516 get_frame_saved_regs (fi, &fsr);
517 if (fsr.regs[FP0_REGNUM])
518 {
519 read_memory (fsr.regs[FP0_REGNUM], raw_buffer, 32 * 4);
520 write_register_bytes (REGISTER_BYTE (FP0_REGNUM), raw_buffer, 32 * 4);
521 }
522 if (fsr.regs[FPS_REGNUM])
523 {
524 read_memory (fsr.regs[FPS_REGNUM], raw_buffer, 4);
525 write_register_bytes (REGISTER_BYTE (FPS_REGNUM), raw_buffer, 4);
526 }
527 if (fsr.regs[CPS_REGNUM])
528 {
529 read_memory (fsr.regs[CPS_REGNUM], raw_buffer, 4);
530 write_register_bytes (REGISTER_BYTE (CPS_REGNUM), raw_buffer, 4);
531 }
532 if (fsr.regs[G1_REGNUM])
533 {
534 read_memory (fsr.regs[G1_REGNUM], raw_buffer, 7 * 4);
535 write_register_bytes (REGISTER_BYTE (G1_REGNUM), raw_buffer, 7 * 4);
536 }
537 if (fsr.regs[I0_REGNUM])
538 {
539 CORE_ADDR sp;
540
541 char reg_temp[REGISTER_BYTES];
542
543 read_memory (fsr.regs[I0_REGNUM], raw_buffer, 8 * 4);
544
545 /* Get the ins and locals which we are about to restore. Just
546 moving the stack pointer is all that is really needed, except
547 store_inferior_registers is then going to write the ins and
548 locals from the registers array, so we need to muck with the
549 registers array. */
550 sp = fsr.regs[SP_REGNUM];
551 read_memory (sp, reg_temp, REGISTER_RAW_SIZE (L0_REGNUM) * 16);
552
553 /* Restore the out registers.
554 Among other things this writes the new stack pointer. */
555 write_register_bytes (REGISTER_BYTE (O0_REGNUM), raw_buffer,
556 REGISTER_RAW_SIZE (O0_REGNUM) * 8);
557
558 write_register_bytes (REGISTER_BYTE (L0_REGNUM), reg_temp,
559 REGISTER_RAW_SIZE (L0_REGNUM) * 16);
560 }
561 if (fsr.regs[PS_REGNUM])
562 write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4));
563 if (fsr.regs[Y_REGNUM])
564 write_register (Y_REGNUM, read_memory_integer (fsr.regs[Y_REGNUM], 4));
565 if (fsr.regs[PC_REGNUM])
566 {
567 /* Explicitly specified PC (and maybe NPC) -- just restore them. */
568 write_register (PC_REGNUM, read_memory_integer (fsr.regs[PC_REGNUM], 4));
569 if (fsr.regs[NPC_REGNUM])
570 write_register (NPC_REGNUM,
571 read_memory_integer (fsr.regs[NPC_REGNUM], 4));
572 }
573 else if (fsr.regs[I7_REGNUM])
574 {
575 /* Return address in %i7 -- adjust it, then restore PC and NPC from it */
576 pc = PC_ADJUST (read_memory_integer (fsr.regs[I7_REGNUM], 4));
577 write_register (PC_REGNUM, pc);
578 write_register (NPC_REGNUM, pc + 4);
579 }
580 flush_cached_frames ();
581 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
582 read_pc ()));
583 }
584
585 /* On the Sun 4 under SunOS, the compile will leave a fake insn which
586 encodes the structure size being returned. If we detect such
587 a fake insn, step past it. */
588
589 CORE_ADDR
590 sparc_pc_adjust(pc)
591 CORE_ADDR pc;
592 {
593 unsigned long insn;
594 char buf[4];
595 int err;
596
597 err = target_read_memory (pc + 8, buf, sizeof(long));
598 insn = extract_unsigned_integer (buf, 4);
599 if ((err == 0) && (insn & 0xfffffe00) == 0)
600 return pc+12;
601 else
602 return pc+8;
603 }
604 \f
605 #ifdef USE_PROC_FS /* Target dependent support for /proc */
606
607 /* The /proc interface divides the target machine's register set up into
608 two different sets, the general register set (gregset) and the floating
609 point register set (fpregset). For each set, there is an ioctl to get
610 the current register set and another ioctl to set the current values.
611
612 The actual structure passed through the ioctl interface is, of course,
613 naturally machine dependent, and is different for each set of registers.
614 For the sparc for example, the general register set is typically defined
615 by:
616
617 typedef int gregset_t[38];
618
619 #define R_G0 0
620 ...
621 #define R_TBR 37
622
623 and the floating point set by:
624
625 typedef struct prfpregset {
626 union {
627 u_long pr_regs[32];
628 double pr_dregs[16];
629 } pr_fr;
630 void * pr_filler;
631 u_long pr_fsr;
632 u_char pr_qcnt;
633 u_char pr_q_entrysize;
634 u_char pr_en;
635 u_long pr_q[64];
636 } prfpregset_t;
637
638 These routines provide the packing and unpacking of gregset_t and
639 fpregset_t formatted data.
640
641 */
642
643
644 /* Given a pointer to a general register set in /proc format (gregset_t *),
645 unpack the register contents and supply them as gdb's idea of the current
646 register values. */
647
648 void
649 supply_gregset (gregsetp)
650 prgregset_t *gregsetp;
651 {
652 register int regi;
653 register prgreg_t *regp = (prgreg_t *) gregsetp;
654
655 /* GDB register numbers for Gn, On, Ln, In all match /proc reg numbers. */
656 for (regi = G0_REGNUM ; regi <= I7_REGNUM ; regi++)
657 {
658 supply_register (regi, (char *) (regp + regi));
659 }
660
661 /* These require a bit more care. */
662 supply_register (PS_REGNUM, (char *) (regp + R_PS));
663 supply_register (PC_REGNUM, (char *) (regp + R_PC));
664 supply_register (NPC_REGNUM,(char *) (regp + R_nPC));
665 supply_register (Y_REGNUM, (char *) (regp + R_Y));
666 }
667
668 void
669 fill_gregset (gregsetp, regno)
670 prgregset_t *gregsetp;
671 int regno;
672 {
673 int regi;
674 register prgreg_t *regp = (prgreg_t *) gregsetp;
675 extern char registers[];
676
677 for (regi = 0 ; regi <= R_I7 ; regi++)
678 {
679 if ((regno == -1) || (regno == regi))
680 {
681 *(regp + regi) = *(int *) &registers[REGISTER_BYTE (regi)];
682 }
683 }
684 if ((regno == -1) || (regno == PS_REGNUM))
685 {
686 *(regp + R_PS) = *(int *) &registers[REGISTER_BYTE (PS_REGNUM)];
687 }
688 if ((regno == -1) || (regno == PC_REGNUM))
689 {
690 *(regp + R_PC) = *(int *) &registers[REGISTER_BYTE (PC_REGNUM)];
691 }
692 if ((regno == -1) || (regno == NPC_REGNUM))
693 {
694 *(regp + R_nPC) = *(int *) &registers[REGISTER_BYTE (NPC_REGNUM)];
695 }
696 if ((regno == -1) || (regno == Y_REGNUM))
697 {
698 *(regp + R_Y) = *(int *) &registers[REGISTER_BYTE (Y_REGNUM)];
699 }
700 }
701
702 #if defined (FP0_REGNUM)
703
704 /* Given a pointer to a floating point register set in /proc format
705 (fpregset_t *), unpack the register contents and supply them as gdb's
706 idea of the current floating point register values. */
707
708 void
709 supply_fpregset (fpregsetp)
710 prfpregset_t *fpregsetp;
711 {
712 register int regi;
713 char *from;
714
715 for (regi = FP0_REGNUM ; regi < FP0_REGNUM+32 ; regi++)
716 {
717 from = (char *) &fpregsetp->pr_fr.pr_regs[regi-FP0_REGNUM];
718 supply_register (regi, from);
719 }
720 supply_register (FPS_REGNUM, (char *) &(fpregsetp->pr_fsr));
721 }
722
723 /* Given a pointer to a floating point register set in /proc format
724 (fpregset_t *), update the register specified by REGNO from gdb's idea
725 of the current floating point register set. If REGNO is -1, update
726 them all. */
727
728 void
729 fill_fpregset (fpregsetp, regno)
730 prfpregset_t *fpregsetp;
731 int regno;
732 {
733 int regi;
734 char *to;
735 char *from;
736 extern char registers[];
737
738 for (regi = FP0_REGNUM ; regi < FP0_REGNUM+32 ; regi++)
739 {
740 if ((regno == -1) || (regno == regi))
741 {
742 from = (char *) &registers[REGISTER_BYTE (regi)];
743 to = (char *) &fpregsetp->pr_fr.pr_regs[regi-FP0_REGNUM];
744 memcpy (to, from, REGISTER_RAW_SIZE (regi));
745 }
746 }
747 if ((regno == -1) || (regno == FPS_REGNUM))
748 {
749 fpregsetp->pr_fsr = *(int *) &registers[REGISTER_BYTE (FPS_REGNUM)];
750 }
751 }
752
753 #endif /* defined (FP0_REGNUM) */
754
755 #endif /* USE_PROC_FS */
756
757
758 #ifdef GET_LONGJMP_TARGET
759
760 /* Figure out where the longjmp will land. We expect that we have just entered
761 longjmp and haven't yet setup the stack frame, so the args are still in the
762 output regs. %o0 (O0_REGNUM) points at the jmp_buf structure from which we
763 extract the pc (JB_PC) that we will land at. The pc is copied into ADDR.
764 This routine returns true on success */
765
766 int
767 get_longjmp_target(pc)
768 CORE_ADDR *pc;
769 {
770 CORE_ADDR jb_addr;
771 #define LONGJMP_TARGET_SIZE 4
772 char buf[LONGJMP_TARGET_SIZE];
773
774 jb_addr = read_register(O0_REGNUM);
775
776 if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
777 LONGJMP_TARGET_SIZE))
778 return 0;
779
780 *pc = extract_address (buf, LONGJMP_TARGET_SIZE);
781
782 return 1;
783 }
784 #endif /* GET_LONGJMP_TARGET */
785
786 /* So far used only for sparc solaris. In sparc solaris, we recognize
787 a trampoline by it's section name. That is, if the pc is in a
788 section named ".plt" then we are in a trampline. */
789
790 int
791 in_solib_trampoline(pc, name)
792 CORE_ADDR pc;
793 char *name;
794 {
795 struct obj_section *s;
796 int retval = 0;
797
798 s = find_pc_section(pc);
799
800 retval = (s != NULL
801 && s->the_bfd_section->name != NULL
802 && STREQ (s->the_bfd_section->name, ".plt"));
803 return(retval);
804 }
805
This page took 0.049052 seconds and 4 git commands to generate.