home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / gdb / sparc-td.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  23.4 KB  |  795 lines

  1. /* Target-dependent code for the SPARC for GDB, the GNU debugger.
  2.    Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "frame.h"
  22. #include "inferior.h"
  23. #include "obstack.h"
  24. #include "target.h"
  25. #include "ieee-float.h"
  26.  
  27. #include "symfile.h" /* for objfiles.h */
  28. #include "objfiles.h" /* for find_pc_section */
  29.  
  30. #ifdef    USE_PROC_FS
  31. #include <sys/procfs.h>
  32. #endif
  33.  
  34. #include "gdbcore.h"
  35.  
  36. /* From infrun.c */
  37. extern int stop_after_trap;
  38.  
  39. /* We don't store all registers immediately when requested, since they
  40.    get sent over in large chunks anyway.  Instead, we accumulate most
  41.    of the changes and send them over once.  "deferred_stores" keeps
  42.    track of which sets of registers we have locally-changed copies of,
  43.    so we only need send the groups that have changed.  */
  44.  
  45. int deferred_stores = 0;    /* Cumulates stores we want to do eventually. */
  46.  
  47. typedef enum
  48. {
  49.   Error, not_branch, bicc, bicca, ba, baa, ticc, ta
  50. } branch_type;
  51.  
  52. /* Simulate single-step ptrace call for sun4.  Code written by Gary
  53.    Beihl (beihl@mcc.com).  */
  54.  
  55. /* npc4 and next_pc describe the situation at the time that the
  56.    step-breakpoint was set, not necessary the current value of NPC_REGNUM.  */
  57. static CORE_ADDR next_pc, npc4, target;
  58. static int brknpc4, brktrg;
  59. typedef char binsn_quantum[BREAKPOINT_MAX];
  60. static binsn_quantum break_mem[3];
  61.  
  62. /* Non-zero if we just simulated a single-step ptrace call.  This is
  63.    needed because we cannot remove the breakpoints in the inferior
  64.    process until after the `wait' in `wait_for_inferior'.  Used for
  65.    sun4. */
  66.  
  67. int one_stepped;
  68.  
  69. /* single_step() is called just before we want to resume the inferior,
  70.    if we want to single-step it but there is no hardware or kernel single-step
  71.    support (as on all SPARCs).  We find all the possible targets of the
  72.    coming instruction and breakpoint them.
  73.  
  74.    single_step is also called just after the inferior stops.  If we had
  75.    set up a simulated single-step, we undo our damage.  */
  76.  
  77. void
  78. single_step (ignore)
  79.      int ignore; /* pid, but we don't need it */
  80. {
  81.   branch_type br, isannulled();
  82.   CORE_ADDR pc;
  83.   long pc_instruction;
  84.  
  85.   if (!one_stepped)
  86.     {
  87.       /* Always set breakpoint for NPC.  */
  88.       next_pc = read_register (NPC_REGNUM);
  89.       npc4 = next_pc + 4; /* branch not taken */
  90.  
  91.       target_insert_breakpoint (next_pc, break_mem[0]);
  92.       /* printf_unfiltered ("set break at %x\n",next_pc); */
  93.  
  94.       pc = read_register (PC_REGNUM);
  95.       pc_instruction = read_memory_integer (pc, sizeof(pc_instruction));
  96.       br = isannulled (pc_instruction, pc, &target);
  97.       brknpc4 = brktrg = 0;
  98.  
  99.       if (br == bicca)
  100.     {
  101.       /* Conditional annulled branch will either end up at
  102.          npc (if taken) or at npc+4 (if not taken).
  103.          Trap npc+4.  */
  104.       brknpc4 = 1;
  105.       target_insert_breakpoint (npc4, break_mem[1]);
  106.     }
  107.       else if (br == baa && target != next_pc)
  108.     {
  109.       /* Unconditional annulled branch will always end up at
  110.          the target.  */
  111.       brktrg = 1;
  112.       target_insert_breakpoint (target, break_mem[2]);
  113.     }
  114.  
  115.       /* We are ready to let it go */
  116.       one_stepped = 1;
  117.       return;
  118.     }
  119.   else
  120.     {
  121.       /* Remove breakpoints */
  122.       target_remove_breakpoint (next_pc, break_mem[0]);
  123.  
  124.       if (brknpc4)
  125.     target_remove_breakpoint (npc4, break_mem[1]);
  126.  
  127.       if (brktrg)
  128.     target_remove_breakpoint (target, break_mem[2]);
  129.  
  130.       one_stepped = 0;
  131.     }
  132. }
  133.  
  134. #define    FRAME_SAVED_L0    0                /* Byte offset from SP */
  135. #define    FRAME_SAVED_I0    (8 * REGISTER_RAW_SIZE (0)) /* Byte offset from SP */
  136.  
  137. CORE_ADDR
  138. sparc_frame_chain (thisframe)
  139.      FRAME thisframe;
  140. {
  141.   char buf[MAX_REGISTER_RAW_SIZE];
  142.   int err;
  143.   CORE_ADDR addr;
  144.  
  145.   addr = thisframe->frame + FRAME_SAVED_I0 +
  146.      REGISTER_RAW_SIZE (FP_REGNUM) * (FP_REGNUM - I0_REGNUM);
  147.   err = target_read_memory (addr, buf, REGISTER_RAW_SIZE (FP_REGNUM));
  148.   if (err)
  149.     return 0;
  150.   return extract_address (buf, REGISTER_RAW_SIZE (FP_REGNUM));
  151. }
  152.  
  153. CORE_ADDR
  154. sparc_extract_struct_value_address (regbuf)
  155.      char regbuf[REGISTER_BYTES];
  156. {
  157.   return read_memory_integer (((int *)(regbuf))[SP_REGNUM]+(16*4), 
  158.                          TARGET_PTR_BIT / TARGET_CHAR_BIT);
  159. }
  160.  
  161. /* Find the pc saved in frame FRAME.  */
  162.  
  163. CORE_ADDR
  164. frame_saved_pc (frame)
  165.      FRAME frame;
  166. {
  167.   char buf[MAX_REGISTER_RAW_SIZE];
  168.   CORE_ADDR addr;
  169.  
  170.   addr = (frame->bottom + FRAME_SAVED_I0 +
  171.       REGISTER_RAW_SIZE (I7_REGNUM) * (I7_REGNUM - I0_REGNUM));
  172.   read_memory (addr, buf, REGISTER_RAW_SIZE (I7_REGNUM));
  173.   return PC_ADJUST (extract_address (buf, REGISTER_RAW_SIZE (I7_REGNUM)));
  174. }
  175.  
  176. /*
  177.  * Since an individual frame in the frame cache is defined by two
  178.  * arguments (a frame pointer and a stack pointer), we need two
  179.  * arguments to get info for an arbitrary stack frame.  This routine
  180.  * takes two arguments and makes the cached frames look as if these
  181.  * two arguments defined a frame on the cache.  This allows the rest
  182.  * of info frame to extract the important arguments without
  183.  * difficulty. 
  184.  */
  185. FRAME
  186. setup_arbitrary_frame (argc, argv)
  187.      int argc;
  188.      FRAME_ADDR *argv;
  189. {
  190.   FRAME fid;
  191.  
  192.   if (argc != 2)
  193.     error ("Sparc frame specifications require two arguments: fp and sp");
  194.  
  195.   fid = create_new_frame (argv[0], 0);
  196.  
  197.   if (!fid)
  198.     fatal ("internal: create_new_frame returned invalid frame id");
  199.   
  200.   fid->bottom = argv[1];
  201.   fid->pc = FRAME_SAVED_PC (fid);
  202.   return fid;
  203. }
  204.  
  205. /* Given a pc value, skip it forward past the function prologue by
  206.    disassembling instructions that appear to be a prologue.
  207.  
  208.    If FRAMELESS_P is set, we are only testing to see if the function
  209.    is frameless.  This allows a quicker answer.
  210.  
  211.    This routine should be more specific in its actions; making sure
  212.    that it uses the same register in the initial prologue section.  */
  213. CORE_ADDR 
  214. skip_prologue (start_pc, frameless_p)
  215.      CORE_ADDR start_pc;
  216.      int frameless_p;
  217. {
  218.   union
  219.     {
  220.       unsigned long int code;
  221.       struct
  222.     {
  223.       unsigned int op:2;
  224.       unsigned int rd:5;
  225.       unsigned int op2:3;
  226.       unsigned int imm22:22;
  227.     } sethi;
  228.       struct
  229.     {
  230.       unsigned int op:2;
  231.       unsigned int rd:5;
  232.       unsigned int op3:6;
  233.       unsigned int rs1:5;
  234.       unsigned int i:1;
  235.       unsigned int simm13:13;
  236.     } add;
  237.       int i;
  238.     } x;
  239.   int dest = -1;
  240.   CORE_ADDR pc = start_pc;
  241.  
  242.   x.i = read_memory_integer (pc, 4);
  243.  
  244.   /* Recognize the `sethi' insn and record its destination.  */
  245.   if (x.sethi.op == 0 && x.sethi.op2 == 4)
  246.     {
  247.       dest = x.sethi.rd;
  248.       pc += 4;
  249.       x.i = read_memory_integer (pc, 4);
  250.     }
  251.  
  252.   /* Recognize an add immediate value to register to either %g1 or
  253.      the destination register recorded above.  Actually, this might
  254.      well recognize several different arithmetic operations.
  255.      It doesn't check that rs1 == rd because in theory "sub %g0, 5, %g1"
  256.      followed by "save %sp, %g1, %sp" is a valid prologue (Not that
  257.      I imagine any compiler really does that, however).  */
  258.   if (x.add.op == 2 && x.add.i && (x.add.rd == 1 || x.add.rd == dest))
  259.     {
  260.       pc += 4;
  261.       x.i = read_memory_integer (pc, 4);
  262.     }
  263.  
  264.   /* This recognizes any SAVE insn.  But why do the XOR and then
  265.      the compare?  That's identical to comparing against 60 (as long
  266.      as there isn't any sign extension).  */
  267.   if (x.add.op == 2 && (x.add.op3 ^ 32) == 28)
  268.     {
  269.       pc += 4;
  270.       if (frameless_p)            /* If the save is all we care about, */
  271.     return pc;            /* return before doing more work */
  272.       x.i = read_memory_integer (pc, 4);
  273.     }
  274.   else
  275.     {
  276.       /* Without a save instruction, it's not a prologue.  */
  277.       return start_pc;
  278.     }
  279.  
  280.   /* Now we need to recognize stores into the frame from the input
  281.      registers.  This recognizes all non alternate stores of input
  282.      register, into a location offset from the frame pointer.  */
  283.   while (x.add.op == 3
  284.      && (x.add.op3 & 0x3c) == 4 /* Store, non-alternate.  */
  285.      && (x.add.rd & 0x18) == 0x18 /* Input register.  */
  286.      && x.add.i        /* Immediate mode.  */
  287.      && x.add.rs1 == 30    /* Off of frame pointer.  */
  288.      /* Into reserved stack space.  */
  289.      && x.add.simm13 >= 0x44
  290.      && x.add.simm13 < 0x5b)
  291.     {
  292.       pc += 4;
  293.       x.i = read_memory_integer (pc, 4);
  294.     }
  295.   return pc;
  296. }
  297.  
  298. /* Check instruction at ADDR to see if it is an annulled branch.
  299.    All other instructions will go to NPC or will trap.
  300.    Set *TARGET if we find a canidate branch; set to zero if not. */
  301.    
  302. branch_type
  303. isannulled (instruction, addr, target)
  304.      long instruction;
  305.      CORE_ADDR addr, *target;
  306. {
  307.   branch_type val = not_branch;
  308.   long int offset;        /* Must be signed for sign-extend.  */
  309.   union
  310.     {
  311.       unsigned long int code;
  312.       struct
  313.     {
  314.       unsigned int op:2;
  315.       unsigned int a:1;
  316.       unsigned int cond:4;
  317.       unsigned int op2:3;
  318.       unsigned int disp22:22;
  319.     } b;
  320.     } insn;
  321.  
  322.   *target = 0;
  323.   insn.code = instruction;
  324.  
  325.   if (insn.b.op == 0
  326.       && (insn.b.op2 == 2 || insn.b.op2 == 6 || insn.b.op2 == 7))
  327.     {
  328.       if (insn.b.cond == 8)
  329.     val = insn.b.a ? baa : ba;
  330.       else
  331.     val = insn.b.a ? bicca : bicc;
  332.       offset = 4 * ((int) (insn.b.disp22 << 10) >> 10);
  333.       *target = addr + offset;
  334.     }
  335.  
  336.   return val;
  337. }
  338.  
  339. /* sparc_frame_find_saved_regs ()
  340.  
  341.    Stores, into a struct frame_saved_regs,
  342.    the addresses of the saved registers of frame described by FRAME_INFO.
  343.    This includes special registers such as pc and fp saved in special
  344.    ways in the stack frame.  sp is even more special:
  345.    the address we return for it IS the sp for the next frame.
  346.  
  347.    Note that on register window machines, we are currently making the
  348.    assumption that window registers are being saved somewhere in the
  349.    frame in which they are being used.  If they are stored in an
  350.    inferior frame, find_saved_register will break.
  351.  
  352.    On the Sun 4, the only time all registers are saved is when
  353.    a dummy frame is involved.  Otherwise, the only saved registers
  354.    are the LOCAL and IN registers which are saved as a result
  355.    of the "save/restore" opcodes.  This condition is determined
  356.    by address rather than by value.
  357.  
  358.    The "pc" is not stored in a frame on the SPARC.  (What is stored
  359.    is a return address minus 8.)  sparc_pop_frame knows how to
  360.    deal with that.  Other routines might or might not.
  361.  
  362.    See tm-sparc.h (PUSH_FRAME and friends) for CRITICAL information
  363.    about how this works.  */
  364.  
  365. void
  366. sparc_frame_find_saved_regs (fi, saved_regs_addr)
  367.      struct frame_info *fi;
  368.      struct frame_saved_regs *saved_regs_addr;
  369. {
  370.   register int regnum;
  371.   FRAME_ADDR frame = read_register (FP_REGNUM);
  372.   FRAME fid = FRAME_INFO_ID (fi);
  373.  
  374.   if (!fid)
  375.     fatal ("Bad frame info struct in FRAME_FIND_SAVED_REGS");
  376.  
  377.   memset (saved_regs_addr, 0, sizeof (*saved_regs_addr));
  378.  
  379.   /* Old test.
  380.   if (fi->pc >= frame - CALL_DUMMY_LENGTH - 0x140
  381.       && fi->pc <= frame) */
  382.  
  383.   if (fi->pc >= (fi->bottom ? fi->bottom :
  384.            read_register (SP_REGNUM))
  385.       && fi->pc <= FRAME_FP(fi))
  386.     {
  387.       /* Dummy frame.  All but the window regs are in there somewhere. */
  388.       for (regnum = G1_REGNUM; regnum < G1_REGNUM+7; regnum++)
  389.     saved_regs_addr->regs[regnum] =
  390.       frame + (regnum - G0_REGNUM) * 4 - 0xa0;
  391.       for (regnum = I0_REGNUM; regnum < I0_REGNUM+8; regnum++)
  392.     saved_regs_addr->regs[regnum] =
  393.       frame + (regnum - I0_REGNUM) * 4 - 0xc0;
  394.       for (regnum = FP0_REGNUM; regnum < FP0_REGNUM + 32; regnum++)
  395.     saved_regs_addr->regs[regnum] =
  396.       frame + (regnum - FP0_REGNUM) * 4 - 0x80;
  397.       for (regnum = Y_REGNUM; regnum < NUM_REGS; regnum++)
  398.     saved_regs_addr->regs[regnum] =
  399.       frame + (regnum - Y_REGNUM) * 4 - 0xe0;
  400.       frame = fi->bottom ?
  401.     fi->bottom : read_register (SP_REGNUM);
  402.     }
  403.   else
  404.     {
  405.       /* Normal frame.  Just Local and In registers */
  406.       frame = fi->bottom ?
  407.     fi->bottom : read_register (SP_REGNUM);
  408.       for (regnum = L0_REGNUM; regnum < L0_REGNUM+16; regnum++)
  409.     saved_regs_addr->regs[regnum] = frame + (regnum-L0_REGNUM) * 4;
  410.     }
  411.   if (fi->next)
  412.     {
  413.       /* Pull off either the next frame pointer or the stack pointer */
  414.       FRAME_ADDR next_next_frame =
  415.     (fi->next->bottom ?
  416.      fi->next->bottom :
  417.      read_register (SP_REGNUM));
  418.       for (regnum = O0_REGNUM; regnum < O0_REGNUM+8; regnum++)
  419.     saved_regs_addr->regs[regnum] = next_next_frame + regnum * 4;
  420.     }
  421.   /* Otherwise, whatever we would get from ptrace(GETREGS) is accurate */
  422.   saved_regs_addr->regs[SP_REGNUM] = FRAME_FP (fi);
  423. }
  424.  
  425. /* Push an empty stack frame, and record in it the current PC, regs, etc.
  426.  
  427.    We save the non-windowed registers and the ins.  The locals and outs
  428.    are new; they don't need to be saved. The i's and l's of
  429.    the last frame were already saved on the stack
  430.  
  431.    The return pointer register %i7 does not have the pc saved into it
  432.    (return from this frame will be accomplished by a POP_FRAME).  In
  433.    fact, we must leave it unclobbered, since we must preserve it in
  434.    the calling routine except across call instructions.  I'm not sure
  435.    the preceding sentence is true; isn't it based on confusing the %i7
  436.    saved in the dummy frame versus the one saved in the frame of the
  437.    calling routine?  */
  438.  
  439. /* Definitely see tm-sparc.h for more doc of the frame format here.  */
  440.  
  441. void
  442. sparc_push_dummy_frame ()
  443. {
  444.   CORE_ADDR sp, old_sp;
  445.   char register_temp[0x140];
  446.  
  447.   old_sp = sp = read_register (SP_REGNUM);
  448.  
  449.   /* Y, PS, WIM, TBR, PC, NPC, FPS, CPS regs */
  450.   read_register_bytes (REGISTER_BYTE (Y_REGNUM), ®ister_temp[0],
  451.                REGISTER_RAW_SIZE (Y_REGNUM) * 8);
  452.  
  453.   read_register_bytes (REGISTER_BYTE (O0_REGNUM), ®ister_temp[8 * 4],
  454.                REGISTER_RAW_SIZE (O0_REGNUM) * 8);
  455.  
  456.   read_register_bytes (REGISTER_BYTE (G0_REGNUM), ®ister_temp[16 * 4],
  457.                REGISTER_RAW_SIZE (G0_REGNUM) * 8);
  458.  
  459.   read_register_bytes (REGISTER_BYTE (FP0_REGNUM), ®ister_temp[24 * 4],
  460.                REGISTER_RAW_SIZE (FP0_REGNUM) * 32);
  461.  
  462.   sp -= 0x140;
  463.  
  464.   write_register (SP_REGNUM, sp);
  465.  
  466.   write_memory (sp + 0x60, ®ister_temp[0], (8 + 8 + 8 + 32) * 4);
  467.  
  468.   write_register (FP_REGNUM, old_sp);
  469. }
  470.  
  471. /* Discard from the stack the innermost frame, restoring all saved registers.
  472.  
  473.    Note that the values stored in fsr by get_frame_saved_regs are *in
  474.    the context of the called frame*.  What this means is that the i
  475.    regs of fsr must be restored into the o regs of the (calling) frame that
  476.    we pop into.  We don't care about the output regs of the calling frame,
  477.    since unless it's a dummy frame, it won't have any output regs in it.
  478.  
  479.    We never have to bother with %l (local) regs, since the called routine's
  480.    locals get tossed, and the calling routine's locals are already saved
  481.    on its stack.  */
  482.  
  483. /* Definitely see tm-sparc.h for more doc of the frame format here.  */
  484.  
  485. void
  486. sparc_pop_frame ()
  487. {
  488.   register FRAME frame = get_current_frame ();
  489.   register CORE_ADDR pc;
  490.   struct frame_saved_regs fsr;
  491.   struct frame_info *fi;
  492.   char raw_buffer[REGISTER_BYTES];
  493.  
  494.   fi = get_frame_info (frame);
  495.   get_frame_saved_regs (fi, &fsr);
  496.   if (fsr.regs[FP0_REGNUM])
  497.     {
  498.       read_memory (fsr.regs[FP0_REGNUM], raw_buffer, 32 * 4);
  499.       write_register_bytes (REGISTER_BYTE (FP0_REGNUM), raw_buffer, 32 * 4);
  500.     }
  501.   if (fsr.regs[FPS_REGNUM])
  502.     {
  503.       read_memory (fsr.regs[FPS_REGNUM], raw_buffer, 4);
  504.       write_register_bytes (REGISTER_BYTE (FPS_REGNUM), raw_buffer, 4);
  505.     }
  506.   if (fsr.regs[CPS_REGNUM])
  507.     {
  508.       read_memory (fsr.regs[CPS_REGNUM], raw_buffer, 4);
  509.       write_register_bytes (REGISTER_BYTE (CPS_REGNUM), raw_buffer, 4);
  510.     }
  511.   if (fsr.regs[G1_REGNUM])
  512.     {
  513.       read_memory (fsr.regs[G1_REGNUM], raw_buffer, 7 * 4);
  514.       write_register_bytes (REGISTER_BYTE (G1_REGNUM), raw_buffer, 7 * 4);
  515.     }
  516.   if (fsr.regs[I0_REGNUM])
  517.     {
  518.       CORE_ADDR sp;
  519.  
  520.       char reg_temp[REGISTER_BYTES];
  521.  
  522.       read_memory (fsr.regs[I0_REGNUM], raw_buffer, 8 * 4);
  523.  
  524.       /* Get the ins and locals which we are about to restore.  Just
  525.      moving the stack pointer is all that is really needed, except
  526.      store_inferior_registers is then going to write the ins and
  527.      locals from the registers array, so we need to muck with the
  528.      registers array.  */
  529.       sp = fsr.regs[SP_REGNUM];
  530.       read_memory (sp, reg_temp, REGISTER_RAW_SIZE (L0_REGNUM) * 16);
  531.  
  532.       /* Restore the out registers.
  533.      Among other things this writes the new stack pointer.  */
  534.       write_register_bytes (REGISTER_BYTE (O0_REGNUM), raw_buffer,
  535.                 REGISTER_RAW_SIZE (O0_REGNUM) * 8);
  536.  
  537.       write_register_bytes (REGISTER_BYTE (L0_REGNUM), reg_temp,
  538.                 REGISTER_RAW_SIZE (L0_REGNUM) * 16);
  539.     }
  540.   if (fsr.regs[PS_REGNUM])
  541.     write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4));
  542.   if (fsr.regs[Y_REGNUM])
  543.     write_register (Y_REGNUM, read_memory_integer (fsr.regs[Y_REGNUM], 4));
  544.   if (fsr.regs[PC_REGNUM])
  545.     {
  546.       /* Explicitly specified PC (and maybe NPC) -- just restore them. */
  547.       write_register (PC_REGNUM, read_memory_integer (fsr.regs[PC_REGNUM], 4));
  548.       if (fsr.regs[NPC_REGNUM])
  549.     write_register (NPC_REGNUM,
  550.             read_memory_integer (fsr.regs[NPC_REGNUM], 4));
  551.     }
  552.   else if (fsr.regs[I7_REGNUM])
  553.     {
  554.       /* Return address in %i7 -- adjust it, then restore PC and NPC from it */
  555.       pc = PC_ADJUST (read_memory_integer (fsr.regs[I7_REGNUM], 4));
  556.       write_register (PC_REGNUM,  pc);
  557.       write_register (NPC_REGNUM, pc + 4);
  558.     }
  559.   flush_cached_frames ();
  560.   set_current_frame ( create_new_frame (read_register (FP_REGNUM),
  561.                     read_pc ()));
  562. }
  563.  
  564. /* On the Sun 4 under SunOS, the compile will leave a fake insn which
  565.    encodes the structure size being returned.  If we detect such
  566.    a fake insn, step past it.  */
  567.  
  568. CORE_ADDR
  569. sparc_pc_adjust(pc)
  570.      CORE_ADDR pc;
  571. {
  572.   unsigned long insn;
  573.   char buf[4];
  574.   int err;
  575.  
  576.   err = target_read_memory (pc + 8, buf, sizeof(long));
  577.   insn = extract_unsigned_integer (buf, 4);
  578.   if ((err == 0) && (insn & 0xfffffe00) == 0)
  579.     return pc+12;
  580.   else
  581.     return pc+8;
  582. }
  583.  
  584.  
  585. /* Structure of SPARC extended floating point numbers.
  586.    This information is not currently used by GDB, since no current SPARC
  587.    implementations support extended float.  */
  588.  
  589. const struct ext_format ext_format_sparc = {
  590. /* tot sbyte smask expbyte manbyte */
  591.    16, 0,    0x80, 0,1,       4,8,        /* sparc */
  592. };
  593.  
  594. #ifdef USE_PROC_FS    /* Target dependent support for /proc */
  595.  
  596. /*  The /proc interface divides the target machine's register set up into
  597.     two different sets, the general register set (gregset) and the floating
  598.     point register set (fpregset).  For each set, there is an ioctl to get
  599.     the current register set and another ioctl to set the current values.
  600.  
  601.     The actual structure passed through the ioctl interface is, of course,
  602.     naturally machine dependent, and is different for each set of registers.
  603.     For the sparc for example, the general register set is typically defined
  604.     by:
  605.  
  606.     typedef int gregset_t[38];
  607.  
  608.     #define    R_G0    0
  609.     ...
  610.     #define    R_TBR    37
  611.  
  612.     and the floating point set by:
  613.  
  614.     typedef struct prfpregset {
  615.         union { 
  616.             u_long  pr_regs[32]; 
  617.             double  pr_dregs[16];
  618.         } pr_fr;
  619.         void *  pr_filler;
  620.         u_long  pr_fsr;
  621.         u_char  pr_qcnt;
  622.         u_char  pr_q_entrysize;
  623.         u_char  pr_en;
  624.         u_long  pr_q[64];
  625.     } prfpregset_t;
  626.  
  627.     These routines provide the packing and unpacking of gregset_t and
  628.     fpregset_t formatted data.
  629.  
  630.  */
  631.  
  632.  
  633. /*  Given a pointer to a general register set in /proc format (gregset_t *),
  634.     unpack the register contents and supply them as gdb's idea of the current
  635.     register values. */
  636.  
  637. void
  638. supply_gregset (gregsetp)
  639. prgregset_t *gregsetp;
  640. {
  641.   register int regi;
  642.   register prgreg_t *regp = (prgreg_t *) gregsetp;
  643.  
  644.   /* GDB register numbers for Gn, On, Ln, In all match /proc reg numbers.  */
  645.   for (regi = G0_REGNUM ; regi <= I7_REGNUM ; regi++)
  646.     {
  647.       supply_register (regi, (char *) (regp + regi));
  648.     }
  649.  
  650.   /* These require a bit more care.  */
  651.   supply_register (PS_REGNUM, (char *) (regp + R_PS));
  652.   supply_register (PC_REGNUM, (char *) (regp + R_PC));
  653.   supply_register (NPC_REGNUM,(char *) (regp + R_nPC));
  654.   supply_register (Y_REGNUM,  (char *) (regp + R_Y));
  655. }
  656.  
  657. void
  658. fill_gregset (gregsetp, regno)
  659. prgregset_t *gregsetp;
  660. int regno;
  661. {
  662.   int regi;
  663.   register prgreg_t *regp = (prgreg_t *) gregsetp;
  664.   extern char registers[];
  665.  
  666.   for (regi = 0 ; regi <= R_I7 ; regi++)
  667.     {
  668.       if ((regno == -1) || (regno == regi))
  669.     {
  670.       *(regp + regi) = *(int *) ®isters[REGISTER_BYTE (regi)];
  671.     }
  672.     }
  673.   if ((regno == -1) || (regno == PS_REGNUM))
  674.     {
  675.       *(regp + R_PS) = *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)];
  676.     }
  677.   if ((regno == -1) || (regno == PC_REGNUM))
  678.     {
  679.       *(regp + R_PC) = *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)];
  680.     }
  681.   if ((regno == -1) || (regno == NPC_REGNUM))
  682.     {
  683.       *(regp + R_nPC) = *(int *) ®isters[REGISTER_BYTE (NPC_REGNUM)];
  684.     }
  685.   if ((regno == -1) || (regno == Y_REGNUM))
  686.     {
  687.       *(regp + R_Y) = *(int *) ®isters[REGISTER_BYTE (Y_REGNUM)];
  688.     }
  689. }
  690.  
  691. #if defined (FP0_REGNUM)
  692.  
  693. /*  Given a pointer to a floating point register set in /proc format
  694.     (fpregset_t *), unpack the register contents and supply them as gdb's
  695.     idea of the current floating point register values. */
  696.  
  697. void 
  698. supply_fpregset (fpregsetp)
  699. prfpregset_t *fpregsetp;
  700. {
  701.   register int regi;
  702.   char *from;
  703.   
  704.   for (regi = FP0_REGNUM ; regi < FP0_REGNUM+32 ; regi++)
  705.     {
  706.       from = (char *) &fpregsetp->pr_fr.pr_regs[regi-FP0_REGNUM];
  707.       supply_register (regi, from);
  708.     }
  709.   supply_register (FPS_REGNUM, (char *) &(fpregsetp->pr_fsr));
  710. }
  711.  
  712. /*  Given a pointer to a floating point register set in /proc format
  713.     (fpregset_t *), update the register specified by REGNO from gdb's idea
  714.     of the current floating point register set.  If REGNO is -1, update
  715.     them all. */
  716.  
  717. void
  718. fill_fpregset (fpregsetp, regno)
  719. prfpregset_t *fpregsetp;
  720. int regno;
  721. {
  722.   int regi;
  723.   char *to;
  724.   char *from;
  725.   extern char registers[];
  726.  
  727.   for (regi = FP0_REGNUM ; regi < FP0_REGNUM+32 ; regi++)
  728.     {
  729.       if ((regno == -1) || (regno == regi))
  730.     {
  731.       from = (char *) ®isters[REGISTER_BYTE (regi)];
  732.       to = (char *) &fpregsetp->pr_fr.pr_regs[regi-FP0_REGNUM];
  733.       memcpy (to, from, REGISTER_RAW_SIZE (regi));
  734.     }
  735.     }
  736.   if ((regno == -1) || (regno == FPS_REGNUM))
  737.     {
  738.       fpregsetp->pr_fsr = *(int *) ®isters[REGISTER_BYTE (FPS_REGNUM)];
  739.     }
  740. }
  741.  
  742. #endif    /* defined (FP0_REGNUM) */
  743.  
  744. #endif  /* USE_PROC_FS */
  745.  
  746.  
  747. #ifdef GET_LONGJMP_TARGET
  748.  
  749. /* Figure out where the longjmp will land.  We expect that we have just entered
  750.    longjmp and haven't yet setup the stack frame, so the args are still in the
  751.    output regs.  %o0 (O0_REGNUM) points at the jmp_buf structure from which we
  752.    extract the pc (JB_PC) that we will land at.  The pc is copied into ADDR.
  753.    This routine returns true on success */
  754.  
  755. int
  756. get_longjmp_target(pc)
  757.      CORE_ADDR *pc;
  758. {
  759.   CORE_ADDR jb_addr;
  760. #define LONGJMP_TARGET_SIZE 4
  761.   char buf[LONGJMP_TARGET_SIZE];
  762.  
  763.   jb_addr = read_register(O0_REGNUM);
  764.  
  765.   if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
  766.              LONGJMP_TARGET_SIZE))
  767.     return 0;
  768.  
  769.   *pc = extract_address (buf, LONGJMP_TARGET_SIZE);
  770.  
  771.   return 1;
  772. }
  773. #endif /* GET_LONGJMP_TARGET */
  774.  
  775. /* So far used only for sparc solaris.  In sparc solaris, we recognize
  776.    a trampoline by it's section name.  That is, if the pc is in a
  777.    section named ".plt" then we are in a trampline.  */
  778.  
  779. int
  780. in_solib_trampoline(pc, name)
  781.      CORE_ADDR pc;
  782.      char *name;
  783. {
  784.   struct obj_section *s;
  785.   int retval = 0;
  786.   
  787.   s = find_pc_section(pc);
  788.   
  789.   retval = (s != NULL
  790.         && s->sec_ptr->name != NULL
  791.         && STREQ (s->sec_ptr->name, ".plt"));
  792.   return(retval);
  793. }
  794.  
  795.