entry.S 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. /*
  2. * linux/arch/i386/entry.S
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /*
  7. * entry.S contains the system-call and fault low-level handling routines.
  8. * This also contains the timer-interrupt handler, as well as all interrupts
  9. * and faults that can result in a task-switch.
  10. *
  11. * NOTE: This code handles signal-recognition, which happens every time
  12. * after a timer-interrupt and after each system call.
  13. *
  14. * I changed all the .align's to 4 (16 byte alignment), as that's faster
  15. * on a 486.
  16. *
  17. * Stack layout in 'ret_from_system_call':
  18. * ptrace needs to have all regs on the stack.
  19. * if the order here is changed, it needs to be
  20. * updated in fork.c:copy_process, signal.c:do_signal,
  21. * ptrace.c and ptrace.h
  22. *
  23. * 0(%esp) - %ebx
  24. * 4(%esp) - %ecx
  25. * 8(%esp) - %edx
  26. * C(%esp) - %esi
  27. * 10(%esp) - %edi
  28. * 14(%esp) - %ebp
  29. * 18(%esp) - %eax
  30. * 1C(%esp) - %ds
  31. * 20(%esp) - %es
  32. * 24(%esp) - %fs
  33. * 28(%esp) - orig_eax
  34. * 2C(%esp) - %eip
  35. * 30(%esp) - %cs
  36. * 34(%esp) - %eflags
  37. * 38(%esp) - %oldesp
  38. * 3C(%esp) - %oldss
  39. *
  40. * "current" is in register %ebx during any slow entries.
  41. */
  42. #include <linux/linkage.h>
  43. #include <asm/thread_info.h>
  44. #include <asm/irqflags.h>
  45. #include <asm/errno.h>
  46. #include <asm/segment.h>
  47. #include <asm/smp.h>
  48. #include <asm/page.h>
  49. #include <asm/desc.h>
  50. #include <asm/percpu.h>
  51. #include <asm/dwarf2.h>
  52. #include "irq_vectors.h"
  53. /*
  54. * We use macros for low-level operations which need to be overridden
  55. * for paravirtualization. The following will never clobber any registers:
  56. * INTERRUPT_RETURN (aka. "iret")
  57. * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
  58. * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
  59. *
  60. * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
  61. * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
  62. * Allowing a register to be clobbered can shrink the paravirt replacement
  63. * enough to patch inline, increasing performance.
  64. */
  65. #define nr_syscalls ((syscall_table_size)/4)
  66. CF_MASK = 0x00000001
  67. TF_MASK = 0x00000100
  68. IF_MASK = 0x00000200
  69. DF_MASK = 0x00000400
  70. NT_MASK = 0x00004000
  71. VM_MASK = 0x00020000
  72. #ifdef CONFIG_PREEMPT
  73. #define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
  74. #else
  75. #define preempt_stop(clobbers)
  76. #define resume_kernel restore_nocheck
  77. #endif
  78. .macro TRACE_IRQS_IRET
  79. #ifdef CONFIG_TRACE_IRQFLAGS
  80. testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off?
  81. jz 1f
  82. TRACE_IRQS_ON
  83. 1:
  84. #endif
  85. .endm
  86. #ifdef CONFIG_VM86
  87. #define resume_userspace_sig check_userspace
  88. #else
  89. #define resume_userspace_sig resume_userspace
  90. #endif
  91. #define SAVE_ALL \
  92. cld; \
  93. pushl %fs; \
  94. CFI_ADJUST_CFA_OFFSET 4;\
  95. /*CFI_REL_OFFSET fs, 0;*/\
  96. pushl %es; \
  97. CFI_ADJUST_CFA_OFFSET 4;\
  98. /*CFI_REL_OFFSET es, 0;*/\
  99. pushl %ds; \
  100. CFI_ADJUST_CFA_OFFSET 4;\
  101. /*CFI_REL_OFFSET ds, 0;*/\
  102. pushl %eax; \
  103. CFI_ADJUST_CFA_OFFSET 4;\
  104. CFI_REL_OFFSET eax, 0;\
  105. pushl %ebp; \
  106. CFI_ADJUST_CFA_OFFSET 4;\
  107. CFI_REL_OFFSET ebp, 0;\
  108. pushl %edi; \
  109. CFI_ADJUST_CFA_OFFSET 4;\
  110. CFI_REL_OFFSET edi, 0;\
  111. pushl %esi; \
  112. CFI_ADJUST_CFA_OFFSET 4;\
  113. CFI_REL_OFFSET esi, 0;\
  114. pushl %edx; \
  115. CFI_ADJUST_CFA_OFFSET 4;\
  116. CFI_REL_OFFSET edx, 0;\
  117. pushl %ecx; \
  118. CFI_ADJUST_CFA_OFFSET 4;\
  119. CFI_REL_OFFSET ecx, 0;\
  120. pushl %ebx; \
  121. CFI_ADJUST_CFA_OFFSET 4;\
  122. CFI_REL_OFFSET ebx, 0;\
  123. movl $(__USER_DS), %edx; \
  124. movl %edx, %ds; \
  125. movl %edx, %es; \
  126. movl $(__KERNEL_PDA), %edx; \
  127. movl %edx, %fs
  128. #define RESTORE_INT_REGS \
  129. popl %ebx; \
  130. CFI_ADJUST_CFA_OFFSET -4;\
  131. CFI_RESTORE ebx;\
  132. popl %ecx; \
  133. CFI_ADJUST_CFA_OFFSET -4;\
  134. CFI_RESTORE ecx;\
  135. popl %edx; \
  136. CFI_ADJUST_CFA_OFFSET -4;\
  137. CFI_RESTORE edx;\
  138. popl %esi; \
  139. CFI_ADJUST_CFA_OFFSET -4;\
  140. CFI_RESTORE esi;\
  141. popl %edi; \
  142. CFI_ADJUST_CFA_OFFSET -4;\
  143. CFI_RESTORE edi;\
  144. popl %ebp; \
  145. CFI_ADJUST_CFA_OFFSET -4;\
  146. CFI_RESTORE ebp;\
  147. popl %eax; \
  148. CFI_ADJUST_CFA_OFFSET -4;\
  149. CFI_RESTORE eax
  150. #define RESTORE_REGS \
  151. RESTORE_INT_REGS; \
  152. 1: popl %ds; \
  153. CFI_ADJUST_CFA_OFFSET -4;\
  154. /*CFI_RESTORE ds;*/\
  155. 2: popl %es; \
  156. CFI_ADJUST_CFA_OFFSET -4;\
  157. /*CFI_RESTORE es;*/\
  158. 3: popl %fs; \
  159. CFI_ADJUST_CFA_OFFSET -4;\
  160. /*CFI_RESTORE fs;*/\
  161. .pushsection .fixup,"ax"; \
  162. 4: movl $0,(%esp); \
  163. jmp 1b; \
  164. 5: movl $0,(%esp); \
  165. jmp 2b; \
  166. 6: movl $0,(%esp); \
  167. jmp 3b; \
  168. .section __ex_table,"a";\
  169. .align 4; \
  170. .long 1b,4b; \
  171. .long 2b,5b; \
  172. .long 3b,6b; \
  173. .popsection
  174. #define RING0_INT_FRAME \
  175. CFI_STARTPROC simple;\
  176. CFI_SIGNAL_FRAME;\
  177. CFI_DEF_CFA esp, 3*4;\
  178. /*CFI_OFFSET cs, -2*4;*/\
  179. CFI_OFFSET eip, -3*4
  180. #define RING0_EC_FRAME \
  181. CFI_STARTPROC simple;\
  182. CFI_SIGNAL_FRAME;\
  183. CFI_DEF_CFA esp, 4*4;\
  184. /*CFI_OFFSET cs, -2*4;*/\
  185. CFI_OFFSET eip, -3*4
  186. #define RING0_PTREGS_FRAME \
  187. CFI_STARTPROC simple;\
  188. CFI_SIGNAL_FRAME;\
  189. CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
  190. /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
  191. CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
  192. /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
  193. /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
  194. CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
  195. CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
  196. CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
  197. CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
  198. CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
  199. CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
  200. CFI_OFFSET ebx, PT_EBX-PT_OLDESP
  201. ENTRY(ret_from_fork)
  202. CFI_STARTPROC
  203. pushl %eax
  204. CFI_ADJUST_CFA_OFFSET 4
  205. call schedule_tail
  206. GET_THREAD_INFO(%ebp)
  207. popl %eax
  208. CFI_ADJUST_CFA_OFFSET -4
  209. pushl $0x0202 # Reset kernel eflags
  210. CFI_ADJUST_CFA_OFFSET 4
  211. popfl
  212. CFI_ADJUST_CFA_OFFSET -4
  213. jmp syscall_exit
  214. CFI_ENDPROC
  215. END(ret_from_fork)
  216. /*
  217. * Return to user mode is not as complex as all this looks,
  218. * but we want the default path for a system call return to
  219. * go as quickly as possible which is why some of this is
  220. * less clear than it otherwise should be.
  221. */
  222. # userspace resumption stub bypassing syscall exit tracing
  223. ALIGN
  224. RING0_PTREGS_FRAME
  225. ret_from_exception:
  226. preempt_stop(CLBR_ANY)
  227. ret_from_intr:
  228. GET_THREAD_INFO(%ebp)
  229. check_userspace:
  230. movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
  231. movb PT_CS(%esp), %al
  232. andl $(VM_MASK | SEGMENT_RPL_MASK), %eax
  233. cmpl $USER_RPL, %eax
  234. jb resume_kernel # not returning to v8086 or userspace
  235. ENTRY(resume_userspace)
  236. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  237. # setting need_resched or sigpending
  238. # between sampling and the iret
  239. movl TI_flags(%ebp), %ecx
  240. andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
  241. # int/exception return?
  242. jne work_pending
  243. jmp restore_all
  244. END(ret_from_exception)
  245. #ifdef CONFIG_PREEMPT
  246. ENTRY(resume_kernel)
  247. DISABLE_INTERRUPTS(CLBR_ANY)
  248. cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
  249. jnz restore_nocheck
  250. need_resched:
  251. movl TI_flags(%ebp), %ecx # need_resched set ?
  252. testb $_TIF_NEED_RESCHED, %cl
  253. jz restore_all
  254. testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off (exception path) ?
  255. jz restore_all
  256. call preempt_schedule_irq
  257. jmp need_resched
  258. END(resume_kernel)
  259. #endif
  260. CFI_ENDPROC
  261. /* SYSENTER_RETURN points to after the "sysenter" instruction in
  262. the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
  263. # sysenter call handler stub
  264. ENTRY(sysenter_entry)
  265. CFI_STARTPROC simple
  266. CFI_SIGNAL_FRAME
  267. CFI_DEF_CFA esp, 0
  268. CFI_REGISTER esp, ebp
  269. movl TSS_sysenter_esp0(%esp),%esp
  270. sysenter_past_esp:
  271. /*
  272. * No need to follow this irqs on/off section: the syscall
  273. * disabled irqs and here we enable it straight after entry:
  274. */
  275. ENABLE_INTERRUPTS(CLBR_NONE)
  276. pushl $(__USER_DS)
  277. CFI_ADJUST_CFA_OFFSET 4
  278. /*CFI_REL_OFFSET ss, 0*/
  279. pushl %ebp
  280. CFI_ADJUST_CFA_OFFSET 4
  281. CFI_REL_OFFSET esp, 0
  282. pushfl
  283. CFI_ADJUST_CFA_OFFSET 4
  284. pushl $(__USER_CS)
  285. CFI_ADJUST_CFA_OFFSET 4
  286. /*CFI_REL_OFFSET cs, 0*/
  287. #ifndef CONFIG_COMPAT_VDSO
  288. /*
  289. * Push current_thread_info()->sysenter_return to the stack.
  290. * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
  291. * pushed above; +8 corresponds to copy_thread's esp0 setting.
  292. */
  293. pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
  294. #else
  295. pushl $SYSENTER_RETURN
  296. #endif
  297. CFI_ADJUST_CFA_OFFSET 4
  298. CFI_REL_OFFSET eip, 0
  299. /*
  300. * Load the potential sixth argument from user stack.
  301. * Careful about security.
  302. */
  303. cmpl $__PAGE_OFFSET-3,%ebp
  304. jae syscall_fault
  305. 1: movl (%ebp),%ebp
  306. .section __ex_table,"a"
  307. .align 4
  308. .long 1b,syscall_fault
  309. .previous
  310. pushl %eax
  311. CFI_ADJUST_CFA_OFFSET 4
  312. SAVE_ALL
  313. GET_THREAD_INFO(%ebp)
  314. /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
  315. testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  316. jnz syscall_trace_entry
  317. cmpl $(nr_syscalls), %eax
  318. jae syscall_badsys
  319. call *sys_call_table(,%eax,4)
  320. movl %eax,PT_EAX(%esp)
  321. DISABLE_INTERRUPTS(CLBR_ECX|CLBR_EDX)
  322. TRACE_IRQS_OFF
  323. movl TI_flags(%ebp), %ecx
  324. testw $_TIF_ALLWORK_MASK, %cx
  325. jne syscall_exit_work
  326. /* if something modifies registers it must also disable sysexit */
  327. movl PT_EIP(%esp), %edx
  328. movl PT_OLDESP(%esp), %ecx
  329. xorl %ebp,%ebp
  330. TRACE_IRQS_ON
  331. 1: mov PT_FS(%esp), %fs
  332. ENABLE_INTERRUPTS_SYSEXIT
  333. CFI_ENDPROC
  334. .pushsection .fixup,"ax"
  335. 2: movl $0,PT_FS(%esp)
  336. jmp 1b
  337. .section __ex_table,"a"
  338. .align 4
  339. .long 1b,2b
  340. .popsection
  341. ENDPROC(sysenter_entry)
  342. # system call handler stub
  343. ENTRY(system_call)
  344. RING0_INT_FRAME # can't unwind into user space anyway
  345. pushl %eax # save orig_eax
  346. CFI_ADJUST_CFA_OFFSET 4
  347. SAVE_ALL
  348. GET_THREAD_INFO(%ebp)
  349. testl $TF_MASK,PT_EFLAGS(%esp)
  350. jz no_singlestep
  351. orl $_TIF_SINGLESTEP,TI_flags(%ebp)
  352. no_singlestep:
  353. # system call tracing in operation / emulation
  354. /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
  355. testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  356. jnz syscall_trace_entry
  357. cmpl $(nr_syscalls), %eax
  358. jae syscall_badsys
  359. syscall_call:
  360. call *sys_call_table(,%eax,4)
  361. movl %eax,PT_EAX(%esp) # store the return value
  362. syscall_exit:
  363. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  364. # setting need_resched or sigpending
  365. # between sampling and the iret
  366. TRACE_IRQS_OFF
  367. movl TI_flags(%ebp), %ecx
  368. testw $_TIF_ALLWORK_MASK, %cx # current->work
  369. jne syscall_exit_work
  370. restore_all:
  371. movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
  372. # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
  373. # are returning to the kernel.
  374. # See comments in process.c:copy_thread() for details.
  375. movb PT_OLDSS(%esp), %ah
  376. movb PT_CS(%esp), %al
  377. andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
  378. cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
  379. CFI_REMEMBER_STATE
  380. je ldt_ss # returning to user-space with LDT SS
  381. restore_nocheck:
  382. TRACE_IRQS_IRET
  383. restore_nocheck_notrace:
  384. RESTORE_REGS
  385. addl $4, %esp # skip orig_eax/error_code
  386. CFI_ADJUST_CFA_OFFSET -4
  387. 1: INTERRUPT_RETURN
  388. .section .fixup,"ax"
  389. iret_exc:
  390. TRACE_IRQS_ON
  391. ENABLE_INTERRUPTS(CLBR_NONE)
  392. pushl $0 # no error code
  393. pushl $do_iret_error
  394. jmp error_code
  395. .previous
  396. .section __ex_table,"a"
  397. .align 4
  398. .long 1b,iret_exc
  399. .previous
  400. CFI_RESTORE_STATE
  401. ldt_ss:
  402. larl PT_OLDSS(%esp), %eax
  403. jnz restore_nocheck
  404. testl $0x00400000, %eax # returning to 32bit stack?
  405. jnz restore_nocheck # allright, normal return
  406. #ifdef CONFIG_PARAVIRT
  407. /*
  408. * The kernel can't run on a non-flat stack if paravirt mode
  409. * is active. Rather than try to fixup the high bits of
  410. * ESP, bypass this code entirely. This may break DOSemu
  411. * and/or Wine support in a paravirt VM, although the option
  412. * is still available to implement the setting of the high
  413. * 16-bits in the INTERRUPT_RETURN paravirt-op.
  414. */
  415. cmpl $0, paravirt_ops+PARAVIRT_enabled
  416. jne restore_nocheck
  417. #endif
  418. /* If returning to userspace with 16bit stack,
  419. * try to fix the higher word of ESP, as the CPU
  420. * won't restore it.
  421. * This is an "official" bug of all the x86-compatible
  422. * CPUs, which we can try to work around to make
  423. * dosemu and wine happy. */
  424. movl PT_OLDESP(%esp), %eax
  425. movl %esp, %edx
  426. call patch_espfix_desc
  427. pushl $__ESPFIX_SS
  428. CFI_ADJUST_CFA_OFFSET 4
  429. pushl %eax
  430. CFI_ADJUST_CFA_OFFSET 4
  431. DISABLE_INTERRUPTS(CLBR_EAX)
  432. TRACE_IRQS_OFF
  433. lss (%esp), %esp
  434. CFI_ADJUST_CFA_OFFSET -8
  435. jmp restore_nocheck
  436. CFI_ENDPROC
  437. ENDPROC(system_call)
  438. # perform work that needs to be done immediately before resumption
  439. ALIGN
  440. RING0_PTREGS_FRAME # can't unwind into user space anyway
  441. work_pending:
  442. testb $_TIF_NEED_RESCHED, %cl
  443. jz work_notifysig
  444. work_resched:
  445. call schedule
  446. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  447. # setting need_resched or sigpending
  448. # between sampling and the iret
  449. TRACE_IRQS_OFF
  450. movl TI_flags(%ebp), %ecx
  451. andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
  452. # than syscall tracing?
  453. jz restore_all
  454. testb $_TIF_NEED_RESCHED, %cl
  455. jnz work_resched
  456. work_notifysig: # deal with pending signals and
  457. # notify-resume requests
  458. #ifdef CONFIG_VM86
  459. testl $VM_MASK, PT_EFLAGS(%esp)
  460. movl %esp, %eax
  461. jne work_notifysig_v86 # returning to kernel-space or
  462. # vm86-space
  463. xorl %edx, %edx
  464. call do_notify_resume
  465. jmp resume_userspace_sig
  466. ALIGN
  467. work_notifysig_v86:
  468. pushl %ecx # save ti_flags for do_notify_resume
  469. CFI_ADJUST_CFA_OFFSET 4
  470. call save_v86_state # %eax contains pt_regs pointer
  471. popl %ecx
  472. CFI_ADJUST_CFA_OFFSET -4
  473. movl %eax, %esp
  474. #else
  475. movl %esp, %eax
  476. #endif
  477. xorl %edx, %edx
  478. call do_notify_resume
  479. jmp resume_userspace_sig
  480. END(work_pending)
  481. # perform syscall exit tracing
  482. ALIGN
  483. syscall_trace_entry:
  484. movl $-ENOSYS,PT_EAX(%esp)
  485. movl %esp, %eax
  486. xorl %edx,%edx
  487. call do_syscall_trace
  488. cmpl $0, %eax
  489. jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
  490. # so must skip actual syscall
  491. movl PT_ORIG_EAX(%esp), %eax
  492. cmpl $(nr_syscalls), %eax
  493. jnae syscall_call
  494. jmp syscall_exit
  495. END(syscall_trace_entry)
  496. # perform syscall exit tracing
  497. ALIGN
  498. syscall_exit_work:
  499. testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
  500. jz work_pending
  501. TRACE_IRQS_ON
  502. ENABLE_INTERRUPTS(CLBR_ANY) # could let do_syscall_trace() call
  503. # schedule() instead
  504. movl %esp, %eax
  505. movl $1, %edx
  506. call do_syscall_trace
  507. jmp resume_userspace
  508. END(syscall_exit_work)
  509. CFI_ENDPROC
  510. RING0_INT_FRAME # can't unwind into user space anyway
  511. syscall_fault:
  512. pushl %eax # save orig_eax
  513. CFI_ADJUST_CFA_OFFSET 4
  514. SAVE_ALL
  515. GET_THREAD_INFO(%ebp)
  516. movl $-EFAULT,PT_EAX(%esp)
  517. jmp resume_userspace
  518. END(syscall_fault)
  519. syscall_badsys:
  520. movl $-ENOSYS,PT_EAX(%esp)
  521. jmp resume_userspace
  522. END(syscall_badsys)
  523. CFI_ENDPROC
  524. #define FIXUP_ESPFIX_STACK \
  525. /* since we are on a wrong stack, we cant make it a C code :( */ \
  526. movl %fs:PDA_cpu, %ebx; \
  527. PER_CPU(cpu_gdt_descr, %ebx); \
  528. movl GDS_address(%ebx), %ebx; \
  529. GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
  530. addl %esp, %eax; \
  531. pushl $__KERNEL_DS; \
  532. CFI_ADJUST_CFA_OFFSET 4; \
  533. pushl %eax; \
  534. CFI_ADJUST_CFA_OFFSET 4; \
  535. lss (%esp), %esp; \
  536. CFI_ADJUST_CFA_OFFSET -8;
  537. #define UNWIND_ESPFIX_STACK \
  538. movl %ss, %eax; \
  539. /* see if on espfix stack */ \
  540. cmpw $__ESPFIX_SS, %ax; \
  541. jne 27f; \
  542. movl $__KERNEL_DS, %eax; \
  543. movl %eax, %ds; \
  544. movl %eax, %es; \
  545. /* switch to normal stack */ \
  546. FIXUP_ESPFIX_STACK; \
  547. 27:;
  548. /*
  549. * Build the entry stubs and pointer table with
  550. * some assembler magic.
  551. */
  552. .data
  553. ENTRY(interrupt)
  554. .text
  555. ENTRY(irq_entries_start)
  556. RING0_INT_FRAME
  557. vector=0
  558. .rept NR_IRQS
  559. ALIGN
  560. .if vector
  561. CFI_ADJUST_CFA_OFFSET -4
  562. .endif
  563. 1: pushl $~(vector)
  564. CFI_ADJUST_CFA_OFFSET 4
  565. jmp common_interrupt
  566. .previous
  567. .long 1b
  568. .text
  569. vector=vector+1
  570. .endr
  571. END(irq_entries_start)
  572. .previous
  573. END(interrupt)
  574. .previous
  575. /*
  576. * the CPU automatically disables interrupts when executing an IRQ vector,
  577. * so IRQ-flags tracing has to follow that:
  578. */
  579. ALIGN
  580. common_interrupt:
  581. SAVE_ALL
  582. TRACE_IRQS_OFF
  583. movl %esp,%eax
  584. call do_IRQ
  585. jmp ret_from_intr
  586. ENDPROC(common_interrupt)
  587. CFI_ENDPROC
  588. #define BUILD_INTERRUPT(name, nr) \
  589. ENTRY(name) \
  590. RING0_INT_FRAME; \
  591. pushl $~(nr); \
  592. CFI_ADJUST_CFA_OFFSET 4; \
  593. SAVE_ALL; \
  594. TRACE_IRQS_OFF \
  595. movl %esp,%eax; \
  596. call smp_/**/name; \
  597. jmp ret_from_intr; \
  598. CFI_ENDPROC; \
  599. ENDPROC(name)
  600. /* The include is where all of the SMP etc. interrupts come from */
  601. #include "entry_arch.h"
  602. /* This alternate entry is needed because we hijack the apic LVTT */
  603. #if defined(CONFIG_VMI) && defined(CONFIG_X86_LOCAL_APIC)
  604. BUILD_INTERRUPT(apic_vmi_timer_interrupt,LOCAL_TIMER_VECTOR)
  605. #endif
  606. KPROBE_ENTRY(page_fault)
  607. RING0_EC_FRAME
  608. pushl $do_page_fault
  609. CFI_ADJUST_CFA_OFFSET 4
  610. ALIGN
  611. error_code:
  612. /* the function address is in %fs's slot on the stack */
  613. pushl %es
  614. CFI_ADJUST_CFA_OFFSET 4
  615. /*CFI_REL_OFFSET es, 0*/
  616. pushl %ds
  617. CFI_ADJUST_CFA_OFFSET 4
  618. /*CFI_REL_OFFSET ds, 0*/
  619. pushl %eax
  620. CFI_ADJUST_CFA_OFFSET 4
  621. CFI_REL_OFFSET eax, 0
  622. pushl %ebp
  623. CFI_ADJUST_CFA_OFFSET 4
  624. CFI_REL_OFFSET ebp, 0
  625. pushl %edi
  626. CFI_ADJUST_CFA_OFFSET 4
  627. CFI_REL_OFFSET edi, 0
  628. pushl %esi
  629. CFI_ADJUST_CFA_OFFSET 4
  630. CFI_REL_OFFSET esi, 0
  631. pushl %edx
  632. CFI_ADJUST_CFA_OFFSET 4
  633. CFI_REL_OFFSET edx, 0
  634. pushl %ecx
  635. CFI_ADJUST_CFA_OFFSET 4
  636. CFI_REL_OFFSET ecx, 0
  637. pushl %ebx
  638. CFI_ADJUST_CFA_OFFSET 4
  639. CFI_REL_OFFSET ebx, 0
  640. cld
  641. pushl %fs
  642. CFI_ADJUST_CFA_OFFSET 4
  643. /*CFI_REL_OFFSET fs, 0*/
  644. movl $(__KERNEL_PDA), %ecx
  645. movl %ecx, %fs
  646. UNWIND_ESPFIX_STACK
  647. popl %ecx
  648. CFI_ADJUST_CFA_OFFSET -4
  649. /*CFI_REGISTER es, ecx*/
  650. movl PT_FS(%esp), %edi # get the function address
  651. movl PT_ORIG_EAX(%esp), %edx # get the error code
  652. movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
  653. mov %ecx, PT_FS(%esp)
  654. /*CFI_REL_OFFSET fs, ES*/
  655. movl $(__USER_DS), %ecx
  656. movl %ecx, %ds
  657. movl %ecx, %es
  658. movl %esp,%eax # pt_regs pointer
  659. call *%edi
  660. jmp ret_from_exception
  661. CFI_ENDPROC
  662. KPROBE_END(page_fault)
  663. ENTRY(coprocessor_error)
  664. RING0_INT_FRAME
  665. pushl $0
  666. CFI_ADJUST_CFA_OFFSET 4
  667. pushl $do_coprocessor_error
  668. CFI_ADJUST_CFA_OFFSET 4
  669. jmp error_code
  670. CFI_ENDPROC
  671. END(coprocessor_error)
  672. ENTRY(simd_coprocessor_error)
  673. RING0_INT_FRAME
  674. pushl $0
  675. CFI_ADJUST_CFA_OFFSET 4
  676. pushl $do_simd_coprocessor_error
  677. CFI_ADJUST_CFA_OFFSET 4
  678. jmp error_code
  679. CFI_ENDPROC
  680. END(simd_coprocessor_error)
  681. ENTRY(device_not_available)
  682. RING0_INT_FRAME
  683. pushl $-1 # mark this as an int
  684. CFI_ADJUST_CFA_OFFSET 4
  685. SAVE_ALL
  686. GET_CR0_INTO_EAX
  687. testl $0x4, %eax # EM (math emulation bit)
  688. jne device_not_available_emulate
  689. preempt_stop(CLBR_ANY)
  690. call math_state_restore
  691. jmp ret_from_exception
  692. device_not_available_emulate:
  693. pushl $0 # temporary storage for ORIG_EIP
  694. CFI_ADJUST_CFA_OFFSET 4
  695. call math_emulate
  696. addl $4, %esp
  697. CFI_ADJUST_CFA_OFFSET -4
  698. jmp ret_from_exception
  699. CFI_ENDPROC
  700. END(device_not_available)
  701. /*
  702. * Debug traps and NMI can happen at the one SYSENTER instruction
  703. * that sets up the real kernel stack. Check here, since we can't
  704. * allow the wrong stack to be used.
  705. *
  706. * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
  707. * already pushed 3 words if it hits on the sysenter instruction:
  708. * eflags, cs and eip.
  709. *
  710. * We just load the right stack, and push the three (known) values
  711. * by hand onto the new stack - while updating the return eip past
  712. * the instruction that would have done it for sysenter.
  713. */
  714. #define FIX_STACK(offset, ok, label) \
  715. cmpw $__KERNEL_CS,4(%esp); \
  716. jne ok; \
  717. label: \
  718. movl TSS_sysenter_esp0+offset(%esp),%esp; \
  719. CFI_DEF_CFA esp, 0; \
  720. CFI_UNDEFINED eip; \
  721. pushfl; \
  722. CFI_ADJUST_CFA_OFFSET 4; \
  723. pushl $__KERNEL_CS; \
  724. CFI_ADJUST_CFA_OFFSET 4; \
  725. pushl $sysenter_past_esp; \
  726. CFI_ADJUST_CFA_OFFSET 4; \
  727. CFI_REL_OFFSET eip, 0
  728. KPROBE_ENTRY(debug)
  729. RING0_INT_FRAME
  730. cmpl $sysenter_entry,(%esp)
  731. jne debug_stack_correct
  732. FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
  733. debug_stack_correct:
  734. pushl $-1 # mark this as an int
  735. CFI_ADJUST_CFA_OFFSET 4
  736. SAVE_ALL
  737. xorl %edx,%edx # error code 0
  738. movl %esp,%eax # pt_regs pointer
  739. call do_debug
  740. jmp ret_from_exception
  741. CFI_ENDPROC
  742. KPROBE_END(debug)
  743. /*
  744. * NMI is doubly nasty. It can happen _while_ we're handling
  745. * a debug fault, and the debug fault hasn't yet been able to
  746. * clear up the stack. So we first check whether we got an
  747. * NMI on the sysenter entry path, but after that we need to
  748. * check whether we got an NMI on the debug path where the debug
  749. * fault happened on the sysenter path.
  750. */
  751. KPROBE_ENTRY(nmi)
  752. RING0_INT_FRAME
  753. pushl %eax
  754. CFI_ADJUST_CFA_OFFSET 4
  755. movl %ss, %eax
  756. cmpw $__ESPFIX_SS, %ax
  757. popl %eax
  758. CFI_ADJUST_CFA_OFFSET -4
  759. je nmi_espfix_stack
  760. cmpl $sysenter_entry,(%esp)
  761. je nmi_stack_fixup
  762. pushl %eax
  763. CFI_ADJUST_CFA_OFFSET 4
  764. movl %esp,%eax
  765. /* Do not access memory above the end of our stack page,
  766. * it might not exist.
  767. */
  768. andl $(THREAD_SIZE-1),%eax
  769. cmpl $(THREAD_SIZE-20),%eax
  770. popl %eax
  771. CFI_ADJUST_CFA_OFFSET -4
  772. jae nmi_stack_correct
  773. cmpl $sysenter_entry,12(%esp)
  774. je nmi_debug_stack_check
  775. nmi_stack_correct:
  776. /* We have a RING0_INT_FRAME here */
  777. pushl %eax
  778. CFI_ADJUST_CFA_OFFSET 4
  779. SAVE_ALL
  780. xorl %edx,%edx # zero error code
  781. movl %esp,%eax # pt_regs pointer
  782. call do_nmi
  783. jmp restore_nocheck_notrace
  784. CFI_ENDPROC
  785. nmi_stack_fixup:
  786. RING0_INT_FRAME
  787. FIX_STACK(12,nmi_stack_correct, 1)
  788. jmp nmi_stack_correct
  789. nmi_debug_stack_check:
  790. /* We have a RING0_INT_FRAME here */
  791. cmpw $__KERNEL_CS,16(%esp)
  792. jne nmi_stack_correct
  793. cmpl $debug,(%esp)
  794. jb nmi_stack_correct
  795. cmpl $debug_esp_fix_insn,(%esp)
  796. ja nmi_stack_correct
  797. FIX_STACK(24,nmi_stack_correct, 1)
  798. jmp nmi_stack_correct
  799. nmi_espfix_stack:
  800. /* We have a RING0_INT_FRAME here.
  801. *
  802. * create the pointer to lss back
  803. */
  804. pushl %ss
  805. CFI_ADJUST_CFA_OFFSET 4
  806. pushl %esp
  807. CFI_ADJUST_CFA_OFFSET 4
  808. addw $4, (%esp)
  809. /* copy the iret frame of 12 bytes */
  810. .rept 3
  811. pushl 16(%esp)
  812. CFI_ADJUST_CFA_OFFSET 4
  813. .endr
  814. pushl %eax
  815. CFI_ADJUST_CFA_OFFSET 4
  816. SAVE_ALL
  817. FIXUP_ESPFIX_STACK # %eax == %esp
  818. xorl %edx,%edx # zero error code
  819. call do_nmi
  820. RESTORE_REGS
  821. lss 12+4(%esp), %esp # back to espfix stack
  822. CFI_ADJUST_CFA_OFFSET -24
  823. 1: INTERRUPT_RETURN
  824. CFI_ENDPROC
  825. .section __ex_table,"a"
  826. .align 4
  827. .long 1b,iret_exc
  828. .previous
  829. KPROBE_END(nmi)
  830. #ifdef CONFIG_PARAVIRT
  831. ENTRY(native_iret)
  832. 1: iret
  833. .section __ex_table,"a"
  834. .align 4
  835. .long 1b,iret_exc
  836. .previous
  837. END(native_iret)
  838. ENTRY(native_irq_enable_sysexit)
  839. sti
  840. sysexit
  841. END(native_irq_enable_sysexit)
  842. #endif
  843. KPROBE_ENTRY(int3)
  844. RING0_INT_FRAME
  845. pushl $-1 # mark this as an int
  846. CFI_ADJUST_CFA_OFFSET 4
  847. SAVE_ALL
  848. xorl %edx,%edx # zero error code
  849. movl %esp,%eax # pt_regs pointer
  850. call do_int3
  851. jmp ret_from_exception
  852. CFI_ENDPROC
  853. KPROBE_END(int3)
  854. ENTRY(overflow)
  855. RING0_INT_FRAME
  856. pushl $0
  857. CFI_ADJUST_CFA_OFFSET 4
  858. pushl $do_overflow
  859. CFI_ADJUST_CFA_OFFSET 4
  860. jmp error_code
  861. CFI_ENDPROC
  862. END(overflow)
  863. ENTRY(bounds)
  864. RING0_INT_FRAME
  865. pushl $0
  866. CFI_ADJUST_CFA_OFFSET 4
  867. pushl $do_bounds
  868. CFI_ADJUST_CFA_OFFSET 4
  869. jmp error_code
  870. CFI_ENDPROC
  871. END(bounds)
  872. ENTRY(invalid_op)
  873. RING0_INT_FRAME
  874. pushl $0
  875. CFI_ADJUST_CFA_OFFSET 4
  876. pushl $do_invalid_op
  877. CFI_ADJUST_CFA_OFFSET 4
  878. jmp error_code
  879. CFI_ENDPROC
  880. END(invalid_op)
  881. ENTRY(coprocessor_segment_overrun)
  882. RING0_INT_FRAME
  883. pushl $0
  884. CFI_ADJUST_CFA_OFFSET 4
  885. pushl $do_coprocessor_segment_overrun
  886. CFI_ADJUST_CFA_OFFSET 4
  887. jmp error_code
  888. CFI_ENDPROC
  889. END(coprocessor_segment_overrun)
  890. ENTRY(invalid_TSS)
  891. RING0_EC_FRAME
  892. pushl $do_invalid_TSS
  893. CFI_ADJUST_CFA_OFFSET 4
  894. jmp error_code
  895. CFI_ENDPROC
  896. END(invalid_TSS)
  897. ENTRY(segment_not_present)
  898. RING0_EC_FRAME
  899. pushl $do_segment_not_present
  900. CFI_ADJUST_CFA_OFFSET 4
  901. jmp error_code
  902. CFI_ENDPROC
  903. END(segment_not_present)
  904. ENTRY(stack_segment)
  905. RING0_EC_FRAME
  906. pushl $do_stack_segment
  907. CFI_ADJUST_CFA_OFFSET 4
  908. jmp error_code
  909. CFI_ENDPROC
  910. END(stack_segment)
  911. KPROBE_ENTRY(general_protection)
  912. RING0_EC_FRAME
  913. pushl $do_general_protection
  914. CFI_ADJUST_CFA_OFFSET 4
  915. jmp error_code
  916. CFI_ENDPROC
  917. KPROBE_END(general_protection)
  918. ENTRY(alignment_check)
  919. RING0_EC_FRAME
  920. pushl $do_alignment_check
  921. CFI_ADJUST_CFA_OFFSET 4
  922. jmp error_code
  923. CFI_ENDPROC
  924. END(alignment_check)
  925. ENTRY(divide_error)
  926. RING0_INT_FRAME
  927. pushl $0 # no error code
  928. CFI_ADJUST_CFA_OFFSET 4
  929. pushl $do_divide_error
  930. CFI_ADJUST_CFA_OFFSET 4
  931. jmp error_code
  932. CFI_ENDPROC
  933. END(divide_error)
  934. #ifdef CONFIG_X86_MCE
  935. ENTRY(machine_check)
  936. RING0_INT_FRAME
  937. pushl $0
  938. CFI_ADJUST_CFA_OFFSET 4
  939. pushl machine_check_vector
  940. CFI_ADJUST_CFA_OFFSET 4
  941. jmp error_code
  942. CFI_ENDPROC
  943. END(machine_check)
  944. #endif
  945. ENTRY(spurious_interrupt_bug)
  946. RING0_INT_FRAME
  947. pushl $0
  948. CFI_ADJUST_CFA_OFFSET 4
  949. pushl $do_spurious_interrupt_bug
  950. CFI_ADJUST_CFA_OFFSET 4
  951. jmp error_code
  952. CFI_ENDPROC
  953. END(spurious_interrupt_bug)
  954. ENTRY(kernel_thread_helper)
  955. pushl $0 # fake return address for unwinder
  956. CFI_STARTPROC
  957. movl %edx,%eax
  958. push %edx
  959. CFI_ADJUST_CFA_OFFSET 4
  960. call *%ebx
  961. push %eax
  962. CFI_ADJUST_CFA_OFFSET 4
  963. call do_exit
  964. CFI_ENDPROC
  965. ENDPROC(kernel_thread_helper)
  966. .section .rodata,"a"
  967. #include "syscall_table.S"
  968. syscall_table_size=(.-sys_call_table)