entry_64_compat.S 7.4 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3
 * Compatibility mode system call entry point for x86-64.
 *
L
Linus Torvalds 已提交
4
 * Copyright 2000-2002 Andi Kleen, SuSE Labs.
5
 */
6
#include "calling.h"
7
#include <asm/asm-offsets.h>
L
Linus Torvalds 已提交
8 9
#include <asm/current.h>
#include <asm/errno.h>
10 11
#include <asm/ia32_unistd.h>
#include <asm/thread_info.h>
L
Linus Torvalds 已提交
12
#include <asm/segment.h>
13
#include <asm/irqflags.h>
14
#include <asm/asm.h>
15
#include <asm/smap.h>
L
Linus Torvalds 已提交
16
#include <linux/linkage.h>
17
#include <linux/err.h>
L
Linus Torvalds 已提交
18

J
Jiri Olsa 已提交
19 20
	.section .entry.text, "ax"

21 22 23 24 25 26 27
#ifdef CONFIG_PARAVIRT
ENTRY(native_usergs_sysret32)
	swapgs
	sysretl
ENDPROC(native_usergs_sysret32)
#endif

L
Linus Torvalds 已提交
28
/*
29
 * 32-bit SYSENTER instruction entry.
L
Linus Torvalds 已提交
30
 *
31 32 33 34 35
 * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs.
 * IF and VM in rflags are cleared (IOW: interrupts are off).
 * SYSENTER does not save anything on the stack,
 * and does not save old rip (!!!) and rflags.
 *
L
Linus Torvalds 已提交
36
 * Arguments:
37 38 39 40 41 42 43 44 45
 * eax  system call number
 * ebx  arg1
 * ecx  arg2
 * edx  arg3
 * esi  arg4
 * edi  arg5
 * ebp  user stack
 * 0(%ebp) arg6
 *
L
Linus Torvalds 已提交
46
 * This is purely a fast path. For anything complicated we use the int 0x80
47
 * path below. We set up a complete hardware stack frame to share code
L
Linus Torvalds 已提交
48
 * with the int 0x80 path.
49
 */
50
ENTRY(entry_SYSENTER_compat)
51
	/* Interrupts are off on entry. */
52
	SWAPGS_UNSAFE_STACK
53
	movq	PER_CPU_VAR(cpu_current_top_of_stack), %rsp
54

55 56 57 58
	/* Zero-extending 32-bit regs, do not remove */
	movl	%ebp, %ebp
	movl	%eax, %eax

59 60 61
	movl	ASM_THREAD_INFO(TI_sysenter_return, %rsp, 0), %r10d

	/* Construct struct pt_regs on stack */
62 63
	pushq	$__USER32_DS		/* pt_regs->ss */
	pushq	%rbp			/* pt_regs->sp */
64 65 66 67 68 69 70 71 72 73

	/*
	 * Push flags.  This is nasty.  First, interrupts are currently
	 * off, but we need pt_regs->flags to have IF set.  Second, even
	 * if TF was set when SYSENTER started, it's clear by now.  We fix
	 * that later using TIF_SINGLESTEP.
	 */
	pushfq				/* pt_regs->flags (except IF = 0) */
	orl	$X86_EFLAGS_IF, (%rsp)	/* Fix saved flags */

74
	pushq	$__USER32_CS		/* pt_regs->cs */
75
	pushq	%r10			/* pt_regs->ip = thread_info->sysenter_return */
76 77 78 79 80 81
	pushq	%rax			/* pt_regs->orig_ax */
	pushq	%rdi			/* pt_regs->di */
	pushq	%rsi			/* pt_regs->si */
	pushq	%rdx			/* pt_regs->dx */
	pushq	%rcx			/* pt_regs->cx */
	pushq	$-ENOSYS		/* pt_regs->ax */
L
Linus Torvalds 已提交
82
	cld
83
	sub	$(10*8), %rsp /* pt_regs->r8-11, bp, bx, r12-15 not saved */
84

85 86 87 88
	/*
	 * Sysenter doesn't filter flags, so we need to clear NT
	 * ourselves.  To save a few cycles, we can check whether
	 * NT was set instead of doing an unconditional popfq.
89 90
	 * This needs to happen before enabling interrupts so that
	 * we don't get preempted with NT set.
91
	 */
92 93
	testl	$X86_EFLAGS_NT, EFLAGS(%rsp)
	jnz	sysenter_fix_flags
94 95
sysenter_flags_fixed:

96 97 98 99 100 101 102 103
	/* Temporary: SYSENTER is disabled. */
#ifdef CONFIG_CONTEXT_TRACKING
	call enter_from_user_mode
#endif
	ENABLE_INTERRUPTS(CLBR_NONE)
	movl $11, %edi
	call do_exit

104 105
	/* Unreachable. */
	ud2
L
Linus Torvalds 已提交
106

107
sysenter_fix_flags:
108
	pushq	$X86_EFLAGS_FIXED
109
	popfq
110
	jmp	sysenter_flags_fixed
111
ENDPROC(entry_SYSENTER_compat)
L
Linus Torvalds 已提交
112 113

/*
114
 * 32-bit SYSCALL instruction entry.
L
Linus Torvalds 已提交
115
 *
116
 * 32-bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11,
117 118 119 120 121 122
 * then loads new ss, cs, and rip from previously programmed MSRs.
 * rflags gets masked by a value from another MSR (so CLD and CLAC
 * are not needed). SYSCALL does not save anything on the stack
 * and does not change rsp.
 *
 * Note: rflags saving+masking-with-MSR happens only in Long mode
123
 * (in legacy 32-bit mode, IF, RF and VM bits are cleared and that's it).
124 125 126 127
 * Don't get confused: rflags saving+masking depends on Long Mode Active bit
 * (EFER.LMA=1), NOT on bitness of userspace where SYSCALL executes
 * or target CS descriptor's L bit (SYSCALL does not read segment descriptors).
 *
L
Linus Torvalds 已提交
128
 * Arguments:
129 130 131 132 133 134 135 136 137 138
 * eax  system call number
 * ecx  return address
 * ebx  arg1
 * ebp  arg2	(note: not saved in the stack frame, should not be touched)
 * edx  arg3
 * esi  arg4
 * edi  arg5
 * esp  user stack
 * 0(%esp) arg6
 *
L
Linus Torvalds 已提交
139
 * This is purely a fast path. For anything complicated we use the int 0x80
140 141 142
 * path below. We set up a complete hardware stack frame to share code
 * with the int 0x80 path.
 */
143
ENTRY(entry_SYSCALL_compat)
144 145 146 147 148
	/*
	 * Interrupts are off on entry.
	 * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON,
	 * it is too small to ever cause noticeable irq latency.
	 */
149
	SWAPGS_UNSAFE_STACK
150 151 152 153 154

	/* Temporary: SYSCALL32 is disabled. */
	movl	$-ENOSYS, %eax
	USERGS_SYSRET32

155 156
	movl	%esp, %r8d
	movq	PER_CPU_VAR(cpu_current_top_of_stack), %rsp
157
	ENABLE_INTERRUPTS(CLBR_NONE)
158

159
	/* Zero-extending 32-bit regs, do not remove */
160
	movl	%eax, %eax
161

162
	/* Construct struct pt_regs on stack */
163 164 165 166 167 168 169 170 171 172
	pushq	$__USER32_DS		/* pt_regs->ss */
	pushq	%r8			/* pt_regs->sp */
	pushq	%r11			/* pt_regs->flags */
	pushq	$__USER32_CS		/* pt_regs->cs */
	pushq	%rcx			/* pt_regs->ip */
	pushq	%rax			/* pt_regs->orig_ax */
	pushq	%rdi			/* pt_regs->di */
	pushq	%rsi			/* pt_regs->si */
	pushq	%rdx			/* pt_regs->dx */
	pushq	%rbp			/* pt_regs->cx */
173
	movl	%ebp, %ecx
174
	pushq	$-ENOSYS		/* pt_regs->ax */
175
	sub	$(10*8), %rsp		/* pt_regs->r8-11, bp, bx, r12-15 not saved */
176

177 178
	/* Unreachable. */
	ud2
179
END(entry_SYSCALL_compat)
180

181 182
/*
 * Emulated IA32 system calls via int 0x80.
L
Linus Torvalds 已提交
183
 *
184 185 186 187 188 189 190 191
 * Arguments:
 * eax  system call number
 * ebx  arg1
 * ecx  arg2
 * edx  arg3
 * esi  arg4
 * edi  arg5
 * ebp  arg6	(note: not saved in the stack frame, should not be touched)
L
Linus Torvalds 已提交
192 193
 *
 * Notes:
194 195
 * Uses the same stack frame as the x86-64 version.
 * All registers except eax must be saved (but ptrace may violate that).
L
Linus Torvalds 已提交
196 197 198
 * Arguments are zero extended. For system calls that want sign extension and
 * take long arguments a wrapper is needed. Most calls can just be called
 * directly.
199 200
 * Assumes it is only called from user space and entered with interrupts off.
 */
L
Linus Torvalds 已提交
201

202
ENTRY(entry_INT80_compat)
203
	/*
204
	 * Interrupts are off on entry.
205
	 */
206 207 208
	PARAVIRT_ADJUST_EXCEPTION_FRAME
	SWAPGS

209 210 211 212 213 214 215
	/*
	 * User tracing code (ptrace or signal handlers) might assume that
	 * the saved RAX contains a 32-bit number when we're invoking a 32-bit
	 * syscall.  Just in case the high bits are nonzero, zero-extend
	 * the syscall number.  (This could almost certainly be deleted
	 * with no ill effects.)
	 */
216
	movl	%eax, %eax
217

218
	/* Construct struct pt_regs on stack (iret frame is already on stack) */
219 220 221 222 223 224
	pushq	%rax			/* pt_regs->orig_ax */
	pushq	%rdi			/* pt_regs->di */
	pushq	%rsi			/* pt_regs->si */
	pushq	%rdx			/* pt_regs->dx */
	pushq	%rcx			/* pt_regs->cx */
	pushq	$-ENOSYS		/* pt_regs->ax */
225 226 227 228 229 230 231 232 233 234 235
	xorq    %r8,%r8
	pushq   %r8                     /* pt_regs->r8  = 0 */
	pushq   %r8                     /* pt_regs->r9  = 0 */
	pushq   %r8                     /* pt_regs->r10 = 0 */
	pushq   %r8                     /* pt_regs->r11 = 0 */
	pushq   %rbx                    /* pt_regs->rbx */
	pushq   %rbp                    /* pt_regs->rbp */
	pushq   %r12                    /* pt_regs->r12 */
	pushq   %r13                    /* pt_regs->r13 */
	pushq   %r14                    /* pt_regs->r14 */
	pushq   %r15                    /* pt_regs->r15 */
L
Linus Torvalds 已提交
236
	cld
237

238
	/*
239 240
	 * User mode is traced as though IRQs are on, and the interrupt
	 * gate turned them off.
241
	 */
242 243 244 245 246 247 248 249 250
	TRACE_IRQS_OFF

	movq	%rsp, %rdi
	call	do_int80_syscall_32

	/* Go back to user mode. */
	TRACE_IRQS_ON
	SWAPGS
	jmp	restore_regs_and_iret
251
END(entry_INT80_compat)
L
Linus Torvalds 已提交
252

253 254
	ALIGN
GLOBAL(stub32_clone)
255
	/*
256 257 258 259 260
	 * The 32-bit clone ABI is: clone(..., int tls_val, int *child_tidptr).
	 * The 64-bit clone ABI is: clone(..., int *child_tidptr, int tls_val).
	 *
	 * The native 64-bit kernel's sys_clone() implements the latter,
	 * so we need to swap arguments here before calling it:
261
	 */
262
	xchg	%r8, %rcx
263
	jmp	sys_clone