1 // OBSOLETE /* Target-dependent code for the Matsushita MN10200 for GDB, the GNU debugger.
3 // OBSOLETE Copyright 1997, 1998, 1999, 2000, 2001, 2003 Free Software
4 // OBSOLETE Foundation, Inc.
6 // OBSOLETE This file is part of GDB.
8 // OBSOLETE This program is free software; you can redistribute it and/or modify
9 // OBSOLETE it under the terms of the GNU General Public License as published by
10 // OBSOLETE the Free Software Foundation; either version 2 of the License, or
11 // OBSOLETE (at your option) any later version.
13 // OBSOLETE This program is distributed in the hope that it will be useful,
14 // OBSOLETE but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // OBSOLETE MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // OBSOLETE GNU General Public License for more details.
18 // OBSOLETE You should have received a copy of the GNU General Public License
19 // OBSOLETE along with this program; if not, write to the Free Software
20 // OBSOLETE Foundation, Inc., 59 Temple Place - Suite 330,
21 // OBSOLETE Boston, MA 02111-1307, USA. */
23 // OBSOLETE #include "defs.h"
24 // OBSOLETE #include "frame.h"
25 // OBSOLETE #include "inferior.h"
26 // OBSOLETE #include "target.h"
27 // OBSOLETE #include "value.h"
28 // OBSOLETE #include "bfd.h"
29 // OBSOLETE #include "gdb_string.h"
30 // OBSOLETE #include "gdbcore.h"
31 // OBSOLETE #include "symfile.h"
32 // OBSOLETE #include "regcache.h"
35 // OBSOLETE /* Should call_function allocate stack space for a struct return? */
37 // OBSOLETE mn10200_use_struct_convention (int gcc_p, struct type *type)
39 // OBSOLETE return (TYPE_NFIELDS (type) > 1 || TYPE_LENGTH (type) > 8);
41 // OBSOLETE /* *INDENT-OFF* */
42 // OBSOLETE /* The main purpose of this file is dealing with prologues to extract
43 // OBSOLETE information about stack frames and saved registers.
45 // OBSOLETE For reference here's how prologues look on the mn10200:
47 // OBSOLETE With frame pointer:
50 // OBSOLETE add <size>,sp
51 // OBSOLETE Register saves for d2, d3, a1, a2 as needed. Saves start
52 // OBSOLETE at fp - <size> + <outgoing_args_size> and work towards higher
53 // OBSOLETE addresses. Note that the saves are actually done off the stack
54 // OBSOLETE pointer in the prologue! This makes for smaller code and easier
55 // OBSOLETE prologue scanning as the displacement fields will unlikely
56 // OBSOLETE be more than 8 bits!
58 // OBSOLETE Without frame pointer:
59 // OBSOLETE add <size>,sp
60 // OBSOLETE Register saves for d2, d3, a1, a2 as needed. Saves start
61 // OBSOLETE at sp + <outgoing_args_size> and work towards higher addresses.
63 // OBSOLETE Out of line prologue:
64 // OBSOLETE add <local size>,sp -- optional
65 // OBSOLETE jsr __prologue
66 // OBSOLETE add <outgoing_size>,sp -- optional
68 // OBSOLETE The stack pointer remains constant throughout the life of most
69 // OBSOLETE functions. As a result the compiler will usually omit the
70 // OBSOLETE frame pointer, so we must handle frame pointerless functions. */
72 // OBSOLETE /* Analyze the prologue to determine where registers are saved,
73 // OBSOLETE the end of the prologue, etc etc. Return the end of the prologue
76 // OBSOLETE We store into FI (if non-null) several tidbits of information:
78 // OBSOLETE * stack_size -- size of this stack frame. Note that if we stop in
79 // OBSOLETE certain parts of the prologue/epilogue we may claim the size of the
80 // OBSOLETE current frame is zero. This happens when the current frame has
81 // OBSOLETE not been allocated yet or has already been deallocated.
83 // OBSOLETE * fsr -- Addresses of registers saved in the stack by this frame.
85 // OBSOLETE * status -- A (relatively) generic status indicator. It's a bitmask
86 // OBSOLETE with the following bits:
88 // OBSOLETE MY_FRAME_IN_SP: The base of the current frame is actually in
89 // OBSOLETE the stack pointer. This can happen for frame pointerless
90 // OBSOLETE functions, or cases where we're stopped in the prologue/epilogue
91 // OBSOLETE itself. For these cases mn10200_analyze_prologue will need up
92 // OBSOLETE update fi->frame before returning or analyzing the register
93 // OBSOLETE save instructions.
95 // OBSOLETE MY_FRAME_IN_FP: The base of the current frame is in the
96 // OBSOLETE frame pointer register ($a2).
98 // OBSOLETE CALLER_A2_IN_A0: $a2 from the caller's frame is temporarily
99 // OBSOLETE in $a0. This can happen if we're stopped in the prologue.
101 // OBSOLETE NO_MORE_FRAMES: Set this if the current frame is "start" or
102 // OBSOLETE if the first instruction looks like mov <imm>,sp. This tells
103 // OBSOLETE frame chain to not bother trying to unwind past this frame. */
104 // OBSOLETE /* *INDENT-ON* */
109 // OBSOLETE #define MY_FRAME_IN_SP 0x1
110 // OBSOLETE #define MY_FRAME_IN_FP 0x2
111 // OBSOLETE #define CALLER_A2_IN_A0 0x4
112 // OBSOLETE #define NO_MORE_FRAMES 0x8
114 // OBSOLETE static CORE_ADDR
115 // OBSOLETE mn10200_analyze_prologue (struct frame_info *fi, CORE_ADDR pc)
117 // OBSOLETE CORE_ADDR func_addr, func_end, addr, stop;
118 // OBSOLETE CORE_ADDR stack_size = 0;
119 // OBSOLETE unsigned char buf[4];
120 // OBSOLETE int status;
121 // OBSOLETE char *name;
122 // OBSOLETE int out_of_line_prologue = 0;
124 // OBSOLETE /* Use the PC in the frame if it's provided to look up the
125 // OBSOLETE start of this function. */
126 // OBSOLETE pc = (fi ? get_frame_pc (fi) : pc);
128 // OBSOLETE /* Find the start of this function. */
129 // OBSOLETE status = find_pc_partial_function (pc, &name, &func_addr, &func_end);
131 // OBSOLETE /* Do nothing if we couldn't find the start of this function or if we're
132 // OBSOLETE stopped at the first instruction in the prologue. */
133 // OBSOLETE if (status == 0)
134 // OBSOLETE return pc;
136 // OBSOLETE /* If we're in start, then give up. */
137 // OBSOLETE if (strcmp (name, "start") == 0)
140 // OBSOLETE fi->status = NO_MORE_FRAMES;
141 // OBSOLETE return pc;
144 // OBSOLETE /* At the start of a function our frame is in the stack pointer. */
146 // OBSOLETE fi->status = MY_FRAME_IN_SP;
148 // OBSOLETE /* If we're physically on an RTS instruction, then our frame has already
149 // OBSOLETE been deallocated.
151 // OBSOLETE fi->frame is bogus, we need to fix it. */
152 // OBSOLETE if (fi && get_frame_pc (fi) + 1 == func_end)
154 // OBSOLETE status = target_read_memory (get_frame_pc (fi), buf, 1);
155 // OBSOLETE if (status != 0)
157 // OBSOLETE if (get_next_frame (fi) == NULL)
158 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
159 // OBSOLETE return get_frame_pc (fi);
162 // OBSOLETE if (buf[0] == 0xfe)
164 // OBSOLETE if (get_next_frame (fi) == NULL)
165 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
166 // OBSOLETE return get_frame_pc (fi);
170 // OBSOLETE /* Similarly if we're stopped on the first insn of a prologue as our
171 // OBSOLETE frame hasn't been allocated yet. */
172 // OBSOLETE if (fi && get_frame_pc (fi) == func_addr)
174 // OBSOLETE if (get_next_frame (fi) == NULL)
175 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
176 // OBSOLETE return get_frame_pc (fi);
179 // OBSOLETE /* Figure out where to stop scanning. */
180 // OBSOLETE stop = fi ? get_frame_pc (fi) : func_end;
182 // OBSOLETE /* Don't walk off the end of the function. */
183 // OBSOLETE stop = stop > func_end ? func_end : stop;
185 // OBSOLETE /* Start scanning on the first instruction of this function. */
186 // OBSOLETE addr = func_addr;
188 // OBSOLETE status = target_read_memory (addr, buf, 2);
189 // OBSOLETE if (status != 0)
191 // OBSOLETE if (fi && get_next_frame (fi) == NULL && fi->status & MY_FRAME_IN_SP)
192 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
193 // OBSOLETE return addr;
196 // OBSOLETE /* First see if this insn sets the stack pointer; if so, it's something
197 // OBSOLETE we won't understand, so quit now. */
198 // OBSOLETE if (buf[0] == 0xdf
199 // OBSOLETE || (buf[0] == 0xf4 && buf[1] == 0x77))
202 // OBSOLETE fi->status = NO_MORE_FRAMES;
203 // OBSOLETE return addr;
206 // OBSOLETE /* Now see if we have a frame pointer.
208 // OBSOLETE Search for mov a2,a0 (0xf278)
209 // OBSOLETE then mov a3,a2 (0xf27e). */
211 // OBSOLETE if (buf[0] == 0xf2 && buf[1] == 0x78)
213 // OBSOLETE /* Our caller's $a2 will be found in $a0 now. Note it for
214 // OBSOLETE our callers. */
216 // OBSOLETE fi->status |= CALLER_A2_IN_A0;
217 // OBSOLETE addr += 2;
218 // OBSOLETE if (addr >= stop)
220 // OBSOLETE /* We still haven't allocated our local stack. Handle this
221 // OBSOLETE as if we stopped on the first or last insn of a function. */
222 // OBSOLETE if (fi && get_next_frame (fi) == NULL)
223 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
224 // OBSOLETE return addr;
227 // OBSOLETE status = target_read_memory (addr, buf, 2);
228 // OBSOLETE if (status != 0)
230 // OBSOLETE if (fi && get_next_frame (fi) == NULL)
231 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
232 // OBSOLETE return addr;
234 // OBSOLETE if (buf[0] == 0xf2 && buf[1] == 0x7e)
236 // OBSOLETE addr += 2;
238 // OBSOLETE /* Our frame pointer is valid now. */
241 // OBSOLETE fi->status |= MY_FRAME_IN_FP;
242 // OBSOLETE fi->status &= ~MY_FRAME_IN_SP;
244 // OBSOLETE if (addr >= stop)
245 // OBSOLETE return addr;
249 // OBSOLETE if (fi && get_next_frame (fi) == NULL)
250 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
251 // OBSOLETE return addr;
255 // OBSOLETE /* Next we should allocate the local frame.
257 // OBSOLETE Search for add imm8,a3 (0xd3XX)
258 // OBSOLETE or add imm16,a3 (0xf70bXXXX)
259 // OBSOLETE or add imm24,a3 (0xf467XXXXXX).
261 // OBSOLETE If none of the above was found, then this prologue has
262 // OBSOLETE no stack, and therefore can't have any register saves,
263 // OBSOLETE so quit now. */
264 // OBSOLETE status = target_read_memory (addr, buf, 2);
265 // OBSOLETE if (status != 0)
267 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
268 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
269 // OBSOLETE return addr;
271 // OBSOLETE if (buf[0] == 0xd3)
273 // OBSOLETE stack_size = extract_signed_integer (&buf[1], 1);
275 // OBSOLETE fi->stack_size = stack_size;
276 // OBSOLETE addr += 2;
277 // OBSOLETE if (addr >= stop)
279 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
280 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp () - stack_size);
281 // OBSOLETE return addr;
284 // OBSOLETE else if (buf[0] == 0xf7 && buf[1] == 0x0b)
286 // OBSOLETE status = target_read_memory (addr + 2, buf, 2);
287 // OBSOLETE if (status != 0)
289 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
290 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
291 // OBSOLETE return addr;
293 // OBSOLETE stack_size = extract_signed_integer (buf, 2);
295 // OBSOLETE fi->stack_size = stack_size;
296 // OBSOLETE addr += 4;
297 // OBSOLETE if (addr >= stop)
299 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
300 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp () - stack_size);
301 // OBSOLETE return addr;
304 // OBSOLETE else if (buf[0] == 0xf4 && buf[1] == 0x67)
306 // OBSOLETE status = target_read_memory (addr + 2, buf, 3);
307 // OBSOLETE if (status != 0)
309 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
310 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
311 // OBSOLETE return addr;
313 // OBSOLETE stack_size = extract_signed_integer (buf, 3);
315 // OBSOLETE fi->stack_size = stack_size;
316 // OBSOLETE addr += 5;
317 // OBSOLETE if (addr >= stop)
319 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
320 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp () - stack_size);
321 // OBSOLETE return addr;
325 // OBSOLETE /* Now see if we have a call to __prologue for an out of line
326 // OBSOLETE prologue. */
327 // OBSOLETE status = target_read_memory (addr, buf, 2);
328 // OBSOLETE if (status != 0)
329 // OBSOLETE return addr;
331 // OBSOLETE /* First check for 16bit pc-relative call to __prologue. */
332 // OBSOLETE if (buf[0] == 0xfd)
334 // OBSOLETE CORE_ADDR temp;
335 // OBSOLETE status = target_read_memory (addr + 1, buf, 2);
336 // OBSOLETE if (status != 0)
338 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
339 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
340 // OBSOLETE return addr;
343 // OBSOLETE /* Get the PC this instruction will branch to. */
344 // OBSOLETE temp = (extract_signed_integer (buf, 2) + addr + 3) & 0xffffff;
346 // OBSOLETE /* Get the name of the function at the target address. */
347 // OBSOLETE status = find_pc_partial_function (temp, &name, NULL, NULL);
348 // OBSOLETE if (status == 0)
350 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
351 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
352 // OBSOLETE return addr;
355 // OBSOLETE /* Note if it is an out of line prologue. */
356 // OBSOLETE out_of_line_prologue = (strcmp (name, "__prologue") == 0);
358 // OBSOLETE /* This sucks up 3 bytes of instruction space. */
359 // OBSOLETE if (out_of_line_prologue)
360 // OBSOLETE addr += 3;
362 // OBSOLETE if (addr >= stop)
364 // OBSOLETE if (fi && get_next_frame (fi) == NULL)
366 // OBSOLETE fi->stack_size -= 16;
367 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp () - fi->stack_size);
369 // OBSOLETE return addr;
372 // OBSOLETE /* Now check for the 24bit pc-relative call to __prologue. */
373 // OBSOLETE else if (buf[0] == 0xf4 && buf[1] == 0xe1)
375 // OBSOLETE CORE_ADDR temp;
376 // OBSOLETE status = target_read_memory (addr + 2, buf, 3);
377 // OBSOLETE if (status != 0)
379 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
380 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
381 // OBSOLETE return addr;
384 // OBSOLETE /* Get the PC this instruction will branch to. */
385 // OBSOLETE temp = (extract_signed_integer (buf, 3) + addr + 5) & 0xffffff;
387 // OBSOLETE /* Get the name of the function at the target address. */
388 // OBSOLETE status = find_pc_partial_function (temp, &name, NULL, NULL);
389 // OBSOLETE if (status == 0)
391 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
392 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp ());
393 // OBSOLETE return addr;
396 // OBSOLETE /* Note if it is an out of line prologue. */
397 // OBSOLETE out_of_line_prologue = (strcmp (name, "__prologue") == 0);
399 // OBSOLETE /* This sucks up 5 bytes of instruction space. */
400 // OBSOLETE if (out_of_line_prologue)
401 // OBSOLETE addr += 5;
403 // OBSOLETE if (addr >= stop)
405 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP))
407 // OBSOLETE fi->stack_size -= 16;
408 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp () - fi->stack_size);
410 // OBSOLETE return addr;
414 // OBSOLETE /* Now actually handle the out of line prologue. */
415 // OBSOLETE if (out_of_line_prologue)
417 // OBSOLETE int outgoing_args_size = 0;
419 // OBSOLETE /* First adjust the stack size for this function. The out of
420 // OBSOLETE line prologue saves 4 registers (16bytes of data). */
422 // OBSOLETE fi->stack_size -= 16;
424 // OBSOLETE /* Update fi->frame if necessary. */
425 // OBSOLETE if (fi && get_next_frame (fi) == NULL)
426 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp () - fi->stack_size);
428 // OBSOLETE /* After the out of line prologue, there may be another
429 // OBSOLETE stack adjustment for the outgoing arguments.
431 // OBSOLETE Search for add imm8,a3 (0xd3XX)
432 // OBSOLETE or add imm16,a3 (0xf70bXXXX)
433 // OBSOLETE or add imm24,a3 (0xf467XXXXXX). */
435 // OBSOLETE status = target_read_memory (addr, buf, 2);
436 // OBSOLETE if (status != 0)
440 // OBSOLETE fi->fsr.regs[2] = get_frame_base (fi) + fi->stack_size + 4;
441 // OBSOLETE fi->fsr.regs[3] = get_frame_base (fi) + fi->stack_size + 8;
442 // OBSOLETE fi->fsr.regs[5] = get_frame_base (fi) + fi->stack_size + 12;
443 // OBSOLETE fi->fsr.regs[6] = get_frame_base (fi) + fi->stack_size + 16;
445 // OBSOLETE return addr;
448 // OBSOLETE if (buf[0] == 0xd3)
450 // OBSOLETE outgoing_args_size = extract_signed_integer (&buf[1], 1);
451 // OBSOLETE addr += 2;
453 // OBSOLETE else if (buf[0] == 0xf7 && buf[1] == 0x0b)
455 // OBSOLETE status = target_read_memory (addr + 2, buf, 2);
456 // OBSOLETE if (status != 0)
460 // OBSOLETE fi->fsr.regs[2] = get_frame_base (fi) + fi->stack_size + 4;
461 // OBSOLETE fi->fsr.regs[3] = get_frame_base (fi) + fi->stack_size + 8;
462 // OBSOLETE fi->fsr.regs[5] = get_frame_base (fi) + fi->stack_size + 12;
463 // OBSOLETE fi->fsr.regs[6] = get_frame_base (fi) + fi->stack_size + 16;
465 // OBSOLETE return addr;
467 // OBSOLETE outgoing_args_size = extract_signed_integer (buf, 2);
468 // OBSOLETE addr += 4;
470 // OBSOLETE else if (buf[0] == 0xf4 && buf[1] == 0x67)
472 // OBSOLETE status = target_read_memory (addr + 2, buf, 3);
473 // OBSOLETE if (status != 0)
475 // OBSOLETE if (fi && get_next_frame (fi) == NULL)
477 // OBSOLETE fi->fsr.regs[2] = get_frame_base (fi) + fi->stack_size + 4;
478 // OBSOLETE fi->fsr.regs[3] = get_frame_base (fi) + fi->stack_size + 8;
479 // OBSOLETE fi->fsr.regs[5] = get_frame_base (fi) + fi->stack_size + 12;
480 // OBSOLETE fi->fsr.regs[6] = get_frame_base (fi) + fi->stack_size + 16;
482 // OBSOLETE return addr;
484 // OBSOLETE outgoing_args_size = extract_signed_integer (buf, 3);
485 // OBSOLETE addr += 5;
488 // OBSOLETE outgoing_args_size = 0;
490 // OBSOLETE /* Now that we know the size of the outgoing arguments, fix
491 // OBSOLETE fi->frame again if this is the innermost frame. */
492 // OBSOLETE if (fi && get_next_frame (fi) == NULL)
493 // OBSOLETE deprecated_update_frame_base_hack (fi, get_frame_base (fi) - outgoing_args_size);
495 // OBSOLETE /* Note the register save information and update the stack
496 // OBSOLETE size for this frame too. */
499 // OBSOLETE fi->fsr.regs[2] = get_frame_base (fi) + fi->stack_size + 4;
500 // OBSOLETE fi->fsr.regs[3] = get_frame_base (fi) + fi->stack_size + 8;
501 // OBSOLETE fi->fsr.regs[5] = get_frame_base (fi) + fi->stack_size + 12;
502 // OBSOLETE fi->fsr.regs[6] = get_frame_base (fi) + fi->stack_size + 16;
503 // OBSOLETE fi->stack_size += outgoing_args_size;
505 // OBSOLETE /* There can be no more prologue insns, so return now. */
506 // OBSOLETE return addr;
509 // OBSOLETE /* At this point fi->frame needs to be correct.
511 // OBSOLETE If MY_FRAME_IN_SP is set and we're the innermost frame, then we
512 // OBSOLETE need to fix fi->frame so that backtracing, find_frame_saved_regs,
513 // OBSOLETE etc work correctly. */
514 // OBSOLETE if (fi && get_next_frame (fi) == NULL && (fi->status & MY_FRAME_IN_SP) != 0)
515 // OBSOLETE deprecated_update_frame_base_hack (fi, read_sp () - fi->stack_size);
517 // OBSOLETE /* And last we have the register saves. These are relatively
518 // OBSOLETE simple because they're physically done off the stack pointer,
519 // OBSOLETE and thus the number of different instructions we need to
520 // OBSOLETE check is greatly reduced because we know the displacements
521 // OBSOLETE will be small.
523 // OBSOLETE Search for movx d2,(X,a3) (0xf55eXX)
524 // OBSOLETE then movx d3,(X,a3) (0xf55fXX)
525 // OBSOLETE then mov a1,(X,a3) (0x5dXX) No frame pointer case
526 // OBSOLETE then mov a2,(X,a3) (0x5eXX) No frame pointer case
527 // OBSOLETE or mov a0,(X,a3) (0x5cXX) Frame pointer case. */
529 // OBSOLETE status = target_read_memory (addr, buf, 2);
530 // OBSOLETE if (status != 0)
531 // OBSOLETE return addr;
532 // OBSOLETE if (buf[0] == 0xf5 && buf[1] == 0x5e)
536 // OBSOLETE status = target_read_memory (addr + 2, buf, 1);
537 // OBSOLETE if (status != 0)
538 // OBSOLETE return addr;
539 // OBSOLETE fi->fsr.regs[2] = (get_frame_base (fi) + stack_size
540 // OBSOLETE + extract_signed_integer (buf, 1));
542 // OBSOLETE addr += 3;
543 // OBSOLETE if (addr >= stop)
544 // OBSOLETE return addr;
545 // OBSOLETE status = target_read_memory (addr, buf, 2);
546 // OBSOLETE if (status != 0)
547 // OBSOLETE return addr;
549 // OBSOLETE if (buf[0] == 0xf5 && buf[1] == 0x5f)
553 // OBSOLETE status = target_read_memory (addr + 2, buf, 1);
554 // OBSOLETE if (status != 0)
555 // OBSOLETE return addr;
556 // OBSOLETE fi->fsr.regs[3] = (get_frame_base (fi) + stack_size
557 // OBSOLETE + extract_signed_integer (buf, 1));
559 // OBSOLETE addr += 3;
560 // OBSOLETE if (addr >= stop)
561 // OBSOLETE return addr;
562 // OBSOLETE status = target_read_memory (addr, buf, 2);
563 // OBSOLETE if (status != 0)
564 // OBSOLETE return addr;
566 // OBSOLETE if (buf[0] == 0x5d)
570 // OBSOLETE status = target_read_memory (addr + 1, buf, 1);
571 // OBSOLETE if (status != 0)
572 // OBSOLETE return addr;
573 // OBSOLETE fi->fsr.regs[5] = (get_frame_base (fi) + stack_size
574 // OBSOLETE + extract_signed_integer (buf, 1));
576 // OBSOLETE addr += 2;
577 // OBSOLETE if (addr >= stop)
578 // OBSOLETE return addr;
579 // OBSOLETE status = target_read_memory (addr, buf, 2);
580 // OBSOLETE if (status != 0)
581 // OBSOLETE return addr;
583 // OBSOLETE if (buf[0] == 0x5e || buf[0] == 0x5c)
587 // OBSOLETE status = target_read_memory (addr + 1, buf, 1);
588 // OBSOLETE if (status != 0)
589 // OBSOLETE return addr;
590 // OBSOLETE fi->fsr.regs[6] = (get_frame_base (fi) + stack_size
591 // OBSOLETE + extract_signed_integer (buf, 1));
592 // OBSOLETE fi->status &= ~CALLER_A2_IN_A0;
594 // OBSOLETE addr += 2;
595 // OBSOLETE if (addr >= stop)
596 // OBSOLETE return addr;
597 // OBSOLETE return addr;
599 // OBSOLETE return addr;
602 // OBSOLETE /* Function: frame_chain
603 // OBSOLETE Figure out and return the caller's frame pointer given current
604 // OBSOLETE frame_info struct.
606 // OBSOLETE We don't handle dummy frames yet but we would probably just return the
607 // OBSOLETE stack pointer that was in use at the time the function call was made? */
609 // OBSOLETE CORE_ADDR
610 // OBSOLETE mn10200_frame_chain (struct frame_info *fi)
612 // OBSOLETE struct frame_info *dummy_frame = deprecated_frame_xmalloc ();
613 // OBSOLETE struct cleanup *old_chain = make_cleanup (xfree, dummy_frame);
614 // OBSOLETE CORE_ADDR ret;
616 // OBSOLETE /* Walk through the prologue to determine the stack size,
617 // OBSOLETE location of saved registers, end of the prologue, etc. */
618 // OBSOLETE if (fi->status == 0)
619 // OBSOLETE mn10200_analyze_prologue (fi, (CORE_ADDR) 0);
621 // OBSOLETE /* Quit now if mn10200_analyze_prologue set NO_MORE_FRAMES. */
622 // OBSOLETE if (fi->status & NO_MORE_FRAMES)
623 // OBSOLETE return 0;
625 // OBSOLETE /* Now that we've analyzed our prologue, determine the frame
626 // OBSOLETE pointer for our caller.
628 // OBSOLETE If our caller has a frame pointer, then we need to
629 // OBSOLETE find the entry value of $a2 to our function.
631 // OBSOLETE If CALLER_A2_IN_A0, then the chain is in $a0.
633 // OBSOLETE If fsr.regs[6] is nonzero, then it's at the memory
634 // OBSOLETE location pointed to by fsr.regs[6].
636 // OBSOLETE Else it's still in $a2.
638 // OBSOLETE If our caller does not have a frame pointer, then his
639 // OBSOLETE frame base is fi->frame + -caller's stack size + 4. */
641 // OBSOLETE /* The easiest way to get that info is to analyze our caller's frame.
643 // OBSOLETE So we set up a dummy frame and call mn10200_analyze_prologue to
644 // OBSOLETE find stuff for us. */
645 // OBSOLETE deprecated_update_frame_pc_hack (dummy_frame, FRAME_SAVED_PC (fi));
646 // OBSOLETE deprecated_update_frame_base_hack (dummy_frame, get_frame_base (fi));
647 // OBSOLETE memset (dummy_frame->fsr.regs, '\000', sizeof dummy_frame->fsr.regs);
648 // OBSOLETE dummy_frame->status = 0;
649 // OBSOLETE dummy_frame->stack_size = 0;
650 // OBSOLETE mn10200_analyze_prologue (dummy_frame, 0);
652 // OBSOLETE if (dummy_frame->status & MY_FRAME_IN_FP)
654 // OBSOLETE /* Our caller has a frame pointer. So find the frame in $a2, $a0,
655 // OBSOLETE or in the stack. */
656 // OBSOLETE if (fi->fsr.regs[6])
657 // OBSOLETE ret = (read_memory_integer (fi->fsr.regs[FP_REGNUM], REGISTER_SIZE)
658 // OBSOLETE & 0xffffff);
659 // OBSOLETE else if (fi->status & CALLER_A2_IN_A0)
660 // OBSOLETE ret = read_register (4);
662 // OBSOLETE ret = read_register (FP_REGNUM);
666 // OBSOLETE /* Our caller does not have a frame pointer. So his frame starts
667 // OBSOLETE at the base of our frame (fi->frame) + <his size> + 4 (saved pc). */
668 // OBSOLETE ret = get_frame_base (fi) + -dummy_frame->stack_size + 4;
670 // OBSOLETE do_cleanups (old_chain);
671 // OBSOLETE return ret;
674 // OBSOLETE /* Function: skip_prologue
675 // OBSOLETE Return the address of the first inst past the prologue of the function. */
677 // OBSOLETE CORE_ADDR
678 // OBSOLETE mn10200_skip_prologue (CORE_ADDR pc)
680 // OBSOLETE /* We used to check the debug symbols, but that can lose if
681 // OBSOLETE we have a null prologue. */
682 // OBSOLETE return mn10200_analyze_prologue (NULL, pc);
685 // OBSOLETE /* Function: pop_frame
686 // OBSOLETE This routine gets called when either the user uses the `return'
687 // OBSOLETE command, or the call dummy breakpoint gets hit. */
690 // OBSOLETE mn10200_pop_frame (struct frame_info *frame)
692 // OBSOLETE int regnum;
694 // OBSOLETE if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame),
695 // OBSOLETE get_frame_base (frame),
696 // OBSOLETE get_frame_base (frame)))
697 // OBSOLETE generic_pop_dummy_frame ();
700 // OBSOLETE write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
702 // OBSOLETE /* Restore any saved registers. */
703 // OBSOLETE for (regnum = 0; regnum < NUM_REGS; regnum++)
704 // OBSOLETE if (frame->fsr.regs[regnum] != 0)
706 // OBSOLETE ULONGEST value;
708 // OBSOLETE value = read_memory_unsigned_integer (frame->fsr.regs[regnum],
709 // OBSOLETE REGISTER_RAW_SIZE (regnum));
710 // OBSOLETE write_register (regnum, value);
713 // OBSOLETE /* Actually cut back the stack. */
714 // OBSOLETE write_register (SP_REGNUM, get_frame_base (frame));
716 // OBSOLETE /* Don't we need to set the PC?!? XXX FIXME. */
719 // OBSOLETE /* Throw away any cached frame information. */
720 // OBSOLETE flush_cached_frames ();
723 // OBSOLETE /* Function: push_arguments
724 // OBSOLETE Setup arguments for a call to the target. Arguments go in
725 // OBSOLETE order on the stack. */
727 // OBSOLETE CORE_ADDR
728 // OBSOLETE mn10200_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
729 // OBSOLETE unsigned char struct_return, CORE_ADDR struct_addr)
731 // OBSOLETE int argnum = 0;
732 // OBSOLETE int len = 0;
733 // OBSOLETE int stack_offset = 0;
734 // OBSOLETE int regsused = struct_return ? 1 : 0;
736 // OBSOLETE /* This should be a nop, but align the stack just in case something
737 // OBSOLETE went wrong. Stacks are two byte aligned on the mn10200. */
738 // OBSOLETE sp &= ~1;
740 // OBSOLETE /* Now make space on the stack for the args.
742 // OBSOLETE XXX This doesn't appear to handle pass-by-invisible reference
743 // OBSOLETE arguments. */
744 // OBSOLETE for (argnum = 0; argnum < nargs; argnum++)
746 // OBSOLETE int arg_length = (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 1) & ~1;
748 // OBSOLETE /* If we've used all argument registers, then this argument is
749 // OBSOLETE pushed. */
750 // OBSOLETE if (regsused >= 2 || arg_length > 4)
752 // OBSOLETE regsused = 2;
753 // OBSOLETE len += arg_length;
755 // OBSOLETE /* We know we've got some arg register space left. If this argument
756 // OBSOLETE will fit entirely in regs, then put it there. */
757 // OBSOLETE else if (arg_length <= 2
758 // OBSOLETE || TYPE_CODE (VALUE_TYPE (args[argnum])) == TYPE_CODE_PTR)
760 // OBSOLETE regsused++;
762 // OBSOLETE else if (regsused == 0)
764 // OBSOLETE regsused = 2;
768 // OBSOLETE regsused = 2;
769 // OBSOLETE len += arg_length;
773 // OBSOLETE /* Allocate stack space. */
774 // OBSOLETE sp -= len;
776 // OBSOLETE regsused = struct_return ? 1 : 0;
777 // OBSOLETE /* Push all arguments onto the stack. */
778 // OBSOLETE for (argnum = 0; argnum < nargs; argnum++)
781 // OBSOLETE char *val;
783 // OBSOLETE /* XXX Check this. What about UNIONS? */
784 // OBSOLETE if (TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_STRUCT
785 // OBSOLETE && TYPE_LENGTH (VALUE_TYPE (*args)) > 8)
787 // OBSOLETE /* XXX Wrong, we want a pointer to this argument. */
788 // OBSOLETE len = TYPE_LENGTH (VALUE_TYPE (*args));
789 // OBSOLETE val = (char *) VALUE_CONTENTS (*args);
793 // OBSOLETE len = TYPE_LENGTH (VALUE_TYPE (*args));
794 // OBSOLETE val = (char *) VALUE_CONTENTS (*args);
797 // OBSOLETE if (regsused < 2
798 // OBSOLETE && (len <= 2
799 // OBSOLETE || TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_PTR))
801 // OBSOLETE write_register (regsused, extract_unsigned_integer (val, 4));
802 // OBSOLETE regsused++;
804 // OBSOLETE else if (regsused == 0 && len == 4)
806 // OBSOLETE write_register (regsused, extract_unsigned_integer (val, 2));
807 // OBSOLETE write_register (regsused + 1, extract_unsigned_integer (val + 2, 2));
808 // OBSOLETE regsused = 2;
812 // OBSOLETE regsused = 2;
813 // OBSOLETE while (len > 0)
815 // OBSOLETE write_memory (sp + stack_offset, val, 2);
817 // OBSOLETE len -= 2;
818 // OBSOLETE val += 2;
819 // OBSOLETE stack_offset += 2;
825 // OBSOLETE return sp;
828 // OBSOLETE /* Function: push_return_address (pc)
829 // OBSOLETE Set up the return address for the inferior function call.
830 // OBSOLETE Needed for targets where we don't actually execute a JSR/BSR instruction */
832 // OBSOLETE CORE_ADDR
833 // OBSOLETE mn10200_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
835 // OBSOLETE unsigned char buf[4];
837 // OBSOLETE store_unsigned_integer (buf, 4, CALL_DUMMY_ADDRESS ());
838 // OBSOLETE write_memory (sp - 4, buf, 4);
839 // OBSOLETE return sp - 4;
842 // OBSOLETE /* Function: store_struct_return (addr,sp)
843 // OBSOLETE Store the structure value return address for an inferior function
846 // OBSOLETE CORE_ADDR
847 // OBSOLETE mn10200_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
849 // OBSOLETE /* The structure return address is passed as the first argument. */
850 // OBSOLETE write_register (0, addr);
851 // OBSOLETE return sp;
854 // OBSOLETE /* Function: frame_saved_pc
855 // OBSOLETE Find the caller of this frame. We do this by seeing if RP_REGNUM
856 // OBSOLETE is saved in the stack anywhere, otherwise we get it from the
857 // OBSOLETE registers. If the inner frame is a dummy frame, return its PC
858 // OBSOLETE instead of RP, because that's where "caller" of the dummy-frame
859 // OBSOLETE will be found. */
861 // OBSOLETE CORE_ADDR
862 // OBSOLETE mn10200_frame_saved_pc (struct frame_info *fi)
864 // OBSOLETE /* The saved PC will always be at the base of the current frame. */
865 // OBSOLETE return (read_memory_integer (get_frame_base (fi), REGISTER_SIZE) & 0xffffff);
868 // OBSOLETE /* Function: init_extra_frame_info
869 // OBSOLETE Setup the frame's frame pointer, pc, and frame addresses for saved
870 // OBSOLETE registers. Most of the work is done in mn10200_analyze_prologue().
872 // OBSOLETE Note that when we are called for the last frame (currently active frame),
873 // OBSOLETE that get_frame_pc (fi) and fi->frame will already be setup. However, fi->frame will
874 // OBSOLETE be valid only if this routine uses FP. For previous frames, fi-frame will
875 // OBSOLETE always be correct. mn10200_analyze_prologue will fix fi->frame if
876 // OBSOLETE it's not valid.
878 // OBSOLETE We can be called with the PC in the call dummy under two circumstances.
879 // OBSOLETE First, during normal backtracing, second, while figuring out the frame
880 // OBSOLETE pointer just prior to calling the target function (see run_stack_dummy). */
883 // OBSOLETE mn10200_init_extra_frame_info (struct frame_info *fi)
885 // OBSOLETE if (get_next_frame (fi))
886 // OBSOLETE deprecated_update_frame_pc_hack (fi, FRAME_SAVED_PC (get_next_frame (fi)));
888 // OBSOLETE memset (fi->fsr.regs, '\000', sizeof fi->fsr.regs);
889 // OBSOLETE fi->status = 0;
890 // OBSOLETE fi->stack_size = 0;
892 // OBSOLETE mn10200_analyze_prologue (fi, 0);
896 // OBSOLETE _initialize_mn10200_tdep (void)
898 // OBSOLETE tm_print_insn = print_insn_mn10200;
This page took 0.051606 seconds and 4 git commands to generate.