(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / sysv / linux / arm / register-dump.h
blob2baccb2cb757644f98dc5b333068bd114be5d6ff
1 /* Dump registers.
2 Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Philip Blundell <pb@nexus.co.uk>, 1998.
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 <sys/uio.h>
22 #include <stdio-common/_itoa.h>
23 #include <bits/armsigctx.h>
25 /* We will print the register dump in this format:
27 R0: XXXXXXXX R1: XXXXXXXX R2: XXXXXXXX R3: XXXXXXXX
28 R4: XXXXXXXX R5: XXXXXXXX R6: XXXXXXXX R7: XXXXXXXX
29 R8: XXXXXXXX R9: XXXXXXXX SL: XXXXXXXX FP: XXXXXXXX
30 IP: XXXXXXXX SP: XXXXXXXX LR: XXXXXXXX PC: XXXXXXXX
32 CPSR: XXXXXXXX
34 Trap: XXXXXXXX Error: XXXXXXXX OldMask: XXXXXXXX
35 Addr: XXXXXXXX
39 static void
40 hexvalue (unsigned long int value, char *buf, size_t len)
42 char *cp = _itoa_word (value, buf + len, 16, 0);
43 while (cp > buf)
44 *--cp = '0';
47 static void
48 register_dump (int fd, union k_sigcontext *ctx)
50 char regs[21][8];
51 struct iovec iov[97];
52 size_t nr = 0;
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
63 /* Generate strings of register contents. */
64 if (ctx->v20.magic == SIGCONTEXT_2_0_MAGIC)
66 hexvalue (ctx->v20.reg.ARM_r0, regs[0], 8);
67 hexvalue (ctx->v20.reg.ARM_r1, regs[1], 8);
68 hexvalue (ctx->v20.reg.ARM_r2, regs[2], 8);
69 hexvalue (ctx->v20.reg.ARM_r3, regs[3], 8);
70 hexvalue (ctx->v20.reg.ARM_r4, regs[4], 8);
71 hexvalue (ctx->v20.reg.ARM_r5, regs[5], 8);
72 hexvalue (ctx->v20.reg.ARM_r6, regs[6], 8);
73 hexvalue (ctx->v20.reg.ARM_r7, regs[7], 8);
74 hexvalue (ctx->v20.reg.ARM_r8, regs[8], 8);
75 hexvalue (ctx->v20.reg.ARM_r9, regs[9], 8);
76 hexvalue (ctx->v20.reg.ARM_r10, regs[10], 8);
77 hexvalue (ctx->v20.reg.ARM_fp, regs[11], 8);
78 hexvalue (ctx->v20.reg.ARM_ip, regs[12], 8);
79 hexvalue (ctx->v20.reg.ARM_sp, regs[13], 8);
80 hexvalue (ctx->v20.reg.ARM_lr, regs[14], 8);
81 hexvalue (ctx->v20.reg.ARM_pc, regs[15], 8);
82 hexvalue (ctx->v20.reg.ARM_cpsr, regs[16], 8);
83 hexvalue (ctx->v20.trap_no, regs[17], 8);
84 hexvalue (ctx->v20.error_code, regs[18], 8);
85 hexvalue (ctx->v20.oldmask, regs[19], 8);
87 else
89 hexvalue (ctx->v21.arm_r0, regs[0], 8);
90 hexvalue (ctx->v21.arm_r1, regs[1], 8);
91 hexvalue (ctx->v21.arm_r2, regs[2], 8);
92 hexvalue (ctx->v21.arm_r3, regs[3], 8);
93 hexvalue (ctx->v21.arm_r4, regs[4], 8);
94 hexvalue (ctx->v21.arm_r5, regs[5], 8);
95 hexvalue (ctx->v21.arm_r6, regs[6], 8);
96 hexvalue (ctx->v21.arm_r7, regs[7], 8);
97 hexvalue (ctx->v21.arm_r8, regs[8], 8);
98 hexvalue (ctx->v21.arm_r9, regs[9], 8);
99 hexvalue (ctx->v21.arm_r10, regs[10], 8);
100 hexvalue (ctx->v21.arm_fp, regs[11], 8);
101 hexvalue (ctx->v21.arm_ip, regs[12], 8);
102 hexvalue (ctx->v21.arm_sp, regs[13], 8);
103 hexvalue (ctx->v21.arm_lr, regs[14], 8);
104 hexvalue (ctx->v21.arm_pc, regs[15], 8);
105 hexvalue (ctx->v21.arm_cpsr, regs[16], 8);
106 hexvalue (ctx->v21.trap_no, regs[17], 8);
107 hexvalue (ctx->v21.error_code, regs[18], 8);
108 hexvalue (ctx->v21.oldmask, regs[19], 8);
109 hexvalue (ctx->v21.fault_address, regs[20], 8);
112 /* Generate the output. */
113 ADD_STRING ("Register dump:\n\n R0: ");
114 ADD_MEM (regs[0], 8);
115 ADD_STRING (" R1: ");
116 ADD_MEM (regs[1], 8);
117 ADD_STRING (" R2: ");
118 ADD_MEM (regs[2], 8);
119 ADD_STRING (" R3: ");
120 ADD_MEM (regs[3], 8);
121 ADD_STRING ("\n R4: ");
122 ADD_MEM (regs[4], 8);
123 ADD_STRING (" R5: ");
124 ADD_MEM (regs[5], 8);
125 ADD_STRING (" R6: ");
126 ADD_MEM (regs[6], 8);
127 ADD_STRING (" R7: ");
128 ADD_MEM (regs[7], 8);
129 ADD_STRING ("\n R8: ");
130 ADD_MEM (regs[8], 8);
131 ADD_STRING (" R9: ");
132 ADD_MEM (regs[9], 8);
133 ADD_STRING (" SL: ");
134 ADD_MEM (regs[10], 8);
135 ADD_STRING (" FP: ");
136 ADD_MEM (regs[11], 8);
137 ADD_STRING ("\n IP: ");
138 ADD_MEM (regs[12], 8);
139 ADD_STRING (" SP: ");
140 ADD_MEM (regs[13], 8);
141 ADD_STRING (" LR: ");
142 ADD_MEM (regs[14], 8);
143 ADD_STRING (" PC: ");
144 ADD_MEM (regs[15], 8);
145 ADD_STRING ("\n\n CPSR: ");
146 ADD_MEM (regs[16], 8);
147 ADD_STRING ("\n\n Trap: ");
148 ADD_MEM (regs[17], 8);
149 ADD_STRING (" Error: ");
150 ADD_MEM (regs[18], 8);
151 ADD_STRING (" OldMask: ");
152 ADD_MEM (regs[19], 8);
153 if (ctx->v20.magic != SIGCONTEXT_2_0_MAGIC)
155 ADD_STRING ("\n Addr: ");
156 ADD_MEM (regs[20], 8);
159 ADD_STRING ("\n");
161 /* Write the stuff out. */
162 writev (fd, iov, nr);
166 #define REGISTER_DUMP register_dump (fd, &ctx)