backtrace.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/kern_levels.h>
  14. #include <linux/linkage.h>
  15. #include <asm/assembler.h>
  16. .text
  17. @ fp is 0 or stack frame
  18. #define frame r4
  19. #define sv_fp r5
  20. #define sv_pc r6
  21. #define mask r7
  22. #define offset r8
  23. ENTRY(c_backtrace)
  24. #if !defined(CONFIG_FRAME_POINTER) || !defined(CONFIG_PRINTK)
  25. ret lr
  26. ENDPROC(c_backtrace)
  27. #else
  28. stmfd sp!, {r4 - r8, lr} @ Save an extra register so we have a location...
  29. movs frame, r0 @ if frame pointer is zero
  30. beq no_frame @ we have no stack frames
  31. tst r1, #0x10 @ 26 or 32-bit mode?
  32. ARM( moveq mask, #0xfc000003 )
  33. THUMB( moveq mask, #0xfc000000 )
  34. THUMB( orreq mask, #0x03 )
  35. movne mask, #0 @ mask for 32-bit
  36. 1: stmfd sp!, {pc} @ calculate offset of PC stored
  37. ldr r0, [sp], #4 @ by stmfd for this CPU
  38. adr r1, 1b
  39. sub offset, r0, r1
  40. /*
  41. * Stack frame layout:
  42. * optionally saved caller registers (r4 - r10)
  43. * saved fp
  44. * saved sp
  45. * saved lr
  46. * frame => saved pc
  47. * optionally saved arguments (r0 - r3)
  48. * saved sp => <next word>
  49. *
  50. * Functions start with the following code sequence:
  51. * mov ip, sp
  52. * stmfd sp!, {r0 - r3} (optional)
  53. * corrected pc => stmfd sp!, {..., fp, ip, lr, pc}
  54. */
  55. for_each_frame: tst frame, mask @ Check for address exceptions
  56. bne no_frame
  57. 1001: ldr sv_pc, [frame, #0] @ get saved pc
  58. 1002: ldr sv_fp, [frame, #-12] @ get saved fp
  59. sub sv_pc, sv_pc, offset @ Correct PC for prefetching
  60. bic sv_pc, sv_pc, mask @ mask PC/LR for the mode
  61. 1003: ldr r2, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
  62. ldr r3, .Ldsi+4 @ adjust saved 'pc' back one
  63. teq r3, r2, lsr #10 @ instruction
  64. subne r0, sv_pc, #4 @ allow for mov
  65. subeq r0, sv_pc, #8 @ allow for mov + stmia
  66. ldr r1, [frame, #-4] @ get saved lr
  67. mov r2, frame
  68. bic r1, r1, mask @ mask PC/LR for the mode
  69. bl dump_backtrace_entry
  70. ldr r1, [sv_pc, #-4] @ if stmfd sp!, {args} exists,
  71. ldr r3, .Ldsi+4
  72. teq r3, r1, lsr #11
  73. ldreq r0, [frame, #-8] @ get sp
  74. subeq r0, r0, #4 @ point at the last arg
  75. bleq dump_backtrace_stm @ dump saved registers
  76. 1004: ldr r1, [sv_pc, #0] @ if stmfd sp!, {..., fp, ip, lr, pc}
  77. ldr r3, .Ldsi @ instruction exists,
  78. teq r3, r1, lsr #11
  79. subeq r0, frame, #16
  80. bleq dump_backtrace_stm @ dump saved registers
  81. teq sv_fp, #0 @ zero saved fp means
  82. beq no_frame @ no further frames
  83. cmp sv_fp, frame @ next frame must be
  84. mov frame, sv_fp @ above the current frame
  85. bhi for_each_frame
  86. 1006: adr r0, .Lbad
  87. mov r1, frame
  88. bl printk
  89. no_frame: ldmfd sp!, {r4 - r8, pc}
  90. ENDPROC(c_backtrace)
  91. .pushsection __ex_table,"a"
  92. .align 3
  93. .long 1001b, 1006b
  94. .long 1002b, 1006b
  95. .long 1003b, 1006b
  96. .long 1004b, 1006b
  97. .popsection
  98. .Lbad: .asciz "Backtrace aborted due to bad frame pointer <%p>\n"
  99. .align
  100. .Ldsi: .word 0xe92dd800 >> 11 @ stmfd sp!, {... fp, ip, lr, pc}
  101. .word 0xe92d0000 >> 11 @ stmfd sp!, {}
  102. #endif