backtrace.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * linux/arch/arm/lib/backtrace.S
  3. *
  4. * Copyright (C) 1995, 1996 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * 27/03/03 Ian Molton Clean up CONFIG_CPU
  11. *
  12. */
  13. #include <linux/linkage.h>
  14. #include <asm/assembler.h>
  15. .text
  16. @ fp is 0 or stack frame
  17. #define frame r4
  18. #define sv_fp r5
  19. #define sv_pc r6
  20. #define mask r7
  21. #define offset r8
  22. ENTRY(c_backtrace)
  23. #if !defined(CONFIG_FRAME_POINTER) || !defined(CONFIG_PRINTK)
  24. mov pc, lr
  25. ENDPROC(c_backtrace)
  26. #else
  27. stmfd sp!, {r4 - r8, lr} @ Save an extra register so we have a location...
  28. movs frame, r0 @ if frame pointer is zero
  29. beq no_frame @ we have no stack frames
  30. tst r1, #0x10 @ 26 or 32-bit mode?
  31. ARM( moveq mask, #0xfc000003 )
  32. THUMB( moveq mask, #0xfc000000 )
  33. THUMB( orreq mask, #0x03 )
  34. movne mask, #0 @ mask for 32-bit
  35. 1: stmfd sp!, {pc} @ calculate offset of PC stored
  36. ldr r0, [sp], #4 @ by stmfd for this CPU
  37. adr r1, 1b
  38. sub offset, r0, r1
  39. /*
  40. * Stack frame layout:
  41. * optionally saved caller registers (r4 - r10)
  42. * saved fp
  43. * saved sp
  44. * saved lr
  45. * frame => saved pc
  46. * optionally saved arguments (r0 - r3)
  47. * saved sp => <next word>
  48. *
  49. * Functions start with the following code sequence:
  50. * mov ip, sp
  51. * stmfd sp!, {r0 - r3} (optional)
  52. * corrected pc => stmfd sp!, {..., fp, ip, lr, pc}
  53. */
  54. for_each_frame: tst frame, mask @ Check for address exceptions
  55. bne no_frame
  56. 1001: ldr sv_pc, [frame, #0] @ get saved pc
  57. 1002: ldr sv_fp, [frame, #-12] @ get saved fp
  58. sub sv_pc, sv_pc, offset @ Correct PC for prefetching
  59. bic sv_pc, sv_pc, mask @ mask PC/LR for the mode
  60. 1003: ldr r2, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
  61. ldr r3, .Ldsi+4 @ adjust saved 'pc' back one
  62. teq r3, r2, lsr #10 @ instruction
  63. subne r0, sv_pc, #4 @ allow for mov
  64. subeq r0, sv_pc, #8 @ allow for mov + stmia
  65. ldr r1, [frame, #-4] @ get saved lr
  66. mov r2, frame
  67. bic r1, r1, mask @ mask PC/LR for the mode
  68. bl dump_backtrace_entry
  69. ldr r1, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
  70. ldr r3, .Ldsi+4
  71. teq r3, r1, lsr #10
  72. ldreq r0, [frame, #-8] @ get sp
  73. subeq r0, r0, #4 @ point at the last arg
  74. bleq .Ldumpstm @ dump saved registers
  75. 1004: ldr r1, [sv_pc, #0] @ if stmfd sp!, {..., fp, ip, lr, pc}
  76. ldr r3, .Ldsi @ instruction exists,
  77. teq r3, r1, lsr #10
  78. subeq r0, frame, #16
  79. bleq .Ldumpstm @ dump saved registers
  80. teq sv_fp, #0 @ zero saved fp means
  81. beq no_frame @ no further frames
  82. cmp sv_fp, frame @ next frame must be
  83. mov frame, sv_fp @ above the current frame
  84. bhi for_each_frame
  85. 1006: adr r0, .Lbad
  86. mov r1, frame
  87. bl printk
  88. no_frame: ldmfd sp!, {r4 - r8, pc}
  89. ENDPROC(c_backtrace)
  90. .pushsection __ex_table,"a"
  91. .align 3
  92. .long 1001b, 1006b
  93. .long 1002b, 1006b
  94. .long 1003b, 1006b
  95. .long 1004b, 1006b
  96. .popsection
  97. #define instr r4
  98. #define reg r5
  99. #define stack r6
  100. .Ldumpstm: stmfd sp!, {instr, reg, stack, r7, lr}
  101. mov stack, r0
  102. mov instr, r1
  103. mov reg, #10
  104. mov r7, #0
  105. 1: mov r3, #1
  106. ARM( tst instr, r3, lsl reg )
  107. THUMB( lsl r3, reg )
  108. THUMB( tst instr, r3 )
  109. beq 2f
  110. add r7, r7, #1
  111. teq r7, #6
  112. moveq r7, #1
  113. moveq r1, #'\n'
  114. movne r1, #' '
  115. ldr r3, [stack], #-4
  116. mov r2, reg
  117. adr r0, .Lfp
  118. bl printk
  119. 2: subs reg, reg, #1
  120. bpl 1b
  121. teq r7, #0
  122. adrne r0, .Lcr
  123. blne printk
  124. ldmfd sp!, {instr, reg, stack, r7, pc}
  125. .Lfp: .asciz "%cr%d:%08x"
  126. .Lcr: .asciz "\n"
  127. .Lbad: .asciz "Backtrace aborted due to bad frame pointer <%p>\n"
  128. .align
  129. .Ldsi: .word 0xe92dd800 >> 10 @ stmfd sp!, {... fp, ip, lr, pc}
  130. .word 0xe92d0000 >> 10 @ stmfd sp!, {}
  131. #endif