f884f054652d465e4c20c8cd9784ff659985c86b
[deliverable/binutils-gdb.git] / gdb / mn10300-tdep.c
1 /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
2 Copyright 1996, 1997, 1998 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22 #include "frame.h"
23 #include "inferior.h"
24 #include "obstack.h"
25 #include "target.h"
26 #include "value.h"
27 #include "bfd.h"
28 #include "gdb_string.h"
29 #include "gdbcore.h"
30 #include "symfile.h"
31
32 extern void _initialize_mn10300_tdep (void);
33 static CORE_ADDR mn10300_analyze_prologue PARAMS ((struct frame_info * fi,
34 CORE_ADDR pc));
35
36 /* Additional info used by the frame */
37
38 struct frame_extra_info
39 {
40 int status;
41 int stack_size;
42 };
43
44
45 static char *mn10300_generic_register_names[] =
46 {"d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
47 "sp", "pc", "mdr", "psw", "lir", "lar", "", "",
48 "", "", "", "", "", "", "", "",
49 "", "", "", "", "", "", "", "fp"};
50
51 static char **mn10300_register_names = mn10300_generic_register_names;
52
53 char *
54 mn10300_register_name (i)
55 int i;
56 {
57 return mn10300_register_names[i];
58 }
59
60 CORE_ADDR
61 mn10300_saved_pc_after_call (fi)
62 struct frame_info *fi;
63 {
64 return read_memory_integer (read_register (SP_REGNUM), 4);
65 }
66
67 void
68 mn10300_extract_return_value (type, regbuf, valbuf)
69 struct type *type;
70 char *regbuf;
71 char *valbuf;
72 {
73 if (TYPE_CODE (type) == TYPE_CODE_PTR)
74 memcpy (valbuf, regbuf + REGISTER_BYTE (4), TYPE_LENGTH (type));
75 else
76 memcpy (valbuf, regbuf + REGISTER_BYTE (0), TYPE_LENGTH (type));
77 }
78
79 CORE_ADDR
80 mn10300_extract_struct_value_address (regbuf)
81 char *regbuf;
82 {
83 return extract_address (regbuf + REGISTER_BYTE (4),
84 REGISTER_RAW_SIZE (4));
85 }
86
87 void
88 mn10300_store_return_value (type, valbuf)
89 struct type *type;
90 char *valbuf;
91 {
92 if (TYPE_CODE (type) == TYPE_CODE_PTR)
93 write_register_bytes (REGISTER_BYTE (4), valbuf, TYPE_LENGTH (type));
94 else
95 write_register_bytes (REGISTER_BYTE (0), valbuf, TYPE_LENGTH (type));
96 }
97
98 static struct frame_info *analyze_dummy_frame PARAMS ((CORE_ADDR, CORE_ADDR));
99 static struct frame_info *
100 analyze_dummy_frame (pc, frame)
101 CORE_ADDR pc;
102 CORE_ADDR frame;
103 {
104 static struct frame_info *dummy = NULL;
105 if (dummy == NULL)
106 {
107 dummy = xmalloc (sizeof (struct frame_info));
108 dummy->saved_regs = xmalloc (SIZEOF_FRAME_SAVED_REGS);
109 dummy->extra_info = xmalloc (sizeof (struct frame_extra_info));
110 }
111 dummy->next = NULL;
112 dummy->prev = NULL;
113 dummy->pc = pc;
114 dummy->frame = frame;
115 dummy->extra_info->status = 0;
116 dummy->extra_info->stack_size = 0;
117 memset (dummy->saved_regs, '\000', SIZEOF_FRAME_SAVED_REGS);
118 mn10300_analyze_prologue (dummy, 0);
119 return dummy;
120 }
121
122 /* Values for frame_info.status */
123
124 #define MY_FRAME_IN_SP 0x1
125 #define MY_FRAME_IN_FP 0x2
126 #define NO_MORE_FRAMES 0x4
127
128
129 /* Should call_function allocate stack space for a struct return? */
130 int
131 mn10300_use_struct_convention (gcc_p, type)
132 int gcc_p;
133 struct type *type;
134 {
135 return (TYPE_NFIELDS (type) > 1 || TYPE_LENGTH (type) > 8);
136 }
137
138 /* The breakpoint instruction must be the same size as the smallest
139 instruction in the instruction set.
140
141 The Matsushita mn10x00 processors have single byte instructions
142 so we need a single byte breakpoint. Matsushita hasn't defined
143 one, so we defined it ourselves. */
144
145 unsigned char *
146 mn10300_breakpoint_from_pc (bp_addr, bp_size)
147 CORE_ADDR *bp_addr;
148 int *bp_size;
149 {
150 static char breakpoint[] =
151 {0xff};
152 *bp_size = 1;
153 return breakpoint;
154 }
155
156
157 /* Fix fi->frame if it's bogus at this point. This is a helper
158 function for mn10300_analyze_prologue. */
159
160 static void
161 fix_frame_pointer (fi, stack_size)
162 struct frame_info *fi;
163 int stack_size;
164 {
165 if (fi && fi->next == NULL)
166 {
167 if (fi->extra_info->status & MY_FRAME_IN_SP)
168 fi->frame = read_sp () - stack_size;
169 else if (fi->extra_info->status & MY_FRAME_IN_FP)
170 fi->frame = read_register (A3_REGNUM);
171 }
172 }
173
174
175 /* Set offsets of registers saved by movm instruction.
176 This is a helper function for mn10300_analyze_prologue. */
177
178 static void
179 set_movm_offsets (fi, movm_args)
180 struct frame_info *fi;
181 int movm_args;
182 {
183 int offset = 0;
184
185 if (fi == NULL || movm_args == 0)
186 return;
187
188 if (movm_args & 0x10)
189 {
190 fi->saved_regs[A3_REGNUM] = fi->frame + offset;
191 offset += 4;
192 }
193 if (movm_args & 0x20)
194 {
195 fi->saved_regs[A2_REGNUM] = fi->frame + offset;
196 offset += 4;
197 }
198 if (movm_args & 0x40)
199 {
200 fi->saved_regs[D3_REGNUM] = fi->frame + offset;
201 offset += 4;
202 }
203 if (movm_args & 0x80)
204 {
205 fi->saved_regs[D2_REGNUM] = fi->frame + offset;
206 offset += 4;
207 }
208 }
209
210
211 /* The main purpose of this file is dealing with prologues to extract
212 information about stack frames and saved registers.
213
214 For reference here's how prologues look on the mn10300:
215
216 With frame pointer:
217 movm [d2,d3,a2,a3],sp
218 mov sp,a3
219 add <size>,sp
220
221 Without frame pointer:
222 movm [d2,d3,a2,a3],sp (if needed)
223 add <size>,sp
224
225 One day we might keep the stack pointer constant, that won't
226 change the code for prologues, but it will make the frame
227 pointerless case much more common. */
228
229 /* Analyze the prologue to determine where registers are saved,
230 the end of the prologue, etc etc. Return the end of the prologue
231 scanned.
232
233 We store into FI (if non-null) several tidbits of information:
234
235 * stack_size -- size of this stack frame. Note that if we stop in
236 certain parts of the prologue/epilogue we may claim the size of the
237 current frame is zero. This happens when the current frame has
238 not been allocated yet or has already been deallocated.
239
240 * fsr -- Addresses of registers saved in the stack by this frame.
241
242 * status -- A (relatively) generic status indicator. It's a bitmask
243 with the following bits:
244
245 MY_FRAME_IN_SP: The base of the current frame is actually in
246 the stack pointer. This can happen for frame pointerless
247 functions, or cases where we're stopped in the prologue/epilogue
248 itself. For these cases mn10300_analyze_prologue will need up
249 update fi->frame before returning or analyzing the register
250 save instructions.
251
252 MY_FRAME_IN_FP: The base of the current frame is in the
253 frame pointer register ($a2).
254
255 NO_MORE_FRAMES: Set this if the current frame is "start" or
256 if the first instruction looks like mov <imm>,sp. This tells
257 frame chain to not bother trying to unwind past this frame. */
258
259 static CORE_ADDR
260 mn10300_analyze_prologue (fi, pc)
261 struct frame_info *fi;
262 CORE_ADDR pc;
263 {
264 CORE_ADDR func_addr, func_end, addr, stop;
265 CORE_ADDR stack_size;
266 int imm_size;
267 unsigned char buf[4];
268 int status, movm_args = 0;
269 char *name;
270
271 /* Use the PC in the frame if it's provided to look up the
272 start of this function. */
273 pc = (fi ? fi->pc : pc);
274
275 /* Find the start of this function. */
276 status = find_pc_partial_function (pc, &name, &func_addr, &func_end);
277
278 /* Do nothing if we couldn't find the start of this function or if we're
279 stopped at the first instruction in the prologue. */
280 if (status == 0)
281 {
282 return pc;
283 }
284
285 /* If we're in start, then give up. */
286 if (strcmp (name, "start") == 0)
287 {
288 if (fi != NULL)
289 fi->extra_info->status = NO_MORE_FRAMES;
290 return pc;
291 }
292
293 /* At the start of a function our frame is in the stack pointer. */
294 if (fi)
295 fi->extra_info->status = MY_FRAME_IN_SP;
296
297 /* Get the next two bytes into buf, we need two because rets is a two
298 byte insn and the first isn't enough to uniquely identify it. */
299 status = read_memory_nobpt (pc, buf, 2);
300 if (status != 0)
301 return pc;
302
303 /* If we're physically on an "rets" instruction, then our frame has
304 already been deallocated. Note this can also be true for retf
305 and ret if they specify a size of zero.
306
307 In this case fi->frame is bogus, we need to fix it. */
308 if (fi && buf[0] == 0xf0 && buf[1] == 0xfc)
309 {
310 if (fi->next == NULL)
311 fi->frame = read_sp ();
312 return fi->pc;
313 }
314
315 /* Similarly if we're stopped on the first insn of a prologue as our
316 frame hasn't been allocated yet. */
317 if (fi && fi->pc == func_addr)
318 {
319 if (fi->next == NULL)
320 fi->frame = read_sp ();
321 return fi->pc;
322 }
323
324 /* Figure out where to stop scanning. */
325 stop = fi ? fi->pc : func_end;
326
327 /* Don't walk off the end of the function. */
328 stop = stop > func_end ? func_end : stop;
329
330 /* Start scanning on the first instruction of this function. */
331 addr = func_addr;
332
333 /* Suck in two bytes. */
334 status = read_memory_nobpt (addr, buf, 2);
335 if (status != 0)
336 {
337 fix_frame_pointer (fi, 0);
338 return addr;
339 }
340
341 /* First see if this insn sets the stack pointer; if so, it's something
342 we won't understand, so quit now. */
343 if (buf[0] == 0xf2 && (buf[1] & 0xf3) == 0xf0)
344 {
345 if (fi)
346 fi->extra_info->status = NO_MORE_FRAMES;
347 return addr;
348 }
349
350 /* Now look for movm [regs],sp, which saves the callee saved registers.
351
352 At this time we don't know if fi->frame is valid, so we only note
353 that we encountered a movm instruction. Later, we'll set the entries
354 in fsr.regs as needed. */
355 if (buf[0] == 0xcf)
356 {
357 /* Extract the register list for the movm instruction. */
358 status = read_memory_nobpt (addr + 1, buf, 1);
359 movm_args = *buf;
360
361 addr += 2;
362
363 /* Quit now if we're beyond the stop point. */
364 if (addr >= stop)
365 {
366 /* Fix fi->frame since it's bogus at this point. */
367 if (fi && fi->next == NULL)
368 fi->frame = read_sp ();
369
370 /* Note if/where callee saved registers were saved. */
371 set_movm_offsets (fi, movm_args);
372 return addr;
373 }
374
375 /* Get the next two bytes so the prologue scan can continue. */
376 status = read_memory_nobpt (addr, buf, 2);
377 if (status != 0)
378 {
379 /* Fix fi->frame since it's bogus at this point. */
380 if (fi && fi->next == NULL)
381 fi->frame = read_sp ();
382
383 /* Note if/where callee saved registers were saved. */
384 set_movm_offsets (fi, movm_args);
385 return addr;
386 }
387 }
388
389 /* Now see if we set up a frame pointer via "mov sp,a3" */
390 if (buf[0] == 0x3f)
391 {
392 addr += 1;
393
394 /* The frame pointer is now valid. */
395 if (fi)
396 {
397 fi->extra_info->status |= MY_FRAME_IN_FP;
398 fi->extra_info->status &= ~MY_FRAME_IN_SP;
399 }
400
401 /* Quit now if we're beyond the stop point. */
402 if (addr >= stop)
403 {
404 /* Fix fi->frame if it's bogus at this point. */
405 fix_frame_pointer (fi, 0);
406
407 /* Note if/where callee saved registers were saved. */
408 set_movm_offsets (fi, movm_args);
409 return addr;
410 }
411
412 /* Get two more bytes so scanning can continue. */
413 status = read_memory_nobpt (addr, buf, 2);
414 if (status != 0)
415 {
416 /* Fix fi->frame if it's bogus at this point. */
417 fix_frame_pointer (fi, 0);
418
419 /* Note if/where callee saved registers were saved. */
420 set_movm_offsets (fi, movm_args);
421 return addr;
422 }
423 }
424
425 /* Next we should allocate the local frame. No more prologue insns
426 are found after allocating the local frame.
427
428 Search for add imm8,sp (0xf8feXX)
429 or add imm16,sp (0xfafeXXXX)
430 or add imm32,sp (0xfcfeXXXXXXXX).
431
432 If none of the above was found, then this prologue has no
433 additional stack. */
434
435 status = read_memory_nobpt (addr, buf, 2);
436 if (status != 0)
437 {
438 /* Fix fi->frame if it's bogus at this point. */
439 fix_frame_pointer (fi, 0);
440
441 /* Note if/where callee saved registers were saved. */
442 set_movm_offsets (fi, movm_args);
443 return addr;
444 }
445
446 imm_size = 0;
447 if (buf[0] == 0xf8 && buf[1] == 0xfe)
448 imm_size = 1;
449 else if (buf[0] == 0xfa && buf[1] == 0xfe)
450 imm_size = 2;
451 else if (buf[0] == 0xfc && buf[1] == 0xfe)
452 imm_size = 4;
453
454 if (imm_size != 0)
455 {
456 /* Suck in imm_size more bytes, they'll hold the size of the
457 current frame. */
458 status = read_memory_nobpt (addr + 2, buf, imm_size);
459 if (status != 0)
460 {
461 /* Fix fi->frame if it's bogus at this point. */
462 fix_frame_pointer (fi, 0);
463
464 /* Note if/where callee saved registers were saved. */
465 set_movm_offsets (fi, movm_args);
466 return addr;
467 }
468
469 /* Note the size of the stack in the frame info structure. */
470 stack_size = extract_signed_integer (buf, imm_size);
471 if (fi)
472 fi->extra_info->stack_size = stack_size;
473
474 /* We just consumed 2 + imm_size bytes. */
475 addr += 2 + imm_size;
476
477 /* No more prologue insns follow, so begin preparation to return. */
478 /* Fix fi->frame if it's bogus at this point. */
479 fix_frame_pointer (fi, stack_size);
480
481 /* Note if/where callee saved registers were saved. */
482 set_movm_offsets (fi, movm_args);
483 return addr;
484 }
485
486 /* We never found an insn which allocates local stack space, regardless
487 this is the end of the prologue. */
488 /* Fix fi->frame if it's bogus at this point. */
489 fix_frame_pointer (fi, 0);
490
491 /* Note if/where callee saved registers were saved. */
492 set_movm_offsets (fi, movm_args);
493 return addr;
494 }
495
496 /* Function: frame_chain
497 Figure out and return the caller's frame pointer given current
498 frame_info struct.
499
500 We don't handle dummy frames yet but we would probably just return the
501 stack pointer that was in use at the time the function call was made? */
502
503 CORE_ADDR
504 mn10300_frame_chain (fi)
505 struct frame_info *fi;
506 {
507 struct frame_info *dummy;
508 /* Walk through the prologue to determine the stack size,
509 location of saved registers, end of the prologue, etc. */
510 if (fi->extra_info->status == 0)
511 mn10300_analyze_prologue (fi, (CORE_ADDR) 0);
512
513 /* Quit now if mn10300_analyze_prologue set NO_MORE_FRAMES. */
514 if (fi->extra_info->status & NO_MORE_FRAMES)
515 return 0;
516
517 /* Now that we've analyzed our prologue, determine the frame
518 pointer for our caller.
519
520 If our caller has a frame pointer, then we need to
521 find the entry value of $a3 to our function.
522
523 If fsr.regs[A3_REGNUM] is nonzero, then it's at the memory
524 location pointed to by fsr.regs[A3_REGNUM].
525
526 Else it's still in $a3.
527
528 If our caller does not have a frame pointer, then his
529 frame base is fi->frame + -caller's stack size. */
530
531 /* The easiest way to get that info is to analyze our caller's frame.
532 So we set up a dummy frame and call mn10300_analyze_prologue to
533 find stuff for us. */
534 dummy = analyze_dummy_frame (FRAME_SAVED_PC (fi), fi->frame);
535
536 if (dummy->extra_info->status & MY_FRAME_IN_FP)
537 {
538 /* Our caller has a frame pointer. So find the frame in $a3 or
539 in the stack. */
540 if (fi->saved_regs[A3_REGNUM])
541 return (read_memory_integer (fi->saved_regs[A3_REGNUM], REGISTER_SIZE));
542 else
543 return read_register (A3_REGNUM);
544 }
545 else
546 {
547 int adjust = 0;
548
549 adjust += (fi->saved_regs[D2_REGNUM] ? 4 : 0);
550 adjust += (fi->saved_regs[D3_REGNUM] ? 4 : 0);
551 adjust += (fi->saved_regs[A2_REGNUM] ? 4 : 0);
552 adjust += (fi->saved_regs[A3_REGNUM] ? 4 : 0);
553
554 /* Our caller does not have a frame pointer. So his frame starts
555 at the base of our frame (fi->frame) + register save space
556 + <his size>. */
557 return fi->frame + adjust + -dummy->extra_info->stack_size;
558 }
559 }
560
561 /* Function: skip_prologue
562 Return the address of the first inst past the prologue of the function. */
563
564 CORE_ADDR
565 mn10300_skip_prologue (pc)
566 CORE_ADDR pc;
567 {
568 /* We used to check the debug symbols, but that can lose if
569 we have a null prologue. */
570 return mn10300_analyze_prologue (NULL, pc);
571 }
572
573
574 /* Function: pop_frame
575 This routine gets called when either the user uses the `return'
576 command, or the call dummy breakpoint gets hit. */
577
578 void
579 mn10300_pop_frame (frame)
580 struct frame_info *frame;
581 {
582 int regnum;
583
584 if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
585 generic_pop_dummy_frame ();
586 else
587 {
588 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
589
590 /* Restore any saved registers. */
591 for (regnum = 0; regnum < NUM_REGS; regnum++)
592 if (frame->saved_regs[regnum] != 0)
593 {
594 ULONGEST value;
595
596 value = read_memory_unsigned_integer (frame->saved_regs[regnum],
597 REGISTER_RAW_SIZE (regnum));
598 write_register (regnum, value);
599 }
600
601 /* Actually cut back the stack. */
602 write_register (SP_REGNUM, FRAME_FP (frame));
603
604 /* Don't we need to set the PC?!? XXX FIXME. */
605 }
606
607 /* Throw away any cached frame information. */
608 flush_cached_frames ();
609 }
610
611 /* Function: push_arguments
612 Setup arguments for a call to the target. Arguments go in
613 order on the stack. */
614
615 CORE_ADDR
616 mn10300_push_arguments (nargs, args, sp, struct_return, struct_addr)
617 int nargs;
618 value_ptr *args;
619 CORE_ADDR sp;
620 unsigned char struct_return;
621 CORE_ADDR struct_addr;
622 {
623 int argnum = 0;
624 int len = 0;
625 int stack_offset = 0;
626 int regsused = struct_return ? 1 : 0;
627
628 /* This should be a nop, but align the stack just in case something
629 went wrong. Stacks are four byte aligned on the mn10300. */
630 sp &= ~3;
631
632 /* Now make space on the stack for the args.
633
634 XXX This doesn't appear to handle pass-by-invisible reference
635 arguments. */
636 for (argnum = 0; argnum < nargs; argnum++)
637 {
638 int arg_length = (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 3) & ~3;
639
640 while (regsused < 2 && arg_length > 0)
641 {
642 regsused++;
643 arg_length -= 4;
644 }
645 len += arg_length;
646 }
647
648 /* Allocate stack space. */
649 sp -= len;
650
651 regsused = struct_return ? 1 : 0;
652 /* Push all arguments onto the stack. */
653 for (argnum = 0; argnum < nargs; argnum++)
654 {
655 int len;
656 char *val;
657
658 /* XXX Check this. What about UNIONS? */
659 if (TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_STRUCT
660 && TYPE_LENGTH (VALUE_TYPE (*args)) > 8)
661 {
662 /* XXX Wrong, we want a pointer to this argument. */
663 len = TYPE_LENGTH (VALUE_TYPE (*args));
664 val = (char *) VALUE_CONTENTS (*args);
665 }
666 else
667 {
668 len = TYPE_LENGTH (VALUE_TYPE (*args));
669 val = (char *) VALUE_CONTENTS (*args);
670 }
671
672 while (regsused < 2 && len > 0)
673 {
674 write_register (regsused, extract_unsigned_integer (val, 4));
675 val += 4;
676 len -= 4;
677 regsused++;
678 }
679
680 while (len > 0)
681 {
682 write_memory (sp + stack_offset, val, 4);
683 len -= 4;
684 val += 4;
685 stack_offset += 4;
686 }
687
688 args++;
689 }
690
691 /* Make space for the flushback area. */
692 sp -= 8;
693 return sp;
694 }
695
696 /* Function: push_return_address (pc)
697 Set up the return address for the inferior function call.
698 Needed for targets where we don't actually execute a JSR/BSR instruction */
699
700 CORE_ADDR
701 mn10300_push_return_address (pc, sp)
702 CORE_ADDR pc;
703 CORE_ADDR sp;
704 {
705 unsigned char buf[4];
706
707 store_unsigned_integer (buf, 4, CALL_DUMMY_ADDRESS ());
708 write_memory (sp - 4, buf, 4);
709 return sp - 4;
710 }
711
712 /* Function: store_struct_return (addr,sp)
713 Store the structure value return address for an inferior function
714 call. */
715
716 CORE_ADDR
717 mn10300_store_struct_return (addr, sp)
718 CORE_ADDR addr;
719 CORE_ADDR sp;
720 {
721 /* The structure return address is passed as the first argument. */
722 write_register (0, addr);
723 return sp;
724 }
725
726 /* Function: frame_saved_pc
727 Find the caller of this frame. We do this by seeing if RP_REGNUM
728 is saved in the stack anywhere, otherwise we get it from the
729 registers. If the inner frame is a dummy frame, return its PC
730 instead of RP, because that's where "caller" of the dummy-frame
731 will be found. */
732
733 CORE_ADDR
734 mn10300_frame_saved_pc (fi)
735 struct frame_info *fi;
736 {
737 int adjust = 0;
738
739 adjust += (fi->saved_regs[D2_REGNUM] ? 4 : 0);
740 adjust += (fi->saved_regs[D3_REGNUM] ? 4 : 0);
741 adjust += (fi->saved_regs[A2_REGNUM] ? 4 : 0);
742 adjust += (fi->saved_regs[A3_REGNUM] ? 4 : 0);
743
744 return (read_memory_integer (fi->frame + adjust, REGISTER_SIZE));
745 }
746
747 /* Function: mn10300_init_extra_frame_info
748 Setup the frame's frame pointer, pc, and frame addresses for saved
749 registers. Most of the work is done in mn10300_analyze_prologue().
750
751 Note that when we are called for the last frame (currently active frame),
752 that fi->pc and fi->frame will already be setup. However, fi->frame will
753 be valid only if this routine uses FP. For previous frames, fi-frame will
754 always be correct. mn10300_analyze_prologue will fix fi->frame if
755 it's not valid.
756
757 We can be called with the PC in the call dummy under two circumstances.
758 First, during normal backtracing, second, while figuring out the frame
759 pointer just prior to calling the target function (see run_stack_dummy). */
760
761 void
762 mn10300_init_extra_frame_info (fi)
763 struct frame_info *fi;
764 {
765 if (fi->next)
766 fi->pc = FRAME_SAVED_PC (fi->next);
767
768 frame_saved_regs_zalloc (fi);
769 fi->extra_info = (struct frame_extra_info *)
770 frame_obstack_alloc (sizeof (struct frame_extra_info));
771
772 fi->extra_info->status = 0;
773 fi->extra_info->stack_size = 0;
774
775 mn10300_analyze_prologue (fi, 0);
776 }
777
778 /* Function: mn10300_virtual_frame_pointer
779 Return the register that the function uses for a frame pointer,
780 plus any necessary offset to be applied to the register before
781 any frame pointer offsets. */
782
783 void
784 mn10300_virtual_frame_pointer (pc, reg, offset)
785 CORE_ADDR pc;
786 long *reg;
787 long *offset;
788 {
789 struct frame_info *dummy = analyze_dummy_frame (pc, 0);
790 /* Set up a dummy frame_info, Analyze the prolog and fill in the
791 extra info. */
792 /* Results will tell us which type of frame it uses. */
793 if (dummy->extra_info->status & MY_FRAME_IN_SP)
794 {
795 *reg = SP_REGNUM;
796 *offset = -(dummy->extra_info->stack_size);
797 }
798 else
799 {
800 *reg = A3_REGNUM;
801 *offset = 0;
802 }
803 }
804
805 /* This can be made more generic later. */
806 static void
807 set_machine_hook (filename)
808 char *filename;
809 {
810 int i;
811
812 if (bfd_get_mach (exec_bfd) == bfd_mach_mn10300
813 || bfd_get_mach (exec_bfd) == 0)
814 {
815 mn10300_register_names = mn10300_generic_register_names;
816 }
817
818 }
819
820 void
821 _initialize_mn10300_tdep ()
822 {
823 /* printf("_initialize_mn10300_tdep\n"); */
824
825 tm_print_insn = print_insn_mn10300;
826
827 specify_exec_file_hook (set_machine_hook);
828 }
This page took 0.049127 seconds and 3 git commands to generate.