1 /* Machine-dependent code for host Mach 386's for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
27 #if defined (GDB_TARGET_IS_MACH386)
29 #include <sys/param.h>
33 #include <sys/ioctl.h>
36 #include <sys/ptrace.h>
37 #include <machine/reg.h>
45 fetch_inferior_registers (regno
)
46 int regno
; /* Original value discarded */
48 struct regs inferior_registers
;
49 struct fp_state inferior_fp_registers
;
50 extern char registers
[];
54 ptrace (PTRACE_GETREGS
, inferior_pid
, &inferior_registers
);
55 ptrace (PTRACE_GETFPREGS
, inferior_pid
, &inferior_fp_registers
);
57 bcopy (&inferior_registers
, registers
, sizeof inferior_registers
);
59 bcopy (inferior_fp_registers
.f_st
,®isters
[REGISTER_BYTE (FP0_REGNUM
)],
60 sizeof inferior_fp_registers
.f_st
);
61 bcopy (&inferior_fp_registers
.f_ctrl
,
62 ®isters
[REGISTER_BYTE (FPC_REGNUM
)],
63 sizeof inferior_fp_registers
- sizeof inferior_fp_registers
.f_st
);
66 /* Store our register values back into the inferior.
67 If REGNO is -1, do this for all registers.
68 Otherwise, REGNO specifies which register (so we can save time). */
71 store_inferior_registers (regno
)
74 struct regs inferior_registers
;
75 struct fp_state inferior_fp_registers
;
76 extern char registers
[];
78 bcopy (registers
, &inferior_registers
, 20 * 4);
80 bcopy (®isters
[REGISTER_BYTE (FP0_REGNUM
)],inferior_fp_registers
.f_st
,
81 sizeof inferior_fp_registers
.f_st
);
82 bcopy (®isters
[REGISTER_BYTE (FPC_REGNUM
)],
83 &inferior_fp_registers
.f_ctrl
,
84 sizeof inferior_fp_registers
- sizeof inferior_fp_registers
.f_st
);
87 if (regno
== FP_REGNUM
|| regno
== -1)
88 /* Storing the frame pointer requires a gross hack, in which an
89 instruction that moves eax into ebp gets single-stepped. */
91 int stack
= inferior_registers
.r_reg
[SP_REGNUM
];
92 int stuff
= ptrace (PTRACE_PEEKDATA
, inferior_pid
, stack
);
93 int reg
= inferior_registers
.r_reg
[EAX
];
94 inferior_registers
.r_reg
[EAX
] =
95 inferior_registers
.r_reg
[FP_REGNUM
];
96 ptrace (PTRACE_SETREGS
, inferior_pid
, &inferior_registers
);
97 ptrace (PTRACE_POKEDATA
, inferior_pid
, stack
, 0xc589);
98 ptrace (PTRACE_SINGLESTEP
, inferior_pid
, stack
, 0);
100 ptrace (PTRACE_POKEDATA
, inferior_pid
, stack
, stuff
);
101 inferior_registers
.r_reg
[EAX
] = reg
;
104 ptrace (PTRACE_SETREGS
, inferior_pid
, &inferior_registers
);
105 ptrace (PTRACE_SETFPREGS
, inferior_pid
, &inferior_fp_registers
);
108 #else /* Not mach386 target. */
110 /* These functions shouldn't be called when we're cross-debugging. */
114 fetch_inferior_registers (regno
)
121 store_inferior_registers (regno
)
126 #endif /* Not mach386 target. */
128 /* Work with core files, for GDB. */
131 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
133 unsigned core_reg_size
;
135 unsigned int reg_addr
; /* Unused in this version */
138 extern char registers
[];
143 bcopy (core_reg_sect
, registers
, core_reg_size
);
148 bcopy (core_reg_sect
,
149 ®isters
[REGISTER_BYTE (FP0_REGNUM
)],
150 core_reg_size
); /* FIXME, probably bogus */
153 bcopy (&corestr
.c_fpu
.f_fpstatus
.f_ctrl
,
154 ®isters
[REGISTER_BYTE (FPC_REGNUM
)],
155 sizeof corestr
.c_fpu
.f_fpstatus
-
156 sizeof corestr
.c_fpu
.f_fpstatus
.f_st
);