ia32entry.S 17 KB

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