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