| 1 | /* Native-dependent code for NetBSD/i386, for GDB. |
| 2 | Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000 |
| 3 | Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/ptrace.h> |
| 25 | #include <machine/reg.h> |
| 26 | #include <machine/frame.h> |
| 27 | #include "inferior.h" |
| 28 | #include "gdbcore.h" /* for registers_fetched() */ |
| 29 | |
| 30 | #define RF(dst, src) \ |
| 31 | memcpy(®isters[REGISTER_BYTE(dst)], &src, sizeof(src)) |
| 32 | |
| 33 | #define RS(src, dst) \ |
| 34 | memcpy(&dst, ®isters[REGISTER_BYTE(src)], sizeof(dst)) |
| 35 | |
| 36 | struct env387 |
| 37 | { |
| 38 | unsigned short control; |
| 39 | unsigned short r0; |
| 40 | unsigned short status; |
| 41 | unsigned short r1; |
| 42 | unsigned short tag; |
| 43 | unsigned short r2; |
| 44 | unsigned long eip; |
| 45 | unsigned short code_seg; |
| 46 | unsigned short opcode; |
| 47 | unsigned long operand; |
| 48 | unsigned short operand_seg; |
| 49 | unsigned short r3; |
| 50 | unsigned char regs[8][10]; |
| 51 | }; |
| 52 | |
| 53 | void |
| 54 | fetch_inferior_registers (int regno) |
| 55 | { |
| 56 | struct reg inferior_registers; |
| 57 | struct env387 inferior_fpregisters; |
| 58 | |
| 59 | ptrace (PT_GETREGS, inferior_pid, |
| 60 | (PTRACE_ARG3_TYPE) &inferior_registers, 0); |
| 61 | ptrace (PT_GETFPREGS, inferior_pid, |
| 62 | (PTRACE_ARG3_TYPE) &inferior_fpregisters, 0); |
| 63 | |
| 64 | RF ( 0, inferior_registers.r_eax); |
| 65 | RF ( 1, inferior_registers.r_ecx); |
| 66 | RF ( 2, inferior_registers.r_edx); |
| 67 | RF ( 3, inferior_registers.r_ebx); |
| 68 | RF ( 4, inferior_registers.r_esp); |
| 69 | RF ( 5, inferior_registers.r_ebp); |
| 70 | RF ( 6, inferior_registers.r_esi); |
| 71 | RF ( 7, inferior_registers.r_edi); |
| 72 | RF ( 8, inferior_registers.r_eip); |
| 73 | RF ( 9, inferior_registers.r_eflags); |
| 74 | RF (10, inferior_registers.r_cs); |
| 75 | RF (11, inferior_registers.r_ss); |
| 76 | RF (12, inferior_registers.r_ds); |
| 77 | RF (13, inferior_registers.r_es); |
| 78 | RF (14, inferior_registers.r_fs); |
| 79 | RF (15, inferior_registers.r_gs); |
| 80 | |
| 81 | RF (FP0_REGNUM, inferior_fpregisters.regs[0]); |
| 82 | RF (FP0_REGNUM + 1, inferior_fpregisters.regs[1]); |
| 83 | RF (FP0_REGNUM + 2, inferior_fpregisters.regs[2]); |
| 84 | RF (FP0_REGNUM + 3, inferior_fpregisters.regs[3]); |
| 85 | RF (FP0_REGNUM + 4, inferior_fpregisters.regs[4]); |
| 86 | RF (FP0_REGNUM + 5, inferior_fpregisters.regs[5]); |
| 87 | RF (FP0_REGNUM + 6, inferior_fpregisters.regs[6]); |
| 88 | RF (FP0_REGNUM + 7, inferior_fpregisters.regs[7]); |
| 89 | |
| 90 | RF (FCTRL_REGNUM, inferior_fpregisters.control); |
| 91 | RF (FSTAT_REGNUM, inferior_fpregisters.status); |
| 92 | RF (FTAG_REGNUM, inferior_fpregisters.tag); |
| 93 | RF (FCS_REGNUM, inferior_fpregisters.code_seg); |
| 94 | RF (FCOFF_REGNUM, inferior_fpregisters.eip); |
| 95 | RF (FDS_REGNUM, inferior_fpregisters.operand_seg); |
| 96 | RF (FDOFF_REGNUM, inferior_fpregisters.operand); |
| 97 | RF (FOP_REGNUM, inferior_fpregisters.opcode); |
| 98 | |
| 99 | registers_fetched (); |
| 100 | } |
| 101 | |
| 102 | void |
| 103 | store_inferior_registers (int regno) |
| 104 | { |
| 105 | struct reg inferior_registers; |
| 106 | struct env387 inferior_fpregisters; |
| 107 | |
| 108 | RS ( 0, inferior_registers.r_eax); |
| 109 | RS ( 1, inferior_registers.r_ecx); |
| 110 | RS ( 2, inferior_registers.r_edx); |
| 111 | RS ( 3, inferior_registers.r_ebx); |
| 112 | RS ( 4, inferior_registers.r_esp); |
| 113 | RS ( 5, inferior_registers.r_ebp); |
| 114 | RS ( 6, inferior_registers.r_esi); |
| 115 | RS ( 7, inferior_registers.r_edi); |
| 116 | RS ( 8, inferior_registers.r_eip); |
| 117 | RS ( 9, inferior_registers.r_eflags); |
| 118 | RS (10, inferior_registers.r_cs); |
| 119 | RS (11, inferior_registers.r_ss); |
| 120 | RS (12, inferior_registers.r_ds); |
| 121 | RS (13, inferior_registers.r_es); |
| 122 | RS (14, inferior_registers.r_fs); |
| 123 | RS (15, inferior_registers.r_gs); |
| 124 | |
| 125 | |
| 126 | RS (FP0_REGNUM, inferior_fpregisters.regs[0]); |
| 127 | RS (FP0_REGNUM + 1, inferior_fpregisters.regs[1]); |
| 128 | RS (FP0_REGNUM + 2, inferior_fpregisters.regs[2]); |
| 129 | RS (FP0_REGNUM + 3, inferior_fpregisters.regs[3]); |
| 130 | RS (FP0_REGNUM + 4, inferior_fpregisters.regs[4]); |
| 131 | RS (FP0_REGNUM + 5, inferior_fpregisters.regs[5]); |
| 132 | RS (FP0_REGNUM + 6, inferior_fpregisters.regs[6]); |
| 133 | RS (FP0_REGNUM + 7, inferior_fpregisters.regs[7]); |
| 134 | |
| 135 | RS (FCTRL_REGNUM, inferior_fpregisters.control); |
| 136 | RS (FSTAT_REGNUM, inferior_fpregisters.status); |
| 137 | RS (FTAG_REGNUM, inferior_fpregisters.tag); |
| 138 | RS (FCS_REGNUM, inferior_fpregisters.code_seg); |
| 139 | RS (FCOFF_REGNUM, inferior_fpregisters.eip); |
| 140 | RS (FDS_REGNUM, inferior_fpregisters.operand_seg); |
| 141 | RS (FDOFF_REGNUM, inferior_fpregisters.operand); |
| 142 | RS (FOP_REGNUM, inferior_fpregisters.opcode); |
| 143 | |
| 144 | ptrace (PT_SETREGS, inferior_pid, |
| 145 | (PTRACE_ARG3_TYPE) &inferior_registers, 0); |
| 146 | ptrace (PT_SETFPREGS, inferior_pid, |
| 147 | (PTRACE_ARG3_TYPE) &inferior_fpregisters, 0); |
| 148 | } |
| 149 | \f |
| 150 | struct md_core |
| 151 | { |
| 152 | struct reg intreg; |
| 153 | struct env387 freg; |
| 154 | }; |
| 155 | |
| 156 | static void |
| 157 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which, |
| 158 | CORE_ADDR ignore) |
| 159 | { |
| 160 | struct md_core *core_reg = (struct md_core *) core_reg_sect; |
| 161 | |
| 162 | /* integer registers */ |
| 163 | memcpy (®isters[REGISTER_BYTE (0)], &core_reg->intreg, |
| 164 | sizeof (struct reg)); |
| 165 | |
| 166 | /* floating point registers */ |
| 167 | RF (FP0_REGNUM, core_reg->freg.regs[0]); |
| 168 | RF (FP0_REGNUM + 1, core_reg->freg.regs[1]); |
| 169 | RF (FP0_REGNUM + 2, core_reg->freg.regs[2]); |
| 170 | RF (FP0_REGNUM + 3, core_reg->freg.regs[3]); |
| 171 | RF (FP0_REGNUM + 4, core_reg->freg.regs[4]); |
| 172 | RF (FP0_REGNUM + 5, core_reg->freg.regs[5]); |
| 173 | RF (FP0_REGNUM + 6, core_reg->freg.regs[6]); |
| 174 | RF (FP0_REGNUM + 7, core_reg->freg.regs[7]); |
| 175 | |
| 176 | RF (FCTRL_REGNUM, core_reg->freg.control); |
| 177 | RF (FSTAT_REGNUM, core_reg->freg.status); |
| 178 | RF (FTAG_REGNUM, core_reg->freg.tag); |
| 179 | RF (FCS_REGNUM, core_reg->freg.code_seg); |
| 180 | RF (FCOFF_REGNUM, core_reg->freg.eip); |
| 181 | RF (FDS_REGNUM, core_reg->freg.operand_seg); |
| 182 | RF (FDOFF_REGNUM, core_reg->freg.operand); |
| 183 | RF (FOP_REGNUM, core_reg->freg.opcode); |
| 184 | |
| 185 | registers_fetched (); |
| 186 | } |
| 187 | |
| 188 | /* Register that we are able to handle i386nbsd core file formats. |
| 189 | FIXME: is this really bfd_target_unknown_flavour? */ |
| 190 | |
| 191 | static struct core_fns i386nbsd_core_fns = |
| 192 | { |
| 193 | bfd_target_unknown_flavour, /* core_flavour */ |
| 194 | default_check_format, /* check_format */ |
| 195 | default_core_sniffer, /* core_sniffer */ |
| 196 | fetch_core_registers, /* core_read_registers */ |
| 197 | NULL /* next */ |
| 198 | }; |
| 199 | |
| 200 | void |
| 201 | _initialize_i386nbsd_nat (void) |
| 202 | { |
| 203 | add_core_fns (&i386nbsd_core_fns); |
| 204 | } |