entry.S 23 KB

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