entry_32.S 26 KB

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