entry.S 26 KB

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