]>
Commit | Line | Data |
---|---|---|
f9e3b3cc | 1 | /* Target-dependent code for the SPARC for GDB, the GNU debugger. |
e50f526e | 2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997 |
94d4b713 | 3 | Free Software Foundation, Inc. |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
5259796b | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
5259796b JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
5259796b | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
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 | |
5259796b | 18 | along with this program; if not, write to the Free Software |
673e1bab | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bd5635a1 | 20 | |
8b0f5a9d DE |
21 | /* ??? Support for calling functions from gdb in sparc64 is unfinished. */ |
22 | ||
bd5635a1 | 23 | #include "defs.h" |
bd5635a1 RP |
24 | #include "frame.h" |
25 | #include "inferior.h" | |
26 | #include "obstack.h" | |
bd5635a1 | 27 | #include "target.h" |
48792545 | 28 | #include "value.h" |
91550191 | 29 | #include "bfd.h" |
e50f526e | 30 | #include "gdb_string.h" |
4365c36c | 31 | |
8f86a4e4 JG |
32 | #ifdef USE_PROC_FS |
33 | #include <sys/procfs.h> | |
8f86a4e4 | 34 | #endif |
bd5635a1 | 35 | |
bd5635a1 RP |
36 | #include "gdbcore.h" |
37 | ||
8b0f5a9d | 38 | #ifdef GDB_TARGET_IS_SPARC64 |
012be3ce | 39 | #define FP_REGISTER_BYTES (64 * 4) |
8b0f5a9d | 40 | #else |
012be3ce DP |
41 | #define FP_REGISTER_BYTES (32 * 4) |
42 | #endif | |
43 | ||
44 | /* If not defined, assume 32 bit sparc. */ | |
45 | #ifndef FP_MAX_REGNUM | |
46 | #define FP_MAX_REGNUM (FP0_REGNUM + 32) | |
8b0f5a9d DE |
47 | #endif |
48 | ||
49 | #define SPARC_INTREG_SIZE (REGISTER_RAW_SIZE (G0_REGNUM)) | |
50 | ||
bd5635a1 RP |
51 | /* From infrun.c */ |
52 | extern int stop_after_trap; | |
53 | ||
b38f304c JG |
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. */ | |
59 | ||
60 | int deferred_stores = 0; /* Cumulates stores we want to do eventually. */ | |
61 | ||
8b0f5a9d DE |
62 | /* Branches with prediction are treated like their non-predicting cousins. */ |
63 | /* FIXME: What about floating point branches? */ | |
64 | ||
ee7b9e92 JK |
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) | |
8b0f5a9d DE |
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) | |
ee7b9e92 | 85 | |
bd5635a1 RP |
86 | typedef enum |
87 | { | |
8b0f5a9d DE |
88 | Error, not_branch, bicc, bicca, ba, baa, ticc, ta, |
89 | #ifdef GDB_TARGET_IS_SPARC64 | |
90 | done_retry | |
91 | #endif | |
bd5635a1 RP |
92 | } branch_type; |
93 | ||
94 | /* Simulate single-step ptrace call for sun4. Code written by Gary | |
95 | Beihl ([email protected]). */ | |
96 | ||
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]; | |
103 | ||
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 | |
107 | sun4. */ | |
108 | ||
109 | int one_stepped; | |
110 | ||
e50f526e MA |
111 | static branch_type isbranch PARAMS ((long, CORE_ADDR, CORE_ADDR *)); |
112 | ||
d11c44f1 JG |
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. | |
117 | ||
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. */ | |
120 | ||
bd5635a1 | 121 | void |
8f86a4e4 | 122 | single_step (ignore) |
e50f526e | 123 | enum target_signal ignore; /* pid, but we don't need it */ |
bd5635a1 | 124 | { |
e50f526e | 125 | branch_type br; |
bd5635a1 RP |
126 | CORE_ADDR pc; |
127 | long pc_instruction; | |
128 | ||
129 | if (!one_stepped) | |
130 | { | |
131 | /* Always set breakpoint for NPC. */ | |
132 | next_pc = read_register (NPC_REGNUM); | |
133 | npc4 = next_pc + 4; /* branch not taken */ | |
134 | ||
135 | target_insert_breakpoint (next_pc, break_mem[0]); | |
f1de67d3 | 136 | /* printf_unfiltered ("set break at %x\n",next_pc); */ |
bd5635a1 RP |
137 | |
138 | pc = read_register (PC_REGNUM); | |
ee7b9e92 | 139 | pc_instruction = read_memory_integer (pc, 4); |
8b0f5a9d | 140 | br = isbranch (pc_instruction, pc, &target); |
bd5635a1 RP |
141 | brknpc4 = brktrg = 0; |
142 | ||
143 | if (br == bicca) | |
144 | { | |
145 | /* Conditional annulled branch will either end up at | |
146 | npc (if taken) or at npc+4 (if not taken). | |
147 | Trap npc+4. */ | |
148 | brknpc4 = 1; | |
149 | target_insert_breakpoint (npc4, break_mem[1]); | |
150 | } | |
151 | else if (br == baa && target != next_pc) | |
152 | { | |
153 | /* Unconditional annulled branch will always end up at | |
154 | the target. */ | |
155 | brktrg = 1; | |
156 | target_insert_breakpoint (target, break_mem[2]); | |
157 | } | |
8b0f5a9d DE |
158 | #ifdef GDB_TARGET_IS_SPARC64 |
159 | else if (br == done_retry) | |
160 | { | |
161 | brktrg = 1; | |
162 | target_insert_breakpoint (target, break_mem[2]); | |
163 | } | |
164 | #endif | |
bd5635a1 | 165 | |
d11c44f1 | 166 | /* We are ready to let it go */ |
bd5635a1 RP |
167 | one_stepped = 1; |
168 | return; | |
169 | } | |
170 | else | |
171 | { | |
172 | /* Remove breakpoints */ | |
173 | target_remove_breakpoint (next_pc, break_mem[0]); | |
174 | ||
175 | if (brknpc4) | |
176 | target_remove_breakpoint (npc4, break_mem[1]); | |
177 | ||
178 | if (brktrg) | |
179 | target_remove_breakpoint (target, break_mem[2]); | |
180 | ||
181 | one_stepped = 0; | |
182 | } | |
183 | } | |
184 | \f | |
84bdfea6 PS |
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. */ | |
190 | ||
191 | void | |
192 | sparc_init_extra_frame_info (fromleaf, fi) | |
193 | int fromleaf; | |
194 | struct frame_info *fi; | |
195 | { | |
196 | char *name; | |
197 | CORE_ADDR addr; | |
ee7b9e92 | 198 | int insn; |
84bdfea6 PS |
199 | |
200 | fi->bottom = | |
201 | (fi->next ? | |
202 | (fi->frame == fi->next->frame ? fi->next->bottom : fi->next->frame) : | |
203 | read_register (SP_REGNUM)); | |
204 | ||
ee7b9e92 JK |
205 | /* If fi->next is NULL, then we already set ->frame by passing read_fp() |
206 | to create_new_frame. */ | |
207 | if (fi->next) | |
208 | { | |
209 | char buf[MAX_REGISTER_RAW_SIZE]; | |
ee7b9e92 JK |
210 | |
211 | /* Compute ->frame as if not flat. If it is flat, we'll change | |
212 | it later. */ | |
e50f526e MA |
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)) | |
217 | { | |
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; | |
222 | } | |
223 | else | |
224 | { | |
225 | get_saved_register (buf, 0, 0, fi, FP_REGNUM, 0); | |
226 | fi->frame = extract_address (buf, REGISTER_RAW_SIZE (FP_REGNUM)); | |
227 | } | |
ee7b9e92 JK |
228 | } |
229 | ||
84bdfea6 PS |
230 | /* Decide whether this is a function with a ``flat register window'' |
231 | frame. For such functions, the frame pointer is actually in %i7. */ | |
232 | fi->flat = 0; | |
233 | if (find_pc_partial_function (fi->pc, &name, &addr, NULL)) | |
234 | { | |
235 | /* See if the function starts with an add (which will be of a | |
ee7b9e92 JK |
236 | negative number if a flat frame) to the sp. FIXME: Does not |
237 | handle large frames which will need more than one instruction | |
238 | to adjust the sp. */ | |
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) | |
84bdfea6 | 242 | { |
ee7b9e92 JK |
243 | int offset = X_SIMM13 (insn); |
244 | ||
84bdfea6 | 245 | /* Then look for a save of %i7 into the frame. */ |
ee7b9e92 JK |
246 | insn = read_memory_integer (addr + 4, 4); |
247 | if (X_OP (insn) == 3 | |
248 | && X_RD (insn) == 31 | |
249 | && X_OP3 (insn) == 4 | |
250 | && X_RS1 (insn) == 14) | |
84bdfea6 | 251 | { |
ee7b9e92 JK |
252 | char buf[MAX_REGISTER_RAW_SIZE]; |
253 | ||
84bdfea6 PS |
254 | /* We definitely have a flat frame now. */ |
255 | fi->flat = 1; | |
ee7b9e92 JK |
256 | |
257 | fi->sp_offset = offset; | |
258 | ||
84bdfea6 | 259 | /* Overwrite the frame's address with the value in %i7. */ |
ee7b9e92 JK |
260 | get_saved_register (buf, 0, 0, fi, I7_REGNUM, 0); |
261 | fi->frame = extract_address (buf, REGISTER_RAW_SIZE (I7_REGNUM)); | |
262 | ||
84bdfea6 | 263 | /* Record where the fp got saved. */ |
ee7b9e92 JK |
264 | fi->fp_addr = fi->frame + fi->sp_offset + X_SIMM13 (insn); |
265 | ||
84bdfea6 PS |
266 | /* Also try to collect where the pc got saved to. */ |
267 | fi->pc_addr = 0; | |
ee7b9e92 JK |
268 | insn = read_memory_integer (addr + 12, 4); |
269 | if (X_OP (insn) == 3 | |
270 | && X_RD (insn) == 15 | |
271 | && X_OP3 (insn) == 4 | |
272 | && X_RS1 (insn) == 14) | |
273 | fi->pc_addr = fi->frame + fi->sp_offset + X_SIMM13 (insn); | |
84bdfea6 PS |
274 | } |
275 | } | |
276 | } | |
ee7b9e92 JK |
277 | if (fi->next && fi->frame == 0) |
278 | { | |
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; | |
282 | } | |
84bdfea6 PS |
283 | } |
284 | ||
d11c44f1 | 285 | CORE_ADDR |
84bdfea6 PS |
286 | sparc_frame_chain (frame) |
287 | struct frame_info *frame; | |
d11c44f1 | 288 | { |
ee7b9e92 JK |
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. */ | |
292 | return (CORE_ADDR)1; | |
d11c44f1 JG |
293 | } |
294 | ||
295 | CORE_ADDR | |
296 | sparc_extract_struct_value_address (regbuf) | |
297 | char regbuf[REGISTER_BYTES]; | |
298 | { | |
b9e58503 PS |
299 | #ifdef GDB_TARGET_IS_SPARC64 |
300 | return extract_address (regbuf + REGISTER_BYTE (O0_REGNUM), | |
301 | REGISTER_RAW_SIZE (O0_REGNUM)); | |
302 | #else | |
e50f526e MA |
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), | |
f1de67d3 | 306 | TARGET_PTR_BIT / TARGET_CHAR_BIT); |
b9e58503 | 307 | #endif |
d11c44f1 JG |
308 | } |
309 | ||
f9e3b3cc JG |
310 | /* Find the pc saved in frame FRAME. */ |
311 | ||
bd5635a1 | 312 | CORE_ADDR |
8bf94f44 | 313 | sparc_frame_saved_pc (frame) |
84bdfea6 | 314 | struct frame_info *frame; |
bd5635a1 | 315 | { |
f1de67d3 | 316 | char buf[MAX_REGISTER_RAW_SIZE]; |
34df79fc | 317 | CORE_ADDR addr; |
f9e3b3cc | 318 | |
48792545 JK |
319 | if (frame->signal_handler_caller) |
320 | { | |
321 | /* This is the signal trampoline frame. | |
322 | Get the saved PC from the sigcontext structure. */ | |
323 | ||
324 | #ifndef SIGCONTEXT_PC_OFFSET | |
325 | #define SIGCONTEXT_PC_OFFSET 12 | |
326 | #endif | |
327 | ||
328 | CORE_ADDR sigcontext_addr; | |
329 | char scbuf[TARGET_PTR_BIT / HOST_CHAR_BIT]; | |
94d4b713 JK |
330 | int saved_pc_offset = SIGCONTEXT_PC_OFFSET; |
331 | char *name = NULL; | |
332 | ||
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; | |
48792545 JK |
339 | |
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); | |
8b0f5a9d | 343 | sigcontext_addr = extract_address (buf, REGISTER_RAW_SIZE (O0_REGNUM + 2)); |
48792545 JK |
344 | |
345 | /* Don't cause a memory_error when accessing sigcontext in case the | |
346 | stack layout has changed or the stack is corrupt. */ | |
94d4b713 | 347 | target_read_memory (sigcontext_addr + saved_pc_offset, |
48792545 JK |
348 | scbuf, sizeof (scbuf)); |
349 | return extract_address (scbuf, sizeof (scbuf)); | |
350 | } | |
e50f526e MA |
351 | else if (frame->next != NULL |
352 | && (frame->next->signal_handler_caller | |
353 | || frame_in_dummy (frame->next)) | |
354 | && frameless_look_for_prologue (frame)) | |
355 | { | |
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)); | |
361 | } | |
84bdfea6 PS |
362 | if (frame->flat) |
363 | addr = frame->pc_addr; | |
364 | else | |
365 | addr = frame->bottom + FRAME_SAVED_I0 + | |
8b0f5a9d | 366 | SPARC_INTREG_SIZE * (I7_REGNUM - I0_REGNUM); |
ee7b9e92 JK |
367 | |
368 | if (addr == 0) | |
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)); | |
372 | ||
8b0f5a9d DE |
373 | read_memory (addr, buf, SPARC_INTREG_SIZE); |
374 | return PC_ADJUST (extract_address (buf, SPARC_INTREG_SIZE)); | |
bd5635a1 RP |
375 | } |
376 | ||
84bdfea6 PS |
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 | |
383 | difficulty. */ | |
384 | ||
385 | struct frame_info * | |
2093fe68 RP |
386 | setup_arbitrary_frame (argc, argv) |
387 | int argc; | |
84bdfea6 | 388 | CORE_ADDR *argv; |
bd5635a1 | 389 | { |
84bdfea6 | 390 | struct frame_info *frame; |
2093fe68 RP |
391 | |
392 | if (argc != 2) | |
393 | error ("Sparc frame specifications require two arguments: fp and sp"); | |
394 | ||
84bdfea6 | 395 | frame = create_new_frame (argv[0], 0); |
bd5635a1 | 396 | |
84bdfea6 PS |
397 | if (!frame) |
398 | fatal ("internal: create_new_frame returned invalid frame"); | |
bd5635a1 | 399 | |
84bdfea6 PS |
400 | frame->bottom = argv[1]; |
401 | frame->pc = FRAME_SAVED_PC (frame); | |
402 | return frame; | |
bd5635a1 RP |
403 | } |
404 | ||
5259796b JG |
405 | /* Given a pc value, skip it forward past the function prologue by |
406 | disassembling instructions that appear to be a prologue. | |
407 | ||
408 | If FRAMELESS_P is set, we are only testing to see if the function | |
409 | is frameless. This allows a quicker answer. | |
410 | ||
411 | This routine should be more specific in its actions; making sure | |
192cbba9 | 412 | that it uses the same register in the initial prologue section. */ |
84bdfea6 | 413 | |
ee7b9e92 JK |
414 | static CORE_ADDR examine_prologue PARAMS ((CORE_ADDR, int, struct frame_info *, |
415 | struct frame_saved_regs *)); | |
416 | ||
417 | static CORE_ADDR | |
418 | examine_prologue (start_pc, frameless_p, fi, saved_regs) | |
192cbba9 | 419 | CORE_ADDR start_pc; |
5259796b | 420 | int frameless_p; |
ee7b9e92 JK |
421 | struct frame_info *fi; |
422 | struct frame_saved_regs *saved_regs; | |
bd5635a1 | 423 | { |
ee7b9e92 | 424 | int insn; |
bd5635a1 | 425 | int dest = -1; |
192cbba9 | 426 | CORE_ADDR pc = start_pc; |
84bdfea6 | 427 | int is_flat = 0; |
bd5635a1 | 428 | |
ee7b9e92 | 429 | insn = read_memory_integer (pc, 4); |
bd5635a1 RP |
430 | |
431 | /* Recognize the `sethi' insn and record its destination. */ | |
ee7b9e92 | 432 | if (X_OP (insn) == 0 && X_OP2 (insn) == 4) |
bd5635a1 | 433 | { |
ee7b9e92 | 434 | dest = X_RD (insn); |
bd5635a1 | 435 | pc += 4; |
ee7b9e92 | 436 | insn = read_memory_integer (pc, 4); |
bd5635a1 RP |
437 | } |
438 | ||
439 | /* Recognize an add immediate value to register to either %g1 or | |
440 | the destination register recorded above. Actually, this might | |
192cbba9 JK |
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). */ | |
ee7b9e92 JK |
445 | if (X_OP (insn) == 2 |
446 | && X_I (insn) | |
447 | && (X_RD (insn) == 1 || X_RD (insn) == dest)) | |
bd5635a1 RP |
448 | { |
449 | pc += 4; | |
ee7b9e92 | 450 | insn = read_memory_integer (pc, 4); |
bd5635a1 RP |
451 | } |
452 | ||
ee7b9e92 JK |
453 | /* Recognize any SAVE insn. */ |
454 | if (X_OP (insn) == 2 && X_OP3 (insn) == 60) | |
bd5635a1 RP |
455 | { |
456 | pc += 4; | |
5259796b JG |
457 | if (frameless_p) /* If the save is all we care about, */ |
458 | return pc; /* return before doing more work */ | |
ee7b9e92 | 459 | insn = read_memory_integer (pc, 4); |
bd5635a1 | 460 | } |
ee7b9e92 JK |
461 | /* Recognize add to %sp. */ |
462 | else if (X_OP (insn) == 2 && X_RD (insn) == 14 && X_OP3 (insn) == 0) | |
5259796b | 463 | { |
84bdfea6 PS |
464 | pc += 4; |
465 | if (frameless_p) /* If the add is all we care about, */ | |
466 | return pc; /* return before doing more work */ | |
ee7b9e92 JK |
467 | is_flat = 1; |
468 | insn = read_memory_integer (pc, 4); | |
469 | /* Recognize store of frame pointer (i7). */ | |
470 | if (X_OP (insn) == 3 | |
471 | && X_RD (insn) == 31 | |
472 | && X_OP3 (insn) == 4 | |
473 | && X_RS1 (insn) == 14) | |
474 | { | |
475 | pc += 4; | |
476 | insn = read_memory_integer (pc, 4); | |
477 | ||
478 | /* Recognize sub %sp, <anything>, %i7. */ | |
479 | if (X_OP (insn) == 2 | |
480 | && X_OP3 (insn) == 4 | |
481 | && X_RS1 (insn) == 14 | |
482 | && X_RD (insn) == 31) | |
483 | { | |
484 | pc += 4; | |
485 | insn = read_memory_integer (pc, 4); | |
486 | } | |
487 | else | |
488 | return pc; | |
489 | } | |
490 | else | |
491 | return pc; | |
5259796b | 492 | } |
84bdfea6 PS |
493 | else |
494 | /* Without a save or add instruction, it's not a prologue. */ | |
495 | return start_pc; | |
bd5635a1 | 496 | |
ee7b9e92 | 497 | while (1) |
bd5635a1 | 498 | { |
ee7b9e92 JK |
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)) | |
510 | ; | |
511 | else if (is_flat | |
512 | && X_OP (insn) == 3 | |
513 | && X_OP3 (insn) == 4 | |
514 | && X_RS1 (insn) == 14 | |
515 | ) | |
516 | { | |
517 | if (saved_regs && X_I (insn)) | |
518 | saved_regs->regs[X_RD (insn)] = | |
519 | fi->frame + fi->sp_offset + X_SIMM13 (insn); | |
520 | } | |
521 | else | |
522 | break; | |
bd5635a1 | 523 | pc += 4; |
ee7b9e92 | 524 | insn = read_memory_integer (pc, 4); |
bd5635a1 | 525 | } |
84bdfea6 | 526 | |
5259796b | 527 | return pc; |
bd5635a1 RP |
528 | } |
529 | ||
ee7b9e92 JK |
530 | CORE_ADDR |
531 | skip_prologue (start_pc, frameless_p) | |
532 | CORE_ADDR start_pc; | |
533 | int frameless_p; | |
534 | { | |
535 | return examine_prologue (start_pc, frameless_p, NULL, NULL); | |
536 | } | |
537 | ||
8b0f5a9d DE |
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. | |
541 | ||
542 | This isn't static as it's used by remote-sa.sparc.c. */ | |
543 | ||
e50f526e | 544 | static branch_type |
8b0f5a9d | 545 | isbranch (instruction, addr, target) |
bd5635a1 RP |
546 | long instruction; |
547 | CORE_ADDR addr, *target; | |
548 | { | |
549 | branch_type val = not_branch; | |
e50f526e | 550 | long int offset = 0; /* Must be signed for sign-extend. */ |
bd5635a1 RP |
551 | |
552 | *target = 0; | |
bd5635a1 | 553 | |
ee7b9e92 JK |
554 | if (X_OP (instruction) == 0 |
555 | && (X_OP2 (instruction) == 2 | |
556 | || X_OP2 (instruction) == 6 | |
8b0f5a9d DE |
557 | || X_OP2 (instruction) == 1 |
558 | || X_OP2 (instruction) == 3 | |
559 | || X_OP2 (instruction) == 5 | |
e50f526e | 560 | #ifndef GDB_TARGET_IS_SPARC64 |
8b0f5a9d DE |
561 | || X_OP2 (instruction) == 7 |
562 | #endif | |
563 | )) | |
bd5635a1 | 564 | { |
ee7b9e92 JK |
565 | if (X_COND (instruction) == 8) |
566 | val = X_A (instruction) ? baa : ba; | |
bd5635a1 | 567 | else |
ee7b9e92 | 568 | val = X_A (instruction) ? bicca : bicc; |
673e1bab | 569 | switch (X_OP2 (instruction)) |
8b0f5a9d DE |
570 | { |
571 | case 2: | |
572 | case 6: | |
573 | #ifndef GDB_TARGET_IS_SPARC64 | |
574 | case 7: | |
575 | #endif | |
576 | offset = 4 * X_DISP22 (instruction); | |
577 | break; | |
8b0f5a9d DE |
578 | case 1: |
579 | case 5: | |
580 | offset = 4 * X_DISP19 (instruction); | |
581 | break; | |
582 | case 3: | |
583 | offset = 4 * X_DISP16 (instruction); | |
584 | break; | |
8b0f5a9d | 585 | } |
bd5635a1 RP |
586 | *target = addr + offset; |
587 | } | |
8b0f5a9d DE |
588 | #ifdef GDB_TARGET_IS_SPARC64 |
589 | else if (X_OP (instruction) == 2 | |
590 | && X_OP3 (instruction) == 62) | |
591 | { | |
592 | if (X_FCN (instruction) == 0) | |
593 | { | |
594 | /* done */ | |
595 | *target = read_register (TNPC_REGNUM); | |
596 | val = done_retry; | |
597 | } | |
598 | else if (X_FCN (instruction) == 1) | |
599 | { | |
600 | /* retry */ | |
601 | *target = read_register (TPC_REGNUM); | |
602 | val = done_retry; | |
603 | } | |
604 | } | |
605 | #endif | |
bd5635a1 RP |
606 | |
607 | return val; | |
608 | } | |
ee7b9e92 JK |
609 | \f |
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. | |
615 | ||
616 | The argument RAW_BUFFER must point to aligned memory. */ | |
617 | ||
618 | void | |
619 | get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval) | |
620 | char *raw_buffer; | |
621 | int *optimized; | |
622 | CORE_ADDR *addrp; | |
623 | struct frame_info *frame; | |
624 | int regnum; | |
625 | enum lval_type *lval; | |
626 | { | |
627 | struct frame_info *frame1; | |
628 | CORE_ADDR addr; | |
629 | ||
888a18ee JK |
630 | if (!target_has_registers) |
631 | error ("No registers."); | |
632 | ||
ee7b9e92 JK |
633 | if (optimized) |
634 | *optimized = 0; | |
635 | ||
636 | addr = 0; | |
012be3ce DP |
637 | |
638 | /* FIXME This code extracted from infcmd.c; should put elsewhere! */ | |
639 | if (frame == NULL) | |
640 | { | |
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); | |
648 | if (frame == 0) | |
649 | error ("Cmd not meaningful in the outermost frame."); | |
650 | } | |
651 | ||
652 | ||
ee7b9e92 | 653 | frame1 = frame->next; |
e50f526e MA |
654 | |
655 | /* Get saved PC from the frame info if not in innermost frame. */ | |
656 | if (regnum == PC_REGNUM && frame1 != NULL) | |
657 | { | |
658 | if (lval != NULL) | |
659 | *lval = not_lval; | |
660 | if (raw_buffer != NULL) | |
661 | { | |
662 | /* Put it back in target format. */ | |
663 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), frame->pc); | |
664 | } | |
665 | if (addrp != NULL) | |
666 | *addrp = 0; | |
667 | return; | |
668 | } | |
669 | ||
ee7b9e92 JK |
670 | while (frame1 != NULL) |
671 | { | |
672 | if (frame1->pc >= (frame1->bottom ? frame1->bottom : | |
673 | read_register (SP_REGNUM)) | |
674 | && frame1->pc <= FRAME_FP (frame1)) | |
675 | { | |
012be3ce DP |
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 | |
678 | normal frame. */ | |
ee7b9e92 | 679 | if (regnum >= G1_REGNUM && regnum < G1_REGNUM + 7) |
8b0f5a9d | 680 | addr = frame1->frame + (regnum - G0_REGNUM) * SPARC_INTREG_SIZE |
012be3ce | 681 | - (FP_REGISTER_BYTES + 8 * SPARC_INTREG_SIZE); |
ee7b9e92 | 682 | else if (regnum >= I0_REGNUM && regnum < I0_REGNUM + 8) |
012be3ce DP |
683 | addr = (frame1->prev->bottom |
684 | + (regnum - I0_REGNUM) * SPARC_INTREG_SIZE | |
685 | + FRAME_SAVED_I0); | |
686 | else if (regnum >= L0_REGNUM && regnum < L0_REGNUM + 8) | |
687 | addr = (frame1->prev->bottom | |
688 | + (regnum - L0_REGNUM) * SPARC_INTREG_SIZE | |
689 | + FRAME_SAVED_L0); | |
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); | |
693 | #ifdef FP0_REGNUM | |
694 | else if (regnum >= FP0_REGNUM && regnum < FP0_REGNUM + 32) | |
8b0f5a9d | 695 | addr = frame1->frame + (regnum - FP0_REGNUM) * 4 |
012be3ce DP |
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); | |
701 | #endif | |
702 | #endif /* FP0_REGNUM */ | |
ee7b9e92 | 703 | else if (regnum >= Y_REGNUM && regnum < NUM_REGS) |
8b0f5a9d | 704 | addr = frame1->frame + (regnum - Y_REGNUM) * SPARC_INTREG_SIZE |
012be3ce | 705 | - (FP_REGISTER_BYTES + 24 * SPARC_INTREG_SIZE); |
ee7b9e92 JK |
706 | } |
707 | else if (frame1->flat) | |
708 | { | |
709 | ||
710 | if (regnum == RP_REGNUM) | |
711 | addr = frame1->pc_addr; | |
712 | else if (regnum == I7_REGNUM) | |
713 | addr = frame1->fp_addr; | |
714 | else | |
715 | { | |
716 | CORE_ADDR func_start; | |
717 | struct frame_saved_regs regs; | |
718 | memset (®s, 0, sizeof (regs)); | |
719 | ||
720 | find_pc_partial_function (frame1->pc, NULL, &func_start, NULL); | |
721 | examine_prologue (func_start, 0, frame1, ®s); | |
722 | addr = regs.regs[regnum]; | |
723 | } | |
724 | } | |
725 | else | |
726 | { | |
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 | |
8b0f5a9d | 730 | + (regnum - I0_REGNUM) * SPARC_INTREG_SIZE |
ee7b9e92 JK |
731 | + FRAME_SAVED_I0); |
732 | else if (regnum >= L0_REGNUM && regnum < L0_REGNUM + 8) | |
733 | addr = (frame1->prev->bottom | |
8b0f5a9d | 734 | + (regnum - L0_REGNUM) * SPARC_INTREG_SIZE |
ee7b9e92 JK |
735 | + FRAME_SAVED_L0); |
736 | else if (regnum >= O0_REGNUM && regnum < O0_REGNUM + 8) | |
737 | { | |
738 | /* Outs become ins. */ | |
739 | get_saved_register (raw_buffer, optimized, addrp, frame1, | |
740 | (regnum - O0_REGNUM + I0_REGNUM), lval); | |
741 | return; | |
742 | } | |
743 | } | |
744 | if (addr != 0) | |
745 | break; | |
746 | frame1 = frame1->next; | |
747 | } | |
748 | if (addr != 0) | |
749 | { | |
750 | if (lval != NULL) | |
751 | *lval = lval_memory; | |
752 | if (regnum == SP_REGNUM) | |
753 | { | |
754 | if (raw_buffer != NULL) | |
755 | { | |
756 | /* Put it back in target format. */ | |
757 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), addr); | |
758 | } | |
759 | if (addrp != NULL) | |
760 | *addrp = 0; | |
761 | return; | |
762 | } | |
763 | if (raw_buffer != NULL) | |
764 | read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum)); | |
765 | } | |
766 | else | |
767 | { | |
768 | if (lval != NULL) | |
769 | *lval = lval_register; | |
770 | addr = REGISTER_BYTE (regnum); | |
771 | if (raw_buffer != NULL) | |
772 | read_register_gen (regnum, raw_buffer); | |
773 | } | |
774 | if (addrp != NULL) | |
775 | *addrp = addr; | |
776 | } | |
777 | ||
778 | /* Push an empty stack frame, and record in it the current PC, regs, etc. | |
779 | ||
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. */ | |
783 | ||
784 | /* Definitely see tm-sparc.h for more doc of the frame format here. */ | |
785 | ||
8b0f5a9d DE |
786 | #ifdef GDB_TARGET_IS_SPARC64 |
787 | #define DUMMY_REG_SAVE_OFFSET (128 + 16) | |
788 | #else | |
789 | #define DUMMY_REG_SAVE_OFFSET 0x60 | |
790 | #endif | |
791 | ||
792 | /* See tm-sparc.h for how this is calculated. */ | |
012be3ce | 793 | #ifdef FP0_REGNUM |
8b0f5a9d DE |
794 | #define DUMMY_STACK_REG_BUF_SIZE \ |
795 | (((8+8+8) * SPARC_INTREG_SIZE) + (32 * REGISTER_RAW_SIZE (FP0_REGNUM))) | |
012be3ce DP |
796 | #else |
797 | #define DUMMY_STACK_REG_BUF_SIZE \ | |
798 | (((8+8+8) * SPARC_INTREG_SIZE) ) | |
799 | #endif /* FP0_REGNUM */ | |
8b0f5a9d DE |
800 | #define DUMMY_STACK_SIZE (DUMMY_STACK_REG_BUF_SIZE + DUMMY_REG_SAVE_OFFSET) |
801 | ||
ee7b9e92 JK |
802 | void |
803 | sparc_push_dummy_frame () | |
804 | { | |
805 | CORE_ADDR sp, old_sp; | |
8b0f5a9d | 806 | char register_temp[DUMMY_STACK_SIZE]; |
ee7b9e92 JK |
807 | |
808 | old_sp = sp = read_register (SP_REGNUM); | |
809 | ||
8b0f5a9d DE |
810 | #ifdef GDB_TARGET_IS_SPARC64 |
811 | /* FIXME: not sure what needs to be saved here. */ | |
812 | #else | |
ee7b9e92 JK |
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); | |
8b0f5a9d | 816 | #endif |
ee7b9e92 | 817 | |
8b0f5a9d DE |
818 | read_register_bytes (REGISTER_BYTE (O0_REGNUM), |
819 | ®ister_temp[8 * SPARC_INTREG_SIZE], | |
820 | SPARC_INTREG_SIZE * 8); | |
ee7b9e92 | 821 | |
8b0f5a9d DE |
822 | read_register_bytes (REGISTER_BYTE (G0_REGNUM), |
823 | ®ister_temp[16 * SPARC_INTREG_SIZE], | |
824 | SPARC_INTREG_SIZE * 8); | |
ee7b9e92 | 825 | |
012be3ce | 826 | #ifdef FP0_REGNUM |
8b0f5a9d DE |
827 | read_register_bytes (REGISTER_BYTE (FP0_REGNUM), |
828 | ®ister_temp[24 * SPARC_INTREG_SIZE], | |
012be3ce DP |
829 | FP_REGISTER_BYTES); |
830 | #endif /* FP0_REGNUM */ | |
ee7b9e92 | 831 | |
8b0f5a9d | 832 | sp -= DUMMY_STACK_SIZE; |
ee7b9e92 JK |
833 | |
834 | write_register (SP_REGNUM, sp); | |
835 | ||
8b0f5a9d DE |
836 | write_memory (sp + DUMMY_REG_SAVE_OFFSET, ®ister_temp[0], |
837 | DUMMY_STACK_REG_BUF_SIZE); | |
ee7b9e92 JK |
838 | |
839 | write_register (FP_REGNUM, old_sp); | |
840 | ||
841 | /* Set return address register for the call dummy to the current PC. */ | |
842 | write_register (I7_REGNUM, read_pc() - 8); | |
843 | } | |
bd5635a1 | 844 | |
ee7b9e92 JK |
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 | |
853 | get_saved_register. | |
bd5635a1 RP |
854 | |
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. | |
860 | ||
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. | |
865 | ||
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. | |
871 | ||
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. | |
875 | ||
876 | See tm-sparc.h (PUSH_FRAME and friends) for CRITICAL information | |
877 | about how this works. */ | |
878 | ||
ee7b9e92 JK |
879 | static void sparc_frame_find_saved_regs PARAMS ((struct frame_info *, |
880 | struct frame_saved_regs *)); | |
881 | ||
882 | static void | |
bd5635a1 RP |
883 | sparc_frame_find_saved_regs (fi, saved_regs_addr) |
884 | struct frame_info *fi; | |
885 | struct frame_saved_regs *saved_regs_addr; | |
886 | { | |
887 | register int regnum; | |
84bdfea6 | 888 | CORE_ADDR frame_addr = FRAME_FP (fi); |
bd5635a1 | 889 | |
84bdfea6 | 890 | if (!fi) |
bd5635a1 RP |
891 | fatal ("Bad frame info struct in FRAME_FIND_SAVED_REGS"); |
892 | ||
b38f304c | 893 | memset (saved_regs_addr, 0, sizeof (*saved_regs_addr)); |
bd5635a1 | 894 | |
bd5635a1 RP |
895 | if (fi->pc >= (fi->bottom ? fi->bottom : |
896 | read_register (SP_REGNUM)) | |
897 | && fi->pc <= FRAME_FP(fi)) | |
898 | { | |
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] = | |
8b0f5a9d | 902 | frame_addr + (regnum - G0_REGNUM) * SPARC_INTREG_SIZE |
e50f526e | 903 | - DUMMY_STACK_REG_BUF_SIZE + 16 * SPARC_INTREG_SIZE; |
bd5635a1 RP |
904 | for (regnum = I0_REGNUM; regnum < I0_REGNUM+8; regnum++) |
905 | saved_regs_addr->regs[regnum] = | |
8b0f5a9d | 906 | frame_addr + (regnum - I0_REGNUM) * SPARC_INTREG_SIZE |
e50f526e | 907 | - DUMMY_STACK_REG_BUF_SIZE + 8 * SPARC_INTREG_SIZE; |
012be3ce | 908 | #ifdef FP0_REGNUM |
bd5635a1 RP |
909 | for (regnum = FP0_REGNUM; regnum < FP0_REGNUM + 32; regnum++) |
910 | saved_regs_addr->regs[regnum] = | |
8b0f5a9d | 911 | frame_addr + (regnum - FP0_REGNUM) * 4 |
e50f526e | 912 | - DUMMY_STACK_REG_BUF_SIZE + 24 * SPARC_INTREG_SIZE; |
012be3ce DP |
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 | |
e50f526e | 917 | - DUMMY_STACK_REG_BUF_SIZE + 24 * SPARC_INTREG_SIZE; |
012be3ce DP |
918 | #endif |
919 | #endif /* FP0_REGNUM */ | |
bd5635a1 RP |
920 | for (regnum = Y_REGNUM; regnum < NUM_REGS; regnum++) |
921 | saved_regs_addr->regs[regnum] = | |
e50f526e MA |
922 | frame_addr + (regnum - Y_REGNUM) * SPARC_INTREG_SIZE |
923 | - DUMMY_STACK_REG_BUF_SIZE; | |
84bdfea6 | 924 | frame_addr = fi->bottom ? |
bd5635a1 RP |
925 | fi->bottom : read_register (SP_REGNUM); |
926 | } | |
84bdfea6 PS |
927 | else if (fi->flat) |
928 | { | |
ee7b9e92 JK |
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); | |
932 | ||
84bdfea6 PS |
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; | |
84bdfea6 | 936 | } |
bd5635a1 RP |
937 | else |
938 | { | |
939 | /* Normal frame. Just Local and In registers */ | |
84bdfea6 | 940 | frame_addr = fi->bottom ? |
bd5635a1 | 941 | fi->bottom : read_register (SP_REGNUM); |
84bdfea6 | 942 | for (regnum = L0_REGNUM; regnum < L0_REGNUM+8; regnum++) |
16726dd1 | 943 | saved_regs_addr->regs[regnum] = |
8b0f5a9d | 944 | (frame_addr + (regnum - L0_REGNUM) * SPARC_INTREG_SIZE |
84bdfea6 PS |
945 | + FRAME_SAVED_L0); |
946 | for (regnum = I0_REGNUM; regnum < I0_REGNUM+8; regnum++) | |
947 | saved_regs_addr->regs[regnum] = | |
8b0f5a9d | 948 | (frame_addr + (regnum - I0_REGNUM) * SPARC_INTREG_SIZE |
84bdfea6 | 949 | + FRAME_SAVED_I0); |
bd5635a1 RP |
950 | } |
951 | if (fi->next) | |
952 | { | |
84bdfea6 PS |
953 | if (fi->flat) |
954 | { | |
955 | saved_regs_addr->regs[O7_REGNUM] = fi->pc_addr; | |
956 | } | |
957 | else | |
958 | { | |
959 | /* Pull off either the next frame pointer or the stack pointer */ | |
960 | CORE_ADDR next_next_frame_addr = | |
961 | (fi->next->bottom ? | |
962 | fi->next->bottom : | |
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 | |
8b0f5a9d | 967 | + (regnum - O0_REGNUM) * SPARC_INTREG_SIZE |
84bdfea6 PS |
968 | + FRAME_SAVED_I0); |
969 | } | |
bd5635a1 RP |
970 | } |
971 | /* Otherwise, whatever we would get from ptrace(GETREGS) is accurate */ | |
972 | saved_regs_addr->regs[SP_REGNUM] = FRAME_FP (fi); | |
973 | } | |
974 | ||
bd5635a1 RP |
975 | /* Discard from the stack the innermost frame, restoring all saved registers. |
976 | ||
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. | |
982 | ||
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 | |
985 | on its stack. */ | |
986 | ||
987 | /* Definitely see tm-sparc.h for more doc of the frame format here. */ | |
988 | ||
989 | void | |
990 | sparc_pop_frame () | |
991 | { | |
84bdfea6 | 992 | register struct frame_info *frame = get_current_frame (); |
bd5635a1 RP |
993 | register CORE_ADDR pc; |
994 | struct frame_saved_regs fsr; | |
bd5635a1 | 995 | char raw_buffer[REGISTER_BYTES]; |
84bdfea6 | 996 | int regnum; |
bd5635a1 | 997 | |
ee7b9e92 | 998 | sparc_frame_find_saved_regs (frame, &fsr); |
012be3ce | 999 | #ifdef FP0_REGNUM |
bd5635a1 RP |
1000 | if (fsr.regs[FP0_REGNUM]) |
1001 | { | |
012be3ce | 1002 | read_memory (fsr.regs[FP0_REGNUM], raw_buffer, FP_REGISTER_BYTES); |
8b0f5a9d | 1003 | write_register_bytes (REGISTER_BYTE (FP0_REGNUM), |
012be3ce | 1004 | raw_buffer, FP_REGISTER_BYTES); |
bd5635a1 | 1005 | } |
8b0f5a9d | 1006 | #ifndef GDB_TARGET_IS_SPARC64 |
f1de67d3 PS |
1007 | if (fsr.regs[FPS_REGNUM]) |
1008 | { | |
1009 | read_memory (fsr.regs[FPS_REGNUM], raw_buffer, 4); | |
1010 | write_register_bytes (REGISTER_BYTE (FPS_REGNUM), raw_buffer, 4); | |
1011 | } | |
1012 | if (fsr.regs[CPS_REGNUM]) | |
1013 | { | |
1014 | read_memory (fsr.regs[CPS_REGNUM], raw_buffer, 4); | |
1015 | write_register_bytes (REGISTER_BYTE (CPS_REGNUM), raw_buffer, 4); | |
1016 | } | |
8b0f5a9d | 1017 | #endif |
012be3ce | 1018 | #endif /* FP0_REGNUM */ |
bd5635a1 RP |
1019 | if (fsr.regs[G1_REGNUM]) |
1020 | { | |
8b0f5a9d DE |
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); | |
bd5635a1 | 1024 | } |
84bdfea6 PS |
1025 | |
1026 | if (frame->flat) | |
1027 | { | |
1028 | /* Each register might or might not have been saved, need to test | |
1029 | individually. */ | |
1030 | for (regnum = L0_REGNUM; regnum < L0_REGNUM + 8; ++regnum) | |
1031 | if (fsr.regs[regnum]) | |
8b0f5a9d DE |
1032 | write_register (regnum, read_memory_integer (fsr.regs[regnum], |
1033 | SPARC_INTREG_SIZE)); | |
84bdfea6 PS |
1034 | for (regnum = I0_REGNUM; regnum < I0_REGNUM + 8; ++regnum) |
1035 | if (fsr.regs[regnum]) | |
8b0f5a9d DE |
1036 | write_register (regnum, read_memory_integer (fsr.regs[regnum], |
1037 | SPARC_INTREG_SIZE)); | |
ee7b9e92 JK |
1038 | |
1039 | /* Handle all outs except stack pointer (o0-o5; o7). */ | |
1040 | for (regnum = O0_REGNUM; regnum < O0_REGNUM + 6; ++regnum) | |
84bdfea6 | 1041 | if (fsr.regs[regnum]) |
8b0f5a9d DE |
1042 | write_register (regnum, read_memory_integer (fsr.regs[regnum], |
1043 | SPARC_INTREG_SIZE)); | |
ee7b9e92 JK |
1044 | if (fsr.regs[O0_REGNUM + 7]) |
1045 | write_register (O0_REGNUM + 7, | |
8b0f5a9d DE |
1046 | read_memory_integer (fsr.regs[O0_REGNUM + 7], |
1047 | SPARC_INTREG_SIZE)); | |
ee7b9e92 | 1048 | |
6cb4e9e0 | 1049 | write_register (SP_REGNUM, frame->frame); |
84bdfea6 PS |
1050 | } |
1051 | else if (fsr.regs[I0_REGNUM]) | |
bd5635a1 | 1052 | { |
dd99f8e4 JK |
1053 | CORE_ADDR sp; |
1054 | ||
1055 | char reg_temp[REGISTER_BYTES]; | |
1056 | ||
8b0f5a9d | 1057 | read_memory (fsr.regs[I0_REGNUM], raw_buffer, 8 * SPARC_INTREG_SIZE); |
dd99f8e4 JK |
1058 | |
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 | |
1063 | registers array. */ | |
1064 | sp = fsr.regs[SP_REGNUM]; | |
8b0f5a9d | 1065 | read_memory (sp, reg_temp, SPARC_INTREG_SIZE * 16); |
dd99f8e4 JK |
1066 | |
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, | |
8b0f5a9d | 1070 | SPARC_INTREG_SIZE * 8); |
dd99f8e4 JK |
1071 | |
1072 | write_register_bytes (REGISTER_BYTE (L0_REGNUM), reg_temp, | |
8b0f5a9d | 1073 | SPARC_INTREG_SIZE * 16); |
bd5635a1 | 1074 | } |
8b0f5a9d | 1075 | #ifndef GDB_TARGET_IS_SPARC64 |
bd5635a1 RP |
1076 | if (fsr.regs[PS_REGNUM]) |
1077 | write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4)); | |
8b0f5a9d | 1078 | #endif |
bd5635a1 | 1079 | if (fsr.regs[Y_REGNUM]) |
8b0f5a9d | 1080 | write_register (Y_REGNUM, read_memory_integer (fsr.regs[Y_REGNUM], REGISTER_RAW_SIZE (Y_REGNUM))); |
bd5635a1 RP |
1081 | if (fsr.regs[PC_REGNUM]) |
1082 | { | |
1083 | /* Explicitly specified PC (and maybe NPC) -- just restore them. */ | |
8b0f5a9d DE |
1084 | write_register (PC_REGNUM, read_memory_integer (fsr.regs[PC_REGNUM], |
1085 | REGISTER_RAW_SIZE (PC_REGNUM))); | |
bd5635a1 RP |
1086 | if (fsr.regs[NPC_REGNUM]) |
1087 | write_register (NPC_REGNUM, | |
8b0f5a9d DE |
1088 | read_memory_integer (fsr.regs[NPC_REGNUM], |
1089 | REGISTER_RAW_SIZE (NPC_REGNUM))); | |
bd5635a1 | 1090 | } |
ee7b9e92 | 1091 | else if (frame->flat) |
84bdfea6 | 1092 | { |
ee7b9e92 | 1093 | if (frame->pc_addr) |
8b0f5a9d DE |
1094 | pc = PC_ADJUST ((CORE_ADDR) |
1095 | read_memory_integer (frame->pc_addr, | |
1096 | REGISTER_RAW_SIZE (PC_REGNUM))); | |
ee7b9e92 JK |
1097 | else |
1098 | { | |
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))); | |
1106 | } | |
1107 | ||
84bdfea6 PS |
1108 | write_register (PC_REGNUM, pc); |
1109 | write_register (NPC_REGNUM, pc + 4); | |
1110 | } | |
bd5635a1 RP |
1111 | else if (fsr.regs[I7_REGNUM]) |
1112 | { | |
1113 | /* Return address in %i7 -- adjust it, then restore PC and NPC from it */ | |
8b0f5a9d DE |
1114 | pc = PC_ADJUST ((CORE_ADDR) read_memory_integer (fsr.regs[I7_REGNUM], |
1115 | SPARC_INTREG_SIZE)); | |
bd5635a1 RP |
1116 | write_register (PC_REGNUM, pc); |
1117 | write_register (NPC_REGNUM, pc + 4); | |
1118 | } | |
1119 | flush_cached_frames (); | |
bd5635a1 RP |
1120 | } |
1121 | ||
5e5215eb JG |
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. */ | |
1125 | ||
1126 | CORE_ADDR | |
1127 | sparc_pc_adjust(pc) | |
1128 | CORE_ADDR pc; | |
1129 | { | |
34df79fc JK |
1130 | unsigned long insn; |
1131 | char buf[4]; | |
5e5215eb JG |
1132 | int err; |
1133 | ||
e50f526e | 1134 | err = target_read_memory (pc + 8, buf, 4); |
34df79fc | 1135 | insn = extract_unsigned_integer (buf, 4); |
e4dbd248 | 1136 | if ((err == 0) && (insn & 0xffc00000) == 0) |
5e5215eb JG |
1137 | return pc+12; |
1138 | else | |
1139 | return pc+8; | |
1140 | } | |
84bdfea6 PS |
1141 | |
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 | |
1146 | sethi %hi(addr),%g1 | |
1147 | jmp %g1+%lo(addr) | |
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 | |
1152 | by hand. */ | |
1153 | ||
1154 | CORE_ADDR | |
1155 | sunos4_skip_trampoline_code (pc) | |
1156 | CORE_ADDR pc; | |
1157 | { | |
1158 | unsigned long insn1; | |
1159 | char buf[4]; | |
1160 | int err; | |
1161 | ||
1162 | err = target_read_memory (pc, buf, 4); | |
1163 | insn1 = extract_unsigned_integer (buf, 4); | |
1164 | if (err == 0 && (insn1 & 0xffc00000) == 0x03000000) | |
1165 | { | |
1166 | unsigned long insn2; | |
1167 | ||
1168 | err = target_read_memory (pc + 4, buf, 4); | |
1169 | insn2 = extract_unsigned_integer (buf, 4); | |
1170 | if (err == 0 && (insn2 & 0xffffe000) == 0x81c06000) | |
1171 | { | |
1172 | CORE_ADDR target_pc = (insn1 & 0x3fffff) << 10; | |
1173 | int delta = insn2 & 0x1fff; | |
1174 | ||
1175 | /* Sign extend the displacement. */ | |
1176 | if (delta & 0x1000) | |
1177 | delta |= ~0x1fff; | |
1178 | return target_pc + delta; | |
1179 | } | |
1180 | } | |
1181 | return find_solib_trampoline_target (pc); | |
1182 | } | |
8f86a4e4 JG |
1183 | \f |
1184 | #ifdef USE_PROC_FS /* Target dependent support for /proc */ | |
1185 | ||
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. | |
1190 | ||
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 | |
1194 | by: | |
1195 | ||
1196 | typedef int gregset_t[38]; | |
1197 | ||
1198 | #define R_G0 0 | |
1199 | ... | |
1200 | #define R_TBR 37 | |
1201 | ||
1202 | and the floating point set by: | |
1203 | ||
1204 | typedef struct prfpregset { | |
1205 | union { | |
1206 | u_long pr_regs[32]; | |
1207 | double pr_dregs[16]; | |
1208 | } pr_fr; | |
1209 | void * pr_filler; | |
1210 | u_long pr_fsr; | |
1211 | u_char pr_qcnt; | |
1212 | u_char pr_q_entrysize; | |
1213 | u_char pr_en; | |
1214 | u_long pr_q[64]; | |
1215 | } prfpregset_t; | |
1216 | ||
1217 | These routines provide the packing and unpacking of gregset_t and | |
1218 | fpregset_t formatted data. | |
1219 | ||
1220 | */ | |
1221 | ||
8b0f5a9d DE |
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 | |
1224 | register values. */ | |
8f86a4e4 JG |
1225 | |
1226 | void | |
1227 | supply_gregset (gregsetp) | |
1228 | prgregset_t *gregsetp; | |
1229 | { | |
b38f304c | 1230 | register int regi; |
8f86a4e4 | 1231 | register prgreg_t *regp = (prgreg_t *) gregsetp; |
e4dbd248 | 1232 | static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0}; |
8f86a4e4 JG |
1233 | |
1234 | /* GDB register numbers for Gn, On, Ln, In all match /proc reg numbers. */ | |
b38f304c | 1235 | for (regi = G0_REGNUM ; regi <= I7_REGNUM ; regi++) |
8f86a4e4 | 1236 | { |
b38f304c | 1237 | supply_register (regi, (char *) (regp + regi)); |
8f86a4e4 JG |
1238 | } |
1239 | ||
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)); | |
e4dbd248 PS |
1245 | |
1246 | /* Fill inaccessible registers with zero. */ | |
1247 | supply_register (WIM_REGNUM, zerobuf); | |
1248 | supply_register (TBR_REGNUM, zerobuf); | |
1249 | supply_register (CPS_REGNUM, zerobuf); | |
8f86a4e4 JG |
1250 | } |
1251 | ||
1252 | void | |
1253 | fill_gregset (gregsetp, regno) | |
1254 | prgregset_t *gregsetp; | |
1255 | int regno; | |
1256 | { | |
1257 | int regi; | |
1258 | register prgreg_t *regp = (prgreg_t *) gregsetp; | |
8f86a4e4 JG |
1259 | |
1260 | for (regi = 0 ; regi <= R_I7 ; regi++) | |
1261 | { | |
1262 | if ((regno == -1) || (regno == regi)) | |
1263 | { | |
b38f304c | 1264 | *(regp + regi) = *(int *) ®isters[REGISTER_BYTE (regi)]; |
8f86a4e4 JG |
1265 | } |
1266 | } | |
1267 | if ((regno == -1) || (regno == PS_REGNUM)) | |
1268 | { | |
1269 | *(regp + R_PS) = *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)]; | |
1270 | } | |
1271 | if ((regno == -1) || (regno == PC_REGNUM)) | |
1272 | { | |
1273 | *(regp + R_PC) = *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)]; | |
1274 | } | |
1275 | if ((regno == -1) || (regno == NPC_REGNUM)) | |
1276 | { | |
1277 | *(regp + R_nPC) = *(int *) ®isters[REGISTER_BYTE (NPC_REGNUM)]; | |
1278 | } | |
1279 | if ((regno == -1) || (regno == Y_REGNUM)) | |
1280 | { | |
1281 | *(regp + R_Y) = *(int *) ®isters[REGISTER_BYTE (Y_REGNUM)]; | |
1282 | } | |
1283 | } | |
1284 | ||
1285 | #if defined (FP0_REGNUM) | |
1286 | ||
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. */ | |
1290 | ||
1291 | void | |
1292 | supply_fpregset (fpregsetp) | |
1293 | prfpregset_t *fpregsetp; | |
1294 | { | |
1295 | register int regi; | |
1296 | char *from; | |
1297 | ||
012be3ce | 1298 | for (regi = FP0_REGNUM ; regi < FP_MAX_REGNUM ; regi++) |
8f86a4e4 JG |
1299 | { |
1300 | from = (char *) &fpregsetp->pr_fr.pr_regs[regi-FP0_REGNUM]; | |
1301 | supply_register (regi, from); | |
1302 | } | |
1303 | supply_register (FPS_REGNUM, (char *) &(fpregsetp->pr_fsr)); | |
1304 | } | |
1305 | ||
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 | |
1309 | them all. */ | |
8b0f5a9d | 1310 | /* ??? This will probably need some changes for sparc64. */ |
8f86a4e4 JG |
1311 | |
1312 | void | |
1313 | fill_fpregset (fpregsetp, regno) | |
1314 | prfpregset_t *fpregsetp; | |
1315 | int regno; | |
1316 | { | |
1317 | int regi; | |
1318 | char *to; | |
1319 | char *from; | |
8f86a4e4 | 1320 | |
012be3ce | 1321 | for (regi = FP0_REGNUM ; regi < FP_MAX_REGNUM ; regi++) |
8f86a4e4 JG |
1322 | { |
1323 | if ((regno == -1) || (regno == regi)) | |
1324 | { | |
1325 | from = (char *) ®isters[REGISTER_BYTE (regi)]; | |
1326 | to = (char *) &fpregsetp->pr_fr.pr_regs[regi-FP0_REGNUM]; | |
b38f304c | 1327 | memcpy (to, from, REGISTER_RAW_SIZE (regi)); |
8f86a4e4 JG |
1328 | } |
1329 | } | |
1330 | if ((regno == -1) || (regno == FPS_REGNUM)) | |
1331 | { | |
1332 | fpregsetp->pr_fsr = *(int *) ®isters[REGISTER_BYTE (FPS_REGNUM)]; | |
1333 | } | |
1334 | } | |
1335 | ||
1336 | #endif /* defined (FP0_REGNUM) */ | |
1337 | ||
1338 | #endif /* USE_PROC_FS */ | |
1339 | ||
1340 | ||
1341 | #ifdef GET_LONGJMP_TARGET | |
f9e3b3cc JG |
1342 | |
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 */ | |
1348 | ||
1349 | int | |
84bdfea6 | 1350 | get_longjmp_target (pc) |
f9e3b3cc JG |
1351 | CORE_ADDR *pc; |
1352 | { | |
1353 | CORE_ADDR jb_addr; | |
34df79fc JK |
1354 | #define LONGJMP_TARGET_SIZE 4 |
1355 | char buf[LONGJMP_TARGET_SIZE]; | |
f9e3b3cc | 1356 | |
84bdfea6 | 1357 | jb_addr = read_register (O0_REGNUM); |
f9e3b3cc | 1358 | |
84bdfea6 PS |
1359 | if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf, |
1360 | LONGJMP_TARGET_SIZE)) | |
f9e3b3cc JG |
1361 | return 0; |
1362 | ||
34df79fc | 1363 | *pc = extract_address (buf, LONGJMP_TARGET_SIZE); |
f9e3b3cc JG |
1364 | |
1365 | return 1; | |
1366 | } | |
8f86a4e4 | 1367 | #endif /* GET_LONGJMP_TARGET */ |
8b0f5a9d DE |
1368 | \f |
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. */ | |
1372 | ||
1373 | char * | |
b9e58503 | 1374 | sunpro_static_transform_name (name) |
8b0f5a9d DE |
1375 | char *name; |
1376 | { | |
1377 | char *p; | |
1378 | if (name[0] == '$') | |
1379 | { | |
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 | |
1386 | last period. */ | |
1387 | p = strrchr (name, '.'); | |
1388 | if (p != NULL) | |
1389 | name = p + 1; | |
1390 | } | |
1391 | return name; | |
1392 | } | |
1393 | #endif /* STATIC_TRANSFORM_NAME */ | |
1394 | \f | |
1395 | #ifdef GDB_TARGET_IS_SPARC64 | |
1396 | ||
8b0f5a9d DE |
1397 | /* Utilities for printing registers. |
1398 | Page numbers refer to the SPARC Architecture Manual. */ | |
1399 | ||
b9e58503 PS |
1400 | static void dump_ccreg PARAMS ((char *, int)); |
1401 | ||
8b0f5a9d DE |
1402 | static void |
1403 | dump_ccreg (reg, val) | |
1404 | char *reg; | |
1405 | int val; | |
1406 | { | |
1407 | /* page 41 */ | |
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" | |
1413 | ); | |
1414 | } | |
1415 | ||
1416 | static char * | |
1417 | decode_asi (val) | |
1418 | int val; | |
1419 | { | |
1420 | /* page 72 */ | |
1421 | switch (val) | |
1422 | { | |
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; | |
1438 | } | |
1439 | } | |
1440 | ||
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. */ | |
1444 | ||
1445 | void | |
1446 | sparc_print_register_hook (regno) | |
1447 | int regno; | |
1448 | { | |
e50f526e | 1449 | ULONGEST val; |
8b0f5a9d | 1450 | |
012be3ce DP |
1451 | /* Handle double/quad versions of lower 32 fp regs. */ |
1452 | if (regno >= FP0_REGNUM && regno < FP0_REGNUM + 32 | |
1453 | && (regno & 1) == 0) | |
1454 | { | |
1455 | char value[16]; | |
1456 | ||
1457 | if (!read_relative_register_raw_bytes (regno, value) | |
1458 | && !read_relative_register_raw_bytes (regno + 1, value + 4)) | |
1459 | { | |
1460 | printf_unfiltered ("\t"); | |
1461 | print_floating (value, builtin_type_double, gdb_stdout); | |
1462 | } | |
1463 | #if 0 /* FIXME: gdb doesn't handle long doubles */ | |
1464 | if ((regno & 3) == 0) | |
1465 | { | |
1466 | if (!read_relative_register_raw_bytes (regno + 2, value + 8) | |
1467 | && !read_relative_register_raw_bytes (regno + 3, value + 12)) | |
1468 | { | |
1469 | printf_unfiltered ("\t"); | |
1470 | print_floating (value, builtin_type_long_double, gdb_stdout); | |
1471 | } | |
1472 | } | |
1473 | #endif | |
1474 | return; | |
1475 | } | |
1476 | ||
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) | |
8b0f5a9d | 1483 | { |
012be3ce DP |
1484 | char value[16]; |
1485 | ||
1486 | if (!read_relative_register_raw_bytes (regno, value) | |
1487 | && !read_relative_register_raw_bytes (regno + 1, value + 8)) | |
8b0f5a9d | 1488 | { |
012be3ce DP |
1489 | printf_unfiltered ("\t"); |
1490 | print_floating (value, builtin_type_long_double, gdb_stdout); | |
8b0f5a9d DE |
1491 | } |
1492 | return; | |
1493 | } | |
012be3ce | 1494 | #endif |
8b0f5a9d DE |
1495 | |
1496 | /* FIXME: Some of these are priviledged registers. | |
1497 | Not sure how they should be handled. */ | |
1498 | ||
1499 | #define BITS(n, mask) ((int) (((val) >> (n)) & (mask))) | |
1500 | ||
1501 | val = read_register (regno); | |
1502 | ||
1503 | /* pages 40 - 60 */ | |
1504 | switch (regno) | |
1505 | { | |
1506 | case CCR_REGNUM : | |
1507 | printf_unfiltered("\t"); | |
1508 | dump_ccreg ("xcc", val >> 4); | |
1509 | printf_unfiltered(", "); | |
1510 | dump_ccreg ("icc", val & 15); | |
1511 | break; | |
1512 | case FPRS_REGNUM : | |
1513 | printf ("\tfef:%d, du:%d, dl:%d", | |
1514 | BITS (2, 1), BITS (1, 1), BITS (0, 1)); | |
1515 | break; | |
1516 | case FSR_REGNUM : | |
1517 | { | |
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)); | |
1526 | break; | |
1527 | } | |
1528 | case ASI_REGNUM : | |
1529 | { | |
1530 | char *asi = decode_asi (val); | |
1531 | if (asi != NULL) | |
1532 | printf ("\t%s", asi); | |
1533 | break; | |
1534 | } | |
1535 | case VER_REGNUM : | |
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)); | |
1539 | break; | |
1540 | case PSTATE_REGNUM : | |
1541 | { | |
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), | |
1546 | BITS (0, 1)); | |
1547 | break; | |
1548 | } | |
1549 | case TSTATE_REGNUM : | |
1550 | /* FIXME: print all 4? */ | |
1551 | break; | |
1552 | case TT_REGNUM : | |
1553 | /* FIXME: print all 4? */ | |
1554 | break; | |
1555 | case TPC_REGNUM : | |
1556 | /* FIXME: print all 4? */ | |
1557 | break; | |
1558 | case TNPC_REGNUM : | |
1559 | /* FIXME: print all 4? */ | |
1560 | break; | |
1561 | case WSTATE_REGNUM : | |
1562 | printf ("\tother:%d, normal:%d", BITS (3, 7), BITS (0, 7)); | |
1563 | break; | |
1564 | case CWP_REGNUM : | |
1565 | printf ("\t%d", BITS (0, 31)); | |
1566 | break; | |
1567 | case CANSAVE_REGNUM : | |
1568 | printf ("\t%-2d before spill", BITS (0, 31)); | |
1569 | break; | |
1570 | case CANRESTORE_REGNUM : | |
1571 | printf ("\t%-2d before fill", BITS (0, 31)); | |
1572 | break; | |
1573 | case CLEANWIN_REGNUM : | |
1574 | printf ("\t%-2d before clean", BITS (0, 31)); | |
1575 | break; | |
1576 | case OTHERWIN_REGNUM : | |
1577 | printf ("\t%d", BITS (0, 31)); | |
1578 | break; | |
1579 | } | |
1580 | ||
1581 | #undef BITS | |
1582 | } | |
1583 | ||
1584 | #endif | |
1585 | \f | |
e50f526e MA |
1586 | int |
1587 | gdb_print_insn_sparc (memaddr, info) | |
1588 | bfd_vma memaddr; | |
1589 | disassemble_info *info; | |
1590 | { | |
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); | |
1594 | } | |
1595 | \f | |
1596 | /* The SPARC passes the arguments on the stack; arguments smaller | |
1597 | than an int are promoted to an int. */ | |
1598 | ||
1599 | CORE_ADDR | |
1600 | sparc_push_arguments (nargs, args, sp, struct_return, struct_addr) | |
1601 | int nargs; | |
1602 | value_ptr *args; | |
1603 | CORE_ADDR sp; | |
1604 | int struct_return; | |
1605 | CORE_ADDR struct_addr; | |
1606 | { | |
1607 | int i; | |
1608 | int accumulate_size = 0; | |
1609 | struct sparc_arg | |
1610 | { | |
1611 | char *contents; | |
1612 | int len; | |
1613 | int offset; | |
1614 | }; | |
1615 | struct sparc_arg *sparc_args = | |
1616 | (struct sparc_arg*)alloca (nargs * sizeof (struct sparc_arg)); | |
1617 | struct sparc_arg *m_arg; | |
1618 | ||
1619 | /* Promote arguments if necessary, and calculate their stack offsets | |
1620 | and sizes. */ | |
1621 | for (i = 0, m_arg = sparc_args; i < nargs; i++, m_arg++) | |
1622 | { | |
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)) | |
1627 | { | |
1628 | case TYPE_CODE_INT: | |
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)) | |
1634 | { | |
1635 | arg_type = builtin_type_long; | |
1636 | arg = value_cast (arg_type, arg); | |
1637 | } | |
1638 | break; | |
1639 | default: | |
1640 | break; | |
1641 | } | |
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); | |
1646 | } | |
1647 | ||
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; | |
1651 | ||
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); | |
1655 | ||
1656 | return sp; | |
1657 | } | |
1658 | \f | |
8b0f5a9d DE |
1659 | void |
1660 | _initialize_sparc_tdep () | |
1661 | { | |
e50f526e | 1662 | tm_print_insn = gdb_print_insn_sparc; |
91550191 | 1663 | tm_print_insn_info.mach = TM_PRINT_INSN_MACH; /* Selects sparc/sparclite */ |
8b0f5a9d | 1664 | } |