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