blob: 027aec4a74df6a99c2e5733e2f68ff5fb5fbc19a [file] [log] [blame]
Andi Kleencc1e6842006-09-26 10:52:29 +02001/*
2 * Save registers before calling assembly functions. This avoids
3 * disturbance of register allocation in some inline assembly constructs.
4 * Copyright 2001,2002 by Andi Kleen, SuSE Labs.
Steven Rostedt81d68a92008-05-12 21:20:42 +02005 * Added trace_hardirqs callers - Copyright 2007 Steven Rostedt, Red Hat, Inc.
Andi Kleencc1e6842006-09-26 10:52:29 +02006 * Subject to the GNU public license, v.2. No warranty of any kind.
7 */
Borislav Petkov38e6b752011-05-31 22:21:54 +02008#include <linux/linkage.h>
Ingo Molnard36f9472015-06-03 18:29:26 +02009#include "calling.h"
Masami Hiramatsu98def1d2014-04-17 17:17:26 +090010#include <asm/asm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Borislav Petkov38e6b752011-05-31 22:21:54 +020012 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
13 .macro THUNK name, func, put_ret_addr_in_rdi=0
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 .globl \name
Josh Poimboeuf058fb732016-01-21 16:49:20 -060015 .type \name, @function
Borislav Petkov38e6b752011-05-31 22:21:54 +020016\name:
Josh Poimboeufd4bf7072016-05-17 13:06:06 -050017 pushq %rbp
18 movq %rsp, %rbp
Borislav Petkov38e6b752011-05-31 22:21:54 +020019
Ingo Molnar131484c2015-05-28 12:21:47 +020020 pushq %rdi
21 pushq %rsi
22 pushq %rdx
23 pushq %rcx
24 pushq %rax
25 pushq %r8
26 pushq %r9
27 pushq %r10
28 pushq %r11
Borislav Petkov38e6b752011-05-31 22:21:54 +020029
30 .if \put_ret_addr_in_rdi
Josh Poimboeufd4bf7072016-05-17 13:06:06 -050031 /* 8(%rbp) is return addr on stack */
32 movq 8(%rbp), %rdi
Borislav Petkov38e6b752011-05-31 22:21:54 +020033 .endif
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 call \func
36 jmp restore
Masami Hiramatsu98def1d2014-04-17 17:17:26 +090037 _ASM_NOKPROBE(\name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 .endm
39
Ingo Molnar6375e2b2006-07-03 00:24:45 -070040#ifdef CONFIG_TRACE_IRQFLAGS
Borislav Petkov38e6b752011-05-31 22:21:54 +020041 THUNK trace_hardirqs_on_thunk,trace_hardirqs_on_caller,1
42 THUNK trace_hardirqs_off_thunk,trace_hardirqs_off_caller,1
Ingo Molnar6375e2b2006-07-03 00:24:45 -070043#endif
Peter Zijlstra10cd7062007-10-11 22:11:12 +020044
45#ifdef CONFIG_DEBUG_LOCK_ALLOC
Borislav Petkov38e6b752011-05-31 22:21:54 +020046 THUNK lockdep_sys_exit_thunk,lockdep_sys_exit
Peter Zijlstra10cd7062007-10-11 22:11:12 +020047#endif
Borislav Petkov38e6b752011-05-31 22:21:54 +020048
Oleg Nesterov0ad6e3c2014-09-21 20:41:53 +020049#ifdef CONFIG_PREEMPT
50 THUNK ___preempt_schedule, preempt_schedule
Frederic Weisbecker4eaca0a2015-06-04 17:39:08 +020051 THUNK ___preempt_schedule_notrace, preempt_schedule_notrace
Oleg Nesterov0ad6e3c2014-09-21 20:41:53 +020052#endif
53
Denys Vlasenko69e85442015-02-26 14:40:24 -080054#if defined(CONFIG_TRACE_IRQFLAGS) \
55 || defined(CONFIG_DEBUG_LOCK_ALLOC) \
56 || defined(CONFIG_PREEMPT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057restore:
Ingo Molnar131484c2015-05-28 12:21:47 +020058 popq %r11
59 popq %r10
60 popq %r9
61 popq %r8
62 popq %rax
63 popq %rcx
64 popq %rdx
65 popq %rsi
66 popq %rdi
Josh Poimboeufd4bf7072016-05-17 13:06:06 -050067 popq %rbp
Borislav Petkov38e6b752011-05-31 22:21:54 +020068 ret
Masami Hiramatsu98def1d2014-04-17 17:17:26 +090069 _ASM_NOKPROBE(restore)
Denys Vlasenko69e85442015-02-26 14:40:24 -080070#endif