m68k: update ColdFire sigcontext ABI
[glibc.git] / sysdeps / unix / sysv / linux / m68k / register-dump.h
blob78709d9cc65e83c55d0d3d36ab5ee4badaf39a36
1 /* Dump registers.
2 Copyright (C) 1998, 2002, 2004 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <stddef.h>
22 #include <sys/uio.h>
23 #include <stdio-common/_itoa.h>
25 /* We will print the register dump in this format:
27 D0: XXXXXXXX D1: XXXXXXXX D2: XXXXXXXX D3: XXXXXXXX
28 D4: XXXXXXXX D5: XXXXXXXX D6: XXXXXXXX D7: XXXXXXXX
29 A0: XXXXXXXX A1: XXXXXXXX A2: XXXXXXXX A3: XXXXXXXX
30 A4: XXXXXXXX A5: XXXXXXXX A6: XXXXXXXX A7: XXXXXXXX
31 PC: XXXXXXXX SR: XXXX
33 OldMask: XXXXXXXX Vector: XXXX
35 FP0: XXXXXXXXXXXXXXXXXXXXXXXX FP1: XXXXXXXXXXXXXXXXXXXXXXXX
36 FP2: XXXXXXXXXXXXXXXXXXXXXXXX FP3: XXXXXXXXXXXXXXXXXXXXXXXX
37 FP4: XXXXXXXXXXXXXXXXXXXXXXXX FP5: XXXXXXXXXXXXXXXXXXXXXXXX
38 FP6: XXXXXXXXXXXXXXXXXXXXXXXX FP7: XXXXXXXXXXXXXXXXXXXXXXXX
39 FPCR: XXXXXXXX FPSR: XXXXXXXX FPIAR: XXXXXXXX
43 /* Linux saves only the call-clobbered registers in the sigcontext. We
44 need to use a trampoline that saves the rest so that the C code can
45 access them. We use the sc_fpstate field, since the handler is not
46 supposed to return anyway, thus it doesn't matter that it's clobbered. */
48 /* static */ void catch_segfault (int, int, struct sigcontext *);
50 /* Dummy function so that we can use asm with arguments. */
51 static void __attribute_used__
52 __dummy__ (void)
54 asm ("\n\
55 catch_segfault:\n\
56 move.l 12(%%sp),%%a0\n\
57 lea %c0(%%a0),%%a0\n\
58 /* Clear the first 4 bytes to make it a null fp state, just\n\
59 in case the handler does return. */\n\
60 clr.l (%%a0)+\n\
61 movem.l %%d2-%%d7/%%a2-%%a6,(%%a0)\n"
62 #ifndef __mcoldfire__
63 "fmovem.x %%fp2-%%fp7,11*4(%%a0)\n"
64 #elif defined __mcffpu__
65 "fmovem.d %%fp2-%%fp7,11*4(%%a0)\n"
66 #endif
67 "jra real_catch_segfault"
68 : : "n" (offsetof (struct sigcontext, sc_fpstate)));
70 #define catch_segfault(a,b) \
71 __attribute_used__ real_catch_segfault(a,b)
73 static void
74 hexvalue (unsigned long int value, char *buf, size_t len)
76 char *cp = _itoa_word (value, buf + len, 16, 0);
77 while (cp > buf)
78 *--cp = '0';
81 static void
82 register_dump (int fd, struct sigcontext *ctx)
84 char regs[20][8];
85 char fpregs[11][24];
86 struct iovec iov[63], *next_iov = iov;
87 unsigned long *p = (unsigned long *) ctx->sc_fpstate + 1;
88 unsigned long *pfp = (unsigned long *) ctx->sc_fpregs;
89 int i, j, fpreg_size;
91 #define ADD_STRING(str) \
92 next_iov->iov_base = (char *) (str); \
93 next_iov->iov_len = strlen (str); \
94 ++next_iov
95 #define ADD_MEM(str, len) \
96 next_iov->iov_base = (str); \
97 next_iov->iov_len = (len); \
98 ++next_iov
100 #ifdef __mcoldfire__
101 fpreg_size = 16;
102 #else
103 fpreg_size = 24;
104 #endif
106 /* Generate strings of register contents. */
107 hexvalue (ctx->sc_d0, regs[0], 8);
108 hexvalue (ctx->sc_d1, regs[1], 8);
109 hexvalue (*p++, regs[2], 8);
110 hexvalue (*p++, regs[3], 8);
111 hexvalue (*p++, regs[4], 8);
112 hexvalue (*p++, regs[5], 8);
113 hexvalue (*p++, regs[6], 8);
114 hexvalue (*p++, regs[7], 8);
115 hexvalue (ctx->sc_a0, regs[8], 8);
116 hexvalue (ctx->sc_a1, regs[9], 8);
117 hexvalue (*p++, regs[10], 8);
118 hexvalue (*p++, regs[11], 8);
119 hexvalue (*p++, regs[12], 8);
120 hexvalue (*p++, regs[13], 8);
121 hexvalue (*p++, regs[14], 8);
122 hexvalue (ctx->sc_usp, regs[15], 8);
123 hexvalue (ctx->sc_pc, regs[16], 8);
124 hexvalue (ctx->sc_sr, regs[17], 4);
125 hexvalue (ctx->sc_mask, regs[18], 8);
126 hexvalue (ctx->sc_formatvec & 0xfff, regs[19], 4);
127 for (i = 0; i < 2; i++)
128 for (j = 0; j < fpreg_size; j += 8)
129 hexvalue (*pfp++, fpregs[i] + j, 8);
130 for (i = 2; i < 8; i++)
131 for (j = 0; j < fpreg_size; j += 8)
132 hexvalue (*p++, fpregs[i] + j, 8);
133 hexvalue (ctx->sc_fpcntl[0], fpregs[8], 8);
134 hexvalue (ctx->sc_fpcntl[1], fpregs[9], 8);
135 hexvalue (ctx->sc_fpcntl[2], fpregs[10], 8);
137 /* Generate the output. */
138 ADD_STRING ("Register dump:\n\n D0: ");
139 ADD_MEM (regs[0], 8);
140 ADD_STRING (" D1: ");
141 ADD_MEM (regs[1], 8);
142 ADD_STRING (" D2: ");
143 ADD_MEM (regs[2], 8);
144 ADD_STRING (" D3: ");
145 ADD_MEM (regs[3], 8);
146 ADD_STRING ("\n D4: ");
147 ADD_MEM (regs[4], 8);
148 ADD_STRING (" D5: ");
149 ADD_MEM (regs[5], 8);
150 ADD_STRING (" D6: ");
151 ADD_MEM (regs[6], 8);
152 ADD_STRING (" D7: ");
153 ADD_MEM (regs[7], 8);
154 ADD_STRING ("\n A0: ");
155 ADD_MEM (regs[8], 8);
156 ADD_STRING (" A1: ");
157 ADD_MEM (regs[9], 8);
158 ADD_STRING (" A2: ");
159 ADD_MEM (regs[10], 8);
160 ADD_STRING (" A3: ");
161 ADD_MEM (regs[11], 8);
162 ADD_STRING ("\n A4: ");
163 ADD_MEM (regs[12], 8);
164 ADD_STRING (" A5: ");
165 ADD_MEM (regs[13], 8);
166 ADD_STRING (" A6: ");
167 ADD_MEM (regs[14], 8);
168 ADD_STRING (" A7: ");
169 ADD_MEM (regs[15], 8);
170 ADD_STRING ("\n PC: ");
171 ADD_MEM (regs[16], 8);
172 ADD_STRING (" SR: ");
173 ADD_MEM (regs[17], 4);
175 ADD_STRING ("\n\n OldMask: ");
176 ADD_MEM (regs[18], 8);
177 ADD_STRING (" Vector: ");
178 ADD_MEM (regs[19], 4);
180 ADD_STRING ("\n\n FP0: ");
181 ADD_MEM (fpregs[0], fpreg_size);
182 ADD_STRING (" FP1: ");
183 ADD_MEM (fpregs[1], fpreg_size);
184 ADD_STRING ("\n FP2: ");
185 ADD_MEM (fpregs[2], fpreg_size);
186 ADD_STRING (" FP3: ");
187 ADD_MEM (fpregs[3], fpreg_size);
188 ADD_STRING ("\n FP4: ");
189 ADD_MEM (fpregs[4], fpreg_size);
190 ADD_STRING (" FP5: ");
191 ADD_MEM (fpregs[5], fpreg_size);
192 ADD_STRING ("\n FP6: ");
193 ADD_MEM (fpregs[6], fpreg_size);
194 ADD_STRING (" FP7: ");
195 ADD_MEM (fpregs[7], fpreg_size);
196 ADD_STRING ("\n FPCR: ");
197 ADD_MEM (fpregs[8], 8);
198 ADD_STRING (" FPSR: ");
199 ADD_MEM (fpregs[9], 8);
200 ADD_STRING (" FPIAR: ");
201 ADD_MEM (fpregs[10], 8);
202 ADD_STRING ("\n");
204 /* Write the stuff out. */
205 writev (fd, iov, next_iov - iov);
208 #define REGISTER_DUMP register_dump (fd, ctx)