]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/mips/register-dump.h
Replace FSF snail mail address by URL.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / mips / register-dump.h
1 /* Dump registers.
2 Copyright (C) 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Andreas Jaeger <aj@suse.de>, 2000.
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, see
18 <http://www.gnu.org/licenses/>. */
19
20 #include <sys/uio.h>
21 #include <stdio-common/_itoa.h>
22
23 /* We will print the register dump in this format:
24
25 R0 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
26 R8 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
27 R16 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
28 R24 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
29 pc lo hi
30 XXXXXXXX XXXXXXXX XXXXXXXX
31 The FPU registers will not be printed.
32 */
33
34 static void
35 hexvalue (unsigned long int value, char *buf, size_t len)
36 {
37 char *cp = _itoa_word (value, buf + len, 16, 0);
38 while (cp > buf)
39 *--cp = '0';
40 }
41
42 static void
43 register_dump (int fd, struct sigcontext *ctx)
44 {
45 char regs[38][8];
46 struct iovec iov[38 * 2 + 10];
47 size_t nr = 0;
48 int i;
49
50 #define ADD_STRING(str) \
51 iov[nr].iov_base = (char *) str; \
52 iov[nr].iov_len = strlen (str); \
53 ++nr
54 #define ADD_MEM(str, len) \
55 iov[nr].iov_base = str; \
56 iov[nr].iov_len = len; \
57 ++nr
58
59 /* Generate strings of register contents. */
60 for (i = 0; i < 32; i++)
61 hexvalue (ctx->sc_regs[i], regs[i], 8);
62 hexvalue (ctx->sc_pc, regs[32], 8);
63 hexvalue (ctx->sc_mdhi, regs[33], 8);
64 hexvalue (ctx->sc_mdlo, regs[34], 8);
65
66 /* Generate the output. */
67 ADD_STRING ("Register dump:\n\n R0 ");
68 for (i = 0; i < 8; i++)
69 {
70 ADD_MEM (regs[i], 8);
71 ADD_STRING (" ");
72 }
73 ADD_STRING ("\n R8 ");
74 for (i = 8; i < 16; i++)
75 {
76 ADD_MEM (regs[i], 8);
77 ADD_STRING (" ");
78 }
79 ADD_STRING ("\n R16 ");
80 for (i = 16; i < 24; i++)
81 {
82 ADD_MEM (regs[i], 8);
83 ADD_STRING (" ");
84 }
85 ADD_STRING ("\n R24 ");
86 for (i = 24; i < 32; i++)
87 {
88 ADD_MEM (regs[i], 8);
89 ADD_STRING (" ");
90 }
91 ADD_STRING ("\n pc lo hi\n ");
92 for (i = 32; i < 35; i++)
93 {
94 ADD_MEM (regs[i], 8);
95 ADD_STRING (" ");
96 }
97 ADD_STRING ("\n");
98
99 /* Write the stuff out. */
100 writev (fd, iov, nr);
101 }
102
103
104 #define REGISTER_DUMP register_dump (fd, ctx)