2019-05-27 09:55:01 +03:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
2017-02-08 12:50:51 +03:00
/ *
* Code t o p r e p a r e d e t o u r b u f f e r f o r o p t p r o b e s i n K e r n e l .
*
* Copyright 2 0 1 7 , A n j u T , I B M C o r p .
* /
# include < a s m / p p c _ a s m . h >
# include < a s m / p t r a c e . h >
# include < a s m / a s m - o f f s e t s . h >
# define O P T _ S L O T _ S I Z E 6 5 5 3 6
.balign 4
/ *
* Reserve a n a r e a t o a l l o c a t e s l o t s f o r d e t o u r b u f f e r .
* This i s p a r t o f . t e x t s e c t i o n ( r a t h e r t h a n v m a l l o c a r e a )
* as t h i s n e e d s t o b e w i t h i n 3 2 M B o f t h e p r o b e d a d d r e s s .
* /
.global optinsn_slot
optinsn_slot :
.space OPT_SLOT_SIZE
/ *
* Optprobe t e m p l a t e :
* This t e m p l a t e g e t s c o p i e d i n t o o n e o f t h e s l o t s i n o p t i n s n _ s l o t
* and g e t s f i x e d u p w i t h r e a l o p t p r o b e s t r u c t u r e s e t a l .
* /
.global optprobe_template_entry
optprobe_template_entry :
/* Create an in-memory pt_regs */
stdu r1 ,- I N T _ F R A M E _ S I Z E ( r1 )
SAVE_ G P R ( 0 ,r1 )
/* Save the previous SP into stack */
addi r0 ,r1 ,I N T _ F R A M E _ S I Z E
std r0 ,G P R 1 ( r1 )
SAVE_ 1 0 G P R S ( 2 ,r1 )
SAVE_ 1 0 G P R S ( 1 2 ,r1 )
SAVE_ 1 0 G P R S ( 2 2 ,r1 )
/* Save SPRS */
mfmsr r5
std r5 ,_ M S R ( r1 )
li r5 ,0 x70 0
std r5 ,_ T R A P ( r1 )
li r5 ,0
std r5 ,O R I G _ G P R 3 ( r1 )
std r5 ,R E S U L T ( r1 )
mfctr r5
std r5 ,_ C T R ( r1 )
mflr r5
std r5 ,_ L I N K ( r1 )
mfspr r5 ,S P R N _ X E R
std r5 ,_ X E R ( r1 )
mfcr r5
std r5 ,_ C C R ( r1 )
2017-12-20 06:55:50 +03:00
lbz r5 ,P A C A I R Q S O F T M A S K ( r13 )
2017-02-08 12:50:51 +03:00
std r5 ,S O F T E ( r1 )
2017-02-21 18:00:47 +03:00
/ *
* We m a y g e t h e r e f r o m a m o d u l e , s o l o a d t h e k e r n e l T O C i n r2 .
* The o r i g i n a l T O C g e t s r e s t o r e d w h e n p t _ r e g s i s r e s t o r e d
* further b e l o w .
* /
ld r2 ,P A C A T O C ( r13 )
2017-02-08 12:50:51 +03:00
.global optprobe_template_op_address
optprobe_template_op_address :
/ *
* Parameters t o o p t i m i z e d _ c a l l b a c k ( ) :
* 1 . optimized_ k p r o b e s t r u c t u r e i n r3
* /
nop
nop
nop
nop
nop
/* 2. pt_regs pointer in r4 */
addi r4 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
.global optprobe_template_call_handler
optprobe_template_call_handler :
/* Branch to optimized_callback() */
nop
/ *
* Parameters f o r i n s t r u c t i o n e m u l a t i o n :
* 1 . Pass S P i n r e g i s t e r r3 .
* /
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
.global optprobe_template_insn
optprobe_template_insn :
/* 2, Pass instruction to be emulated in r4 */
nop
nop
2020-05-15 05:12:55 +03:00
nop
nop
nop
2017-02-08 12:50:51 +03:00
.global optprobe_template_call_emulate
optprobe_template_call_emulate :
/* Branch to emulate_step() */
nop
/ *
* All d o n e .
* Now, r e s t o r e t h e r e g i s t e r s . . .
* /
ld r5 ,_ M S R ( r1 )
mtmsr r5
ld r5 ,_ C T R ( r1 )
mtctr r5
ld r5 ,_ L I N K ( r1 )
mtlr r5
ld r5 ,_ X E R ( r1 )
mtxer r5
ld r5 ,_ C C R ( r1 )
mtcr r5
REST_ G P R ( 0 ,r1 )
REST_ 1 0 G P R S ( 2 ,r1 )
REST_ 1 0 G P R S ( 1 2 ,r1 )
REST_ 1 0 G P R S ( 2 2 ,r1 )
/* Restore the previous SP */
addi r1 ,r1 ,I N T _ F R A M E _ S I Z E
.global optprobe_template_ret
optprobe_template_ret :
/* ... and jump back from trampoline */
nop
.global optprobe_template_end
optprobe_template_end :