entry.S 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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 'ret_from_system_call':
  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_SYSEXIT (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_PDA), %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. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  237. # setting need_resched or sigpending
  238. # between sampling and the iret
  239. movl TI_flags(%ebp), %ecx
  240. andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
  241. # int/exception return?
  242. jne work_pending
  243. jmp restore_all
  244. END(ret_from_exception)
  245. #ifdef CONFIG_PREEMPT
  246. ENTRY(resume_kernel)
  247. DISABLE_INTERRUPTS(CLBR_ANY)
  248. cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
  249. jnz restore_nocheck
  250. need_resched:
  251. movl TI_flags(%ebp), %ecx # need_resched set ?
  252. testb $_TIF_NEED_RESCHED, %cl
  253. jz restore_all
  254. testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off (exception path) ?
  255. jz restore_all
  256. call preempt_schedule_irq
  257. jmp need_resched
  258. END(resume_kernel)
  259. #endif
  260. CFI_ENDPROC
  261. /* SYSENTER_RETURN points to after the "sysenter" instruction in
  262. the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
  263. # sysenter call handler stub
  264. ENTRY(sysenter_entry)
  265. CFI_STARTPROC simple
  266. CFI_SIGNAL_FRAME
  267. CFI_DEF_CFA esp, 0
  268. CFI_REGISTER esp, ebp
  269. movl TSS_sysenter_esp0(%esp),%esp
  270. sysenter_past_esp:
  271. /*
  272. * No need to follow this irqs on/off section: the syscall
  273. * disabled irqs and here we enable it straight after entry:
  274. */
  275. ENABLE_INTERRUPTS(CLBR_NONE)
  276. pushl $(__USER_DS)
  277. CFI_ADJUST_CFA_OFFSET 4
  278. /*CFI_REL_OFFSET ss, 0*/
  279. pushl %ebp
  280. CFI_ADJUST_CFA_OFFSET 4
  281. CFI_REL_OFFSET esp, 0
  282. pushfl
  283. CFI_ADJUST_CFA_OFFSET 4
  284. pushl $(__USER_CS)
  285. CFI_ADJUST_CFA_OFFSET 4
  286. /*CFI_REL_OFFSET cs, 0*/
  287. #ifndef CONFIG_COMPAT_VDSO
  288. /*
  289. * Push current_thread_info()->sysenter_return to the stack.
  290. * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
  291. * pushed above; +8 corresponds to copy_thread's esp0 setting.
  292. */
  293. pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
  294. #else
  295. pushl $SYSENTER_RETURN
  296. #endif
  297. CFI_ADJUST_CFA_OFFSET 4
  298. CFI_REL_OFFSET eip, 0
  299. /*
  300. * Load the potential sixth argument from user stack.
  301. * Careful about security.
  302. */
  303. cmpl $__PAGE_OFFSET-3,%ebp
  304. jae syscall_fault
  305. 1: movl (%ebp),%ebp
  306. .section __ex_table,"a"
  307. .align 4
  308. .long 1b,syscall_fault
  309. .previous
  310. pushl %eax
  311. CFI_ADJUST_CFA_OFFSET 4
  312. SAVE_ALL
  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. DISABLE_INTERRUPTS(CLBR_ECX|CLBR_EDX)
  322. TRACE_IRQS_OFF
  323. movl TI_flags(%ebp), %ecx
  324. testw $_TIF_ALLWORK_MASK, %cx
  325. jne syscall_exit_work
  326. /* if something modifies registers it must also disable sysexit */
  327. movl PT_EIP(%esp), %edx
  328. movl PT_OLDESP(%esp), %ecx
  329. xorl %ebp,%ebp
  330. TRACE_IRQS_ON
  331. 1: mov PT_FS(%esp), %fs
  332. ENABLE_INTERRUPTS_SYSEXIT
  333. CFI_ENDPROC
  334. .pushsection .fixup,"ax"
  335. 2: movl $0,PT_FS(%esp)
  336. jmp 1b
  337. .section __ex_table,"a"
  338. .align 4
  339. .long 1b,2b
  340. .popsection
  341. ENDPROC(sysenter_entry)
  342. # system call handler stub
  343. ENTRY(system_call)
  344. RING0_INT_FRAME # can't unwind into user space anyway
  345. pushl %eax # save orig_eax
  346. CFI_ADJUST_CFA_OFFSET 4
  347. SAVE_ALL
  348. GET_THREAD_INFO(%ebp)
  349. testl $TF_MASK,PT_EFLAGS(%esp)
  350. jz no_singlestep
  351. orl $_TIF_SINGLESTEP,TI_flags(%ebp)
  352. no_singlestep:
  353. # system call tracing in operation / emulation
  354. /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
  355. testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  356. jnz syscall_trace_entry
  357. cmpl $(nr_syscalls), %eax
  358. jae syscall_badsys
  359. syscall_call:
  360. call *sys_call_table(,%eax,4)
  361. movl %eax,PT_EAX(%esp) # store the return value
  362. syscall_exit:
  363. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  364. # setting need_resched or sigpending
  365. # between sampling and the iret
  366. TRACE_IRQS_OFF
  367. movl TI_flags(%ebp), %ecx
  368. testw $_TIF_ALLWORK_MASK, %cx # current->work
  369. jne syscall_exit_work
  370. restore_all:
  371. movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
  372. # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
  373. # are returning to the kernel.
  374. # See comments in process.c:copy_thread() for details.
  375. movb PT_OLDSS(%esp), %ah
  376. movb PT_CS(%esp), %al
  377. andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
  378. cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
  379. CFI_REMEMBER_STATE
  380. je ldt_ss # returning to user-space with LDT SS
  381. restore_nocheck:
  382. TRACE_IRQS_IRET
  383. restore_nocheck_notrace:
  384. RESTORE_REGS
  385. addl $4, %esp # skip orig_eax/error_code
  386. CFI_ADJUST_CFA_OFFSET -4
  387. 1: INTERRUPT_RETURN
  388. .section .fixup,"ax"
  389. iret_exc:
  390. TRACE_IRQS_ON
  391. ENABLE_INTERRUPTS(CLBR_NONE)
  392. pushl $0 # no error code
  393. pushl $do_iret_error
  394. jmp error_code
  395. .previous
  396. .section __ex_table,"a"
  397. .align 4
  398. .long 1b,iret_exc
  399. .previous
  400. CFI_RESTORE_STATE
  401. ldt_ss:
  402. larl PT_OLDSS(%esp), %eax
  403. jnz restore_nocheck
  404. testl $0x00400000, %eax # returning to 32bit stack?
  405. jnz restore_nocheck # allright, normal return
  406. #ifdef CONFIG_PARAVIRT
  407. /*
  408. * The kernel can't run on a non-flat stack if paravirt mode
  409. * is active. Rather than try to fixup the high bits of
  410. * ESP, bypass this code entirely. This may break DOSemu
  411. * and/or Wine support in a paravirt VM, although the option
  412. * is still available to implement the setting of the high
  413. * 16-bits in the INTERRUPT_RETURN paravirt-op.
  414. */
  415. cmpl $0, paravirt_ops+PARAVIRT_enabled
  416. jne restore_nocheck
  417. #endif
  418. /* If returning to userspace with 16bit stack,
  419. * try to fix the higher word of ESP, as the CPU
  420. * won't restore it.
  421. * This is an "official" bug of all the x86-compatible
  422. * CPUs, which we can try to work around to make
  423. * dosemu and wine happy. */
  424. movl PT_OLDESP(%esp), %eax
  425. movl %esp, %edx
  426. call patch_espfix_desc
  427. pushl $__ESPFIX_SS
  428. CFI_ADJUST_CFA_OFFSET 4
  429. pushl %eax
  430. CFI_ADJUST_CFA_OFFSET 4
  431. DISABLE_INTERRUPTS(CLBR_EAX)
  432. TRACE_IRQS_OFF
  433. lss (%esp), %esp
  434. CFI_ADJUST_CFA_OFFSET -8
  435. jmp restore_nocheck
  436. CFI_ENDPROC
  437. ENDPROC(system_call)
  438. # perform work that needs to be done immediately before resumption
  439. ALIGN
  440. RING0_PTREGS_FRAME # can't unwind into user space anyway
  441. work_pending:
  442. testb $_TIF_NEED_RESCHED, %cl
  443. jz work_notifysig
  444. work_resched:
  445. call schedule
  446. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  447. # setting need_resched or sigpending
  448. # between sampling and the iret
  449. TRACE_IRQS_OFF
  450. movl TI_flags(%ebp), %ecx
  451. andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
  452. # than syscall tracing?
  453. jz restore_all
  454. testb $_TIF_NEED_RESCHED, %cl
  455. jnz work_resched
  456. work_notifysig: # deal with pending signals and
  457. # notify-resume requests
  458. #ifdef CONFIG_VM86
  459. testl $VM_MASK, PT_EFLAGS(%esp)
  460. movl %esp, %eax
  461. jne work_notifysig_v86 # returning to kernel-space or
  462. # vm86-space
  463. xorl %edx, %edx
  464. call do_notify_resume
  465. jmp resume_userspace_sig
  466. ALIGN
  467. work_notifysig_v86:
  468. pushl %ecx # save ti_flags for do_notify_resume
  469. CFI_ADJUST_CFA_OFFSET 4
  470. call save_v86_state # %eax contains pt_regs pointer
  471. popl %ecx
  472. CFI_ADJUST_CFA_OFFSET -4
  473. movl %eax, %esp
  474. #else
  475. movl %esp, %eax
  476. #endif
  477. xorl %edx, %edx
  478. call do_notify_resume
  479. jmp resume_userspace_sig
  480. END(work_pending)
  481. # perform syscall exit tracing
  482. ALIGN
  483. syscall_trace_entry:
  484. movl $-ENOSYS,PT_EAX(%esp)
  485. movl %esp, %eax
  486. xorl %edx,%edx
  487. call do_syscall_trace
  488. cmpl $0, %eax
  489. jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
  490. # so must skip actual syscall
  491. movl PT_ORIG_EAX(%esp), %eax
  492. cmpl $(nr_syscalls), %eax
  493. jnae syscall_call
  494. jmp syscall_exit
  495. END(syscall_trace_entry)
  496. # perform syscall exit tracing
  497. ALIGN
  498. syscall_exit_work:
  499. testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
  500. jz work_pending
  501. TRACE_IRQS_ON
  502. ENABLE_INTERRUPTS(CLBR_ANY) # could let do_syscall_trace() call
  503. # schedule() instead
  504. movl %esp, %eax
  505. movl $1, %edx
  506. call do_syscall_trace
  507. jmp resume_userspace
  508. END(syscall_exit_work)
  509. CFI_ENDPROC
  510. RING0_INT_FRAME # can't unwind into user space anyway
  511. syscall_fault:
  512. pushl %eax # save orig_eax
  513. CFI_ADJUST_CFA_OFFSET 4
  514. SAVE_ALL
  515. GET_THREAD_INFO(%ebp)
  516. movl $-EFAULT,PT_EAX(%esp)
  517. jmp resume_userspace
  518. END(syscall_fault)
  519. syscall_badsys:
  520. movl $-ENOSYS,PT_EAX(%esp)
  521. jmp resume_userspace
  522. END(syscall_badsys)
  523. CFI_ENDPROC
  524. #define FIXUP_ESPFIX_STACK \
  525. /* since we are on a wrong stack, we cant make it a C code :( */ \
  526. movl %fs:PDA_cpu, %ebx; \
  527. PER_CPU(cpu_gdt, %ebx); \
  528. GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
  529. addl %esp, %eax; \
  530. pushl $__KERNEL_DS; \
  531. CFI_ADJUST_CFA_OFFSET 4; \
  532. pushl %eax; \
  533. CFI_ADJUST_CFA_OFFSET 4; \
  534. lss (%esp), %esp; \
  535. CFI_ADJUST_CFA_OFFSET -8;
  536. #define UNWIND_ESPFIX_STACK \
  537. movl %ss, %eax; \
  538. /* see if on espfix stack */ \
  539. cmpw $__ESPFIX_SS, %ax; \
  540. jne 27f; \
  541. movl $__KERNEL_DS, %eax; \
  542. movl %eax, %ds; \
  543. movl %eax, %es; \
  544. /* switch to normal stack */ \
  545. FIXUP_ESPFIX_STACK; \
  546. 27:;
  547. /*
  548. * Build the entry stubs and pointer table with
  549. * some assembler magic.
  550. */
  551. .data
  552. ENTRY(interrupt)
  553. .text
  554. ENTRY(irq_entries_start)
  555. RING0_INT_FRAME
  556. vector=0
  557. .rept NR_IRQS
  558. ALIGN
  559. .if vector
  560. CFI_ADJUST_CFA_OFFSET -4
  561. .endif
  562. 1: pushl $~(vector)
  563. CFI_ADJUST_CFA_OFFSET 4
  564. jmp common_interrupt
  565. .previous
  566. .long 1b
  567. .text
  568. vector=vector+1
  569. .endr
  570. END(irq_entries_start)
  571. .previous
  572. END(interrupt)
  573. .previous
  574. /*
  575. * the CPU automatically disables interrupts when executing an IRQ vector,
  576. * so IRQ-flags tracing has to follow that:
  577. */
  578. ALIGN
  579. common_interrupt:
  580. SAVE_ALL
  581. TRACE_IRQS_OFF
  582. movl %esp,%eax
  583. call do_IRQ
  584. jmp ret_from_intr
  585. ENDPROC(common_interrupt)
  586. CFI_ENDPROC
  587. #define BUILD_INTERRUPT(name, nr) \
  588. ENTRY(name) \
  589. RING0_INT_FRAME; \
  590. pushl $~(nr); \
  591. CFI_ADJUST_CFA_OFFSET 4; \
  592. SAVE_ALL; \
  593. TRACE_IRQS_OFF \
  594. movl %esp,%eax; \
  595. call smp_##name; \
  596. jmp ret_from_intr; \
  597. CFI_ENDPROC; \
  598. ENDPROC(name)
  599. /* The include is where all of the SMP etc. interrupts come from */
  600. #include "entry_arch.h"
  601. /* This alternate entry is needed because we hijack the apic LVTT */
  602. #if defined(CONFIG_VMI) && defined(CONFIG_X86_LOCAL_APIC)
  603. BUILD_INTERRUPT(apic_vmi_timer_interrupt,LOCAL_TIMER_VECTOR)
  604. #endif
  605. KPROBE_ENTRY(page_fault)
  606. RING0_EC_FRAME
  607. pushl $do_page_fault
  608. CFI_ADJUST_CFA_OFFSET 4
  609. ALIGN
  610. error_code:
  611. /* the function address is in %fs's slot on the stack */
  612. pushl %es
  613. CFI_ADJUST_CFA_OFFSET 4
  614. /*CFI_REL_OFFSET es, 0*/
  615. pushl %ds
  616. CFI_ADJUST_CFA_OFFSET 4
  617. /*CFI_REL_OFFSET ds, 0*/
  618. pushl %eax
  619. CFI_ADJUST_CFA_OFFSET 4
  620. CFI_REL_OFFSET eax, 0
  621. pushl %ebp
  622. CFI_ADJUST_CFA_OFFSET 4
  623. CFI_REL_OFFSET ebp, 0
  624. pushl %edi
  625. CFI_ADJUST_CFA_OFFSET 4
  626. CFI_REL_OFFSET edi, 0
  627. pushl %esi
  628. CFI_ADJUST_CFA_OFFSET 4
  629. CFI_REL_OFFSET esi, 0
  630. pushl %edx
  631. CFI_ADJUST_CFA_OFFSET 4
  632. CFI_REL_OFFSET edx, 0
  633. pushl %ecx
  634. CFI_ADJUST_CFA_OFFSET 4
  635. CFI_REL_OFFSET ecx, 0
  636. pushl %ebx
  637. CFI_ADJUST_CFA_OFFSET 4
  638. CFI_REL_OFFSET ebx, 0
  639. cld
  640. pushl %fs
  641. CFI_ADJUST_CFA_OFFSET 4
  642. /*CFI_REL_OFFSET fs, 0*/
  643. movl $(__KERNEL_PDA), %ecx
  644. movl %ecx, %fs
  645. UNWIND_ESPFIX_STACK
  646. popl %ecx
  647. CFI_ADJUST_CFA_OFFSET -4
  648. /*CFI_REGISTER es, ecx*/
  649. movl PT_FS(%esp), %edi # get the function address
  650. movl PT_ORIG_EAX(%esp), %edx # get the error code
  651. movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
  652. mov %ecx, PT_FS(%esp)
  653. /*CFI_REL_OFFSET fs, ES*/
  654. movl $(__USER_DS), %ecx
  655. movl %ecx, %ds
  656. movl %ecx, %es
  657. movl %esp,%eax # pt_regs pointer
  658. call *%edi
  659. jmp ret_from_exception
  660. CFI_ENDPROC
  661. KPROBE_END(page_fault)
  662. ENTRY(coprocessor_error)
  663. RING0_INT_FRAME
  664. pushl $0
  665. CFI_ADJUST_CFA_OFFSET 4
  666. pushl $do_coprocessor_error
  667. CFI_ADJUST_CFA_OFFSET 4
  668. jmp error_code
  669. CFI_ENDPROC
  670. END(coprocessor_error)
  671. ENTRY(simd_coprocessor_error)
  672. RING0_INT_FRAME
  673. pushl $0
  674. CFI_ADJUST_CFA_OFFSET 4
  675. pushl $do_simd_coprocessor_error
  676. CFI_ADJUST_CFA_OFFSET 4
  677. jmp error_code
  678. CFI_ENDPROC
  679. END(simd_coprocessor_error)
  680. ENTRY(device_not_available)
  681. RING0_INT_FRAME
  682. pushl $-1 # mark this as an int
  683. CFI_ADJUST_CFA_OFFSET 4
  684. SAVE_ALL
  685. GET_CR0_INTO_EAX
  686. testl $0x4, %eax # EM (math emulation bit)
  687. jne device_not_available_emulate
  688. preempt_stop(CLBR_ANY)
  689. call math_state_restore
  690. jmp ret_from_exception
  691. device_not_available_emulate:
  692. pushl $0 # temporary storage for ORIG_EIP
  693. CFI_ADJUST_CFA_OFFSET 4
  694. call math_emulate
  695. addl $4, %esp
  696. CFI_ADJUST_CFA_OFFSET -4
  697. jmp ret_from_exception
  698. CFI_ENDPROC
  699. END(device_not_available)
  700. /*
  701. * Debug traps and NMI can happen at the one SYSENTER instruction
  702. * that sets up the real kernel stack. Check here, since we can't
  703. * allow the wrong stack to be used.
  704. *
  705. * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
  706. * already pushed 3 words if it hits on the sysenter instruction:
  707. * eflags, cs and eip.
  708. *
  709. * We just load the right stack, and push the three (known) values
  710. * by hand onto the new stack - while updating the return eip past
  711. * the instruction that would have done it for sysenter.
  712. */
  713. #define FIX_STACK(offset, ok, label) \
  714. cmpw $__KERNEL_CS,4(%esp); \
  715. jne ok; \
  716. label: \
  717. movl TSS_sysenter_esp0+offset(%esp),%esp; \
  718. CFI_DEF_CFA esp, 0; \
  719. CFI_UNDEFINED eip; \
  720. pushfl; \
  721. CFI_ADJUST_CFA_OFFSET 4; \
  722. pushl $__KERNEL_CS; \
  723. CFI_ADJUST_CFA_OFFSET 4; \
  724. pushl $sysenter_past_esp; \
  725. CFI_ADJUST_CFA_OFFSET 4; \
  726. CFI_REL_OFFSET eip, 0
  727. KPROBE_ENTRY(debug)
  728. RING0_INT_FRAME
  729. cmpl $sysenter_entry,(%esp)
  730. jne debug_stack_correct
  731. FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
  732. debug_stack_correct:
  733. pushl $-1 # mark this as an int
  734. CFI_ADJUST_CFA_OFFSET 4
  735. SAVE_ALL
  736. xorl %edx,%edx # error code 0
  737. movl %esp,%eax # pt_regs pointer
  738. call do_debug
  739. jmp ret_from_exception
  740. CFI_ENDPROC
  741. KPROBE_END(debug)
  742. /*
  743. * NMI is doubly nasty. It can happen _while_ we're handling
  744. * a debug fault, and the debug fault hasn't yet been able to
  745. * clear up the stack. So we first check whether we got an
  746. * NMI on the sysenter entry path, but after that we need to
  747. * check whether we got an NMI on the debug path where the debug
  748. * fault happened on the sysenter path.
  749. */
  750. KPROBE_ENTRY(nmi)
  751. RING0_INT_FRAME
  752. pushl %eax
  753. CFI_ADJUST_CFA_OFFSET 4
  754. movl %ss, %eax
  755. cmpw $__ESPFIX_SS, %ax
  756. popl %eax
  757. CFI_ADJUST_CFA_OFFSET -4
  758. je nmi_espfix_stack
  759. cmpl $sysenter_entry,(%esp)
  760. je nmi_stack_fixup
  761. pushl %eax
  762. CFI_ADJUST_CFA_OFFSET 4
  763. movl %esp,%eax
  764. /* Do not access memory above the end of our stack page,
  765. * it might not exist.
  766. */
  767. andl $(THREAD_SIZE-1),%eax
  768. cmpl $(THREAD_SIZE-20),%eax
  769. popl %eax
  770. CFI_ADJUST_CFA_OFFSET -4
  771. jae nmi_stack_correct
  772. cmpl $sysenter_entry,12(%esp)
  773. je nmi_debug_stack_check
  774. nmi_stack_correct:
  775. /* We have a RING0_INT_FRAME here */
  776. pushl %eax
  777. CFI_ADJUST_CFA_OFFSET 4
  778. SAVE_ALL
  779. xorl %edx,%edx # zero error code
  780. movl %esp,%eax # pt_regs pointer
  781. call do_nmi
  782. jmp restore_nocheck_notrace
  783. CFI_ENDPROC
  784. nmi_stack_fixup:
  785. RING0_INT_FRAME
  786. FIX_STACK(12,nmi_stack_correct, 1)
  787. jmp nmi_stack_correct
  788. nmi_debug_stack_check:
  789. /* We have a RING0_INT_FRAME here */
  790. cmpw $__KERNEL_CS,16(%esp)
  791. jne nmi_stack_correct
  792. cmpl $debug,(%esp)
  793. jb nmi_stack_correct
  794. cmpl $debug_esp_fix_insn,(%esp)
  795. ja nmi_stack_correct
  796. FIX_STACK(24,nmi_stack_correct, 1)
  797. jmp nmi_stack_correct
  798. nmi_espfix_stack:
  799. /* We have a RING0_INT_FRAME here.
  800. *
  801. * create the pointer to lss back
  802. */
  803. pushl %ss
  804. CFI_ADJUST_CFA_OFFSET 4
  805. pushl %esp
  806. CFI_ADJUST_CFA_OFFSET 4
  807. addw $4, (%esp)
  808. /* copy the iret frame of 12 bytes */
  809. .rept 3
  810. pushl 16(%esp)
  811. CFI_ADJUST_CFA_OFFSET 4
  812. .endr
  813. pushl %eax
  814. CFI_ADJUST_CFA_OFFSET 4
  815. SAVE_ALL
  816. FIXUP_ESPFIX_STACK # %eax == %esp
  817. xorl %edx,%edx # zero error code
  818. call do_nmi
  819. RESTORE_REGS
  820. lss 12+4(%esp), %esp # back to espfix stack
  821. CFI_ADJUST_CFA_OFFSET -24
  822. 1: INTERRUPT_RETURN
  823. CFI_ENDPROC
  824. .section __ex_table,"a"
  825. .align 4
  826. .long 1b,iret_exc
  827. .previous
  828. KPROBE_END(nmi)
  829. #ifdef CONFIG_PARAVIRT
  830. ENTRY(native_iret)
  831. 1: iret
  832. .section __ex_table,"a"
  833. .align 4
  834. .long 1b,iret_exc
  835. .previous
  836. END(native_iret)
  837. ENTRY(native_irq_enable_sysexit)
  838. sti
  839. sysexit
  840. END(native_irq_enable_sysexit)
  841. #endif
  842. KPROBE_ENTRY(int3)
  843. RING0_INT_FRAME
  844. pushl $-1 # mark this as an int
  845. CFI_ADJUST_CFA_OFFSET 4
  846. SAVE_ALL
  847. xorl %edx,%edx # zero error code
  848. movl %esp,%eax # pt_regs pointer
  849. call do_int3
  850. jmp ret_from_exception
  851. CFI_ENDPROC
  852. KPROBE_END(int3)
  853. ENTRY(overflow)
  854. RING0_INT_FRAME
  855. pushl $0
  856. CFI_ADJUST_CFA_OFFSET 4
  857. pushl $do_overflow
  858. CFI_ADJUST_CFA_OFFSET 4
  859. jmp error_code
  860. CFI_ENDPROC
  861. END(overflow)
  862. ENTRY(bounds)
  863. RING0_INT_FRAME
  864. pushl $0
  865. CFI_ADJUST_CFA_OFFSET 4
  866. pushl $do_bounds
  867. CFI_ADJUST_CFA_OFFSET 4
  868. jmp error_code
  869. CFI_ENDPROC
  870. END(bounds)
  871. ENTRY(invalid_op)
  872. RING0_INT_FRAME
  873. pushl $0
  874. CFI_ADJUST_CFA_OFFSET 4
  875. pushl $do_invalid_op
  876. CFI_ADJUST_CFA_OFFSET 4
  877. jmp error_code
  878. CFI_ENDPROC
  879. END(invalid_op)
  880. ENTRY(coprocessor_segment_overrun)
  881. RING0_INT_FRAME
  882. pushl $0
  883. CFI_ADJUST_CFA_OFFSET 4
  884. pushl $do_coprocessor_segment_overrun
  885. CFI_ADJUST_CFA_OFFSET 4
  886. jmp error_code
  887. CFI_ENDPROC
  888. END(coprocessor_segment_overrun)
  889. ENTRY(invalid_TSS)
  890. RING0_EC_FRAME
  891. pushl $do_invalid_TSS
  892. CFI_ADJUST_CFA_OFFSET 4
  893. jmp error_code
  894. CFI_ENDPROC
  895. END(invalid_TSS)
  896. ENTRY(segment_not_present)
  897. RING0_EC_FRAME
  898. pushl $do_segment_not_present
  899. CFI_ADJUST_CFA_OFFSET 4
  900. jmp error_code
  901. CFI_ENDPROC
  902. END(segment_not_present)
  903. ENTRY(stack_segment)
  904. RING0_EC_FRAME
  905. pushl $do_stack_segment
  906. CFI_ADJUST_CFA_OFFSET 4
  907. jmp error_code
  908. CFI_ENDPROC
  909. END(stack_segment)
  910. KPROBE_ENTRY(general_protection)
  911. RING0_EC_FRAME
  912. pushl $do_general_protection
  913. CFI_ADJUST_CFA_OFFSET 4
  914. jmp error_code
  915. CFI_ENDPROC
  916. KPROBE_END(general_protection)
  917. ENTRY(alignment_check)
  918. RING0_EC_FRAME
  919. pushl $do_alignment_check
  920. CFI_ADJUST_CFA_OFFSET 4
  921. jmp error_code
  922. CFI_ENDPROC
  923. END(alignment_check)
  924. ENTRY(divide_error)
  925. RING0_INT_FRAME
  926. pushl $0 # no error code
  927. CFI_ADJUST_CFA_OFFSET 4
  928. pushl $do_divide_error
  929. CFI_ADJUST_CFA_OFFSET 4
  930. jmp error_code
  931. CFI_ENDPROC
  932. END(divide_error)
  933. #ifdef CONFIG_X86_MCE
  934. ENTRY(machine_check)
  935. RING0_INT_FRAME
  936. pushl $0
  937. CFI_ADJUST_CFA_OFFSET 4
  938. pushl machine_check_vector
  939. CFI_ADJUST_CFA_OFFSET 4
  940. jmp error_code
  941. CFI_ENDPROC
  942. END(machine_check)
  943. #endif
  944. ENTRY(spurious_interrupt_bug)
  945. RING0_INT_FRAME
  946. pushl $0
  947. CFI_ADJUST_CFA_OFFSET 4
  948. pushl $do_spurious_interrupt_bug
  949. CFI_ADJUST_CFA_OFFSET 4
  950. jmp error_code
  951. CFI_ENDPROC
  952. END(spurious_interrupt_bug)
  953. ENTRY(kernel_thread_helper)
  954. pushl $0 # fake return address for unwinder
  955. CFI_STARTPROC
  956. movl %edx,%eax
  957. push %edx
  958. CFI_ADJUST_CFA_OFFSET 4
  959. call *%ebx
  960. push %eax
  961. CFI_ADJUST_CFA_OFFSET 4
  962. call do_exit
  963. CFI_ENDPROC
  964. ENDPROC(kernel_thread_helper)
  965. .section .rodata,"a"
  966. #include "syscall_table.S"
  967. syscall_table_size=(.-sys_call_table)