1 /* Target-dependent code for the i860 for GDB, the GNU debugger.
2 Copyright is unclear on this module!!!
3 Copyright (C) 1992 Free Software Foundation, Inc.
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!
36 #include "i860-opcode.h"
42 #include <sys/types.h>
43 #include <sys/param.h>
48 #include <sys/ioctl.h>
51 /* #include <sys/reg.h> */
60 #include <sys/elftypes.h>
61 #include <sys/elf_860.h>
65 extern int read_memory();
66 extern int write_memory();
67 extern int read_memory_integer();
68 extern int print_insn();
71 extern int store_inferior_registers(int);
72 extern int outside_startup_file();
74 int btdebug = 0; /* change value to 1 to enable debugging code */
76 #define BTDEBUG if (btdebug) btdebug_message
79 extern int attach_flag;
81 #define INSTRUCTION_LENGTH 4
82 #define REGISTER_LENGTH 4
84 /* routine to print debugging messages */
85 void btdebug_message(char *format, ...)
88 va_start( arglist, format );
91 vfprintf (stderr, format, arglist );
97 /* return nonzero if the routine containing pc has been
98 * compiled with -g. We assume -g if the first instruction is
99 * an addu|adds -X,sp and the second is st.l fp,XX(sp)
101 * based on skip_prologue();
104 static int g_routine(pc)
110 top_pc = get_pc_function_start(pc);
113 instr = (unsigned)( adj_read_memory_integer (top_pc));
114 /* Recognize "addu|adds -X,sp,sp" insn. */
116 if ((instr & 0xEFFF0000) == 0x84420000)
118 top_pc += INSTRUCTION_LENGTH;
119 instr = (unsigned)(adj_read_memory_integer (top_pc));
121 if( (instr & 0xFFE0F801) == 0x1C401801 ) /* st.l fp,X(sp) */
129 /* return the stack offset where the fp register is stored */
130 static int find_fp_offset(pc)
136 /* look for the instruction and examine the offset */
138 for (i=INSTRUCTION_LENGTH*1; i< INSTRUCTION_LENGTH*4; i+=INSTRUCTION_LENGTH){
139 instr = (unsigned)(adj_read_memory_integer(pc+i));
140 if( (instr & 0xFFE0F801) == 0x1C401801) { /* st.l fp,X(sp) */
142 fp_off = SIGN_EXT16(((instr&0x001F0000) >> 5) |
150 /* return the stack offset where r1 (return linkage ) register is stored */
151 static int find_r1_offset(pc)
157 /* look for the instruction and examine the offset */
159 for (i=INSTRUCTION_LENGTH*1; i< INSTRUCTION_LENGTH*4; i+=INSTRUCTION_LENGTH){
160 instr = (unsigned)( adj_read_memory_integer(pc+i));
161 if ((instr & 0xFFE0F801) == 0x1C400801) { /* st.l r1,X(sp) */
163 r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) |
171 CORE_ADDR skip_prologue(CORE_ADDR);
173 /* does routine starting at pc build a stack frame of any kind?? */
174 static int has_a_frame(pc)
177 if( skip_prologue(pc) != pc )return(1);
183 Routine to validate the return register and the frame pointer
184 This routine is called when the routine we are in doesn't have a frame
185 In that case, we assume that the return address and frame pointer have
186 not been touched. In the following routine, we try to range check them
187 to see if they are valid. */
189 static int valid_regs (rp, fp)
192 if ( ( (rp % 4) != 0) | ( (fp % 16) != 0) )
200 /* get the pc and frame pointer (or sp )
201 * for the routine that called us
202 * when we (this_pc) is not within a -g routine
203 * if caller is non g we return sp for fp
206 /* note this is written for Metaware version R2.1d compiler */
208 static int caller_pc(this_pc,this_sp,to_pc,to_fp)
209 CORE_ADDR this_pc,this_sp;
210 CORE_ADDR *to_pc, *to_fp;
212 CORE_ADDR func_start;
213 int sp_offset,offset;
214 CORE_ADDR sp,pc,fp,instr;
216 BTDEBUG("caller_pc %x sp = %x\n",this_pc,this_sp);
218 func_start = get_pc_function_start(this_pc);
220 BTDEBUG("caller_pc func_start %x\n", func_start);
222 if (func_start!= NULL)
224 if( has_a_frame(func_start) ){
226 BTDEBUG("has_a_frame\n");
228 /* if our caller has a preamble and
229 * declares space for a stack frame
230 * then we must work to find our return address
232 instr = (unsigned)( adj_read_memory_integer (func_start));
233 /* Recognize "addu|adds -X,sp,sp" insn. */
235 if ((instr & 0xEFFF0000) == 0x84420000)
236 sp_offset=SIGN_EXT16(instr&0x0000FFFF);
240 /* if we get here, procedure doesn't have a frame. If we didn't
241 do anything weird, the frame pointer and return register have
242 the values we want. Check them to see if they are valid. */
244 CORE_ADDR temp_rp, temp_fp;
246 temp_rp = read_register(RP_REGNUM);
247 temp_fp = read_register(FP_REGNUM);
249 if (!valid_regs(temp_rp, temp_fp))
251 printf("error frame_chain\n");
254 BTDEBUG("caller_pc no frame, using r1 %x and fp %x\n",
261 BTDEBUG("sp_offset = %d %x\n",sp_offset,sp_offset);
263 offset = find_r1_offset(func_start);
266 printf("cant find return address for routine at %x\n",
270 pc = read_memory_integer(this_sp+offset,sizeof(long));
271 sp= this_sp - sp_offset;
273 BTDEBUG("callers pc = %x sp = %x\n",pc,sp);
275 /* our caller a -g routine ?
276 * if he is we have to find his real fp
277 * else provide the sp as his fp
282 BTDEBUG("caller_a_g\n");
284 if( ! (offset = find_fp_offset(func_start)) ) {
285 printf("error fp_offset\n");
288 BTDEBUG("offset = %x %d\n",offset,offset);
290 fp = read_memory_integer(this_sp+offset,sizeof(long));
291 *to_pc = CLEAN_PC(pc);
295 *to_pc = CLEAN_PC(pc);
299 /* pc = read_register(RP_REGNUM); */
301 /* if we get here, procedure doesn't have a frame. If we didn't
302 do anything weird, the frame pointer and return register have
303 the values we want. Check them to see if they are valid. */
305 CORE_ADDR temp_rp, temp_fp;
307 temp_rp = read_register(RP_REGNUM);
308 temp_fp = read_register(FP_REGNUM);
310 if (!valid_regs(temp_rp, temp_fp))
312 printf("error frame_chain\n");
315 BTDEBUG("caller_pc no frame, using r1 %x and fp %x\n",
324 ** Figure out address to place next breakpoint. Avoid tricky spots,
325 ** ie. delayed instruction slots etc.
326 ** Need to upgrade this later to allow delayed instruction breakpoints
327 ** with fix-up work done AFTER breakpoint.
328 ** Note that this routine DOES deal with dual instruction mode
333 place_brk (addr, mode, brk)
336 struct breakpoint *brk;
339 CORE_ADDR nextadr, prevadr;
340 int val = not_branch;
341 long offset; /* Must be signed for sign-extend */
342 extern char registers[];
343 prevadr = nextadr = 0;
347 if (mode == SINGLE_STEP_MODE)
351 nextadr = brk->address = (addr + INSTRUCTION_LENGTH*2);
352 instr = (unsigned)(adj_read_memory_integer ((addr + INSTRUCTION_LENGTH)));
357 nextadr = brk->address = (addr + INSTRUCTION_LENGTH);
358 instr = (unsigned)(adj_read_memory_integer (addr));
367 ** For br/call one more sequential instruction gets executed and then we
368 ** continue at the current addr + offset. We are definitely going to
369 ** the dest. We are NOT allowed to place a breakpoint in the "delay"
370 ** slot - (the next sequential instruction) so we only place 1 breakpoint
371 ** at the destination.
372 ** For the bc/bnc the next instruction executed is EITHER the next sequential
373 ** or the destination of the branch, we therefore place 2 breakpoints one
375 ** For the bc.t/bnc.t either 1 more sequential instruction is performed
376 ** followed by a branch (like br/call) OR we skip the sequential
377 ** instruction and keep going. We therefore place a breakpoint at the
378 ** destination of the branch AND the second sequential instruction after
379 ** the branch. Again a breakpoint is NOT allowed in the "delay slot"
381 if ((instr & 0xE0000000) == 0x60000000 && /* CTRL format */
382 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
384 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
386 else if ((instr & 0xF4000000) == 0x74000000) /* bc.t/bnc.t */
388 else if ((instr & 0xF4000000) == 0x70000000) /* bc or bnc */
390 offset = (instr & 0x03ffffff);
391 if (offset & 0x02000000) /*?sign extend*/
392 offset |= 0xFC000000;
393 if (val == uncond_d) /* br/call*/
395 else if (val == cond_d) /* bc.t/bnc.t */
397 if ((INDIM) && !(ENDIM))
398 prevadr = nextadr + (2*INSTRUCTION_LENGTH);
400 prevadr = nextadr + INSTRUCTION_LENGTH;
401 } else { /* bc /bnc */
402 if ((INDIM) && !(ENDIM))
407 nextadr += (offset << 2);
410 ** We treat the bri/calli the same way as the br/call case.
412 else if ((instr & 0xFC00003F) == 0x4C000002 || /* calli */
413 (instr & 0xFC000000) == 0x40000000) /* bri */
416 offset = ((instr & 0x0000F800) >> 11);
417 nextadr = (read_register(offset + R0) & 0xFFFFFFFC);
421 ** We treat the bte/btne the same way as the bc/bnc case.
423 else if ((instr & 0xF0000000) == 0x50000000) /* bte/btne */
426 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) |
427 (instr & 0x000007FF));
428 if ((INDIM) && !(ENDIM))
433 nextadr += (offset << 2);
436 ** We treat the bte/btne the same way as the bc/bnc case.
437 ** With the caveat that the 2 breakpoints may turn out to be at the same
438 ** address in which case we ignore one of them.
440 else if ((instr & 0xFC000000) == 0xB4000000) /* bla */
443 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) |
444 (instr & 0x000007FF));
445 if ((INDIM) && !(ENDIM))
447 prevadr = nextadr + 2*INSTRUCTION_LENGTH;
449 prevadr = nextadr + INSTRUCTION_LENGTH;
451 nextadr += (offset << 2);
452 if (prevadr == nextadr) prevadr = 0;
459 if (ISDIM(FOPADR(addr)))
461 if (ISDIM(FOPADR(nextadr- INSTRUCTION_LENGTH*2)))
463 instr = (unsigned)(adj_read_memory_integer(CORADR(addr
464 -(INSTRUCTION_LENGTH*2))));
467 instr = (unsigned)(adj_read_memory_integer(addr-INSTRUCTION_LENGTH));
471 if (ISDIM(addr-INSTRUCTION_LENGTH))
473 instr = (unsigned)(adj_read_memory_integer(addr-INSTRUCTION_LENGTH));
476 instr = (unsigned)(adj_read_memory_integer (addr-INSTRUCTION_LENGTH));
481 /* examine the PREVIOUS instruction to determine if we are in a branch delay
482 slot. If we are, dont set a break here -- set it on the previous instruction.
483 This code also accounts for dual instruction mode */
484 if ((instr & 0xE0000000) == 0x60000000 &&
485 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
491 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
492 printf(" Breakpoint adjusted to avoid br/call delay slot and multiple breakpoints\n");
494 if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
495 printf(" Breakpoint adjusted to avoid bc.t/bnc.t delay slot and multiple breakpoints\n");
496 /* it IS really OK to set a break on the instruction AFTER the conditional branch
497 -- it DOESN't have a delay slot */
498 if ((instr & 0xF4000000) == 0x70000000) /* bc / bnc */
499 /* printf(" Breakpoint adjusted to avoid bc/bnc delay slot and multiple breakpoints\n"); */
502 ((instr & 0xFC00003F) == 0x4C000002 || /* bri/ calli */
503 (instr & 0xFC000000) == 0x40000000)
506 printf(" Breakpoint adjusted to avoid calli/bri delay slot and multiple breakpoints\n");
508 ((instr & 0xF0000000) == 0x50000000) /* bte - btne */
510 /* it's OK to set a break here -- we are NOT in aa branch delay slot */
513 printf(" Breakpoint adjusted to avoid bte/btne multiple breakpoints\n");
517 ((instr & 0xFC000000) == 0xB4000000)
520 printf(" Breakpoint adjusted to avoid bla delay slot and multiple breakpoints\n");
524 if (brk->mode == DIM)
526 nextadr -= INSTRUCTION_LENGTH*2;
527 nextadr = CORADR(nextadr);
530 nextadr -= INSTRUCTION_LENGTH;
535 if (brk->mode == RIM)
537 if (brk->mode == BIM)
542 if (brk->mode == DIM)
544 brk->act_addr[0] = CORADR(nextadr);
545 brk->act_addr[1] = FOPADR(nextadr);
547 brk->act_addr[0] = nextadr;
548 brk->act_addr[1] = 0;
554 brk->address1 = prevadr;
555 if (brk->mode == DIM)
557 brk->act_addr[2] = CORADR(prevadr);
558 brk->act_addr[3] = FOPADR(prevadr);
560 brk->act_addr[2] = prevadr;
561 brk->act_addr[3] = 0;
564 brk->act_addr[2] = brk->act_addr[3] = 0;
569 /* This routine checks to see if r1 has been stored into the frame between
570 the addresses prologue_start and prologue_end. Recognize stores of r1
571 relative to both the sp and fp registers. */
572 static int has_stored_r1(CORE_ADDR prologue_start, CORE_ADDR prologue_end)
577 BTDEBUG("has_stored_r1, prologue_start %x, prologue_end %x\n",
578 prologue_start, prologue_end);
580 for (addr = prologue_start; addr <= prologue_end; addr += INSTRUCTION_LENGTH)
583 instr = (unsigned)(adj_read_memory_integer (addr));
584 if ((instr & 0xFFE0F801) == 0x1C400801 /* st.l r1,X(sp) */
585 || (instr & 0xFFE0F801) == 0x1C600801) /* st.l r1,X(fp) */
590 /* This is used when GDB is exiting. It gives less chance of error.*/
593 /* Simulate single-step ptrace call for sun4. Code written by Gary
598 static struct breakpoint brk;
599 typedef char binsn_quantum[sizeof break_insn];
601 /* Non-zero if we just simulated a single-step ptrace call. This is
602 needed because we cannot remove the breakpoints in the inferior
603 process until after the `wait' in `wait_for_inferior'. Used for
608 /* single_step() is called just before we want to resume the inferior,
609 if we want to single-step it but there is no hardware or kernel single-step
610 support. We find all the possible targets of the coming instruction and
613 single_step is also called just after the inferior stops. If we had
614 set up a simulated single-step, we undo our damage. */
615 /* Note that we don't need the parameter, but it's dictated as part of the interface. */
621 branch_type place_brk();
623 pc = read_register (PC_REGNUM);
628 place_brk (pc, SINGLE_STEP_MODE, &brk);
629 brk.shadow_contents[0] = brk.shadow_contents[1] = 0;
630 brk.shadow_contents[2] = brk.shadow_contents[3] = 0;
636 btdebug_message(" DIM1 -> %x : ", brk.act_addr[3]);
637 print_insn( brk.act_addr[3], stderr);
638 btdebug_message("\t -|- %x : ", brk.act_addr[2]);
639 print_insn( brk.act_addr[2], stderr);
640 btdebug_message("\n");
642 if (( brk.address1 != NULL))
644 adj_read_memory (brk.act_addr[2], &brk.shadow_contents[2],
646 adj_write_memory (brk.act_addr[2], break_insn, INSTRUCTION_LENGTH);
647 adj_read_memory (brk.act_addr[3], &brk.shadow_contents[3],
649 /* adj_write_memory (brk.act_addr[3], float_insn,
650 INSTRUCTION_LENGTH); */
655 if ( brk.address1 != 0)
656 btdebug_message(" DIM2 ->");
658 btdebug_message(" DIM1 ->");
660 btdebug_message(" %x : ", brk.act_addr[1]);
661 print_insn( brk.act_addr[1], stderr);
662 btdebug_message("\t -|- %x : ", brk.act_addr[0]);
663 print_insn( brk.act_addr[0], stderr);
664 btdebug_message("\n");
667 adj_read_memory (brk.act_addr[0], &brk.shadow_contents[0],
669 adj_write_memory (brk.act_addr[0], break_insn,
671 adj_read_memory (brk.act_addr[1], &brk.shadow_contents[1],
673 /* adj_write_memory (brk.act_addr[1], float_insn,
674 INSTRUCTION_LENGTH); */
678 if (brk.address1 != NULL)
682 btdebug_message(" SIM1 ->");
683 btdebug_message(" %x : ", brk.act_addr[2]);
684 print_insn( brk.act_addr[2], stderr);
685 btdebug_message("\n");
687 adj_read_memory (brk.act_addr[2], &brk.shadow_contents[2],
689 adj_write_memory (brk.act_addr[2], break_insn, INSTRUCTION_LENGTH);
693 if ( brk.address1 != NULL)
694 btdebug_message(" SIM2 ->");
696 btdebug_message(" SIM1 ->");
698 btdebug_message(" %x : ", brk.act_addr[0]);
699 print_insn( brk.act_addr[0], stderr);
700 btdebug_message("\n");
702 adj_read_memory (brk.act_addr[0], &brk.shadow_contents[0],
704 adj_write_memory (brk.act_addr[0], break_insn,INSTRUCTION_LENGTH);
713 /* Remove breakpoints */
716 adj_write_memory (brk.act_addr[0], &brk.shadow_contents[0],
718 adj_write_memory (brk.act_addr[1], &brk.shadow_contents[1],
721 adj_write_memory (brk.act_addr[0], &brk.shadow_contents[0],
725 if (brk.address1 != NULL)
729 adj_write_memory (brk.act_addr[2], &brk.shadow_contents[2],
731 adj_write_memory (brk.act_addr[3], &brk.shadow_contents[3],
734 adj_write_memory (brk.act_addr[2], &brk.shadow_contents[2],
747 /* This routine returns the first memory address following the prologue code,
748 if there is a prologue. */
750 struct command_line *get_breakpoint_commands ();
759 instr = (unsigned)(adj_read_memory_integer (pc));
761 /* Recognize "addu|adds -X,sp,sp" insn. */
762 if ((instr & 0xEFFF0000) == 0x84420000)
764 pc += INSTRUCTION_LENGTH;
765 instr = (unsigned)(adj_read_memory_integer (pc));
768 return(pc); /* No frame! */
770 /* Recognize store of return addr and frame pointer into frame */
773 if ((instr & 0xFFE0F801) == 0x1C400801 || /* st.l r1,X(sp) */
774 (instr & 0xFFE0F801) == 0x1C401801) /* st.l fp,X(sp) */
776 pc += INSTRUCTION_LENGTH;
777 instr = (unsigned)(adj_read_memory_integer (pc));
783 /* Recognize "addu|adds X,sp,fp" insn. */
784 if ((instr & 0xEFFF0000) == 0x84430000)
786 pc += INSTRUCTION_LENGTH;
787 instr = (unsigned)(adj_read_memory_integer (pc));
790 /* Now recognize stores into the frame from the registers. */
794 if ((instr & 0xFFA00003) == 0x1C200001 || /* st.l rn,X(fp|sp) */
795 (instr & 0xFFA00001) == 0x4C200000) /* fst.y fn,X(fp|sp) */
797 regno = (instr >> 11) & 0x1f;
798 if (regno == 0) /* source reg == 0? quit */
800 pc += INSTRUCTION_LENGTH;
801 instr = (unsigned)(adj_read_memory_integer (pc));
811 /* This routine is uncalled. Remove it sometime. */
812 /* Set *nextpc to branch target if we find a branch. If it is not a branch,
813 set it to the next instruction (addr + 4) */
817 isabranch (addr, nextpc)
818 CORE_ADDR addr, *nextpc;
821 branch_type val = not_branch;
822 long offset; /* Must be signed for sign-extend */
824 BTDEBUG(" isabranch\n");
826 instr = (unsigned)(adj_read_memory_integer (addr));
828 if ((instr & 0xE0000000) == 0x60000000 && /* CTRL format */
829 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
831 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
833 else if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
835 else if ((instr & 0xF4000000) == 0x70000000) /* bc or bnc */
838 offset = (instr & 0x03ffffff);
839 if (offset & 0x02000000) /* sign extend? */
840 offset |= 0xFC000000;
841 *nextpc = addr + 4 + (offset << 2);
843 else if ((instr & 0xFC00003F) == 0x4C000002 || /* calli */
844 (instr & 0xFC000000) == 0x40000000) /* bri */
847 offset = ((instr & 0x0000F800) >> 11);
848 *nextpc = (read_register(offset) & 0xFFFFFFFC);
850 else if ((instr & 0xF0000000) == 0x50000000) /* bte or btne */
854 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
855 *nextpc = addr + 4 + (offset << 2);
857 else if ((instr & 0xFC000000) == 0xB4000000) /* bla */
861 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
862 *nextpc = addr + 4 + (offset << 2);
865 BTDEBUG(" Final addr - %x\n", *nextpc);
866 /*BTDEBUG("isabranch ret: %d\n",val); */
871 /* set in call_function() [valops.c] to the address of the "call dummy" code
872 so dummy frames can be easily recognized; also used in wait_for_inferior()
873 [infrun.c]. When not used, it points into the ABI's 'reserved area' */
875 CORE_ADDR call_dummy_set = 0; /* true if dummy call being done */
876 CORE_ADDR call_dummy_start; /* address of call dummy code */
878 /* this routine routine gets the values of the registers stored in the frame
879 and stores their values into the frame_saved_regs structure. */
882 frame_find_saved_regs(frame_info, frame_saved_regs)
883 struct frame_info *frame_info;
884 struct frame_saved_regs *frame_saved_regs;
886 register CORE_ADDR pc;
888 long offset, spdelta = 0;
890 int r1_off = -1, fp_off = -1;
893 bzero (frame_saved_regs, sizeof(*frame_saved_regs));
895 if (call_dummy_set && frame_info->pc >= call_dummy_start &&
896 frame_info->pc <= call_dummy_start + CALL_DUMMY_LENGTH)
898 /* DUMMY frame - all registers stored in order at fp; old sp is
899 at fp + NUM_REGS*4 */
901 for (i = 1; i < NUM_REGS; i++) /* skip reg 0 */
902 if (i != SP_REGNUM && i != FP0_REGNUM && i != FP0_REGNUM + 1)
903 /* the register numbers used in the instruction and the ones used to index
904 the regs array are not the same -- compensate */
905 frame_saved_regs->regs[i+R0] = frame_info->frame + i*REGISTER_LENGTH;
907 frame_saved_regs->regs[SP_REGNUM] = frame_info->frame + NUM_REGS*REGISTER_LENGTH;
913 pc = get_pc_function_start (frame_info->pc);
916 instr = (unsigned)(adj_read_memory_integer (pc));
917 /* Recognize "addu|adds -X,sp,sp" insn. */
918 if ((instr & 0xEFFF0000) == 0x84420000)
920 framesize = -SIGN_EXT16(instr & 0x0000FFFF);
921 pc += INSTRUCTION_LENGTH;
922 instr = (unsigned)(adj_read_memory_integer (pc));
926 goto punt; /* No frame! */
928 /* Recognize store of return addr and frame pointer into frame */
931 if ((instr & 0xFFE0F801) == 0x1C400801) /* st.l r1,X(sp) */
933 r1_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
934 pc += INSTRUCTION_LENGTH;
935 instr = (unsigned)(adj_read_memory_integer (pc));
937 else if ((instr & 0xFFE0F801) == 0x1C401801) /* st.l fp,X(sp) */
939 fp_off = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
940 pc += INSTRUCTION_LENGTH;
941 instr = (unsigned)(adj_read_memory_integer (pc));
947 /* Recognize "addu|adds X,sp,fp" insn. */
948 if ((instr & 0xEFFF0000) == 0x84430000)
950 spdelta = SIGN_EXT16(instr & 0x0000FFFF);
951 pc += INSTRUCTION_LENGTH;
952 instr = (unsigned)(adj_read_memory_integer (pc));
955 /* Now recognize stores into the frame from the registers. */
959 if ((instr & 0xFFC00003) == 0x1C400001) /* st.l rn,X(fp|sp) */
961 offset = SIGN_EXT16(((instr&0x001F0000) >> 5) | (instr&0x000007FE));
962 reg = (instr >> 11) & 0x1F;
965 if ((instr & 0x00200000) == 0) /* was this using sp? */
966 if (spdelta != 0) /* and we know sp-fp delta */
967 offset -= spdelta; /* if so, adjust the offset */
969 break; /* if not, give up */
972 /* Handle the case where the return address is stored after the fp
976 frame_saved_regs->regs[PC_REGNUM] = frame_info->frame + offset;
978 frame_saved_regs->regs[reg+R0] = frame_info->frame + offset;
980 pc += INSTRUCTION_LENGTH;
981 instr = (unsigned)(adj_read_memory_integer (pc));
983 else if ((instr & 0xFFC00001) == 0x2C400000) /* fst.y fn,X(fp|sp) */
986 * The number of words in a floating store based on 3 LSB of instr
988 static int fst_sizes[] = {2, 0, 1, 0, 4, 0, 1, 0};
990 size = fst_sizes[instr & 7];
991 reg = ((instr >> 16) & 0x1F) + FP0_REGNUM;
995 if (size > 1) /* align the offset */
996 offset = SIGN_EXT16(instr & 0x0000FFF8); /* drop 3 bits */
998 offset = SIGN_EXT16(instr & 0x0000FFFC); /* drop 2 bits */
1000 if ((instr & 0x00200000) == 0) /* was this using sp? */
1001 if (spdelta != 0) /* and we know sp-fp delta */
1002 offset -= spdelta; /* if so, adjust the offset */
1004 break; /* if not, give up */
1006 for (i = 0; i < size; i++)
1008 frame_saved_regs->regs[reg] = frame_info->frame + offset;
1010 offset += REGISTER_LENGTH;
1014 pc += INSTRUCTION_LENGTH;
1015 instr = (unsigned)(adj_read_memory_integer (pc));
1022 if (framesize != 0 && spdelta != 0)
1023 frame_saved_regs->regs[SP_REGNUM] = frame_info->frame+(framesize-spdelta);
1025 frame_saved_regs->regs[SP_REGNUM] = frame_info->frame + 8;
1027 if ((spdelta != 0) && fp_off != -1)
1028 frame_saved_regs->regs[FP_REGNUM] = frame_info->frame - spdelta + fp_off;
1030 frame_saved_regs->regs[FP_REGNUM] = frame_info->frame;
1032 if ((spdelta != 0) && r1_off != -1)
1033 frame_saved_regs->regs[PC_REGNUM] = frame_info->frame - spdelta + r1_off;
1035 frame_saved_regs->regs[PC_REGNUM] = frame_info->frame + 4;
1039 /* get the frame pointer of the caller.
1040 * note that only routines that have been compiled with
1041 * -g have full (XX)fp style stack frames
1042 * if we are not returning to a non -g caller then we
1043 * return the sp at entry to us as it is the caller's
1047 frame_chain(thisframe)
1051 CORE_ADDR func_start;
1054 CORE_ADDR thisfp = thisframe->frame;
1056 /* get the frame pointer actually sp for a non -g
1057 * for the routine that called us routine
1060 BTDEBUG("FRAME_CHAIN(%x)\n",thisframe);
1062 if ( !read_memory_integer (thisframe->frame,sizeof(long)) )
1067 if( ! g_routine(thisframe->pc) ){
1068 BTDEBUG( "non g at %x\n",thisframe->pc);
1069 caller_pc(thisframe->pc,thisframe->sp,&pc,&fp);
1070 BTDEBUG("caller_pc returned %x %x \n",pc,fp);
1073 }/* else a -g routine */
1076 fp = read_memory_integer (thisfp, sizeof(long));
1078 if (fp < thisfp || fp > (unsigned) STACK_END_ADDR)
1080 /* handle the Metaware-type pseudo-frame */
1082 func_start = get_pc_function_start(thisframe->pc);
1084 if (func_start != NULL)
1087 instr = (unsigned)(adj_read_memory_integer (func_start));
1088 /* Recognize "addu|adds -X,sp,sp" insn. */
1089 if ((instr & 0xEFFF0000) == 0x84420000)
1090 offset = SIGN_EXT16(instr & 0x0000FFFF);
1096 fp = thisfp - offset;
1098 BTDEBUG("frame_chain returned %d\n",fp);
1102 /* This function returns 1 if there is no stored r1, 0 otherwise.
1103 The function returns 1 if the pc is in a function prologue,
1104 or the function prologue didn't save the return pointer in
1105 the stack frame, 0 otherwise */
1107 int no_stored_rp(CORE_ADDR pc)
1109 CORE_ADDR func_start, prologue_end;
1111 func_start = get_pc_function_start(pc);
1112 if (func_start != NULL)
1114 prologue_end = func_start;
1115 SKIP_PROLOGUE(prologue_end);
1116 if ( (pc >= func_start) && (pc <= prologue_end))
1118 BTDEBUG("no_stored_rp: pc %x is in prologue \n",pc);
1121 /* otherwise, see if the entry sequence stored the return pointer.
1122 If it didn't, return 1 */
1123 /* Some procedures , at least, store the return pointer AFTER
1124 the prologue sequence, so check for stores from function start to
1125 present pc value. */
1126 if (!has_stored_r1(func_start, pc))
1128 BTDEBUG("no_stored_rp, for pc %x, prologue didn't store r1\n",pc);
1132 BTDEBUG("no_stored_rp for pc %x return pointer was stored \n", pc);
1137 /* get the PC of the caller */
1138 CORE_ADDR frame_saved_pc(frame_struct)
1147 frame = frame_struct->frame;
1148 pc = frame_struct->pc;
1149 sp = frame_struct->sp;
1151 BTDEBUG("frame_saved_pc input: frame %x, pc %x",
1154 /* First see if this is the current frame. If it is, return the value in r1,
1155 as it may not have been stored */
1157 fp = read_register(FP_REGNUM);
1159 /* check to see if we are in an entry sequence, where the return pointer has not yet been stored */
1160 if (fp == frame && no_stored_rp(pc))
1162 pc = read_register(RP_REGNUM);
1163 frame_struct->rp = pc;
1165 else if( ! g_routine(pc) )
1167 caller_pc(pc,sp,&pc,&frame);
1172 pc = read_memory_integer (frame + 4, sizeof(long));
1174 if (!outside_startup_file(pc))
1177 BTDEBUG("pc %x outside startup file \n",pc);
1179 pc1 = read_memory_integer (frame, sizeof(long));
1181 if (outside_startup_file(pc1))
1187 BTDEBUG(" returning pc %x\n", CLEAN_PC(pc));
1188 return(CLEAN_PC(pc));
1192 /* Pass arguments to a function in the inferior process - ABI compliant
1193 Note that this routine DOES NOT HANDLE memory argument lists, ie
1194 it gives up if there are too many arguments to pass in registers.*/
1197 pass_function_arguments(args, nargs, struct_return)
1202 int ireg = (struct_return) ? 17 : 16;
1203 int freg = FP0_REGNUM + 8;
1208 value value_arg_coerce();
1211 for (i = 0; i < nargs; i++)
1213 arg = value_arg_coerce(args[i]);
1214 type = VALUE_TYPE(arg);
1215 if (type == builtin_type_double)
1217 write_register_bytes(REGISTER_BYTE(freg), VALUE_CONTENTS(arg), sizeof(double));
1222 bcopy(VALUE_CONTENTS(arg), &tmp, sizeof(long));
1223 write_register(ireg, tmp);
1227 if (ireg >= 28 || freg >= FP0_REGNUM + 16)
1228 error("Too many arguments to function");
1233 #define P_SPACES " "
1236 int screen_lines=24;
1238 char *spec_reg[] = {
1239 "fsr", "db", "dirbase", "fir", "psr", "epsr",
1242 char *doro_reg[] = {
1243 "scp", "cbsp", "pt_cs", "intmsk", "intack",
1248 /* This routine is uncalled -- remove this routine sometime */
1251 char raw_buffer[32];
1255 read_relative_register_raw_bytes (regno, raw_buffer);
1256 REGISTER_CONVERT_TO_VIRTUAL (addr, raw_buffer, &virtual_buffer);
1257 return(virtual_buffer);
1263 /* This routine is uncalled. Remove it sometime. */
1266 ** Figure out whether we are in a delayed slot and if so then take necessary
1267 ** action to resume properly - remember trap pre-empts instruction
1270 wasabranch (addr, nextpc, ss)
1271 CORE_ADDR addr, *nextpc;
1274 CORE_ADDR nextadr, instr;
1275 int val = not_branch;
1276 long offset; /* Must be signed for sign-extend */
1282 nextadr = CORADR((int)(addr + INSTRUCTION_LENGTH*2));
1283 instr = (unsigned)(adj_read_memory_integer (CORADR(addr)));
1287 nextadr = addr + INSTRUCTION_LENGTH;
1288 instr = (unsigned)(adj_read_memory_integer (addr));
1293 nextadr = CORADR(addr);
1294 instr = (unsigned)(adj_read_memory_integer (nextadr));
1299 instr = (unsigned)(adj_read_memory_integer (addr));
1304 if ((instr & 0xE0000000) == 0x60000000 && /* CTRL format */
1305 (instr & 0xF8000000) != 0x60000000) /* not pfld.y */
1307 if ((instr & 0xF8000000) == 0x68000000) /* br or call */
1309 else if ((instr & 0xF4000000) == 0x74000000) /* bc.t or bnc.t */
1311 else if ((instr & 0xF4000000) == 0x70000000) /* bc or bnc */
1314 offset = (instr & 0x03ffffff);
1315 if (offset & 0x02000000) /* sign extend? */
1316 offset |= 0xFC000000;
1317 nextadr += (offset << 2);
1319 else if ((instr & 0xFC00003F) == 0x4C000002 || /* calli */
1320 (instr & 0xFC000000) == 0x40000000) /* bri */
1325 offset = ((instr & 0x0000F800) >> 11);
1326 nextadr = (read_register(offset) & 0xFFFFFFFC);
1331 else if ((instr & 0xF0000000) == 0x50000000) /* bte or btne */
1335 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
1336 nextadr += (offset << 2);
1338 else if ((instr & 0xFC000000) == 0xB4000000) /* bla */
1342 offset = SIGN_EXT16(((instr & 0x001F0000) >> 5) | (instr & 0x000007FF));
1343 nextadr += (offset << 2);
1351 extern char registers[];
1353 /* i860-specific routine to print the register set. Note that we ALWAYS print information
1354 on the floating point registers, so we ignore the parameter fpregs */
1355 void i860_do_registers_info(regnum,fpregs)
1366 "Register Contents (relative to selected stack frame)\n\n");
1368 if (regnum != -1) /* print one register */
1370 if ((regnum >=F0 ) && (regnum <= F31))
1371 bcopy (®isters[ADJ_FREG(regnum)<<2], &val, sizeof (long));
1373 bcopy (®isters[regnum<<2], &val, sizeof (long));
1374 printf("%-4s 0x%08x\t", reg_names[regnum], val);
1375 printf("\n\t"); fflush(stdout);
1377 else /* print all registers */
1380 printf("\n Control/Status Registers :- \n\t");
1381 for (j=0; j<=DB; j++)
1383 bcopy (®isters[j<<2], &val, sizeof (long));
1384 printf("%-4s 0x%08x\t", reg_names[j], val);
1386 printf("\n\t"); fflush(stdout);
1389 bcopy (®isters[EPSR<<2], &val, sizeof (long));
1390 printf("%-4s 0x%08x\t", reg_names[EPSR], val);
1393 bcopy (®isters[FSR<<2], &val, sizeof (long));
1394 printf("%-4s 0x%08x\t", reg_names[FSR], val);
1397 bcopy (®isters[CCR<<2], &val, sizeof (long));
1398 printf("%-4s 0x%08x\t", reg_names[CCR], val);
1400 bcopy (®isters[BEAR<<2], &val, sizeof (long));
1401 printf("%-4s 0x%08x\t", reg_names[BEAR], val);
1405 for (j=P0; j<=P3; j++)
1407 bcopy (®isters[j<<2], &val, sizeof (long));
1408 printf("%-4s 0x%08x\t", reg_names[j], val);
1412 printf("\n Integer Registers :- \n\t");
1413 for (j=R0; j<=R31; j++)
1415 if (j != IREGS && (j % REGISTER_LENGTH == 0))
1417 printf("\n\t"); fflush(stdout);
1419 bcopy (®isters[j<<2], &val, sizeof (long));
1420 printf("%-4s 0x%08x\t", reg_names[j], val);
1423 printf("\n Floating Registers :- \n\t");
1424 for (j=F0; j<=F31; j++)
1426 if (j != FREGS && (j % REGISTER_LENGTH == 0))
1428 printf("\n\t"); fflush(stdout);
1430 bcopy (®isters[ADJ_FREG(j)<<2], &val, sizeof (long));
1431 printf("%-4s 0x%08x\t", reg_names[j], val);
1434 printf("\n Special Registers :- \n\t");
1435 for (j=SPC_KI; j<=SPC_MERGE; j+=2)
1440 printf("\n\t"); fflush(stdout);
1442 bcopy (®isters[j<<2], &val, sizeof (long));
1443 bcopy (®isters[(j+1)<<2], &valh, sizeof (long));
1444 printf("%-6s 0x%08x %08x\t", reg_names[j], val,valh);
1447 printf("\n Graphics Pipeline :- \n");
1451 bcopy (®isters[j<<2], &val, sizeof (long));
1452 bcopy (®isters[(j+1)<<2], &valh, sizeof (long));
1453 printf("\t\t\t%-8s 0x%08x %08x \n", reg_names[j], val,valh);
1456 printf(" Memory Load Pipeline :- \n");
1457 for (j=PSV_L1; j<=PSV_L3; j+=REGISTER_LENGTH)
1459 unsigned int valh, val2,val3;
1460 bcopy (®isters[j<<2], &val, sizeof (long));
1461 bcopy (®isters[(j+1)<<2], &valh, sizeof (long));
1462 bcopy (®isters[(j+2)<<2], &val2, sizeof (long));
1463 bcopy (®isters[(j+3)<<2], &val3, sizeof (long));
1464 printf("\t\t%-8s 0x%08x %08x %08x %08x\n", reg_names[j],
1465 val,valh,val2,val3);
1468 printf("\n Adder Pipeline :-\t\tMultiplier Pipeline :-\t\tFSR results :-\n");
1469 for (i=PSV_FSR1,j=PSV_A1,k=PSV_M1; j<=PSV_A3; i++,j+=2,k+=2)
1471 unsigned int valh,val2,val3,val4;
1472 bcopy (®isters[i<<2], &val4, sizeof (long));
1473 bcopy (®isters[j<<2], &val, sizeof (long));
1474 bcopy (®isters[(j+1)<<2], &valh, sizeof (long));
1475 bcopy (®isters[k<<2], &val2, sizeof (long));
1476 bcopy (®isters[(k+1)<<2], &val3, sizeof (long));
1477 printf(" %-4s 0x%08x %08x\t", reg_names[j], val,valh);
1478 printf("%-4s 0x%08x %08x\t", reg_names[k], val2,val3);
1479 printf("%-4s 0x%08x\n", reg_names[i], val4);
1489 /* The following set of routines was adapted from existing code previously
1490 in an i860-specific version of breakpoint.c by Peggy Fieland
1492 /* routines to set a data breakpoint by setting the value in the DB register.
1493 Note that "hitting" the breakpoint will generate a data access trap. We
1494 do not have a special trap handler. */
1495 unsigned int dbrkval, dbrkmod;
1496 void i860_dbrk_breakpoint()
1498 BTDEBUG("i860_dbrk_breakpoint was called , dbrkval %x\n", dbrkval);
1502 *(int *)®isters[DB<<2] = dbrkval;
1506 *(int *)®isters[DB<<2] = 0;
1509 *(int *)®isters[PSR<<2] &= ~3;
1510 *(int *)®isters[PSR<<2] |= dbrkmod;
1512 store_inferior_registers(DB);
1513 store_inferior_registers(PSR);
1517 /* set a "read" data breakpoint. */
1519 d_ro_break_command(arg)
1522 dbrkval = strtoul(arg, NULL, 0);
1524 BTDEBUG(" ro_dbreak - %x %x\n", dbrkval, dbrkmod);
1527 /* set a "write" data breakpoint. */
1529 d_wo_break_command(arg)
1532 dbrkval = strtoul(arg, NULL, 0);
1534 BTDEBUG(" wo_dbreak - %x %x\n", dbrkval, dbrkmod);
1537 /* set a "read/write" data breakpoint. */
1539 d_rw_break_command(arg)
1542 dbrkval = strtoul(arg, NULL, 0);
1544 BTDEBUG(" rw_dbreak - %x %x\n", dbrkval, dbrkmod);
1547 /* clear data breakpoint. */
1555 /* i860-specific breakpoint initialization. Includes adding the i860-specific
1556 data breakpoint commands. */
1558 i860_init_breakpoints()
1560 dbrkval = dbrkmod = 0;
1561 add_com ("dbro", class_breakpoint, d_ro_break_command,
1562 "Set a data breakpoint READ ONLY, 32-bit data element.");
1563 add_com ("dbwo", class_breakpoint, d_wo_break_command,
1564 "Set a data breakpoint WRITE ONLY, 32-bit data element.");
1565 add_com ("dbrw", class_breakpoint, d_rw_break_command,
1566 "Set a data breakpoint READ/WRITE, 32-bit data element.");
1567 add_com ("dclear", class_breakpoint, clear_dbreak,
1568 "clear the current data breakpoint.");
1569 add_com_alias ("dc", "dclear", class_breakpoint, 1);
1573 /* i860-specific code to insert a breakpoint. */
1574 int i860_insert_breakpoint(b)
1575 struct breakpoint *b;
1579 place_brk( b->address, BREAK_MODE, b );
1583 adj_read_memory (b->act_addr[0], &b->shadow_contents[0], INSTRUCTION_LENGTH);
1584 val = adj_write_memory (b->act_addr[0], break_insn, INSTRUCTION_LENGTH);
1585 if (val != 0 ) return val;
1586 adj_read_memory (b->act_addr[1], &b->shadow_contents[1], INSTRUCTION_LENGTH);
1587 /* val = adj_write_memory (b->act_addr[1], float_insn, INSTRUCTION_LENGTH); */
1588 if (val != 0) return val;
1592 adj_read_memory (b->act_addr[0], &b->shadow_contents[0], INSTRUCTION_LENGTH);
1593 val = adj_write_memory (b->act_addr[0], break_insn, INSTRUCTION_LENGTH);
1595 if (b->address1 != 0)
1600 adj_read_memory (b->act_addr[2], &b->shadow_contents[2], INSTRUCTION_LENGTH);
1601 val = adj_write_memory (b->act_addr[2], break_insn, INSTRUCTION_LENGTH);
1602 if (val) return val;
1603 adj_read_memory (b->act_addr[3], &b->shadow_contents[3], INSTRUCTION_LENGTH);
1604 /* val = adj_write_memory (b->act_addr[3], float_insn, INSTRUCTION_LENGTH); */
1605 if (val != 0) return val;
1609 adj_read_memory (b->act_addr[2], &b->shadow_contents[0], INSTRUCTION_LENGTH);
1610 val = adj_write_memory (b->act_addr[2], break_insn, INSTRUCTION_LENGTH);
1615 BTDEBUG("Inserted breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
1616 b->address, b->shadow_contents[0], b->shadow_contents[1]);
1621 int i860_remove_breakpoint(b)
1622 struct breakpoint *b;
1630 val =adj_write_memory (b->act_addr[0], &(b->shadow_contents[0]),
1631 INSTRUCTION_LENGTH);
1632 val =adj_write_memory (b->act_addr[1], &(b->shadow_contents[1]),
1633 INSTRUCTION_LENGTH);
1634 if (b->address1 != NULL)
1636 val =adj_write_memory (b->act_addr[2], &(b->shadow_contents[2]),
1637 INSTRUCTION_LENGTH);
1638 val =adj_write_memory (b->act_addr[3], &(b->shadow_contents[3]),
1639 INSTRUCTION_LENGTH);
1644 val =adj_write_memory (b->act_addr[0], b->shadow_contents,
1645 INSTRUCTION_LENGTH);
1646 if (b->address1 != NULL)
1648 val =adj_write_memory (b->act_addr[2], b->shadow_contents,
1649 INSTRUCTION_LENGTH);
1655 BTDEBUG( "Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
1656 b->address, b->shadow_contents[0], b->shadow_contents[1]);
1665 #ifdef USE_PROC_FS /* Target dependent support for /proc */
1667 #include <sys/procfs.h>
1670 They were adapted from the m-68k versions of the routines .*/
1672 /* Given a pointer to a floating point register set in /proc format
1673 (fpregset_t *), unpack the register contents and supply them as gdb's
1674 idea of the current floating point register values. */
1677 supply_fpregset (fpregsetp)
1678 fpregset_t *fpregsetp;
1682 BTDEBUG("supply_fregset called \n");
1684 for (regno = F0 ; regno <= F31 ; regno++)
1686 supply_register (regno, (char *) &(fpregsetp -> fpu.r_freg[regno-F0]));
1690 /* Given a pointer to a floating point register set in /proc format
1691 (fpregset_t *), update the register specified by REGNO from gdb's idea
1692 of the current floating point register set. If REGNO is -1, update
1696 fill_fpregset (fpregsetp, regno)
1697 fpregset_t *fpregsetp;
1703 extern char registers[];
1704 BTDEBUG("fill_fregset regno %d\n",regno);
1706 for (regi = F0 ; regi <= F31 ; regi++)
1708 if ((regno == -1) || (regno == regi))
1710 from = (char *) ®isters[REGISTER_BYTE (regi)];
1711 to = (char *) &(fpregsetp -> fpu.r_freg[regi-F0]);
1712 bcopy (from, to, REGISTER_RAW_SIZE (regno));
1718 /* Given a pointer to a general register set in /proc format (gregset_t *),
1719 unpack the register contents and supply them as gdb's idea of the current
1723 supply_gregset (gregsetp)
1724 gregset_t *gregsetp;
1727 register greg_t *regp = (greg_t *) gregsetp;
1729 BTDEBUG("supply_gregset called \n");
1731 for (regno = 0 ; regno <= R31 ; regno++)
1733 supply_register (regno, (char *) (regp + regno));
1737 /* Given a pointer to a general register set in /proc format (gregset_t *),
1738 update the register specified by REGNO from gdb's idea
1739 of the current general register set. If REGNO is -1, update
1743 fill_gregset (gregsetp, regno)
1744 gregset_t *gregsetp;
1748 extern char registers[];
1749 register greg_t *regp = (greg_t *) gregsetp;
1750 BTDEBUG("fill_gregset regno %d \n",regno);
1752 for (regi = 0 ; regi <= R31 ; regi++)
1754 if ((regno == -1) || (regno == regi))
1756 *(regp + regi) = *(int *) ®isters[REGISTER_BYTE (regi)];