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