1 /* Target-dependent code for the SPARC for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* ??? Support for calling functions from gdb in sparc64 is unfinished. */
30 #include "gdb_string.h"
33 #include <sys/procfs.h>
38 #ifdef GDB_TARGET_IS_SPARC64
39 #define FP_REGISTER_BYTES (64 * 4)
41 #define FP_REGISTER_BYTES (32 * 4)
44 /* If not defined, assume 32 bit sparc. */
46 #define FP_MAX_REGNUM (FP0_REGNUM + 32)
49 #define SPARC_INTREG_SIZE (REGISTER_RAW_SIZE (G0_REGNUM))
52 extern int stop_after_trap
;
54 /* We don't store all registers immediately when requested, since they
55 get sent over in large chunks anyway. Instead, we accumulate most
56 of the changes and send them over once. "deferred_stores" keeps
57 track of which sets of registers we have locally-changed copies of,
58 so we only need send the groups that have changed. */
60 int deferred_stores
= 0; /* Cumulates stores we want to do eventually. */
62 /* Branches with prediction are treated like their non-predicting cousins. */
63 /* FIXME: What about floating point branches? */
65 /* Macros to extract fields from sparc instructions. */
66 #define X_OP(i) (((i) >> 30) & 0x3)
67 #define X_RD(i) (((i) >> 25) & 0x1f)
68 #define X_A(i) (((i) >> 29) & 1)
69 #define X_COND(i) (((i) >> 25) & 0xf)
70 #define X_OP2(i) (((i) >> 22) & 0x7)
71 #define X_IMM22(i) ((i) & 0x3fffff)
72 #define X_OP3(i) (((i) >> 19) & 0x3f)
73 #define X_RS1(i) (((i) >> 14) & 0x1f)
74 #define X_I(i) (((i) >> 13) & 1)
75 #define X_IMM13(i) ((i) & 0x1fff)
76 /* Sign extension macros. */
77 #define X_SIMM13(i) ((X_IMM13 (i) ^ 0x1000) - 0x1000)
78 #define X_DISP22(i) ((X_IMM22 (i) ^ 0x200000) - 0x200000)
79 #define X_CC(i) (((i) >> 20) & 3)
80 #define X_P(i) (((i) >> 19) & 1)
81 #define X_DISP19(i) ((((i) & 0x7ffff) ^ 0x40000) - 0x40000)
82 #define X_RCOND(i) (((i) >> 25) & 7)
83 #define X_DISP16(i) ((((((i) >> 6) && 0xc000) | ((i) & 0x3fff)) ^ 0x8000) - 0x8000)
84 #define X_FCN(i) (((i) >> 25) & 31)
88 Error
, not_branch
, bicc
, bicca
, ba
, baa
, ticc
, ta
,
89 #ifdef GDB_TARGET_IS_SPARC64
94 /* Simulate single-step ptrace call for sun4. Code written by Gary
95 Beihl (beihl@mcc.com). */
97 /* npc4 and next_pc describe the situation at the time that the
98 step-breakpoint was set, not necessary the current value of NPC_REGNUM. */
99 static CORE_ADDR next_pc
, npc4
, target
;
100 static int brknpc4
, brktrg
;
101 typedef char binsn_quantum
[BREAKPOINT_MAX
];
102 static binsn_quantum break_mem
[3];
104 /* Non-zero if we just simulated a single-step ptrace call. This is
105 needed because we cannot remove the breakpoints in the inferior
106 process until after the `wait' in `wait_for_inferior'. Used for
111 static branch_type isbranch
PARAMS ((long, CORE_ADDR
, CORE_ADDR
*));
113 /* single_step() is called just before we want to resume the inferior,
114 if we want to single-step it but there is no hardware or kernel single-step
115 support (as on all SPARCs). We find all the possible targets of the
116 coming instruction and breakpoint them.
118 single_step is also called just after the inferior stops. If we had
119 set up a simulated single-step, we undo our damage. */
123 enum target_signal ignore
; /* pid, but we don't need it */
131 /* Always set breakpoint for NPC. */
132 next_pc
= read_register (NPC_REGNUM
);
133 npc4
= next_pc
+ 4; /* branch not taken */
135 target_insert_breakpoint (next_pc
, break_mem
[0]);
136 /* printf_unfiltered ("set break at %x\n",next_pc); */
138 pc
= read_register (PC_REGNUM
);
139 pc_instruction
= read_memory_integer (pc
, 4);
140 br
= isbranch (pc_instruction
, pc
, &target
);
141 brknpc4
= brktrg
= 0;
145 /* Conditional annulled branch will either end up at
146 npc (if taken) or at npc+4 (if not taken).
149 target_insert_breakpoint (npc4
, break_mem
[1]);
151 else if (br
== baa
&& target
!= next_pc
)
153 /* Unconditional annulled branch will always end up at
156 target_insert_breakpoint (target
, break_mem
[2]);
158 #ifdef GDB_TARGET_IS_SPARC64
159 else if (br
== done_retry
)
162 target_insert_breakpoint (target
, break_mem
[2]);
166 /* We are ready to let it go */
172 /* Remove breakpoints */
173 target_remove_breakpoint (next_pc
, break_mem
[0]);
176 target_remove_breakpoint (npc4
, break_mem
[1]);
179 target_remove_breakpoint (target
, break_mem
[2]);
185 /* Call this for each newly created frame. For SPARC, we need to calculate
186 the bottom of the frame, and do some extra work if the prologue
187 has been generated via the -mflat option to GCC. In particular,
188 we need to know where the previous fp and the pc have been stashed,
189 since their exact position within the frame may vary. */
192 sparc_init_extra_frame_info (fromleaf
, fi
)
194 struct frame_info
*fi
;
202 (fi
->frame
== fi
->next
->frame
? fi
->next
->bottom
: fi
->next
->frame
) :
203 read_register (SP_REGNUM
));
205 /* If fi->next is NULL, then we already set ->frame by passing read_fp()
206 to create_new_frame. */
209 char buf
[MAX_REGISTER_RAW_SIZE
];
211 /* Compute ->frame as if not flat. If it is flat, we'll change
213 if (fi
->next
->next
!= NULL
214 && (fi
->next
->next
->signal_handler_caller
215 || frame_in_dummy (fi
->next
->next
))
216 && frameless_look_for_prologue (fi
->next
))
218 /* A frameless function interrupted by a signal did not change
219 the frame pointer, fix up frame pointer accordingly. */
220 fi
->frame
= FRAME_FP (fi
->next
);
221 fi
->bottom
= fi
->next
->bottom
;
225 get_saved_register (buf
, 0, 0, fi
, FP_REGNUM
, 0);
226 fi
->frame
= extract_address (buf
, REGISTER_RAW_SIZE (FP_REGNUM
));
230 /* Decide whether this is a function with a ``flat register window''
231 frame. For such functions, the frame pointer is actually in %i7. */
233 if (find_pc_partial_function (fi
->pc
, &name
, &addr
, NULL
))
235 /* See if the function starts with an add (which will be of a
236 negative number if a flat frame) to the sp. FIXME: Does not
237 handle large frames which will need more than one instruction
239 insn
= read_memory_integer (addr
, 4);
240 if (X_OP (insn
) == 2 && X_RD (insn
) == 14 && X_OP3 (insn
) == 0
241 && X_I (insn
) && X_SIMM13 (insn
) < 0)
243 int offset
= X_SIMM13 (insn
);
245 /* Then look for a save of %i7 into the frame. */
246 insn
= read_memory_integer (addr
+ 4, 4);
250 && X_RS1 (insn
) == 14)
252 char buf
[MAX_REGISTER_RAW_SIZE
];
254 /* We definitely have a flat frame now. */
257 fi
->sp_offset
= offset
;
259 /* Overwrite the frame's address with the value in %i7. */
260 get_saved_register (buf
, 0, 0, fi
, I7_REGNUM
, 0);
261 fi
->frame
= extract_address (buf
, REGISTER_RAW_SIZE (I7_REGNUM
));
263 /* Record where the fp got saved. */
264 fi
->fp_addr
= fi
->frame
+ fi
->sp_offset
+ X_SIMM13 (insn
);
266 /* Also try to collect where the pc got saved to. */
268 insn
= read_memory_integer (addr
+ 12, 4);
272 && X_RS1 (insn
) == 14)
273 fi
->pc_addr
= fi
->frame
+ fi
->sp_offset
+ X_SIMM13 (insn
);
277 if (fi
->next
&& fi
->frame
== 0)
279 /* Kludge to cause init_prev_frame_info to destroy the new frame. */
280 fi
->frame
= fi
->next
->frame
;
281 fi
->pc
= fi
->next
->pc
;
286 sparc_frame_chain (frame
)
287 struct frame_info
*frame
;
289 /* Value that will cause FRAME_CHAIN_VALID to not worry about the chain
290 value. If it realy is zero, we detect it later in
291 sparc_init_prev_frame. */
296 sparc_extract_struct_value_address (regbuf
)
297 char regbuf
[REGISTER_BYTES
];
299 #ifdef GDB_TARGET_IS_SPARC64
300 return extract_address (regbuf
+ REGISTER_BYTE (O0_REGNUM
),
301 REGISTER_RAW_SIZE (O0_REGNUM
));
303 CORE_ADDR sp
= extract_address (®buf
[REGISTER_BYTE (SP_REGNUM
)],
304 REGISTER_RAW_SIZE (SP_REGNUM
));
305 return read_memory_integer (sp
+ (16 * SPARC_INTREG_SIZE
),
306 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
310 /* Find the pc saved in frame FRAME. */
313 sparc_frame_saved_pc (frame
)
314 struct frame_info
*frame
;
316 char buf
[MAX_REGISTER_RAW_SIZE
];
319 if (frame
->signal_handler_caller
)
321 /* This is the signal trampoline frame.
322 Get the saved PC from the sigcontext structure. */
324 #ifndef SIGCONTEXT_PC_OFFSET
325 #define SIGCONTEXT_PC_OFFSET 12
328 CORE_ADDR sigcontext_addr
;
329 char scbuf
[TARGET_PTR_BIT
/ HOST_CHAR_BIT
];
330 int saved_pc_offset
= SIGCONTEXT_PC_OFFSET
;
333 /* Solaris2 ucbsigvechandler passes a pointer to a sigcontext
334 as the third parameter. The offset to the saved pc is 12. */
335 find_pc_partial_function (frame
->pc
, &name
,
336 (CORE_ADDR
*)NULL
,(CORE_ADDR
*)NULL
);
337 if (name
&& STREQ (name
, "ucbsigvechandler"))
338 saved_pc_offset
= 12;
340 /* The sigcontext address is contained in register O2. */
341 get_saved_register (buf
, (int *)NULL
, (CORE_ADDR
*)NULL
,
342 frame
, O0_REGNUM
+ 2, (enum lval_type
*)NULL
);
343 sigcontext_addr
= extract_address (buf
, REGISTER_RAW_SIZE (O0_REGNUM
+ 2));
345 /* Don't cause a memory_error when accessing sigcontext in case the
346 stack layout has changed or the stack is corrupt. */
347 target_read_memory (sigcontext_addr
+ saved_pc_offset
,
348 scbuf
, sizeof (scbuf
));
349 return extract_address (scbuf
, sizeof (scbuf
));
351 else if (frame
->next
!= NULL
352 && (frame
->next
->signal_handler_caller
353 || frame_in_dummy (frame
->next
))
354 && frameless_look_for_prologue (frame
))
356 /* A frameless function interrupted by a signal did not save
357 the PC, it is still in %o7. */
358 get_saved_register (buf
, (int *)NULL
, (CORE_ADDR
*)NULL
,
359 frame
, O7_REGNUM
, (enum lval_type
*)NULL
);
360 return PC_ADJUST (extract_address (buf
, SPARC_INTREG_SIZE
));
363 addr
= frame
->pc_addr
;
365 addr
= frame
->bottom
+ FRAME_SAVED_I0
+
366 SPARC_INTREG_SIZE
* (I7_REGNUM
- I0_REGNUM
);
369 /* A flat frame leaf function might not save the PC anywhere,
370 just leave it in %o7. */
371 return PC_ADJUST (read_register (O7_REGNUM
));
373 read_memory (addr
, buf
, SPARC_INTREG_SIZE
);
374 return PC_ADJUST (extract_address (buf
, SPARC_INTREG_SIZE
));
377 /* Since an individual frame in the frame cache is defined by two
378 arguments (a frame pointer and a stack pointer), we need two
379 arguments to get info for an arbitrary stack frame. This routine
380 takes two arguments and makes the cached frames look as if these
381 two arguments defined a frame on the cache. This allows the rest
382 of info frame to extract the important arguments without
386 setup_arbitrary_frame (argc
, argv
)
390 struct frame_info
*frame
;
393 error ("Sparc frame specifications require two arguments: fp and sp");
395 frame
= create_new_frame (argv
[0], 0);
398 fatal ("internal: create_new_frame returned invalid frame");
400 frame
->bottom
= argv
[1];
401 frame
->pc
= FRAME_SAVED_PC (frame
);
405 /* Given a pc value, skip it forward past the function prologue by
406 disassembling instructions that appear to be a prologue.
408 If FRAMELESS_P is set, we are only testing to see if the function
409 is frameless. This allows a quicker answer.
411 This routine should be more specific in its actions; making sure
412 that it uses the same register in the initial prologue section. */
414 static CORE_ADDR examine_prologue
PARAMS ((CORE_ADDR
, int, struct frame_info
*,
415 struct frame_saved_regs
*));
418 examine_prologue (start_pc
, frameless_p
, fi
, saved_regs
)
421 struct frame_info
*fi
;
422 struct frame_saved_regs
*saved_regs
;
426 CORE_ADDR pc
= start_pc
;
429 insn
= read_memory_integer (pc
, 4);
431 /* Recognize the `sethi' insn and record its destination. */
432 if (X_OP (insn
) == 0 && X_OP2 (insn
) == 4)
436 insn
= read_memory_integer (pc
, 4);
439 /* Recognize an add immediate value to register to either %g1 or
440 the destination register recorded above. Actually, this might
441 well recognize several different arithmetic operations.
442 It doesn't check that rs1 == rd because in theory "sub %g0, 5, %g1"
443 followed by "save %sp, %g1, %sp" is a valid prologue (Not that
444 I imagine any compiler really does that, however). */
447 && (X_RD (insn
) == 1 || X_RD (insn
) == dest
))
450 insn
= read_memory_integer (pc
, 4);
453 /* Recognize any SAVE insn. */
454 if (X_OP (insn
) == 2 && X_OP3 (insn
) == 60)
457 if (frameless_p
) /* If the save is all we care about, */
458 return pc
; /* return before doing more work */
459 insn
= read_memory_integer (pc
, 4);
461 /* Recognize add to %sp. */
462 else if (X_OP (insn
) == 2 && X_RD (insn
) == 14 && X_OP3 (insn
) == 0)
465 if (frameless_p
) /* If the add is all we care about, */
466 return pc
; /* return before doing more work */
468 insn
= read_memory_integer (pc
, 4);
469 /* Recognize store of frame pointer (i7). */
473 && X_RS1 (insn
) == 14)
476 insn
= read_memory_integer (pc
, 4);
478 /* Recognize sub %sp, <anything>, %i7. */
481 && X_RS1 (insn
) == 14
482 && X_RD (insn
) == 31)
485 insn
= read_memory_integer (pc
, 4);
494 /* Without a save or add instruction, it's not a prologue. */
499 /* Recognize stores into the frame from the input registers.
500 This recognizes all non alternate stores of input register,
501 into a location offset from the frame pointer. */
502 if ((X_OP (insn
) == 3
503 && (X_OP3 (insn
) & 0x3c) == 4 /* Store, non-alternate. */
504 && (X_RD (insn
) & 0x18) == 0x18 /* Input register. */
505 && X_I (insn
) /* Immediate mode. */
506 && X_RS1 (insn
) == 30 /* Off of frame pointer. */
507 /* Into reserved stack space. */
508 && X_SIMM13 (insn
) >= 0x44
509 && X_SIMM13 (insn
) < 0x5b))
514 && X_RS1 (insn
) == 14
517 if (saved_regs
&& X_I (insn
))
518 saved_regs
->regs
[X_RD (insn
)] =
519 fi
->frame
+ fi
->sp_offset
+ X_SIMM13 (insn
);
524 insn
= read_memory_integer (pc
, 4);
531 skip_prologue (start_pc
, frameless_p
)
535 return examine_prologue (start_pc
, frameless_p
, NULL
, NULL
);
538 /* Check instruction at ADDR to see if it is a branch.
539 All non-annulled instructions will go to NPC or will trap.
540 Set *TARGET if we find a candidate branch; set to zero if not.
542 This isn't static as it's used by remote-sa.sparc.c. */
545 isbranch (instruction
, addr
, target
)
547 CORE_ADDR addr
, *target
;
549 branch_type val
= not_branch
;
550 long int offset
= 0; /* Must be signed for sign-extend. */
554 if (X_OP (instruction
) == 0
555 && (X_OP2 (instruction
) == 2
556 || X_OP2 (instruction
) == 6
557 || X_OP2 (instruction
) == 1
558 || X_OP2 (instruction
) == 3
559 || X_OP2 (instruction
) == 5
560 #ifndef GDB_TARGET_IS_SPARC64
561 || X_OP2 (instruction
) == 7
565 if (X_COND (instruction
) == 8)
566 val
= X_A (instruction
) ? baa
: ba
;
568 val
= X_A (instruction
) ? bicca
: bicc
;
569 switch (X_OP2 (instruction
))
573 #ifndef GDB_TARGET_IS_SPARC64
576 offset
= 4 * X_DISP22 (instruction
);
580 offset
= 4 * X_DISP19 (instruction
);
583 offset
= 4 * X_DISP16 (instruction
);
586 *target
= addr
+ offset
;
588 #ifdef GDB_TARGET_IS_SPARC64
589 else if (X_OP (instruction
) == 2
590 && X_OP3 (instruction
) == 62)
592 if (X_FCN (instruction
) == 0)
595 *target
= read_register (TNPC_REGNUM
);
598 else if (X_FCN (instruction
) == 1)
601 *target
= read_register (TPC_REGNUM
);
610 /* Find register number REGNUM relative to FRAME and put its
611 (raw) contents in *RAW_BUFFER. Set *OPTIMIZED if the variable
612 was optimized out (and thus can't be fetched). If the variable
613 was fetched from memory, set *ADDRP to where it was fetched from,
614 otherwise it was fetched from a register.
616 The argument RAW_BUFFER must point to aligned memory. */
619 get_saved_register (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
)
623 struct frame_info
*frame
;
625 enum lval_type
*lval
;
627 struct frame_info
*frame1
;
630 if (!target_has_registers
)
631 error ("No registers.");
638 /* FIXME This code extracted from infcmd.c; should put elsewhere! */
641 /* error ("No selected frame."); */
642 if (!target_has_registers
)
643 error ("The program has no registers now.");
644 if (selected_frame
== NULL
)
645 error ("No selected frame.");
646 /* Try to use selected frame */
647 frame
= get_prev_frame (selected_frame
);
649 error ("Cmd not meaningful in the outermost frame.");
653 frame1
= frame
->next
;
655 /* Get saved PC from the frame info if not in innermost frame. */
656 if (regnum
== PC_REGNUM
&& frame1
!= NULL
)
660 if (raw_buffer
!= NULL
)
662 /* Put it back in target format. */
663 store_address (raw_buffer
, REGISTER_RAW_SIZE (regnum
), frame
->pc
);
670 while (frame1
!= NULL
)
672 if (frame1
->pc
>= (frame1
->bottom
? frame1
->bottom
:
673 read_register (SP_REGNUM
))
674 && frame1
->pc
<= FRAME_FP (frame1
))
676 /* Dummy frame. All but the window regs are in there somewhere.
677 The window registers are saved on the stack, just like in a
679 if (regnum
>= G1_REGNUM
&& regnum
< G1_REGNUM
+ 7)
680 addr
= frame1
->frame
+ (regnum
- G0_REGNUM
) * SPARC_INTREG_SIZE
681 - (FP_REGISTER_BYTES
+ 8 * SPARC_INTREG_SIZE
);
682 else if (regnum
>= I0_REGNUM
&& regnum
< I0_REGNUM
+ 8)
683 addr
= (frame1
->prev
->bottom
684 + (regnum
- I0_REGNUM
) * SPARC_INTREG_SIZE
686 else if (regnum
>= L0_REGNUM
&& regnum
< L0_REGNUM
+ 8)
687 addr
= (frame1
->prev
->bottom
688 + (regnum
- L0_REGNUM
) * SPARC_INTREG_SIZE
690 else if (regnum
>= O0_REGNUM
&& regnum
< O0_REGNUM
+ 8)
691 addr
= frame1
->frame
+ (regnum
- O0_REGNUM
) * SPARC_INTREG_SIZE
692 - (FP_REGISTER_BYTES
+ 16 * SPARC_INTREG_SIZE
);
694 else if (regnum
>= FP0_REGNUM
&& regnum
< FP0_REGNUM
+ 32)
695 addr
= frame1
->frame
+ (regnum
- FP0_REGNUM
) * 4
696 - (FP_REGISTER_BYTES
);
697 #ifdef GDB_TARGET_IS_SPARC64
698 else if (regnum
>= FP0_REGNUM
+ 32 && regnum
< FP_MAX_REGNUM
)
699 addr
= frame1
->frame
+ 32 * 4 + (regnum
- FP0_REGNUM
- 32) * 8
700 - (FP_REGISTER_BYTES
);
702 #endif /* FP0_REGNUM */
703 else if (regnum
>= Y_REGNUM
&& regnum
< NUM_REGS
)
704 addr
= frame1
->frame
+ (regnum
- Y_REGNUM
) * SPARC_INTREG_SIZE
705 - (FP_REGISTER_BYTES
+ 24 * SPARC_INTREG_SIZE
);
707 else if (frame1
->flat
)
710 if (regnum
== RP_REGNUM
)
711 addr
= frame1
->pc_addr
;
712 else if (regnum
== I7_REGNUM
)
713 addr
= frame1
->fp_addr
;
716 CORE_ADDR func_start
;
717 struct frame_saved_regs regs
;
718 memset (®s
, 0, sizeof (regs
));
720 find_pc_partial_function (frame1
->pc
, NULL
, &func_start
, NULL
);
721 examine_prologue (func_start
, 0, frame1
, ®s
);
722 addr
= regs
.regs
[regnum
];
727 /* Normal frame. Local and In registers are saved on stack. */
728 if (regnum
>= I0_REGNUM
&& regnum
< I0_REGNUM
+ 8)
729 addr
= (frame1
->prev
->bottom
730 + (regnum
- I0_REGNUM
) * SPARC_INTREG_SIZE
732 else if (regnum
>= L0_REGNUM
&& regnum
< L0_REGNUM
+ 8)
733 addr
= (frame1
->prev
->bottom
734 + (regnum
- L0_REGNUM
) * SPARC_INTREG_SIZE
736 else if (regnum
>= O0_REGNUM
&& regnum
< O0_REGNUM
+ 8)
738 /* Outs become ins. */
739 get_saved_register (raw_buffer
, optimized
, addrp
, frame1
,
740 (regnum
- O0_REGNUM
+ I0_REGNUM
), lval
);
746 frame1
= frame1
->next
;
752 if (regnum
== SP_REGNUM
)
754 if (raw_buffer
!= NULL
)
756 /* Put it back in target format. */
757 store_address (raw_buffer
, REGISTER_RAW_SIZE (regnum
), addr
);
763 if (raw_buffer
!= NULL
)
764 read_memory (addr
, raw_buffer
, REGISTER_RAW_SIZE (regnum
));
769 *lval
= lval_register
;
770 addr
= REGISTER_BYTE (regnum
);
771 if (raw_buffer
!= NULL
)
772 read_register_gen (regnum
, raw_buffer
);
778 /* Push an empty stack frame, and record in it the current PC, regs, etc.
780 We save the non-windowed registers and the ins. The locals and outs
781 are new; they don't need to be saved. The i's and l's of
782 the last frame were already saved on the stack. */
784 /* Definitely see tm-sparc.h for more doc of the frame format here. */
786 #ifdef GDB_TARGET_IS_SPARC64
787 #define DUMMY_REG_SAVE_OFFSET (128 + 16)
789 #define DUMMY_REG_SAVE_OFFSET 0x60
792 /* See tm-sparc.h for how this is calculated. */
794 #define DUMMY_STACK_REG_BUF_SIZE \
795 (((8+8+8) * SPARC_INTREG_SIZE) + (32 * REGISTER_RAW_SIZE (FP0_REGNUM)))
797 #define DUMMY_STACK_REG_BUF_SIZE \
798 (((8+8+8) * SPARC_INTREG_SIZE) )
799 #endif /* FP0_REGNUM */
800 #define DUMMY_STACK_SIZE (DUMMY_STACK_REG_BUF_SIZE + DUMMY_REG_SAVE_OFFSET)
803 sparc_push_dummy_frame ()
805 CORE_ADDR sp
, old_sp
;
806 char register_temp
[DUMMY_STACK_SIZE
];
808 old_sp
= sp
= read_register (SP_REGNUM
);
810 #ifdef GDB_TARGET_IS_SPARC64
811 /* FIXME: not sure what needs to be saved here. */
813 /* Y, PS, WIM, TBR, PC, NPC, FPS, CPS regs */
814 read_register_bytes (REGISTER_BYTE (Y_REGNUM
), ®ister_temp
[0],
815 REGISTER_RAW_SIZE (Y_REGNUM
) * 8);
818 read_register_bytes (REGISTER_BYTE (O0_REGNUM
),
819 ®ister_temp
[8 * SPARC_INTREG_SIZE
],
820 SPARC_INTREG_SIZE
* 8);
822 read_register_bytes (REGISTER_BYTE (G0_REGNUM
),
823 ®ister_temp
[16 * SPARC_INTREG_SIZE
],
824 SPARC_INTREG_SIZE
* 8);
827 read_register_bytes (REGISTER_BYTE (FP0_REGNUM
),
828 ®ister_temp
[24 * SPARC_INTREG_SIZE
],
830 #endif /* FP0_REGNUM */
832 sp
-= DUMMY_STACK_SIZE
;
834 write_register (SP_REGNUM
, sp
);
836 write_memory (sp
+ DUMMY_REG_SAVE_OFFSET
, ®ister_temp
[0],
837 DUMMY_STACK_REG_BUF_SIZE
);
839 write_register (FP_REGNUM
, old_sp
);
841 /* Set return address register for the call dummy to the current PC. */
842 write_register (I7_REGNUM
, read_pc() - 8);
845 /* sparc_frame_find_saved_regs (). This function is here only because
846 pop_frame uses it. Note there is an interesting corner case which
847 I think few ports of GDB get right--if you are popping a frame
848 which does not save some register that *is* saved by a more inner
849 frame (such a frame will never be a dummy frame because dummy
850 frames save all registers). Rewriting pop_frame to use
851 get_saved_register would solve this problem and also get rid of the
852 ugly duplication between sparc_frame_find_saved_regs and
855 Stores, into a struct frame_saved_regs,
856 the addresses of the saved registers of frame described by FRAME_INFO.
857 This includes special registers such as pc and fp saved in special
858 ways in the stack frame. sp is even more special:
859 the address we return for it IS the sp for the next frame.
861 Note that on register window machines, we are currently making the
862 assumption that window registers are being saved somewhere in the
863 frame in which they are being used. If they are stored in an
864 inferior frame, find_saved_register will break.
866 On the Sun 4, the only time all registers are saved is when
867 a dummy frame is involved. Otherwise, the only saved registers
868 are the LOCAL and IN registers which are saved as a result
869 of the "save/restore" opcodes. This condition is determined
870 by address rather than by value.
872 The "pc" is not stored in a frame on the SPARC. (What is stored
873 is a return address minus 8.) sparc_pop_frame knows how to
874 deal with that. Other routines might or might not.
876 See tm-sparc.h (PUSH_FRAME and friends) for CRITICAL information
877 about how this works. */
879 static void sparc_frame_find_saved_regs
PARAMS ((struct frame_info
*,
880 struct frame_saved_regs
*));
883 sparc_frame_find_saved_regs (fi
, saved_regs_addr
)
884 struct frame_info
*fi
;
885 struct frame_saved_regs
*saved_regs_addr
;
888 CORE_ADDR frame_addr
= FRAME_FP (fi
);
891 fatal ("Bad frame info struct in FRAME_FIND_SAVED_REGS");
893 memset (saved_regs_addr
, 0, sizeof (*saved_regs_addr
));
895 if (fi
->pc
>= (fi
->bottom
? fi
->bottom
:
896 read_register (SP_REGNUM
))
897 && fi
->pc
<= FRAME_FP(fi
))
899 /* Dummy frame. All but the window regs are in there somewhere. */
900 for (regnum
= G1_REGNUM
; regnum
< G1_REGNUM
+7; regnum
++)
901 saved_regs_addr
->regs
[regnum
] =
902 frame_addr
+ (regnum
- G0_REGNUM
) * SPARC_INTREG_SIZE
903 - DUMMY_STACK_REG_BUF_SIZE
+ 16 * SPARC_INTREG_SIZE
;
904 for (regnum
= I0_REGNUM
; regnum
< I0_REGNUM
+8; regnum
++)
905 saved_regs_addr
->regs
[regnum
] =
906 frame_addr
+ (regnum
- I0_REGNUM
) * SPARC_INTREG_SIZE
907 - DUMMY_STACK_REG_BUF_SIZE
+ 8 * SPARC_INTREG_SIZE
;
909 for (regnum
= FP0_REGNUM
; regnum
< FP0_REGNUM
+ 32; regnum
++)
910 saved_regs_addr
->regs
[regnum
] =
911 frame_addr
+ (regnum
- FP0_REGNUM
) * 4
912 - DUMMY_STACK_REG_BUF_SIZE
+ 24 * SPARC_INTREG_SIZE
;
913 #ifdef GDB_TARGET_IS_SPARC64
914 for (regnum
= FP0_REGNUM
+ 32; regnum
< FP_MAX_REGNUM
; regnum
++)
915 saved_regs_addr
->regs
[regnum
] =
916 frame_addr
+ 32 * 4 + (regnum
- FP0_REGNUM
- 32) * 8
917 - DUMMY_STACK_REG_BUF_SIZE
+ 24 * SPARC_INTREG_SIZE
;
919 #endif /* FP0_REGNUM */
920 for (regnum
= Y_REGNUM
; regnum
< NUM_REGS
; regnum
++)
921 saved_regs_addr
->regs
[regnum
] =
922 frame_addr
+ (regnum
- Y_REGNUM
) * SPARC_INTREG_SIZE
923 - DUMMY_STACK_REG_BUF_SIZE
;
924 frame_addr
= fi
->bottom
?
925 fi
->bottom
: read_register (SP_REGNUM
);
929 CORE_ADDR func_start
;
930 find_pc_partial_function (fi
->pc
, NULL
, &func_start
, NULL
);
931 examine_prologue (func_start
, 0, fi
, saved_regs_addr
);
933 /* Flat register window frame. */
934 saved_regs_addr
->regs
[RP_REGNUM
] = fi
->pc_addr
;
935 saved_regs_addr
->regs
[I7_REGNUM
] = fi
->fp_addr
;
939 /* Normal frame. Just Local and In registers */
940 frame_addr
= fi
->bottom
?
941 fi
->bottom
: read_register (SP_REGNUM
);
942 for (regnum
= L0_REGNUM
; regnum
< L0_REGNUM
+8; regnum
++)
943 saved_regs_addr
->regs
[regnum
] =
944 (frame_addr
+ (regnum
- L0_REGNUM
) * SPARC_INTREG_SIZE
946 for (regnum
= I0_REGNUM
; regnum
< I0_REGNUM
+8; regnum
++)
947 saved_regs_addr
->regs
[regnum
] =
948 (frame_addr
+ (regnum
- I0_REGNUM
) * SPARC_INTREG_SIZE
955 saved_regs_addr
->regs
[O7_REGNUM
] = fi
->pc_addr
;
959 /* Pull off either the next frame pointer or the stack pointer */
960 CORE_ADDR next_next_frame_addr
=
963 read_register (SP_REGNUM
));
964 for (regnum
= O0_REGNUM
; regnum
< O0_REGNUM
+8; regnum
++)
965 saved_regs_addr
->regs
[regnum
] =
966 (next_next_frame_addr
967 + (regnum
- O0_REGNUM
) * SPARC_INTREG_SIZE
971 /* Otherwise, whatever we would get from ptrace(GETREGS) is accurate */
972 saved_regs_addr
->regs
[SP_REGNUM
] = FRAME_FP (fi
);
975 /* Discard from the stack the innermost frame, restoring all saved registers.
977 Note that the values stored in fsr by get_frame_saved_regs are *in
978 the context of the called frame*. What this means is that the i
979 regs of fsr must be restored into the o regs of the (calling) frame that
980 we pop into. We don't care about the output regs of the calling frame,
981 since unless it's a dummy frame, it won't have any output regs in it.
983 We never have to bother with %l (local) regs, since the called routine's
984 locals get tossed, and the calling routine's locals are already saved
987 /* Definitely see tm-sparc.h for more doc of the frame format here. */
992 register struct frame_info
*frame
= get_current_frame ();
993 register CORE_ADDR pc
;
994 struct frame_saved_regs fsr
;
995 char raw_buffer
[REGISTER_BYTES
];
998 sparc_frame_find_saved_regs (frame
, &fsr
);
1000 if (fsr
.regs
[FP0_REGNUM
])
1002 read_memory (fsr
.regs
[FP0_REGNUM
], raw_buffer
, FP_REGISTER_BYTES
);
1003 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
),
1004 raw_buffer
, FP_REGISTER_BYTES
);
1006 #ifndef GDB_TARGET_IS_SPARC64
1007 if (fsr
.regs
[FPS_REGNUM
])
1009 read_memory (fsr
.regs
[FPS_REGNUM
], raw_buffer
, 4);
1010 write_register_bytes (REGISTER_BYTE (FPS_REGNUM
), raw_buffer
, 4);
1012 if (fsr
.regs
[CPS_REGNUM
])
1014 read_memory (fsr
.regs
[CPS_REGNUM
], raw_buffer
, 4);
1015 write_register_bytes (REGISTER_BYTE (CPS_REGNUM
), raw_buffer
, 4);
1018 #endif /* FP0_REGNUM */
1019 if (fsr
.regs
[G1_REGNUM
])
1021 read_memory (fsr
.regs
[G1_REGNUM
], raw_buffer
, 7 * SPARC_INTREG_SIZE
);
1022 write_register_bytes (REGISTER_BYTE (G1_REGNUM
), raw_buffer
,
1023 7 * SPARC_INTREG_SIZE
);
1028 /* Each register might or might not have been saved, need to test
1030 for (regnum
= L0_REGNUM
; regnum
< L0_REGNUM
+ 8; ++regnum
)
1031 if (fsr
.regs
[regnum
])
1032 write_register (regnum
, read_memory_integer (fsr
.regs
[regnum
],
1033 SPARC_INTREG_SIZE
));
1034 for (regnum
= I0_REGNUM
; regnum
< I0_REGNUM
+ 8; ++regnum
)
1035 if (fsr
.regs
[regnum
])
1036 write_register (regnum
, read_memory_integer (fsr
.regs
[regnum
],
1037 SPARC_INTREG_SIZE
));
1039 /* Handle all outs except stack pointer (o0-o5; o7). */
1040 for (regnum
= O0_REGNUM
; regnum
< O0_REGNUM
+ 6; ++regnum
)
1041 if (fsr
.regs
[regnum
])
1042 write_register (regnum
, read_memory_integer (fsr
.regs
[regnum
],
1043 SPARC_INTREG_SIZE
));
1044 if (fsr
.regs
[O0_REGNUM
+ 7])
1045 write_register (O0_REGNUM
+ 7,
1046 read_memory_integer (fsr
.regs
[O0_REGNUM
+ 7],
1047 SPARC_INTREG_SIZE
));
1049 write_register (SP_REGNUM
, frame
->frame
);
1051 else if (fsr
.regs
[I0_REGNUM
])
1055 char reg_temp
[REGISTER_BYTES
];
1057 read_memory (fsr
.regs
[I0_REGNUM
], raw_buffer
, 8 * SPARC_INTREG_SIZE
);
1059 /* Get the ins and locals which we are about to restore. Just
1060 moving the stack pointer is all that is really needed, except
1061 store_inferior_registers is then going to write the ins and
1062 locals from the registers array, so we need to muck with the
1064 sp
= fsr
.regs
[SP_REGNUM
];
1065 read_memory (sp
, reg_temp
, SPARC_INTREG_SIZE
* 16);
1067 /* Restore the out registers.
1068 Among other things this writes the new stack pointer. */
1069 write_register_bytes (REGISTER_BYTE (O0_REGNUM
), raw_buffer
,
1070 SPARC_INTREG_SIZE
* 8);
1072 write_register_bytes (REGISTER_BYTE (L0_REGNUM
), reg_temp
,
1073 SPARC_INTREG_SIZE
* 16);
1075 #ifndef GDB_TARGET_IS_SPARC64
1076 if (fsr
.regs
[PS_REGNUM
])
1077 write_register (PS_REGNUM
, read_memory_integer (fsr
.regs
[PS_REGNUM
], 4));
1079 if (fsr
.regs
[Y_REGNUM
])
1080 write_register (Y_REGNUM
, read_memory_integer (fsr
.regs
[Y_REGNUM
], REGISTER_RAW_SIZE (Y_REGNUM
)));
1081 if (fsr
.regs
[PC_REGNUM
])
1083 /* Explicitly specified PC (and maybe NPC) -- just restore them. */
1084 write_register (PC_REGNUM
, read_memory_integer (fsr
.regs
[PC_REGNUM
],
1085 REGISTER_RAW_SIZE (PC_REGNUM
)));
1086 if (fsr
.regs
[NPC_REGNUM
])
1087 write_register (NPC_REGNUM
,
1088 read_memory_integer (fsr
.regs
[NPC_REGNUM
],
1089 REGISTER_RAW_SIZE (NPC_REGNUM
)));
1091 else if (frame
->flat
)
1094 pc
= PC_ADJUST ((CORE_ADDR
)
1095 read_memory_integer (frame
->pc_addr
,
1096 REGISTER_RAW_SIZE (PC_REGNUM
)));
1099 /* I think this happens only in the innermost frame, if so then
1100 it is a complicated way of saying
1101 "pc = read_register (O7_REGNUM);". */
1102 char buf
[MAX_REGISTER_RAW_SIZE
];
1103 get_saved_register (buf
, 0, 0, frame
, O7_REGNUM
, 0);
1104 pc
= PC_ADJUST (extract_address
1105 (buf
, REGISTER_RAW_SIZE (O7_REGNUM
)));
1108 write_register (PC_REGNUM
, pc
);
1109 write_register (NPC_REGNUM
, pc
+ 4);
1111 else if (fsr
.regs
[I7_REGNUM
])
1113 /* Return address in %i7 -- adjust it, then restore PC and NPC from it */
1114 pc
= PC_ADJUST ((CORE_ADDR
) read_memory_integer (fsr
.regs
[I7_REGNUM
],
1115 SPARC_INTREG_SIZE
));
1116 write_register (PC_REGNUM
, pc
);
1117 write_register (NPC_REGNUM
, pc
+ 4);
1119 flush_cached_frames ();
1122 /* On the Sun 4 under SunOS, the compile will leave a fake insn which
1123 encodes the structure size being returned. If we detect such
1124 a fake insn, step past it. */
1134 err
= target_read_memory (pc
+ 8, buf
, 4);
1135 insn
= extract_unsigned_integer (buf
, 4);
1136 if ((err
== 0) && (insn
& 0xffc00000) == 0)
1142 /* If pc is in a shared library trampoline, return its target.
1143 The SunOs 4.x linker rewrites the jump table entries for PIC
1144 compiled modules in the main executable to bypass the dynamic linker
1145 with jumps of the form
1148 and removes the corresponding jump table relocation entry in the
1149 dynamic relocations.
1150 find_solib_trampoline_target relies on the presence of the jump
1151 table relocation entry, so we have to detect these jump instructions
1155 sunos4_skip_trampoline_code (pc
)
1158 unsigned long insn1
;
1162 err
= target_read_memory (pc
, buf
, 4);
1163 insn1
= extract_unsigned_integer (buf
, 4);
1164 if (err
== 0 && (insn1
& 0xffc00000) == 0x03000000)
1166 unsigned long insn2
;
1168 err
= target_read_memory (pc
+ 4, buf
, 4);
1169 insn2
= extract_unsigned_integer (buf
, 4);
1170 if (err
== 0 && (insn2
& 0xffffe000) == 0x81c06000)
1172 CORE_ADDR target_pc
= (insn1
& 0x3fffff) << 10;
1173 int delta
= insn2
& 0x1fff;
1175 /* Sign extend the displacement. */
1178 return target_pc
+ delta
;
1181 return find_solib_trampoline_target (pc
);
1184 #ifdef USE_PROC_FS /* Target dependent support for /proc */
1186 /* The /proc interface divides the target machine's register set up into
1187 two different sets, the general register set (gregset) and the floating
1188 point register set (fpregset). For each set, there is an ioctl to get
1189 the current register set and another ioctl to set the current values.
1191 The actual structure passed through the ioctl interface is, of course,
1192 naturally machine dependent, and is different for each set of registers.
1193 For the sparc for example, the general register set is typically defined
1196 typedef int gregset_t[38];
1202 and the floating point set by:
1204 typedef struct prfpregset {
1207 double pr_dregs[16];
1212 u_char pr_q_entrysize;
1217 These routines provide the packing and unpacking of gregset_t and
1218 fpregset_t formatted data.
1222 /* Given a pointer to a general register set in /proc format (gregset_t *),
1223 unpack the register contents and supply them as gdb's idea of the current
1227 supply_gregset (gregsetp
)
1228 prgregset_t
*gregsetp
;
1231 register prgreg_t
*regp
= (prgreg_t
*) gregsetp
;
1232 static char zerobuf
[MAX_REGISTER_RAW_SIZE
] = {0};
1234 /* GDB register numbers for Gn, On, Ln, In all match /proc reg numbers. */
1235 for (regi
= G0_REGNUM
; regi
<= I7_REGNUM
; regi
++)
1237 supply_register (regi
, (char *) (regp
+ regi
));
1240 /* These require a bit more care. */
1241 supply_register (PS_REGNUM
, (char *) (regp
+ R_PS
));
1242 supply_register (PC_REGNUM
, (char *) (regp
+ R_PC
));
1243 supply_register (NPC_REGNUM
,(char *) (regp
+ R_nPC
));
1244 supply_register (Y_REGNUM
, (char *) (regp
+ R_Y
));
1246 /* Fill inaccessible registers with zero. */
1247 supply_register (WIM_REGNUM
, zerobuf
);
1248 supply_register (TBR_REGNUM
, zerobuf
);
1249 supply_register (CPS_REGNUM
, zerobuf
);
1253 fill_gregset (gregsetp
, regno
)
1254 prgregset_t
*gregsetp
;
1258 register prgreg_t
*regp
= (prgreg_t
*) gregsetp
;
1260 for (regi
= 0 ; regi
<= R_I7
; regi
++)
1262 if ((regno
== -1) || (regno
== regi
))
1264 *(regp
+ regi
) = *(int *) ®isters
[REGISTER_BYTE (regi
)];
1267 if ((regno
== -1) || (regno
== PS_REGNUM
))
1269 *(regp
+ R_PS
) = *(int *) ®isters
[REGISTER_BYTE (PS_REGNUM
)];
1271 if ((regno
== -1) || (regno
== PC_REGNUM
))
1273 *(regp
+ R_PC
) = *(int *) ®isters
[REGISTER_BYTE (PC_REGNUM
)];
1275 if ((regno
== -1) || (regno
== NPC_REGNUM
))
1277 *(regp
+ R_nPC
) = *(int *) ®isters
[REGISTER_BYTE (NPC_REGNUM
)];
1279 if ((regno
== -1) || (regno
== Y_REGNUM
))
1281 *(regp
+ R_Y
) = *(int *) ®isters
[REGISTER_BYTE (Y_REGNUM
)];
1285 #if defined (FP0_REGNUM)
1287 /* Given a pointer to a floating point register set in /proc format
1288 (fpregset_t *), unpack the register contents and supply them as gdb's
1289 idea of the current floating point register values. */
1292 supply_fpregset (fpregsetp
)
1293 prfpregset_t
*fpregsetp
;
1298 for (regi
= FP0_REGNUM
; regi
< FP_MAX_REGNUM
; regi
++)
1300 from
= (char *) &fpregsetp
->pr_fr
.pr_regs
[regi
-FP0_REGNUM
];
1301 supply_register (regi
, from
);
1303 supply_register (FPS_REGNUM
, (char *) &(fpregsetp
->pr_fsr
));
1306 /* Given a pointer to a floating point register set in /proc format
1307 (fpregset_t *), update the register specified by REGNO from gdb's idea
1308 of the current floating point register set. If REGNO is -1, update
1310 /* ??? This will probably need some changes for sparc64. */
1313 fill_fpregset (fpregsetp
, regno
)
1314 prfpregset_t
*fpregsetp
;
1321 for (regi
= FP0_REGNUM
; regi
< FP_MAX_REGNUM
; regi
++)
1323 if ((regno
== -1) || (regno
== regi
))
1325 from
= (char *) ®isters
[REGISTER_BYTE (regi
)];
1326 to
= (char *) &fpregsetp
->pr_fr
.pr_regs
[regi
-FP0_REGNUM
];
1327 memcpy (to
, from
, REGISTER_RAW_SIZE (regi
));
1330 if ((regno
== -1) || (regno
== FPS_REGNUM
))
1332 fpregsetp
->pr_fsr
= *(int *) ®isters
[REGISTER_BYTE (FPS_REGNUM
)];
1336 #endif /* defined (FP0_REGNUM) */
1338 #endif /* USE_PROC_FS */
1341 #ifdef GET_LONGJMP_TARGET
1343 /* Figure out where the longjmp will land. We expect that we have just entered
1344 longjmp and haven't yet setup the stack frame, so the args are still in the
1345 output regs. %o0 (O0_REGNUM) points at the jmp_buf structure from which we
1346 extract the pc (JB_PC) that we will land at. The pc is copied into ADDR.
1347 This routine returns true on success */
1350 get_longjmp_target (pc
)
1354 #define LONGJMP_TARGET_SIZE 4
1355 char buf
[LONGJMP_TARGET_SIZE
];
1357 jb_addr
= read_register (O0_REGNUM
);
1359 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
1360 LONGJMP_TARGET_SIZE
))
1363 *pc
= extract_address (buf
, LONGJMP_TARGET_SIZE
);
1367 #endif /* GET_LONGJMP_TARGET */
1369 #ifdef STATIC_TRANSFORM_NAME
1370 /* SunPRO (3.0 at least), encodes the static variables. This is not
1371 related to C++ mangling, it is done for C too. */
1374 sunpro_static_transform_name (name
)
1380 /* For file-local statics there will be a dollar sign, a bunch
1381 of junk (the contents of which match a string given in the
1382 N_OPT), a period and the name. For function-local statics
1383 there will be a bunch of junk (which seems to change the
1384 second character from 'A' to 'B'), a period, the name of the
1385 function, and the name. So just skip everything before the
1387 p
= strrchr (name
, '.');
1393 #endif /* STATIC_TRANSFORM_NAME */
1395 #ifdef GDB_TARGET_IS_SPARC64
1397 /* Utilities for printing registers.
1398 Page numbers refer to the SPARC Architecture Manual. */
1400 static void dump_ccreg
PARAMS ((char *, int));
1403 dump_ccreg (reg
, val
)
1408 printf_unfiltered ("%s:%s,%s,%s,%s", reg
,
1409 val
& 8 ? "N" : "NN",
1410 val
& 4 ? "Z" : "NZ",
1411 val
& 2 ? "O" : "NO",
1412 val
& 1 ? "C" : "NC"
1423 case 4 : return "ASI_NUCLEUS";
1424 case 0x0c : return "ASI_NUCLEUS_LITTLE";
1425 case 0x10 : return "ASI_AS_IF_USER_PRIMARY";
1426 case 0x11 : return "ASI_AS_IF_USER_SECONDARY";
1427 case 0x18 : return "ASI_AS_IF_USER_PRIMARY_LITTLE";
1428 case 0x19 : return "ASI_AS_IF_USER_SECONDARY_LITTLE";
1429 case 0x80 : return "ASI_PRIMARY";
1430 case 0x81 : return "ASI_SECONDARY";
1431 case 0x82 : return "ASI_PRIMARY_NOFAULT";
1432 case 0x83 : return "ASI_SECONDARY_NOFAULT";
1433 case 0x88 : return "ASI_PRIMARY_LITTLE";
1434 case 0x89 : return "ASI_SECONDARY_LITTLE";
1435 case 0x8a : return "ASI_PRIMARY_NOFAULT_LITTLE";
1436 case 0x8b : return "ASI_SECONDARY_NOFAULT_LITTLE";
1437 default : return NULL
;
1441 /* PRINT_REGISTER_HOOK routine.
1442 Pretty print various registers. */
1443 /* FIXME: Would be nice if this did some fancy things for 32 bit sparc. */
1446 sparc_print_register_hook (regno
)
1451 /* Handle double/quad versions of lower 32 fp regs. */
1452 if (regno
>= FP0_REGNUM
&& regno
< FP0_REGNUM
+ 32
1453 && (regno
& 1) == 0)
1457 if (!read_relative_register_raw_bytes (regno
, value
)
1458 && !read_relative_register_raw_bytes (regno
+ 1, value
+ 4))
1460 printf_unfiltered ("\t");
1461 print_floating (value
, builtin_type_double
, gdb_stdout
);
1463 #if 0 /* FIXME: gdb doesn't handle long doubles */
1464 if ((regno
& 3) == 0)
1466 if (!read_relative_register_raw_bytes (regno
+ 2, value
+ 8)
1467 && !read_relative_register_raw_bytes (regno
+ 3, value
+ 12))
1469 printf_unfiltered ("\t");
1470 print_floating (value
, builtin_type_long_double
, gdb_stdout
);
1477 #if 0 /* FIXME: gdb doesn't handle long doubles */
1478 /* Print upper fp regs as long double if appropriate. */
1479 if (regno
>= FP0_REGNUM
+ 32 && regno
< FP_MAX_REGNUM
1480 /* We test for even numbered regs and not a multiple of 4 because
1481 the upper fp regs are recorded as doubles. */
1482 && (regno
& 1) == 0)
1486 if (!read_relative_register_raw_bytes (regno
, value
)
1487 && !read_relative_register_raw_bytes (regno
+ 1, value
+ 8))
1489 printf_unfiltered ("\t");
1490 print_floating (value
, builtin_type_long_double
, gdb_stdout
);
1496 /* FIXME: Some of these are priviledged registers.
1497 Not sure how they should be handled. */
1499 #define BITS(n, mask) ((int) (((val) >> (n)) & (mask)))
1501 val
= read_register (regno
);
1507 printf_unfiltered("\t");
1508 dump_ccreg ("xcc", val
>> 4);
1509 printf_unfiltered(", ");
1510 dump_ccreg ("icc", val
& 15);
1513 printf ("\tfef:%d, du:%d, dl:%d",
1514 BITS (2, 1), BITS (1, 1), BITS (0, 1));
1518 static char *fcc
[4] = { "=", "<", ">", "?" };
1519 static char *rd
[4] = { "N", "0", "+", "-" };
1520 /* Long, yes, but I'd rather leave it as is and use a wide screen. */
1521 printf ("\t0:%s, 1:%s, 2:%s, 3:%s, rd:%s, tem:%d, ns:%d, ver:%d, ftt:%d, qne:%d, aexc:%d, cexc:%d",
1522 fcc
[BITS (10, 3)], fcc
[BITS (32, 3)],
1523 fcc
[BITS (34, 3)], fcc
[BITS (36, 3)],
1524 rd
[BITS (30, 3)], BITS (23, 31), BITS (22, 1), BITS (17, 7),
1525 BITS (14, 7), BITS (13, 1), BITS (5, 31), BITS (0, 31));
1530 char *asi
= decode_asi (val
);
1532 printf ("\t%s", asi
);
1536 printf ("\tmanuf:%d, impl:%d, mask:%d, maxtl:%d, maxwin:%d",
1537 BITS (48, 0xffff), BITS (32, 0xffff),
1538 BITS (24, 0xff), BITS (8, 0xff), BITS (0, 31));
1540 case PSTATE_REGNUM
:
1542 static char *mm
[4] = { "tso", "pso", "rso", "?" };
1543 printf ("\tcle:%d, tle:%d, mm:%s, red:%d, pef:%d, am:%d, priv:%d, ie:%d, ag:%d",
1544 BITS (9, 1), BITS (8, 1), mm
[BITS (6, 3)], BITS (5, 1),
1545 BITS (4, 1), BITS (3, 1), BITS (2, 1), BITS (1, 1),
1549 case TSTATE_REGNUM
:
1550 /* FIXME: print all 4? */
1553 /* FIXME: print all 4? */
1556 /* FIXME: print all 4? */
1559 /* FIXME: print all 4? */
1561 case WSTATE_REGNUM
:
1562 printf ("\tother:%d, normal:%d", BITS (3, 7), BITS (0, 7));
1565 printf ("\t%d", BITS (0, 31));
1567 case CANSAVE_REGNUM
:
1568 printf ("\t%-2d before spill", BITS (0, 31));
1570 case CANRESTORE_REGNUM
:
1571 printf ("\t%-2d before fill", BITS (0, 31));
1573 case CLEANWIN_REGNUM
:
1574 printf ("\t%-2d before clean", BITS (0, 31));
1576 case OTHERWIN_REGNUM
:
1577 printf ("\t%d", BITS (0, 31));
1587 gdb_print_insn_sparc (memaddr
, info
)
1589 disassemble_info
*info
;
1591 /* It's necessary to override mach again because print_insn messes it up. */
1592 info
->mach
= TM_PRINT_INSN_MACH
;
1593 return print_insn_sparc (memaddr
, info
);
1596 /* The SPARC passes the arguments on the stack; arguments smaller
1597 than an int are promoted to an int. */
1600 sparc_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
1605 CORE_ADDR struct_addr
;
1608 int accumulate_size
= 0;
1615 struct sparc_arg
*sparc_args
=
1616 (struct sparc_arg
*)alloca (nargs
* sizeof (struct sparc_arg
));
1617 struct sparc_arg
*m_arg
;
1619 /* Promote arguments if necessary, and calculate their stack offsets
1621 for (i
= 0, m_arg
= sparc_args
; i
< nargs
; i
++, m_arg
++)
1623 value_ptr arg
= args
[i
];
1624 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
1625 /* Cast argument to long if necessary as the compiler does it too. */
1626 switch (TYPE_CODE (arg_type
))
1629 case TYPE_CODE_BOOL
:
1630 case TYPE_CODE_CHAR
:
1631 case TYPE_CODE_RANGE
:
1632 case TYPE_CODE_ENUM
:
1633 if (TYPE_LENGTH (arg_type
) < TYPE_LENGTH (builtin_type_long
))
1635 arg_type
= builtin_type_long
;
1636 arg
= value_cast (arg_type
, arg
);
1642 m_arg
->len
= TYPE_LENGTH (arg_type
);
1643 m_arg
->offset
= accumulate_size
;
1644 accumulate_size
= (accumulate_size
+ m_arg
->len
+ 3) & ~3;
1645 m_arg
->contents
= VALUE_CONTENTS(arg
);
1648 /* Make room for the arguments on the stack. */
1649 accumulate_size
+= CALL_DUMMY_STACK_ADJUST
;
1650 sp
= ((sp
- accumulate_size
) & ~7) + CALL_DUMMY_STACK_ADJUST
;
1652 /* `Push' arguments on the stack. */
1653 for (i
= nargs
; m_arg
--, --i
>= 0; )
1654 write_memory(sp
+ m_arg
->offset
, m_arg
->contents
, m_arg
->len
);
1660 _initialize_sparc_tdep ()
1662 tm_print_insn
= gdb_print_insn_sparc
;
1663 tm_print_insn_info
.mach
= TM_PRINT_INSN_MACH
; /* Selects sparc/sparclite */