along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include <stdio.h>
#include "defs.h"
#include "frame.h"
#include "inferior.h"
#include "gdbcore.h"
+#include "target.h"
+
+#ifdef USE_PROC_FS /* Target dependent support for /proc */
+#include <sys/procfs.h>
+#endif
+
+static long
+i386_get_frame_setup PARAMS ((int));
+
+static void
+i386_follow_jump PARAMS ((void));
+
+static void
+codestream_read PARAMS ((unsigned char *, int));
+
+static void
+codestream_seek PARAMS ((int));
+
+static unsigned char
+codestream_fill PARAMS ((int));
/* helper functions for tm-i386.h */
-/* stdio style buffering to minimize calls to ptrace */
+/* Stdio style buffering was used to minimize calls to ptrace, but this
+ buffering did not take into account that the code section being accessed
+ may not be an even number of buffers long (even if the buffer is only
+ sizeof(int) long). In cases where the code section size happened to
+ be a non-integral number of buffers long, attempting to read the last
+ buffer would fail. Simply using target_read_memory and ignoring errors,
+ rather than read_memory, is not the correct solution, since legitimate
+ access errors would then be totally ignored. To properly handle this
+ situation and continue to use buffering would require that this code
+ be able to determine the minimum code section size granularity (not the
+ alignment of the section itself, since the actual failing case that
+ pointed out this problem had a section alignment of 4 but was not a
+ multiple of 4 bytes long), on a target by target basis, and then
+ adjust it's buffer size accordingly. This is messy, but potentially
+ feasible. It probably needs the bfd library's help and support. For
+ now, the buffer size is set to 1. (FIXME -fnf) */
+
+#define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
static CORE_ADDR codestream_next_addr;
static CORE_ADDR codestream_addr;
-static unsigned char codestream_buf[sizeof (int)];
+static unsigned char codestream_buf[CODESTREAM_BUFSIZ];
static int codestream_off;
static int codestream_cnt;
static unsigned char
codestream_fill (peek_flag)
+ int peek_flag;
{
codestream_addr = codestream_next_addr;
- codestream_next_addr += sizeof (int);
+ codestream_next_addr += CODESTREAM_BUFSIZ;
codestream_off = 0;
- codestream_cnt = sizeof (int);
+ codestream_cnt = CODESTREAM_BUFSIZ;
read_memory (codestream_addr,
(unsigned char *)codestream_buf,
- sizeof (int));
+ CODESTREAM_BUFSIZ);
if (peek_flag)
return (codestream_peek());
static void
codestream_seek (place)
+ int place;
{
- codestream_next_addr = place & -sizeof (int);
+ codestream_next_addr = place / CODESTREAM_BUFSIZ;
+ codestream_next_addr *= CODESTREAM_BUFSIZ;
codestream_cnt = 0;
codestream_fill (1);
while (codestream_tell() != place)
static void
codestream_read (buf, count)
unsigned char *buf;
+ int count;
{
unsigned char *p;
int i;
}
/* next instruction is a jump, move to target */
-static
+
+static void
i386_follow_jump ()
{
int long_delta;
* if entry sequence doesn't make sense, return -1, and leave
* codestream pointer random
*/
+
static long
i386_get_frame_setup (pc)
+ int pc;
{
unsigned char op;
static unsigned char proto2[4] = { 0x87,0x44,0x24,0x00 };
pos = codestream_tell ();
codestream_read (buf, 4);
- if (bcmp (buf, proto1, 3) == 0)
+ if (memcmp (buf, proto1, 3) == 0)
pos += 3;
- else if (bcmp (buf, proto2, 4) == 0)
+ else if (memcmp (buf, proto2, 4) == 0)
pos += 4;
codestream_seek (pos);
int
i386_frame_num_args (fi)
- struct frame_info fi;
+ struct frame_info *fi;
{
int retpc;
unsigned char op;
nameless arguments. */
return -1;
- pfi = get_prev_frame_info ((fi));
+ pfi = get_prev_frame_info (fi);
if (pfi == 0)
{
/* Note: this can happen if we are looking at the frame for
* next instruction will be a branch back to the start.
*/
+void
i386_frame_find_saved_regs (fip, fsrp)
struct frame_info *fip;
struct frame_saved_regs *fsrp;
{
long locals;
- unsigned char *p;
unsigned char op;
CORE_ADDR dummy_bottom;
CORE_ADDR adr;
int i;
- bzero (fsrp, sizeof *fsrp);
+ (void) memset (fsrp, 0, sizeof *fsrp);
/* if frame is the end of a dummy, compute where the
* beginning would be
}
/* return pc of first real instruction */
+
+int
i386_skip_prologue (pc)
+ int pc;
{
unsigned char op;
int i;
return (codestream_tell ());
}
+void
i386_push_dummy_frame ()
{
CORE_ADDR sp = read_register (SP_REGNUM);
write_register (SP_REGNUM, sp);
}
+void
i386_pop_frame ()
{
FRAME frame = get_current_frame ();
set_current_frame ( create_new_frame (read_register (FP_REGNUM),
read_pc ()));
}
+
+#ifdef USE_PROC_FS /* Target dependent support for /proc */
+
+/* The /proc interface divides the target machine's register set up into
+ two different sets, the general register set (gregset) and the floating
+ point register set (fpregset). For each set, there is an ioctl to get
+ the current register set and another ioctl to set the current values.
+
+ The actual structure passed through the ioctl interface is, of course,
+ naturally machine dependent, and is different for each set of registers.
+ For the i386 for example, the general register set is typically defined
+ by:
+
+ typedef int gregset_t[19]; (in <sys/regset.h>)
+
+ #define GS 0 (in <sys/reg.h>)
+ #define FS 1
+ ...
+ #define UESP 17
+ #define SS 18
+
+ and the floating point set by:
+
+ typedef struct fpregset
+ {
+ union
+ {
+ struct fpchip_state // fp extension state //
+ {
+ int state[27]; // 287/387 saved state //
+ int status; // status word saved at exception //
+ } fpchip_state;
+ struct fp_emul_space // for emulators //
+ {
+ char fp_emul[246];
+ char fp_epad[2];
+ } fp_emul_space;
+ int f_fpregs[62]; // union of the above //
+ } fp_reg_set;
+ long f_wregs[33]; // saved weitek state //
+ } fpregset_t;
+
+ These routines provide the packing and unpacking of gregset_t and
+ fpregset_t formatted data.
+
+ */
+
+/* This is a duplicate of the table in i386-xdep.c. */
+
+static int regmap[] =
+{
+ EAX, ECX, EDX, EBX,
+ UESP, EBP, ESI, EDI,
+ EIP, EFL, CS, SS,
+ DS, ES, FS, GS,
+};
+
+
+/* Given a pointer to a general register set in /proc format (gregset_t *),
+ unpack the register contents and supply them as gdb's idea of the current
+ register values. */
+
+void
+supply_gregset (gregsetp)
+ gregset_t *gregsetp;
+{
+ register int regno;
+ register greg_t *regp = (greg_t *) gregsetp;
+ extern int regmap[];
+
+ for (regno = 0 ; regno < NUM_REGS ; regno++)
+ {
+ supply_register (regno, (char *) (regp + regmap[regno]));
+ }
+}
+
+void
+fill_gregset (gregsetp, regno)
+ gregset_t *gregsetp;
+ int regno;
+{
+ int regi;
+ register greg_t *regp = (greg_t *) gregsetp;
+ extern char registers[];
+ extern int regmap[];
+
+ for (regi = 0 ; regi < NUM_REGS ; regi++)
+ {
+ if ((regno == -1) || (regno == regi))
+ {
+ *(regp + regmap[regno]) = *(int *) ®isters[REGISTER_BYTE (regi)];
+ }
+ }
+}
+
+#if defined (FP0_REGNUM)
+
+/* Given a pointer to a floating point register set in /proc format
+ (fpregset_t *), unpack the register contents and supply them as gdb's
+ idea of the current floating point register values. */
+
+void
+supply_fpregset (fpregsetp)
+ fpregset_t *fpregsetp;
+{
+ register int regno;
+
+ /* FIXME: see m68k-tdep.c for an example, for the m68k. */
+}
+
+/* Given a pointer to a floating point register set in /proc format
+ (fpregset_t *), update the register specified by REGNO from gdb's idea
+ of the current floating point register set. If REGNO is -1, update
+ them all. */
+
+void
+fill_fpregset (fpregsetp, regno)
+ fpregset_t *fpregsetp;
+ int regno;
+{
+ int regi;
+ char *to;
+ char *from;
+ extern char registers[];
+
+ /* FIXME: see m68k-tdep.c for an example, for the m68k. */
+}
+
+#endif /* defined (FP0_REGNUM) */
+
+#endif /* USE_PROC_FS */
+
+#ifdef GET_LONGJMP_TARGET
+
+/* Figure out where the longjmp will land. Slurp the args out of the stack.
+ We expect the first arg to be a pointer to the jmp_buf structure from which
+ we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
+ This routine returns true on success. */
+
+int
+get_longjmp_target(pc)
+ CORE_ADDR *pc;
+{
+ CORE_ADDR sp, jb_addr;
+
+ sp = read_register(SP_REGNUM);
+
+ if (target_read_memory(sp + SP_ARG0, /* Offset of first arg on stack */
+ (char *) &jb_addr,
+ sizeof(CORE_ADDR)))
+ return 0;
+
+
+ SWAP_TARGET_AND_HOST(&jb_addr, sizeof(CORE_ADDR));
+
+ if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, (char *) pc,
+ sizeof(CORE_ADDR)))
+ return 0;
+
+ SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR));
+
+ return 1;
+}
+
+#endif /* GET_LONGJMP_TARGET */