chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / sysdeps / unix / sysv / linux / i386 / register-dump.h
1 /* Dump registers.
2    Copyright (C) 1998 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library 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 GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
20
21 #include <sys/uio.h>
22 #include <stdio-common/_itoa.h>
23
24 /* We will print the register dump in this format:
25
26  EAX: XXXXXXXX   EBX: XXXXXXXX   ECX: XXXXXXXX   EDX: XXXXXXXX
27  ESI: XXXXXXXX   EDI: XXXXXXXX   EBP: XXXXXXXX   ESP: XXXXXXXX
28
29  EIP: XXXXXXXX   EFLAGS: XXXXXXXX
30
31  CS:  XXXX   DS: XXXX   ES: XXXX   FS: XXXX   GS: XXXX   SS: XXXX
32
33  Trap:  XXXXXXXX   Error: XXXXXXXX   OldMask: XXXXXXXX
34  ESP/SIGNAL: XXXXXXXX   CR2: XXXXXXXX
35
36  FPUCW: XXXXXXXX   FPUSW: XXXXXXXX   TAG: XXXXXXXX
37  IPOFF: XXXXXXXX   CSSEL: XXXX   DATAOFF: XXXXXXXX   DATASEL: XXXX
38
39  ST(0) XXXX XXXXXXXXXXXXXXXX   ST(1) XXXX XXXXXXXXXXXXXXXX
40  ST(2) XXXX XXXXXXXXXXXXXXXX   ST(3) XXXX XXXXXXXXXXXXXXXX
41  ST(4) XXXX XXXXXXXXXXXXXXXX   ST(5) XXXX XXXXXXXXXXXXXXXX
42  ST(6) XXXX XXXXXXXXXXXXXXXX   ST(7) XXXX XXXXXXXXXXXXXXXX
43
44  */
45
46 static void
47 hexvalue (unsigned long int value, char *buf, size_t len)
48 {
49   char *cp = _itoa_word (value, buf + len, 16, 0);
50   while (cp > buf)
51     *--cp = '0';
52 }
53
54 static void
55 register_dump (int fd, struct sigcontext *ctx)
56 {
57   char regs[21][8];
58   char fpregs[31][8];
59   struct iovec iov[97];
60   size_t nr = 0;
61
62 #define ADD_STRING(str) \
63   iov[nr].iov_base = (char *) str;                                            \
64   iov[nr].iov_len = strlen (str);                                             \
65   ++nr
66 #define ADD_MEM(str, len) \
67   iov[nr].iov_base = str;                                                     \
68   iov[nr].iov_len = len;                                                      \
69   ++nr
70
71   /* Generate strings of register contents.  */
72   hexvalue (ctx->eax, regs[0], 8);
73   hexvalue (ctx->ebx, regs[1], 8);
74   hexvalue (ctx->ecx, regs[2], 8);
75   hexvalue (ctx->edx, regs[3], 8);
76   hexvalue (ctx->esi, regs[4], 8);
77   hexvalue (ctx->edi, regs[5], 8);
78   hexvalue (ctx->ebp, regs[6], 8);
79   hexvalue (ctx->esp, regs[7], 8);
80   hexvalue (ctx->eip, regs[8], 8);
81   hexvalue (ctx->eflags, regs[9], 8);
82   hexvalue (ctx->cs, regs[10], 4);
83   hexvalue (ctx->ds, regs[11], 4);
84   hexvalue (ctx->es, regs[12], 4);
85   hexvalue (ctx->fs, regs[13], 4);
86   hexvalue (ctx->gs, regs[14], 4);
87   hexvalue (ctx->ss, regs[15], 4);
88   hexvalue (ctx->trapno, regs[16], 8);
89   hexvalue (ctx->err, regs[17], 8);
90   hexvalue (ctx->oldmask, regs[18], 8);
91   hexvalue (ctx->esp_at_signal, regs[19], 8);
92   hexvalue (ctx->cr2, regs[20], 8);
93
94   /* Generate the output.  */
95   ADD_STRING ("Register dump:\n\n EAX: ");
96   ADD_MEM (regs[0], 8);
97   ADD_STRING ("   EBX: ");
98   ADD_MEM (regs[1], 8);
99   ADD_STRING ("   ECX: ");
100   ADD_MEM (regs[2], 8);
101   ADD_STRING ("   EDX: ");
102   ADD_MEM (regs[3], 8);
103   ADD_STRING ("\n ESI: ");
104   ADD_MEM (regs[4], 8);
105   ADD_STRING ("   EDI: ");
106   ADD_MEM (regs[5], 8);
107   ADD_STRING ("   EBP: ");
108   ADD_MEM (regs[6], 8);
109   ADD_STRING ("   ESP: ");
110   ADD_MEM (regs[7], 8);
111   ADD_STRING ("\n\n EIP: ");
112   ADD_MEM (regs[8], 8);
113   ADD_STRING ("   EFLAGS: ");
114   ADD_MEM (regs[9], 8);
115   ADD_STRING ("\n\n CS: ");
116   ADD_MEM (regs[10], 4);
117   ADD_STRING ("   DS: ");
118   ADD_MEM (regs[11], 4);
119   ADD_STRING ("   ES: ");
120   ADD_MEM (regs[12], 4);
121   ADD_STRING ("   FS: ");
122   ADD_MEM (regs[13], 4);
123   ADD_STRING ("   GS: ");
124   ADD_MEM (regs[14], 4);
125   ADD_STRING ("   SS: ");
126   ADD_MEM (regs[15], 4);
127   ADD_STRING ("\n\n Trap: ");
128   ADD_MEM (regs[16], 8);
129   ADD_STRING ("   Error: ");
130   ADD_MEM (regs[17], 8);
131   ADD_STRING ("   OldMask: ");
132   ADD_MEM (regs[18], 8);
133   ADD_STRING ("\n ESP/signal: ");
134   ADD_MEM (regs[19], 8);
135   ADD_STRING ("   CR2: ");
136   ADD_MEM (regs[20], 8);
137
138   if (ctx->fpstate != NULL)
139     {
140
141       /* Generate output for the FPU control/status registers.  */
142       hexvalue (ctx->fpstate->cw, fpregs[0], 8);
143       hexvalue (ctx->fpstate->sw, fpregs[1], 8);
144       hexvalue (ctx->fpstate->tag, fpregs[2], 8);
145       hexvalue (ctx->fpstate->ipoff, fpregs[3], 8);
146       hexvalue (ctx->fpstate->cssel, fpregs[4], 4);
147       hexvalue (ctx->fpstate->dataoff, fpregs[5], 8);
148       hexvalue (ctx->fpstate->datasel, fpregs[6], 4);
149
150       ADD_STRING ("\n\n FPUCW: ");
151       ADD_MEM (fpregs[0], 8);
152       ADD_STRING ("   FPUSW: ");
153       ADD_MEM (fpregs[1], 8);
154       ADD_STRING ("   TAG: ");
155       ADD_MEM (fpregs[2], 8);
156       ADD_STRING ("\n IPOFF: ");
157       ADD_MEM (fpregs[3], 8);
158       ADD_STRING ("   CSSEL: ");
159       ADD_MEM (fpregs[4], 4);
160       ADD_STRING ("   DATAOFF: ");
161       ADD_MEM (fpregs[5], 8);
162       ADD_STRING ("   DATASEL: ");
163       ADD_MEM (fpregs[6], 4);
164
165       /* Now the real FPU registers.  */
166       hexvalue (ctx->fpstate->_st[0].exponent, fpregs[7], 8);
167       hexvalue (ctx->fpstate->_st[0].significand[3] << 16
168                 | ctx->fpstate->_st[0].significand[2], fpregs[8], 8);
169       hexvalue (ctx->fpstate->_st[0].significand[1] << 16
170                 | ctx->fpstate->_st[0].significand[0], fpregs[9], 8);
171       hexvalue (ctx->fpstate->_st[1].exponent, fpregs[10], 8);
172       hexvalue (ctx->fpstate->_st[1].significand[3] << 16
173                 | ctx->fpstate->_st[1].significand[2], fpregs[11], 8);
174       hexvalue (ctx->fpstate->_st[1].significand[1] << 16
175                 | ctx->fpstate->_st[1].significand[0], fpregs[12], 8);
176       hexvalue (ctx->fpstate->_st[2].exponent, fpregs[13], 8);
177       hexvalue (ctx->fpstate->_st[2].significand[3] << 16
178                 | ctx->fpstate->_st[2].significand[2], fpregs[14], 8);
179       hexvalue (ctx->fpstate->_st[2].significand[1] << 16
180                 | ctx->fpstate->_st[2].significand[0], fpregs[15], 8);
181       hexvalue (ctx->fpstate->_st[3].exponent, fpregs[16], 8);
182       hexvalue (ctx->fpstate->_st[3].significand[3] << 16
183                 | ctx->fpstate->_st[3].significand[2], fpregs[17], 8);
184       hexvalue (ctx->fpstate->_st[3].significand[1] << 16
185                 | ctx->fpstate->_st[3].significand[0], fpregs[18], 8);
186       hexvalue (ctx->fpstate->_st[4].exponent, fpregs[19], 8);
187       hexvalue (ctx->fpstate->_st[4].significand[3] << 16
188                 | ctx->fpstate->_st[4].significand[2], fpregs[20], 8);
189       hexvalue (ctx->fpstate->_st[4].significand[1] << 16
190                 | ctx->fpstate->_st[4].significand[0], fpregs[21], 8);
191       hexvalue (ctx->fpstate->_st[5].exponent, fpregs[22], 8);
192       hexvalue (ctx->fpstate->_st[5].significand[3] << 16
193                 | ctx->fpstate->_st[5].significand[2], fpregs[23], 8);
194       hexvalue (ctx->fpstate->_st[5].significand[1] << 16
195                 | ctx->fpstate->_st[5].significand[0], fpregs[24], 8);
196       hexvalue (ctx->fpstate->_st[6].exponent, fpregs[25], 8);
197       hexvalue (ctx->fpstate->_st[6].significand[3] << 16
198                 | ctx->fpstate->_st[6].significand[2], fpregs[26], 8);
199       hexvalue (ctx->fpstate->_st[6].significand[1] << 16
200                 | ctx->fpstate->_st[6].significand[0], fpregs[27], 8);
201       hexvalue (ctx->fpstate->_st[7].exponent, fpregs[28], 8);
202       hexvalue (ctx->fpstate->_st[7].significand[3] << 16
203                 | ctx->fpstate->_st[7].significand[2], fpregs[29], 8);
204       hexvalue (ctx->fpstate->_st[7].significand[1] << 16
205                 | ctx->fpstate->_st[7].significand[0], fpregs[30], 8);
206
207       ADD_STRING ("\n\n ST(0) ");
208       ADD_MEM (fpregs[7], 4);
209       ADD_STRING (" ");
210       ADD_MEM (fpregs[8], 8);
211       ADD_MEM (fpregs[9], 8);
212       ADD_STRING ("   ST(1) ");
213       ADD_MEM (fpregs[10], 4);
214       ADD_STRING (" ");
215       ADD_MEM (fpregs[11], 8);
216       ADD_MEM (fpregs[12], 8);
217       ADD_STRING ("\n ST(2) ");
218       ADD_MEM (fpregs[13], 4);
219       ADD_STRING (" ");
220       ADD_MEM (fpregs[14], 8);
221       ADD_MEM (fpregs[15], 8);
222       ADD_STRING ("   ST(3) ");
223       ADD_MEM (fpregs[16], 4);
224       ADD_STRING (" ");
225       ADD_MEM (fpregs[17], 8);
226       ADD_MEM (fpregs[18], 8);
227       ADD_STRING ("\n ST(4) ");
228       ADD_MEM (fpregs[19], 4);
229       ADD_STRING (" ");
230       ADD_MEM (fpregs[20], 8);
231       ADD_MEM (fpregs[21], 8);
232       ADD_STRING ("   ST(5) ");
233       ADD_MEM (fpregs[22], 4);
234       ADD_STRING (" ");
235       ADD_MEM (fpregs[23], 8);
236       ADD_MEM (fpregs[24], 8);
237       ADD_STRING ("\n ST(6) ");
238       ADD_MEM (fpregs[25], 4);
239       ADD_STRING (" ");
240       ADD_MEM (fpregs[26], 8);
241       ADD_MEM (fpregs[27], 8);
242       ADD_STRING ("   ST(7) ");
243       ADD_MEM (fpregs[28], 4);
244       ADD_STRING (" ");
245       ADD_MEM (fpregs[29], 8);
246       ADD_MEM (fpregs[30], 8);
247     }
248
249   ADD_STRING ("\n");
250
251   /* Write the stuff out.  */
252   writev (fd, iov, nr);
253 }
254
255
256 #define REGISTER_DUMP register_dump (fd, &ctx)