1 /* Machine-dependent code which would otherwise be in inflow.c and core.c,
2 for GDB, the GNU debugger.
3 Copyright (C) 1986, 1987 Free Software Foundation, Inc.
4 This code is for the i860 cpu.
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.
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.
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!
35 #include "i860-opcode.h"
37 #include "breakpoint.h"
38 #include "i860-break.h"
43 #include <sys/types.h>
44 #include <sys/param.h>
49 #include <sys/ioctl.h>
52 /* #include <sys/reg.h> */
61 #include <sys/elftypes.h>
62 #include <sys/elf_860.h>
66 extern int print_insn();
68 int btdebug = 0; /* change value to 1 to enable debugging code */
71 #define BTDEBUG if (btdebug) btdebug_message
74 extern char registers[];
75 CORE_ADDR get_saved_basereg();
77 #define INSTRUCTION_LENGTH 4
78 #define REGISTER_LENGTH 4
79 #define ALIGN_ARG(size,len) ((size + (len-1))&(-len))
80 #define NUM_FLOAT_ARG_REGS 8
81 #define NUM_INT_ARG_REGS 12
83 /* routine to print debugging messages */
84 void btdebug_message(char *format, ...)
87 va_start( arglist, format );
90 vfprintf (stderr, format, arglist );
95 /* Peggy Fieland. Routine that attempts to find the start of the entry sequence
97 /* maximum number of instrutions to search back */
98 #define MAX_ROUTINE_SIZE 4096
99 CORE_ADDR find_entry_start(pc)
102 CORE_ADDR instr, top_pc;
106 for (i = 0; i < MAX_ROUTINE_SIZE; ++i)
109 instr = (unsigned)( adj_read_memory_integer (top_pc));
110 /* Recognize "addu|adds -X,sp,sp" insn. */
112 if ((instr & 0xEFFF0000) == 0x84420000)
116 top_pc -= INSTRUCTION_LENGTH;
124 /* get the contents of a base register. Used for dwarf OP_BASEREG */
125 /* At present, only OP_BASEREG generated is for R28. NOTE that for stuff based on R28,
126 the value we want is the VALUE AT PROCEDURE INVOKATION, and thus is the frame we
127 use to get the value is the caller's frame. */
128 CORE_ADDR get_saved_basereg (frame, basereg)
133 if (basereg == R28) /* Unconditionally ??? */
135 frame = get_prev_frame (frame);
136 get_saved_register((char *) &addr, (int *) NULL, (CORE_ADDR *) NULL, frame,
137 basereg, (enum lval_type *)NULL);
141 get_saved_register((char *) &addr, (int *) NULL, (CORE_ADDR *) NULL, frame,
142 basereg, (enum lval_type *)NULL);
149 /* return nonzero if the routine containing pc has been
150 * compiled with -g. We assume -g if the first instruction is
151 * an addu|adds -X,sp and the second is st.l fp,XX(sp)
153 * based on skip_prologue();
156 static int g_routine(pc)
163 top_pc = get_pc_function_start(pc);
165 top_pc = find_entry_start (pc);
169 instr = (unsigned)( adj_read_memory_integer (top_pc));
170 /* Recognize "addu|adds -X,sp,sp" insn. */
172 if ((instr & 0xEFFF0000) == 0x84420000)
174 top_pc += INSTRUCTION_LENGTH;
175 instr = (unsigned)(adj_read_memory_integer (top_pc));
177 if( (instr & 0xFFE0F801) == 0x1C401801 ) /* st.l fp,X(sp) */
185 /* return the stack offset where the fp register is stored */
186 static int find_fp_offset(pc)
192 /* look for the instruction and examine the offset */
194 for (i=INSTRUCTION_LENGTH*1; i< INSTRUCTION_LENGTH*4; i+=INSTRUCTION_LENGTH){
195 instr = (unsigned)(adj_read_memory_integer(pc+i));
196 if( (instr & 0xFFE0F801) == 0x1C401801) { /* st.l fp,X(sp) */
198 fp_off = SIGN_EXT16(((instr&0x001F0000) >> 5) |
207 /* return the stack offset where r1 (return linkage ) register is stored */
208 static CORE_ADDR find_r1(pc,sp,fp)
212 CORE_ADDR instr, ret_pc;
214 /* look for the instruction and examine the offset */
216 for (i=INSTRUCTION_LENGTH*1; i< INSTRUCTION_LENGTH*4; i+=INSTRUCTION_LENGTH)
218 instr = (unsigned)( adj_read_memory_integer(pc+i));
219 if ((instr & 0xFFE0F801) == 0x1C400801)
223 r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) |
225 ret_pc = read_memory_integer(sp+r1_off,sizeof(long));
228 else if ((instr & 0xFFE0F801) == 0x1C600801)
231 r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) |
233 ret_pc = read_memory_integer(fp+r1_off,sizeof(long));
240 CORE_ADDR skip_prologue(CORE_ADDR);
242 /* does routine starting at pc build a stack frame of any kind?? */
243 static int has_a_frame(pc)
246 if( skip_prologue(pc) != pc )return(1);
252 Routine to validate the return register and the frame pointer
253 This routine is called when the routine we are in doesn't have a frame
254 In that case, we assume that the return address and frame pointer have
255 not been touched. In the following routine, we try to range check them
256 to see if they are valid. */
258 static int valid_regs (rp, fp)
261 if ( ( (rp % 4) != 0) | ( (fp % 16) != 0) )
266 /* get the pc and frame pointer (or sp )
267 * for the routine that called us
268 * when we (this_pc) is not within a -g routine
269 * if caller is non g we return sp for fp
272 /* note this is written for Metaware version R2.1d compiler */
274 static int caller_pc(this_pc,this_sp,this_fp,to_pc,to_fp, called_from_frame_chain)
275 CORE_ADDR this_pc,this_sp, this_fp;
276 CORE_ADDR *to_pc, *to_fp;
277 int called_from_frame_chain;
279 CORE_ADDR func_start;
280 int sp_offset,offset;
281 CORE_ADDR sp,pc,fp,instr;
283 BTDEBUG("caller_pc %x sp = %x\n",this_pc,this_sp);
285 func_start = get_pc_function_start(this_pc);
287 if (func_start == NULL)
288 func_start = find_entry_start (this_pc);
290 BTDEBUG("caller_pc func_start %x\n", func_start);
292 if ((func_start == NULL))
294 /* error in traceback */
295 fprintf(stderr, "error, unable to find start of function\n");
300 if (func_start!= NULL)
302 if( has_a_frame(func_start) ){
304 BTDEBUG("has_a_frame\n");
306 /* if our caller has a preamble and
307 * declares space for a stack frame
308 * then we must work to find our return address
310 instr = (unsigned)( adj_read_memory_integer (func_start));
311 /* Recognize "addu|adds -X,sp,sp" insn. */
313 if ((instr & 0xEFFF0000) == 0x84420000)
314 sp_offset=SIGN_EXT16(instr&0x0000FFFF);
318 /* if we get here, procedure doesn't have a frame. If we
319 do anything weird, the frame pointer and return register have
320 the values we want. Check them to see if they are valid. */
322 CORE_ADDR temp_rp, temp_fp;
324 /* temporary warning, since at the moment we don't have support for
325 the shared library */
327 temp_rp = read_register(RP_REGNUM);
328 temp_fp = read_register(FP_REGNUM);
330 if (!valid_regs(temp_rp, temp_fp))
333 "error - unable to find return address, traceback terminating\n");
336 BTDEBUG("caller_pc no frame, using r1 %x and fp %x\n",
343 BTDEBUG("sp_offset = %d %x\n",sp_offset,sp_offset);
345 pc = find_r1(func_start, this_sp, this_fp);
350 /* r1 wasn't stored between pc and function start */
351 pc = read_register (RP_REGNUM);
354 sp= this_sp - sp_offset;
356 BTDEBUG("callers pc = %x sp = %x\n",pc,sp);
358 /* our caller a -g routine ?
359 * if he is we have to find his real fp
360 * else provide the sp as his fp
365 BTDEBUG("caller_a_g\n");
367 if( ! (offset = find_fp_offset(func_start)) ) {
368 fprintf(stderr, "error - unable to find caller frame for routine at 0x%x, "
369 "traceback terminating\n", func_start);
372 BTDEBUG("offset = %x %d\n",offset,offset);
374 fp = read_memory_integer(this_sp+offset,sizeof(long));
375 *to_pc = CLEAN_PC(pc);
379 *to_pc = CLEAN_PC(pc);
383 /* pc = read_register(RP_REGNUM); */
385 /* if we get here, procedure doesn't have a frame. If we didn't
386 do anything weird, the frame pointer and return register have
387 the values we want. Check them to see if they are valid. */
389 CORE_ADDR temp_rp, temp_fp;
391 temp_rp = read_register(RP_REGNUM);
392 temp_fp = read_register(FP_REGNUM);
394 if (!valid_regs(temp_rp, temp_fp))
397 "error - unable to find return address, traceback terminating\n");
401 BTDEBUG("caller_pc no frame, using r1 %x and fp %x\n",
410 ** Figure out address to place next breakpoint. Avoid tricky spots,
411 ** ie. delayed instruction slots etc.
412 ** Need to upgrade this later to allow delayed instruction breakpoints
413 ** with fix-up work done AFTER breakpoint.
414 ** Note that this routine DOES deal with dual instruction mode
419 place_brk (addr, mode, brk)
422 struct breakpoint *brk;
425 CORE_ADDR nextadr, prevadr;
426 int val = not_branch;
427 long offset; /* Must be signed for sign-extend */
428 prevadr = nextadr = 0;
432 if (mode == SINGLE_STEP_MODE)
436 nextadr = brk->address = (addr + INSTRUCTION_LENGTH*2);
437 instr = (unsigned)(adj_read_memory_integer ((addr + INSTRUCTION_LENGTH)));
442 nextadr = brk->address = (addr + INSTRUCTION_LENGTH);
443 instr = (unsigned)(adj_read_memory_integer (addr));
452 ** For br/call one more sequential instruction gets executed and then we
453 ** continue at the current addr + offset. We are definitely going to
454 ** the dest. We are NOT allowed to place a breakpoint in the "delay"
455 ** slot - (the next sequential instruction) so we only place 1 breakpoint
456 ** at the destination.
457 ** For the bc/bnc the next instruction executed is EITHER the next sequential
458 ** or the destination of the branch, we therefore place 2 breakpoints one
460 ** For the bc.t/bnc.t either 1 more sequential instruction is performed
461 ** followed by a branch (like br/call) OR we skip the sequential
462 ** instruction and keep going. We therefore place a breakpoint at the
463 ** destination of the branch AND the second sequential instruction after
464 ** the branch. Again a breakpoint is NOT allowed in the "delay slot"
466 if ((instr & 0xE0000000) == 0x60000000 && /* CTRL format */
467 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
469 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
471 else if ((instr & 0xF4000000) == 0x74000000) /* bc.t/bnc.t */
473 else if ((instr & 0xF4000000) == 0x70000000) /* bc or bnc */
475 offset = (instr & 0x03ffffff);
476 if (offset & 0x02000000) /*?sign extend*/
477 offset |= 0xFC000000;
478 if (val == uncond_d) /* br/call*/
480 else if (val == cond_d) /* bc.t/bnc.t */
482 if ((INDIM) && !(ENDIM))
483 prevadr = nextadr + (2*INSTRUCTION_LENGTH);
485 prevadr = nextadr + INSTRUCTION_LENGTH;
486 } else { /* bc /bnc */
487 if ((INDIM) && !(ENDIM))
492 nextadr += (offset << 2);
495 ** We treat the bri/calli the same way as the br/call case.
497 else if ((instr & 0xFC00003F) == 0x4C000002 || /* calli */
498 (instr & 0xFC000000) == 0x40000000) /* bri */
501 offset = ((instr & 0x0000F800) >> 11);
502 nextadr = (read_register(offset + R0) & 0xFFFFFFFC);
506 ** We treat the bte/btne the same way as the bc/bnc case.
508 else if ((instr & 0xF0000000) == 0x50000000) /* bte/btne */
511 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) |
512 (instr & 0x000007FF));
513 if ((INDIM) && !(ENDIM))
518 nextadr += (offset << 2);
521 ** We treat the bte/btne the same way as the bc/bnc case.
522 ** With the caveat that the 2 breakpoints may turn out to be at the same
523 ** address in which case we ignore one of them.
525 else if ((instr & 0xFC000000) == 0xB4000000) /* bla */
528 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) |
529 (instr & 0x000007FF));
530 if ((INDIM) && !(ENDIM))
532 prevadr = nextadr + 2*INSTRUCTION_LENGTH;
534 prevadr = nextadr + INSTRUCTION_LENGTH;
536 nextadr += (offset << 2);
537 if (prevadr == nextadr) prevadr = 0;
544 if (ISDIM(FOPADR(addr)))
546 if (ISDIM(FOPADR(nextadr- INSTRUCTION_LENGTH*2)))
548 instr = (unsigned)(adj_read_memory_integer(CORADR(addr
549 -(INSTRUCTION_LENGTH*2))));
552 instr = (unsigned)(adj_read_memory_integer(addr-INSTRUCTION_LENGTH));
556 if (ISDIM(addr-INSTRUCTION_LENGTH))
558 instr = (unsigned)(adj_read_memory_integer(addr-INSTRUCTION_LENGTH));
561 instr = (unsigned)(adj_read_memory_integer (addr-INSTRUCTION_LENGTH));
566 /* examine the PREVIOUS instruction to determine if we are in a branch delay
567 slot. If we are, dont set a break here -- set it on the previous instruction.
568 This code also accounts for dual instruction mode */
569 if ((instr & 0xE0000000) == 0x60000000 &&
570 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
576 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
577 BTDEBUG(" Breakpoint adjusted to avoid br/call delay slot and multiple breakpoints\n");
579 if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
580 BTDEBUG(" Breakpoint adjusted to avoid bc.t/bnc.t delay slot and"
581 "multiple breakpoints\n");
583 /* it IS really OK to set a break on the instruction AFTER the conditional branch
584 -- it DOESN't have a delay slot */
585 if ((instr & 0xF4000000) == 0x70000000) /* bc / bnc */
588 ((instr & 0xFC00003F) == 0x4C000002 || /* bri/ calli */
589 (instr & 0xFC000000) == 0x40000000)
592 BTDEBUG(" Breakpoint adjusted to avoid calli/bri delay slot and"
593 " multiple breakpoints\n");
595 ((instr & 0xF0000000) == 0x50000000) /* bte - btne */
597 /* it's OK to set a break here -- we are NOT in aa branch delay slot */
600 printf(" Breakpoint adjusted to avoid bte/btne multiple breakpoints\n");
604 ((instr & 0xFC000000) == 0xB4000000)
607 BTDEBUG(" Breakpoint adjusted to avoid bla delay slot and"
608 " multiple breakpoints\n");
612 if (brk->mode == DIM)
614 nextadr -= INSTRUCTION_LENGTH*2;
615 nextadr = CORADR(nextadr);
618 nextadr -= INSTRUCTION_LENGTH;
623 if (brk->mode == RIM)
625 if (brk->mode == BIM)
630 if (brk->mode == DIM)
632 brk->act_addr[0] = CORADR(nextadr);
633 brk->act_addr[1] = FOPADR(nextadr);
635 brk->act_addr[0] = nextadr;
636 brk->act_addr[1] = 0;
642 brk->address1 = prevadr;
643 if (brk->mode == DIM)
645 brk->act_addr[2] = CORADR(prevadr);
646 brk->act_addr[3] = FOPADR(prevadr);
648 brk->act_addr[2] = prevadr;
649 brk->act_addr[3] = 0;
652 brk->act_addr[2] = brk->act_addr[3] = 0;
657 /* This routine checks to see if r1 has been stored into the frame between
658 the addresses prologue_start and prologue_end. Recognize stores of r1
659 relative to both the sp and fp registers. */
660 static int has_stored_r1(CORE_ADDR prologue_start, CORE_ADDR prologue_end)
665 BTDEBUG("has_stored_r1, prologue_start %x, prologue_end %x\n",
666 prologue_start, prologue_end);
668 for (addr = prologue_start; addr <= prologue_end; addr += INSTRUCTION_LENGTH)
671 instr = (unsigned)(adj_read_memory_integer (addr));
672 if ((instr & 0xFFE0F801) == 0x1C400801 /* st.l r1,X(sp) */
673 || (instr & 0xFFE0F801) == 0x1C600801) /* st.l r1,X(fp) */
678 /* This is used when GDB is exiting. It gives less chance of error.*/
681 /* Simulate single-step ptrace call for sun4. Code written by Gary
686 static struct breakpoint brk;
687 typedef char binsn_quantum[sizeof break_insn];
689 /* Non-zero if we just simulated a single-step ptrace call. This is
690 needed because we cannot remove the breakpoints in the inferior
691 process until after the `wait' in `wait_for_inferior'. Used for
696 /* single_step() is called just before we want to resume the inferior,
697 if we want to single-step it but there is no hardware or kernel single-step
698 support. We find all the possible targets of the coming instruction and
701 single_step is also called just after the inferior stops. If we had
702 set up a simulated single-step, we undo our damage. */
703 /* Note that we don't need the parameter, but it's dictated as part of the interface. */
709 branch_type place_brk();
710 int *shadow0, *shadow1, *shadow2, *shadow3;
712 shadow0 = (int *) &brk.shadow_contents[0];
713 shadow1 = (int *) &brk.shadow_contents[4];
714 shadow2 = (int *) &brk.shadow_contents[8];
715 shadow3 = (int *) &brk.shadow_contents[12];
716 pc = read_register (PC_REGNUM);
721 place_brk (pc, SINGLE_STEP_MODE, &brk);
722 *shadow0 = *shadow1 = *shadow2 = *shadow3 = 0;
728 btdebug_message(" DIM1 -> %x : ", brk.act_addr[3]);
729 print_insn( brk.act_addr[3], stderr);
730 btdebug_message("\t -|- %x : ", brk.act_addr[2]);
731 print_insn( brk.act_addr[2], stderr);
732 btdebug_message("\n");
734 if (( brk.address1 != NULL))
736 adj_read_memory (brk.act_addr[2], shadow2,
738 adj_write_memory (brk.act_addr[2], break_insn, INSTRUCTION_LENGTH);
739 adj_read_memory (brk.act_addr[3], shadow3,
741 /* adj_write_memory (brk.act_addr[3], float_insn,
742 INSTRUCTION_LENGTH); */
747 if ( brk.address1 != 0)
748 btdebug_message(" DIM2 ->");
750 btdebug_message(" DIM1 ->");
752 btdebug_message(" %x : ", brk.act_addr[1]);
753 print_insn( brk.act_addr[1], stderr);
754 btdebug_message("\t -|- %x : ", brk.act_addr[0]);
755 print_insn( brk.act_addr[0], stderr);
756 btdebug_message("\n");
759 adj_read_memory (brk.act_addr[0], shadow0,
761 adj_write_memory (brk.act_addr[0], break_insn,
763 adj_read_memory (brk.act_addr[1], shadow1,
765 /* adj_write_memory (brk.act_addr[1], float_insn,
766 INSTRUCTION_LENGTH); */
770 if (brk.address1 != NULL)
774 btdebug_message(" SIM1 ->");
775 btdebug_message(" %x : ", brk.act_addr[2]);
776 print_insn( brk.act_addr[2], stderr);
777 btdebug_message("\n");
779 adj_read_memory (brk.act_addr[2], shadow2,
781 adj_write_memory (brk.act_addr[2], break_insn, INSTRUCTION_LENGTH);
785 if ( brk.address1 != NULL)
786 btdebug_message(" SIM2 ->");
788 btdebug_message(" SIM1 ->");
790 btdebug_message(" %x : ", brk.act_addr[0]);
791 print_insn( brk.act_addr[0], stderr);
792 btdebug_message("\n");
794 adj_read_memory (brk.act_addr[0], shadow0,
796 adj_write_memory (brk.act_addr[0], break_insn,INSTRUCTION_LENGTH);
805 /* Remove breakpoints */
808 adj_write_memory (brk.act_addr[0], shadow0,
810 adj_write_memory (brk.act_addr[1], shadow1,
813 adj_write_memory (brk.act_addr[0], shadow0,
817 if (brk.address1 != NULL)
821 adj_write_memory (brk.act_addr[2], shadow2,
823 adj_write_memory (brk.act_addr[3], shadow3,
826 adj_write_memory (brk.act_addr[2], shadow2,
839 /* This routine returns the first memory address following the prologue code,
840 if there is a prologue. */
842 struct command_line *get_breakpoint_commands ();
851 instr = (unsigned)(adj_read_memory_integer (pc));
853 /* Recognize "addu|adds -X,sp,sp" insn. */
854 if ((instr & 0xEFFF0000) == 0x84420000)
856 pc += INSTRUCTION_LENGTH;
857 instr = (unsigned)(adj_read_memory_integer (pc));
860 return(pc); /* No frame! */
862 /* Recognize store of return addr and frame pointer into frame */
865 if ((instr & 0xFFE0F801) == 0x1C400801 || /* st.l r1,X(sp) */
866 (instr & 0xFFE0F801) == 0x1C401801) /* st.l fp,X(sp) */
868 pc += INSTRUCTION_LENGTH;
869 instr = (unsigned)(adj_read_memory_integer (pc));
875 /* Recognize "addu|adds X,sp,fp" insn. */
876 if ((instr & 0xEFFF0000) == 0x84430000)
878 pc += INSTRUCTION_LENGTH;
879 instr = (unsigned)(adj_read_memory_integer (pc));
882 /* Now recognize stores into the frame from the registers. */
886 if ((instr & 0xFFA00003) == 0x1C200001 || /* st.l rn,X(fp|sp) */
887 (instr & 0xFFA00001) == 0x4C200000) /* fst.y fn,X(fp|sp) */
889 regno = (instr >> 11) & 0x1f;
890 if (regno == 0) /* source reg == 0? quit */
892 pc += INSTRUCTION_LENGTH;
893 instr = (unsigned)(adj_read_memory_integer (pc));
903 /* This routine is uncalled. Remove it sometime. */
904 /* Set *nextpc to branch target if we find a branch. If it is not a branch,
905 set it to the next instruction (addr + 4) */
909 isabranch (addr, nextpc)
910 CORE_ADDR addr, *nextpc;
913 branch_type val = not_branch;
914 long offset; /* Must be signed for sign-extend */
916 BTDEBUG(" isabranch\n");
918 instr = (unsigned)(adj_read_memory_integer (addr));
920 if ((instr & 0xE0000000) == 0x60000000 && /* CTRL format */
921 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
923 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
925 else if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
927 else if ((instr & 0xF4000000) == 0x70000000) /* bc or bnc */
930 offset = (instr & 0x03ffffff);
931 if (offset & 0x02000000) /* sign extend? */
932 offset |= 0xFC000000;
933 *nextpc = addr + 4 + (offset << 2);
935 else if ((instr & 0xFC00003F) == 0x4C000002 || /* calli */
936 (instr & 0xFC000000) == 0x40000000) /* bri */
939 offset = ((instr & 0x0000F800) >> 11);
940 *nextpc = (read_register(offset) & 0xFFFFFFFC);
942 else if ((instr & 0xF0000000) == 0x50000000) /* bte or btne */
946 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
947 *nextpc = addr + 4 + (offset << 2);
949 else if ((instr & 0xFC000000) == 0xB4000000) /* bla */
953 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
954 *nextpc = addr + 4 + (offset << 2);
957 BTDEBUG(" Final addr - %x\n", *nextpc);
958 /*BTDEBUG("isabranch ret: %d\n",val); */
963 /* set in call_function() [valops.c] to the address of the "call dummy" code
964 so dummy frames can be easily recognized; also used in wait_for_inferior()
965 [infrun.c]. When not used, it points into the ABI's 'reserved area' */
967 CORE_ADDR call_dummy_set = 0; /* true if dummy call being done */
968 CORE_ADDR call_dummy_start; /* address of call dummy code */
970 /* this routine routine gets the values of the registers stored in the frame
971 and stores their values into the frame_saved_regs structure. */
974 frame_find_saved_regs(frame_info, frame_saved_regs)
975 struct frame_info *frame_info;
976 struct frame_saved_regs *frame_saved_regs;
978 register CORE_ADDR pc;
980 long offset, spdelta = 0;
982 int r1_off = -1, fp_off = -1;
985 bzero (frame_saved_regs, sizeof(*frame_saved_regs));
987 if (call_dummy_set && frame_info->pc >= call_dummy_start &&
988 frame_info->pc <= call_dummy_start + CALL_DUMMY_LENGTH)
990 /* DUMMY frame - all registers stored in order at fp; old sp is
991 at fp + NUM_REGS*4 */
993 for (i = 1; i < NUM_REGS; i++) /* skip reg 0 */
994 /* the register numbers used in the instruction and the ones used to index
995 the regs array are not the same -- compensate */
996 frame_saved_regs->regs[i+R0] = frame_info->frame + i*REGISTER_LENGTH;
1002 pc = get_pc_function_start (frame_info->pc);
1004 pc = find_entry_start (frame_info->pc);
1008 instr = (unsigned)(adj_read_memory_integer (pc));
1009 /* Recognize "addu|adds -X,sp,sp" insn. */
1010 if ((instr & 0xEFFF0000) == 0x84420000)
1012 framesize = -SIGN_EXT16(instr & 0x0000FFFF);
1013 pc += INSTRUCTION_LENGTH;
1014 instr = (unsigned)(adj_read_memory_integer (pc));
1018 goto punt; /* No frame! */
1020 /* Recognize store of return addr and frame pointer into frame */
1023 if ((instr & 0xFFE0F801) == 0x1C400801) /* st.l r1,X(sp) */
1025 r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
1026 pc += INSTRUCTION_LENGTH;
1027 instr = (unsigned)(adj_read_memory_integer (pc));
1029 else if ((instr & 0xFFE0F801) == 0x1C401801) /* st.l fp,X(sp) */
1031 fp_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
1032 pc += INSTRUCTION_LENGTH;
1033 instr = (unsigned)(adj_read_memory_integer (pc));
1039 /* Recognize "addu|adds X,sp,fp" insn. */
1040 if ((instr & 0xEFFF0000) == 0x84430000)
1042 spdelta = SIGN_EXT16(instr & 0x0000FFFF);
1043 pc += INSTRUCTION_LENGTH;
1044 instr = (unsigned)(adj_read_memory_integer (pc));
1047 /* Now recognize stores into the frame from the registers. */
1051 if ((instr & 0xFFC00003) == 0x1C400001) /* st.l rn,X(fp|sp) */
1053 offset = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
1054 reg = (instr >> 11) & 0x1F;
1057 if ((instr & 0x00200000) == 0) /* was this using sp? */
1058 if (spdelta != 0) /* and we know sp-fp delta */
1059 offset -= spdelta; /* if so, adjust the offset */
1061 break; /* if not, give up */
1064 /* Handle the case where the return address is stored after the fp
1068 frame_saved_regs->regs[PC_REGNUM] = frame_info->frame + offset;
1070 frame_saved_regs->regs[reg+R0] = frame_info->frame + offset;
1072 pc += INSTRUCTION_LENGTH;
1073 instr = (unsigned)(adj_read_memory_integer (pc));
1075 else if ((instr & 0xFFC00001) == 0x2C400000) /* fst.y fn,X(fp|sp) */
1078 * The number of words in a floating store based on 3 LSB of instr
1080 static int fst_sizes[] = {2, 0, 1, 0, 4, 0, 1, 0};
1082 size = fst_sizes[instr & 7];
1083 reg = ((instr >> 16) & 0x1F) + FP0_REGNUM;
1087 if (size > 1) /* align the offset */
1088 offset = SIGN_EXT16(instr & 0x0000FFF8); /* drop 3 bits */
1090 offset = SIGN_EXT16(instr & 0x0000FFFC); /* drop 2 bits */
1092 if ((instr & 0x00200000) == 0) /* was this using sp? */
1093 if (spdelta != 0) /* and we know sp-fp delta */
1094 offset -= spdelta; /* if so, adjust the offset */
1096 break; /* if not, give up */
1098 for (i = 0; i < size; i++)
1100 frame_saved_regs->regs[reg] = frame_info->frame + offset;
1102 offset += REGISTER_LENGTH;
1106 pc += INSTRUCTION_LENGTH;
1107 instr = (unsigned)(adj_read_memory_integer (pc));
1114 if (framesize != 0 && spdelta != 0)
1115 frame_saved_regs->regs[SP_REGNUM] = frame_info->frame+(framesize-spdelta);
1117 frame_saved_regs->regs[SP_REGNUM] = frame_info->frame + 8;
1119 if ((spdelta != 0) && fp_off != -1)
1120 frame_saved_regs->regs[FP_REGNUM] = frame_info->frame - spdelta + fp_off;
1122 frame_saved_regs->regs[FP_REGNUM] = frame_info->frame;
1124 if ((spdelta != 0) && r1_off != -1)
1125 frame_saved_regs->regs[PC_REGNUM] = frame_info->frame - spdelta + r1_off;
1127 frame_saved_regs->regs[PC_REGNUM] = frame_info->frame + 4;
1131 /* get the frame pointer of the caller.
1132 * note that only routines that have been compiled with
1133 * -g have full (XX)fp style stack frames
1134 * if we are not returning to a non -g caller then we
1135 * return the sp at entry to us as it is the caller's
1139 frame_chain(thisframe)
1143 CORE_ADDR func_start;
1146 CORE_ADDR thisfp = thisframe->frame;
1147 struct frame_saved_regs fsr;
1150 /* get the frame pointer actually sp for a non -g
1151 * for the routine that called us routine
1154 BTDEBUG("FRAME_CHAIN(%x)\n",thisframe);
1156 if ( !read_memory_integer (thisframe->frame,sizeof(long)) )
1161 if( ! g_routine(thisframe->pc) ){
1162 thissp = get_saved_basereg (thisframe, SP_REGNUM);
1164 BTDEBUG( "non g at %x\n",thisframe->pc);
1165 caller_pc(thisframe->pc, thissp, thisfp,&pc,&fp, 1);
1166 BTDEBUG("caller_pc returned %x %x \n",pc,fp);
1169 }/* else a -g routine */
1172 fp = read_memory_integer (thisfp, sizeof(long));
1174 if (fp < thisfp || fp > (unsigned) STACK_END_ADDR)
1176 /* handle the Metaware-type pseudo-frame */
1178 func_start = get_pc_function_start(thisframe->pc);
1179 if (func_start == NULL)
1180 func_start = find_entry_start (thisframe->pc);
1182 if (func_start != NULL)
1185 instr = (unsigned)(adj_read_memory_integer (func_start));
1186 /* Recognize "addu|adds -X,sp,sp" insn. */
1187 if ((instr & 0xEFFF0000) == 0x84420000)
1188 offset = SIGN_EXT16(instr & 0x0000FFFF);
1194 fp = thisfp - offset;
1196 BTDEBUG("frame_chain returned %d\n",fp);
1200 /* This function returns 1 if there is no stored r1, 0 otherwise.
1201 The function returns 1 if the pc is in a function prologue,
1202 or the function prologue didn't save the return pointer in
1203 the stack frame, 0 otherwise */
1205 int no_stored_rp(CORE_ADDR pc)
1207 CORE_ADDR func_start, prologue_end;
1209 func_start = get_pc_function_start(pc);
1210 if (func_start == NULL)
1211 func_start = find_entry_start (pc);
1213 if (func_start != NULL)
1215 prologue_end = func_start;
1216 SKIP_PROLOGUE(prologue_end);
1217 if ( (pc >= func_start) && (pc <= prologue_end))
1219 BTDEBUG("no_stored_rp: pc %x is in prologue \n",pc);
1222 /* otherwise, see if the entry sequence stored the return pointer.
1223 If it didn't, return 1 */
1224 /* Some procedures , at least, store the return pointer AFTER
1225 the prologue sequence, so check for stores from function start to
1226 present pc value. */
1227 if (!has_stored_r1(func_start, pc))
1229 BTDEBUG("no_stored_rp, for pc %x, prologue didn't store r1\n",pc);
1233 BTDEBUG("no_stored_rp for pc %x return pointer was stored \n", pc);
1238 /* get the PC of the caller */
1239 CORE_ADDR frame_saved_pc(frame_struct)
1247 struct frame_saved_regs fsr;
1249 frame = frame_struct->frame;
1250 pc = frame_struct->pc;
1253 BTDEBUG("frame_saved_pc input: frame %x, pc %x",
1256 /* First see if this is the current frame. If it is, return the value in r1,
1257 as it may not have been stored */
1259 fp = read_register(FP_REGNUM);
1261 /* check to see if we are in an entry sequence, where the return pointer has not yet been stored */
1262 if (fp == frame && no_stored_rp(pc))
1264 pc = read_register(RP_REGNUM);
1265 frame_struct->rp = pc;
1267 else if( ! g_routine(pc) )
1269 sp = get_saved_basereg (frame_struct, SP_REGNUM);
1271 caller_pc(pc,sp,frame_struct->frame, &pc,&frame, 0);
1276 pc = read_memory_integer (frame + 4, sizeof(long));
1278 if (inside_entry_file(pc))
1281 BTDEBUG("pc %x outside entry file \n",pc);
1283 pc1 = read_memory_integer (frame, sizeof(long));
1285 if (!inside_entry_file(pc1))
1291 BTDEBUG(" returning pc %x\n", CLEAN_PC(pc));
1292 return(CLEAN_PC(pc));
1296 /* Pass arguments to a function in the inferior process - ABI compliant
1298 for newer ABI conventions. Note that now, unfortunately, we MUST KNOW
1299 if we expect a float or a double. For now, we will assume that the
1300 caller of this routine has the types of these arguments correct....
1301 NOTE THAT THIS ROUTINE DOES NO ARGUMENT COERCION -- it's all in the
1303 Modified by Peggy Fieland to handle memory argument lists.
1306 #define IS_EVEN_REG(fl) (((fl - FP0_REGNUM)%2) == 0)
1308 pass_function_arguments(args, nargs, struct_return, struct_addr, sp)
1312 CORE_ADDR struct_addr;
1315 int ireg = (struct_return) ? R17 : R16;
1321 unsigned long ul_tmp;
1323 unsigned short us_tmp;
1325 unsigned char uc_tmp;
1331 write_register(R16, struct_addr);
1334 arg_ptr = sp; /* Space was allocated for memory argument list in i860_arg_coerce */
1336 /* Loop through the arguments, putting the values in a register or memory as appropriate. */
1338 for (i = 0; i < nargs; i++)
1341 type = VALUE_TYPE(arg);
1342 len = TYPE_LENGTH(type);
1343 if (type == builtin_type_double)
1345 /* see ABI . Note freg MUST BE INCREMENTED even if arg goes into the
1346 memory argument list for this code to work correctly for subsequent
1348 if (!IS_EVEN_REG(freg))
1350 /* see if argument can be put in a register, or whether it must go
1351 into the memory argument list */
1352 if (freg < F8 + NUM_FLOAT_ARG_REGS)
1354 /* It can go in a register */
1355 bcopy(VALUE_CONTENTS(arg), &tmp, sizeof(double));
1356 write_register_bytes(REGISTER_BYTE(freg), (char *) &tmp, TYPE_LENGTH(type));
1361 /* It goes into memory argument list */
1362 arg_ptr = ALIGN_ARG( arg_ptr, sizeof(double));
1363 write_memory (arg_ptr, VALUE_CONTENTS (arg), len);
1368 else if (type == builtin_type_float)
1370 if (freg < F8 + NUM_FLOAT_ARG_REGS)
1372 /* It can go in a register */
1373 bcopy(VALUE_CONTENTS(arg), &tmp, sizeof(long));
1374 write_register_bytes (REGISTER_BYTE(freg), (char *) &tmp, TYPE_LENGTH(type));
1379 /* It goes into the memory argument list */
1380 arg_ptr = ALIGN_ARG(arg_ptr, sizeof(float));
1381 write_memory (arg_ptr, VALUE_CONTENTS (arg), len);
1387 /* All structs are passed by value, and hence they all go into the memory
1388 argument list (see ABI); otherwise, as above, see if we have run
1391 /* Cast value correctly so we can load it into a register or into the
1392 memory argument list -- see ABI */
1393 if (TYPE_LENGTH(type) < sizeof(long))
1395 if (TYPE_FLAGS(type) & TYPE_FLAG_UNSIGNED)
1396 arg = value_cast(builtin_type_unsigned_int, arg);
1398 arg = value_cast (builtin_type_int, arg);
1399 type = VALUE_TYPE(arg);
1400 len = TYPE_LENGTH(type);
1403 if ((TYPE_CODE(type) == TYPE_CODE_STRUCT) || (ireg >= R16 + NUM_INT_ARG_REGS))
1405 /* It goes into the memory argument list. Minimum alignment requirements
1406 are on a 4-byte boundary */
1408 if ((TYPE_CODE(type) == TYPE_CODE_INT) ||
1409 (TYPE_CODE(type) == TYPE_CODE_ENUM) ||
1410 (TYPE_CODE(type) == TYPE_CODE_CHAR) ||
1411 (TYPE_CODE(type) == TYPE_CODE_BOOL))
1412 arg_ptr = ALIGN_ARG(arg_ptr, len);
1414 arg_ptr = ALIGN_ARG (arg_ptr, sizeof(long)); /* align on 4-byte boundary */
1415 write_memory (arg_ptr, VALUE_CONTENTS (arg), len);
1421 bcopy(VALUE_CONTENTS(arg), &tmp, sizeof(long));
1422 write_register(ireg, tmp);
1436 #define P_SPACES " "
1439 int screen_lines=24;
1441 char *spec_reg[] = {
1442 "fsr", "db", "dirbase", "fir", "psr", "epsr",
1445 char *doro_reg[] = {
1446 "scp", "cbsp", "pt_cs", "intmsk", "intack",
1453 char raw_buffer[32];
1457 /* NOTE that only integer and floating point registers can be relative to a frame */
1459 if ((regno >= R0) && (regno <= F31)) /* user register */
1460 read_relative_register_raw_bytes (regno, raw_buffer);
1462 bcopy (®isters[regno << 2], raw_buffer, sizeof (long));
1464 REGISTER_CONVERT_TO_VIRTUAL (addr, raw_buffer, &virtual_buffer);
1465 return(virtual_buffer);
1470 /* This routine is uncalled. Remove it sometime. */
1473 ** Figure out whether we are in a delayed slot and if so then take necessary
1474 ** action to resume properly - remember trap pre-empts instruction
1477 wasabranch (addr, nextpc, ss)
1478 CORE_ADDR addr, *nextpc;
1481 CORE_ADDR nextadr, instr;
1482 int val = not_branch;
1483 long offset; /* Must be signed for sign-extend */
1489 nextadr = CORADR((int)(addr + INSTRUCTION_LENGTH*2));
1490 instr = (unsigned)(adj_read_memory_integer (CORADR(addr)));
1494 nextadr = addr + INSTRUCTION_LENGTH;
1495 instr = (unsigned)(adj_read_memory_integer (addr));
1500 nextadr = CORADR(addr);
1501 instr = (unsigned)(adj_read_memory_integer (nextadr));
1506 instr = (unsigned)(adj_read_memory_integer (addr));
1511 if ((instr & 0xE0000000) == 0x60000000 && /* CTRL format */
1512 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
1514 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
1516 else if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
1518 else if ((instr & 0xF4000000) == 0x70000000) /* bc or bnc */
1521 offset = (instr & 0x03ffffff);
1522 if (offset & 0x02000000) /* sign extend? */
1523 offset |= 0xFC000000;
1524 nextadr += (offset << 2);
1526 else if ((instr & 0xFC00003F) == 0x4C000002 || /* calli */
1527 (instr & 0xFC000000) == 0x40000000) /* bri */
1532 offset = ((instr & 0x0000F800) >> 11);
1533 nextadr = (read_register(offset) & 0xFFFFFFFC);
1538 else if ((instr & 0xF0000000) == 0x50000000) /* bte or btne */
1542 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
1543 nextadr += (offset << 2);
1545 else if ((instr & 0xFC000000) == 0xB4000000) /* bla */
1549 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
1550 nextadr += (offset << 2);
1559 /* i860-specific routine to print the register set. Note that we ALWAYS print information
1560 on the floating point registers, so we ignore the parameter fpregs.
1561 NOTE also that only integer and floating point registers can be relative to a frame --
1562 see subroutine get_reg (above ) */
1564 void i860_do_registers_info(regnum,fpregs)
1575 "Register Contents (relative to selected stack frame)\n\n");
1577 if (regnum != -1) /* print one register */
1579 val = get_reg(regnum);
1580 printf("%-4s 0x%08x\t", reg_names[regnum], val);
1581 printf("\n\t"); fflush(stdout);
1583 else /* print all registers */
1586 printf("\n Control/Status Registers :- \n\t");
1587 for (j=0; j<=DB; j++)
1590 printf("%-4s 0x%08x\t", reg_names[j], val);
1592 printf("\n\t"); fflush(stdout);
1595 val = get_reg(EPSR);
1596 printf("%-4s 0x%08x\t", reg_names[EPSR], val);
1600 printf("%-4s 0x%08x\t", reg_names[FSR], val);
1604 printf("%-4s 0x%08x\t", reg_names[CCR], val);
1606 val = get_reg(BEAR);
1607 printf("%-4s 0x%08x\t", reg_names[BEAR], val);
1611 for (j=P0; j<=P3; j++)
1614 printf("%-4s 0x%08x\t", reg_names[j], val);
1618 printf("\n Integer Registers :- \n\t");
1619 for (j=R0; j<=R31; j++)
1621 if (j != IREGS && (j % REGISTER_LENGTH == 0))
1623 printf("\n\t"); fflush(stdout);
1626 printf("%-4s 0x%08x\t", reg_names[j], val);
1629 printf("\n Floating Registers :- \n\t");
1630 for (j=F0; j<=F31; j++)
1632 if (j != FREGS && (j % REGISTER_LENGTH == 0))
1634 printf("\n\t"); fflush(stdout);
1637 printf("%-4s 0x%08x\t", reg_names[j], val);
1640 printf("\n Special Registers :- \n\t");
1641 for (j=SPC_KI; j<=SPC_MERGE; j+=2)
1646 printf("\n\t"); fflush(stdout);
1649 valh = get_reg(j+1);
1650 printf("%-6s 0x%08x %08x\t", reg_names[j], val,valh);
1653 printf("\n Graphics Pipeline :- \n");
1658 valh = get_reg(j+1);
1659 printf("\t\t\t%-8s 0x%08x %08x \n", reg_names[j], val,valh);
1662 printf(" Memory Load Pipeline :- \n");
1663 for (j=PSV_L1; j<=PSV_L3; j+=REGISTER_LENGTH)
1665 unsigned int valh, val2,val3;
1668 valh = get_reg(j+1);
1669 val2 = get_reg(j+2);
1670 val3 = get_reg(j+3);
1672 printf("\t\t%-8s 0x%08x %08x %08x %08x\n", reg_names[j],
1673 val,valh,val2,val3);
1676 printf("\n Adder Pipeline :-\t\tMultiplier Pipeline :-\t\tFSR results :-\n");
1677 for (i=PSV_FSR1,j=PSV_A1,k=PSV_M1; j<=PSV_A3; i++,j+=2,k+=2)
1679 unsigned int valh,val2,val3,val4;
1683 valh = get_reg(j+1);
1685 val3 = get_reg(k+1);
1687 printf(" %-4s 0x%08x %08x\t", reg_names[j], val,valh);
1688 printf("%-4s 0x%08x %08x\t", reg_names[k], val2,val3);
1689 printf("%-4s 0x%08x\n", reg_names[i], val4);
1699 /* The following set of routines was adapted from existing code previously
1700 in an i860-specific version of breakpoint.c by Peggy Fieland
1702 /* routines to set a data breakpoint by setting the value in the DB register.
1703 Note that "hitting" the breakpoint will generate a data access trap. We
1704 do not have a special trap handler. */
1705 unsigned int dbrkval, dbrkmod;
1706 void i860_dbrk_breakpoint()
1708 BTDEBUG("i860_dbrk_breakpoint was called , dbrkval %x\n", dbrkval);
1712 *(int *)®isters[DB<<2] = dbrkval;
1716 *(int *)®isters[DB<<2] = 0;
1719 *(int *)®isters[PSR<<2] &= ~3;
1720 *(int *)®isters[PSR<<2] |= dbrkmod;
1722 store_inferior_registers(DB);
1723 store_inferior_registers(PSR);
1727 /* set a "read" data breakpoint. */
1729 d_ro_break_command(char *arg, int num)
1731 dbrkval = strtoul(arg, NULL, 0);
1733 BTDEBUG(" ro_dbreak - %x %x\n", dbrkval, dbrkmod);
1736 /* set a "write" data breakpoint. */
1738 d_wo_break_command(char *arg, int num)
1740 dbrkval = strtoul(arg, NULL, 0);
1742 BTDEBUG(" wo_dbreak - %x %x\n", dbrkval, dbrkmod);
1745 /* set a "read/write" data breakpoint. */
1747 d_rw_break_command(char *arg, int num)
1749 dbrkval = strtoul(arg, NULL, 0);
1751 BTDEBUG(" rw_dbreak - %x %x\n", dbrkval, dbrkmod);
1754 /* clear data breakpoint. */
1755 void clear_dbreak(char *arg, int num)
1761 /* i860-specific breakpoint initialization. Includes adding the
1762 i860-specific data breakpoint commands. */
1763 void i860_init_breakpoints()
1765 dbrkval = dbrkmod = 0;
1766 add_com ("dbro", class_breakpoint, d_ro_break_command,
1767 "Set a data breakpoint READ ONLY, 32-bit data element.");
1768 add_com ("dbwo", class_breakpoint, d_wo_break_command,
1769 "Set a data breakpoint WRITE ONLY, 32-bit data element.");
1770 add_com ("dbrw", class_breakpoint, d_rw_break_command,
1771 "Set a data breakpoint READ/WRITE, 32-bit data element.");
1772 add_com ("dclear", class_breakpoint, clear_dbreak,
1773 "clear the current data breakpoint.");
1774 add_com_alias ("dc", "dclear", class_breakpoint, 1);
1778 /* i860-specific code to insert a breakpoint. */
1779 int i860_insert_breakpoint(b)
1780 struct breakpoint *b;
1783 int *shadow0, *shadow1, *shadow2, *shadow3;
1785 shadow0 = (int *)&b->shadow_contents[0];
1786 shadow1 = (int *)&b->shadow_contents[4];
1787 shadow2 = (int *)&b->shadow_contents[8];
1788 shadow3 = (int *)&b->shadow_contents[12];
1790 place_brk( b->address, BREAK_MODE, b );
1795 adj_read_memory (b->act_addr[0], shadow0, INSTRUCTION_LENGTH);
1796 val = adj_write_memory (b->act_addr[0], break_insn, INSTRUCTION_LENGTH);
1797 if (val != 0 ) return val;
1798 adj_read_memory (b->act_addr[1], shadow1, INSTRUCTION_LENGTH);
1799 /* val = adj_write_memory (b->act_addr[1], float_insn, INSTRUCTION_LENGTH); */
1800 if (val != 0) return val;
1804 adj_read_memory (b->act_addr[0], shadow0, INSTRUCTION_LENGTH);
1805 val = adj_write_memory (b->act_addr[0], break_insn, INSTRUCTION_LENGTH);
1807 if (b->address1 != 0)
1812 adj_read_memory (b->act_addr[2], shadow2, INSTRUCTION_LENGTH);
1813 val = adj_write_memory (b->act_addr[2], break_insn, INSTRUCTION_LENGTH);
1814 if (val) return val;
1815 adj_read_memory (b->act_addr[3], shadow3, INSTRUCTION_LENGTH);
1816 /* val = adj_write_memory (b->act_addr[3], float_insn, INSTRUCTION_LENGTH); */
1817 if (val != 0) return val;
1821 adj_read_memory (b->act_addr[2], shadow0, INSTRUCTION_LENGTH);
1822 val = adj_write_memory (b->act_addr[2], break_insn, INSTRUCTION_LENGTH);
1832 int i860_remove_breakpoint(b)
1833 struct breakpoint *b;
1836 int *shadow0, *shadow1, *shadow2, *shadow3;
1838 shadow0 = (int *)&b->shadow_contents[0];
1839 shadow1 = (int *)&b->shadow_contents[4];
1840 shadow2 = (int *)&b->shadow_contents[8];
1841 shadow3 = (int *)&b->shadow_contents[12];
1848 val =adj_write_memory (b->act_addr[0], shadow0,
1849 INSTRUCTION_LENGTH);
1850 val =adj_write_memory (b->act_addr[1],shadow1,
1851 INSTRUCTION_LENGTH);
1852 if (b->address1 != NULL)
1854 val =adj_write_memory (b->act_addr[2],shadow2,
1855 INSTRUCTION_LENGTH);
1856 val =adj_write_memory (b->act_addr[3], shadow3,
1857 INSTRUCTION_LENGTH);
1862 val =adj_write_memory (b->act_addr[0], shadow0,
1863 INSTRUCTION_LENGTH);
1864 if (b->address1 != NULL)
1866 val =adj_write_memory (b->act_addr[2],shadow0,
1867 INSTRUCTION_LENGTH);
1881 #ifdef USE_PROC_FS /* Target dependent support for /proc */
1883 #include <sys/procfs.h>
1886 They were adapted from the m-68k versions of the routines .*/
1888 /* Given a pointer to a floating point register set in /proc format
1889 (fpregset_t *), unpack the register contents and supply them as gdb's
1890 idea of the current floating point register values. */
1893 supply_fpregset (fpregsetp)
1894 fpregset_t *fpregsetp;
1898 BTDEBUG("supply_fregset called \n");
1900 for (regno = F0 ; regno <= F31 ; regno++)
1902 supply_register (regno, (char *) &(fpregsetp -> fpu.r_freg[regno-F0]));
1906 /* Given a pointer to a floating point register set in /proc format
1907 (fpregset_t *), update the register specified by REGNO from gdb's idea
1908 of the current floating point register set. If REGNO is -1, update
1912 fill_fpregset (fpregsetp, regno)
1913 fpregset_t *fpregsetp;
1919 extern char registers[];
1920 BTDEBUG("fill_fregset regno %d\n",regno);
1922 for (regi = F0 ; regi <= F31 ; regi++)
1924 if ((regno == -1) || (regno == regi))
1926 from = (char *) ®isters[REGISTER_BYTE (regi)];
1927 to = (char *) &(fpregsetp -> fpu.r_freg[regi-F0]);
1928 bcopy (from, to, REGISTER_RAW_SIZE (regno));
1934 /* Given a pointer to a general register set in /proc format (gregset_t *),
1935 unpack the register contents and supply them as gdb's idea of the current
1939 supply_gregset (gregsetp)
1940 gregset_t *gregsetp;
1943 register greg_t *regp = (greg_t *) gregsetp;
1945 BTDEBUG("supply_gregset called \n");
1947 for (regno = 0 ; regno <= R31 ; regno++)
1949 supply_register (regno, (char *) (regp + regno));
1953 /* Given a pointer to a general register set in /proc format (gregset_t *),
1954 update the register specified by REGNO from gdb's idea
1955 of the current general register set. If REGNO is -1, update
1959 fill_gregset (gregsetp, regno)
1960 gregset_t *gregsetp;
1964 extern char registers[];
1965 register greg_t *regp = (greg_t *) gregsetp;
1966 BTDEBUG("fill_gregset regno %d \n",regno);
1968 for (regi = 0 ; regi <= R31 ; regi++)
1970 if ((regno == -1) || (regno == regi))
1972 *(regp + regi) = *(int *) ®isters[REGISTER_BYTE (regi)];
1980 /* Push an empty stack frame, to record the current PC, etc. */
1981 /* We have this frame with fp pointing to a block where all GDB-visible
1982 registers are stored in the order GDB knows them, and sp at the next
1983 alignment point below fp. Note: fp + NUM_REGS*4 was the old sp
1985 extern CORE_ADDR text_end;
1986 CORE_ADDR dummy_start_addr;
1987 void i860_push_frame()
1989 register CORE_ADDR old_fp = read_register(FP_REGNUM);
1990 register CORE_ADDR old_sp = read_register(SP_REGNUM);
1991 register CORE_ADDR fp ;
1992 extern char registers[];
1994 fp = old_sp - REGISTER_BYTES;
1995 write_memory(fp, registers, REGISTER_BYTES); /* write out old register values */
1996 /* reset FP and SP */
1997 write_register(FP_REGNUM, fp);
1998 write_register(SP_REGNUM, (fp &~ 15)); /* re-align */
2001 /* Discard from the stack the innermost frame,
2002 restoring all saved registers. */
2004 void i860_pop_frame()
2005 { register FRAME frame = get_current_frame ();
2006 register CORE_ADDR fp;
2007 struct frame_info *fi;
2010 fi = get_frame_info (frame);
2013 if (call_dummy_set && fi -> pc >= call_dummy_start &&
2014 fi -> pc <= call_dummy_start + CALL_DUMMY_LENGTH)
2017 read_memory(fp, registers, REGISTER_BYTES);
2019 target_store_registers(-1);
2022 /* since we stomped on code that will be executed when we exit the program,
2024 extern REGISTER_TYPE call_save_code[4];
2026 write_memory (call_dummy_start, (char *) call_save_code, 16);
2033 register int regnum;
2034 struct frame_saved_regs fsr;
2035 char raw_buffer[12];
2037 get_frame_saved_regs (fi, &fsr);
2038 for (regnum = FP0_REGNUM + 31; regnum >= FP0_REGNUM; regnum--)
2039 if (fsr.regs[regnum])
2040 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4));
2041 for (regnum = R31; regnum >= 1; regnum--)
2042 if (fsr.regs[regnum])
2043 if (regnum != SP_REGNUM)
2044 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4));
2046 write_register (SP_REGNUM, fsr.regs[SP_REGNUM]);
2047 if (fsr.regs[PS_REGNUM])
2048 write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4));
2049 if (fsr.regs[FPS_REGNUM])
2050 write_register (FPS_REGNUM, read_memory_integer (fsr.regs[FPS_REGNUM],4));
2051 if (fsr.regs[PC_REGNUM])
2052 write_register (PC_REGNUM,CLEAN_PC( read_memory_integer (fsr.regs[PC_REGNUM], 4)));
2055 flush_cached_frames ();
2057 set_current_frame (create_new_frame (read_register (FP_REGNUM),
2062 CORE_ADDR i860_arg_coerce(nargs, args, struct_return, sp)
2069 register int scalar;
2070 register enum type_code code2;
2071 register struct type *type;
2074 int num_int_args = 0;
2075 int num_float_args = 0;
2079 /* if we return a structure, it's address is in R16, and thus it uses up one of the integer
2080 argument registers. See the ABI. */
2084 /* loop to do the right thing with all the arguments and calculate the size of the memory
2085 argument list. We keep count of the number of integer and the number of float parameters,
2086 as well as the size of the memory argument list. */
2088 for (i = 0; i < nargs; i++)
2091 /* NOTE that this is all hunky dory in spite of the fact that we don't actually
2092 have the signature of the called procedure EXCEPT if we are passing in floats!
2093 This is true, since registers are 4 bytes, and the minimum alignment in the
2094 memory argument list is 4 bytes. See the ABI for more gory details. The switch
2095 "ansi-conformant" is an attempt to get around this problem. */
2097 code2 = TYPE_CODE (VALUE_TYPE(args[i]));
2099 /* Only coerce if we've got switch "ansi-conformant" off.
2100 Actually, it's OK ( and probably helpful) to coerce ALL integer arguments
2101 (see comment above), but never mind, we make them the right size in
2102 pass_function_arguments. */
2104 if ((!ansi_conformant) && (code2 != TYPE_CODE_STRUCT))
2105 value_arg_coerce(args[i]);
2108 type = VALUE_TYPE(args[i]);
2110 /* All structures are passed by value in the memory argument list. */
2111 if (code2 == TYPE_CODE_STRUCT)
2113 size = ALIGN_ARG(size, sizeof(long));
2114 size += TYPE_LENGTH(type);
2116 else if (type == builtin_type_float)
2118 num_float_args += 1;
2119 if (num_float_args > NUM_FLOAT_ARG_REGS)
2121 size = ALIGN_ARG(size, TYPE_LENGTH(type)) ;
2122 size += TYPE_LENGTH(type);
2125 else if (type == builtin_type_double)
2127 /* floating register alignment -- see ABI */
2128 if ((num_float_args%2) != 0)
2129 num_float_args += 1;
2131 num_float_args += 2; /* use up two registers */
2133 if (num_float_args > NUM_FLOAT_ARG_REGS)
2135 size = ALIGN_ARG(size, TYPE_LENGTH(type)) ;
2136 size += TYPE_LENGTH(type);
2141 int len = max (sizeof(long), TYPE_LENGTH(type));
2145 if (num_int_args > NUM_INT_ARG_REGS)
2147 /* see ABI -- in-memory arguments have AT LEAST word alignment */
2148 if ((TYPE_CODE(type) == TYPE_CODE_INT) ||
2149 (TYPE_CODE(type) == TYPE_CODE_ENUM) ||
2150 (TYPE_CODE(type) == TYPE_CODE_CHAR) ||
2151 (TYPE_CODE(type) == TYPE_CODE_BOOL))
2152 size = ALIGN_ARG(size, len);
2154 size = ALIGN_ARG(size, sizeof(long));
2162 /* recalculate the stack pointer, leaving enough space for the memory argument list and
2163 realigning the stack pointer. */
2166 arg_ptr = sp - size;
2168 arg_ptr = arg_ptr & (-16); /* realign stack */
2169 write_register (R28,arg_ptr);
2176 void i860_extract_return_value(type,regbuf,valbuf)
2178 char regbuf[REGISTER_BYTES];
2181 register int len = TYPE_LENGTH (type);
2185 if ((TYPE_CODE(type) == TYPE_CODE_FLT))
2187 if (len == sizeof (float))
2190 NOTE that this assumes that the function declaration was ANSI_CONFORMANT --
2191 at the present time I can't think of ANY WAY to disambiguate the two following
2193 float really_does_return_a_float(float ff)
2196 float actually_returns_a_double(ff)
2200 bcopy ((char *) (regbuf) + REGISTER_BYTE(ADJ_FREG(F8)), (valbuf), TYPE_LENGTH (type)) ;
2203 bcopy ((char *) (regbuf) + REGISTER_BYTE(F8), (valbuf), TYPE_LENGTH (type)) ;
2206 bcopy ((char *) (regbuf) + REGISTER_BYTE(R16), (valbuf), TYPE_LENGTH (type));
2209 void i860_store_return_value(type,valbuf)
2213 register int len = TYPE_LENGTH (type);
2216 if ((TYPE_CODE(type) == TYPE_CODE_FLT) )
2218 write_register_bytes (REGISTER_BYTE (F8), valbuf, len);
2221 write_register_bytes (REGISTER_BYTE (R16), valbuf, TYPE_LENGTH (type));