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