Add rudiments on frames.
[deliverable/binutils-gdb.git] / gdb / m88k-tdep.c
CommitLineData
8aa13b87
JK
1/* Copyright (C) 1988, 1990 Free Software Foundation, Inc.
2
3This file is part of GDB.
4
99a7de40 5This program is free software; you can redistribute it and/or modify
8aa13b87 6it under the terms of the GNU General Public License as published by
99a7de40
JG
7the Free Software Foundation; either version 2 of the License, or
8(at your option) any later version.
8aa13b87 9
99a7de40 10This program is distributed in the hope that it will be useful,
8aa13b87
JK
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
99a7de40
JG
16along with this program; if not, write to the Free Software
17Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
8aa13b87
JK
18
19#include <stdio.h>
20#include "defs.h"
21#include "param.h"
22#include "frame.h"
23#include "inferior.h"
24#include "value.h"
25
26#ifdef USG
27#include <sys/types.h>
28#endif
29
30#include <sys/param.h>
31#include <sys/dir.h>
32#include <signal.h>
33#include "gdbcore.h"
34#include <sys/user.h>
35#ifndef USER /* added to support BCS ptrace_user */
36
37#define USER ptrace_user
38#endif
39#include <sys/ioctl.h>
40#include <fcntl.h>
41
8aa13b87
JK
42#include <sys/file.h>
43#include <sys/stat.h>
44
45#include "symtab.h"
46#include "setjmp.h"
47#include "value.h"
48
49int stack_error;
50jmp_buf stack_jmp;
51
52void
53tdesc_error_function (environment, continuable, message)
54dc_word_t environment;
55dc_boolean_t continuable;
56char *message;
57{
58 if (stack_error) longjmp (stack_jmp, 1);
59 if (!continuable)
60 {
61 printf("%s\n",message);
62 abort();
63 }
64}
65
66
67void
68tdesc_read_function (environment, memory, length, buffer)
69dc_word_t environment;
70dc_word_t memory;
71int length;
72char *buffer;
73{
74 int ptrace_code;
75 errno = 0;
76 if (memory < 2048)
77#if 0
78 /* This is a no-op! It sets buffer, but doesn't do anything to
79 what buffer points to. What does this function do anyway?
80 And this is wrong for cross-debugging. */
81 buffer = ptrace (3, inferior_pid, memory, 0);
82#else
83 return;
84#endif
85 else
86 read_memory (memory, buffer, length);
87}
88
89/* Map function for tdesc */
90void
91tdesc_map_function (map_env, loc, map_info_in, map_info_out)
92dc_word_t map_env;
93dc_word_t loc;
94dc_map_info_in_t map_info_in;
95dc_map_info_out_t *map_info_out;
96{
97int map_flags = DC_MIO_ENTRY_POINT | DC_MIO_IMPLICIT_PROLOGUE_END;
98int entry_point = get_pc_function_start(loc);
99map_info_out->flags = map_flags;
100map_info_out->entry_point = entry_point;
101}
102
103dc_handle_t tdesc_handle;
104
105extern int debug_info;
106
107void
108init_tdesc ()
109{
110 tdesc_handle = dc_initiate (debug_info, tdesc_error_function,
111 0,tdesc_read_function,0,0,0,0,0,tdesc_map_function,0);
112}
113dc_dcontext_t current_context;
114
115/* setup current context, called from wait_for_inferior */
116
117dc_dcontext_t
118init_dcontext()
119{
120 dc_word_t reg_info[DC_NUM_REG];
121 dc_word_t reg_flags[2] = {0,-1};
122 dc_word_t aux_info[DC_NUM_AUX];
123 dc_word_t aux_flags[2] = {0,-1};
124 dc_exactness_t loc_exact = DC_NO;
125 dc_word_t psr_info;
126 dc_boolean_t psr_ind = 0;
127 dc_word_t psr_flags[2] = {0,-1};
128
129 bcopy (&registers, reg_info, DC_NUM_REG * 4);
130 aux_info[DC_AUX_LOC] = read_register(SXIP_REGNUM);
131 aux_info[DC_AUX_SXIP] = read_register(SXIP_REGNUM);
132 aux_info[DC_AUX_SNIP] = read_register(SNIP_REGNUM);
133 aux_info[DC_AUX_SFIP] = read_register(SFIP_REGNUM);
134 aux_info[DC_AUX_FPSR] = read_register(FPSR_REGNUM);
135 aux_info[DC_AUX_FPCR] = read_register(FPCR_REGNUM);
136
137 psr_info = read_register(PSR_REGNUM);
138
139 return dc_make_dcontext (tdesc_handle, reg_info, reg_flags, aux_info,
140 aux_flags, loc_exact, psr_info, psr_ind, psr_flags);
141}
142
143
144dc_dcontext_t
145get_prev_context (context)
146 dc_dcontext_t context;
147{
148 return current_context = dc_previous_dcontext (context);
149}
150
151
152
153
154/* Determine frame base for this file's frames. This will be either
155 the CFA or the old style FP_REGNUM; the symtab for the current pc's
156 file has the information */
157
158CORE_ADDR
159get_frame_base(pc)
160CORE_ADDR pc;
161{
162 struct symtab *this_file = find_pc_symtab(pc);
163 int coffsem_frame_position;
164
165 /* If this_file is null, there's a good chance the file was compiled
166 without -g. If that's the case, use CFA (canonical frame addr)
167 as the default frame pointer. */
168
169 if (this_file)
170 {
171 coffsem_frame_position = this_file->coffsem & 3;
172 if (coffsem_frame_position == 1)
173 return (CORE_ADDR) dc_general_register (current_context, FP_REGNUM);
174 else
175 /* default is CFA, as well as if coffsem==2 */
176 return (CORE_ADDR) dc_frame_address (current_context);
177 }
178
179 return (CORE_ADDR) dc_frame_address (current_context);
180}
181
182#if TARGET_BYTE_ORDER != HOST_BYTE_ORDER
183you lose
184#else /* Host and target byte order the same. */
185#define SINGLE_EXP_BITS 8
186#define DOUBLE_EXP_BITS 11
187int
188IEEE_isNAN(fp, len)
189 int *fp, len;
190 /* fp points to a single precision OR double precision
191 * floating point value; len is the number of bytes, either 4 or 8.
192 * Returns 1 iff fp points to a valid IEEE floating point number.
193 * Returns 0 if fp points to a denormalized number or a NaN
194 */
195{
196 int exponent;
197 if (len == 4)
198 {
199 exponent = *fp;
200 exponent = exponent << 1 >> (32 - SINGLE_EXP_BITS - 1);
201 return ((exponent == -1) || (! exponent && *fp));
202 }
203 else if (len == 8)
204 {
205 exponent = *(fp+1);
206 exponent = exponent << 1 >> (32 - DOUBLE_EXP_BITS - 1);
207 return ((exponent == -1) || (! exponent && *fp * *(fp+1)));
208 }
209 else return 1;
210}
211#endif /* Host and target byte order the same. */
212
213#define FIRST_PRESERVED_REGNUM 14
214#define LAST_PRESERVED_REGNUM 25
215#define FIRST_PARM_REGNUM 2
216#define LAST_PARM_REGNUM 9
217
218#define MAX_REG_PARMS (LAST_PARM_REGNUM - FIRST_PARM_REGNUM + 1)
219
220void
221frame_find_saved_regs (fi, fsr)
222 struct frame_info *fi;
223 struct frame_saved_regs *fsr;
224{
225 register int regnum;
226
227 error ("Feature not implemented for the 88k yet.");
228 return;
229
230#if 0
231 for (regnum = FIRST_PARM_REGNUM; regnum <= LAST_PARM_REGNUM; regnum++)
232 fsr->regs[regnum]
233 = (unsigned) fi->frame - ((regnum - FIRST_PARM_REGNUM) * 4);
234
235 fsr->regs[SP_REGNUM] = 0; /* SP not saved in frames */
236 fsr->regs[FP_REGNUM] = fi->frame;
237 fsr->regs[PC_REGNUM] = fi->frame + 4;
238#endif
ef98d5ac
JG
239}
240
241static int
242pushed_size (prev_words, v)
243 int prev_words;
244 struct value *v;
245{
246 switch (TYPE_CODE (VALUE_TYPE (v)))
247 {
248 case TYPE_CODE_VOID: /* Void type (values zero length) */
249
250 return 0; /* That was easy! */
251
252 case TYPE_CODE_PTR: /* Pointer type */
253 case TYPE_CODE_ENUM: /* Enumeration type */
254 case TYPE_CODE_INT: /* Integer type */
255 case TYPE_CODE_REF: /* C++ Reference types */
256 case TYPE_CODE_ARRAY: /* Array type, lower bound zero */
257
258 return 1;
259
260 case TYPE_CODE_FLT: /* Floating type */
261
262 if (TYPE_LENGTH (VALUE_TYPE (v)) == 4)
263 return 1;
264 else
265 /* Assume that it must be a double. */
266 if (prev_words & 1) /* at an odd-word boundary */
267 return 3; /* round to 8-byte boundary */
268 else
269 return 2;
270
271 case TYPE_CODE_STRUCT: /* C struct or Pascal record */
272 case TYPE_CODE_UNION: /* C union or Pascal variant part */
273
274 return (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4);
275
276 case TYPE_CODE_FUNC: /* Function type */
277 case TYPE_CODE_SET: /* Pascal sets */
278 case TYPE_CODE_RANGE: /* Range (integers within bounds) */
279 case TYPE_CODE_PASCAL_ARRAY: /* Array with explicit type of index */
280 case TYPE_CODE_MEMBER: /* Member type */
281 case TYPE_CODE_METHOD: /* Method type */
282 /* Don't know how to pass these yet. */
283
284 case TYPE_CODE_UNDEF: /* Not used; catches errors */
285 default:
286 abort ();
287 }
288}
289
290static void
291store_parm_word (address, val)
292 CORE_ADDR address;
293 int val;
294{
295 write_memory (address, &val, 4);
296}
297
298static int
299store_parm (prev_words, left_parm_addr, v)
300 unsigned int prev_words;
301 CORE_ADDR left_parm_addr;
302 struct value *v;
303{
304 CORE_ADDR start = left_parm_addr + (prev_words * 4);
305 int *val_addr = (int *)VALUE_CONTENTS(v);
306
307 switch (TYPE_CODE (VALUE_TYPE (v)))
308 {
309 case TYPE_CODE_VOID: /* Void type (values zero length) */
310
311 return 0;
312
313 case TYPE_CODE_PTR: /* Pointer type */
314 case TYPE_CODE_ENUM: /* Enumeration type */
315 case TYPE_CODE_INT: /* Integer type */
316 case TYPE_CODE_ARRAY: /* Array type, lower bound zero */
317 case TYPE_CODE_REF: /* C++ Reference types */
318
319 store_parm_word (start, *val_addr);
320 return 1;
321
322 case TYPE_CODE_FLT: /* Floating type */
323
324 if (TYPE_LENGTH (VALUE_TYPE (v)) == 4)
325 {
326 store_parm_word (start, *val_addr);
327 return 1;
328 }
329 else
330 {
331 store_parm_word (start + ((prev_words & 1) * 4), val_addr[0]);
332 store_parm_word (start + ((prev_words & 1) * 4) + 4, val_addr[1]);
333 return 2 + (prev_words & 1);
334 }
335
336 case TYPE_CODE_STRUCT: /* C struct or Pascal record */
337 case TYPE_CODE_UNION: /* C union or Pascal variant part */
338
339 {
340 unsigned int words = (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4);
341 unsigned int word;
342
343 for (word = 0; word < words; word++)
344 store_parm_word (start + (word * 4), val_addr[word]);
345 return words;
346 }
347
348 default:
349 abort ();
350 }
351}
8aa13b87 352
8aa13b87
JK
353 /* This routine sets up all of the parameter values needed to make a pseudo
354 call. The name "push_parameters" is a misnomer on some archs,
355 because (on the m88k) most parameters generally end up being passed in
356 registers rather than on the stack. In this routine however, we do
357 end up storing *all* parameter values onto the stack (even if we will
358 realize later that some of these stores were unnecessary). */
359
360void
361push_parameters (return_type, struct_conv, nargs, args)
362 struct type *return_type;
363 int struct_conv;
364 int nargs;
365 value *args;
366 {
367 int parm_num;
368 unsigned int p_words = 0;
369 CORE_ADDR left_parm_addr;
370
371 /* Start out by creating a space for the return value (if need be). We
372 only need to do this if the return value is a struct or union. If we
373 do make a space for a struct or union return value, then we must also
374 arrange for the base address of that space to go into r12, which is the
375 standard place to pass the address of the return value area to the
376 callee. Note that only structs and unions are returned in this fashion.
377 Ints, enums, pointers, and floats are returned into r2. Doubles are
378 returned into the register pair {r2,r3}. Note also that the space
379 reserved for a struct or union return value only has to be word aligned
380 (not double-word) but it is double-word aligned here anyway (just in
381 case that becomes important someday). */
382
383 switch (TYPE_CODE (return_type))
384 {
385 case TYPE_CODE_STRUCT:
386 case TYPE_CODE_UNION:
387 {
388 int return_bytes = ((TYPE_LENGTH (return_type) + 7) / 8) * 8;
389 CORE_ADDR rv_addr;
390
391 rv_addr = read_register (SP_REGNUM) - return_bytes;
392
393 write_register (SP_REGNUM, rv_addr); /* push space onto the stack */
394 write_register (SRA_REGNUM, rv_addr);/* set return value register */
395 }
396 }
397
398 /* Here we make a pre-pass on the whole parameter list to figure out exactly
399 how many words worth of stuff we are going to pass. */
400
401 for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++)
402 p_words += pushed_size (p_words, value_arg_coerce (args[parm_num]));
403
404 /* Now, check to see if we have to round up the number of parameter words
405 to get up to the next 8-bytes boundary. This may be necessary because
406 of the software convention to always keep the stack aligned on an 8-byte
407 boundary. */
408
409 if (p_words & 1)
410 p_words++; /* round to 8-byte boundary */
411
412 /* Now figure out the absolute address of the leftmost parameter, and update
413 the stack pointer to point at that address. */
414
415 left_parm_addr = read_register (SP_REGNUM) - (p_words * 4);
416 write_register (SP_REGNUM, left_parm_addr);
417
418 /* Now we can go through all of the parameters (in left-to-right order)
419 and write them to their parameter stack slots. Note that we are not
420 really "pushing" the parameter values. The stack space for these values
421 was already allocated above. Now we are just filling it up. */
422
423 for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++)
424 p_words +=
425 store_parm (p_words, left_parm_addr, value_arg_coerce (args[parm_num]));
426
427 /* Now that we are all done storing the parameter values into the stack, we
428 must go back and load up the parameter registers with the values from the
429 corresponding stack slots. Note that in the two cases of (a) gaps in the
430 parameter word sequence causes by (otherwise) misaligned doubles, and (b)
431 slots correcponding to structs or unions, the work we do here in loading
432 some parameter registers may be unnecessary, but who cares? */
433
434 for (p_words = 0; p_words < 8; p_words++)
435 {
436 write_register (FIRST_PARM_REGNUM + p_words,
437 read_memory_integer (left_parm_addr + (p_words * 4), 4));
438 }
439}
440
441void
442pop_frame ()
443{
444 error ("Feature not implemented for the m88k yet.");
445 return;
446}
447
448 void
449 collect_returned_value (rval, value_type, struct_return, nargs, args)
450 value *rval;
451 struct type *value_type;
452 int struct_return;
453 int nargs;
454 value *args;
455 {
456 char retbuf[REGISTER_BYTES];
457
458 bcopy (registers, retbuf, REGISTER_BYTES);
459 *rval = value_being_returned (value_type, retbuf, struct_return);
460 return;
461 }
462
463#if 0
464/* Now handled in a machine independent way with CALL_DUMMY_LOCATION. */
465 /* Stuff a breakpoint instruction onto the stack (or elsewhere if the stack
466 is not a good place for it). Return the address at which the instruction
467 got stuffed, or zero if we were unable to stuff it anywhere. */
468
469 CORE_ADDR
470 push_breakpoint ()
471 {
472 static char breakpoint_insn[] = BREAKPOINT;
473 extern CORE_ADDR text_end; /* of inferior */
474 static char readback_buffer[] = BREAKPOINT;
475 int i;
476
477 /* With a little bit of luck, we can just stash the breakpoint instruction
478 in the word just beyond the end of normal text space. For systems on
479 which the hardware will not allow us to execute out of the stack segment,
480 we have to hope that we *are* at least allowed to effectively extend the
481 text segment by one word. If the actual end of user's the text segment
482 happens to fall right at a page boundary this trick may fail. Note that
483 we check for this by reading after writing, and comparing in order to
484 be sure that the write worked. */
485
486 write_memory (text_end, &breakpoint_insn, 4);
487
488 /* Fill the readback buffer with some garbage which is certain to be
489 unequal to the breakpoint insn. That way we can tell if the
490 following read doesn't actually succeed. */
491
492 for (i = 0; i < sizeof (readback_buffer); i++)
493 readback_buffer[i] = ~ readback_buffer[i]; /* Invert the bits */
494
495 /* Now check that the breakpoint insn was successfully installed. */
496
497 read_memory (text_end, readback_buffer, sizeof (readback_buffer));
498 for (i = 0; i < sizeof (readback_buffer); i++)
499 if (readback_buffer[i] != breakpoint_insn[i])
500 return 0; /* Failed to install! */
501
502 return text_end;
503 }
504#endif
505
506/* Like dc_psr_register but takes an extra int arg. */
507static dc_word_t
508psr_register (context, dummy)
509 dc_dcontext_t context;
510 int dummy;
511{
512 return dc_psr_register (context);
513}
514
515/* Same functionality as get_saved_register in findvar.c, but implemented
516 to use tdesc. */
517void
518get_saved_register (raw_buffer, optim, addrp, frame, regnum, lvalp)
519 char *raw_buffer;
520 int *optim;
521 CORE_ADDR *addrp;
522 FRAME frame;
523 int regnum;
524 enum lval_type *lvalp;
525{
526 struct frame_info *fi = get_frame_info (frame);
527
528 /* Functions to say whether a register is optimized out, and
529 if not, to get the value. Take as args a context and the
530 value of get_reg_arg. */
531 int (*get_reg_state) ();
532 dc_word_t (*get_reg) ();
533 int get_reg_arg;
534
535 /* Because tdesc doesn't tell us whether it got it from a register
536 or memory, always say we don't have an address for it. */
537 if (addrp != NULL)
538 *addrp = 0;
539
540 if (regnum < DC_NUM_REG)
541 {
542 get_reg_state = dc_general_register_state;
543 get_reg = dc_general_register;
544 get_reg_arg = regnum;
545 }
546 else
547 {
548 get_reg_state = dc_auxiliary_register_state;
549 get_reg = dc_auxiliary_register;
550 switch (regnum)
551 {
552 case SXIP_REGNUM:
553 get_reg_arg = DC_AUX_SXIP;
554 break;
555 case SNIP_REGNUM:
556 get_reg_arg = DC_AUX_SNIP;
557 break;
558 case FPSR_REGNUM:
559 get_reg_arg = DC_AUX_FPSR;
560 break;
561 case FPCR_REGNUM:
562 get_reg_arg = DC_AUX_FPCR;
563 break;
564 case PSR_REGNUM:
565 get_reg_state = dc_psr_register_bit_state;
566 get_reg = psr_register;
567 get_reg_arg = 0;
568 break;
569 default:
570 if (optim != NULL)
571 *optim = 1;
572 return;
573 }
574 }
575
576 if ((*get_reg_state) (fi->frame_context, get_reg_arg))
577 {
578 if (raw_buffer != NULL)
579 *(int *)raw_buffer = (*get_reg) (fi->frame_context, get_reg_arg);
580 if (optim != NULL)
581 *optim = 0;
582 return;
583 }
584 else
585 {
586 if (optim != NULL)
587 *optim = 1;
588 return;
589 }
590
591 /* Well, the caller can't treat it as a register or memory... */
592 if (lvalp != NULL)
593 *lvalp = not_lval;
594}
This page took 0.076653 seconds and 4 git commands to generate.