entry.S 24 KB

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