Back to index

glibc  2.9
register-dump.h
Go to the documentation of this file.
00001 /* Dump registers.
00002    Copyright (C) 1998, 2002, 2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <sys/uio.h>
00021 #include <stdio-common/_itoa.h>
00022 
00023 /* This prints out the information in the following form: */
00024 static const char dumpform[] = "\
00025 Register dump:\n\
00026 sr0=000000000000020% sr1=000000000000021% dar=000000000000029% dsi=000002a%\n\
00027 lr=000000000000024%  ctr=000000000000023% gr3*=000000000000022% trap=0000028%\n\
00028 ccr=0000026%  xer=0000025%\n\
00029 gr0-3:   000000000000000% 000000000000001% 000000000000002% 000000000000003%\n\
00030 gr4-7:   000000000000004% 000000000000005% 000000000000006% 000000000000007%\n\
00031 gr8-11:  000000000000008% 000000000000009% 00000000000000a% 00000000000000b%\n\
00032 gr12-15: 00000000000000c% 00000000000000d% 00000000000000e% 00000000000000f%\n\
00033 gr16-19: 000000000000010% 000000000000011% 000000000000012% 000000000000013%\n\
00034 gr20-23: 000000000000014% 000000000000015% 000000000000016% 000000000000017%\n\
00035 gr24-27: 000000000000018% 000000000000019% 00000000000001a% 00000000000001b%\n\
00036 gr28-31: 00000000000001c% 00000000000001d% 00000000000001e% 00000000000001f%\n\
00037 fscr=000000000000050%\n\
00038 fp0-3:   000000000000030% 000000000000031% 000000000000032% 000000000000033%\n\
00039 fp4-7:   000000000000034% 000000000000035% 000000000000036% 000000000000037%\n\
00040 fp8-11:  000000000000038% 000000000000038% 00000000000003a% 00000000000003b%\n\
00041 fp12-15: 00000000000003c% 00000000000003d% 00000000000003e% 00000000000003f%\n\
00042 fp16-19: 000000000000040% 000000000000041% 000000000000042% 000000000000043%\n\
00043 fp20-23: 000000000000044% 000000000000045% 000000000000046% 000000000000047%\n\
00044 fp24-27: 000000000000048% 000000000000049% 00000000000004a% 00000000000004b%\n\
00045 fp28-31: 00000000000004c% 00000000000004d% 00000000000004e% 00000000000004f%\n\
00046 ";
00047 
00048 /* Most of the fields are self-explanatory.  'sr0' is the next
00049    instruction to execute, from SRR0, which may have some relationship
00050    with the instruction that caused the exception.  'r3*' is the value
00051    that will be returned in register 3 when the current system call
00052    returns.  'sr1' is SRR1, bits 16-31 of which are copied from the MSR:
00053 
00054    16 - External interrupt enable
00055    17 - Privilege level (1=user, 0=supervisor)
00056    18 - FP available
00057    19 - Machine check enable (if clear, processor locks up on machine check)
00058    20 - FP exception mode bit 0 (FP exceptions recoverable)
00059    21 - Single-step trace enable
00060    22 - Branch trace enable
00061    23 - FP exception mode bit 1
00062    25 - exception prefix (if set, exceptions are taken from 0xFFFnnnnn,
00063         otherwise from 0x000nnnnn).
00064    26 - Instruction address translation enabled.
00065    27 - Data address translation enabled.
00066    30 - Exception is recoverable (otherwise, don't try to return).
00067    31 - Little-endian mode enable.
00068 
00069    'Trap' is the address of the exception:
00070 
00071    00200 - Machine check exception (memory parity error, for instance)
00072    00300 - Data access exception (memory not mapped, see dsisr for why)
00073    00400 - Instruction access exception (memory not mapped)
00074    00500 - External interrupt
00075    00600 - Alignment exception (see dsisr for more information)
00076    00700 - Program exception (illegal/trap instruction, FP exception)
00077    00800 - FP unavailable (should not be seen by user code)
00078    00900 - Decrementer exception (for instance, SIGALRM)
00079    00A00 - I/O controller interface exception
00080    00C00 - System call exception (for instance, kill(3)).
00081    00E00 - FP assist exception (optional FP instructions, etc.)
00082 
00083    'dar' is the memory location, for traps 00300, 00400, 00600, 00A00.
00084    'dsisr' has the following bits under trap 00300:
00085    0 - direct-store error exception
00086    1 - no page table entry for page
00087    4 - memory access not permitted
00088    5 - trying to access I/O controller space or using lwarx/stwcx on
00089        non-write-cached memory
00090    6 - access was store
00091    9 - data access breakpoint hit
00092    10 - segment table search failed to find translation (64-bit ppcs only)
00093    11 - I/O controller instruction not permitted
00094    For trap 00400, the same bits are set in SRR1 instead.
00095    For trap 00600, bits 12-31 of the DSISR set to allow emulation of
00096    the instruction without actually having to read it from memory.
00097 */
00098 
00099 #define xtoi(x) (x >= 'a' ? x + 10 - 'a' : x - '0')
00100 
00101 static void
00102 register_dump (int fd, struct sigcontext *ctx)
00103 {
00104   char buffer[sizeof(dumpform)];
00105   char *bufferpos;
00106   unsigned regno;
00107   unsigned long *regs = (unsigned long *)(ctx->regs);
00108 
00109   memcpy(buffer, dumpform, sizeof(dumpform));
00110 
00111   /* Generate the output.  */
00112   while ((bufferpos = memchr (buffer, '%', sizeof(dumpform))))
00113     {
00114       regno = xtoi (bufferpos[-1]) | xtoi (bufferpos[-2]) << 4;
00115       memset (bufferpos-2, '0', 3);
00116       _itoa_word (regs[regno], bufferpos+1, 16, 0);
00117     }
00118 
00119   /* Write the output.  */
00120   write (fd, buffer, sizeof(buffer) - 1);
00121 }
00122 
00123 
00124 #define REGISTER_DUMP \
00125   register_dump (fd, ctx)