optprobes_head.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Code to prepare detour buffer for optprobes in Kernel.
  4. *
  5. * Copyright 2017, Anju T, IBM Corp.
  6. */
  7. #include <asm/ppc_asm.h>
  8. #include <asm/ptrace.h>
  9. #include <asm/asm-offsets.h>
  10. #define OPT_SLOT_SIZE 65536
  11. .balign 4
  12. /*
  13. * Reserve an area to allocate slots for detour buffer.
  14. * This is part of .text section (rather than vmalloc area)
  15. * as this needs to be within 32MB of the probed address.
  16. */
  17. .global optinsn_slot
  18. optinsn_slot:
  19. .space OPT_SLOT_SIZE
  20. /*
  21. * Optprobe template:
  22. * This template gets copied into one of the slots in optinsn_slot
  23. * and gets fixed up with real optprobe structures et al.
  24. */
  25. .global optprobe_template_entry
  26. optprobe_template_entry:
  27. /* Create an in-memory pt_regs */
  28. stdu r1,-INT_FRAME_SIZE(r1)
  29. SAVE_GPR(0,r1)
  30. /* Save the previous SP into stack */
  31. addi r0,r1,INT_FRAME_SIZE
  32. std r0,GPR1(r1)
  33. SAVE_10GPRS(2,r1)
  34. SAVE_10GPRS(12,r1)
  35. SAVE_10GPRS(22,r1)
  36. /* Save SPRS */
  37. mfmsr r5
  38. std r5,_MSR(r1)
  39. li r5,0x700
  40. std r5,_TRAP(r1)
  41. li r5,0
  42. std r5,ORIG_GPR3(r1)
  43. std r5,RESULT(r1)
  44. mfctr r5
  45. std r5,_CTR(r1)
  46. mflr r5
  47. std r5,_LINK(r1)
  48. mfspr r5,SPRN_XER
  49. std r5,_XER(r1)
  50. mfcr r5
  51. std r5,_CCR(r1)
  52. lbz r5,PACAIRQSOFTMASK(r13)
  53. std r5,SOFTE(r1)
  54. /*
  55. * We may get here from a module, so load the kernel TOC in r2.
  56. * The original TOC gets restored when pt_regs is restored
  57. * further below.
  58. */
  59. ld r2,PACATOC(r13)
  60. .global optprobe_template_op_address
  61. optprobe_template_op_address:
  62. /*
  63. * Parameters to optimized_callback():
  64. * 1. optimized_kprobe structure in r3
  65. */
  66. nop
  67. nop
  68. nop
  69. nop
  70. nop
  71. /* 2. pt_regs pointer in r4 */
  72. addi r4,r1,STACK_FRAME_OVERHEAD
  73. .global optprobe_template_call_handler
  74. optprobe_template_call_handler:
  75. /* Branch to optimized_callback() */
  76. nop
  77. /*
  78. * Parameters for instruction emulation:
  79. * 1. Pass SP in register r3.
  80. */
  81. addi r3,r1,STACK_FRAME_OVERHEAD
  82. .global optprobe_template_insn
  83. optprobe_template_insn:
  84. /* 2, Pass instruction to be emulated in r4 */
  85. nop
  86. nop
  87. nop
  88. nop
  89. nop
  90. .global optprobe_template_call_emulate
  91. optprobe_template_call_emulate:
  92. /* Branch to emulate_step() */
  93. nop
  94. /*
  95. * All done.
  96. * Now, restore the registers...
  97. */
  98. ld r5,_MSR(r1)
  99. mtmsr r5
  100. ld r5,_CTR(r1)
  101. mtctr r5
  102. ld r5,_LINK(r1)
  103. mtlr r5
  104. ld r5,_XER(r1)
  105. mtxer r5
  106. ld r5,_CCR(r1)
  107. mtcr r5
  108. REST_GPR(0,r1)
  109. REST_10GPRS(2,r1)
  110. REST_10GPRS(12,r1)
  111. REST_10GPRS(22,r1)
  112. /* Restore the previous SP */
  113. addi r1,r1,INT_FRAME_SIZE
  114. .global optprobe_template_ret
  115. optprobe_template_ret:
  116. /* ... and jump back from trampoline */
  117. nop
  118. .global optprobe_template_end
  119. optprobe_template_end: