Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / mips / register-dump.h
blobd00f500bc1fddae86ae1d33840d3fdac589aa553
1 /* Dump registers.
2 Copyright (C) 2000-2015 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, see
18 <http://www.gnu.org/licenses/>. */
20 #include <sgidefs.h>
21 #include <sys/uio.h>
22 #include <_itoa.h>
24 #if _MIPS_SIM == _ABIO32
25 # define CTX_TYPE struct sigcontext *
26 # define CTX_REG(ctx, i) ((ctx)->sc_regs[(i)])
27 # define CTX_PC(ctx) ((ctx)->sc_pc)
28 # define CTX_MDHI(ctx) ((ctx)->sc_mdhi)
29 # define CTX_MDLO(ctx) ((ctx)->sc_mdlo)
30 # define REG_HEX_SIZE 8
31 #else
32 # define CTX_TYPE ucontext_t *
33 # define CTX_REG(ctx, i) ((ctx)->uc_mcontext.gregs[(i)])
34 # define CTX_PC(ctx) ((ctx)->uc_mcontext.pc)
35 # define CTX_MDHI(ctx) ((ctx)->uc_mcontext.mdhi)
36 # define CTX_MDLO(ctx) ((ctx)->uc_mcontext.mdhi)
37 # define REG_HEX_SIZE 16
38 #endif
40 /* We will print the register dump in this format:
42 R0 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
43 R8 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
44 R16 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
45 R24 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
46 pc lo hi
47 XXXXXXXX XXXXXXXX XXXXXXXX
48 The FPU registers will not be printed.
51 static void
52 hexvalue (_ITOA_WORD_TYPE value, char *buf, size_t len)
54 char *cp = _itoa_word (value, buf + len, 16, 0);
55 while (cp > buf)
56 *--cp = '0';
59 static void
60 register_dump (int fd, CTX_TYPE ctx)
62 char regs[38][REG_HEX_SIZE];
63 struct iovec iov[38 * 2 + 10];
64 size_t nr = 0;
65 int i;
67 #define ADD_STRING(str) \
68 iov[nr].iov_base = (char *) str; \
69 iov[nr].iov_len = strlen (str); \
70 ++nr
71 #define ADD_MEM(str, len) \
72 iov[nr].iov_base = str; \
73 iov[nr].iov_len = len; \
74 ++nr
76 /* Generate strings of register contents. */
77 for (i = 0; i < 32; i++)
78 hexvalue (CTX_REG (ctx, i), regs[i], REG_HEX_SIZE);
79 hexvalue (CTX_PC (ctx), regs[32], REG_HEX_SIZE);
80 hexvalue (CTX_MDHI (ctx), regs[33], REG_HEX_SIZE);
81 hexvalue (CTX_MDLO (ctx), regs[34], REG_HEX_SIZE);
83 /* Generate the output. */
84 ADD_STRING ("Register dump:\n\n R0 ");
85 for (i = 0; i < 8; i++)
87 ADD_MEM (regs[i], REG_HEX_SIZE);
88 ADD_STRING (" ");
90 ADD_STRING ("\n R8 ");
91 for (i = 8; i < 16; i++)
93 ADD_MEM (regs[i], REG_HEX_SIZE);
94 ADD_STRING (" ");
96 ADD_STRING ("\n R16 ");
97 for (i = 16; i < 24; i++)
99 ADD_MEM (regs[i], REG_HEX_SIZE);
100 ADD_STRING (" ");
102 ADD_STRING ("\n R24 ");
103 for (i = 24; i < 32; i++)
105 ADD_MEM (regs[i], REG_HEX_SIZE);
106 ADD_STRING (" ");
108 ADD_STRING ("\n pc lo hi\n ");
109 for (i = 32; i < 35; i++)
111 ADD_MEM (regs[i], REG_HEX_SIZE);
112 ADD_STRING (" ");
114 ADD_STRING ("\n");
116 /* Write the stuff out. */
117 writev (fd, iov, nr);
121 #define REGISTER_DUMP register_dump (fd, ctx)