2005-03-15 Jakub Jelinek <jakub@redhat.com>
[glibc-ports.git] / sysdeps / unix / sysv / linux / mips / register-dump.h
blobf5bd3a2735cceb3f81877601bd5b1eaaaccc4f5b
1 /* Dump registers.
2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Andreas Jaeger <aj@suse.de>, 2000.
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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <sys/uio.h>
22 #include <stdio-common/_itoa.h>
24 /* We will print the register dump in this format:
26 R0 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
27 R8 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
28 R16 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
29 R24 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
30 pc cause status badvaddr lo hi
31 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
32 The FPU registers will not be printed.
35 static void
36 hexvalue (unsigned long int value, char *buf, size_t len)
38 char *cp = _itoa_word (value, buf + len, 16, 0);
39 while (cp > buf)
40 *--cp = '0';
43 static void
44 register_dump (int fd, struct sigcontext *ctx)
46 char regs[38][8];
47 struct iovec iov[38 * 2 + 10];
48 size_t nr = 0;
49 int i;
51 #define ADD_STRING(str) \
52 iov[nr].iov_base = (char *) str; \
53 iov[nr].iov_len = strlen (str); \
54 ++nr
55 #define ADD_MEM(str, len) \
56 iov[nr].iov_base = str; \
57 iov[nr].iov_len = len; \
58 ++nr
60 /* Generate strings of register contents. */
61 for (i = 0; i < 32; i++)
62 hexvalue (ctx->sc_regs[i], regs[i], 8);
63 hexvalue (ctx->sc_pc, regs[32], 8);
64 hexvalue (ctx->sc_cause, regs[33], 8);
65 hexvalue (ctx->sc_status, regs[34], 8);
66 hexvalue (ctx->sc_badvaddr, regs[35], 8);
67 hexvalue (ctx->sc_mdhi, regs[36], 8);
68 hexvalue (ctx->sc_mdlo, regs[37], 8);
70 /* Generate the output. */
71 ADD_STRING ("Register dump:\n\n R0 ");
72 for (i = 0; i < 8; i++)
74 ADD_MEM (regs[i], 8);
75 ADD_STRING (" ");
77 ADD_STRING ("\n R8 ");
78 for (i = 8; i < 16; i++)
80 ADD_MEM (regs[i], 8);
81 ADD_STRING (" ");
83 ADD_STRING ("\n R16 ");
84 for (i = 16; i < 24; i++)
86 ADD_MEM (regs[i], 8);
87 ADD_STRING (" ");
89 ADD_STRING ("\n R24 ");
90 for (i = 24; i < 32; i++)
92 ADD_MEM (regs[i], 8);
93 ADD_STRING (" ");
95 ADD_STRING ("\n pc cause status badvaddr lo hi\n ");
96 for (i = 32; i < 38; i++)
98 ADD_MEM (regs[i], 8);
99 ADD_STRING (" ");
101 ADD_STRING ("\n");
103 /* Write the stuff out. */
104 writev (fd, iov, nr);
108 #define REGISTER_DUMP register_dump (fd, ctx)