reg-dump.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2008 by Duane Ellis
  3. *
  4. * All rights reserved.
  5. *
  6. * The original code had been released as part of the LoastARM Project
  7. * under GPL Version 2 and is published here under the following license
  8. * with kind permission from the author:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the copyright holders nor the names of
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  33. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. * SUCH DAMAGE.
  35. *
  36. * For additional information see http://lostarm.sourceforge.net/
  37. */
  38. /*!
  39. * \file arch/arm/debug/reg-dump.c
  40. *
  41. * \verbatim
  42. * $Id: reg-dump.c 4115 2012-04-12 21:06:13Z olereinhardt $
  43. * \endverbatim
  44. */
  45. #include <stdio.h>
  46. #include <sys/ptrace.h>
  47. #include <arch/arm/ptrace.h>
  48. /*
  49. * For Nut/OS we can use DEV_DEBUG with stdio.
  50. */
  51. void
  52. ptrace_dump_regs( struct pt_regs *p )
  53. {
  54. int x;
  55. char *mode;
  56. for (x = PTRACE_R0_idx; x <= PTRACE_R7_idx; x++) {
  57. printf("R%d : 0x%08lx ", x, p->uregs[x]);
  58. x += PTRACE_R8_idx;
  59. printf("R%d%s: 0x%08lx\n", x, x < 10 ? " " : "", p->uregs[x]);
  60. x -= PTRACE_R8_idx;
  61. }
  62. printf("PSW: 0x%08lx ", p->uregs[ PTRACE_CPSR_idx ] );
  63. /* now decode the flags */
  64. x = p->uregs[ PTRACE_CPSR_idx ];
  65. putchar( ( x & ARM_CPSR_N_BIT ) ? 'N' : 'n' );
  66. putchar( ( x & ARM_CPSR_Z_BIT ) ? 'Z' : 'z' );
  67. putchar( ( x & ARM_CPSR_C_BIT ) ? 'C' : 'c' );
  68. putchar( ( x & ARM_CPSR_V_BIT ) ? 'V' : 'v' );
  69. printf("...");
  70. putchar( ( x & ARM_CPSR_F_BIT ) ? 'F' : 'f' );
  71. putchar( ( x & ARM_CPSR_I_BIT ) ? 'I' : 'i' );
  72. putchar( ( x & ARM_CPSR_T_BIT ) ? 'T' : 't' );
  73. putchar(' ');
  74. switch( ARM_MODE_MASK & x ){
  75. case ARM_USR_MODE:
  76. mode = "user";
  77. break;
  78. case ARM_FIQ_MODE:
  79. mode = "fiq";
  80. break;
  81. case ARM_IRQ_MODE:
  82. mode = "irq";
  83. break;
  84. case ARM_SVC_MODE:
  85. mode = "svc";
  86. break;
  87. case ARM_ABT_MODE:
  88. if( p->uregs[ PTRACE_FRAMETYPE_idx ] == PTRACE_FRAMETYPE_pfa ){
  89. mode = "pfa";
  90. } else if( p->uregs[ PTRACE_FRAMETYPE_idx ] == PTRACE_FRAMETYPE_da ){
  91. mode = "da";
  92. } else {
  93. mode = "unknown-abort";
  94. }
  95. break;
  96. case ARM_UND_MODE:
  97. mode = "und";
  98. break;
  99. case ARM_SYS_MODE:
  100. mode = "sys";
  101. break;
  102. default:
  103. mode = NULL;
  104. break;
  105. }
  106. if (mode)
  107. printf("%s-mode\n", mode);
  108. }