]> Git Repo - binutils.git/blob - gdb/i860-tdep.c
Update comments to make it clear that the copyright status is UNCLEAR.
[binutils.git] / gdb / i860-tdep.c
1 /* Target-dependent code for the i860 for GDB, the GNU debugger.
2    Copyright is unclear on this module!!!
3    Copyright (C) 1992 Free Software Foundation, Inc.
4    SVR4 and ELF/DWARF changes Contributed by Peggy Fieland ([email protected])
5    
6    GDB is distributed in the hope that it will be useful, but WITHOUT ANY
7    WARRANTY.  No author or distributor accepts responsibility to anyone
8    for the consequences of using it or for whether it serves any
9    particular purpose or works at all, unless he says so in writing.
10    Refer to the GDB General Public License for full details.
11    
12    Everyone is granted permission to copy, modify and redistribute GDB,
13    but only under the conditions described in the GDB General Public
14    License.  A copy of this license is supposed to have been given to you
15    along with GDB so you can know your rights and responsibilities.  It
16    should be in a file named COPYING.  Among other things, the copyright
17    notice and this notice must be preserved on all copies.
18    
19    In other words, go ahead and share GDB, but don't try to stop
20    anyone else from sharing it farther.  Help stamp out software hoarding!
21    */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25
26
27 #include "defs.h"
28 #include "tm-i860.h"
29 #include "frame.h"
30 #include "inferior.h"
31 #include "obstack.h"
32 #include "symtab.h"
33 #include "value.h"
34
35 #include "tm-i860.h"
36 #include "i860-opcode.h"
37
38 #include "break.h"
39 #include "command.h"
40
41 #ifdef notdef
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/dir.h>
45 #endif
46
47 #include <signal.h>
48 #include <sys/ioctl.h>
49 #include <fcntl.h>
50
51 /* #include <sys/reg.h> */
52 #include "i860_reg.h"
53
54 #include <a.out.h>
55 #include <sys/file.h>
56 #include <core.h>
57
58 #include <sys/user.h>
59 #include <elf.h>
60 #include <sys/elftypes.h>
61 #include <sys/elf_860.h>
62 #include <libelf.h>
63
64
65 extern int read_memory();
66 extern int write_memory();
67 extern int read_memory_integer();
68 extern int print_insn();
69 extern void bzero();
70 extern void bcopy();
71 extern int store_inferior_registers(int);
72 extern int outside_startup_file();
73
74 int btdebug = 0;    /* change value to 1 to enable debugging code */
75
76 #define  BTDEBUG  if (btdebug) btdebug_message
77
78 extern int errno;
79 extern int attach_flag;
80
81 #define INSTRUCTION_LENGTH 4
82 #define REGISTER_LENGTH 4
83
84 /* routine to print debugging messages */
85 void btdebug_message(char *format, ...)
86 {       
87    va_list      arglist;
88    va_start( arglist, format );
89    
90    if( btdebug )
91       vfprintf (stderr,  format, arglist );
92    va_end  ( arglist      );
93 }
94
95 \f
96
97 /* return nonzero if the routine containing pc has been 
98  * compiled with -g. We assume -g if the first instruction is 
99  * an  addu|adds -X,sp and the second is st.l fp,XX(sp) 
100  *
101  *      based on  skip_prologue();
102  */
103
104 static int g_routine(pc)
105      CORE_ADDR pc;
106 {
107    CORE_ADDR instr;
108    CORE_ADDR top_pc;
109    
110    top_pc = get_pc_function_start(pc);
111    if (top_pc != NULL)
112       {
113          instr = (unsigned)( adj_read_memory_integer (top_pc));
114          /* Recognize "addu|adds -X,sp,sp" insn. */
115    
116          if ((instr & 0xEFFF0000) == 0x84420000) 
117             {
118                top_pc += INSTRUCTION_LENGTH;
119                instr =  (unsigned)(adj_read_memory_integer (top_pc));
120       
121                if( (instr & 0xFFE0F801) == 0x1C401801 )    /* st.l fp,X(sp) */
122                   return(1);
123             } 
124       }
125    return(0);
126 }
127
128
129 /* return the stack offset where the fp register is stored */
130 static int find_fp_offset(pc)
131 CORE_ADDR pc;
132 {
133    int fp_off,i;
134    CORE_ADDR    instr;
135    
136    /* look for the instruction and examine the offset */
137    
138    for (i=INSTRUCTION_LENGTH*1; i< INSTRUCTION_LENGTH*4; i+=INSTRUCTION_LENGTH){
139       instr =   (unsigned)(adj_read_memory_integer(pc+i));
140       if( (instr & 0xFFE0F801) == 0x1C401801) {    /* st.l fp,X(sp) */
141          
142          fp_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | 
143                              (instr&0x000007FE));
144          return(fp_off);
145       }
146    }
147    return(0);
148 }
149
150 /* return the stack offset where r1 (return linkage ) register is stored */
151 static int find_r1_offset(pc)
152 CORE_ADDR pc;
153 {
154    int r1_off,i;
155    CORE_ADDR    instr;
156    
157    /* look for the instruction and examine the offset */
158    
159    for (i=INSTRUCTION_LENGTH*1; i< INSTRUCTION_LENGTH*4; i+=INSTRUCTION_LENGTH){
160       instr = (unsigned)( adj_read_memory_integer(pc+i));
161       if ((instr & 0xFFE0F801) == 0x1C400801) { /* st.l r1,X(sp) */
162          
163          r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | 
164                              (instr&0x000007FE));
165          return(r1_off);
166       }
167    }
168    return(-1);
169 }
170
171 CORE_ADDR skip_prologue(CORE_ADDR);
172
173 /* does routine starting at pc build a stack frame of any kind?? */
174 static int has_a_frame(pc)
175 CORE_ADDR pc;
176 {
177    if( skip_prologue(pc) != pc )return(1);
178    else return(0);
179 }
180
181
182 /* written by Peggy Fieland [email protected]
183    Routine to validate the return register and the frame pointer
184    This routine is called when the routine we are in doesn't have a frame
185    In that case, we assume that the return address and frame pointer have 
186    not been touched.  In the following routine, we try to range check them 
187   to see if they are valid. */
188
189 static int valid_regs (rp, fp)
190 CORE_ADDR rp, fp;
191 {
192    if ( ( (rp % 4) != 0) | ( (fp % 16) != 0) )
193       return (0);
194    else 
195       return (1);
196 }
197
198
199   
200 /* get the pc and frame pointer (or sp )
201  * for the routine that called us
202  * when we (this_pc) is not within a  -g routine
203  * if caller is non g we return sp for fp
204  */
205
206 /* note this is written for Metaware version R2.1d compiler */
207 /* Modified by Peggy Fieland [email protected] */
208 static int caller_pc(this_pc,this_sp,to_pc,to_fp)
209      CORE_ADDR this_pc,this_sp;
210      CORE_ADDR *to_pc, *to_fp;
211 {
212    CORE_ADDR func_start;
213    int sp_offset,offset;
214    CORE_ADDR sp,pc,fp,instr;
215    
216    BTDEBUG("caller_pc %x sp = %x\n",this_pc,this_sp);
217    
218    func_start = get_pc_function_start(this_pc);
219
220    BTDEBUG("caller_pc func_start %x\n", func_start);
221
222    if (func_start!= NULL)
223       {
224          if( has_a_frame(func_start) ){
225       
226             BTDEBUG("has_a_frame\n");
227       
228             /* if our caller has a preamble and 
229              * declares space for a stack frame
230              * then we must work to find our return address
231              */
232             instr = (unsigned)( adj_read_memory_integer (func_start));
233             /* Recognize "addu|adds -X,sp,sp" insn. */
234       
235             if ((instr & 0xEFFF0000) == 0x84420000)
236                sp_offset=SIGN_EXT16(instr&0x0000FFFF);
237          }
238          else   
239             { 
240                /* if we get here, procedure doesn't have a frame.  If we didn't
241                   do anything weird, the frame pointer and return register have
242                   the values we want.  Check them to see if they are valid. */
243                   
244                CORE_ADDR temp_rp, temp_fp;
245
246                temp_rp = read_register(RP_REGNUM);
247                temp_fp = read_register(FP_REGNUM);
248
249                if (!valid_regs(temp_rp, temp_fp))
250                   {           
251                      printf("error frame_chain\n");
252                      return(0);
253                   }
254                BTDEBUG("caller_pc no frame, using r1 %x and fp %x\n",
255                        temp_rp, temp_fp);
256                *to_pc = temp_rp;
257                *to_fp = temp_fp;
258                return (1);
259             }
260       
261       BTDEBUG("sp_offset = %d %x\n",sp_offset,sp_offset);
262       
263       offset = find_r1_offset(func_start);
264       
265       if( offset < 0 ){
266          printf("cant find return address for routine at %x\n",
267                 func_start);
268          return(0);
269       }
270       pc = read_memory_integer(this_sp+offset,sizeof(long));
271       sp= this_sp - sp_offset;
272       
273       BTDEBUG("callers pc = %x sp = %x\n",pc,sp);
274       
275       /* our caller a -g routine  ?
276        * if he is we have to find his real fp
277        * else provide the sp as his fp
278        */
279       
280       if( g_routine(pc) ){
281          
282          BTDEBUG("caller_a_g\n");
283          
284          if( ! (offset = find_fp_offset(func_start)) ) {
285             printf("error fp_offset\n");
286             return(0);
287          }
288          BTDEBUG("offset = %x %d\n",offset,offset);
289          
290          fp = read_memory_integer(this_sp+offset,sizeof(long));
291          *to_pc = CLEAN_PC(pc);
292          *to_fp = fp;
293          return(1);
294       }else  
295          *to_pc = CLEAN_PC(pc);
296       *to_fp = sp;
297       return(1);
298    } else {
299 /*      pc = read_register(RP_REGNUM); */
300 /*       pc = 0;  */
301       /* if we get here, procedure doesn't have a frame.  If we didn't
302          do anything weird, the frame pointer and return register have
303          the values we want.  Check them to see if they are valid. */
304                   
305       CORE_ADDR temp_rp, temp_fp;
306       
307       temp_rp = read_register(RP_REGNUM);
308       temp_fp = read_register(FP_REGNUM);
309       
310       if (!valid_regs(temp_rp, temp_fp))
311          {           
312             printf("error frame_chain\n");
313             return(0);
314          }
315       BTDEBUG("caller_pc no frame, using r1 %x and fp %x\n",
316               temp_rp, temp_fp);
317       *to_pc = temp_rp;
318       *to_fp = temp_fp;
319       return (1);
320    }
321 }
322
323 /*
324  ** Figure out address to place next breakpoint. Avoid tricky spots, 
325  **     ie. delayed instruction slots etc.
326  ** Need to upgrade this later to allow delayed instruction breakpoints
327  **     with fix-up work done AFTER breakpoint.
328  ** Note that this routine DOES deal with dual instruction mode
329  */
330 #define BIM 0x8008
331
332 static branch_type
333    place_brk (addr, mode, brk)
334 CORE_ADDR addr; 
335 int mode;
336 struct breakpoint *brk;
337 {
338    CORE_ADDR  instr;
339    CORE_ADDR nextadr, prevadr;
340    int val = not_branch;
341    long offset; /* Must be signed for sign-extend */
342    extern char registers[];
343    prevadr = nextadr = 0;
344    
345    brk->address1 = 0;
346    
347    if (mode == SINGLE_STEP_MODE)
348       {
349          if (INDIM || ENDIM)
350             {
351                         nextadr = brk->address   = (addr +  INSTRUCTION_LENGTH*2);
352                         instr   =  (unsigned)(adj_read_memory_integer ((addr + INSTRUCTION_LENGTH)));
353                         brk->mode       = DIM;
354             }
355          else
356             {
357                         nextadr = brk->address   = (addr + INSTRUCTION_LENGTH);
358                         instr   =  (unsigned)(adj_read_memory_integer (addr));
359                         if (STDIM) 
360                   brk->mode = DIM;
361                         else
362                   brk->mode = SIM;
363             }
364          
365          
366          /*
367           ** For br/call one more sequential instruction gets executed and  then we
368           **    continue at the current addr + offset. We are definitely going to
369           **    the dest. We are NOT allowed to place a breakpoint in the "delay"
370           **    slot - (the next sequential instruction) so we only place 1 breakpoint
371           **    at the destination.
372           ** For the bc/bnc the next instruction executed is EITHER the next sequential
373           **    or the destination of the branch, we therefore place 2 breakpoints one
374           **    at each location.
375           ** For the bc.t/bnc.t either 1 more sequential instruction is performed
376           **    followed by a branch (like br/call) OR we skip the sequential 
377           **    instruction and keep going. We therefore place a breakpoint at the
378           **    destination of the branch AND the second sequential instruction after
379           **    the branch. Again a breakpoint is NOT allowed in the "delay slot"
380           */
381          if ((instr & 0xE0000000) == 0x60000000 &&      /* CTRL format */
382              (instr & 0xF8000000) != 0x60000000)                /* not pfld.y  */
383             {
384                if      ((instr & 0xF8000000) == 0x68000000)     /* br or call */
385                   val = uncond_d;
386                else if ((instr & 0xF4000000) == 0x74000000)     /* bc.t/bnc.t */
387                   val = cond_d;
388                else if ((instr & 0xF4000000) == 0x70000000)     /* bc or bnc  */
389                   val = cond;
390                offset = (instr & 0x03ffffff);
391                if (offset & 0x02000000)                 /*?sign extend*/
392                   offset |= 0xFC000000;
393                if (val == uncond_d)                     /* br/call*/
394                   prevadr = 0;
395                else if (val == cond_d)                  /* bc.t/bnc.t */
396                   {
397                      if ((INDIM) && !(ENDIM))
398                         prevadr = nextadr + (2*INSTRUCTION_LENGTH);
399                      else
400                         prevadr = nextadr + INSTRUCTION_LENGTH;
401                   } else {                              /* bc  /bnc   */
402                      if ((INDIM) && !(ENDIM))
403                         prevadr = nextadr;
404                      else
405                         prevadr = nextadr;
406                   }
407                nextadr += (offset << 2);
408             }
409          /*
410           ** We treat the bri/calli the same way as the br/call case.
411           */
412          else if ((instr & 0xFC00003F) == 0x4C000002 ||         /* calli    */
413                   (instr & 0xFC000000) == 0x40000000)           /* bri      */
414             {
415                val      = uncond_d;
416                offset   = ((instr & 0x0000F800) >> 11);
417                nextadr  = (read_register(offset + R0) & 0xFFFFFFFC);
418                prevadr = 0;
419             }
420          /*
421           ** We treat the bte/btne the same way as the bc/bnc case.
422           */
423          else if ((instr & 0xF0000000) == 0x50000000)           /* bte/btne */
424             {
425                val = cond;
426                offset = SIGN_EXT16(((instr & 0x001F0000) >> 5)  | 
427                                    (instr & 0x000007FF));
428                if ((INDIM) && !(ENDIM))
429                   prevadr = nextadr;
430                else
431                   prevadr = nextadr;
432                
433                nextadr += (offset << 2);
434             }
435          /*
436           ** We treat the bte/btne the same way as the bc/bnc case.
437           **    With the caveat that the 2 breakpoints may turn out to be at the same
438           **    address in which case we ignore one of them.
439           */
440          else if ((instr & 0xFC000000) == 0xB4000000)           /* bla */
441             {
442                val      = cond_d;
443                offset   = SIGN_EXT16(((instr & 0x001F0000) >> 5)  | 
444                                       (instr & 0x000007FF));
445                if ((INDIM) && !(ENDIM))
446                   {
447                      prevadr = nextadr + 2*INSTRUCTION_LENGTH;
448                   } else        {
449                      prevadr = nextadr + INSTRUCTION_LENGTH;
450                   }
451                nextadr += (offset << 2);
452                if (prevadr == nextadr) prevadr = 0;
453             }
454       } else    {
455          int adjust = 0;
456          
457          nextadr = addr;
458          
459          if (ISDIM(FOPADR(addr)))
460             {
461                if (ISDIM(FOPADR(nextadr- INSTRUCTION_LENGTH*2)))
462                   {
463                      instr      =  (unsigned)(adj_read_memory_integer(CORADR(addr
464                                                        -(INSTRUCTION_LENGTH*2))));
465                      brk->mode  = DIM;
466                   } else        {
467                      instr      =  (unsigned)(adj_read_memory_integer(addr-INSTRUCTION_LENGTH));
468                      brk->mode  = RIM;
469                   }
470             } else {
471                if (ISDIM(addr-INSTRUCTION_LENGTH))
472                   {
473                      instr      =  (unsigned)(adj_read_memory_integer(addr-INSTRUCTION_LENGTH));
474                      brk->mode  = BIM;
475                   } else        {
476                      instr      =  (unsigned)(adj_read_memory_integer (addr-INSTRUCTION_LENGTH));
477                      brk->mode  = SIM;
478                   }
479             }
480          
481          /* examine the PREVIOUS instruction to determine if we are in a branch delay
482             slot.  If we are, dont set a break here -- set it on the previous instruction.
483             This code also accounts for dual instruction mode */
484          if ((instr & 0xE0000000) == 0x60000000 &&
485              (instr & 0xF8000000) != 0x60000000)                /* not pfld.y  */
486             {
487                adjust++;
488                /* br    /call */
489                /* bc     /bnc  */
490                /* bc.t   /bnc.t*/
491                if ((instr & 0xF8000000) == 0x68000000) /* br or call */
492                   printf(" Breakpoint adjusted to avoid br/call delay slot and multiple breakpoints\n");
493                
494                if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
495                   printf(" Breakpoint adjusted to avoid bc.t/bnc.t delay slot and multiple breakpoints\n");
496                /* it IS really OK to set a break on the instruction AFTER the conditional branch
497                   -- it DOESN't have a delay slot */
498                if ((instr & 0xF4000000) == 0x70000000) /* bc / bnc */
499                   /* printf(" Breakpoint adjusted to avoid bc/bnc delay slot and multiple breakpoints\n"); */
500                   adjust = 0; 
501             } else if
502                ((instr & 0xFC00003F) == 0x4C000002 ||   /* bri/  calli */
503                 (instr & 0xFC000000) == 0x40000000)     
504                   {
505                      adjust++;
506                      printf(" Breakpoint adjusted to avoid calli/bri delay slot and multiple breakpoints\n");
507                   } else if
508                      ((instr & 0xF0000000) == 0x50000000) /* bte - btne */
509                         {
510                            /* it's OK to set a break here -- we are NOT in aa branch delay slot */
511                            /*
512                            adjust++;
513                            printf(" Breakpoint adjusted to avoid bte/btne multiple breakpoints\n");
514                            */
515                            adjust = 0;
516                         } else if
517                            ((instr & 0xFC000000) == 0xB4000000)
518                               {
519                                  adjust++;
520                                  printf(" Breakpoint adjusted to avoid bla delay slot and multiple breakpoints\n");
521                               }
522          if (adjust != 0)
523             {
524                if (brk->mode == DIM)
525                   {
526                      nextadr -= INSTRUCTION_LENGTH*2;
527                      nextadr = CORADR(nextadr); 
528                   }
529                else
530                   nextadr -= INSTRUCTION_LENGTH;
531             }
532          
533       }
534    
535    if (brk->mode == RIM) 
536       brk->mode = DIM;
537    if (brk->mode == BIM) 
538       brk->mode = SIM;
539    
540    if (nextadr != NULL)
541       {
542          if (brk->mode == DIM)
543             {
544                brk->act_addr[0] = CORADR(nextadr);
545                brk->act_addr[1] = FOPADR(nextadr);
546             } else      {
547                brk->act_addr[0] = nextadr;
548                brk->act_addr[1] = 0;
549             }
550       }
551    
552    if (prevadr != NULL)
553       {
554          brk->address1 = prevadr;
555          if (brk->mode == DIM)
556             {
557                brk->act_addr[2] = CORADR(prevadr);
558                brk->act_addr[3] = FOPADR(prevadr);
559             } else      {
560                brk->act_addr[2] = prevadr;
561                brk->act_addr[3] = 0;
562             }
563       } else    {
564          brk->act_addr[2] = brk->act_addr[3] = 0;
565       }
566    return val;
567 }
568
569 /* This routine checks to see if r1 has been stored into the frame between
570    the addresses prologue_start and prologue_end. Recognize stores of r1 
571    relative to both the sp and fp registers. */
572 static int has_stored_r1(CORE_ADDR prologue_start, CORE_ADDR prologue_end)
573 {
574    CORE_ADDR instr;
575    CORE_ADDR addr;
576    
577    BTDEBUG("has_stored_r1, prologue_start %x, prologue_end %x\n",
578            prologue_start, prologue_end);
579
580    for (addr = prologue_start; addr <= prologue_end;  addr += INSTRUCTION_LENGTH)
581       {
582    
583          instr =  (unsigned)(adj_read_memory_integer (addr));
584          if   ((instr & 0xFFE0F801) == 0x1C400801 /* st.l r1,X(sp) */
585             || (instr & 0xFFE0F801) == 0x1C600801) /* st.l r1,X(fp) */
586             return (1);
587       }
588    return 0;
589 }
590 /* This is used when GDB is exiting.  It gives less chance of error.*/
591
592
593 /* Simulate single-step ptrace call for sun4.  Code written by Gary
594    Beihl ([email protected]).  */
595 /* Modified for i860 by Jim Hanko ([email protected]) */
596
597
598 static struct breakpoint brk;
599 typedef char binsn_quantum[sizeof break_insn];
600
601 /* Non-zero if we just simulated a single-step ptrace call.  This is
602    needed because we cannot remove the breakpoints in the inferior
603    process until after the `wait' in `wait_for_inferior'.  Used for
604    i860. */
605
606 int one_stepped;
607
608 /* single_step() is called just before we want to resume the inferior,
609    if we want to single-step it but there is no hardware or kernel single-step
610    support.  We find all the possible targets of the coming instruction and 
611    breakpoint them.
612
613    single_step is also called just after the inferior stops.  If we had
614    set up a simulated single-step, we undo our damage.  */
615 /* Note that we don't need the parameter, but it's dictated as part of the interface. */
616 void
617    single_step (signal)
618 int signal;
619 {
620    CORE_ADDR pc;
621    branch_type place_brk();
622    
623    pc = read_register (PC_REGNUM);
624    
625    if (!one_stepped)
626       {
627          brk.address = pc;
628          place_brk (pc, SINGLE_STEP_MODE, &brk);
629          brk.shadow_contents[0] = brk.shadow_contents[1] = 0;
630          brk.shadow_contents[2] = brk.shadow_contents[3] = 0;
631          
632          if (brk.mode == DIM)
633             {
634                if (btdebug != 0)
635                   {
636                      btdebug_message(" DIM1 -> %x : ", brk.act_addr[3]);
637                      print_insn( brk.act_addr[3], stderr);
638                      btdebug_message("\t -|-  %x : ", brk.act_addr[2]);
639                      print_insn( brk.act_addr[2], stderr);
640                      btdebug_message("\n");
641                   }
642                if (( brk.address1 != NULL))
643                   { 
644                      adj_read_memory  (brk.act_addr[2], &brk.shadow_contents[2],
645                                        INSTRUCTION_LENGTH);
646                      adj_write_memory (brk.act_addr[2], break_insn, INSTRUCTION_LENGTH);
647                      adj_read_memory  (brk.act_addr[3], &brk.shadow_contents[3],
648                                        INSTRUCTION_LENGTH);
649                      /*         adj_write_memory (brk.act_addr[3], float_insn,
650                               INSTRUCTION_LENGTH); */
651                      
652                   }
653                if (btdebug != 0)
654                   {
655                      if ( brk.address1 != 0)
656                         btdebug_message(" DIM2 ->");
657                      else
658                         btdebug_message(" DIM1 ->");
659                
660                      btdebug_message(" %x : ", brk.act_addr[1]);
661                      print_insn( brk.act_addr[1], stderr);
662                      btdebug_message("\t -|-  %x : ", brk.act_addr[0]);
663                      print_insn( brk.act_addr[0], stderr);
664                      btdebug_message("\n");
665                   }
666                
667                adj_read_memory  (brk.act_addr[0], &brk.shadow_contents[0],      
668                                  INSTRUCTION_LENGTH);
669                adj_write_memory (brk.act_addr[0], break_insn,
670                                  INSTRUCTION_LENGTH);
671                adj_read_memory  (brk.act_addr[1], &brk.shadow_contents[1],      
672                                  INSTRUCTION_LENGTH);
673                /*               adj_write_memory (brk.act_addr[1], float_insn,
674                                  INSTRUCTION_LENGTH); */
675                
676             } 
677          else   {
678             if (brk.address1 != NULL)
679                {
680                   if (btdebug)
681                      {
682                         btdebug_message(" SIM1 ->");
683                         btdebug_message(" %x : ", brk.act_addr[2]);
684                         print_insn( brk.act_addr[2], stderr);
685                         btdebug_message("\n");
686                      }
687                   adj_read_memory  (brk.act_addr[2], &brk.shadow_contents[2],
688                                     INSTRUCTION_LENGTH);
689                   adj_write_memory (brk.act_addr[2], break_insn, INSTRUCTION_LENGTH);
690                }
691             if (btdebug)
692                {
693                   if ( brk.address1 != NULL)
694                      btdebug_message(" SIM2 ->");
695                   else
696                      btdebug_message(" SIM1 ->");
697                   
698                   btdebug_message(" %x : ", brk.act_addr[0]);
699                   print_insn( brk.act_addr[0], stderr);
700                   btdebug_message("\n");
701                }
702             adj_read_memory  (brk.act_addr[0], &brk.shadow_contents[0],
703                               INSTRUCTION_LENGTH);
704             adj_write_memory (brk.act_addr[0], break_insn,INSTRUCTION_LENGTH);
705          }
706          
707          /* Let it go */
708          one_stepped = 1;
709          return;
710       }
711    else
712       {
713          /* Remove breakpoints */
714          if (brk.mode == DIM)
715             {
716                adj_write_memory (brk.act_addr[0], &brk.shadow_contents[0],
717                                  INSTRUCTION_LENGTH);
718                adj_write_memory (brk.act_addr[1], &brk.shadow_contents[1],
719                                  INSTRUCTION_LENGTH);
720             } else      {
721                adj_write_memory (brk.act_addr[0], &brk.shadow_contents[0],
722                                  INSTRUCTION_LENGTH);
723             }
724          
725          if (brk.address1 != NULL)
726             {
727                if (brk.mode == DIM)
728                   {
729                      adj_write_memory (brk.act_addr[2], &brk.shadow_contents[2], 
730                                  INSTRUCTION_LENGTH);
731                      adj_write_memory (brk.act_addr[3], &brk.shadow_contents[3],
732                                  INSTRUCTION_LENGTH);
733                   } else        {
734                      adj_write_memory (brk.act_addr[2], &brk.shadow_contents[2], 
735                                  INSTRUCTION_LENGTH);
736                   }
737             }
738          one_stepped = 0;
739       }
740 }
741
742
743
744 /* Written for i860 by Jim Hanko ([email protected]) */
745 /* This code was based on SPARC code written by Gary Beihl ([email protected]),
746    by Michael Tiemann ([email protected]).  */
747 /* This routine returns the first memory address following the prologue code,
748    if there is a prologue. */
749
750 struct command_line *get_breakpoint_commands ();
751
752 CORE_ADDR 
753    skip_prologue (pc)
754 CORE_ADDR pc;
755 {
756    CORE_ADDR instr;
757    int regno;
758    
759    instr =  (unsigned)(adj_read_memory_integer (pc));
760    
761    /* Recognize "addu|adds -X,sp,sp" insn. */
762    if ((instr & 0xEFFF0000) == 0x84420000)
763       {
764          pc += INSTRUCTION_LENGTH;
765          instr =  (unsigned)(adj_read_memory_integer (pc));
766       }
767    else
768       return(pc);                                       /* No frame! */
769    
770    /* Recognize store of return addr and frame pointer into frame */
771    for (; ;)
772       {
773          if ((instr & 0xFFE0F801) == 0x1C400801 ||  /* st.l r1,X(sp) */
774              (instr & 0xFFE0F801) == 0x1C401801)    /* st.l fp,X(sp) */
775             {
776                pc += INSTRUCTION_LENGTH;
777                instr =  (unsigned)(adj_read_memory_integer (pc));
778             }
779          else
780             break;
781       }
782    
783    /* Recognize "addu|adds X,sp,fp" insn. */
784    if ((instr & 0xEFFF0000) == 0x84430000)
785       {
786          pc += INSTRUCTION_LENGTH;
787          instr =  (unsigned)(adj_read_memory_integer (pc));
788       }
789    
790    /* Now recognize stores into the frame from the registers. */
791    
792    for (; ;)
793       {
794          if ((instr & 0xFFA00003) == 0x1C200001 ||      /* st.l rn,X(fp|sp) */
795              (instr & 0xFFA00001) == 0x4C200000)        /* fst.y fn,X(fp|sp) */
796             {
797                regno = (instr >> 11) & 0x1f;
798                if (regno == 0)                  /* source reg == 0? quit */
799                   break;
800                pc += INSTRUCTION_LENGTH;
801                instr =  (unsigned)(adj_read_memory_integer (pc));
802             }
803          else
804             break;
805       }
806    
807    return(pc);
808 }
809
810 #if 0
811 /* This routine is uncalled.  Remove it sometime. */
812 /* Set *nextpc to branch target if we find a branch.  If it is not a branch, 
813    set it to the next instruction (addr + 4) */
814
815
816 branch_type
817    isabranch (addr,  nextpc)
818 CORE_ADDR addr, *nextpc;
819 {
820    CORE_ADDR instr;
821    branch_type val = not_branch;
822    long offset; /* Must be signed for sign-extend */
823    
824    BTDEBUG(" isabranch\n");
825    *nextpc = addr;
826    instr =  (unsigned)(adj_read_memory_integer (addr));
827    
828    if ((instr & 0xE0000000) == 0x60000000 &&            /* CTRL format */
829        (instr & 0xF8000000) != 0x60000000)              /* not pfld.y  */
830       {
831          if ((instr & 0xF8000000) == 0x68000000)                /* br or call */
832             val = uncond_d;
833          else if ((instr & 0xF4000000) == 0x74000000)   /* bc.t or bnc.t */
834             val = cond_d;
835          else if ((instr & 0xF4000000) == 0x70000000)   /* bc or bnc */
836             val = cond;
837          
838          offset = (instr & 0x03ffffff);
839          if (offset & 0x02000000)       /* sign extend? */
840             offset |= 0xFC000000;
841          *nextpc = addr + 4 + (offset << 2);
842       }
843    else if ((instr & 0xFC00003F) == 0x4C000002 ||       /* calli */
844             (instr & 0xFC000000) == 0x40000000)         /* bri */
845       {
846          val = uncond_d;
847          offset = ((instr & 0x0000F800) >> 11);
848          *nextpc = (read_register(offset) & 0xFFFFFFFC);
849       }
850    else if ((instr & 0xF0000000) == 0x50000000)         /* bte or btne */
851       {
852          val = cond;
853          
854          offset = SIGN_EXT16(((instr & 0x001F0000) >> 5)  | (instr & 0x000007FF));
855          *nextpc = addr + 4 + (offset << 2);
856       }
857    else if ((instr & 0xFC000000) == 0xB4000000)         /* bla */
858       {
859          val = cond_d;
860          
861          offset = SIGN_EXT16(((instr & 0x001F0000) >> 5)  | (instr & 0x000007FF));
862          *nextpc = addr + 4 + (offset << 2);
863       }
864    
865    BTDEBUG(" Final addr - %x\n", *nextpc);
866    /*BTDEBUG("isabranch ret: %d\n",val); */
867    return val;
868 }
869 #endif
870
871 /* set in call_function() [valops.c] to the address of the "call dummy" code
872    so dummy frames can be easily recognized; also used in wait_for_inferior() 
873    [infrun.c]. When not used, it points into the ABI's 'reserved area' */
874
875 CORE_ADDR call_dummy_set = 0;   /* true if dummy call being done */
876 CORE_ADDR call_dummy_start;     /* address of call dummy code */
877
878 /* this routine routine gets the values of the registers stored in the frame
879    and stores their values into the frame_saved_regs structure. */
880
881 void 
882 frame_find_saved_regs(frame_info, frame_saved_regs)
883      struct frame_info *frame_info;
884      struct frame_saved_regs *frame_saved_regs;
885 {
886    register CORE_ADDR pc;
887    CORE_ADDR instr;
888    long offset, spdelta = 0;
889    int i, size, reg;
890    int r1_off = -1, fp_off = -1;
891    int framesize;
892    
893    bzero (frame_saved_regs, sizeof(*frame_saved_regs));
894    
895    if (call_dummy_set && frame_info->pc >= call_dummy_start && 
896        frame_info->pc <= call_dummy_start + CALL_DUMMY_LENGTH)
897       {
898          /* DUMMY frame - all registers stored in order at fp; old sp is
899             at fp + NUM_REGS*4 */
900          
901          for (i = 1; i < NUM_REGS; i++) /* skip reg 0 */
902             if (i != SP_REGNUM && i != FP0_REGNUM && i != FP0_REGNUM + 1)
903                /* the register numbers used in the instruction and the ones used to index
904                   the regs array are not the same -- compensate */
905                frame_saved_regs->regs[i+R0] = frame_info->frame + i*REGISTER_LENGTH;
906          
907          frame_saved_regs->regs[SP_REGNUM] = frame_info->frame + NUM_REGS*REGISTER_LENGTH;
908          
909          call_dummy_set = 0;
910          return;
911       }
912    
913    pc = get_pc_function_start (frame_info->pc); 
914    if (pc != NULL)
915       {
916          instr =  (unsigned)(adj_read_memory_integer (pc));
917          /* Recognize "addu|adds -X,sp,sp" insn. */
918          if ((instr & 0xEFFF0000) == 0x84420000)
919             {
920                framesize = -SIGN_EXT16(instr & 0x0000FFFF);
921                pc += INSTRUCTION_LENGTH;
922                instr =  (unsigned)(adj_read_memory_integer (pc));
923             }
924       }
925    else
926       goto punt;                                        /* No frame! */
927    
928    /* Recognize store of return addr and frame pointer into frame */
929    for (; ;)
930       {
931          if ((instr & 0xFFE0F801) == 0x1C400801)  /* st.l r1,X(sp) */
932             {
933                r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
934                pc += INSTRUCTION_LENGTH;
935                instr =  (unsigned)(adj_read_memory_integer (pc));
936             }
937          else if ((instr & 0xFFE0F801) == 0x1C401801)    /* st.l fp,X(sp) */
938             {
939                fp_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
940                pc += INSTRUCTION_LENGTH;
941                instr =  (unsigned)(adj_read_memory_integer (pc));
942             }
943          else
944             break;
945       }
946    
947    /* Recognize "addu|adds X,sp,fp" insn. */
948    if ((instr & 0xEFFF0000) == 0x84430000)
949       {
950          spdelta = SIGN_EXT16(instr & 0x0000FFFF);
951          pc += INSTRUCTION_LENGTH;
952          instr =  (unsigned)(adj_read_memory_integer (pc));
953       }
954    
955    /* Now recognize stores into the frame from the registers. */
956    
957    for (; ;)
958       {
959          if ((instr & 0xFFC00003) == 0x1C400001)        /* st.l rn,X(fp|sp) */
960             {
961                offset = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
962                reg = (instr >> 11) & 0x1F;
963                if (reg == 0)
964                   break;
965                if ((instr & 0x00200000) == 0)   /* was this using sp? */
966                   if (spdelta != 0)                     /* and we know sp-fp delta */
967                      offset -= spdelta;         /* if so, adjust the offset */
968                   else
969                      break;                             /* if not, give up */
970                
971                
972                /* Handle the case where the return address is stored after the fp 
973                   is adjusted */
974                
975                if (reg == 1)
976                   frame_saved_regs->regs[PC_REGNUM] = frame_info->frame + offset;
977                else
978                   frame_saved_regs->regs[reg+R0] = frame_info->frame + offset;
979                
980                pc +=  INSTRUCTION_LENGTH;
981                instr =  (unsigned)(adj_read_memory_integer (pc));
982             }
983          else if ((instr & 0xFFC00001) == 0x2C400000) /* fst.y fn,X(fp|sp) */
984             {
985                /*
986                 * The number of words in a floating store based on 3 LSB of instr
987                 */
988                static int fst_sizes[] = {2, 0, 1, 0, 4, 0, 1, 0};
989                
990                size = fst_sizes[instr & 7];
991                reg = ((instr >> 16) & 0x1F) + FP0_REGNUM;
992                if (reg == 0)
993                   break;
994                
995                if (size > 1)                                    /* align the offset */
996                   offset = SIGN_EXT16(instr & 0x0000FFF8);      /* drop 3 bits */
997                else
998                   offset = SIGN_EXT16(instr & 0x0000FFFC);      /* drop 2 bits */
999                
1000                if ((instr & 0x00200000) == 0)   /* was this using sp? */
1001                   if (spdelta != 0)                     /* and we know sp-fp delta */
1002                      offset -= spdelta;         /* if so, adjust the offset */
1003                   else
1004                      break;                             /* if not, give up */
1005                
1006                for (i = 0; i < size; i++)
1007                   {
1008                      frame_saved_regs->regs[reg] = frame_info->frame + offset;
1009                      
1010                      offset +=  REGISTER_LENGTH;
1011                      reg++;
1012                   }
1013                
1014                pc +=  INSTRUCTION_LENGTH;
1015                instr =  (unsigned)(adj_read_memory_integer (pc));
1016             }
1017          else
1018             break;
1019       }
1020    
1021    punt: ;
1022    if (framesize != 0 && spdelta != 0)
1023       frame_saved_regs->regs[SP_REGNUM] = frame_info->frame+(framesize-spdelta);
1024    else
1025       frame_saved_regs->regs[SP_REGNUM] = frame_info->frame + 8;
1026    
1027    if ((spdelta != 0) && fp_off != -1)
1028       frame_saved_regs->regs[FP_REGNUM] = frame_info->frame - spdelta + fp_off;
1029    else
1030       frame_saved_regs->regs[FP_REGNUM] = frame_info->frame;
1031    
1032    if ((spdelta != 0) && r1_off != -1)
1033       frame_saved_regs->regs[PC_REGNUM] = frame_info->frame - spdelta + r1_off;
1034    else
1035       frame_saved_regs->regs[PC_REGNUM] = frame_info->frame + 4;
1036 }
1037
1038
1039 /* get the frame pointer of the caller.
1040  * note that only routines that have been compiled with
1041  * -g have full (XX)fp style stack frames
1042  * if we are not returning to a non -g caller then we
1043  * return the sp at entry to us as it is the caller's
1044  * frame reference.
1045  */
1046
1047 frame_chain(thisframe)
1048      FRAME thisframe;
1049 {
1050    CORE_ADDR fp, pc;
1051    CORE_ADDR func_start;
1052    CORE_ADDR instr;
1053    int offset;
1054    CORE_ADDR thisfp = thisframe->frame;
1055    
1056    /* get the frame pointer actually sp for  a non -g
1057     * for the routine that called us routine 
1058     */
1059    
1060    BTDEBUG("FRAME_CHAIN(%x)\n",thisframe);
1061    
1062    if ( !read_memory_integer (thisframe->frame,sizeof(long)) )
1063       {
1064          return (0);
1065       }
1066    
1067    if( ! g_routine(thisframe->pc) ){
1068       BTDEBUG( "non g at %x\n",thisframe->pc);
1069       caller_pc(thisframe->pc,thisframe->sp,&pc,&fp);
1070       BTDEBUG("caller_pc returned %x %x \n",pc,fp);
1071       return(fp);
1072       
1073    }/* else a -g routine */
1074    
1075    
1076    fp = read_memory_integer (thisfp, sizeof(long));
1077    
1078    if (fp < thisfp || fp > (unsigned) STACK_END_ADDR)
1079       {
1080          /* handle the Metaware-type pseudo-frame */
1081          
1082          func_start = get_pc_function_start(thisframe->pc);
1083          
1084          if (func_start != NULL)
1085             {
1086                
1087                instr =  (unsigned)(adj_read_memory_integer (func_start));
1088                /* Recognize "addu|adds -X,sp,sp" insn. */
1089                if ((instr & 0xEFFF0000) == 0x84420000)
1090                   offset = SIGN_EXT16(instr & 0x0000FFFF);
1091                
1092             }
1093          
1094          fp = 0;
1095          if (offset < 0)
1096             fp = thisfp - offset;
1097       }
1098    BTDEBUG("frame_chain returned %d\n",fp);
1099    return(fp);
1100 }
1101
1102 /* This function returns 1 if there is no stored r1, 0 otherwise.
1103    The function returns 1 if the pc is in a function prologue,
1104    or the function prologue didn't save the return pointer in
1105    the stack frame,  0 otherwise */
1106
1107 int no_stored_rp(CORE_ADDR pc)
1108 {
1109    CORE_ADDR func_start, prologue_end;
1110    
1111    func_start = get_pc_function_start(pc);
1112    if (func_start != NULL)
1113       {
1114          prologue_end = func_start;
1115          SKIP_PROLOGUE(prologue_end);
1116          if ( (pc >= func_start) && (pc <= prologue_end))
1117             {
1118                BTDEBUG("no_stored_rp: pc %x is in prologue \n",pc);
1119                return 1;
1120             }
1121          /* otherwise, see if the entry sequence stored the return pointer.
1122             If it didn't, return 1 */
1123          /* Some procedures , at least, store the return pointer AFTER 
1124             the prologue sequence, so check for stores from function start to
1125             present pc value. */
1126          if (!has_stored_r1(func_start, pc))
1127             {  
1128                BTDEBUG("no_stored_rp, for pc %x, prologue didn't store r1\n",pc);
1129                return 1;
1130             }
1131       }
1132    BTDEBUG("no_stored_rp for pc %x return pointer was stored \n", pc);
1133
1134    return 0; 
1135 }
1136
1137 /* get the PC of the caller */
1138 CORE_ADDR frame_saved_pc(frame_struct)
1139 FRAME frame_struct;
1140 {
1141      CORE_ADDR frame;
1142      CORE_ADDR pc;
1143      CORE_ADDR pc1;
1144      CORE_ADDR sp ;
1145      CORE_ADDR fp;
1146      
1147      frame = frame_struct->frame;
1148      pc = frame_struct->pc;
1149      sp = frame_struct->sp;
1150
1151      BTDEBUG("frame_saved_pc input: frame %x, pc %x",
1152            frame, pc);
1153
1154      /* First see if this is the current frame. If it is, return the value in r1,
1155         as it may not have been stored */
1156
1157      fp = read_register(FP_REGNUM);
1158
1159      /* check to see if we are in an entry sequence, where the return pointer has not yet been stored */
1160      if (fp == frame &&  no_stored_rp(pc))
1161         {
1162            pc = read_register(RP_REGNUM);
1163            frame_struct->rp = pc;
1164         }
1165      else if( ! g_routine(pc) )
1166         {
1167            caller_pc(pc,sp,&pc,&frame);
1168         }
1169      else 
1170         {
1171            
1172            pc = read_memory_integer (frame + 4, sizeof(long)); 
1173    
1174            if (!outside_startup_file(pc))
1175               {
1176                  
1177                  BTDEBUG("pc %x outside startup file \n",pc);
1178
1179                  pc1 = read_memory_integer (frame, sizeof(long));
1180                
1181                  if (outside_startup_file(pc1))
1182                     pc = pc1;
1183                  else
1184                     pc = 0;
1185               }
1186         } 
1187      BTDEBUG(" returning pc %x\n", CLEAN_PC(pc));
1188      return(CLEAN_PC(pc));
1189
1190   }
1191
1192 /* Pass arguments to a function in the inferior process - ABI compliant
1193    Note that this routine DOES NOT HANDLE memory argument lists, ie
1194    it gives up if there are too many arguments to pass in registers.*/
1195
1196 void
1197 pass_function_arguments(args, nargs, struct_return)
1198      value *args;
1199      int nargs;
1200      int struct_return;
1201 {
1202    int ireg = (struct_return) ? 17 : 16;
1203    int freg = FP0_REGNUM + 8;
1204    int i;
1205    struct type *type;
1206    value arg;
1207    long tmp;
1208    value value_arg_coerce();
1209    
1210    
1211    for (i = 0; i < nargs; i++) 
1212       {
1213          arg = value_arg_coerce(args[i]);
1214          type = VALUE_TYPE(arg);
1215          if (type == builtin_type_double) 
1216             {
1217                write_register_bytes(REGISTER_BYTE(freg), VALUE_CONTENTS(arg), sizeof(double));
1218                freg += 2;
1219             }
1220          else
1221             {
1222                bcopy(VALUE_CONTENTS(arg), &tmp, sizeof(long));
1223                write_register(ireg, tmp);
1224                ireg++;
1225             }
1226       }
1227    if (ireg >= 28 || freg >= FP0_REGNUM + 16)
1228       error("Too many arguments to function");
1229 }
1230
1231
1232 #define SPACES          "       "
1233 #define P_SPACES        "   "
1234 #define BYTE 0xff
1235
1236 int screen_lines=24;
1237
1238 char *spec_reg[] = {
1239    "fsr", "db", "dirbase", "fir", "psr", "epsr",
1240 };
1241
1242 char *doro_reg[] = {
1243    "scp", "cbsp", "pt_cs", "intmsk", "intack",
1244 };
1245 #define NREGS 32
1246
1247 #if 0
1248 /* This routine is uncalled -- remove this routine sometime */
1249 get_reg(regno)
1250 {
1251    char raw_buffer[32];
1252    int addr;
1253    int virtual_buffer;
1254    
1255    read_relative_register_raw_bytes (regno, raw_buffer);
1256    REGISTER_CONVERT_TO_VIRTUAL (addr, raw_buffer, &virtual_buffer);
1257    return(virtual_buffer);
1258 }
1259 #endif
1260
1261
1262 #if 0
1263 /* This routine is uncalled.  Remove it sometime. */
1264
1265 /*
1266  ** Figure out whether we are in a delayed slot and if so then take necessary
1267  **     action to resume properly - remember trap pre-empts instruction
1268  */
1269 int
1270    wasabranch (addr, nextpc, ss)
1271 CORE_ADDR addr, *nextpc;
1272 int ss;
1273 {
1274    CORE_ADDR nextadr, instr;
1275    int val = not_branch;
1276    long offset; /* Must be signed for sign-extend */
1277    
1278    if (ss)
1279       {
1280          if (INDIM)
1281             {
1282                         nextadr = CORADR((int)(addr +  INSTRUCTION_LENGTH*2));
1283                         instr   =  (unsigned)(adj_read_memory_integer (CORADR(addr)));
1284             }
1285          else
1286             {
1287                         nextadr = addr +  INSTRUCTION_LENGTH;
1288                         instr   =  (unsigned)(adj_read_memory_integer (addr));
1289             }
1290       } else    {
1291          if (ISDIM(addr))
1292             {
1293                         nextadr = CORADR(addr);
1294                         instr   =  (unsigned)(adj_read_memory_integer (nextadr));
1295             }
1296          else
1297             {
1298                         nextadr = addr;
1299                         instr   =  (unsigned)(adj_read_memory_integer (addr));
1300             }
1301       }
1302    
1303    
1304    if ((instr & 0xE0000000) == 0x60000000 &&            /* CTRL format */
1305        (instr & 0xF8000000) != 0x60000000)              /* not pfld.y  */
1306       {
1307          if ((instr & 0xF8000000) == 0x68000000)                /* br or call */
1308             val = uncond_d;
1309          else if ((instr & 0xF4000000) == 0x74000000)   /* bc.t or bnc.t */
1310             val = cond_d;
1311          else if ((instr & 0xF4000000) == 0x70000000)   /* bc or bnc */
1312             val = cond;
1313          
1314          offset = (instr & 0x03ffffff);
1315          if (offset & 0x02000000)       /* sign extend? */
1316             offset |= 0xFC000000;
1317          nextadr += (offset << 2);
1318       }
1319    else if ((instr & 0xFC00003F) == 0x4C000002 ||       /* calli */
1320             (instr & 0xFC000000) == 0x40000000)         /* bri */
1321       {
1322          if (ss)
1323             {
1324                val      = uncond_d;
1325                 offset  = ((instr & 0x0000F800) >> 11);
1326                 nextadr = (read_register(offset) & 0xFFFFFFFC);
1327             } else      {
1328                val      = uncond_d;
1329             }
1330       }
1331    else if ((instr & 0xF0000000) == 0x50000000)         /* bte or btne */
1332       {
1333          val = cond;
1334          
1335          offset = SIGN_EXT16(((instr & 0x001F0000) >> 5)  | (instr & 0x000007FF));
1336          nextadr += (offset << 2);
1337       }
1338    else if ((instr & 0xFC000000) == 0xB4000000)         /* bla */
1339       {
1340          val = cond_d;
1341          
1342          offset = SIGN_EXT16(((instr & 0x001F0000) >> 5)  | (instr & 0x000007FF));
1343          nextadr += (offset << 2);
1344       }
1345    
1346    *nextpc = nextadr;
1347    return val;
1348 }
1349 #endif
1350
1351 extern char registers[];
1352
1353 /* i860-specific routine to print the register set. Note that we ALWAYS print information
1354    on the floating point registers, so we ignore the parameter fpregs */
1355 void i860_do_registers_info(regnum,fpregs)
1356      int regnum;
1357      int fpregs;
1358 {
1359    register int i;
1360    unsigned int val;
1361    unsigned int j,k;
1362    
1363    
1364    if (regnum == -1)
1365       printf_filtered (
1366                        "Register       Contents (relative to selected stack frame)\n\n");
1367    
1368    if (regnum != -1) /* print one register */
1369       {
1370          if ((regnum >=F0 ) && (regnum <= F31))
1371             bcopy (&registers[ADJ_FREG(regnum)<<2], &val, sizeof (long));
1372          else
1373             bcopy (&registers[regnum<<2], &val, sizeof (long));
1374          printf("%-4s 0x%08x\t", reg_names[regnum], val);
1375          printf("\n\t"); fflush(stdout);
1376       }
1377    else /* print all registers */
1378       {
1379          
1380          printf("\n Control/Status Registers :- \n\t");
1381          for (j=0; j<=DB; j++)
1382             {
1383                bcopy (&registers[j<<2], &val, sizeof (long));
1384                printf("%-4s 0x%08x\t", reg_names[j], val);
1385             }
1386          printf("\n\t"); fflush(stdout);
1387          
1388          /* EPSR */
1389          bcopy (&registers[EPSR<<2], &val, sizeof (long));
1390          printf("%-4s 0x%08x\t", reg_names[EPSR], val);
1391          
1392          /* FSR */
1393          bcopy (&registers[FSR<<2], &val, sizeof (long));
1394          printf("%-4s 0x%08x\t", reg_names[FSR], val);
1395          
1396          /* CCR */
1397          bcopy (&registers[CCR<<2], &val, sizeof (long));
1398          printf("%-4s 0x%08x\t", reg_names[CCR], val);
1399          /* BEAR*/
1400          bcopy (&registers[BEAR<<2], &val, sizeof (long));
1401          printf("%-4s 0x%08x\t", reg_names[BEAR], val);
1402          
1403          
1404 #ifdef JIM_ADD_PRIV
1405          for (j=P0; j<=P3; j++)
1406             {
1407                bcopy (&registers[j<<2], &val, sizeof (long));
1408                printf("%-4s 0x%08x\t", reg_names[j], val);
1409             }
1410 #endif
1411          
1412          printf("\n Integer Registers :- \n\t");
1413          for (j=R0; j<=R31; j++)
1414             {
1415                if (j != IREGS  && (j % REGISTER_LENGTH == 0)) 
1416                   {
1417                      printf("\n\t");  fflush(stdout);
1418                   }
1419                bcopy (&registers[j<<2], &val, sizeof (long));
1420                printf("%-4s 0x%08x\t", reg_names[j], val);
1421             }
1422          
1423          printf("\n Floating Registers :- \n\t");
1424          for (j=F0; j<=F31; j++)
1425             {
1426                if (j != FREGS && (j % REGISTER_LENGTH == 0)) 
1427                   {
1428                      printf("\n\t");  fflush(stdout);
1429                   }
1430                bcopy (&registers[ADJ_FREG(j)<<2], &val, sizeof (long));
1431                printf("%-4s 0x%08x\t", reg_names[j], val);
1432             }
1433          
1434          printf("\n Special Registers :- \n\t");
1435          for (j=SPC_KI; j<=SPC_MERGE; j+=2)
1436             {
1437                unsigned int valh;
1438                if (j == SPC_T)
1439                   {
1440                      printf("\n\t");  fflush(stdout);
1441                   }
1442                bcopy (&registers[j<<2], &val, sizeof (long));
1443                bcopy (&registers[(j+1)<<2], &valh, sizeof (long));
1444                printf("%-6s 0x%08x %08x\t", reg_names[j], val,valh);
1445             }
1446          
1447          printf("\n Graphics Pipeline :- \n");
1448          {
1449             unsigned int valh;
1450             j = PSV_I1;
1451             bcopy (&registers[j<<2], &val, sizeof (long));
1452             bcopy (&registers[(j+1)<<2], &valh, sizeof (long));
1453             printf("\t\t\t%-8s 0x%08x %08x \n", reg_names[j], val,valh);
1454          }
1455          
1456          printf(" Memory Load Pipeline :- \n");
1457          for (j=PSV_L1; j<=PSV_L3; j+=REGISTER_LENGTH)
1458             {
1459                unsigned int valh, val2,val3;
1460                bcopy (&registers[j<<2], &val, sizeof (long));
1461                bcopy (&registers[(j+1)<<2], &valh, sizeof (long));
1462                bcopy (&registers[(j+2)<<2], &val2, sizeof (long));
1463                bcopy (&registers[(j+3)<<2], &val3, sizeof (long));
1464                printf("\t\t%-8s 0x%08x %08x %08x %08x\n", reg_names[j], 
1465                       val,valh,val2,val3);
1466             }
1467          
1468          printf("\n Adder Pipeline :-\t\tMultiplier Pipeline :-\t\tFSR results :-\n");
1469          for (i=PSV_FSR1,j=PSV_A1,k=PSV_M1; j<=PSV_A3; i++,j+=2,k+=2)
1470             {
1471                unsigned int valh,val2,val3,val4;
1472                bcopy (&registers[i<<2], &val4, sizeof (long));
1473                bcopy (&registers[j<<2], &val, sizeof (long));
1474                bcopy (&registers[(j+1)<<2], &valh, sizeof (long));
1475                bcopy (&registers[k<<2], &val2, sizeof (long));
1476                bcopy (&registers[(k+1)<<2], &val3, sizeof (long));
1477                printf("  %-4s 0x%08x %08x\t", reg_names[j], val,valh);
1478                printf("%-4s 0x%08x %08x\t", reg_names[k], val2,val3);
1479                printf("%-4s 0x%08x\n", reg_names[i], val4);
1480             }
1481          
1482       }
1483    
1484    
1485 }
1486
1487
1488
1489 /* The following set of routines was adapted from existing code previously
1490    in an i860-specific version of breakpoint.c by Peggy Fieland
1491    ([email protected]) */
1492 /* routines to set a data breakpoint by setting the value in the DB register. 
1493    Note that "hitting" the breakpoint will generate a data access trap. We
1494    do not have a special trap handler. */
1495 unsigned int dbrkval, dbrkmod;
1496 void i860_dbrk_breakpoint()
1497 {
1498    BTDEBUG("i860_dbrk_breakpoint was called , dbrkval %x\n", dbrkval);
1499    
1500    if (dbrkval != 0)
1501       {
1502          *(int *)&registers[DB<<2] = dbrkval;
1503       }
1504    else
1505       {
1506          *(int *)&registers[DB<<2] = 0;
1507       }
1508
1509    *(int *)&registers[PSR<<2] &= ~3;
1510    *(int *)&registers[PSR<<2] |= dbrkmod;
1511
1512    store_inferior_registers(DB);
1513    store_inferior_registers(PSR);
1514
1515 }
1516
1517 /* set a "read" data breakpoint. */
1518 void
1519 d_ro_break_command(arg)
1520 char *arg;
1521 {
1522         dbrkval = strtoul(arg, NULL, 0);
1523         dbrkmod = 0x01;
1524      BTDEBUG(" ro_dbreak - %x %x\n", dbrkval, dbrkmod);
1525 }
1526
1527 /* set a "write" data breakpoint. */
1528 void
1529 d_wo_break_command(arg)
1530 char *arg;
1531 {
1532         dbrkval = strtoul(arg, NULL, 0);
1533         dbrkmod = 0x02;
1534      BTDEBUG(" wo_dbreak - %x %x\n", dbrkval, dbrkmod);
1535 }
1536
1537 /* set a "read/write" data breakpoint. */
1538 void
1539 d_rw_break_command(arg)
1540 char *arg;
1541 {
1542         dbrkval = strtoul(arg, NULL, 0);
1543         dbrkmod = 0x03;
1544      BTDEBUG(" rw_dbreak - %x %x\n", dbrkval, dbrkmod);
1545 }
1546
1547 /* clear data breakpoint. */
1548 void
1549 clear_dbreak()
1550 {
1551         dbrkval = 0;
1552         dbrkmod = 0;
1553 }
1554
1555 /* i860-specific breakpoint initialization.  Includes adding the i860-specific
1556    data breakpoint commands. */
1557 void 
1558 i860_init_breakpoints()
1559 {
1560   dbrkval = dbrkmod = 0;
1561   add_com ("dbro", class_breakpoint, d_ro_break_command,
1562            "Set a data breakpoint READ ONLY, 32-bit data element.");
1563   add_com ("dbwo", class_breakpoint, d_wo_break_command,
1564            "Set a data breakpoint WRITE ONLY, 32-bit data element.");
1565   add_com ("dbrw", class_breakpoint, d_rw_break_command,
1566            "Set a data breakpoint READ/WRITE, 32-bit data element.");
1567   add_com ("dclear", class_breakpoint, clear_dbreak,
1568            "clear the current data breakpoint.");
1569   add_com_alias ("dc", "dclear", class_breakpoint, 1);
1570
1571 }
1572
1573 /* i860-specific code to insert a breakpoint. */
1574 int i860_insert_breakpoint(b)
1575 struct breakpoint *b;
1576 {
1577    int val;
1578
1579    place_brk( b->address, BREAK_MODE, b );
1580    if (b->mode == DIM)
1581       {
1582          
1583          adj_read_memory (b->act_addr[0], &b->shadow_contents[0],  INSTRUCTION_LENGTH);
1584          val =  adj_write_memory (b->act_addr[0], break_insn,  INSTRUCTION_LENGTH);
1585          if (val != 0 ) return val;
1586          adj_read_memory (b->act_addr[1], &b->shadow_contents[1],  INSTRUCTION_LENGTH);
1587          /*     val = adj_write_memory (b->act_addr[1], float_insn,  INSTRUCTION_LENGTH); */
1588          if (val != 0) return val;
1589       } 
1590    else 
1591       {
1592          adj_read_memory (b->act_addr[0], &b->shadow_contents[0],  INSTRUCTION_LENGTH);
1593          val = adj_write_memory (b->act_addr[0], break_insn,  INSTRUCTION_LENGTH);
1594       }
1595    if (b->address1 != 0)
1596       {
1597          if (b->mode == DIM)
1598             {
1599
1600                adj_read_memory (b->act_addr[2], &b->shadow_contents[2],  INSTRUCTION_LENGTH);
1601                val = adj_write_memory (b->act_addr[2], break_insn,  INSTRUCTION_LENGTH);
1602                if (val) return val;
1603                adj_read_memory (b->act_addr[3], &b->shadow_contents[3],  INSTRUCTION_LENGTH);
1604                /*       val = adj_write_memory (b->act_addr[3], float_insn,  INSTRUCTION_LENGTH); */
1605                if (val != 0) return val;
1606             }
1607          else   
1608             {
1609                adj_read_memory (b->act_addr[2], &b->shadow_contents[0],  INSTRUCTION_LENGTH);
1610                val = adj_write_memory (b->act_addr[2], break_insn,  INSTRUCTION_LENGTH);
1611             }
1612       }
1613    if (val != 0)
1614       return val;
1615    BTDEBUG("Inserted breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
1616            b->address, b->shadow_contents[0], b->shadow_contents[1]);
1617    b->inserted = 1;
1618    return 0;
1619 }
1620
1621 int i860_remove_breakpoint(b)
1622 struct breakpoint *b;
1623 {
1624    int val;
1625
1626    if (b->inserted)
1627       {
1628          if (b->mode == DIM)
1629             {
1630                val =adj_write_memory (b->act_addr[0], &(b->shadow_contents[0]),  
1631                                       INSTRUCTION_LENGTH);
1632                val =adj_write_memory (b->act_addr[1], &(b->shadow_contents[1]), 
1633                                        INSTRUCTION_LENGTH);
1634                if (b->address1 != NULL)
1635                   {
1636                      val =adj_write_memory (b->act_addr[2], &(b->shadow_contents[2]), 
1637                                              INSTRUCTION_LENGTH);
1638                      val =adj_write_memory (b->act_addr[3], &(b->shadow_contents[3]), 
1639                                              INSTRUCTION_LENGTH);
1640                   }
1641             } 
1642          else   
1643             {
1644                val =adj_write_memory (b->act_addr[0], b->shadow_contents, 
1645                                        INSTRUCTION_LENGTH);
1646                if (b->address1 != NULL)
1647                   {
1648                      val =adj_write_memory (b->act_addr[2], b->shadow_contents,  
1649                                             INSTRUCTION_LENGTH);
1650                   }
1651             }
1652          if (val != 0)
1653             return val;
1654          b->inserted = 0;
1655          BTDEBUG( "Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
1656                  b->address, b->shadow_contents[0], b->shadow_contents[1]);
1657       }
1658
1659    return 0;
1660
1661
1662 }
1663
1664
1665 #ifdef USE_PROC_FS      /* Target dependent support for /proc */
1666
1667 #include <sys/procfs.h>
1668
1669 /* The following routines were added by Peggy Fieland ([email protected])
1670 They were adapted from the m-68k versions of the routines .*/
1671
1672 /*  Given a pointer to a floating point register set in /proc format
1673     (fpregset_t *), unpack the register contents and supply them as gdb's
1674     idea of the current floating point register values. */
1675
1676 void 
1677 supply_fpregset (fpregsetp)
1678 fpregset_t *fpregsetp;
1679 {
1680   register int regno;
1681   
1682   BTDEBUG("supply_fregset called \n");
1683   
1684   for (regno = F0 ; regno <= F31 ; regno++)
1685     {
1686       supply_register (regno, (char *) &(fpregsetp -> fpu.r_freg[regno-F0]));
1687     }
1688 }
1689
1690 /*  Given a pointer to a floating point register set in /proc format
1691     (fpregset_t *), update the register specified by REGNO from gdb's idea
1692     of the current floating point register set.  If REGNO is -1, update
1693     them all. */
1694
1695 void
1696 fill_fpregset (fpregsetp, regno)
1697 fpregset_t *fpregsetp;
1698 int regno;
1699 {
1700   int regi;
1701   char *to;
1702   char *from;
1703   extern char registers[];
1704   BTDEBUG("fill_fregset  regno %d\n",regno);
1705
1706   for (regi = F0 ; regi <= F31 ; regi++)
1707     {
1708       if ((regno == -1) || (regno == regi))
1709         {
1710           from = (char *) &registers[REGISTER_BYTE (regi)];
1711        to = (char *) &(fpregsetp -> fpu.r_freg[regi-F0]);
1712           bcopy (from, to, REGISTER_RAW_SIZE (regno));
1713         }
1714     }
1715 }
1716
1717
1718 /*  Given a pointer to a general register set in /proc format (gregset_t *),
1719     unpack the register contents and supply them as gdb's idea of the current
1720     register values. */
1721
1722 void
1723 supply_gregset (gregsetp)
1724 gregset_t *gregsetp;
1725 {
1726   register int regno;
1727   register greg_t *regp = (greg_t *) gregsetp;
1728
1729   BTDEBUG("supply_gregset called \n");
1730
1731   for (regno = 0 ; regno <= R31 ; regno++)
1732     {
1733       supply_register (regno, (char *) (regp + regno));
1734     }
1735 }
1736
1737 /*  Given a pointer to a general register set in /proc format (gregset_t *),
1738     update the register specified by REGNO from gdb's idea
1739     of the current general register set.  If REGNO is -1, update
1740     them all. */
1741
1742 void
1743 fill_gregset (gregsetp, regno)
1744 gregset_t *gregsetp;
1745 int regno;
1746 {
1747   int regi;
1748   extern char registers[];
1749   register greg_t *regp = (greg_t *) gregsetp;
1750   BTDEBUG("fill_gregset regno %d \n",regno);
1751
1752   for (regi = 0 ; regi <= R31 ; regi++)
1753     {
1754       if ((regno == -1) || (regno == regi))
1755         {
1756         *(regp + regi) = *(int *) &registers[REGISTER_BYTE (regi)];
1757         }
1758
1759    }
1760 }
1761 #endif
This page took 0.12963 seconds and 4 git commands to generate.