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