Intel 386 Mach host port.
[platform/upstream/binutils.git] / gdb / mach386-xdep.c
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.
3
4 This file is part of GDB.
5
6 GDB 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 1, or (at your option)
9 any later version.
10
11 GDB 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 GDB; see the file COPYING.  If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #if defined (GDB_TARGET_IS_MACH386)
21
22 #include <stdio.h>
23 #include "defs.h"
24 #include "param.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "signame.h"
28 #include "gdbcore.h"
29
30 #include <sys/param.h>
31 #include <sys/dir.h>
32 #include <sys/user.h>
33 #include <signal.h>
34 #include <sys/ioctl.h>
35 #include <fcntl.h>
36
37 #include <sys/ptrace.h>
38 #include <machine/reg.h>
39
40 #include <sys/file.h>
41 #include <sys/stat.h>
42 #include <sys/core.h>
43 \f
44 void
45 fetch_inferior_registers ()
46 {
47   struct regs inferior_registers;
48   struct fp_state inferior_fp_registers;
49   extern char registers[];
50
51   registers_fetched ();
52
53   ptrace (PTRACE_GETREGS, inferior_pid, &inferior_registers);
54   ptrace (PTRACE_GETFPREGS, inferior_pid, &inferior_fp_registers);
55
56   bcopy (&inferior_registers, registers, sizeof inferior_registers);
57
58   bcopy (inferior_fp_registers.f_st,&registers[REGISTER_BYTE (FP0_REGNUM)],
59          sizeof inferior_fp_registers.f_st);
60   bcopy (&inferior_fp_registers.f_ctrl,
61          &registers[REGISTER_BYTE (FPC_REGNUM)],
62          sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
63 }
64
65 /* Store our register values back into the inferior.
66    If REGNO is -1, do this for all registers.
67    Otherwise, REGNO specifies which register (so we can save time).  */
68
69 store_inferior_registers (regno)
70      int regno;
71 {
72   struct regs inferior_registers;
73   struct fp_state inferior_fp_registers;
74   extern char registers[];
75
76   bcopy (registers, &inferior_registers, 20 * 4);
77
78   bcopy (&registers[REGISTER_BYTE (FP0_REGNUM)],inferior_fp_registers.f_st,
79          sizeof inferior_fp_registers.f_st);
80   bcopy (&registers[REGISTER_BYTE (FPC_REGNUM)],
81          &inferior_fp_registers.f_ctrl,
82          sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
83   
84 #ifdef PTRACE_FP_BUG
85   if (regno == FP_REGNUM || regno == -1)
86     /* Storing the frame pointer requires a gross hack, in which an
87        instruction that moves eax into ebp gets single-stepped.  */
88     {
89       int stack = inferior_registers.r_reg[SP_REGNUM];
90       int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid, stack);
91       int reg = inferior_registers.r_reg[EAX];
92       inferior_registers.r_reg[EAX] =
93         inferior_registers.r_reg[FP_REGNUM];
94       ptrace (PTRACE_SETREGS, inferior_pid, &inferior_registers);
95       ptrace (PTRACE_POKEDATA, inferior_pid, stack, 0xc589);
96       ptrace (PTRACE_SINGLESTEP, inferior_pid, stack, 0);
97       wait (0);
98       ptrace (PTRACE_POKEDATA, inferior_pid, stack, stuff);
99       inferior_registers.r_reg[EAX] = reg;
100     }
101 #endif
102   ptrace (PTRACE_SETREGS, inferior_pid, &inferior_registers);
103   ptrace (PTRACE_SETFPREGS, inferior_pid, &inferior_fp_registers);
104 }
105
106 /* Machine-dependent code which would otherwise be in core.c */
107 /* Work with core files, for GDB. */
108
109 \f
110 void
111 fetch_core_registers (core_reg_sect, core_reg_size, which)
112      char *core_reg_sect;
113      unsigned core_reg_size;
114      int which;
115 {
116   int val;
117   extern char registers[];
118
119   switch (which) {
120   case 0:
121   case 1:
122     bcopy (core_reg_sect, registers, core_reg_size);
123     break;
124
125   case 2:
126     bcopy (core_reg_sect,
127            &registers[REGISTER_BYTE (FP0_REGNUM)],
128            core_reg_size);              /* FIXME, probably bogus */
129 #if 0
130     bcopy (&corestr.c_fpu.f_fpstatus.f_ctrl,
131            &registers[REGISTER_BYTE (FPC_REGNUM)],
132            sizeof corestr.c_fpu.f_fpstatus -
133            sizeof corestr.c_fpu.f_fpstatus.f_st);
134 #endif
135     break;
136   }
137 }
138 #else /* Not mach386 target.  */
139
140 /* These functions shouldn't be called when we're cross-debugging.  */
141
142 void
143 fetch_inferior_registers ()
144 {
145 }
146
147 /* ARGSUSED */
148 store_inferior_registers (regno)
149      int regno;
150 {
151 }
152
153 /* ARGSUSED */
154 void
155 fetch_core_registers (core_reg_sect, core_reg_size, which)
156      char *core_reg_sect;
157      unsigned core_reg_size;
158      int which;
159 {
160 }
161
162 #endif /* Not mach386 target.  */