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