Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / unix / sysv / linux / tile / tilepro / register-dump.h
blob45298ec7c266ed6148712dfc036d6ec1bc763529
1 /* Copyright (C) 2011-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
4 Based on work 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 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 R32: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
30 R40: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
31 R48: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
32 R52: XXXXXXXX TP: XXXXXXXX SP: XXXXXXXX LR: XXXXXXXX
34 PC: XXXXXXXX ICS: X FAULTNUM: XX
38 static void
39 hexvalue (unsigned long int value, char *buf, size_t len)
41 char *cp = _itoa_word (value, buf + len, 16, 0);
42 while (cp > buf)
43 *--cp = '0';
46 static void
47 register_dump (int fd, mcontext_t *ctx)
49 char regs[59][8];
50 struct iovec iov[143];
51 size_t nr = 0;
52 unsigned int i;
54 #define ADD_STRING(str) \
55 iov[nr].iov_base = (char *) str; \
56 iov[nr].iov_len = strlen (str); \
57 ++nr
58 #define ADD_MEM(str, len) \
59 iov[nr].iov_base = str; \
60 iov[nr].iov_len = len; \
61 ++nr
63 /* Generate strings of register contents. */
64 for (i = 0; i < 56; ++i)
65 hexvalue (ctx->gregs[i], regs[i], 8);
66 hexvalue (ctx->pc, regs[56], 8);
67 hexvalue (ctx->ics, regs[57], 1);
68 hexvalue (ctx->faultnum, regs[58], 2);
70 /* Generate the output. */
71 for (i = 0; i < 52;)
73 const char *prefixes[] = {
74 "Register dump:\n\n R0: ",
75 "\n R8: ",
76 "\n R16: ",
77 "\n R24: ",
78 "\n R32: ",
79 "\n R40: ",
80 "\n R48: "
82 ADD_STRING (prefixes[i / 8]);
85 ADD_MEM (regs[i], 8);
86 ADD_STRING (" ");
88 while (++i % 8 && i < 52);
90 ADD_STRING ("\n R52: ");
91 ADD_MEM (regs[52], 8);
92 ADD_STRING (" TP: ");
93 ADD_MEM (regs[53], 8);
94 ADD_STRING (" SP: ");
95 ADD_MEM (regs[54], 8);
96 ADD_STRING (" LR: ");
97 ADD_MEM (regs[55], 8);
98 ADD_STRING ("\n\n PC: ");
99 ADD_MEM (regs[56], 8);
100 ADD_STRING (" ICS: ");
101 ADD_MEM (regs[57], 1);
102 ADD_STRING (" FAULTNUM: ");
103 ADD_MEM (regs[58], 2);
104 ADD_STRING ("\n");
106 /* Write the stuff out. */
107 writev (fd, iov, nr);
111 #define REGISTER_DUMP register_dump (fd, &ctx->uc_mcontext)