Refactor sigcontextinfo.h
[glibc.git] / sysdeps / unix / sysv / linux / m68k / register-dump.h
blob9edf53f7716359bb7b93303b23ef2fc16a6ab2e8
1 /* Dump registers.
2 Copyright (C) 1998-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Andreas Schwab <schwab@gnu.org>.
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 <stddef.h>
21 #include <sys/uio.h>
22 #include <_itoa.h>
24 /* We will print the register dump in this format:
26 D0: XXXXXXXX D1: XXXXXXXX D2: XXXXXXXX D3: XXXXXXXX
27 D4: XXXXXXXX D5: XXXXXXXX D6: XXXXXXXX D7: XXXXXXXX
28 A0: XXXXXXXX A1: XXXXXXXX A2: XXXXXXXX A3: XXXXXXXX
29 A4: XXXXXXXX A5: XXXXXXXX A6: XXXXXXXX A7: XXXXXXXX
30 PC: XXXXXXXX SR: XXXX
32 OldMask: XXXXXXXX Vector: XXXX
34 FP0: XXXXXXXXXXXXXXXXXXXXXXXX FP1: XXXXXXXXXXXXXXXXXXXXXXXX
35 FP2: XXXXXXXXXXXXXXXXXXXXXXXX FP3: XXXXXXXXXXXXXXXXXXXXXXXX
36 FP4: XXXXXXXXXXXXXXXXXXXXXXXX FP5: XXXXXXXXXXXXXXXXXXXXXXXX
37 FP6: XXXXXXXXXXXXXXXXXXXXXXXX FP7: XXXXXXXXXXXXXXXXXXXXXXXX
38 FPCR: XXXXXXXX FPSR: XXXXXXXX FPIAR: XXXXXXXX
42 #define FPCONTEXT_SIZE 216
43 #define uc_formatvec __glibc_reserved1[FPCONTEXT_SIZE/4]
44 #define uc_oldmask uc_sigmask.__val[0]
46 static void
47 hexvalue (unsigned long int value, char *buf, size_t len)
49 char *cp = _itoa_word (value, buf + len, 16, 0);
50 while (cp > buf)
51 *--cp = '0';
54 static void
55 register_dump (int fd, struct ucontext_t *ctx)
57 char regs[20][8];
58 char fpregs[11][24];
59 struct iovec iov[63], *next_iov = iov;
60 int i, j, fpreg_size;
62 #define ADD_STRING(str) \
63 next_iov->iov_base = (char *) (str); \
64 next_iov->iov_len = strlen (str); \
65 ++next_iov
66 #define ADD_MEM(str, len) \
67 next_iov->iov_base = (str); \
68 next_iov->iov_len = (len); \
69 ++next_iov
71 #ifdef __mcoldfire__
72 fpreg_size = 16;
73 #else
74 fpreg_size = 24;
75 #endif
77 /* Generate strings of register contents. */
78 hexvalue (ctx->uc_mcontext.gregs[R_D0], regs[0], 8);
79 hexvalue (ctx->uc_mcontext.gregs[R_D1], regs[1], 8);
80 hexvalue (ctx->uc_mcontext.gregs[R_D2], regs[2], 8);
81 hexvalue (ctx->uc_mcontext.gregs[R_D3], regs[3], 8);
82 hexvalue (ctx->uc_mcontext.gregs[R_D4], regs[4], 8);
83 hexvalue (ctx->uc_mcontext.gregs[R_D5], regs[5], 8);
84 hexvalue (ctx->uc_mcontext.gregs[R_D6], regs[6], 8);
85 hexvalue (ctx->uc_mcontext.gregs[R_D7], regs[7], 8);
86 hexvalue (ctx->uc_mcontext.gregs[R_A0], regs[8], 8);
87 hexvalue (ctx->uc_mcontext.gregs[R_A1], regs[9], 8);
88 hexvalue (ctx->uc_mcontext.gregs[R_A2], regs[10], 8);
89 hexvalue (ctx->uc_mcontext.gregs[R_A3], regs[11], 8);
90 hexvalue (ctx->uc_mcontext.gregs[R_A4], regs[12], 8);
91 hexvalue (ctx->uc_mcontext.gregs[R_A5], regs[13], 8);
92 hexvalue (ctx->uc_mcontext.gregs[R_A6], regs[14], 8);
93 hexvalue (ctx->uc_mcontext.gregs[R_SP], regs[15], 8);
94 hexvalue (ctx->uc_mcontext.gregs[R_PC], regs[16], 8);
95 hexvalue (ctx->uc_mcontext.gregs[R_PS], regs[17], 4);
96 hexvalue (ctx->uc_oldmask, regs[18], 8);
97 hexvalue (ctx->uc_formatvec & 0xfff, regs[19], 4);
99 for (i = 0; i < 8; i++)
100 for (j = 0; j < fpreg_size; j += 8)
101 hexvalue (ctx->uc_mcontext.fpregs.f_fpregs[i][j/8], fpregs[i] + j, 8);
102 hexvalue (ctx->uc_mcontext.fpregs.f_pcr, fpregs[8], 8);
103 hexvalue (ctx->uc_mcontext.fpregs.f_psr, fpregs[9], 8);
104 hexvalue (ctx->uc_mcontext.fpregs.f_fpiaddr, fpregs[10], 8);
106 /* Generate the output. */
107 ADD_STRING ("Register dump:\n\n D0: ");
108 ADD_MEM (regs[0], 8);
109 ADD_STRING (" D1: ");
110 ADD_MEM (regs[1], 8);
111 ADD_STRING (" D2: ");
112 ADD_MEM (regs[2], 8);
113 ADD_STRING (" D3: ");
114 ADD_MEM (regs[3], 8);
115 ADD_STRING ("\n D4: ");
116 ADD_MEM (regs[4], 8);
117 ADD_STRING (" D5: ");
118 ADD_MEM (regs[5], 8);
119 ADD_STRING (" D6: ");
120 ADD_MEM (regs[6], 8);
121 ADD_STRING (" D7: ");
122 ADD_MEM (regs[7], 8);
123 ADD_STRING ("\n A0: ");
124 ADD_MEM (regs[8], 8);
125 ADD_STRING (" A1: ");
126 ADD_MEM (regs[9], 8);
127 ADD_STRING (" A2: ");
128 ADD_MEM (regs[10], 8);
129 ADD_STRING (" A3: ");
130 ADD_MEM (regs[11], 8);
131 ADD_STRING ("\n A4: ");
132 ADD_MEM (regs[12], 8);
133 ADD_STRING (" A5: ");
134 ADD_MEM (regs[13], 8);
135 ADD_STRING (" A6: ");
136 ADD_MEM (regs[14], 8);
137 ADD_STRING (" A7: ");
138 ADD_MEM (regs[15], 8);
139 ADD_STRING ("\n PC: ");
140 ADD_MEM (regs[16], 8);
141 ADD_STRING (" SR: ");
142 ADD_MEM (regs[17], 4);
144 ADD_STRING ("\n\n OldMask: ");
145 ADD_MEM (regs[18], 8);
146 ADD_STRING (" Vector: ");
147 ADD_MEM (regs[19], 4);
149 ADD_STRING ("\n\n FP0: ");
150 ADD_MEM (fpregs[0], fpreg_size);
151 ADD_STRING (" FP1: ");
152 ADD_MEM (fpregs[1], fpreg_size);
153 ADD_STRING ("\n FP2: ");
154 ADD_MEM (fpregs[2], fpreg_size);
155 ADD_STRING (" FP3: ");
156 ADD_MEM (fpregs[3], fpreg_size);
157 ADD_STRING ("\n FP4: ");
158 ADD_MEM (fpregs[4], fpreg_size);
159 ADD_STRING (" FP5: ");
160 ADD_MEM (fpregs[5], fpreg_size);
161 ADD_STRING ("\n FP6: ");
162 ADD_MEM (fpregs[6], fpreg_size);
163 ADD_STRING (" FP7: ");
164 ADD_MEM (fpregs[7], fpreg_size);
165 ADD_STRING ("\n FPCR: ");
166 ADD_MEM (fpregs[8], 8);
167 ADD_STRING (" FPSR: ");
168 ADD_MEM (fpregs[9], 8);
169 ADD_STRING (" FPIAR: ");
170 ADD_MEM (fpregs[10], 8);
171 ADD_STRING ("\n");
173 /* Write the stuff out. */
174 writev (fd, iov, next_iov - iov);
177 #define REGISTER_DUMP register_dump (fd, ctx)