]> Git Repo - binutils.git/blame - gdb/m88k-tdep.c
ansi name abuse changes
[binutils.git] / gdb / m88k-tdep.c
CommitLineData
ea3c0839
JG
1/* Target-machine dependent code for Motorola 88000 series, for GDB.
2 Copyright (C) 1988, 1990, 1991 Free Software Foundation, Inc.
8aa13b87
JK
3
4This file is part of GDB.
5
99a7de40 6This program is free software; you can redistribute it and/or modify
8aa13b87 7it under the terms of the GNU General Public License as published by
99a7de40
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
8aa13b87 10
99a7de40 11This program is distributed in the hope that it will be useful,
8aa13b87
JK
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
99a7de40
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
8aa13b87
JK
19
20#include <stdio.h>
21#include "defs.h"
22#include "param.h"
23#include "frame.h"
24#include "inferior.h"
25#include "value.h"
26
27#ifdef USG
28#include <sys/types.h>
29#endif
30
31#include <sys/param.h>
32#include <sys/dir.h>
33#include <signal.h>
34#include "gdbcore.h"
35#include <sys/user.h>
36#ifndef USER /* added to support BCS ptrace_user */
37
38#define USER ptrace_user
39#endif
40#include <sys/ioctl.h>
41#include <fcntl.h>
42
8aa13b87
JK
43#include <sys/file.h>
44#include <sys/stat.h>
45
46#include "symtab.h"
47#include "setjmp.h"
48#include "value.h"
49
ea3c0839 50void frame_find_saved_regs ();
8aa13b87 51
ea3c0839
JG
52
53/* Given a GDB frame, determine the address of the calling function's frame.
54 This will be used to create a new GDB frame struct, and then
55 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
56
57 For us, the frame address is its stack pointer value, so we look up
58 the function prologue to determine the caller's sp value, and return it. */
59
60FRAME_ADDR
61frame_chain (thisframe)
62 FRAME thisframe;
8aa13b87 63{
8aa13b87 64
ea3c0839
JG
65 frame_find_saved_regs (thisframe, (struct frame_saved_regs *) 0);
66 /* NOTE: this depends on frame_find_saved_regs returning the VALUE, not
67 the ADDRESS, of SP_REGNUM. It also depends on the cache of
68 frame_find_saved_regs results. */
69 if (thisframe->fsr->regs[SP_REGNUM])
70 return thisframe->fsr->regs[SP_REGNUM];
71 else
72 return thisframe->frame; /* Leaf fn -- next frame up has same SP. */
73}
8aa13b87 74
ea3c0839
JG
75int
76frameless_function_invocation (frame)
77 FRAME frame;
8aa13b87 78{
ea3c0839
JG
79
80 frame_find_saved_regs (frame, (struct frame_saved_regs *) 0);
81 /* NOTE: this depends on frame_find_saved_regs returning the VALUE, not
82 the ADDRESS, of SP_REGNUM. It also depends on the cache of
83 frame_find_saved_regs results. */
84 if (frame->fsr->regs[SP_REGNUM])
85 return 0; /* Frameful -- return addr saved somewhere */
8aa13b87 86 else
ea3c0839 87 return 1; /* Frameless -- no saved return address */
8aa13b87
JK
88}
89
ea3c0839
JG
90int
91frame_chain_valid (chain, thisframe)
92 CORE_ADDR chain;
93 struct frame_info *thisframe;
8aa13b87 94{
ea3c0839
JG
95 return (chain != 0
96 && outside_startup_file (FRAME_SAVED_PC (thisframe)));
8aa13b87
JK
97}
98
ea3c0839
JG
99CORE_ADDR
100frame_chain_combine (chain, thisframe)
101 CORE_ADDR chain;
102{
103 return chain;
104}
8aa13b87 105
ea3c0839
JG
106void
107init_extra_frame_info (fromleaf, fi)
108 int fromleaf;
109 struct frame_info *fi;
110{
111 fi->fsr = 0; /* Not yet allocated */
112 fi->args_pointer = 0; /* Unknown */
113 fi->locals_pointer = 0; /* Unknown */
114}
8aa13b87
JK
115
116void
ea3c0839
JG
117init_frame_pc (fromleaf, prev)
118 int fromleaf;
119 struct frame_info *prev;
8aa13b87 120{
ea3c0839
JG
121 /* FIXME, for now it's the default from blockframe.c. If it stays that
122 way, remove it entirely from here. */
123 prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) :
124 prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
125
126}
127\f
128/* Examine an m88k function prologue, recording the addresses at which
129 registers are saved explicitly by the prologue code, and returning
130 the address of the first instruction after the prologue (but not
131 after the instruction at address LIMIT, as explained below).
132
133 LIMIT places an upper bound on addresses of the instructions to be
134 examined. If the prologue code scan reaches LIMIT, the scan is
135 aborted and LIMIT is returned. This is used, when examining the
136 prologue for the current frame, to keep examine_prologue () from
137 claiming that a given register has been saved when in fact the
138 instruction that saves it has not yet been executed. LIMIT is used
139 at other times to stop the scan when we hit code after the true
140 function prologue (e.g. for the first source line) which might
141 otherwise be mistaken for function prologue.
142
143 The format of the function prologue matched by this routine is
144 derived from examination of the source to gcc 1.95, particularly
145 the routine output_prologue () in config/out-m88k.c.
146
147 subu r31,r31,n # stack pointer update
148
149 (st rn,r31,offset)? # save incoming regs
150 (st.d rn,r31,offset)?
151
152 (addu r30,r31,n)? # frame pointer update
153
154 (pic sequence)? # PIC code prologue
430923f3
JG
155
156 (or rn,rm,0)? # Move parameters to other regs
ea3c0839
JG
157*/
158
159/* Macros for extracting fields from instructions. */
160
161#define BITMASK(pos, width) (((0x1 << (width)) - 1) << (pos))
162#define EXTRACT_FIELD(val, pos, width) ((val) >> (pos) & BITMASK (0, width))
163
164/* Prologue code that handles position-independent-code setup. */
165
166struct pic_prologue_code {
167 unsigned long insn, mask;
168};
169
170static struct pic_prologue_code pic_prologue_code [] = {
171/* FIXME -- until this is translated to hex, we won't match it... */
172 0xffffffff, 0,
173 /* or r10,r1,0 (if not saved) */
174 /* bsr.n LabN */
175 /* or.u r25,r0,const */
176 /*LabN: or r25,r25,const2 */
177 /* addu r25,r25,1 */
178 /* or r1,r10,0 (if not saved) */
179};
180
181/* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
182 is not the address of a valid instruction, the address of the next
183 instruction beyond ADDR otherwise. *PWORD1 receives the first word
184 of the instruction. PWORD2 is ignored -- a remnant of the original
185 i960 version. */
186
187#define NEXT_PROLOGUE_INSN(addr, lim, pword1, pword2) \
188 (((addr) < (lim)) ? next_insn (addr, pword1) : 0)
189
190/* Read the m88k instruction at 'memaddr' and return the address of
191 the next instruction after that, or 0 if 'memaddr' is not the
192 address of a valid instruction. The instruction
193 is stored at 'pword1'. */
8aa13b87 194
ea3c0839
JG
195CORE_ADDR
196next_insn (memaddr, pword1)
197 unsigned long *pword1;
198 CORE_ADDR memaddr;
8aa13b87 199{
ea3c0839
JG
200 unsigned long buf[1];
201
202 read_memory (memaddr, buf, sizeof (buf));
203 *pword1 = buf[0];
204 SWAP_TARGET_AND_HOST (pword1, sizeof (long));
205
206 return memaddr + 4;
8aa13b87
JK
207}
208
ea3c0839 209/* Read a register from frames called by us (or from the hardware regs). */
8aa13b87 210
ea3c0839
JG
211int
212read_next_frame_reg(fi, regno)
213 FRAME fi;
214 int regno;
8aa13b87 215{
ea3c0839
JG
216 for (; fi; fi = fi->next) {
217 if (regno == SP_REGNUM) return fi->frame;
218 else if (fi->fsr->regs[regno])
219 return read_memory_integer(fi->fsr->regs[regno], 4);
220 }
221 return read_register(regno);
8aa13b87 222}
8aa13b87 223
ea3c0839
JG
224/* Examine the prologue of a function. `ip' points to the first instruction.
225 `limit' is the limit of the prologue (e.g. the addr of the first
226 linenumber, or perhaps the program counter if we're stepping through).
227 `frame_sp' is the stack pointer value in use in this frame.
228 `fsr' is a pointer to a frame_saved_regs structure into which we put
229 info about the registers saved by this frame.
230 `fi' is a struct frame_info pointer; we fill in various fields in it
231 to reflect the offsets of the arg pointer and the locals pointer. */
232
233static CORE_ADDR
234examine_prologue (ip, limit, frame_sp, fsr, fi)
235 register CORE_ADDR ip;
236 register CORE_ADDR limit;
237 FRAME_ADDR frame_sp;
238 struct frame_saved_regs *fsr;
239 struct frame_info *fi;
240{
241 register CORE_ADDR next_ip;
242 register int src;
243 register struct pic_prologue_code *pcode;
244 unsigned int insn1, insn2;
245 int size, offset;
246 char must_adjust[32]; /* If set, must adjust offsets in fsr */
247 int sp_offset = -1; /* -1 means not set (valid must be mult of 8) */
248 int fp_offset = -1; /* -1 means not set */
249 CORE_ADDR frame_fp;
250
251 bzero (must_adjust, sizeof (must_adjust));
252 next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
253
653d6c56
JG
254 /* Accept move of incoming registers to other registers, using
255 "or rd,rs,0" or "or.u rd,rs,0" or "or rd,r0,rs" or "or rd,rs,r0".
256 We don't have to worry about walking into the first lines of code,
257 since the first line number will stop us (assuming we have symbols).
258 What we have actually seen is "or r10,r0,r12". */
259
260#define OR_MOVE_INSN 0x58000000 /* or/or.u with immed of 0 */
261#define OR_MOVE_MASK 0xF800FFFF
262#define OR_REG_MOVE1_INSN 0xF4005800 /* or rd,r0,rs */
263#define OR_REG_MOVE1_MASK 0xFC1FFFE0
264#define OR_REG_MOVE2_INSN 0xF4005800 /* or rd,rs,r0 */
265#define OR_REG_MOVE2_MASK 0xFC00FFFF
266 while (next_ip &&
267 ((insn1 & OR_MOVE_MASK) == OR_MOVE_INSN ||
268 (insn1 & OR_REG_MOVE1_MASK) == OR_REG_MOVE1_INSN ||
269 (insn1 & OR_REG_MOVE2_MASK) == OR_REG_MOVE2_INSN
270 )
271 )
272 {
273 /* We don't care what moves to where. The result of the moves
274 has already been reflected in what the compiler tells us is the
275 location of these parameters. */
276 ip = next_ip;
277 next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
278 }
279
ea3c0839
JG
280 /* Accept an optional "subu sp,sp,n" to set up the stack pointer. */
281
282#define SUBU_SP_INSN 0x67ff0000
283#define SUBU_SP_MASK 0xffff0007 /* Note offset must be mult. of 8 */
284#define SUBU_OFFSET(x) ((unsigned)(x & 0xFFFF))
285 if (next_ip &&
286 ((insn1 & SUBU_SP_MASK) == SUBU_SP_INSN)) /* subu r31, r31, N */
287 {
288 sp_offset = -SUBU_OFFSET (insn1);
289 ip = next_ip;
290 next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
291 }
292
293 /* The function must start with a stack-pointer adjustment, or
294 we don't know WHAT'S going on... */
295 if (sp_offset == -1)
296 return ip;
297
298 /* Accept zero or more instances of "st rx,sp,n" or "st.d rx,sp,n".
299 This may cause us to mistake the copying of a register
300 parameter to the frame for the saving of a callee-saved
301 register, but that can't be helped, since with the
302 "-fcall-saved" flag, any register can be made callee-saved.
303 This probably doesn't matter, since the ``saved'' caller's values of
304 non-callee-saved registers are not relevant anyway. */
305
306#define STD_STACK_INSN 0x201f0000
307#define STD_STACK_MASK 0xfc1f0000
308#define ST_STACK_INSN 0x241f0000
309#define ST_STACK_MASK 0xfc1f0000
310#define ST_OFFSET(x) ((unsigned)((x) & 0xFFFF))
311#define ST_SRC(x) EXTRACT_FIELD ((x), 21, 5)
312
313 while (next_ip)
314 {
315 if ((insn1 & ST_STACK_MASK) == ST_STACK_INSN)
316 size = 1;
317 else if ((insn1 & STD_STACK_MASK) == STD_STACK_INSN)
318 size = 2;
319 else
320 break;
321
322 src = ST_SRC (insn1);
323 offset = ST_OFFSET (insn1);
324 while (size--)
325 {
326 must_adjust[src] = 1;
327 fsr->regs[src++] = offset; /* Will be adjusted later */
328 offset += 4;
329 }
330 ip = next_ip;
331 next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
332 }
333
334 /* Accept an optional "addu r30,r31,n" to set up the frame pointer. */
335
336#define ADDU_FP_INSN 0x63df0000
337#define ADDU_FP_MASK 0xffff0000
338#define ADDU_OFFSET(x) ((unsigned)(x & 0xFFFF))
339 if (next_ip &&
340 ((insn1 & ADDU_FP_MASK) == ADDU_FP_INSN)) /* addu r30, r31, N */
341 {
342 fp_offset = ADDU_OFFSET (insn1);
343 ip = next_ip;
344 next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
345 }
346
347 /* Accept the PIC prologue code if present. */
348
349 pcode = pic_prologue_code;
350 size = sizeof (pic_prologue_code) / sizeof (*pic_prologue_code);
351 /* If return addr is saved, we don't use first or last insn of PICstuff. */
352 if (fsr->regs[SRP_REGNUM]) {
353 pcode++;
354 size-=2;
355 }
356
357 while (size-- && next_ip && (pcode->insn == (pcode->mask & insn1)))
358 {
359 pcode++;
360 ip = next_ip;
361 next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
362 }
363
430923f3
JG
364 /* Accept moves of parameter registers to other registers, using
365 "or rd,rs,0" or "or.u rd,rs,0" or "or rd,r0,rs" or "or rd,rs,r0".
366 We don't have to worry about walking into the first lines of code,
367 since the first line number will stop us (assuming we have symbols).
368 What gcc actually seems to produce is "or rd,r0,rs". */
369
370#define OR_MOVE_INSN 0x58000000 /* or/or.u with immed of 0 */
371#define OR_MOVE_MASK 0xF800FFFF
372#define OR_REG_MOVE1_INSN 0xF4005800 /* or rd,r0,rs */
373#define OR_REG_MOVE1_MASK 0xFC1FFFE0
374#define OR_REG_MOVE2_INSN 0xF4005800 /* or rd,rs,r0 */
375#define OR_REG_MOVE2_MASK 0xFC00FFFF
376 while (next_ip &&
377 ((insn1 & OR_MOVE_MASK) == OR_MOVE_INSN ||
378 (insn1 & OR_REG_MOVE1_MASK) == OR_REG_MOVE1_INSN ||
379 (insn1 & OR_REG_MOVE2_MASK) == OR_REG_MOVE2_INSN
380 )
381 )
382 {
383 /* We don't care what moves to where. The result of the moves
384 has already been reflected in what the compiler tells us is the
385 location of these parameters. */
386 ip = next_ip;
387 next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
388 }
389
ea3c0839
JG
390 /* We're done with the prologue. If we don't care about the stack
391 frame itself, just return. (Note that fsr->regs has been trashed,
392 but the one caller who calls with fi==0 passes a dummy there.) */
393
394 if (fi == 0)
395 return ip;
396
397 /* OK, now we have:
398 sp_offset original negative displacement of SP
399 fp_offset positive displacement between new SP and new FP, or -1
400 fsr->regs[0..31] offset from original SP where reg is stored
401 must_adjust[0..31] set if corresp. offset was set
402
403 The current SP (frame_sp) might not be the original new SP as set
404 by the function prologue, if alloca has been called. This can
405 only occur if fp_offset is set, though (the compiler allocates an
406 FP when it sees alloca). In that case, we have the FP,
407 and can calculate the original new SP from the FP.
408
409 Then, we figure out where the arguments and locals are, and
410 relocate the offsets in fsr->regs to absolute addresses. */
411
412 if (fp_offset != -1) {
413 /* We have a frame pointer, so get it, and base our calc's on it. */
414 frame_fp = (CORE_ADDR) read_next_frame_reg (fi->next, FP_REGNUM);
415 frame_sp = frame_fp - fp_offset;
416 } else {
417 /* We have no frame pointer, therefore frame_sp is still the same value
418 as set by prologue. But where is the frame itself? */
419 if (must_adjust[SRP_REGNUM]) {
420 /* Function header saved SRP (r1), the return address. Frame starts
421 4 bytes down from where it was saved. */
422 frame_fp = frame_sp + fsr->regs[SRP_REGNUM] - 4;
423 fi->locals_pointer = frame_fp;
424 } else {
425 /* Function header didn't save SRP (r1), so we are in a leaf fn or
426 are otherwise confused. */
427 frame_fp = -1;
428 }
429 }
430
431 /* The locals are relative to the FP (whether it exists as an allocated
432 register, or just as an assumed offset from the SP) */
433 fi->locals_pointer = frame_fp;
434
435 /* The arguments are just above the SP as it was before we adjusted it
436 on entry. */
437 fi->args_pointer = frame_sp - sp_offset;
438
439 /* Now that we know the SP value used by the prologue, we know where
440 it saved all the registers. */
441 for (src = 0; src < 32; src++)
442 if (must_adjust[src])
443 fsr->regs[src] += frame_sp;
444
445 /* The saved value of the SP is always known. */
446 /* (we hope...) */
447 if (fsr->regs[SP_REGNUM] != 0
448 && fsr->regs[SP_REGNUM] != frame_sp - sp_offset)
449 fprintf(stderr, "Bad saved SP value %x != %x, offset %x!\n",
450 fsr->regs[SP_REGNUM],
451 frame_sp - sp_offset, sp_offset);
452
453 fsr->regs[SP_REGNUM] = frame_sp - sp_offset;
8aa13b87 454
ea3c0839
JG
455 return (ip);
456}
8aa13b87 457
ea3c0839
JG
458/* Given an ip value corresponding to the start of a function,
459 return the ip of the first instruction after the function
460 prologue. */
8aa13b87
JK
461
462CORE_ADDR
ea3c0839
JG
463skip_prologue (ip)
464 CORE_ADDR (ip);
8aa13b87 465{
ea3c0839
JG
466 struct frame_saved_regs saved_regs_dummy;
467 struct symtab_and_line sal;
468 CORE_ADDR limit;
8aa13b87 469
ea3c0839
JG
470 sal = find_pc_line (ip, 0);
471 limit = (sal.end) ? sal.end : 0xffffffff;
472
473 return (examine_prologue (ip, limit, (FRAME_ADDR) 0, &saved_regs_dummy,
474 (struct frame_info *)0 ));
475}
476
477/* Put here the code to store, into a struct frame_saved_regs,
478 the addresses of the saved registers of frame described by FRAME_INFO.
479 This includes special registers such as pc and fp saved in special
480 ways in the stack frame. sp is even more special:
481 the address we return for it IS the sp for the next frame.
482
483 We cache the result of doing this in the frame_cache_obstack, since
484 it is fairly expensive. */
485
486void
487frame_find_saved_regs (fi, fsr)
488 struct frame_info *fi;
489 struct frame_saved_regs *fsr;
490{
491 register CORE_ADDR next_addr;
492 register CORE_ADDR *saved_regs;
493 register int regnum;
494 register struct frame_saved_regs *cache_fsr;
495 extern struct obstack frame_cache_obstack;
496 CORE_ADDR ip;
497 struct symtab_and_line sal;
498 CORE_ADDR limit;
499
500 if (!fi->fsr)
8aa13b87 501 {
ea3c0839
JG
502 cache_fsr = (struct frame_saved_regs *)
503 obstack_alloc (&frame_cache_obstack,
504 sizeof (struct frame_saved_regs));
505 bzero (cache_fsr, sizeof (struct frame_saved_regs));
506 fi->fsr = cache_fsr;
507
508 /* Find the start and end of the function prologue. If the PC
509 is in the function prologue, we only consider the part that
510 has executed already. */
511
512 ip = get_pc_function_start (fi->pc);
513 sal = find_pc_line (ip, 0);
514 limit = (sal.end && sal.end < fi->pc) ? sal.end: fi->pc;
515
516 /* This will fill in fields in *fi as well as in cache_fsr. */
517 examine_prologue (ip, limit, fi->frame, cache_fsr, fi);
8aa13b87
JK
518 }
519
ea3c0839
JG
520 if (fsr)
521 *fsr = *fi->fsr;
522}
523
524/* Return the address of the locals block for the frame
525 described by FI. Returns 0 if the address is unknown.
526 NOTE! Frame locals are referred to by negative offsets from the
527 argument pointer, so this is the same as frame_args_address(). */
528
529CORE_ADDR
530frame_locals_address (fi)
531 struct frame_info *fi;
532{
533 register FRAME frame;
534 struct frame_saved_regs fsr;
535 CORE_ADDR ap;
536
537 if (fi->args_pointer) /* Cached value is likely there. */
538 return fi->args_pointer;
539
540 /* Nope, generate it. */
541
542 get_frame_saved_regs (fi, &fsr);
543
544 return fi->args_pointer;
545}
546
547/* Return the address of the argument block for the frame
548 described by FI. Returns 0 if the address is unknown. */
549
550CORE_ADDR
551frame_args_address (fi)
552 struct frame_info *fi;
553{
554 register FRAME frame;
555 struct frame_saved_regs fsr;
556 CORE_ADDR ap;
557
558 if (fi->args_pointer) /* Cached value is likely there. */
559 return fi->args_pointer;
560
561 /* Nope, generate it. */
562
563 get_frame_saved_regs (fi, &fsr);
564
565 return fi->args_pointer;
566}
567
568/* Return the saved PC from this frame.
569
570 If the frame has a memory copy of SRP_REGNUM, use that. If not,
571 just use the register SRP_REGNUM itself. */
572
573CORE_ADDR
574frame_saved_pc (frame)
575 FRAME frame;
576{
577 return read_next_frame_reg(frame, SRP_REGNUM);
8aa13b87
JK
578}
579
ea3c0839 580
8aa13b87
JK
581#if TARGET_BYTE_ORDER != HOST_BYTE_ORDER
582you lose
583#else /* Host and target byte order the same. */
584#define SINGLE_EXP_BITS 8
585#define DOUBLE_EXP_BITS 11
586int
587IEEE_isNAN(fp, len)
588 int *fp, len;
589 /* fp points to a single precision OR double precision
590 * floating point value; len is the number of bytes, either 4 or 8.
591 * Returns 1 iff fp points to a valid IEEE floating point number.
592 * Returns 0 if fp points to a denormalized number or a NaN
593 */
594{
595 int exponent;
596 if (len == 4)
597 {
598 exponent = *fp;
599 exponent = exponent << 1 >> (32 - SINGLE_EXP_BITS - 1);
600 return ((exponent == -1) || (! exponent && *fp));
601 }
602 else if (len == 8)
603 {
604 exponent = *(fp+1);
605 exponent = exponent << 1 >> (32 - DOUBLE_EXP_BITS - 1);
606 return ((exponent == -1) || (! exponent && *fp * *(fp+1)));
607 }
608 else return 1;
609}
610#endif /* Host and target byte order the same. */
611
ef98d5ac
JG
612static int
613pushed_size (prev_words, v)
614 int prev_words;
615 struct value *v;
616{
617 switch (TYPE_CODE (VALUE_TYPE (v)))
618 {
619 case TYPE_CODE_VOID: /* Void type (values zero length) */
620
621 return 0; /* That was easy! */
622
623 case TYPE_CODE_PTR: /* Pointer type */
624 case TYPE_CODE_ENUM: /* Enumeration type */
625 case TYPE_CODE_INT: /* Integer type */
626 case TYPE_CODE_REF: /* C++ Reference types */
627 case TYPE_CODE_ARRAY: /* Array type, lower bound zero */
628
629 return 1;
630
631 case TYPE_CODE_FLT: /* Floating type */
632
633 if (TYPE_LENGTH (VALUE_TYPE (v)) == 4)
634 return 1;
635 else
636 /* Assume that it must be a double. */
637 if (prev_words & 1) /* at an odd-word boundary */
638 return 3; /* round to 8-byte boundary */
639 else
640 return 2;
641
642 case TYPE_CODE_STRUCT: /* C struct or Pascal record */
643 case TYPE_CODE_UNION: /* C union or Pascal variant part */
644
645 return (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4);
646
647 case TYPE_CODE_FUNC: /* Function type */
648 case TYPE_CODE_SET: /* Pascal sets */
649 case TYPE_CODE_RANGE: /* Range (integers within bounds) */
650 case TYPE_CODE_PASCAL_ARRAY: /* Array with explicit type of index */
651 case TYPE_CODE_MEMBER: /* Member type */
652 case TYPE_CODE_METHOD: /* Method type */
653 /* Don't know how to pass these yet. */
654
655 case TYPE_CODE_UNDEF: /* Not used; catches errors */
656 default:
657 abort ();
658 }
659}
660
661static void
662store_parm_word (address, val)
663 CORE_ADDR address;
664 int val;
665{
666 write_memory (address, &val, 4);
667}
668
669static int
670store_parm (prev_words, left_parm_addr, v)
671 unsigned int prev_words;
672 CORE_ADDR left_parm_addr;
673 struct value *v;
674{
675 CORE_ADDR start = left_parm_addr + (prev_words * 4);
676 int *val_addr = (int *)VALUE_CONTENTS(v);
677
678 switch (TYPE_CODE (VALUE_TYPE (v)))
679 {
680 case TYPE_CODE_VOID: /* Void type (values zero length) */
681
682 return 0;
683
684 case TYPE_CODE_PTR: /* Pointer type */
685 case TYPE_CODE_ENUM: /* Enumeration type */
686 case TYPE_CODE_INT: /* Integer type */
687 case TYPE_CODE_ARRAY: /* Array type, lower bound zero */
688 case TYPE_CODE_REF: /* C++ Reference types */
689
690 store_parm_word (start, *val_addr);
691 return 1;
692
693 case TYPE_CODE_FLT: /* Floating type */
694
695 if (TYPE_LENGTH (VALUE_TYPE (v)) == 4)
696 {
697 store_parm_word (start, *val_addr);
698 return 1;
699 }
700 else
701 {
702 store_parm_word (start + ((prev_words & 1) * 4), val_addr[0]);
703 store_parm_word (start + ((prev_words & 1) * 4) + 4, val_addr[1]);
704 return 2 + (prev_words & 1);
705 }
706
707 case TYPE_CODE_STRUCT: /* C struct or Pascal record */
708 case TYPE_CODE_UNION: /* C union or Pascal variant part */
709
710 {
711 unsigned int words = (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4);
712 unsigned int word;
713
714 for (word = 0; word < words; word++)
715 store_parm_word (start + (word * 4), val_addr[word]);
716 return words;
717 }
718
719 default:
720 abort ();
721 }
722}
8aa13b87 723
8aa13b87
JK
724 /* This routine sets up all of the parameter values needed to make a pseudo
725 call. The name "push_parameters" is a misnomer on some archs,
726 because (on the m88k) most parameters generally end up being passed in
727 registers rather than on the stack. In this routine however, we do
728 end up storing *all* parameter values onto the stack (even if we will
729 realize later that some of these stores were unnecessary). */
730
ea3c0839
JG
731#define FIRST_PARM_REGNUM 2
732
8aa13b87
JK
733void
734push_parameters (return_type, struct_conv, nargs, args)
735 struct type *return_type;
736 int struct_conv;
737 int nargs;
738 value *args;
ea3c0839 739{
8aa13b87
JK
740 int parm_num;
741 unsigned int p_words = 0;
742 CORE_ADDR left_parm_addr;
743
744 /* Start out by creating a space for the return value (if need be). We
745 only need to do this if the return value is a struct or union. If we
746 do make a space for a struct or union return value, then we must also
747 arrange for the base address of that space to go into r12, which is the
748 standard place to pass the address of the return value area to the
749 callee. Note that only structs and unions are returned in this fashion.
750 Ints, enums, pointers, and floats are returned into r2. Doubles are
751 returned into the register pair {r2,r3}. Note also that the space
752 reserved for a struct or union return value only has to be word aligned
753 (not double-word) but it is double-word aligned here anyway (just in
754 case that becomes important someday). */
755
756 switch (TYPE_CODE (return_type))
757 {
758 case TYPE_CODE_STRUCT:
759 case TYPE_CODE_UNION:
760 {
761 int return_bytes = ((TYPE_LENGTH (return_type) + 7) / 8) * 8;
762 CORE_ADDR rv_addr;
763
764 rv_addr = read_register (SP_REGNUM) - return_bytes;
765
766 write_register (SP_REGNUM, rv_addr); /* push space onto the stack */
767 write_register (SRA_REGNUM, rv_addr);/* set return value register */
768 }
769 }
770
771 /* Here we make a pre-pass on the whole parameter list to figure out exactly
772 how many words worth of stuff we are going to pass. */
773
774 for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++)
775 p_words += pushed_size (p_words, value_arg_coerce (args[parm_num]));
776
777 /* Now, check to see if we have to round up the number of parameter words
778 to get up to the next 8-bytes boundary. This may be necessary because
779 of the software convention to always keep the stack aligned on an 8-byte
780 boundary. */
781
782 if (p_words & 1)
783 p_words++; /* round to 8-byte boundary */
784
785 /* Now figure out the absolute address of the leftmost parameter, and update
786 the stack pointer to point at that address. */
787
788 left_parm_addr = read_register (SP_REGNUM) - (p_words * 4);
789 write_register (SP_REGNUM, left_parm_addr);
790
791 /* Now we can go through all of the parameters (in left-to-right order)
792 and write them to their parameter stack slots. Note that we are not
793 really "pushing" the parameter values. The stack space for these values
794 was already allocated above. Now we are just filling it up. */
795
796 for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++)
797 p_words +=
798 store_parm (p_words, left_parm_addr, value_arg_coerce (args[parm_num]));
799
800 /* Now that we are all done storing the parameter values into the stack, we
801 must go back and load up the parameter registers with the values from the
802 corresponding stack slots. Note that in the two cases of (a) gaps in the
803 parameter word sequence causes by (otherwise) misaligned doubles, and (b)
804 slots correcponding to structs or unions, the work we do here in loading
805 some parameter registers may be unnecessary, but who cares? */
806
807 for (p_words = 0; p_words < 8; p_words++)
808 {
809 write_register (FIRST_PARM_REGNUM + p_words,
810 read_memory_integer (left_parm_addr + (p_words * 4), 4));
811 }
812}
813
814void
815pop_frame ()
816{
817 error ("Feature not implemented for the m88k yet.");
818 return;
819}
820
ea3c0839
JG
821void
822collect_returned_value (rval, value_type, struct_return, nargs, args)
823 value *rval;
824 struct type *value_type;
825 int struct_return;
826 int nargs;
827 value *args;
828{
829 char retbuf[REGISTER_BYTES];
830
831 bcopy (registers, retbuf, REGISTER_BYTES);
832 *rval = value_being_returned (value_type, retbuf, struct_return);
833 return;
834}
8aa13b87
JK
835
836#if 0
837/* Now handled in a machine independent way with CALL_DUMMY_LOCATION. */
838 /* Stuff a breakpoint instruction onto the stack (or elsewhere if the stack
839 is not a good place for it). Return the address at which the instruction
840 got stuffed, or zero if we were unable to stuff it anywhere. */
841
ea3c0839
JG
842CORE_ADDR
843push_breakpoint ()
844{
845 static char breakpoint_insn[] = BREAKPOINT;
846 extern CORE_ADDR text_end; /* of inferior */
847 static char readback_buffer[] = BREAKPOINT;
848 int i;
8aa13b87 849
ea3c0839
JG
850 /* With a little bit of luck, we can just stash the breakpoint instruction
851 in the word just beyond the end of normal text space. For systems on
852 which the hardware will not allow us to execute out of the stack segment,
853 we have to hope that we *are* at least allowed to effectively extend the
854 text segment by one word. If the actual end of user's the text segment
855 happens to fall right at a page boundary this trick may fail. Note that
856 we check for this by reading after writing, and comparing in order to
857 be sure that the write worked. */
8aa13b87 858
ea3c0839 859 write_memory (text_end, &breakpoint_insn, 4);
8aa13b87 860
ea3c0839
JG
861 /* Fill the readback buffer with some garbage which is certain to be
862 unequal to the breakpoint insn. That way we can tell if the
863 following read doesn't actually succeed. */
8aa13b87 864
ea3c0839
JG
865 for (i = 0; i < sizeof (readback_buffer); i++)
866 readback_buffer[i] = ~ readback_buffer[i]; /* Invert the bits */
867
868 /* Now check that the breakpoint insn was successfully installed. */
8aa13b87 869
ea3c0839
JG
870 read_memory (text_end, readback_buffer, sizeof (readback_buffer));
871 for (i = 0; i < sizeof (readback_buffer); i++)
872 if (readback_buffer[i] != breakpoint_insn[i])
873 return 0; /* Failed to install! */
874
875 return text_end;
8aa13b87 876}
ea3c0839 877#endif
This page took 0.206773 seconds and 4 git commands to generate.