blob: a30aa42ec76a8ff92ee0377264eb8166e7d206b2 [file] [log] [blame]
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -05001// SPDX-License-Identifier: GPL-2.0-only
2#include <linux/module.h>
3
4#include <linux/sched.h> /* for wake_up_process() */
5#include <linux/ftrace.h>
Heiko Carstens1254cfbc2021-10-12 15:38:02 +02006#include <asm/asm-offsets.h>
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -05007
8void my_direct_func(struct task_struct *p)
9{
Colin Ian King760f8bc2019-11-15 08:59:38 +000010 trace_printk("waking up %s-%d\n", p->comm, p->pid);
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050011}
12
13extern void my_tramp(void *);
14
Heiko Carstens1254cfbc2021-10-12 15:38:02 +020015#ifdef CONFIG_X86_64
16
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050017asm (
18" .pushsection .text, \"ax\", @progbits\n"
Josh Poimboeuf9d907f12020-04-24 15:40:43 -050019" .type my_tramp, @function\n"
Sami Tolvanen983df5f2020-11-13 10:34:14 -080020" .globl my_tramp\n"
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050021" my_tramp:"
22" pushq %rbp\n"
23" movq %rsp, %rbp\n"
24" pushq %rdi\n"
25" call my_direct_func\n"
26" popq %rdi\n"
27" leave\n"
28" ret\n"
Josh Poimboeuf9d907f12020-04-24 15:40:43 -050029" .size my_tramp, .-my_tramp\n"
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050030" .popsection\n"
31);
32
Heiko Carstens1254cfbc2021-10-12 15:38:02 +020033#endif /* CONFIG_X86_64 */
34
35#ifdef CONFIG_S390
36
37asm (
38" .pushsection .text, \"ax\", @progbits\n"
39" .type my_tramp, @function\n"
40" .globl my_tramp\n"
41" my_tramp:"
42" lgr %r1,%r15\n"
43" stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
44" stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
45" aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
46" stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
47" brasl %r14,my_direct_func\n"
48" aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
49" lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
50" lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
51" lgr %r1,%r0\n"
52" br %r1\n"
53" .size my_tramp, .-my_tramp\n"
54" .popsection\n"
55);
56
57#endif /* CONFIG_S390 */
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050058
59static int __init ftrace_direct_init(void)
60{
61 return register_ftrace_direct((unsigned long)wake_up_process,
62 (unsigned long)my_tramp);
63}
64
65static void __exit ftrace_direct_exit(void)
66{
67 unregister_ftrace_direct((unsigned long)wake_up_process,
68 (unsigned long)my_tramp);
69}
70
71module_init(ftrace_direct_init);
72module_exit(ftrace_direct_exit);
73
74MODULE_AUTHOR("Steven Rostedt");
75MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
76MODULE_LICENSE("GPL");