]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/csky/register-dump.h
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / csky / register-dump.h
1 /* Dump registers.
2 Copyright (C) 2018-2019 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, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <sys/uio.h>
20 #include <_itoa.h>
21 #include <bits/sigcontext.h>
22 #include <sys/ucontext.h>
23
24 /* abiv1 register dump in this format:
25
26 PSR: XXXXXXXX PC: XXXXXXXX SP: XXXXXXXX LR: XXXXXXXX
27 MASK: XXXXXXXX
28
29 A0: XXXXXXXX A1: XXXXXXXX A2: XXXXXXXX A3: XXXXXXXX
30 R6: XXXXXXXX R7: XXXXXXXX R8: XXXXXXXX R9: XXXXXXXX
31 R10: XXXXXXXX R11: XXXXXXXX R12: XXXXXXXX R13: XXXXXXXX
32 R14: XXXXXXXX R1: XXXXXXXX
33
34 abiv2 register dump in this format:
35
36 PSR: XXXXXXXX PC: XXXXXXXX SP: XXXXXXXX LR: XXXXXXXX
37 MASK: XXXXXXXX
38
39 A0: XXXXXXXX A1: XXXXXXXX A2: XXXXXXXX A3: XXXXXXXX
40 R4: XXXXXXXX R5: XXXXXXXX R6: XXXXXXXX R7: XXXXXXXX
41 R8: XXXXXXXX R9: XXXXXXXX R10: XXXXXXXX R11: XXXXXXXX
42 R12: XXXXXXXX R13: XXXXXXXX R14: XXXXXXXX R15: XXXXXXXX
43 R16: XXXXXXXX R17: XXXXXXXX R18: XXXXXXXX R19: XXXXXXXX
44 R20: XXXXXXXX R21: XXXXXXXX R22: XXXXXXXX R23: XXXXXXXX
45 R24: XXXXXXXX R25: XXXXXXXX R26: XXXXXXXX R27: XXXXXXXX
46 R28: XXXXXXXX R29: XXXXXXXX R30: XXXXXXXX R31: XXXXXXXX
47
48 */
49
50 static void
51 hexvalue (unsigned long int value, char *buf, size_t len)
52 {
53 char *cp = _itoa_word (value, buf + len, 16, 0);
54 while (cp > buf)
55 *--cp = '0';
56 }
57
58 static void
59 register_dump (int fd, const struct ucontext_t *ctx)
60 {
61 char regs[35][8];
62 struct iovec iov[97];
63 size_t nr = 0;
64
65 #define ADD_STRING(str) \
66 iov[nr].iov_base = (char *) str; \
67 iov[nr].iov_len = strlen (str); \
68 ++nr
69 #define ADD_MEM(str, len) \
70 iov[nr].iov_base = str; \
71 iov[nr].iov_len = len; \
72 ++nr
73
74 /* Generate strings of register contents. */
75 hexvalue (ctx->uc_mcontext.__gregs.__sr, regs[0], 8);
76 hexvalue (ctx->uc_mcontext.__gregs.__pc, regs[1], 8);
77 hexvalue (ctx->uc_mcontext.__gregs.__usp, regs[2], 8);
78 hexvalue (ctx->uc_mcontext.__gregs.__lr, regs[3], 8);
79 hexvalue (ctx->uc_mcontext.__gregs.__a0, regs[4], 8);
80 hexvalue (ctx->uc_mcontext.__gregs.__a1, regs[5], 8);
81 hexvalue (ctx->uc_mcontext.__gregs.__a2, regs[6], 8);
82 hexvalue (ctx->uc_mcontext.__gregs.__a3, regs[7], 8);
83 hexvalue (ctx->uc_mcontext.__gregs.__regs[0], regs[8], 8);
84 hexvalue (ctx->uc_mcontext.__gregs.__regs[1], regs[9], 8);
85 hexvalue (ctx->uc_mcontext.__gregs.__regs[2], regs[10], 8);
86 hexvalue (ctx->uc_mcontext.__gregs.__regs[3], regs[11], 8);
87 hexvalue (ctx->uc_mcontext.__gregs.__regs[4], regs[12], 8);
88 hexvalue (ctx->uc_mcontext.__gregs.__regs[5], regs[13], 8);
89 hexvalue (ctx->uc_mcontext.__gregs.__regs[6], regs[14], 8);
90 hexvalue (ctx->uc_mcontext.__gregs.__regs[7], regs[15], 8);
91 hexvalue (ctx->uc_mcontext.__gregs.__regs[8], regs[16], 8);
92 hexvalue (ctx->uc_mcontext.__gregs.__regs[9], regs[17], 8);
93 hexvalue (ctx->uc_mcontext.__gregs.__exregs[0], regs[18], 8);
94 hexvalue (ctx->uc_mcontext.__gregs.__exregs[1], regs[19], 8);
95 hexvalue (ctx->uc_mcontext.__gregs.__exregs[2], regs[20], 8);
96 hexvalue (ctx->uc_mcontext.__gregs.__exregs[3], regs[21], 8);
97 hexvalue (ctx->uc_mcontext.__gregs.__exregs[4], regs[22], 8);
98 hexvalue (ctx->uc_mcontext.__gregs.__exregs[5], regs[23], 8);
99 hexvalue (ctx->uc_mcontext.__gregs.__exregs[6], regs[24], 8);
100 hexvalue (ctx->uc_mcontext.__gregs.__exregs[7], regs[25], 8);
101 hexvalue (ctx->uc_mcontext.__gregs.__exregs[8], regs[26], 8);
102 hexvalue (ctx->uc_mcontext.__gregs.__exregs[9], regs[27], 8);
103 hexvalue (ctx->uc_mcontext.__gregs.__exregs[10], regs[28], 8);
104 hexvalue (ctx->uc_mcontext.__gregs.__exregs[11], regs[29], 8);
105 hexvalue (ctx->uc_mcontext.__gregs.__exregs[12], regs[30], 8);
106 hexvalue (ctx->uc_mcontext.__gregs.__exregs[13], regs[31], 8);
107 hexvalue (ctx->uc_mcontext.__gregs.__exregs[14], regs[32], 8);
108 hexvalue (ctx->uc_mcontext.__gregs.__tls, regs[33], 8);
109
110 /* Generate the output. */
111 ADD_STRING ("Register dump:\n\n PSR: ");
112 ADD_MEM (regs[0], 8);
113 ADD_STRING (" PC: ");
114 ADD_MEM (regs[1], 8);
115 ADD_STRING (" SP: ");
116 ADD_MEM (regs[2], 8);
117 ADD_STRING (" LR: ");
118 ADD_MEM (regs[3], 8);
119 ADD_STRING ("\n\n A0: ");
120 ADD_MEM (regs[4], 8);
121 ADD_STRING (" A1: ");
122 ADD_MEM (regs[5], 8);
123 ADD_STRING (" A2: ");
124 ADD_MEM (regs[6], 8);
125 ADD_STRING (" A3: ");
126 ADD_MEM (regs[7], 8);
127 ADD_STRING ("\n R4: ");
128 ADD_MEM (regs[8], 8);
129 ADD_STRING (" R5: ");
130 ADD_MEM (regs[9], 8);
131 ADD_STRING (" R6: ");
132 ADD_MEM (regs[10], 8);
133 ADD_STRING (" R7: ");
134 ADD_MEM (regs[11], 8);
135 ADD_STRING ("\n R8: ");
136 ADD_MEM (regs[12], 8);
137 ADD_STRING (" R9: ");
138 ADD_MEM (regs[13], 8);
139 ADD_STRING (" R10: ");
140 ADD_MEM (regs[14], 8);
141 ADD_STRING (" R11: ");
142 ADD_MEM (regs[15], 8);
143 ADD_STRING ("\n R12: ");
144 ADD_MEM (regs[16], 8);
145 ADD_STRING (" R13: ");
146 ADD_MEM (regs[17], 8);
147 ADD_STRING (" R14: ");
148 ADD_MEM (regs[2], 8);
149 ADD_STRING (" R15: ");
150 ADD_MEM (regs[3], 8);
151 ADD_STRING ("\n R16: ");
152 ADD_MEM (regs[18], 8);
153 ADD_STRING (" R17: ");
154 ADD_MEM (regs[19], 8);
155 ADD_STRING (" R18: ");
156 ADD_MEM (regs[20], 8);
157 ADD_STRING (" R19: ");
158 ADD_MEM (regs[21], 8);
159 ADD_STRING ("\n R20: ");
160 ADD_MEM (regs[22], 8);
161 ADD_STRING (" R21: ");
162 ADD_MEM (regs[23], 8);
163 ADD_STRING (" R22: ");
164 ADD_MEM (regs[24], 8);
165 ADD_STRING (" R23: ");
166 ADD_MEM (regs[25], 8);
167 ADD_STRING ("\n R24: ");
168 ADD_MEM (regs[26], 8);
169 ADD_STRING (" R25: ");
170 ADD_MEM (regs[27], 8);
171 ADD_STRING (" R26: ");
172 ADD_MEM (regs[28], 8);
173 ADD_STRING (" R27: ");
174 ADD_MEM (regs[29], 8);
175 ADD_STRING ("\n R28: ");
176 ADD_MEM (regs[30], 8);
177 ADD_STRING (" R29: ");
178 ADD_MEM (regs[31], 8);
179 ADD_STRING (" R30: ");
180 ADD_MEM (regs[32], 8);
181 ADD_STRING (" R31: ");
182 ADD_MEM (regs[33], 8);
183
184 ADD_STRING ("\n");
185
186 /* Write the stuff out. */
187 writev (fd, iov, nr);
188 }
189
190 #define REGISTER_DUMP register_dump (fd, ctx)