entry_32.S 26 KB

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