entry_32.S 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. /*
  2. * linux/arch/i386/entry.S
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /*
  7. * entry.S contains the system-call and fault low-level handling routines.
  8. * This also contains the timer-interrupt handler, as well as all interrupts
  9. * and faults that can result in a task-switch.
  10. *
  11. * NOTE: This code handles signal-recognition, which happens every time
  12. * after a timer-interrupt and after each system call.
  13. *
  14. * I changed all the .align's to 4 (16 byte alignment), as that's faster
  15. * on a 486.
  16. *
  17. * Stack layout in 'syscall_exit':
  18. * ptrace needs to have all regs on the stack.
  19. * if the order here is changed, it needs to be
  20. * updated in fork.c:copy_process, signal.c:do_signal,
  21. * ptrace.c and ptrace.h
  22. *
  23. * 0(%esp) - %ebx
  24. * 4(%esp) - %ecx
  25. * 8(%esp) - %edx
  26. * C(%esp) - %esi
  27. * 10(%esp) - %edi
  28. * 14(%esp) - %ebp
  29. * 18(%esp) - %eax
  30. * 1C(%esp) - %ds
  31. * 20(%esp) - %es
  32. * 24(%esp) - %fs
  33. * 28(%esp) - orig_eax
  34. * 2C(%esp) - %eip
  35. * 30(%esp) - %cs
  36. * 34(%esp) - %eflags
  37. * 38(%esp) - %oldesp
  38. * 3C(%esp) - %oldss
  39. *
  40. * "current" is in register %ebx during any slow entries.
  41. */
  42. #include <linux/linkage.h>
  43. #include <asm/thread_info.h>
  44. #include <asm/irqflags.h>
  45. #include <asm/errno.h>
  46. #include <asm/segment.h>
  47. #include <asm/smp.h>
  48. #include <asm/page.h>
  49. #include <asm/desc.h>
  50. #include <asm/percpu.h>
  51. #include <asm/dwarf2.h>
  52. #include <asm/processor-flags.h>
  53. #include "irq_vectors.h"
  54. /*
  55. * We use macros for low-level operations which need to be overridden
  56. * for paravirtualization. The following will never clobber any registers:
  57. * INTERRUPT_RETURN (aka. "iret")
  58. * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
  59. * ENABLE_INTERRUPTS_SYSCALL_RET (aka "sti; sysexit").
  60. *
  61. * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
  62. * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
  63. * Allowing a register to be clobbered can shrink the paravirt replacement
  64. * enough to patch inline, increasing performance.
  65. */
  66. #define nr_syscalls ((syscall_table_size)/4)
  67. #ifdef CONFIG_PREEMPT
  68. #define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
  69. #else
  70. #define preempt_stop(clobbers)
  71. #define resume_kernel restore_nocheck
  72. #endif
  73. .macro TRACE_IRQS_IRET
  74. #ifdef CONFIG_TRACE_IRQFLAGS
  75. testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
  76. jz 1f
  77. TRACE_IRQS_ON
  78. 1:
  79. #endif
  80. .endm
  81. #ifdef CONFIG_VM86
  82. #define resume_userspace_sig check_userspace
  83. #else
  84. #define resume_userspace_sig resume_userspace
  85. #endif
  86. #define SAVE_ALL \
  87. cld; \
  88. pushl %fs; \
  89. CFI_ADJUST_CFA_OFFSET 4;\
  90. /*CFI_REL_OFFSET fs, 0;*/\
  91. pushl %es; \
  92. CFI_ADJUST_CFA_OFFSET 4;\
  93. /*CFI_REL_OFFSET es, 0;*/\
  94. pushl %ds; \
  95. CFI_ADJUST_CFA_OFFSET 4;\
  96. /*CFI_REL_OFFSET ds, 0;*/\
  97. pushl %eax; \
  98. CFI_ADJUST_CFA_OFFSET 4;\
  99. CFI_REL_OFFSET eax, 0;\
  100. pushl %ebp; \
  101. CFI_ADJUST_CFA_OFFSET 4;\
  102. CFI_REL_OFFSET ebp, 0;\
  103. pushl %edi; \
  104. CFI_ADJUST_CFA_OFFSET 4;\
  105. CFI_REL_OFFSET edi, 0;\
  106. pushl %esi; \
  107. CFI_ADJUST_CFA_OFFSET 4;\
  108. CFI_REL_OFFSET esi, 0;\
  109. pushl %edx; \
  110. CFI_ADJUST_CFA_OFFSET 4;\
  111. CFI_REL_OFFSET edx, 0;\
  112. pushl %ecx; \
  113. CFI_ADJUST_CFA_OFFSET 4;\
  114. CFI_REL_OFFSET ecx, 0;\
  115. pushl %ebx; \
  116. CFI_ADJUST_CFA_OFFSET 4;\
  117. CFI_REL_OFFSET ebx, 0;\
  118. movl $(__USER_DS), %edx; \
  119. movl %edx, %ds; \
  120. movl %edx, %es; \
  121. movl $(__KERNEL_PERCPU), %edx; \
  122. movl %edx, %fs
  123. #define RESTORE_INT_REGS \
  124. popl %ebx; \
  125. CFI_ADJUST_CFA_OFFSET -4;\
  126. CFI_RESTORE ebx;\
  127. popl %ecx; \
  128. CFI_ADJUST_CFA_OFFSET -4;\
  129. CFI_RESTORE ecx;\
  130. popl %edx; \
  131. CFI_ADJUST_CFA_OFFSET -4;\
  132. CFI_RESTORE edx;\
  133. popl %esi; \
  134. CFI_ADJUST_CFA_OFFSET -4;\
  135. CFI_RESTORE esi;\
  136. popl %edi; \
  137. CFI_ADJUST_CFA_OFFSET -4;\
  138. CFI_RESTORE edi;\
  139. popl %ebp; \
  140. CFI_ADJUST_CFA_OFFSET -4;\
  141. CFI_RESTORE ebp;\
  142. popl %eax; \
  143. CFI_ADJUST_CFA_OFFSET -4;\
  144. CFI_RESTORE eax
  145. #define RESTORE_REGS \
  146. RESTORE_INT_REGS; \
  147. 1: popl %ds; \
  148. CFI_ADJUST_CFA_OFFSET -4;\
  149. /*CFI_RESTORE ds;*/\
  150. 2: popl %es; \
  151. CFI_ADJUST_CFA_OFFSET -4;\
  152. /*CFI_RESTORE es;*/\
  153. 3: popl %fs; \
  154. CFI_ADJUST_CFA_OFFSET -4;\
  155. /*CFI_RESTORE fs;*/\
  156. .pushsection .fixup,"ax"; \
  157. 4: movl $0,(%esp); \
  158. jmp 1b; \
  159. 5: movl $0,(%esp); \
  160. jmp 2b; \
  161. 6: movl $0,(%esp); \
  162. jmp 3b; \
  163. .section __ex_table,"a";\
  164. .align 4; \
  165. .long 1b,4b; \
  166. .long 2b,5b; \
  167. .long 3b,6b; \
  168. .popsection
  169. #define RING0_INT_FRAME \
  170. CFI_STARTPROC simple;\
  171. CFI_SIGNAL_FRAME;\
  172. CFI_DEF_CFA esp, 3*4;\
  173. /*CFI_OFFSET cs, -2*4;*/\
  174. CFI_OFFSET eip, -3*4
  175. #define RING0_EC_FRAME \
  176. CFI_STARTPROC simple;\
  177. CFI_SIGNAL_FRAME;\
  178. CFI_DEF_CFA esp, 4*4;\
  179. /*CFI_OFFSET cs, -2*4;*/\
  180. CFI_OFFSET eip, -3*4
  181. #define RING0_PTREGS_FRAME \
  182. CFI_STARTPROC simple;\
  183. CFI_SIGNAL_FRAME;\
  184. CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
  185. /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
  186. CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
  187. /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
  188. /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
  189. CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
  190. CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
  191. CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
  192. CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
  193. CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
  194. CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
  195. CFI_OFFSET ebx, PT_EBX-PT_OLDESP
  196. ENTRY(ret_from_fork)
  197. CFI_STARTPROC
  198. pushl %eax
  199. CFI_ADJUST_CFA_OFFSET 4
  200. call schedule_tail
  201. GET_THREAD_INFO(%ebp)
  202. popl %eax
  203. CFI_ADJUST_CFA_OFFSET -4
  204. pushl $0x0202 # Reset kernel eflags
  205. CFI_ADJUST_CFA_OFFSET 4
  206. popfl
  207. CFI_ADJUST_CFA_OFFSET -4
  208. jmp syscall_exit
  209. CFI_ENDPROC
  210. END(ret_from_fork)
  211. /*
  212. * Return to user mode is not as complex as all this looks,
  213. * but we want the default path for a system call return to
  214. * go as quickly as possible which is why some of this is
  215. * less clear than it otherwise should be.
  216. */
  217. # userspace resumption stub bypassing syscall exit tracing
  218. ALIGN
  219. RING0_PTREGS_FRAME
  220. ret_from_exception:
  221. preempt_stop(CLBR_ANY)
  222. ret_from_intr:
  223. GET_THREAD_INFO(%ebp)
  224. check_userspace:
  225. movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
  226. movb PT_CS(%esp), %al
  227. andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
  228. cmpl $USER_RPL, %eax
  229. jb resume_kernel # not returning to v8086 or userspace
  230. ENTRY(resume_userspace)
  231. LOCKDEP_SYS_EXIT
  232. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  233. # setting need_resched or sigpending
  234. # between sampling and the iret
  235. movl TI_flags(%ebp), %ecx
  236. andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
  237. # int/exception return?
  238. jne work_pending
  239. jmp restore_all
  240. END(ret_from_exception)
  241. #ifdef CONFIG_PREEMPT
  242. ENTRY(resume_kernel)
  243. DISABLE_INTERRUPTS(CLBR_ANY)
  244. cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
  245. jnz restore_nocheck
  246. need_resched:
  247. movl TI_flags(%ebp), %ecx # need_resched set ?
  248. testb $_TIF_NEED_RESCHED, %cl
  249. jz restore_all
  250. testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
  251. jz restore_all
  252. call preempt_schedule_irq
  253. jmp need_resched
  254. END(resume_kernel)
  255. #endif
  256. CFI_ENDPROC
  257. /* SYSENTER_RETURN points to after the "sysenter" instruction in
  258. the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
  259. # sysenter call handler stub
  260. ENTRY(ia32_sysenter_target)
  261. CFI_STARTPROC simple
  262. CFI_SIGNAL_FRAME
  263. CFI_DEF_CFA esp, 0
  264. CFI_REGISTER esp, ebp
  265. movl TSS_sysenter_sp0(%esp),%esp
  266. sysenter_past_esp:
  267. /*
  268. * Interrupts are disabled here, but we can't trace it until
  269. * enough kernel state to call TRACE_IRQS_OFF can be called - but
  270. * we immediately enable interrupts at that point anyway.
  271. */
  272. pushl $(__USER_DS)
  273. CFI_ADJUST_CFA_OFFSET 4
  274. /*CFI_REL_OFFSET ss, 0*/
  275. pushl %ebp
  276. CFI_ADJUST_CFA_OFFSET 4
  277. CFI_REL_OFFSET esp, 0
  278. pushfl
  279. orl $X86_EFLAGS_IF, (%esp)
  280. CFI_ADJUST_CFA_OFFSET 4
  281. pushl $(__USER_CS)
  282. CFI_ADJUST_CFA_OFFSET 4
  283. /*CFI_REL_OFFSET cs, 0*/
  284. /*
  285. * Push current_thread_info()->sysenter_return to the stack.
  286. * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
  287. * pushed above; +8 corresponds to copy_thread's esp0 setting.
  288. */
  289. pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
  290. CFI_ADJUST_CFA_OFFSET 4
  291. CFI_REL_OFFSET eip, 0
  292. pushl %eax
  293. CFI_ADJUST_CFA_OFFSET 4
  294. SAVE_ALL
  295. ENABLE_INTERRUPTS(CLBR_NONE)
  296. /*
  297. * Load the potential sixth argument from user stack.
  298. * Careful about security.
  299. */
  300. cmpl $__PAGE_OFFSET-3,%ebp
  301. jae syscall_fault
  302. 1: movl (%ebp),%ebp
  303. movl %ebp,PT_EBP(%esp)
  304. .section __ex_table,"a"
  305. .align 4
  306. .long 1b,syscall_fault
  307. .previous
  308. GET_THREAD_INFO(%ebp)
  309. /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
  310. testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  311. jnz syscall_trace_entry
  312. cmpl $(nr_syscalls), %eax
  313. jae syscall_badsys
  314. call *sys_call_table(,%eax,4)
  315. movl %eax,PT_EAX(%esp)
  316. LOCKDEP_SYS_EXIT
  317. DISABLE_INTERRUPTS(CLBR_ANY)
  318. TRACE_IRQS_OFF
  319. movl TI_flags(%ebp), %ecx
  320. testw $_TIF_ALLWORK_MASK, %cx
  321. jne syscall_exit_work
  322. /* if something modifies registers it must also disable sysexit */
  323. movl PT_EIP(%esp), %edx
  324. movl PT_OLDESP(%esp), %ecx
  325. xorl %ebp,%ebp
  326. TRACE_IRQS_ON
  327. 1: mov PT_FS(%esp), %fs
  328. ENABLE_INTERRUPTS_SYSCALL_RET
  329. CFI_ENDPROC
  330. .pushsection .fixup,"ax"
  331. 2: movl $0,PT_FS(%esp)
  332. jmp 1b
  333. .section __ex_table,"a"
  334. .align 4
  335. .long 1b,2b
  336. .popsection
  337. ENDPROC(ia32_sysenter_target)
  338. # system call handler stub
  339. ENTRY(system_call)
  340. RING0_INT_FRAME # can't unwind into user space anyway
  341. pushl %eax # save orig_eax
  342. CFI_ADJUST_CFA_OFFSET 4
  343. SAVE_ALL
  344. GET_THREAD_INFO(%ebp)
  345. # system call tracing in operation / emulation
  346. /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
  347. testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  348. jnz syscall_trace_entry
  349. cmpl $(nr_syscalls), %eax
  350. jae syscall_badsys
  351. syscall_call:
  352. call *sys_call_table(,%eax,4)
  353. movl %eax,PT_EAX(%esp) # store the return value
  354. syscall_exit:
  355. LOCKDEP_SYS_EXIT
  356. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  357. # setting need_resched or sigpending
  358. # between sampling and the iret
  359. TRACE_IRQS_OFF
  360. testl $X86_EFLAGS_TF,PT_EFLAGS(%esp) # If tracing set singlestep flag on exit
  361. jz no_singlestep
  362. orl $_TIF_SINGLESTEP,TI_flags(%ebp)
  363. no_singlestep:
  364. movl TI_flags(%ebp), %ecx
  365. testw $_TIF_ALLWORK_MASK, %cx # current->work
  366. jne syscall_exit_work
  367. restore_all:
  368. movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
  369. # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
  370. # are returning to the kernel.
  371. # See comments in process.c:copy_thread() for details.
  372. movb PT_OLDSS(%esp), %ah
  373. movb PT_CS(%esp), %al
  374. andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
  375. cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
  376. CFI_REMEMBER_STATE
  377. je ldt_ss # returning to user-space with LDT SS
  378. restore_nocheck:
  379. TRACE_IRQS_IRET
  380. restore_nocheck_notrace:
  381. RESTORE_REGS
  382. addl $4, %esp # skip orig_eax/error_code
  383. CFI_ADJUST_CFA_OFFSET -4
  384. irq_return:
  385. INTERRUPT_RETURN
  386. .section .fixup,"ax"
  387. iret_exc:
  388. pushl $0 # no error code
  389. pushl $do_iret_error
  390. jmp error_code
  391. .previous
  392. .section __ex_table,"a"
  393. .align 4
  394. .long irq_return,iret_exc
  395. .previous
  396. CFI_RESTORE_STATE
  397. ldt_ss:
  398. larl PT_OLDSS(%esp), %eax
  399. jnz restore_nocheck
  400. testl $0x00400000, %eax # returning to 32bit stack?
  401. jnz restore_nocheck # allright, normal return
  402. #ifdef CONFIG_PARAVIRT
  403. /*
  404. * The kernel can't run on a non-flat stack if paravirt mode
  405. * is active. Rather than try to fixup the high bits of
  406. * ESP, bypass this code entirely. This may break DOSemu
  407. * and/or Wine support in a paravirt VM, although the option
  408. * is still available to implement the setting of the high
  409. * 16-bits in the INTERRUPT_RETURN paravirt-op.
  410. */
  411. cmpl $0, pv_info+PARAVIRT_enabled
  412. jne restore_nocheck
  413. #endif
  414. /* If returning to userspace with 16bit stack,
  415. * try to fix the higher word of ESP, as the CPU
  416. * won't restore it.
  417. * This is an "official" bug of all the x86-compatible
  418. * CPUs, which we can try to work around to make
  419. * dosemu and wine happy. */
  420. movl PT_OLDESP(%esp), %eax
  421. movl %esp, %edx
  422. call patch_espfix_desc
  423. pushl $__ESPFIX_SS
  424. CFI_ADJUST_CFA_OFFSET 4
  425. pushl %eax
  426. CFI_ADJUST_CFA_OFFSET 4
  427. DISABLE_INTERRUPTS(CLBR_EAX)
  428. TRACE_IRQS_OFF
  429. lss (%esp), %esp
  430. CFI_ADJUST_CFA_OFFSET -8
  431. jmp restore_nocheck
  432. CFI_ENDPROC
  433. ENDPROC(system_call)
  434. # perform work that needs to be done immediately before resumption
  435. ALIGN
  436. RING0_PTREGS_FRAME # can't unwind into user space anyway
  437. work_pending:
  438. testb $_TIF_NEED_RESCHED, %cl
  439. jz work_notifysig
  440. work_resched:
  441. call schedule
  442. LOCKDEP_SYS_EXIT
  443. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  444. # setting need_resched or sigpending
  445. # between sampling and the iret
  446. TRACE_IRQS_OFF
  447. movl TI_flags(%ebp), %ecx
  448. andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
  449. # than syscall tracing?
  450. jz restore_all
  451. testb $_TIF_NEED_RESCHED, %cl
  452. jnz work_resched
  453. work_notifysig: # deal with pending signals and
  454. # notify-resume requests
  455. #ifdef CONFIG_VM86
  456. testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
  457. movl %esp, %eax
  458. jne work_notifysig_v86 # returning to kernel-space or
  459. # vm86-space
  460. xorl %edx, %edx
  461. call do_notify_resume
  462. jmp resume_userspace_sig
  463. ALIGN
  464. work_notifysig_v86:
  465. pushl %ecx # save ti_flags for do_notify_resume
  466. CFI_ADJUST_CFA_OFFSET 4
  467. call save_v86_state # %eax contains pt_regs pointer
  468. popl %ecx
  469. CFI_ADJUST_CFA_OFFSET -4
  470. movl %eax, %esp
  471. #else
  472. movl %esp, %eax
  473. #endif
  474. xorl %edx, %edx
  475. call do_notify_resume
  476. jmp resume_userspace_sig
  477. END(work_pending)
  478. # perform syscall exit tracing
  479. ALIGN
  480. syscall_trace_entry:
  481. movl $-ENOSYS,PT_EAX(%esp)
  482. movl %esp, %eax
  483. xorl %edx,%edx
  484. call do_syscall_trace
  485. cmpl $0, %eax
  486. jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
  487. # so must skip actual syscall
  488. movl PT_ORIG_EAX(%esp), %eax
  489. cmpl $(nr_syscalls), %eax
  490. jnae syscall_call
  491. jmp syscall_exit
  492. END(syscall_trace_entry)
  493. # perform syscall exit tracing
  494. ALIGN
  495. syscall_exit_work:
  496. testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
  497. jz work_pending
  498. TRACE_IRQS_ON
  499. ENABLE_INTERRUPTS(CLBR_ANY) # could let do_syscall_trace() call
  500. # schedule() instead
  501. movl %esp, %eax
  502. movl $1, %edx
  503. call do_syscall_trace
  504. jmp resume_userspace
  505. END(syscall_exit_work)
  506. CFI_ENDPROC
  507. RING0_INT_FRAME # can't unwind into user space anyway
  508. syscall_fault:
  509. GET_THREAD_INFO(%ebp)
  510. movl $-EFAULT,PT_EAX(%esp)
  511. jmp resume_userspace
  512. END(syscall_fault)
  513. syscall_badsys:
  514. movl $-ENOSYS,PT_EAX(%esp)
  515. jmp resume_userspace
  516. END(syscall_badsys)
  517. CFI_ENDPROC
  518. #define FIXUP_ESPFIX_STACK \
  519. /* since we are on a wrong stack, we cant make it a C code :( */ \
  520. PER_CPU(gdt_page, %ebx); \
  521. GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
  522. addl %esp, %eax; \
  523. pushl $__KERNEL_DS; \
  524. CFI_ADJUST_CFA_OFFSET 4; \
  525. pushl %eax; \
  526. CFI_ADJUST_CFA_OFFSET 4; \
  527. lss (%esp), %esp; \
  528. CFI_ADJUST_CFA_OFFSET -8;
  529. #define UNWIND_ESPFIX_STACK \
  530. movl %ss, %eax; \
  531. /* see if on espfix stack */ \
  532. cmpw $__ESPFIX_SS, %ax; \
  533. jne 27f; \
  534. movl $__KERNEL_DS, %eax; \
  535. movl %eax, %ds; \
  536. movl %eax, %es; \
  537. /* switch to normal stack */ \
  538. FIXUP_ESPFIX_STACK; \
  539. 27:;
  540. /*
  541. * Build the entry stubs and pointer table with
  542. * some assembler magic.
  543. */
  544. .section .rodata,"a"
  545. ENTRY(interrupt)
  546. .text
  547. ENTRY(irq_entries_start)
  548. RING0_INT_FRAME
  549. vector=0
  550. .rept NR_IRQS
  551. ALIGN
  552. .if vector
  553. CFI_ADJUST_CFA_OFFSET -4
  554. .endif
  555. 1: pushl $~(vector)
  556. CFI_ADJUST_CFA_OFFSET 4
  557. jmp common_interrupt
  558. .previous
  559. .long 1b
  560. .text
  561. vector=vector+1
  562. .endr
  563. END(irq_entries_start)
  564. .previous
  565. END(interrupt)
  566. .previous
  567. /*
  568. * the CPU automatically disables interrupts when executing an IRQ vector,
  569. * so IRQ-flags tracing has to follow that:
  570. */
  571. ALIGN
  572. common_interrupt:
  573. SAVE_ALL
  574. TRACE_IRQS_OFF
  575. movl %esp,%eax
  576. call do_IRQ
  577. jmp ret_from_intr
  578. ENDPROC(common_interrupt)
  579. CFI_ENDPROC
  580. #define BUILD_INTERRUPT(name, nr) \
  581. ENTRY(name) \
  582. RING0_INT_FRAME; \
  583. pushl $~(nr); \
  584. CFI_ADJUST_CFA_OFFSET 4; \
  585. SAVE_ALL; \
  586. TRACE_IRQS_OFF \
  587. movl %esp,%eax; \
  588. call smp_##name; \
  589. jmp ret_from_intr; \
  590. CFI_ENDPROC; \
  591. ENDPROC(name)
  592. /* The include is where all of the SMP etc. interrupts come from */
  593. #include "entry_arch.h"
  594. KPROBE_ENTRY(page_fault)
  595. RING0_EC_FRAME
  596. pushl $do_page_fault
  597. CFI_ADJUST_CFA_OFFSET 4
  598. ALIGN
  599. error_code:
  600. /* the function address is in %fs's slot on the stack */
  601. pushl %es
  602. CFI_ADJUST_CFA_OFFSET 4
  603. /*CFI_REL_OFFSET es, 0*/
  604. pushl %ds
  605. CFI_ADJUST_CFA_OFFSET 4
  606. /*CFI_REL_OFFSET ds, 0*/
  607. pushl %eax
  608. CFI_ADJUST_CFA_OFFSET 4
  609. CFI_REL_OFFSET eax, 0
  610. pushl %ebp
  611. CFI_ADJUST_CFA_OFFSET 4
  612. CFI_REL_OFFSET ebp, 0
  613. pushl %edi
  614. CFI_ADJUST_CFA_OFFSET 4
  615. CFI_REL_OFFSET edi, 0
  616. pushl %esi
  617. CFI_ADJUST_CFA_OFFSET 4
  618. CFI_REL_OFFSET esi, 0
  619. pushl %edx
  620. CFI_ADJUST_CFA_OFFSET 4
  621. CFI_REL_OFFSET edx, 0
  622. pushl %ecx
  623. CFI_ADJUST_CFA_OFFSET 4
  624. CFI_REL_OFFSET ecx, 0
  625. pushl %ebx
  626. CFI_ADJUST_CFA_OFFSET 4
  627. CFI_REL_OFFSET ebx, 0
  628. cld
  629. pushl %fs
  630. CFI_ADJUST_CFA_OFFSET 4
  631. /*CFI_REL_OFFSET fs, 0*/
  632. movl $(__KERNEL_PERCPU), %ecx
  633. movl %ecx, %fs
  634. UNWIND_ESPFIX_STACK
  635. popl %ecx
  636. CFI_ADJUST_CFA_OFFSET -4
  637. /*CFI_REGISTER es, ecx*/
  638. movl PT_FS(%esp), %edi # get the function address
  639. movl PT_ORIG_EAX(%esp), %edx # get the error code
  640. movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
  641. mov %ecx, PT_FS(%esp)
  642. /*CFI_REL_OFFSET fs, ES*/
  643. movl $(__USER_DS), %ecx
  644. movl %ecx, %ds
  645. movl %ecx, %es
  646. movl %esp,%eax # pt_regs pointer
  647. call *%edi
  648. jmp ret_from_exception
  649. CFI_ENDPROC
  650. KPROBE_END(page_fault)
  651. ENTRY(coprocessor_error)
  652. RING0_INT_FRAME
  653. pushl $0
  654. CFI_ADJUST_CFA_OFFSET 4
  655. pushl $do_coprocessor_error
  656. CFI_ADJUST_CFA_OFFSET 4
  657. jmp error_code
  658. CFI_ENDPROC
  659. END(coprocessor_error)
  660. ENTRY(simd_coprocessor_error)
  661. RING0_INT_FRAME
  662. pushl $0
  663. CFI_ADJUST_CFA_OFFSET 4
  664. pushl $do_simd_coprocessor_error
  665. CFI_ADJUST_CFA_OFFSET 4
  666. jmp error_code
  667. CFI_ENDPROC
  668. END(simd_coprocessor_error)
  669. ENTRY(device_not_available)
  670. RING0_INT_FRAME
  671. pushl $-1 # mark this as an int
  672. CFI_ADJUST_CFA_OFFSET 4
  673. SAVE_ALL
  674. GET_CR0_INTO_EAX
  675. testl $0x4, %eax # EM (math emulation bit)
  676. jne device_not_available_emulate
  677. preempt_stop(CLBR_ANY)
  678. call math_state_restore
  679. jmp ret_from_exception
  680. device_not_available_emulate:
  681. pushl $0 # temporary storage for ORIG_EIP
  682. CFI_ADJUST_CFA_OFFSET 4
  683. call math_emulate
  684. addl $4, %esp
  685. CFI_ADJUST_CFA_OFFSET -4
  686. jmp ret_from_exception
  687. CFI_ENDPROC
  688. END(device_not_available)
  689. /*
  690. * Debug traps and NMI can happen at the one SYSENTER instruction
  691. * that sets up the real kernel stack. Check here, since we can't
  692. * allow the wrong stack to be used.
  693. *
  694. * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
  695. * already pushed 3 words if it hits on the sysenter instruction:
  696. * eflags, cs and eip.
  697. *
  698. * We just load the right stack, and push the three (known) values
  699. * by hand onto the new stack - while updating the return eip past
  700. * the instruction that would have done it for sysenter.
  701. */
  702. #define FIX_STACK(offset, ok, label) \
  703. cmpw $__KERNEL_CS,4(%esp); \
  704. jne ok; \
  705. label: \
  706. movl TSS_sysenter_sp0+offset(%esp),%esp; \
  707. CFI_DEF_CFA esp, 0; \
  708. CFI_UNDEFINED eip; \
  709. pushfl; \
  710. CFI_ADJUST_CFA_OFFSET 4; \
  711. pushl $__KERNEL_CS; \
  712. CFI_ADJUST_CFA_OFFSET 4; \
  713. pushl $sysenter_past_esp; \
  714. CFI_ADJUST_CFA_OFFSET 4; \
  715. CFI_REL_OFFSET eip, 0
  716. KPROBE_ENTRY(debug)
  717. RING0_INT_FRAME
  718. cmpl $ia32_sysenter_target,(%esp)
  719. jne debug_stack_correct
  720. FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
  721. debug_stack_correct:
  722. pushl $-1 # mark this as an int
  723. CFI_ADJUST_CFA_OFFSET 4
  724. SAVE_ALL
  725. xorl %edx,%edx # error code 0
  726. movl %esp,%eax # pt_regs pointer
  727. call do_debug
  728. jmp ret_from_exception
  729. CFI_ENDPROC
  730. KPROBE_END(debug)
  731. /*
  732. * NMI is doubly nasty. It can happen _while_ we're handling
  733. * a debug fault, and the debug fault hasn't yet been able to
  734. * clear up the stack. So we first check whether we got an
  735. * NMI on the sysenter entry path, but after that we need to
  736. * check whether we got an NMI on the debug path where the debug
  737. * fault happened on the sysenter path.
  738. */
  739. KPROBE_ENTRY(nmi)
  740. RING0_INT_FRAME
  741. pushl %eax
  742. CFI_ADJUST_CFA_OFFSET 4
  743. movl %ss, %eax
  744. cmpw $__ESPFIX_SS, %ax
  745. popl %eax
  746. CFI_ADJUST_CFA_OFFSET -4
  747. je nmi_espfix_stack
  748. cmpl $ia32_sysenter_target,(%esp)
  749. je nmi_stack_fixup
  750. pushl %eax
  751. CFI_ADJUST_CFA_OFFSET 4
  752. movl %esp,%eax
  753. /* Do not access memory above the end of our stack page,
  754. * it might not exist.
  755. */
  756. andl $(THREAD_SIZE-1),%eax
  757. cmpl $(THREAD_SIZE-20),%eax
  758. popl %eax
  759. CFI_ADJUST_CFA_OFFSET -4
  760. jae nmi_stack_correct
  761. cmpl $ia32_sysenter_target,12(%esp)
  762. je nmi_debug_stack_check
  763. nmi_stack_correct:
  764. /* We have a RING0_INT_FRAME here */
  765. pushl %eax
  766. CFI_ADJUST_CFA_OFFSET 4
  767. SAVE_ALL
  768. xorl %edx,%edx # zero error code
  769. movl %esp,%eax # pt_regs pointer
  770. call do_nmi
  771. jmp restore_nocheck_notrace
  772. CFI_ENDPROC
  773. nmi_stack_fixup:
  774. RING0_INT_FRAME
  775. FIX_STACK(12,nmi_stack_correct, 1)
  776. jmp nmi_stack_correct
  777. nmi_debug_stack_check:
  778. /* We have a RING0_INT_FRAME here */
  779. cmpw $__KERNEL_CS,16(%esp)
  780. jne nmi_stack_correct
  781. cmpl $debug,(%esp)
  782. jb nmi_stack_correct
  783. cmpl $debug_esp_fix_insn,(%esp)
  784. ja nmi_stack_correct
  785. FIX_STACK(24,nmi_stack_correct, 1)
  786. jmp nmi_stack_correct
  787. nmi_espfix_stack:
  788. /* We have a RING0_INT_FRAME here.
  789. *
  790. * create the pointer to lss back
  791. */
  792. pushl %ss
  793. CFI_ADJUST_CFA_OFFSET 4
  794. pushl %esp
  795. CFI_ADJUST_CFA_OFFSET 4
  796. addw $4, (%esp)
  797. /* copy the iret frame of 12 bytes */
  798. .rept 3
  799. pushl 16(%esp)
  800. CFI_ADJUST_CFA_OFFSET 4
  801. .endr
  802. pushl %eax
  803. CFI_ADJUST_CFA_OFFSET 4
  804. SAVE_ALL
  805. FIXUP_ESPFIX_STACK # %eax == %esp
  806. xorl %edx,%edx # zero error code
  807. call do_nmi
  808. RESTORE_REGS
  809. lss 12+4(%esp), %esp # back to espfix stack
  810. CFI_ADJUST_CFA_OFFSET -24
  811. jmp irq_return
  812. CFI_ENDPROC
  813. KPROBE_END(nmi)
  814. #ifdef CONFIG_PARAVIRT
  815. ENTRY(native_iret)
  816. iret
  817. .section __ex_table,"a"
  818. .align 4
  819. .long native_iret, iret_exc
  820. .previous
  821. END(native_iret)
  822. ENTRY(native_irq_enable_syscall_ret)
  823. sti
  824. sysexit
  825. END(native_irq_enable_syscall_ret)
  826. #endif
  827. KPROBE_ENTRY(int3)
  828. RING0_INT_FRAME
  829. pushl $-1 # mark this as an int
  830. CFI_ADJUST_CFA_OFFSET 4
  831. SAVE_ALL
  832. xorl %edx,%edx # zero error code
  833. movl %esp,%eax # pt_regs pointer
  834. call do_int3
  835. jmp ret_from_exception
  836. CFI_ENDPROC
  837. KPROBE_END(int3)
  838. ENTRY(overflow)
  839. RING0_INT_FRAME
  840. pushl $0
  841. CFI_ADJUST_CFA_OFFSET 4
  842. pushl $do_overflow
  843. CFI_ADJUST_CFA_OFFSET 4
  844. jmp error_code
  845. CFI_ENDPROC
  846. END(overflow)
  847. ENTRY(bounds)
  848. RING0_INT_FRAME
  849. pushl $0
  850. CFI_ADJUST_CFA_OFFSET 4
  851. pushl $do_bounds
  852. CFI_ADJUST_CFA_OFFSET 4
  853. jmp error_code
  854. CFI_ENDPROC
  855. END(bounds)
  856. ENTRY(invalid_op)
  857. RING0_INT_FRAME
  858. pushl $0
  859. CFI_ADJUST_CFA_OFFSET 4
  860. pushl $do_invalid_op
  861. CFI_ADJUST_CFA_OFFSET 4
  862. jmp error_code
  863. CFI_ENDPROC
  864. END(invalid_op)
  865. ENTRY(coprocessor_segment_overrun)
  866. RING0_INT_FRAME
  867. pushl $0
  868. CFI_ADJUST_CFA_OFFSET 4
  869. pushl $do_coprocessor_segment_overrun
  870. CFI_ADJUST_CFA_OFFSET 4
  871. jmp error_code
  872. CFI_ENDPROC
  873. END(coprocessor_segment_overrun)
  874. ENTRY(invalid_TSS)
  875. RING0_EC_FRAME
  876. pushl $do_invalid_TSS
  877. CFI_ADJUST_CFA_OFFSET 4
  878. jmp error_code
  879. CFI_ENDPROC
  880. END(invalid_TSS)
  881. ENTRY(segment_not_present)
  882. RING0_EC_FRAME
  883. pushl $do_segment_not_present
  884. CFI_ADJUST_CFA_OFFSET 4
  885. jmp error_code
  886. CFI_ENDPROC
  887. END(segment_not_present)
  888. ENTRY(stack_segment)
  889. RING0_EC_FRAME
  890. pushl $do_stack_segment
  891. CFI_ADJUST_CFA_OFFSET 4
  892. jmp error_code
  893. CFI_ENDPROC
  894. END(stack_segment)
  895. KPROBE_ENTRY(general_protection)
  896. RING0_EC_FRAME
  897. pushl $do_general_protection
  898. CFI_ADJUST_CFA_OFFSET 4
  899. jmp error_code
  900. CFI_ENDPROC
  901. KPROBE_END(general_protection)
  902. ENTRY(alignment_check)
  903. RING0_EC_FRAME
  904. pushl $do_alignment_check
  905. CFI_ADJUST_CFA_OFFSET 4
  906. jmp error_code
  907. CFI_ENDPROC
  908. END(alignment_check)
  909. ENTRY(divide_error)
  910. RING0_INT_FRAME
  911. pushl $0 # no error code
  912. CFI_ADJUST_CFA_OFFSET 4
  913. pushl $do_divide_error
  914. CFI_ADJUST_CFA_OFFSET 4
  915. jmp error_code
  916. CFI_ENDPROC
  917. END(divide_error)
  918. #ifdef CONFIG_X86_MCE
  919. ENTRY(machine_check)
  920. RING0_INT_FRAME
  921. pushl $0
  922. CFI_ADJUST_CFA_OFFSET 4
  923. pushl machine_check_vector
  924. CFI_ADJUST_CFA_OFFSET 4
  925. jmp error_code
  926. CFI_ENDPROC
  927. END(machine_check)
  928. #endif
  929. ENTRY(spurious_interrupt_bug)
  930. RING0_INT_FRAME
  931. pushl $0
  932. CFI_ADJUST_CFA_OFFSET 4
  933. pushl $do_spurious_interrupt_bug
  934. CFI_ADJUST_CFA_OFFSET 4
  935. jmp error_code
  936. CFI_ENDPROC
  937. END(spurious_interrupt_bug)
  938. ENTRY(kernel_thread_helper)
  939. pushl $0 # fake return address for unwinder
  940. CFI_STARTPROC
  941. movl %edx,%eax
  942. push %edx
  943. CFI_ADJUST_CFA_OFFSET 4
  944. call *%ebx
  945. push %eax
  946. CFI_ADJUST_CFA_OFFSET 4
  947. call do_exit
  948. CFI_ENDPROC
  949. ENDPROC(kernel_thread_helper)
  950. #ifdef CONFIG_XEN
  951. ENTRY(xen_hypervisor_callback)
  952. CFI_STARTPROC
  953. pushl $0
  954. CFI_ADJUST_CFA_OFFSET 4
  955. SAVE_ALL
  956. TRACE_IRQS_OFF
  957. /* Check to see if we got the event in the critical
  958. region in xen_iret_direct, after we've reenabled
  959. events and checked for pending events. This simulates
  960. iret instruction's behaviour where it delivers a
  961. pending interrupt when enabling interrupts. */
  962. movl PT_EIP(%esp),%eax
  963. cmpl $xen_iret_start_crit,%eax
  964. jb 1f
  965. cmpl $xen_iret_end_crit,%eax
  966. jae 1f
  967. call xen_iret_crit_fixup
  968. 1: mov %esp, %eax
  969. call xen_evtchn_do_upcall
  970. jmp ret_from_intr
  971. CFI_ENDPROC
  972. ENDPROC(xen_hypervisor_callback)
  973. # Hypervisor uses this for application faults while it executes.
  974. # We get here for two reasons:
  975. # 1. Fault while reloading DS, ES, FS or GS
  976. # 2. Fault while executing IRET
  977. # Category 1 we fix up by reattempting the load, and zeroing the segment
  978. # register if the load fails.
  979. # Category 2 we fix up by jumping to do_iret_error. We cannot use the
  980. # normal Linux return path in this case because if we use the IRET hypercall
  981. # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
  982. # We distinguish between categories by maintaining a status value in EAX.
  983. ENTRY(xen_failsafe_callback)
  984. CFI_STARTPROC
  985. pushl %eax
  986. CFI_ADJUST_CFA_OFFSET 4
  987. movl $1,%eax
  988. 1: mov 4(%esp),%ds
  989. 2: mov 8(%esp),%es
  990. 3: mov 12(%esp),%fs
  991. 4: mov 16(%esp),%gs
  992. testl %eax,%eax
  993. popl %eax
  994. CFI_ADJUST_CFA_OFFSET -4
  995. lea 16(%esp),%esp
  996. CFI_ADJUST_CFA_OFFSET -16
  997. jz 5f
  998. addl $16,%esp
  999. jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
  1000. 5: pushl $0 # EAX == 0 => Category 1 (Bad segment)
  1001. CFI_ADJUST_CFA_OFFSET 4
  1002. SAVE_ALL
  1003. jmp ret_from_exception
  1004. CFI_ENDPROC
  1005. .section .fixup,"ax"
  1006. 6: xorl %eax,%eax
  1007. movl %eax,4(%esp)
  1008. jmp 1b
  1009. 7: xorl %eax,%eax
  1010. movl %eax,8(%esp)
  1011. jmp 2b
  1012. 8: xorl %eax,%eax
  1013. movl %eax,12(%esp)
  1014. jmp 3b
  1015. 9: xorl %eax,%eax
  1016. movl %eax,16(%esp)
  1017. jmp 4b
  1018. .previous
  1019. .section __ex_table,"a"
  1020. .align 4
  1021. .long 1b,6b
  1022. .long 2b,7b
  1023. .long 3b,8b
  1024. .long 4b,9b
  1025. .previous
  1026. ENDPROC(xen_failsafe_callback)
  1027. #endif /* CONFIG_XEN */
  1028. .section .rodata,"a"
  1029. #include "syscall_table_32.S"
  1030. syscall_table_size=(.-sys_call_table)