Use glibc_likely instead __builtin_expect.
[jlayton/glibc.git] / ports / sysdeps / unix / sysv / linux / tile / tilepro / register-dump.h
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.
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 <_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  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
33
34  PC:  XXXXXXXX  ICS: X  FAULTNUM: XX
35
36  */
37
38 static void
39 hexvalue (unsigned long int value, char *buf, size_t len)
40 {
41   char *cp = _itoa_word (value, buf + len, 16, 0);
42   while (cp > buf)
43     *--cp = '0';
44 }
45
46 static void
47 register_dump (int fd, mcontext_t *ctx)
48 {
49   char regs[59][8];
50   struct iovec iov[143];
51   size_t nr = 0;
52   unsigned int i;
53
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
62
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);
69
70   /* Generate the output.  */
71   for (i = 0; i < 52;)
72     {
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:  "
81       };
82       ADD_STRING (prefixes[i / 8]);
83       do
84         {
85           ADD_MEM (regs[i], 8);
86           ADD_STRING (" ");
87         }
88       while (++i % 8 && i < 52);
89     }
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");
105
106   /* Write the stuff out.  */
107   writev (fd, iov, nr);
108 }
109
110
111 #define REGISTER_DUMP register_dump (fd, &ctx->uc_mcontext)