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 read_memory();
67 extern int write_memory();
68 extern int read_memory_integer();
69 extern int print_insn();
73 int btdebug = 0; /* change value to 1 to enable debugging code */
76 #define BTDEBUG if (btdebug) btdebug_message
79 extern int attach_flag;
80 extern char registers[];
81 CORE_ADDR get_saved_basereg();
83 #define INSTRUCTION_LENGTH 4
84 #define REGISTER_LENGTH 4
85 #define ALIGN_ARG(size,len) ((size + (len-1))&(-len))
86 #define NUM_FLOAT_ARG_REGS 8
87 #define NUM_INT_ARG_REGS 12
89 /* routine to print debugging messages */
90 void btdebug_message(char *format, ...)
93 va_start( arglist, format );
96 vfprintf (stderr, format, arglist );
101 /* Peggy Fieland. Routine that attempts to find the start of the entry sequence
103 /* maximum number of instrutions to search back */
104 #define MAX_ROUTINE_SIZE 4096
105 CORE_ADDR find_entry_start(pc)
108 CORE_ADDR instr, top_pc;
112 for (i = 0; i < MAX_ROUTINE_SIZE; ++i)
115 instr = (unsigned)( adj_read_memory_integer (top_pc));
116 /* Recognize "addu|adds -X,sp,sp" insn. */
118 if ((instr & 0xEFFF0000) == 0x84420000)
122 top_pc -= INSTRUCTION_LENGTH;
130 /* get the contents of a base register. Used for dwarf OP_BASEREG */
131 /* At present, only OP_BASEREG generated is for R28. NOTE that for stuff based on R28,
132 the value we want is the VALUE AT PROCEDURE INVOKATION, and thus is the frame we
133 use to get the value is the caller's frame. */
134 CORE_ADDR get_saved_basereg (frame, basereg)
139 if (basereg == R28) /* Unconditionally ??? */
141 frame = get_prev_frame (frame);
142 get_saved_register((char *) &addr, (int *) NULL, (CORE_ADDR *) NULL, frame,
143 basereg, (enum lval_type *)NULL);
147 get_saved_register((char *) &addr, (int *) NULL, (CORE_ADDR *) NULL, frame,
148 basereg, (enum lval_type *)NULL);
155 /* return nonzero if the routine containing pc has been
156 * compiled with -g. We assume -g if the first instruction is
157 * an addu|adds -X,sp and the second is st.l fp,XX(sp)
159 * based on skip_prologue();
162 static int g_routine(pc)
169 top_pc = get_pc_function_start(pc);
171 top_pc = find_entry_start (pc);
175 instr = (unsigned)( adj_read_memory_integer (top_pc));
176 /* Recognize "addu|adds -X,sp,sp" insn. */
178 if ((instr & 0xEFFF0000) == 0x84420000)
180 top_pc += INSTRUCTION_LENGTH;
181 instr = (unsigned)(adj_read_memory_integer (top_pc));
183 if( (instr & 0xFFE0F801) == 0x1C401801 ) /* st.l fp,X(sp) */
191 /* return the stack offset where the fp register is stored */
192 static int find_fp_offset(pc)
198 /* look for the instruction and examine the offset */
200 for (i=INSTRUCTION_LENGTH*1; i< INSTRUCTION_LENGTH*4; i+=INSTRUCTION_LENGTH){
201 instr = (unsigned)(adj_read_memory_integer(pc+i));
202 if( (instr & 0xFFE0F801) == 0x1C401801) { /* st.l fp,X(sp) */
204 fp_off = SIGN_EXT16(((instr&0x001F0000) >> 5) |
213 /* return the stack offset where r1 (return linkage ) register is stored */
214 static CORE_ADDR find_r1(pc,sp,fp)
218 CORE_ADDR instr, ret_pc;
220 /* look for the instruction and examine the offset */
222 for (i=INSTRUCTION_LENGTH*1; i< INSTRUCTION_LENGTH*4; i+=INSTRUCTION_LENGTH)
224 instr = (unsigned)( adj_read_memory_integer(pc+i));
225 if ((instr & 0xFFE0F801) == 0x1C400801)
229 r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) |
231 ret_pc = read_memory_integer(sp+r1_off,sizeof(long));
234 else if ((instr & 0xFFE0F801) == 0x1C600801)
237 r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) |
239 ret_pc = read_memory_integer(fp+r1_off,sizeof(long));
246 CORE_ADDR skip_prologue(CORE_ADDR);
248 /* does routine starting at pc build a stack frame of any kind?? */
249 static int has_a_frame(pc)
252 if( skip_prologue(pc) != pc )return(1);
258 Routine to validate the return register and the frame pointer
259 This routine is called when the routine we are in doesn't have a frame
260 In that case, we assume that the return address and frame pointer have
261 not been touched. In the following routine, we try to range check them
262 to see if they are valid. */
264 static int valid_regs (rp, fp)
267 if ( ( (rp % 4) != 0) | ( (fp % 16) != 0) )
272 /* get the pc and frame pointer (or sp )
273 * for the routine that called us
274 * when we (this_pc) is not within a -g routine
275 * if caller is non g we return sp for fp
278 /* note this is written for Metaware version R2.1d compiler */
280 static int caller_pc(this_pc,this_sp,this_fp,to_pc,to_fp, called_from_frame_chain)
281 CORE_ADDR this_pc,this_sp, this_fp;
282 CORE_ADDR *to_pc, *to_fp;
283 int called_from_frame_chain;
285 CORE_ADDR func_start;
286 int sp_offset,offset;
287 CORE_ADDR sp,pc,fp,instr;
289 BTDEBUG("caller_pc %x sp = %x\n",this_pc,this_sp);
291 func_start = get_pc_function_start(this_pc);
293 if (func_start == NULL)
294 func_start = find_entry_start (this_pc);
296 BTDEBUG("caller_pc func_start %x\n", func_start);
298 if ((func_start == NULL))
300 /* error in traceback */
301 fprintf(stderr, "error, unable to find start of function\n");
306 if (func_start!= NULL)
308 if( has_a_frame(func_start) ){
310 BTDEBUG("has_a_frame\n");
312 /* if our caller has a preamble and
313 * declares space for a stack frame
314 * then we must work to find our return address
316 instr = (unsigned)( adj_read_memory_integer (func_start));
317 /* Recognize "addu|adds -X,sp,sp" insn. */
319 if ((instr & 0xEFFF0000) == 0x84420000)
320 sp_offset=SIGN_EXT16(instr&0x0000FFFF);
324 /* if we get here, procedure doesn't have a frame. If we
325 do anything weird, the frame pointer and return register have
326 the values we want. Check them to see if they are valid. */
328 CORE_ADDR temp_rp, temp_fp;
330 /* temporary warning, since at the moment we don't have support for
331 the shared library */
333 temp_rp = read_register(RP_REGNUM);
334 temp_fp = read_register(FP_REGNUM);
336 if (!valid_regs(temp_rp, temp_fp))
339 "error - unable to find return address, traceback terminating\n");
342 BTDEBUG("caller_pc no frame, using r1 %x and fp %x\n",
349 BTDEBUG("sp_offset = %d %x\n",sp_offset,sp_offset);
351 pc = find_r1(func_start, this_sp, this_fp);
356 /* r1 wasn't stored between pc and function start */
357 pc = read_register (RP_REGNUM);
360 sp= this_sp - sp_offset;
362 BTDEBUG("callers pc = %x sp = %x\n",pc,sp);
364 /* our caller a -g routine ?
365 * if he is we have to find his real fp
366 * else provide the sp as his fp
371 BTDEBUG("caller_a_g\n");
373 if( ! (offset = find_fp_offset(func_start)) ) {
374 fprintf(stderr, "error - unable to find caller frame for routine at 0x%x, "
375 "traceback terminating\n", func_start);
378 BTDEBUG("offset = %x %d\n",offset,offset);
380 fp = read_memory_integer(this_sp+offset,sizeof(long));
381 *to_pc = CLEAN_PC(pc);
385 *to_pc = CLEAN_PC(pc);
389 /* pc = read_register(RP_REGNUM); */
391 /* if we get here, procedure doesn't have a frame. If we didn't
392 do anything weird, the frame pointer and return register have
393 the values we want. Check them to see if they are valid. */
395 CORE_ADDR temp_rp, temp_fp;
397 temp_rp = read_register(RP_REGNUM);
398 temp_fp = read_register(FP_REGNUM);
400 if (!valid_regs(temp_rp, temp_fp))
403 "error - unable to find return address, traceback terminating\n");
407 BTDEBUG("caller_pc no frame, using r1 %x and fp %x\n",
416 ** Figure out address to place next breakpoint. Avoid tricky spots,
417 ** ie. delayed instruction slots etc.
418 ** Need to upgrade this later to allow delayed instruction breakpoints
419 ** with fix-up work done AFTER breakpoint.
420 ** Note that this routine DOES deal with dual instruction mode
425 place_brk (addr, mode, brk)
428 struct breakpoint *brk;
431 CORE_ADDR nextadr, prevadr;
432 int val = not_branch;
433 long offset; /* Must be signed for sign-extend */
434 prevadr = nextadr = 0;
438 if (mode == SINGLE_STEP_MODE)
442 nextadr = brk->address = (addr + INSTRUCTION_LENGTH*2);
443 instr = (unsigned)(adj_read_memory_integer ((addr + INSTRUCTION_LENGTH)));
448 nextadr = brk->address = (addr + INSTRUCTION_LENGTH);
449 instr = (unsigned)(adj_read_memory_integer (addr));
458 ** For br/call one more sequential instruction gets executed and then we
459 ** continue at the current addr + offset. We are definitely going to
460 ** the dest. We are NOT allowed to place a breakpoint in the "delay"
461 ** slot - (the next sequential instruction) so we only place 1 breakpoint
462 ** at the destination.
463 ** For the bc/bnc the next instruction executed is EITHER the next sequential
464 ** or the destination of the branch, we therefore place 2 breakpoints one
466 ** For the bc.t/bnc.t either 1 more sequential instruction is performed
467 ** followed by a branch (like br/call) OR we skip the sequential
468 ** instruction and keep going. We therefore place a breakpoint at the
469 ** destination of the branch AND the second sequential instruction after
470 ** the branch. Again a breakpoint is NOT allowed in the "delay slot"
472 if ((instr & 0xE0000000) == 0x60000000 && /* CTRL format */
473 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
475 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
477 else if ((instr & 0xF4000000) == 0x74000000) /* bc.t/bnc.t */
479 else if ((instr & 0xF4000000) == 0x70000000) /* bc or bnc */
481 offset = (instr & 0x03ffffff);
482 if (offset & 0x02000000) /*?sign extend*/
483 offset |= 0xFC000000;
484 if (val == uncond_d) /* br/call*/
486 else if (val == cond_d) /* bc.t/bnc.t */
488 if ((INDIM) && !(ENDIM))
489 prevadr = nextadr + (2*INSTRUCTION_LENGTH);
491 prevadr = nextadr + INSTRUCTION_LENGTH;
492 } else { /* bc /bnc */
493 if ((INDIM) && !(ENDIM))
498 nextadr += (offset << 2);
501 ** We treat the bri/calli the same way as the br/call case.
503 else if ((instr & 0xFC00003F) == 0x4C000002 || /* calli */
504 (instr & 0xFC000000) == 0x40000000) /* bri */
507 offset = ((instr & 0x0000F800) >> 11);
508 nextadr = (read_register(offset + R0) & 0xFFFFFFFC);
512 ** We treat the bte/btne the same way as the bc/bnc case.
514 else if ((instr & 0xF0000000) == 0x50000000) /* bte/btne */
517 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) |
518 (instr & 0x000007FF));
519 if ((INDIM) && !(ENDIM))
524 nextadr += (offset << 2);
527 ** We treat the bte/btne the same way as the bc/bnc case.
528 ** With the caveat that the 2 breakpoints may turn out to be at the same
529 ** address in which case we ignore one of them.
531 else if ((instr & 0xFC000000) == 0xB4000000) /* bla */
534 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) |
535 (instr & 0x000007FF));
536 if ((INDIM) && !(ENDIM))
538 prevadr = nextadr + 2*INSTRUCTION_LENGTH;
540 prevadr = nextadr + INSTRUCTION_LENGTH;
542 nextadr += (offset << 2);
543 if (prevadr == nextadr) prevadr = 0;
550 if (ISDIM(FOPADR(addr)))
552 if (ISDIM(FOPADR(nextadr- INSTRUCTION_LENGTH*2)))
554 instr = (unsigned)(adj_read_memory_integer(CORADR(addr
555 -(INSTRUCTION_LENGTH*2))));
558 instr = (unsigned)(adj_read_memory_integer(addr-INSTRUCTION_LENGTH));
562 if (ISDIM(addr-INSTRUCTION_LENGTH))
564 instr = (unsigned)(adj_read_memory_integer(addr-INSTRUCTION_LENGTH));
567 instr = (unsigned)(adj_read_memory_integer (addr-INSTRUCTION_LENGTH));
572 /* examine the PREVIOUS instruction to determine if we are in a branch delay
573 slot. If we are, dont set a break here -- set it on the previous instruction.
574 This code also accounts for dual instruction mode */
575 if ((instr & 0xE0000000) == 0x60000000 &&
576 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
582 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
583 BTDEBUG(" Breakpoint adjusted to avoid br/call delay slot and multiple breakpoints\n");
585 if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
586 BTDEBUG(" Breakpoint adjusted to avoid bc.t/bnc.t delay slot and"
587 "multiple breakpoints\n");
589 /* it IS really OK to set a break on the instruction AFTER the conditional branch
590 -- it DOESN't have a delay slot */
591 if ((instr & 0xF4000000) == 0x70000000) /* bc / bnc */
594 ((instr & 0xFC00003F) == 0x4C000002 || /* bri/ calli */
595 (instr & 0xFC000000) == 0x40000000)
598 BTDEBUG(" Breakpoint adjusted to avoid calli/bri delay slot and"
599 " multiple breakpoints\n");
601 ((instr & 0xF0000000) == 0x50000000) /* bte - btne */
603 /* it's OK to set a break here -- we are NOT in aa branch delay slot */
606 printf(" Breakpoint adjusted to avoid bte/btne multiple breakpoints\n");
610 ((instr & 0xFC000000) == 0xB4000000)
613 BTDEBUG(" Breakpoint adjusted to avoid bla delay slot and"
614 " multiple breakpoints\n");
618 if (brk->mode == DIM)
620 nextadr -= INSTRUCTION_LENGTH*2;
621 nextadr = CORADR(nextadr);
624 nextadr -= INSTRUCTION_LENGTH;
629 if (brk->mode == RIM)
631 if (brk->mode == BIM)
636 if (brk->mode == DIM)
638 brk->act_addr[0] = CORADR(nextadr);
639 brk->act_addr[1] = FOPADR(nextadr);
641 brk->act_addr[0] = nextadr;
642 brk->act_addr[1] = 0;
648 brk->address1 = prevadr;
649 if (brk->mode == DIM)
651 brk->act_addr[2] = CORADR(prevadr);
652 brk->act_addr[3] = FOPADR(prevadr);
654 brk->act_addr[2] = prevadr;
655 brk->act_addr[3] = 0;
658 brk->act_addr[2] = brk->act_addr[3] = 0;
663 /* This routine checks to see if r1 has been stored into the frame between
664 the addresses prologue_start and prologue_end. Recognize stores of r1
665 relative to both the sp and fp registers. */
666 static int has_stored_r1(CORE_ADDR prologue_start, CORE_ADDR prologue_end)
671 BTDEBUG("has_stored_r1, prologue_start %x, prologue_end %x\n",
672 prologue_start, prologue_end);
674 for (addr = prologue_start; addr <= prologue_end; addr += INSTRUCTION_LENGTH)
677 instr = (unsigned)(adj_read_memory_integer (addr));
678 if ((instr & 0xFFE0F801) == 0x1C400801 /* st.l r1,X(sp) */
679 || (instr & 0xFFE0F801) == 0x1C600801) /* st.l r1,X(fp) */
684 /* This is used when GDB is exiting. It gives less chance of error.*/
687 /* Simulate single-step ptrace call for sun4. Code written by Gary
692 static struct breakpoint brk;
693 typedef char binsn_quantum[sizeof break_insn];
695 /* Non-zero if we just simulated a single-step ptrace call. This is
696 needed because we cannot remove the breakpoints in the inferior
697 process until after the `wait' in `wait_for_inferior'. Used for
702 /* single_step() is called just before we want to resume the inferior,
703 if we want to single-step it but there is no hardware or kernel single-step
704 support. We find all the possible targets of the coming instruction and
707 single_step is also called just after the inferior stops. If we had
708 set up a simulated single-step, we undo our damage. */
709 /* Note that we don't need the parameter, but it's dictated as part of the interface. */
715 branch_type place_brk();
716 int *shadow0, *shadow1, *shadow2, *shadow3;
718 shadow0 = (int *) &brk.shadow_contents[0];
719 shadow1 = (int *) &brk.shadow_contents[4];
720 shadow2 = (int *) &brk.shadow_contents[8];
721 shadow3 = (int *) &brk.shadow_contents[12];
722 pc = read_register (PC_REGNUM);
727 place_brk (pc, SINGLE_STEP_MODE, &brk);
728 *shadow0 = *shadow1 = *shadow2 = *shadow3 = 0;
734 btdebug_message(" DIM1 -> %x : ", brk.act_addr[3]);
735 print_insn( brk.act_addr[3], stderr);
736 btdebug_message("\t -|- %x : ", brk.act_addr[2]);
737 print_insn( brk.act_addr[2], stderr);
738 btdebug_message("\n");
740 if (( brk.address1 != NULL))
742 adj_read_memory (brk.act_addr[2], shadow2,
744 adj_write_memory (brk.act_addr[2], break_insn, INSTRUCTION_LENGTH);
745 adj_read_memory (brk.act_addr[3], shadow3,
747 /* adj_write_memory (brk.act_addr[3], float_insn,
748 INSTRUCTION_LENGTH); */
753 if ( brk.address1 != 0)
754 btdebug_message(" DIM2 ->");
756 btdebug_message(" DIM1 ->");
758 btdebug_message(" %x : ", brk.act_addr[1]);
759 print_insn( brk.act_addr[1], stderr);
760 btdebug_message("\t -|- %x : ", brk.act_addr[0]);
761 print_insn( brk.act_addr[0], stderr);
762 btdebug_message("\n");
765 adj_read_memory (brk.act_addr[0], shadow0,
767 adj_write_memory (brk.act_addr[0], break_insn,
769 adj_read_memory (brk.act_addr[1], shadow1,
771 /* adj_write_memory (brk.act_addr[1], float_insn,
772 INSTRUCTION_LENGTH); */
776 if (brk.address1 != NULL)
780 btdebug_message(" SIM1 ->");
781 btdebug_message(" %x : ", brk.act_addr[2]);
782 print_insn( brk.act_addr[2], stderr);
783 btdebug_message("\n");
785 adj_read_memory (brk.act_addr[2], shadow2,
787 adj_write_memory (brk.act_addr[2], break_insn, INSTRUCTION_LENGTH);
791 if ( brk.address1 != NULL)
792 btdebug_message(" SIM2 ->");
794 btdebug_message(" SIM1 ->");
796 btdebug_message(" %x : ", brk.act_addr[0]);
797 print_insn( brk.act_addr[0], stderr);
798 btdebug_message("\n");
800 adj_read_memory (brk.act_addr[0], shadow0,
802 adj_write_memory (brk.act_addr[0], break_insn,INSTRUCTION_LENGTH);
811 /* Remove breakpoints */
814 adj_write_memory (brk.act_addr[0], shadow0,
816 adj_write_memory (brk.act_addr[1], shadow1,
819 adj_write_memory (brk.act_addr[0], shadow0,
823 if (brk.address1 != NULL)
827 adj_write_memory (brk.act_addr[2], shadow2,
829 adj_write_memory (brk.act_addr[3], shadow3,
832 adj_write_memory (brk.act_addr[2], shadow2,
845 /* This routine returns the first memory address following the prologue code,
846 if there is a prologue. */
848 struct command_line *get_breakpoint_commands ();
857 instr = (unsigned)(adj_read_memory_integer (pc));
859 /* Recognize "addu|adds -X,sp,sp" insn. */
860 if ((instr & 0xEFFF0000) == 0x84420000)
862 pc += INSTRUCTION_LENGTH;
863 instr = (unsigned)(adj_read_memory_integer (pc));
866 return(pc); /* No frame! */
868 /* Recognize store of return addr and frame pointer into frame */
871 if ((instr & 0xFFE0F801) == 0x1C400801 || /* st.l r1,X(sp) */
872 (instr & 0xFFE0F801) == 0x1C401801) /* st.l fp,X(sp) */
874 pc += INSTRUCTION_LENGTH;
875 instr = (unsigned)(adj_read_memory_integer (pc));
881 /* Recognize "addu|adds X,sp,fp" insn. */
882 if ((instr & 0xEFFF0000) == 0x84430000)
884 pc += INSTRUCTION_LENGTH;
885 instr = (unsigned)(adj_read_memory_integer (pc));
888 /* Now recognize stores into the frame from the registers. */
892 if ((instr & 0xFFA00003) == 0x1C200001 || /* st.l rn,X(fp|sp) */
893 (instr & 0xFFA00001) == 0x4C200000) /* fst.y fn,X(fp|sp) */
895 regno = (instr >> 11) & 0x1f;
896 if (regno == 0) /* source reg == 0? quit */
898 pc += INSTRUCTION_LENGTH;
899 instr = (unsigned)(adj_read_memory_integer (pc));
909 /* This routine is uncalled. Remove it sometime. */
910 /* Set *nextpc to branch target if we find a branch. If it is not a branch,
911 set it to the next instruction (addr + 4) */
915 isabranch (addr, nextpc)
916 CORE_ADDR addr, *nextpc;
919 branch_type val = not_branch;
920 long offset; /* Must be signed for sign-extend */
922 BTDEBUG(" isabranch\n");
924 instr = (unsigned)(adj_read_memory_integer (addr));
926 if ((instr & 0xE0000000) == 0x60000000 && /* CTRL format */
927 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
929 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
931 else if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
933 else if ((instr & 0xF4000000) == 0x70000000) /* bc or bnc */
936 offset = (instr & 0x03ffffff);
937 if (offset & 0x02000000) /* sign extend? */
938 offset |= 0xFC000000;
939 *nextpc = addr + 4 + (offset << 2);
941 else if ((instr & 0xFC00003F) == 0x4C000002 || /* calli */
942 (instr & 0xFC000000) == 0x40000000) /* bri */
945 offset = ((instr & 0x0000F800) >> 11);
946 *nextpc = (read_register(offset) & 0xFFFFFFFC);
948 else if ((instr & 0xF0000000) == 0x50000000) /* bte or btne */
952 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
953 *nextpc = addr + 4 + (offset << 2);
955 else if ((instr & 0xFC000000) == 0xB4000000) /* bla */
959 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
960 *nextpc = addr + 4 + (offset << 2);
963 BTDEBUG(" Final addr - %x\n", *nextpc);
964 /*BTDEBUG("isabranch ret: %d\n",val); */
969 /* set in call_function() [valops.c] to the address of the "call dummy" code
970 so dummy frames can be easily recognized; also used in wait_for_inferior()
971 [infrun.c]. When not used, it points into the ABI's 'reserved area' */
973 CORE_ADDR call_dummy_set = 0; /* true if dummy call being done */
974 CORE_ADDR call_dummy_start; /* address of call dummy code */
976 /* this routine routine gets the values of the registers stored in the frame
977 and stores their values into the frame_saved_regs structure. */
980 frame_find_saved_regs(frame_info, frame_saved_regs)
981 struct frame_info *frame_info;
982 struct frame_saved_regs *frame_saved_regs;
984 register CORE_ADDR pc;
986 long offset, spdelta = 0;
988 int r1_off = -1, fp_off = -1;
991 bzero (frame_saved_regs, sizeof(*frame_saved_regs));
993 if (call_dummy_set && frame_info->pc >= call_dummy_start &&
994 frame_info->pc <= call_dummy_start + CALL_DUMMY_LENGTH)
996 /* DUMMY frame - all registers stored in order at fp; old sp is
997 at fp + NUM_REGS*4 */
999 for (i = 1; i < NUM_REGS; i++) /* skip reg 0 */
1000 /* the register numbers used in the instruction and the ones used to index
1001 the regs array are not the same -- compensate */
1002 frame_saved_regs->regs[i+R0] = frame_info->frame + i*REGISTER_LENGTH;
1008 pc = get_pc_function_start (frame_info->pc);
1010 pc = find_entry_start (frame_info->pc);
1014 instr = (unsigned)(adj_read_memory_integer (pc));
1015 /* Recognize "addu|adds -X,sp,sp" insn. */
1016 if ((instr & 0xEFFF0000) == 0x84420000)
1018 framesize = -SIGN_EXT16(instr & 0x0000FFFF);
1019 pc += INSTRUCTION_LENGTH;
1020 instr = (unsigned)(adj_read_memory_integer (pc));
1024 goto punt; /* No frame! */
1026 /* Recognize store of return addr and frame pointer into frame */
1029 if ((instr & 0xFFE0F801) == 0x1C400801) /* st.l r1,X(sp) */
1031 r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
1032 pc += INSTRUCTION_LENGTH;
1033 instr = (unsigned)(adj_read_memory_integer (pc));
1035 else if ((instr & 0xFFE0F801) == 0x1C401801) /* st.l fp,X(sp) */
1037 fp_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
1038 pc += INSTRUCTION_LENGTH;
1039 instr = (unsigned)(adj_read_memory_integer (pc));
1045 /* Recognize "addu|adds X,sp,fp" insn. */
1046 if ((instr & 0xEFFF0000) == 0x84430000)
1048 spdelta = SIGN_EXT16(instr & 0x0000FFFF);
1049 pc += INSTRUCTION_LENGTH;
1050 instr = (unsigned)(adj_read_memory_integer (pc));
1053 /* Now recognize stores into the frame from the registers. */
1057 if ((instr & 0xFFC00003) == 0x1C400001) /* st.l rn,X(fp|sp) */
1059 offset = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
1060 reg = (instr >> 11) & 0x1F;
1063 if ((instr & 0x00200000) == 0) /* was this using sp? */
1064 if (spdelta != 0) /* and we know sp-fp delta */
1065 offset -= spdelta; /* if so, adjust the offset */
1067 break; /* if not, give up */
1070 /* Handle the case where the return address is stored after the fp
1074 frame_saved_regs->regs[PC_REGNUM] = frame_info->frame + offset;
1076 frame_saved_regs->regs[reg+R0] = frame_info->frame + offset;
1078 pc += INSTRUCTION_LENGTH;
1079 instr = (unsigned)(adj_read_memory_integer (pc));
1081 else if ((instr & 0xFFC00001) == 0x2C400000) /* fst.y fn,X(fp|sp) */
1084 * The number of words in a floating store based on 3 LSB of instr
1086 static int fst_sizes[] = {2, 0, 1, 0, 4, 0, 1, 0};
1088 size = fst_sizes[instr & 7];
1089 reg = ((instr >> 16) & 0x1F) + FP0_REGNUM;
1093 if (size > 1) /* align the offset */
1094 offset = SIGN_EXT16(instr & 0x0000FFF8); /* drop 3 bits */
1096 offset = SIGN_EXT16(instr & 0x0000FFFC); /* drop 2 bits */
1098 if ((instr & 0x00200000) == 0) /* was this using sp? */
1099 if (spdelta != 0) /* and we know sp-fp delta */
1100 offset -= spdelta; /* if so, adjust the offset */
1102 break; /* if not, give up */
1104 for (i = 0; i < size; i++)
1106 frame_saved_regs->regs[reg] = frame_info->frame + offset;
1108 offset += REGISTER_LENGTH;
1112 pc += INSTRUCTION_LENGTH;
1113 instr = (unsigned)(adj_read_memory_integer (pc));
1120 if (framesize != 0 && spdelta != 0)
1121 frame_saved_regs->regs[SP_REGNUM] = frame_info->frame+(framesize-spdelta);
1123 frame_saved_regs->regs[SP_REGNUM] = frame_info->frame + 8;
1125 if ((spdelta != 0) && fp_off != -1)
1126 frame_saved_regs->regs[FP_REGNUM] = frame_info->frame - spdelta + fp_off;
1128 frame_saved_regs->regs[FP_REGNUM] = frame_info->frame;
1130 if ((spdelta != 0) && r1_off != -1)
1131 frame_saved_regs->regs[PC_REGNUM] = frame_info->frame - spdelta + r1_off;
1133 frame_saved_regs->regs[PC_REGNUM] = frame_info->frame + 4;
1137 /* get the frame pointer of the caller.
1138 * note that only routines that have been compiled with
1139 * -g have full (XX)fp style stack frames
1140 * if we are not returning to a non -g caller then we
1141 * return the sp at entry to us as it is the caller's
1145 frame_chain(thisframe)
1149 CORE_ADDR func_start;
1152 CORE_ADDR thisfp = thisframe->frame;
1153 struct frame_saved_regs fsr;
1156 /* get the frame pointer actually sp for a non -g
1157 * for the routine that called us routine
1160 BTDEBUG("FRAME_CHAIN(%x)\n",thisframe);
1162 if ( !read_memory_integer (thisframe->frame,sizeof(long)) )
1167 if( ! g_routine(thisframe->pc) ){
1168 thissp = get_saved_basereg (thisframe, SP_REGNUM);
1170 BTDEBUG( "non g at %x\n",thisframe->pc);
1171 caller_pc(thisframe->pc, thissp, thisfp,&pc,&fp, 1);
1172 BTDEBUG("caller_pc returned %x %x \n",pc,fp);
1175 }/* else a -g routine */
1178 fp = read_memory_integer (thisfp, sizeof(long));
1180 if (fp < thisfp || fp > (unsigned) STACK_END_ADDR)
1182 /* handle the Metaware-type pseudo-frame */
1184 func_start = get_pc_function_start(thisframe->pc);
1185 if (func_start == NULL)
1186 func_start = find_entry_start (thisframe->pc);
1188 if (func_start != NULL)
1191 instr = (unsigned)(adj_read_memory_integer (func_start));
1192 /* Recognize "addu|adds -X,sp,sp" insn. */
1193 if ((instr & 0xEFFF0000) == 0x84420000)
1194 offset = SIGN_EXT16(instr & 0x0000FFFF);
1200 fp = thisfp - offset;
1202 BTDEBUG("frame_chain returned %d\n",fp);
1206 /* This function returns 1 if there is no stored r1, 0 otherwise.
1207 The function returns 1 if the pc is in a function prologue,
1208 or the function prologue didn't save the return pointer in
1209 the stack frame, 0 otherwise */
1211 int no_stored_rp(CORE_ADDR pc)
1213 CORE_ADDR func_start, prologue_end;
1215 func_start = get_pc_function_start(pc);
1216 if (func_start == NULL)
1217 func_start = find_entry_start (pc);
1219 if (func_start != NULL)
1221 prologue_end = func_start;
1222 SKIP_PROLOGUE(prologue_end);
1223 if ( (pc >= func_start) && (pc <= prologue_end))
1225 BTDEBUG("no_stored_rp: pc %x is in prologue \n",pc);
1228 /* otherwise, see if the entry sequence stored the return pointer.
1229 If it didn't, return 1 */
1230 /* Some procedures , at least, store the return pointer AFTER
1231 the prologue sequence, so check for stores from function start to
1232 present pc value. */
1233 if (!has_stored_r1(func_start, pc))
1235 BTDEBUG("no_stored_rp, for pc %x, prologue didn't store r1\n",pc);
1239 BTDEBUG("no_stored_rp for pc %x return pointer was stored \n", pc);
1244 /* get the PC of the caller */
1245 CORE_ADDR frame_saved_pc(frame_struct)
1253 struct frame_saved_regs fsr;
1255 frame = frame_struct->frame;
1256 pc = frame_struct->pc;
1259 BTDEBUG("frame_saved_pc input: frame %x, pc %x",
1262 /* First see if this is the current frame. If it is, return the value in r1,
1263 as it may not have been stored */
1265 fp = read_register(FP_REGNUM);
1267 /* check to see if we are in an entry sequence, where the return pointer has not yet been stored */
1268 if (fp == frame && no_stored_rp(pc))
1270 pc = read_register(RP_REGNUM);
1271 frame_struct->rp = pc;
1273 else if( ! g_routine(pc) )
1275 sp = get_saved_basereg (frame_struct, SP_REGNUM);
1277 caller_pc(pc,sp,frame_struct->frame, &pc,&frame, 0);
1282 pc = read_memory_integer (frame + 4, sizeof(long));
1284 if (inside_entry_file(pc))
1287 BTDEBUG("pc %x outside entry file \n",pc);
1289 pc1 = read_memory_integer (frame, sizeof(long));
1291 if (!inside_entry_file(pc1))
1297 BTDEBUG(" returning pc %x\n", CLEAN_PC(pc));
1298 return(CLEAN_PC(pc));
1302 /* Pass arguments to a function in the inferior process - ABI compliant
1304 for newer ABI conventions. Note that now, unfortunately, we MUST KNOW
1305 if we expect a float or a double. For now, we will assume that the
1306 caller of this routine has the types of these arguments correct....
1307 NOTE THAT THIS ROUTINE DOES NO ARGUMENT COERCION -- it's all in the
1309 Modified by Peggy Fieland to handle memory argument lists.
1312 #define IS_EVEN_REG(fl) (((fl - FP0_REGNUM)%2) == 0)
1314 pass_function_arguments(args, nargs, struct_return, struct_addr, sp)
1318 CORE_ADDR struct_addr;
1321 int ireg = (struct_return) ? R17 : R16;
1327 unsigned long ul_tmp;
1329 unsigned short us_tmp;
1331 unsigned char uc_tmp;
1337 write_register(R16, struct_addr);
1340 arg_ptr = sp; /* Space was allocated for memory argument list in i860_arg_coerce */
1342 /* Loop through the arguments, putting the values in a register or memory as appropriate. */
1344 for (i = 0; i < nargs; i++)
1347 type = VALUE_TYPE(arg);
1348 len = TYPE_LENGTH(type);
1349 if (type == builtin_type_double)
1351 /* see ABI . Note freg MUST BE INCREMENTED even if arg goes into the
1352 memory argument list for this code to work correctly for subsequent
1354 if (!IS_EVEN_REG(freg))
1356 /* see if argument can be put in a register, or whether it must go
1357 into the memory argument list */
1358 if (freg < F8 + NUM_FLOAT_ARG_REGS)
1360 /* It can go in a register */
1361 bcopy(VALUE_CONTENTS(arg), &tmp, sizeof(double));
1362 write_register_bytes(REGISTER_BYTE(freg), (char *) &tmp, TYPE_LENGTH(type));
1367 /* It goes into memory argument list */
1368 arg_ptr = ALIGN_ARG( arg_ptr, sizeof(double));
1369 write_memory (arg_ptr, VALUE_CONTENTS (arg), len);
1374 else if (type == builtin_type_float)
1376 if (freg < F8 + NUM_FLOAT_ARG_REGS)
1378 /* It can go in a register */
1379 bcopy(VALUE_CONTENTS(arg), &tmp, sizeof(long));
1380 write_register_bytes (REGISTER_BYTE(freg), (char *) &tmp, TYPE_LENGTH(type));
1385 /* It goes into the memory argument list */
1386 arg_ptr = ALIGN_ARG(arg_ptr, sizeof(float));
1387 write_memory (arg_ptr, VALUE_CONTENTS (arg), len);
1393 /* All structs are passed by value, and hence they all go into the memory
1394 argument list (see ABI); otherwise, as above, see if we have run
1397 /* Cast value correctly so we can load it into a register or into the
1398 memory argument list -- see ABI */
1399 if (TYPE_LENGTH(type) < sizeof(long))
1401 if (TYPE_FLAGS(type) & TYPE_FLAG_UNSIGNED)
1402 arg = value_cast(builtin_type_unsigned_int, arg);
1404 arg = value_cast (builtin_type_int, arg);
1405 type = VALUE_TYPE(arg);
1406 len = TYPE_LENGTH(type);
1409 if ((TYPE_CODE(type) == TYPE_CODE_STRUCT) || (ireg >= R16 + NUM_INT_ARG_REGS))
1411 /* It goes into the memory argument list. Minimum alignment requirements
1412 are on a 4-byte boundary */
1414 if ((TYPE_CODE(type) == TYPE_CODE_INT) ||
1415 (TYPE_CODE(type) == TYPE_CODE_ENUM) ||
1416 (TYPE_CODE(type) == TYPE_CODE_CHAR) ||
1417 (TYPE_CODE(type) == TYPE_CODE_BOOL))
1418 arg_ptr = ALIGN_ARG(arg_ptr, len);
1420 arg_ptr = ALIGN_ARG (arg_ptr, sizeof(long)); /* align on 4-byte boundary */
1421 write_memory (arg_ptr, VALUE_CONTENTS (arg), len);
1427 bcopy(VALUE_CONTENTS(arg), &tmp, sizeof(long));
1428 write_register(ireg, tmp);
1442 #define P_SPACES " "
1445 int screen_lines=24;
1447 char *spec_reg[] = {
1448 "fsr", "db", "dirbase", "fir", "psr", "epsr",
1451 char *doro_reg[] = {
1452 "scp", "cbsp", "pt_cs", "intmsk", "intack",
1459 char raw_buffer[32];
1463 /* NOTE that only integer and floating point registers can be relative to a frame */
1465 if ((regno >= R0) && (regno <= F31)) /* user register */
1466 read_relative_register_raw_bytes (regno, raw_buffer);
1468 bcopy (®isters[regno << 2], raw_buffer, sizeof (long));
1470 REGISTER_CONVERT_TO_VIRTUAL (addr, raw_buffer, &virtual_buffer);
1471 return(virtual_buffer);
1476 /* This routine is uncalled. Remove it sometime. */
1479 ** Figure out whether we are in a delayed slot and if so then take necessary
1480 ** action to resume properly - remember trap pre-empts instruction
1483 wasabranch (addr, nextpc, ss)
1484 CORE_ADDR addr, *nextpc;
1487 CORE_ADDR nextadr, instr;
1488 int val = not_branch;
1489 long offset; /* Must be signed for sign-extend */
1495 nextadr = CORADR((int)(addr + INSTRUCTION_LENGTH*2));
1496 instr = (unsigned)(adj_read_memory_integer (CORADR(addr)));
1500 nextadr = addr + INSTRUCTION_LENGTH;
1501 instr = (unsigned)(adj_read_memory_integer (addr));
1506 nextadr = CORADR(addr);
1507 instr = (unsigned)(adj_read_memory_integer (nextadr));
1512 instr = (unsigned)(adj_read_memory_integer (addr));
1517 if ((instr & 0xE0000000) == 0x60000000 && /* CTRL format */
1518 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
1520 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
1522 else if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
1524 else if ((instr & 0xF4000000) == 0x70000000) /* bc or bnc */
1527 offset = (instr & 0x03ffffff);
1528 if (offset & 0x02000000) /* sign extend? */
1529 offset |= 0xFC000000;
1530 nextadr += (offset << 2);
1532 else if ((instr & 0xFC00003F) == 0x4C000002 || /* calli */
1533 (instr & 0xFC000000) == 0x40000000) /* bri */
1538 offset = ((instr & 0x0000F800) >> 11);
1539 nextadr = (read_register(offset) & 0xFFFFFFFC);
1544 else if ((instr & 0xF0000000) == 0x50000000) /* bte or btne */
1548 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
1549 nextadr += (offset << 2);
1551 else if ((instr & 0xFC000000) == 0xB4000000) /* bla */
1555 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
1556 nextadr += (offset << 2);
1565 /* i860-specific routine to print the register set. Note that we ALWAYS print information
1566 on the floating point registers, so we ignore the parameter fpregs.
1567 NOTE also that only integer and floating point registers can be relative to a frame --
1568 see subroutine get_reg (above ) */
1570 void i860_do_registers_info(regnum,fpregs)
1581 "Register Contents (relative to selected stack frame)\n\n");
1583 if (regnum != -1) /* print one register */
1585 val = get_reg(regnum);
1586 printf("%-4s 0x%08x\t", reg_names[regnum], val);
1587 printf("\n\t"); fflush(stdout);
1589 else /* print all registers */
1592 printf("\n Control/Status Registers :- \n\t");
1593 for (j=0; j<=DB; j++)
1596 printf("%-4s 0x%08x\t", reg_names[j], val);
1598 printf("\n\t"); fflush(stdout);
1601 val = get_reg(EPSR);
1602 printf("%-4s 0x%08x\t", reg_names[EPSR], val);
1606 printf("%-4s 0x%08x\t", reg_names[FSR], val);
1610 printf("%-4s 0x%08x\t", reg_names[CCR], val);
1612 val = get_reg(BEAR);
1613 printf("%-4s 0x%08x\t", reg_names[BEAR], val);
1617 for (j=P0; j<=P3; j++)
1620 printf("%-4s 0x%08x\t", reg_names[j], val);
1624 printf("\n Integer Registers :- \n\t");
1625 for (j=R0; j<=R31; j++)
1627 if (j != IREGS && (j % REGISTER_LENGTH == 0))
1629 printf("\n\t"); fflush(stdout);
1632 printf("%-4s 0x%08x\t", reg_names[j], val);
1635 printf("\n Floating Registers :- \n\t");
1636 for (j=F0; j<=F31; j++)
1638 if (j != FREGS && (j % REGISTER_LENGTH == 0))
1640 printf("\n\t"); fflush(stdout);
1643 printf("%-4s 0x%08x\t", reg_names[j], val);
1646 printf("\n Special Registers :- \n\t");
1647 for (j=SPC_KI; j<=SPC_MERGE; j+=2)
1652 printf("\n\t"); fflush(stdout);
1655 valh = get_reg(j+1);
1656 printf("%-6s 0x%08x %08x\t", reg_names[j], val,valh);
1659 printf("\n Graphics Pipeline :- \n");
1664 valh = get_reg(j+1);
1665 printf("\t\t\t%-8s 0x%08x %08x \n", reg_names[j], val,valh);
1668 printf(" Memory Load Pipeline :- \n");
1669 for (j=PSV_L1; j<=PSV_L3; j+=REGISTER_LENGTH)
1671 unsigned int valh, val2,val3;
1674 valh = get_reg(j+1);
1675 val2 = get_reg(j+2);
1676 val3 = get_reg(j+3);
1678 printf("\t\t%-8s 0x%08x %08x %08x %08x\n", reg_names[j],
1679 val,valh,val2,val3);
1682 printf("\n Adder Pipeline :-\t\tMultiplier Pipeline :-\t\tFSR results :-\n");
1683 for (i=PSV_FSR1,j=PSV_A1,k=PSV_M1; j<=PSV_A3; i++,j+=2,k+=2)
1685 unsigned int valh,val2,val3,val4;
1689 valh = get_reg(j+1);
1691 val3 = get_reg(k+1);
1693 printf(" %-4s 0x%08x %08x\t", reg_names[j], val,valh);
1694 printf("%-4s 0x%08x %08x\t", reg_names[k], val2,val3);
1695 printf("%-4s 0x%08x\n", reg_names[i], val4);
1705 /* The following set of routines was adapted from existing code previously
1706 in an i860-specific version of breakpoint.c by Peggy Fieland
1708 /* routines to set a data breakpoint by setting the value in the DB register.
1709 Note that "hitting" the breakpoint will generate a data access trap. We
1710 do not have a special trap handler. */
1711 unsigned int dbrkval, dbrkmod;
1712 void i860_dbrk_breakpoint()
1714 BTDEBUG("i860_dbrk_breakpoint was called , dbrkval %x\n", dbrkval);
1718 *(int *)®isters[DB<<2] = dbrkval;
1722 *(int *)®isters[DB<<2] = 0;
1725 *(int *)®isters[PSR<<2] &= ~3;
1726 *(int *)®isters[PSR<<2] |= dbrkmod;
1728 store_inferior_registers(DB);
1729 store_inferior_registers(PSR);
1733 /* set a "read" data breakpoint. */
1735 d_ro_break_command(char *arg, int num)
1737 dbrkval = strtoul(arg, NULL, 0);
1739 BTDEBUG(" ro_dbreak - %x %x\n", dbrkval, dbrkmod);
1742 /* set a "write" data breakpoint. */
1744 d_wo_break_command(char *arg, int num)
1746 dbrkval = strtoul(arg, NULL, 0);
1748 BTDEBUG(" wo_dbreak - %x %x\n", dbrkval, dbrkmod);
1751 /* set a "read/write" data breakpoint. */
1753 d_rw_break_command(char *arg, int num)
1755 dbrkval = strtoul(arg, NULL, 0);
1757 BTDEBUG(" rw_dbreak - %x %x\n", dbrkval, dbrkmod);
1760 /* clear data breakpoint. */
1761 void clear_dbreak(char *arg, int num)
1767 /* i860-specific breakpoint initialization. Includes adding the
1768 i860-specific data breakpoint commands. */
1769 void i860_init_breakpoints()
1771 dbrkval = dbrkmod = 0;
1772 add_com ("dbro", class_breakpoint, d_ro_break_command,
1773 "Set a data breakpoint READ ONLY, 32-bit data element.");
1774 add_com ("dbwo", class_breakpoint, d_wo_break_command,
1775 "Set a data breakpoint WRITE ONLY, 32-bit data element.");
1776 add_com ("dbrw", class_breakpoint, d_rw_break_command,
1777 "Set a data breakpoint READ/WRITE, 32-bit data element.");
1778 add_com ("dclear", class_breakpoint, clear_dbreak,
1779 "clear the current data breakpoint.");
1780 add_com_alias ("dc", "dclear", class_breakpoint, 1);
1784 /* i860-specific code to insert a breakpoint. */
1785 int i860_insert_breakpoint(b)
1786 struct breakpoint *b;
1789 int *shadow0, *shadow1, *shadow2, *shadow3;
1791 shadow0 = (int *)&b->shadow_contents[0];
1792 shadow1 = (int *)&b->shadow_contents[4];
1793 shadow2 = (int *)&b->shadow_contents[8];
1794 shadow3 = (int *)&b->shadow_contents[12];
1796 place_brk( b->address, BREAK_MODE, b );
1801 adj_read_memory (b->act_addr[0], shadow0, INSTRUCTION_LENGTH);
1802 val = adj_write_memory (b->act_addr[0], break_insn, INSTRUCTION_LENGTH);
1803 if (val != 0 ) return val;
1804 adj_read_memory (b->act_addr[1], shadow1, INSTRUCTION_LENGTH);
1805 /* val = adj_write_memory (b->act_addr[1], float_insn, INSTRUCTION_LENGTH); */
1806 if (val != 0) return val;
1810 adj_read_memory (b->act_addr[0], shadow0, INSTRUCTION_LENGTH);
1811 val = adj_write_memory (b->act_addr[0], break_insn, INSTRUCTION_LENGTH);
1813 if (b->address1 != 0)
1818 adj_read_memory (b->act_addr[2], shadow2, INSTRUCTION_LENGTH);
1819 val = adj_write_memory (b->act_addr[2], break_insn, INSTRUCTION_LENGTH);
1820 if (val) return val;
1821 adj_read_memory (b->act_addr[3], shadow3, INSTRUCTION_LENGTH);
1822 /* val = adj_write_memory (b->act_addr[3], float_insn, INSTRUCTION_LENGTH); */
1823 if (val != 0) return val;
1827 adj_read_memory (b->act_addr[2], shadow0, INSTRUCTION_LENGTH);
1828 val = adj_write_memory (b->act_addr[2], break_insn, INSTRUCTION_LENGTH);
1838 int i860_remove_breakpoint(b)
1839 struct breakpoint *b;
1842 int *shadow0, *shadow1, *shadow2, *shadow3;
1844 shadow0 = (int *)&b->shadow_contents[0];
1845 shadow1 = (int *)&b->shadow_contents[4];
1846 shadow2 = (int *)&b->shadow_contents[8];
1847 shadow3 = (int *)&b->shadow_contents[12];
1854 val =adj_write_memory (b->act_addr[0], shadow0,
1855 INSTRUCTION_LENGTH);
1856 val =adj_write_memory (b->act_addr[1],shadow1,
1857 INSTRUCTION_LENGTH);
1858 if (b->address1 != NULL)
1860 val =adj_write_memory (b->act_addr[2],shadow2,
1861 INSTRUCTION_LENGTH);
1862 val =adj_write_memory (b->act_addr[3], shadow3,
1863 INSTRUCTION_LENGTH);
1868 val =adj_write_memory (b->act_addr[0], shadow0,
1869 INSTRUCTION_LENGTH);
1870 if (b->address1 != NULL)
1872 val =adj_write_memory (b->act_addr[2],shadow0,
1873 INSTRUCTION_LENGTH);
1887 #ifdef USE_PROC_FS /* Target dependent support for /proc */
1889 #include <sys/procfs.h>
1892 They were adapted from the m-68k versions of the routines .*/
1894 /* Given a pointer to a floating point register set in /proc format
1895 (fpregset_t *), unpack the register contents and supply them as gdb's
1896 idea of the current floating point register values. */
1899 supply_fpregset (fpregsetp)
1900 fpregset_t *fpregsetp;
1904 BTDEBUG("supply_fregset called \n");
1906 for (regno = F0 ; regno <= F31 ; regno++)
1908 supply_register (regno, (char *) &(fpregsetp -> fpu.r_freg[regno-F0]));
1912 /* Given a pointer to a floating point register set in /proc format
1913 (fpregset_t *), update the register specified by REGNO from gdb's idea
1914 of the current floating point register set. If REGNO is -1, update
1918 fill_fpregset (fpregsetp, regno)
1919 fpregset_t *fpregsetp;
1925 extern char registers[];
1926 BTDEBUG("fill_fregset regno %d\n",regno);
1928 for (regi = F0 ; regi <= F31 ; regi++)
1930 if ((regno == -1) || (regno == regi))
1932 from = (char *) ®isters[REGISTER_BYTE (regi)];
1933 to = (char *) &(fpregsetp -> fpu.r_freg[regi-F0]);
1934 bcopy (from, to, REGISTER_RAW_SIZE (regno));
1940 /* Given a pointer to a general register set in /proc format (gregset_t *),
1941 unpack the register contents and supply them as gdb's idea of the current
1945 supply_gregset (gregsetp)
1946 gregset_t *gregsetp;
1949 register greg_t *regp = (greg_t *) gregsetp;
1951 BTDEBUG("supply_gregset called \n");
1953 for (regno = 0 ; regno <= R31 ; regno++)
1955 supply_register (regno, (char *) (regp + regno));
1959 /* Given a pointer to a general register set in /proc format (gregset_t *),
1960 update the register specified by REGNO from gdb's idea
1961 of the current general register set. If REGNO is -1, update
1965 fill_gregset (gregsetp, regno)
1966 gregset_t *gregsetp;
1970 extern char registers[];
1971 register greg_t *regp = (greg_t *) gregsetp;
1972 BTDEBUG("fill_gregset regno %d \n",regno);
1974 for (regi = 0 ; regi <= R31 ; regi++)
1976 if ((regno == -1) || (regno == regi))
1978 *(regp + regi) = *(int *) ®isters[REGISTER_BYTE (regi)];
1986 /* Push an empty stack frame, to record the current PC, etc. */
1987 /* We have this frame with fp pointing to a block where all GDB-visible
1988 registers are stored in the order GDB knows them, and sp at the next
1989 alignment point below fp. Note: fp + NUM_REGS*4 was the old sp
1991 extern CORE_ADDR text_end;
1992 CORE_ADDR dummy_start_addr;
1993 void i860_push_frame()
1995 register CORE_ADDR old_fp = read_register(FP_REGNUM);
1996 register CORE_ADDR old_sp = read_register(SP_REGNUM);
1997 register CORE_ADDR fp ;
1998 extern char registers[];
2000 fp = old_sp - REGISTER_BYTES;
2001 write_memory(fp, registers, REGISTER_BYTES); /* write out old register values */
2002 /* reset FP and SP */
2003 write_register(FP_REGNUM, fp);
2004 write_register(SP_REGNUM, (fp &~ 15)); /* re-align */
2007 /* Discard from the stack the innermost frame,
2008 restoring all saved registers. */
2010 void i860_pop_frame()
2011 { register FRAME frame = get_current_frame ();
2012 register CORE_ADDR fp;
2013 struct frame_info *fi;
2016 fi = get_frame_info (frame);
2019 if (call_dummy_set && fi -> pc >= call_dummy_start &&
2020 fi -> pc <= call_dummy_start + CALL_DUMMY_LENGTH)
2023 read_memory(fp, registers, REGISTER_BYTES);
2025 target_store_registers(-1);
2028 /* since we stomped on code that will be executed when we exit the program,
2030 extern REGISTER_TYPE call_save_code[4];
2032 write_memory (call_dummy_start, (char *) call_save_code, 16);
2039 register int regnum;
2040 struct frame_saved_regs fsr;
2041 char raw_buffer[12];
2043 get_frame_saved_regs (fi, &fsr);
2044 for (regnum = FP0_REGNUM + 31; regnum >= FP0_REGNUM; regnum--)
2045 if (fsr.regs[regnum])
2046 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4));
2047 for (regnum = R31; regnum >= 1; regnum--)
2048 if (fsr.regs[regnum])
2049 if (regnum != SP_REGNUM)
2050 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4));
2052 write_register (SP_REGNUM, fsr.regs[SP_REGNUM]);
2053 if (fsr.regs[PS_REGNUM])
2054 write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4));
2055 if (fsr.regs[FPS_REGNUM])
2056 write_register (FPS_REGNUM, read_memory_integer (fsr.regs[FPS_REGNUM],4));
2057 if (fsr.regs[PC_REGNUM])
2058 write_register (PC_REGNUM,CLEAN_PC( read_memory_integer (fsr.regs[PC_REGNUM], 4)));
2061 flush_cached_frames ();
2063 set_current_frame (create_new_frame (read_register (FP_REGNUM),
2068 CORE_ADDR i860_arg_coerce(nargs, args, struct_return, sp)
2075 register int scalar;
2076 register enum type_code code2;
2077 register struct type *type;
2080 int num_int_args = 0;
2081 int num_float_args = 0;
2085 /* if we return a structure, it's address is in R16, and thus it uses up one of the integer
2086 argument registers. See the ABI. */
2090 /* loop to do the right thing with all the arguments and calculate the size of the memory
2091 argument list. We keep count of the number of integer and the number of float parameters,
2092 as well as the size of the memory argument list. */
2094 for (i = 0; i < nargs; i++)
2097 /* NOTE that this is all hunky dory in spite of the fact that we don't actually
2098 have the signature of the called procedure EXCEPT if we are passing in floats!
2099 This is true, since registers are 4 bytes, and the minimum alignment in the
2100 memory argument list is 4 bytes. See the ABI for more gory details. The switch
2101 "ansi-conformant" is an attempt to get around this problem. */
2103 code2 = TYPE_CODE (VALUE_TYPE(args[i]));
2105 /* Only coerce if we've got switch "ansi-conformant" off.
2106 Actually, it's OK ( and probably helpful) to coerce ALL integer arguments
2107 (see comment above), but never mind, we make them the right size in
2108 pass_function_arguments. */
2110 if ((!ansi_conformant) && (code2 != TYPE_CODE_STRUCT))
2111 value_arg_coerce(args[i]);
2114 type = VALUE_TYPE(args[i]);
2116 /* All structures are passed by value in the memory argument list. */
2117 if (code2 == TYPE_CODE_STRUCT)
2119 size = ALIGN_ARG(size, sizeof(long));
2120 size += TYPE_LENGTH(type);
2122 else if (type == builtin_type_float)
2124 num_float_args += 1;
2125 if (num_float_args > NUM_FLOAT_ARG_REGS)
2127 size = ALIGN_ARG(size, TYPE_LENGTH(type)) ;
2128 size += TYPE_LENGTH(type);
2131 else if (type == builtin_type_double)
2133 /* floating register alignment -- see ABI */
2134 if ((num_float_args%2) != 0)
2135 num_float_args += 1;
2137 num_float_args += 2; /* use up two registers */
2139 if (num_float_args > NUM_FLOAT_ARG_REGS)
2141 size = ALIGN_ARG(size, TYPE_LENGTH(type)) ;
2142 size += TYPE_LENGTH(type);
2147 int len = max (sizeof(long), TYPE_LENGTH(type));
2151 if (num_int_args > NUM_INT_ARG_REGS)
2153 /* see ABI -- in-memory arguments have AT LEAST word alignment */
2154 if ((TYPE_CODE(type) == TYPE_CODE_INT) ||
2155 (TYPE_CODE(type) == TYPE_CODE_ENUM) ||
2156 (TYPE_CODE(type) == TYPE_CODE_CHAR) ||
2157 (TYPE_CODE(type) == TYPE_CODE_BOOL))
2158 size = ALIGN_ARG(size, len);
2160 size = ALIGN_ARG(size, sizeof(long));
2168 /* recalculate the stack pointer, leaving enough space for the memory argument list and
2169 realigning the stack pointer. */
2172 arg_ptr = sp - size;
2174 arg_ptr = arg_ptr & (-16); /* realign stack */
2175 write_register (R28,arg_ptr);
2182 void i860_extract_return_value(type,regbuf,valbuf)
2184 char regbuf[REGISTER_BYTES];
2187 register int len = TYPE_LENGTH (type);
2191 if ((TYPE_CODE(type) == TYPE_CODE_FLT))
2193 if (len == sizeof (float))
2196 NOTE that this assumes that the function declaration was ANSI_CONFORMANT --
2197 at the present time I can't think of ANY WAY to disambiguate the two following
2199 float really_does_return_a_float(float ff)
2202 float actually_returns_a_double(ff)
2206 bcopy ((char *) (regbuf) + REGISTER_BYTE(ADJ_FREG(F8)), (valbuf), TYPE_LENGTH (type)) ;
2209 bcopy ((char *) (regbuf) + REGISTER_BYTE(F8), (valbuf), TYPE_LENGTH (type)) ;
2212 bcopy ((char *) (regbuf) + REGISTER_BYTE(R16), (valbuf), TYPE_LENGTH (type));
2215 void i860_store_return_value(type,valbuf)
2219 register int len = TYPE_LENGTH (type);
2222 if ((TYPE_CODE(type) == TYPE_CODE_FLT) )
2224 write_register_bytes (REGISTER_BYTE (F8), valbuf, len);
2227 write_register_bytes (REGISTER_BYTE (R16), valbuf, TYPE_LENGTH (type));