Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Compatibility mode system call entry point for x86-64. |
| 3 | * |
| 4 | * Copyright 2000-2002 Andi Kleen, SuSE Labs. |
| 5 | */ |
| 6 | |
| 7 | #include <asm/dwarf2.h> |
| 8 | #include <asm/calling.h> |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 9 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <asm/current.h> |
| 11 | #include <asm/errno.h> |
| 12 | #include <asm/ia32_unistd.h> |
| 13 | #include <asm/thread_info.h> |
| 14 | #include <asm/segment.h> |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 15 | #include <asm/irqflags.h> |
H. Peter Anvin | 1ce6f86 | 2012-04-20 12:19:50 -0700 | [diff] [blame] | 16 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 17 | #include <asm/smap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/linkage.h> |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 19 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 21 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ |
| 22 | #include <linux/elf-em.h> |
| 23 | #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE) |
| 24 | #define __AUDIT_ARCH_LE 0x40000000 |
| 25 | |
| 26 | #ifndef CONFIG_AUDITSYSCALL |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 27 | #define sysexit_audit ia32_ret_from_sys_call |
| 28 | #define sysretl_audit ia32_ret_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 29 | #endif |
| 30 | |
Jiri Olsa | ea71454 | 2011-03-07 19:10:39 +0100 | [diff] [blame] | 31 | .section .entry.text, "ax" |
| 32 | |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 33 | /* clobbers %rax */ |
| 34 | .macro CLEAR_RREGS _r9=rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | xorl %eax,%eax |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 36 | movq %rax,R11(%rsp) |
| 37 | movq %rax,R10(%rsp) |
| 38 | movq %\_r9,R9(%rsp) |
| 39 | movq %rax,R8(%rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | .endm |
| 41 | |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 42 | /* |
| 43 | * Reload arg registers from stack in case ptrace changed them. |
| 44 | * We don't reload %eax because syscall_trace_enter() returned |
Roland McGrath | eefdca0 | 2010-09-14 12:22:58 -0700 | [diff] [blame] | 45 | * the %rax value we should see. Instead, we just truncate that |
| 46 | * value to 32 bits again as we did on entry from user mode. |
| 47 | * If it's a new value set by user_regset during entry tracing, |
| 48 | * this matches the normal truncation of the user-mode value. |
| 49 | * If it's -1 to make us punt the syscall, then (u32)-1 is still |
| 50 | * an appropriately invalid value. |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 51 | */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 52 | .macro LOAD_ARGS32 _r9=0 |
Jan Beulich | 295286a | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 53 | .if \_r9 |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 54 | movl R9(%rsp),%r9d |
Jan Beulich | 295286a | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 55 | .endif |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 56 | movl RCX(%rsp),%ecx |
| 57 | movl RDX(%rsp),%edx |
| 58 | movl RSI(%rsp),%esi |
| 59 | movl RDI(%rsp),%edi |
Roland McGrath | eefdca0 | 2010-09-14 12:22:58 -0700 | [diff] [blame] | 60 | movl %eax,%eax /* zero extension */ |
Andi Kleen | 176df24 | 2007-09-21 16:16:18 +0200 | [diff] [blame] | 61 | .endm |
| 62 | |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 63 | .macro CFI_STARTPROC32 simple |
| 64 | CFI_STARTPROC \simple |
| 65 | CFI_UNDEFINED r8 |
| 66 | CFI_UNDEFINED r9 |
| 67 | CFI_UNDEFINED r10 |
| 68 | CFI_UNDEFINED r11 |
| 69 | CFI_UNDEFINED r12 |
| 70 | CFI_UNDEFINED r13 |
| 71 | CFI_UNDEFINED r14 |
| 72 | CFI_UNDEFINED r15 |
| 73 | .endm |
| 74 | |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 75 | #ifdef CONFIG_PARAVIRT |
| 76 | ENTRY(native_usergs_sysret32) |
| 77 | swapgs |
| 78 | sysretl |
| 79 | ENDPROC(native_usergs_sysret32) |
| 80 | |
| 81 | ENTRY(native_irq_enable_sysexit) |
| 82 | swapgs |
| 83 | sti |
| 84 | sysexit |
| 85 | ENDPROC(native_irq_enable_sysexit) |
| 86 | #endif |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* |
| 89 | * 32bit SYSENTER instruction entry. |
| 90 | * |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 91 | * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs. |
| 92 | * IF and VM in rflags are cleared (IOW: interrupts are off). |
| 93 | * SYSENTER does not save anything on the stack, |
| 94 | * and does not save old rip (!!!) and rflags. |
| 95 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | * Arguments: |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 97 | * eax system call number |
| 98 | * ebx arg1 |
| 99 | * ecx arg2 |
| 100 | * edx arg3 |
| 101 | * esi arg4 |
| 102 | * edi arg5 |
| 103 | * ebp user stack |
| 104 | * 0(%ebp) arg6 |
| 105 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | * This is purely a fast path. For anything complicated we use the int 0x80 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 107 | * path below. We set up a complete hardware stack frame to share code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * with the int 0x80 path. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 109 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | ENTRY(ia32_sysenter_target) |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 111 | CFI_STARTPROC32 simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 112 | CFI_SIGNAL_FRAME |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 113 | CFI_DEF_CFA rsp,0 |
| 114 | CFI_REGISTER rsp,rbp |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * Interrupts are off on entry. |
| 118 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, |
| 119 | * it is too small to ever cause noticeable irq latency. |
| 120 | */ |
Jeremy Fitzhardinge | 457da70 | 2008-06-26 07:28:51 -0700 | [diff] [blame] | 121 | SWAPGS_UNSAFE_STACK |
Andy Lutomirski | 24933b8 | 2015-03-05 19:19:05 -0800 | [diff] [blame] | 122 | movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 123 | ENABLE_INTERRUPTS(CLBR_NONE) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 124 | |
Denys Vlasenko | 4ee8ec1 | 2015-03-27 11:36:21 +0100 | [diff] [blame^] | 125 | /* Zero-extending 32-bit regs, do not remove */ |
| 126 | movl %ebp, %ebp |
| 127 | movl %eax, %eax |
| 128 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 129 | /* Construct iret frame (ss,rsp,rflags,cs,rip) */ |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 130 | pushq_cfi $__USER32_DS |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 131 | /*CFI_REL_OFFSET ss,0*/ |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 132 | pushq_cfi %rbp |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 133 | CFI_REL_OFFSET rsp,0 |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 134 | pushfq_cfi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 135 | /*CFI_REL_OFFSET rflags,0*/ |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 136 | movl ASM_THREAD_INFO(TI_sysenter_return, %rsp, 3*8), %r10d |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 137 | CFI_REGISTER rip,r10 |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 138 | pushq_cfi $__USER32_CS |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 139 | /*CFI_REL_OFFSET cs,0*/ |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 140 | /* Store thread_info->sysenter_return in rip stack slot */ |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 141 | pushq_cfi %r10 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 142 | CFI_REL_OFFSET rip,0 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 143 | /* Store orig_ax */ |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 144 | pushq_cfi %rax |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 145 | /* Construct the rest of "struct pt_regs" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | cld |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 147 | ALLOC_PT_GPREGS_ON_STACK |
| 148 | SAVE_C_REGS_EXCEPT_R891011 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 149 | /* |
| 150 | * no need to do an access_ok check here because rbp has been |
| 151 | * 32bit zero extended |
| 152 | */ |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 153 | ASM_STAC |
Jan Beulich | 295286a | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 154 | 1: movl (%rbp),%ebp |
H. Peter Anvin | 1ce6f86 | 2012-04-20 12:19:50 -0700 | [diff] [blame] | 155 | _ASM_EXTABLE(1b,ia32_badarg) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 156 | ASM_CLAC |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Sysenter doesn't filter flags, so we need to clear NT |
| 160 | * ourselves. To save a few cycles, we can check whether |
| 161 | * NT was set instead of doing an unconditional popfq. |
| 162 | */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 163 | testl $X86_EFLAGS_NT,EFLAGS(%rsp) |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 164 | jnz sysenter_fix_flags |
| 165 | sysenter_flags_fixed: |
| 166 | |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 167 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
| 168 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 169 | CFI_REMEMBER_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | jnz sysenter_tracesys |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 171 | cmpq $(IA32_NR_syscalls-1),%rax |
Andi Kleen | 67d53ea | 2006-04-07 19:50:31 +0200 | [diff] [blame] | 172 | ja ia32_badsys |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 173 | sysenter_do_call: |
Denys Vlasenko | 14f6e95 | 2015-02-26 14:40:35 -0800 | [diff] [blame] | 174 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
| 175 | movl %edi,%r8d /* arg5 */ |
| 176 | movl %ebp,%r9d /* arg6 */ |
| 177 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
| 178 | movl %ebx,%edi /* arg1 */ |
| 179 | movl %edx,%edx /* arg3 (zero extension) */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 180 | sysenter_dispatch: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | call *ia32_sys_call_table(,%rax,8) |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 182 | movq %rax,RAX(%rsp) |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 183 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 184 | TRACE_IRQS_OFF |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 185 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 186 | jnz sysexit_audit |
| 187 | sysexit_from_sys_call: |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 188 | andl $~TS_COMPAT,ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* clear IF, that popfq doesn't enable interrupts early */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 190 | andl $~0x200,EFLAGS(%rsp) |
| 191 | movl RIP(%rsp),%edx /* User %eip */ |
Roland McGrath | 36197c9 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 192 | CFI_REGISTER rip,rdx |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 193 | RESTORE_RSI_RDI |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 194 | /* pop everything except ss,rsp,rflags slots */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 195 | REMOVE_PT_GPREGS_FROM_STACK 3*8 |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 196 | xorq %r8,%r8 |
| 197 | xorq %r9,%r9 |
| 198 | xorq %r10,%r10 |
| 199 | xorq %r11,%r11 |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 200 | popfq_cfi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 201 | /*CFI_RESTORE rflags*/ |
Jan Beulich | 60cf637 | 2011-02-28 15:54:40 +0000 | [diff] [blame] | 202 | popq_cfi %rcx /* User %esp */ |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 203 | CFI_REGISTER rsp,rcx |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 204 | TRACE_IRQS_ON |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 205 | /* |
| 206 | * 32bit SYSEXIT restores eip from edx, esp from ecx. |
| 207 | * cs and ss are loaded from MSRs. |
| 208 | */ |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 209 | ENABLE_INTERRUPTS_SYSEXIT32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 211 | CFI_RESTORE_STATE |
| 212 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 213 | #ifdef CONFIG_AUDITSYSCALL |
| 214 | .macro auditsys_entry_common |
Richard Guy Briggs | b4f0d37 | 2014-03-04 10:38:06 -0500 | [diff] [blame] | 215 | movl %esi,%r8d /* 5th arg: 4th syscall arg */ |
| 216 | movl %ecx,%r9d /*swap with edx*/ |
| 217 | movl %edx,%ecx /* 4th arg: 3rd syscall arg */ |
| 218 | movl %r9d,%edx /* 3rd arg: 2nd syscall arg */ |
| 219 | movl %ebx,%esi /* 2nd arg: 1st syscall arg */ |
| 220 | movl %eax,%edi /* 1st arg: syscall number */ |
Eric Paris | b05d844 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 221 | call __audit_syscall_entry |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 222 | movl RAX(%rsp),%eax /* reload syscall number */ |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 223 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 224 | ja ia32_badsys |
| 225 | movl %ebx,%edi /* reload 1st syscall arg */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 226 | movl RCX(%rsp),%esi /* reload 2nd syscall arg */ |
| 227 | movl RDX(%rsp),%edx /* reload 3rd syscall arg */ |
| 228 | movl RSI(%rsp),%ecx /* reload 4th syscall arg */ |
| 229 | movl RDI(%rsp),%r8d /* reload 5th syscall arg */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 230 | .endm |
| 231 | |
Jan Beulich | 8176674 | 2009-10-26 15:20:29 +0000 | [diff] [blame] | 232 | .macro auditsys_exit exit |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 233 | testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 234 | jnz ia32_ret_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 235 | TRACE_IRQS_ON |
Jan Beulich | 40a1ef9 | 2013-01-30 07:55:53 +0000 | [diff] [blame] | 236 | ENABLE_INTERRUPTS(CLBR_NONE) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 237 | movl %eax,%esi /* second arg, syscall return value */ |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 238 | cmpl $-MAX_ERRNO,%eax /* is it an error ? */ |
Eric Paris | f031cd2 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 239 | jbe 1f |
| 240 | movslq %eax, %rsi /* if error sign extend to 64 bits */ |
| 241 | 1: setbe %al /* 1 if error, 0 if not */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 242 | movzbl %al,%edi /* zero-extend that into %edi */ |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 243 | call __audit_syscall_exit |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 244 | movq RAX(%rsp),%rax /* reload syscall return value */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 245 | movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi |
Jan Beulich | 40a1ef9 | 2013-01-30 07:55:53 +0000 | [diff] [blame] | 246 | DISABLE_INTERRUPTS(CLBR_NONE) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 247 | TRACE_IRQS_OFF |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 248 | testl %edi, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 249 | jz \exit |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 250 | CLEAR_RREGS |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 251 | jmp int_with_check |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 252 | .endm |
| 253 | |
| 254 | sysenter_auditsys: |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 255 | auditsys_entry_common |
| 256 | movl %ebp,%r9d /* reload 6th syscall arg */ |
| 257 | jmp sysenter_dispatch |
| 258 | |
| 259 | sysexit_audit: |
| 260 | auditsys_exit sysexit_from_sys_call |
| 261 | #endif |
| 262 | |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 263 | sysenter_fix_flags: |
| 264 | pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) |
| 265 | popfq_cfi |
| 266 | jmp sysenter_flags_fixed |
| 267 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 268 | sysenter_tracesys: |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 269 | #ifdef CONFIG_AUDITSYSCALL |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 270 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 271 | jz sysenter_auditsys |
| 272 | #endif |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 273 | SAVE_EXTRA_REGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | CLEAR_RREGS |
Roland McGrath | 48ee679 | 2008-03-18 18:23:50 -0700 | [diff] [blame] | 275 | movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
| 277 | call syscall_trace_enter |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 278 | LOAD_ARGS32 /* reload args from stack in case ptrace changed it */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 279 | RESTORE_EXTRA_REGS |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 280 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | 48ee679 | 2008-03-18 18:23:50 -0700 | [diff] [blame] | 281 | ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | jmp sysenter_do_call |
| 283 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 284 | ENDPROC(ia32_sysenter_target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | /* |
| 287 | * 32bit SYSCALL instruction entry. |
| 288 | * |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 289 | * 32bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11, |
| 290 | * then loads new ss, cs, and rip from previously programmed MSRs. |
| 291 | * rflags gets masked by a value from another MSR (so CLD and CLAC |
| 292 | * are not needed). SYSCALL does not save anything on the stack |
| 293 | * and does not change rsp. |
| 294 | * |
| 295 | * Note: rflags saving+masking-with-MSR happens only in Long mode |
| 296 | * (in legacy 32bit mode, IF, RF and VM bits are cleared and that's it). |
| 297 | * Don't get confused: rflags saving+masking depends on Long Mode Active bit |
| 298 | * (EFER.LMA=1), NOT on bitness of userspace where SYSCALL executes |
| 299 | * or target CS descriptor's L bit (SYSCALL does not read segment descriptors). |
| 300 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | * Arguments: |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 302 | * eax system call number |
| 303 | * ecx return address |
| 304 | * ebx arg1 |
| 305 | * ebp arg2 (note: not saved in the stack frame, should not be touched) |
| 306 | * edx arg3 |
| 307 | * esi arg4 |
| 308 | * edi arg5 |
| 309 | * esp user stack |
| 310 | * 0(%esp) arg6 |
| 311 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | * This is purely a fast path. For anything complicated we use the int 0x80 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 313 | * path below. We set up a complete hardware stack frame to share code |
| 314 | * with the int 0x80 path. |
| 315 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | ENTRY(ia32_cstar_target) |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 317 | CFI_STARTPROC32 simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 318 | CFI_SIGNAL_FRAME |
Denys Vlasenko | ef59326 | 2015-03-19 18:17:46 +0100 | [diff] [blame] | 319 | CFI_DEF_CFA rsp,0 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 320 | CFI_REGISTER rip,rcx |
| 321 | /*CFI_REGISTER rflags,r11*/ |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 322 | |
| 323 | /* |
| 324 | * Interrupts are off on entry. |
| 325 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, |
| 326 | * it is too small to ever cause noticeable irq latency. |
| 327 | */ |
Jeremy Fitzhardinge | 457da70 | 2008-06-26 07:28:51 -0700 | [diff] [blame] | 328 | SWAPGS_UNSAFE_STACK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | movl %esp,%r8d |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 330 | CFI_REGISTER rsp,r8 |
Brian Gerst | 9af4565 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 331 | movq PER_CPU_VAR(kernel_stack),%rsp |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 332 | ENABLE_INTERRUPTS(CLBR_NONE) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 333 | |
Denys Vlasenko | 4ee8ec1 | 2015-03-27 11:36:21 +0100 | [diff] [blame^] | 334 | /* Zero-extending 32-bit regs, do not remove */ |
| 335 | movl %eax,%eax |
| 336 | |
Denys Vlasenko | ef59326 | 2015-03-19 18:17:46 +0100 | [diff] [blame] | 337 | ALLOC_PT_GPREGS_ON_STACK 6*8 /* 6*8: space for orig_ax and iret frame */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 338 | SAVE_C_REGS_EXCEPT_RCX_R891011 |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 339 | movq %rax,ORIG_RAX(%rsp) |
| 340 | movq %rcx,RIP(%rsp) |
| 341 | CFI_REL_OFFSET rip,RIP |
| 342 | movq %rbp,RCX(%rsp) /* this lies slightly to ptrace */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | movl %ebp,%ecx |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 344 | movq $__USER32_CS,CS(%rsp) |
| 345 | movq $__USER32_DS,SS(%rsp) |
| 346 | movq %r11,EFLAGS(%rsp) |
| 347 | /*CFI_REL_OFFSET rflags,EFLAGS*/ |
| 348 | movq %r8,RSP(%rsp) |
| 349 | CFI_REL_OFFSET rsp,RSP |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 350 | /* iret stack frame is complete now */ |
| 351 | /* |
| 352 | * no need to do an access_ok check here because r8 has been |
| 353 | * 32bit zero extended |
| 354 | */ |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 355 | ASM_STAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | 1: movl (%r8),%r9d |
H. Peter Anvin | a3e859f | 2012-04-20 16:51:50 -0700 | [diff] [blame] | 357 | _ASM_EXTABLE(1b,ia32_badarg) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 358 | ASM_CLAC |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 359 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
| 360 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 361 | CFI_REMEMBER_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | jnz cstar_tracesys |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 363 | cmpq $IA32_NR_syscalls-1,%rax |
Andi Kleen | 67d53ea | 2006-04-07 19:50:31 +0200 | [diff] [blame] | 364 | ja ia32_badsys |
Jan Beulich | 295286a | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 365 | cstar_do_call: |
Denys Vlasenko | 14f6e95 | 2015-02-26 14:40:35 -0800 | [diff] [blame] | 366 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
| 367 | movl %edi,%r8d /* arg5 */ |
| 368 | /* r9 already loaded */ /* arg6 */ |
| 369 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
| 370 | movl %ebx,%edi /* arg1 */ |
| 371 | movl %edx,%edx /* arg3 (zero extension) */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 372 | cstar_dispatch: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | call *ia32_sys_call_table(,%rax,8) |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 374 | movq %rax,RAX(%rsp) |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 375 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 376 | TRACE_IRQS_OFF |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 377 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 378 | jnz sysretl_audit |
| 379 | sysretl_from_sys_call: |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 380 | andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 381 | RESTORE_RSI_RDI_RDX |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 382 | movl RIP(%rsp),%ecx |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 383 | CFI_REGISTER rip,rcx |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 384 | movl EFLAGS(%rsp),%r11d |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 385 | /*CFI_REGISTER rflags,r11*/ |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 386 | xorq %r10,%r10 |
| 387 | xorq %r9,%r9 |
| 388 | xorq %r8,%r8 |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 389 | TRACE_IRQS_ON |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 390 | movl RSP(%rsp),%esp |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 391 | CFI_RESTORE rsp |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 392 | /* |
| 393 | * 64bit->32bit SYSRET restores eip from ecx, |
| 394 | * eflags from r11 (but RF and VM bits are forced to 0), |
| 395 | * cs and ss are loaded from MSRs. |
| 396 | * (Note: 32bit->32bit SYSRET is different: since r11 |
| 397 | * does not exist, it merely sets eflags.IF=1). |
| 398 | */ |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 399 | USERGS_SYSRET32 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 400 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 401 | #ifdef CONFIG_AUDITSYSCALL |
| 402 | cstar_auditsys: |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 403 | CFI_RESTORE_STATE |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 404 | movl %r9d,R9(%rsp) /* register to be clobbered by call */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 405 | auditsys_entry_common |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 406 | movl R9(%rsp),%r9d /* reload 6th syscall arg */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 407 | jmp cstar_dispatch |
| 408 | |
| 409 | sysretl_audit: |
Jan Beulich | 8176674 | 2009-10-26 15:20:29 +0000 | [diff] [blame] | 410 | auditsys_exit sysretl_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 411 | #endif |
| 412 | |
| 413 | cstar_tracesys: |
| 414 | #ifdef CONFIG_AUDITSYSCALL |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 415 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 416 | jz cstar_auditsys |
| 417 | #endif |
Chuck Ebbert | ecd744e | 2007-11-07 10:48:39 -0500 | [diff] [blame] | 418 | xchgl %r9d,%ebp |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 419 | SAVE_EXTRA_REGS |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 420 | CLEAR_RREGS r9 |
Roland McGrath | 48ee679 | 2008-03-18 18:23:50 -0700 | [diff] [blame] | 421 | movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
| 423 | call syscall_trace_enter |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 424 | LOAD_ARGS32 1 /* reload args from stack in case ptrace changed it */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 425 | RESTORE_EXTRA_REGS |
Chuck Ebbert | ecd744e | 2007-11-07 10:48:39 -0500 | [diff] [blame] | 426 | xchgl %ebp,%r9d |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 427 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | 48ee679 | 2008-03-18 18:23:50 -0700 | [diff] [blame] | 428 | ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | jmp cstar_do_call |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 430 | END(ia32_cstar_target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | ia32_badarg: |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 433 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | movq $-EFAULT,%rax |
| 435 | jmp ia32_sysret |
| 436 | CFI_ENDPROC |
| 437 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 438 | /* |
| 439 | * Emulated IA32 system calls via int 0x80. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | * |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 441 | * Arguments: |
| 442 | * eax system call number |
| 443 | * ebx arg1 |
| 444 | * ecx arg2 |
| 445 | * edx arg3 |
| 446 | * esi arg4 |
| 447 | * edi arg5 |
| 448 | * ebp arg6 (note: not saved in the stack frame, should not be touched) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | * |
| 450 | * Notes: |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 451 | * Uses the same stack frame as the x86-64 version. |
| 452 | * All registers except eax must be saved (but ptrace may violate that). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | * Arguments are zero extended. For system calls that want sign extension and |
| 454 | * take long arguments a wrapper is needed. Most calls can just be called |
| 455 | * directly. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 456 | * Assumes it is only called from user space and entered with interrupts off. |
| 457 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | ENTRY(ia32_syscall) |
Jan Beulich | cdc1793 | 2007-07-21 17:10:20 +0200 | [diff] [blame] | 460 | CFI_STARTPROC32 simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 461 | CFI_SIGNAL_FRAME |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 462 | CFI_DEF_CFA rsp,5*8 |
| 463 | /*CFI_REL_OFFSET ss,4*8 */ |
| 464 | CFI_REL_OFFSET rsp,3*8 |
| 465 | /*CFI_REL_OFFSET rflags,2*8 */ |
| 466 | /*CFI_REL_OFFSET cs,1*8 */ |
| 467 | CFI_REL_OFFSET rip,0*8 |
| 468 | |
| 469 | /* |
| 470 | * Interrupts are off on entry. |
| 471 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, |
| 472 | * it is too small to ever cause noticeable irq latency. |
| 473 | */ |
Jeremy Fitzhardinge | 360c044 | 2008-07-08 15:06:28 -0700 | [diff] [blame] | 474 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 475 | SWAPGS |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 476 | ENABLE_INTERRUPTS(CLBR_NONE) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 477 | |
Denys Vlasenko | 4ee8ec1 | 2015-03-27 11:36:21 +0100 | [diff] [blame^] | 478 | /* Zero-extending 32-bit regs, do not remove */ |
| 479 | movl %eax,%eax |
| 480 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 481 | pushq_cfi %rax /* store orig_ax */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | cld |
| 483 | /* note the registers are not zero extended to the sf. |
| 484 | this could be a problem. */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 485 | ALLOC_PT_GPREGS_ON_STACK |
| 486 | SAVE_C_REGS_EXCEPT_R891011 |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 487 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
| 488 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | jnz ia32_tracesys |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 490 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | c09249f | 2009-02-06 18:15:18 -0800 | [diff] [blame] | 491 | ja ia32_badsys |
| 492 | ia32_do_call: |
Denys Vlasenko | 14f6e95 | 2015-02-26 14:40:35 -0800 | [diff] [blame] | 493 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
| 494 | movl %edi,%r8d /* arg5 */ |
| 495 | movl %ebp,%r9d /* arg6 */ |
| 496 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
| 497 | movl %ebx,%edi /* arg1 */ |
| 498 | movl %edx,%edx /* arg3 (zero extension) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | call *ia32_sys_call_table(,%rax,8) # xxx: rip relative |
| 500 | ia32_sysret: |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 501 | movq %rax,RAX(%rsp) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 502 | ia32_ret_from_sys_call: |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 503 | CLEAR_RREGS |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 504 | jmp int_ret_from_sys_call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 506 | ia32_tracesys: |
| 507 | SAVE_EXTRA_REGS |
Jan Beulich | cdc1793 | 2007-07-21 17:10:20 +0200 | [diff] [blame] | 508 | CLEAR_RREGS |
Roland McGrath | 8ab32bb | 2008-03-16 21:57:41 -0700 | [diff] [blame] | 509 | movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
| 511 | call syscall_trace_enter |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 512 | LOAD_ARGS32 /* reload args from stack in case ptrace changed it */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 513 | RESTORE_EXTRA_REGS |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 514 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | c09249f | 2009-02-06 18:15:18 -0800 | [diff] [blame] | 515 | ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */ |
| 516 | jmp ia32_do_call |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 517 | END(ia32_syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
| 519 | ia32_badsys: |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 520 | movq $0,ORIG_RAX(%rsp) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 521 | movq $-ENOSYS,%rax |
| 522 | jmp ia32_sysret |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | CFI_ENDPROC |
| 525 | |
Ramkumar Ramachandra | d2475b8 | 2013-07-10 23:34:28 +0530 | [diff] [blame] | 526 | .macro PTREGSCALL label, func |
Jan Beulich | f6b2bc8 | 2011-11-29 11:24:10 +0000 | [diff] [blame] | 527 | ALIGN |
| 528 | GLOBAL(\label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | leaq \func(%rip),%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | jmp ia32_ptregs_common |
| 531 | .endm |
| 532 | |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 533 | CFI_STARTPROC32 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 534 | |
Al Viro | 3fe26fa | 2012-11-12 14:32:42 -0500 | [diff] [blame] | 535 | PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn |
| 536 | PTREGSCALL stub32_sigreturn, sys32_sigreturn |
| 537 | PTREGSCALL stub32_execve, compat_sys_execve |
David Drysdale | 27d6ec7 | 2014-12-12 16:57:33 -0800 | [diff] [blame] | 538 | PTREGSCALL stub32_execveat, compat_sys_execveat |
Al Viro | 3fe26fa | 2012-11-12 14:32:42 -0500 | [diff] [blame] | 539 | PTREGSCALL stub32_fork, sys_fork |
| 540 | PTREGSCALL stub32_vfork, sys_vfork |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Jan Beulich | f6b2bc8 | 2011-11-29 11:24:10 +0000 | [diff] [blame] | 542 | ALIGN |
Al Viro | 1d4b4b2 | 2012-10-22 22:34:11 -0400 | [diff] [blame] | 543 | GLOBAL(stub32_clone) |
| 544 | leaq sys_clone(%rip),%rax |
| 545 | mov %r8, %rcx |
| 546 | jmp ia32_ptregs_common |
| 547 | |
| 548 | ALIGN |
Jan Beulich | f6b2bc8 | 2011-11-29 11:24:10 +0000 | [diff] [blame] | 549 | ia32_ptregs_common: |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 550 | CFI_ENDPROC |
| 551 | CFI_STARTPROC32 simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 552 | CFI_SIGNAL_FRAME |
Denys Vlasenko | b3ab90b | 2015-02-26 14:40:37 -0800 | [diff] [blame] | 553 | CFI_DEF_CFA rsp,SIZEOF_PTREGS |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 554 | CFI_REL_OFFSET rax,RAX |
| 555 | CFI_REL_OFFSET rcx,RCX |
| 556 | CFI_REL_OFFSET rdx,RDX |
| 557 | CFI_REL_OFFSET rsi,RSI |
| 558 | CFI_REL_OFFSET rdi,RDI |
| 559 | CFI_REL_OFFSET rip,RIP |
| 560 | /* CFI_REL_OFFSET cs,CS*/ |
| 561 | /* CFI_REL_OFFSET rflags,EFLAGS*/ |
| 562 | CFI_REL_OFFSET rsp,RSP |
| 563 | /* CFI_REL_OFFSET ss,SS*/ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 564 | SAVE_EXTRA_REGS 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | call *%rax |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 566 | RESTORE_EXTRA_REGS 8 |
| 567 | ret |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 569 | END(ia32_ptregs_common) |