chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / ports / sysdeps / unix / sysv / linux / cris / register-dump.h
1 /* Dump registers.
2    Copyright (C) 1998, 2001 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include <stddef.h>
21 #include <sys/uio.h>
22 #include <stdio-common/_itoa.h>
23
24 /* We will print the register dump in this format:
25
26   R0: XXXXXXXX   R1: XXXXXXXX   R2: XXXXXXXX   R3: XXXXXXXX
27   R4: XXXXXXXX   R5: XXXXXXXX   R6: XXXXXXXX   R7: XXXXXXXX
28   R8: XXXXXXXX   R9: XXXXXXXX  R10: XXXXXXXX  R11: XXXXXXXX
29  R12: XXXXXXXX  R13: XXXXXXXX   SP: XXXXXXXX   PC: XXXXXXXX
30 DCCR: XXXXXXXX  SRP: XXXXXXXX */
31
32 static void
33 hexvalue (unsigned long int value, char *buf, size_t len)
34 {
35   char *cp = _itoa_word (value, buf + len, 16, 0);
36   while (cp > buf)
37     *--cp = '0';
38 }
39
40 static void register_dump (int fd, struct sigcontext *ctx)
41 {
42   char regs[18][8];
43   struct iovec iov[36], *next_iov = iov;
44   struct pt_regs *rx = &ctx->regs;
45
46 #define ADD_STRING(str) \
47   next_iov->iov_base = (char *) (str); \
48   next_iov->iov_len = strlen (str); \
49   ++next_iov
50 #define ADD_MEM(str, len) \
51   next_iov->iov_base = (str); \
52   next_iov->iov_len = (len); \
53   ++next_iov
54
55   /* Generate strings of register contents.  */
56   hexvalue (rx->r0, regs[0], 8);
57   hexvalue (rx->r1, regs[1], 8);
58   hexvalue (rx->r2, regs[2], 8);
59   hexvalue (rx->r3, regs[3], 8);
60   hexvalue (rx->r4, regs[4], 8);
61   hexvalue (rx->r5, regs[5], 8);
62   hexvalue (rx->r6, regs[6], 8);
63   hexvalue (rx->r7, regs[7], 8);
64   hexvalue (rx->r8, regs[8], 8);
65   hexvalue (rx->r9, regs[9], 8);
66   hexvalue (rx->r10, regs[10], 8);
67   hexvalue (rx->r11, regs[11], 8);
68   hexvalue (rx->r12, regs[12], 8);
69   hexvalue (rx->r13, regs[13], 8);
70   hexvalue (ctx->usp, regs[14], 8);
71   hexvalue (rx->irp, regs[17], 8);
72   hexvalue (rx->dccr, regs[15], 8);
73   hexvalue (rx->srp, regs[16], 8);
74
75   /* Generate the output.  */
76   ADD_STRING ("Register dump:\n\n  R0: ");
77   ADD_MEM (regs[0], 8);
78   ADD_STRING ("  R1: ");
79   ADD_MEM (regs[1], 8);
80   ADD_STRING ("  R2: ");
81   ADD_MEM (regs[2], 8);
82   ADD_STRING ("  R3: ");
83   ADD_MEM (regs[3], 8);
84   ADD_STRING ("\n  R4: ");
85   ADD_MEM (regs[4], 8);
86   ADD_STRING ("  R5: ");
87   ADD_MEM (regs[5], 8);
88   ADD_STRING ("  R6: ");
89   ADD_MEM (regs[6], 8);
90   ADD_STRING ("  R7: ");
91   ADD_MEM (regs[7], 8);
92   ADD_STRING ("\n  R8: ");
93   ADD_MEM (regs[8], 8);
94   ADD_STRING ("  R9: ");
95   ADD_MEM (regs[9], 8);
96   ADD_STRING (" R10: ");
97   ADD_MEM (regs[10], 8);
98   ADD_STRING (" R11: ");
99   ADD_MEM (regs[11], 8);
100   ADD_STRING ("\n R12: ");
101   ADD_MEM (regs[12], 8);
102   ADD_STRING (" R13: ");
103   ADD_MEM (regs[13], 8);
104   ADD_STRING ("  SP: ");
105   ADD_MEM (regs[14], 8);
106   ADD_STRING ("  PC: ");
107   ADD_MEM (regs[17], 8);
108   ADD_STRING ("\nDCCR: ");
109   ADD_MEM (regs[15], 8);
110   ADD_STRING (" SRP: ");
111   ADD_MEM (regs[16], 4);
112
113   /* Write the stuff out.  */
114   writev (fd, iov, next_iov - iov);
115 }
116
117 #define REGISTER_DUMP register_dump (fd, ctx)