2018-02-13 13:13:17 +08:00
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2017 Andes Technology Corporation */
# include < l i n u x / i n i t . h >
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s m . h >
# include < a s m / c s r . h >
# include < a s m / u n i s t d . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / a s m - o f f s e t s . h >
# include < a s m - g e n e r i c / e x p o r t . h >
# include < a s m / f t r a c e . h >
.text
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
# define F E N T R Y _ R A _ O F F S E T 1 2
# define A B I _ S I Z E _ O N _ S T A C K 7 2
# define A B I _ A 0 0
# define A B I _ A 1 8
# define A B I _ A 2 1 6
# define A B I _ A 3 2 4
# define A B I _ A 4 3 2
# define A B I _ A 5 4 0
# define A B I _ A 6 4 8
# define A B I _ A 7 5 6
# define A B I _ R A 6 4
.macro SAVE_ABI
addi s p , s p , - S Z R E G
addi s p , s p , - A B I _ S I Z E _ O N _ S T A C K
REG_ S a0 , A B I _ A 0 ( s p )
REG_ S a1 , A B I _ A 1 ( s p )
REG_ S a2 , A B I _ A 2 ( s p )
REG_ S a3 , A B I _ A 3 ( s p )
REG_ S a4 , A B I _ A 4 ( s p )
REG_ S a5 , A B I _ A 5 ( s p )
REG_ S a6 , A B I _ A 6 ( s p )
REG_ S a7 , A B I _ A 7 ( s p )
REG_ S r a , A B I _ R A ( s p )
2018-02-13 13:13:17 +08:00
.endm
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
.macro RESTORE_ABI
REG_ L a0 , A B I _ A 0 ( s p )
REG_ L a1 , A B I _ A 1 ( s p )
REG_ L a2 , A B I _ A 2 ( s p )
REG_ L a3 , A B I _ A 3 ( s p )
REG_ L a4 , A B I _ A 4 ( s p )
REG_ L a5 , A B I _ A 5 ( s p )
REG_ L a6 , A B I _ A 6 ( s p )
REG_ L a7 , A B I _ A 7 ( s p )
REG_ L r a , A B I _ R A ( s p )
addi s p , s p , A B I _ S I Z E _ O N _ S T A C K
addi s p , s p , S Z R E G
2018-02-13 13:13:17 +08:00
.endm
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
# ifdef C O N F I G _ D Y N A M I C _ F T R A C E _ W I T H _ R E G S
.macro SAVE_ALL
addi s p , s p , - S Z R E G
addi s p , s p , - P T _ S I Z E _ O N _ S T A C K
REG_ S x1 , P T _ E P C ( s p )
addi s p , s p , P T _ S I Z E _ O N _ S T A C K
REG_ L x1 , ( s p )
addi s p , s p , - P T _ S I Z E _ O N _ S T A C K
REG_ S x1 , P T _ R A ( s p )
REG_ L x1 , P T _ E P C ( s p )
REG_ S x2 , P T _ S P ( s p )
REG_ S x3 , P T _ G P ( s p )
REG_ S x4 , P T _ T P ( s p )
REG_ S x5 , P T _ T 0 ( s p )
REG_ S x6 , P T _ T 1 ( s p )
REG_ S x7 , P T _ T 2 ( s p )
REG_ S x8 , P T _ S 0 ( s p )
REG_ S x9 , P T _ S 1 ( s p )
REG_ S x10 , P T _ A 0 ( s p )
REG_ S x11 , P T _ A 1 ( s p )
REG_ S x12 , P T _ A 2 ( s p )
REG_ S x13 , P T _ A 3 ( s p )
REG_ S x14 , P T _ A 4 ( s p )
REG_ S x15 , P T _ A 5 ( s p )
REG_ S x16 , P T _ A 6 ( s p )
REG_ S x17 , P T _ A 7 ( s p )
REG_ S x18 , P T _ S 2 ( s p )
REG_ S x19 , P T _ S 3 ( s p )
REG_ S x20 , P T _ S 4 ( s p )
REG_ S x21 , P T _ S 5 ( s p )
REG_ S x22 , P T _ S 6 ( s p )
REG_ S x23 , P T _ S 7 ( s p )
REG_ S x24 , P T _ S 8 ( s p )
REG_ S x25 , P T _ S 9 ( s p )
REG_ S x26 , P T _ S 1 0 ( s p )
REG_ S x27 , P T _ S 1 1 ( s p )
REG_ S x28 , P T _ T 3 ( s p )
REG_ S x29 , P T _ T 4 ( s p )
REG_ S x30 , P T _ T 5 ( s p )
REG_ S x31 , P T _ T 6 ( s p )
2018-02-13 13:13:18 +08:00
.endm
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
.macro RESTORE_ALL
REG_ L x1 , P T _ R A ( s p )
addi s p , s p , P T _ S I Z E _ O N _ S T A C K
REG_ S x1 , ( s p )
addi s p , s p , - P T _ S I Z E _ O N _ S T A C K
REG_ L x1 , P T _ E P C ( s p )
REG_ L x2 , P T _ S P ( s p )
REG_ L x3 , P T _ G P ( s p )
REG_ L x4 , P T _ T P ( s p )
REG_ L x5 , P T _ T 0 ( s p )
REG_ L x6 , P T _ T 1 ( s p )
REG_ L x7 , P T _ T 2 ( s p )
REG_ L x8 , P T _ S 0 ( s p )
REG_ L x9 , P T _ S 1 ( s p )
REG_ L x10 , P T _ A 0 ( s p )
REG_ L x11 , P T _ A 1 ( s p )
REG_ L x12 , P T _ A 2 ( s p )
REG_ L x13 , P T _ A 3 ( s p )
REG_ L x14 , P T _ A 4 ( s p )
REG_ L x15 , P T _ A 5 ( s p )
REG_ L x16 , P T _ A 6 ( s p )
REG_ L x17 , P T _ A 7 ( s p )
REG_ L x18 , P T _ S 2 ( s p )
REG_ L x19 , P T _ S 3 ( s p )
REG_ L x20 , P T _ S 4 ( s p )
REG_ L x21 , P T _ S 5 ( s p )
REG_ L x22 , P T _ S 6 ( s p )
REG_ L x23 , P T _ S 7 ( s p )
REG_ L x24 , P T _ S 8 ( s p )
REG_ L x25 , P T _ S 9 ( s p )
REG_ L x26 , P T _ S 1 0 ( s p )
REG_ L x27 , P T _ S 1 1 ( s p )
REG_ L x28 , P T _ T 3 ( s p )
REG_ L x29 , P T _ T 4 ( s p )
REG_ L x30 , P T _ T 5 ( s p )
REG_ L x31 , P T _ T 6 ( s p )
addi s p , s p , P T _ S I Z E _ O N _ S T A C K
addi s p , s p , S Z R E G
.endm
# endif / * C O N F I G _ D Y N A M I C _ F T R A C E _ W I T H _ R E G S * /
2018-02-13 13:13:18 +08:00
2018-02-13 13:13:17 +08:00
ENTRY( f t r a c e _ c a l l e r )
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
SAVE_ A B I
2018-02-13 13:13:18 +08:00
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
addi a0 , r a , - F E N T R Y _ R A _ O F F S E T
la a1 , f u n c t i o n _ t r a c e _ o p
REG_ L a2 , 0 ( a1 )
REG_ L a1 , A B I _ S I Z E _ O N _ S T A C K ( s p )
mv a3 , s p
2018-02-13 13:13:18 +08:00
2018-02-13 13:13:17 +08:00
ftrace_call :
.global ftrace_call
call f t r a c e _ s t u b
2018-02-13 13:13:18 +08:00
# ifdef C O N F I G _ F U N C T I O N _ G R A P H _ T R A C E R
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
addi a0 , s p , A B I _ S I Z E _ O N _ S T A C K
REG_ L a1 , A B I _ R A ( s p )
addi a1 , a1 , - F E N T R Y _ R A _ O F F S E T
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
mv a2 , s0
2018-02-13 13:13:18 +08:00
# endif
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
ftrace_graph_call :
.global ftrace_graph_call
call f t r a c e _ s t u b
# endif
RESTORE_ A B I
2018-02-13 13:13:17 +08:00
ret
ENDPROC( f t r a c e _ c a l l e r )
2018-02-13 13:13:20 +08:00
# ifdef C O N F I G _ D Y N A M I C _ F T R A C E _ W I T H _ R E G S
ENTRY( f t r a c e _ r e g s _ c a l l e r )
SAVE_ A L L
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
addi a0 , r a , - F E N T R Y _ R A _ O F F S E T
la a1 , f u n c t i o n _ t r a c e _ o p
REG_ L a2 , 0 ( a1 )
REG_ L a1 , P T _ S I Z E _ O N _ S T A C K ( s p )
mv a3 , s p
2018-02-13 13:13:20 +08:00
ftrace_regs_call :
.global ftrace_regs_call
call f t r a c e _ s t u b
# ifdef C O N F I G _ F U N C T I O N _ G R A P H _ T R A C E R
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].
Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
mv a5,ra
mv a0,a5
auipc ra,0x0 -> nop
jalr -296(ra) <_mcount@plt> ->nop
...
After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...
The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.
[1] https://www.linuxplumbersconf.org/event/7/contributions/807/
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-12-17 16:01:41 +00:00
addi a0 , s p , P T _ R A
REG_ L a1 , P T _ E P C ( s p )
addi a1 , a1 , - F E N T R Y _ R A _ O F F S E T
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
mv a2 , s0
# endif
ftrace_graph_regs_call :
.global ftrace_graph_regs_call
call f t r a c e _ s t u b
2018-02-13 13:13:20 +08:00
# endif
RESTORE_ A L L
ret
ENDPROC( f t r a c e _ r e g s _ c a l l e r )
# endif / * C O N F I G _ D Y N A M I C _ F T R A C E _ W I T H _ R E G S * /