| 1 | /* Native-dependent code for BSD Unix running on i386's, for GDB. |
| 2 | Copyright 1988, 1989, 1991, 1992, 1994 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 <machine/reg.h> |
| 22 | |
| 23 | /* this table must line up with REGISTER_NAMES in tm-i386.h */ |
| 24 | /* symbols like 'tEAX' come from <machine/reg.h> */ |
| 25 | static int tregmap[] = |
| 26 | { |
| 27 | tEAX, tECX, tEDX, tEBX, |
| 28 | tESP, tEBP, tESI, tEDI, |
| 29 | tEIP, tEFLAGS, tCS, tSS |
| 30 | }; |
| 31 | |
| 32 | #ifdef sEAX |
| 33 | static int sregmap[] = |
| 34 | { |
| 35 | sEAX, sECX, sEDX, sEBX, |
| 36 | sESP, sEBP, sESI, sEDI, |
| 37 | sEIP, sEFLAGS, sCS, sSS |
| 38 | }; |
| 39 | #else /* No sEAX */ |
| 40 | |
| 41 | /* NetBSD has decided to collapse the s* and t* symbols. So if the s* |
| 42 | ones aren't around, use the t* ones for sregmap too. */ |
| 43 | |
| 44 | static int sregmap[] = |
| 45 | { |
| 46 | tEAX, tECX, tEDX, tEBX, |
| 47 | tESP, tEBP, tESI, tEDI, |
| 48 | tEIP, tEFLAGS, tCS, tSS |
| 49 | }; |
| 50 | #endif /* No sEAX */ |
| 51 | |
| 52 | /* blockend is the value of u.u_ar0, and points to the |
| 53 | place where ES is stored. */ |
| 54 | |
| 55 | int |
| 56 | i386_register_u_addr (blockend, regnum) |
| 57 | int blockend; |
| 58 | int regnum; |
| 59 | { |
| 60 | /* The following condition is a kludge to get at the proper register map |
| 61 | depending upon the state of pcb_flag. |
| 62 | The proper condition would be |
| 63 | if (u.u_pcb.pcb_flag & FM_TRAP) |
| 64 | but that would require a ptrace call here and wouldn't work |
| 65 | for corefiles. */ |
| 66 | |
| 67 | if (blockend < 0x1fcc) |
| 68 | return (blockend + 4 * tregmap[regnum]); |
| 69 | else |
| 70 | return (blockend + 4 * sregmap[regnum]); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | #ifdef FLOAT_INFO |
| 75 | #include "floatformat.h" |
| 76 | |
| 77 | #include <sys/param.h> |
| 78 | #include <sys/dir.h> |
| 79 | #include <signal.h> |
| 80 | #include <sys/ioctl.h> |
| 81 | #include <fcntl.h> |
| 82 | |
| 83 | #include <a.out.h> |
| 84 | |
| 85 | #include <sys/time.h> |
| 86 | #include <sys/resource.h> |
| 87 | #include <sys/uio.h> |
| 88 | #define curpcb Xcurpcb /* XXX avoid leaking declaration from pcb.h */ |
| 89 | #include <sys/user.h> |
| 90 | #undef curpcb |
| 91 | #include <sys/file.h> |
| 92 | #include <sys/stat.h> |
| 93 | #include <sys/ptrace.h> |
| 94 | |
| 95 | extern void print_387_control_word (); /* i387-tdep.h */ |
| 96 | extern void print_387_status_word (); |
| 97 | |
| 98 | #define fpstate save87 |
| 99 | #define U_FPSTATE(u) u.u_pcb.pcb_savefpu |
| 100 | |
| 101 | struct env387 |
| 102 | { |
| 103 | unsigned short control; |
| 104 | unsigned short r0; |
| 105 | unsigned short status; |
| 106 | unsigned short r1; |
| 107 | unsigned short tag; |
| 108 | unsigned short r2; |
| 109 | unsigned long eip; |
| 110 | unsigned short code_seg; |
| 111 | unsigned short opcode; |
| 112 | unsigned long operand; |
| 113 | unsigned short operand_seg; |
| 114 | unsigned short r3; |
| 115 | unsigned char regs[8][10]; |
| 116 | }; |
| 117 | |
| 118 | static |
| 119 | print_387_status (status, ep) |
| 120 | unsigned short status; |
| 121 | struct env387 *ep; |
| 122 | { |
| 123 | int i; |
| 124 | int bothstatus; |
| 125 | int top; |
| 126 | int fpreg; |
| 127 | unsigned char *p; |
| 128 | |
| 129 | bothstatus = ((status != 0) && (ep->status != 0)); |
| 130 | if (status != 0) |
| 131 | { |
| 132 | if (bothstatus) |
| 133 | printf_unfiltered ("u: "); |
| 134 | print_387_status_word ((unsigned int)status); |
| 135 | } |
| 136 | |
| 137 | if (ep->status != 0) |
| 138 | { |
| 139 | if (bothstatus) |
| 140 | printf_unfiltered ("e: "); |
| 141 | print_387_status_word ((unsigned int)ep->status); |
| 142 | } |
| 143 | |
| 144 | print_387_control_word ((unsigned int)ep->control); |
| 145 | printf_unfiltered ("last exception: "); |
| 146 | printf_unfiltered ("opcode %s; ", local_hex_string(ep->opcode)); |
| 147 | printf_unfiltered ("pc %s:", local_hex_string(ep->code_seg)); |
| 148 | printf_unfiltered ("%s; ", local_hex_string(ep->eip)); |
| 149 | printf_unfiltered ("operand %s", local_hex_string(ep->operand_seg)); |
| 150 | printf_unfiltered (":%s\n", local_hex_string(ep->operand)); |
| 151 | |
| 152 | top = (ep->status >> 11) & 7; |
| 153 | |
| 154 | printf_unfiltered ("regno tag msb lsb value\n"); |
| 155 | for (fpreg = 7; fpreg >= 0; fpreg--) |
| 156 | { |
| 157 | double val; |
| 158 | |
| 159 | printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : " ", fpreg); |
| 160 | |
| 161 | switch ((ep->tag >> (fpreg * 2)) & 3) |
| 162 | { |
| 163 | case 0: printf_unfiltered ("valid "); break; |
| 164 | case 1: printf_unfiltered ("zero "); break; |
| 165 | case 2: printf_unfiltered ("trap "); break; |
| 166 | case 3: printf_unfiltered ("empty "); break; |
| 167 | } |
| 168 | for (i = 9; i >= 0; i--) |
| 169 | printf_unfiltered ("%02x", ep->regs[fpreg][i]); |
| 170 | |
| 171 | floatformat_to_double(&floatformat_i387_ext, (char *) ep->regs[fpreg], |
| 172 | &val); |
| 173 | printf_unfiltered (" %g\n", val); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | i386_float_info () |
| 178 | { |
| 179 | struct user u; /* just for address computations */ |
| 180 | int i; |
| 181 | /* fpstate defined in <sys/user.h> */ |
| 182 | struct fpstate *fpstatep; |
| 183 | char buf[sizeof (struct fpstate) + 2 * sizeof (int)]; |
| 184 | unsigned int uaddr; |
| 185 | char fpvalid; |
| 186 | unsigned int rounded_addr; |
| 187 | unsigned int rounded_size; |
| 188 | /*extern int corechan;*/ |
| 189 | int skip; |
| 190 | extern int inferior_pid; |
| 191 | |
| 192 | uaddr = (char *)&U_FPSTATE(u) - (char *)&u; |
| 193 | if (inferior_pid) |
| 194 | { |
| 195 | int *ip; |
| 196 | |
| 197 | rounded_addr = uaddr & -sizeof (int); |
| 198 | rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) + |
| 199 | sizeof (int) - 1) / sizeof (int); |
| 200 | skip = uaddr - rounded_addr; |
| 201 | |
| 202 | ip = (int *)buf; |
| 203 | for (i = 0; i < rounded_size; i++) |
| 204 | { |
| 205 | *ip++ = ptrace (PT_READ_U, inferior_pid, (caddr_t)rounded_addr, 0); |
| 206 | rounded_addr += sizeof (int); |
| 207 | } |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | printf("float info: can't do a core file (yet)\n"); |
| 212 | return; |
| 213 | #if 0 |
| 214 | if (lseek (corechan, uaddr, 0) < 0) |
| 215 | perror_with_name ("seek on core file"); |
| 216 | if (myread (corechan, buf, sizeof (struct fpstate)) < 0) |
| 217 | perror_with_name ("read from core file"); |
| 218 | skip = 0; |
| 219 | #endif |
| 220 | } |
| 221 | |
| 222 | print_387_status (0, (struct env387 *)buf); |
| 223 | } |
| 224 | |
| 225 | #endif |