entry_32.S 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. /*
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. */
  5. /*
  6. * entry.S contains the system-call and fault low-level handling routines.
  7. * This also contains the timer-interrupt handler, as well as all interrupts
  8. * and faults that can result in a task-switch.
  9. *
  10. * NOTE: This code handles signal-recognition, which happens every time
  11. * after a timer-interrupt and after each system call.
  12. *
  13. * I changed all the .align's to 4 (16 byte alignment), as that's faster
  14. * on a 486.
  15. *
  16. * Stack layout in 'syscall_exit':
  17. * ptrace needs to have all regs on the stack.
  18. * if the order here is changed, it needs to be
  19. * updated in fork.c:copy_process, signal.c:do_signal,
  20. * ptrace.c and ptrace.h
  21. *
  22. * 0(%esp) - %ebx
  23. * 4(%esp) - %ecx
  24. * 8(%esp) - %edx
  25. * C(%esp) - %esi
  26. * 10(%esp) - %edi
  27. * 14(%esp) - %ebp
  28. * 18(%esp) - %eax
  29. * 1C(%esp) - %ds
  30. * 20(%esp) - %es
  31. * 24(%esp) - %fs
  32. * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
  33. * 2C(%esp) - orig_eax
  34. * 30(%esp) - %eip
  35. * 34(%esp) - %cs
  36. * 38(%esp) - %eflags
  37. * 3C(%esp) - %oldesp
  38. * 40(%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_types.h>
  49. #include <asm/percpu.h>
  50. #include <asm/dwarf2.h>
  51. #include <asm/processor-flags.h>
  52. #include <asm/ftrace.h>
  53. #include <asm/irq_vectors.h>
  54. #include <asm/cpufeature.h>
  55. /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
  56. #include <linux/elf-em.h>
  57. #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
  58. #define __AUDIT_ARCH_LE 0x40000000
  59. #ifndef CONFIG_AUDITSYSCALL
  60. #define sysenter_audit syscall_trace_entry
  61. #define sysexit_audit syscall_exit_work
  62. #endif
  63. /*
  64. * We use macros for low-level operations which need to be overridden
  65. * for paravirtualization. The following will never clobber any registers:
  66. * INTERRUPT_RETURN (aka. "iret")
  67. * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
  68. * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
  69. *
  70. * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
  71. * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
  72. * Allowing a register to be clobbered can shrink the paravirt replacement
  73. * enough to patch inline, increasing performance.
  74. */
  75. #define nr_syscalls ((syscall_table_size)/4)
  76. #ifdef CONFIG_PREEMPT
  77. #define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
  78. #else
  79. #define preempt_stop(clobbers)
  80. #define resume_kernel restore_all
  81. #endif
  82. .macro TRACE_IRQS_IRET
  83. #ifdef CONFIG_TRACE_IRQFLAGS
  84. testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
  85. jz 1f
  86. TRACE_IRQS_ON
  87. 1:
  88. #endif
  89. .endm
  90. #ifdef CONFIG_VM86
  91. #define resume_userspace_sig check_userspace
  92. #else
  93. #define resume_userspace_sig resume_userspace
  94. #endif
  95. /*
  96. * User gs save/restore
  97. *
  98. * %gs is used for userland TLS and kernel only uses it for stack
  99. * canary which is required to be at %gs:20 by gcc. Read the comment
  100. * at the top of stackprotector.h for more info.
  101. *
  102. * Local labels 98 and 99 are used.
  103. */
  104. #ifdef CONFIG_X86_32_LAZY_GS
  105. /* unfortunately push/pop can't be no-op */
  106. .macro PUSH_GS
  107. pushl_cfi $0
  108. .endm
  109. .macro POP_GS pop=0
  110. addl $(4 + \pop), %esp
  111. CFI_ADJUST_CFA_OFFSET -(4 + \pop)
  112. .endm
  113. .macro POP_GS_EX
  114. .endm
  115. /* all the rest are no-op */
  116. .macro PTGS_TO_GS
  117. .endm
  118. .macro PTGS_TO_GS_EX
  119. .endm
  120. .macro GS_TO_REG reg
  121. .endm
  122. .macro REG_TO_PTGS reg
  123. .endm
  124. .macro SET_KERNEL_GS reg
  125. .endm
  126. #else /* CONFIG_X86_32_LAZY_GS */
  127. .macro PUSH_GS
  128. pushl_cfi %gs
  129. /*CFI_REL_OFFSET gs, 0*/
  130. .endm
  131. .macro POP_GS pop=0
  132. 98: popl_cfi %gs
  133. /*CFI_RESTORE gs*/
  134. .if \pop <> 0
  135. add $\pop, %esp
  136. CFI_ADJUST_CFA_OFFSET -\pop
  137. .endif
  138. .endm
  139. .macro POP_GS_EX
  140. .pushsection .fixup, "ax"
  141. 99: movl $0, (%esp)
  142. jmp 98b
  143. .section __ex_table, "a"
  144. .align 4
  145. .long 98b, 99b
  146. .popsection
  147. .endm
  148. .macro PTGS_TO_GS
  149. 98: mov PT_GS(%esp), %gs
  150. .endm
  151. .macro PTGS_TO_GS_EX
  152. .pushsection .fixup, "ax"
  153. 99: movl $0, PT_GS(%esp)
  154. jmp 98b
  155. .section __ex_table, "a"
  156. .align 4
  157. .long 98b, 99b
  158. .popsection
  159. .endm
  160. .macro GS_TO_REG reg
  161. movl %gs, \reg
  162. /*CFI_REGISTER gs, \reg*/
  163. .endm
  164. .macro REG_TO_PTGS reg
  165. movl \reg, PT_GS(%esp)
  166. /*CFI_REL_OFFSET gs, PT_GS*/
  167. .endm
  168. .macro SET_KERNEL_GS reg
  169. movl $(__KERNEL_STACK_CANARY), \reg
  170. movl \reg, %gs
  171. .endm
  172. #endif /* CONFIG_X86_32_LAZY_GS */
  173. .macro SAVE_ALL
  174. cld
  175. PUSH_GS
  176. pushl_cfi %fs
  177. /*CFI_REL_OFFSET fs, 0;*/
  178. pushl_cfi %es
  179. /*CFI_REL_OFFSET es, 0;*/
  180. pushl_cfi %ds
  181. /*CFI_REL_OFFSET ds, 0;*/
  182. pushl_cfi %eax
  183. CFI_REL_OFFSET eax, 0
  184. pushl_cfi %ebp
  185. CFI_REL_OFFSET ebp, 0
  186. pushl_cfi %edi
  187. CFI_REL_OFFSET edi, 0
  188. pushl_cfi %esi
  189. CFI_REL_OFFSET esi, 0
  190. pushl_cfi %edx
  191. CFI_REL_OFFSET edx, 0
  192. pushl_cfi %ecx
  193. CFI_REL_OFFSET ecx, 0
  194. pushl_cfi %ebx
  195. CFI_REL_OFFSET ebx, 0
  196. movl $(__USER_DS), %edx
  197. movl %edx, %ds
  198. movl %edx, %es
  199. movl $(__KERNEL_PERCPU), %edx
  200. movl %edx, %fs
  201. SET_KERNEL_GS %edx
  202. .endm
  203. .macro RESTORE_INT_REGS
  204. popl_cfi %ebx
  205. CFI_RESTORE ebx
  206. popl_cfi %ecx
  207. CFI_RESTORE ecx
  208. popl_cfi %edx
  209. CFI_RESTORE edx
  210. popl_cfi %esi
  211. CFI_RESTORE esi
  212. popl_cfi %edi
  213. CFI_RESTORE edi
  214. popl_cfi %ebp
  215. CFI_RESTORE ebp
  216. popl_cfi %eax
  217. CFI_RESTORE eax
  218. .endm
  219. .macro RESTORE_REGS pop=0
  220. RESTORE_INT_REGS
  221. 1: popl_cfi %ds
  222. /*CFI_RESTORE ds;*/
  223. 2: popl_cfi %es
  224. /*CFI_RESTORE es;*/
  225. 3: popl_cfi %fs
  226. /*CFI_RESTORE fs;*/
  227. POP_GS \pop
  228. .pushsection .fixup, "ax"
  229. 4: movl $0, (%esp)
  230. jmp 1b
  231. 5: movl $0, (%esp)
  232. jmp 2b
  233. 6: movl $0, (%esp)
  234. jmp 3b
  235. .section __ex_table, "a"
  236. .align 4
  237. .long 1b, 4b
  238. .long 2b, 5b
  239. .long 3b, 6b
  240. .popsection
  241. POP_GS_EX
  242. .endm
  243. .macro RING0_INT_FRAME
  244. CFI_STARTPROC simple
  245. CFI_SIGNAL_FRAME
  246. CFI_DEF_CFA esp, 3*4
  247. /*CFI_OFFSET cs, -2*4;*/
  248. CFI_OFFSET eip, -3*4
  249. .endm
  250. .macro RING0_EC_FRAME
  251. CFI_STARTPROC simple
  252. CFI_SIGNAL_FRAME
  253. CFI_DEF_CFA esp, 4*4
  254. /*CFI_OFFSET cs, -2*4;*/
  255. CFI_OFFSET eip, -3*4
  256. .endm
  257. .macro RING0_PTREGS_FRAME
  258. CFI_STARTPROC simple
  259. CFI_SIGNAL_FRAME
  260. CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
  261. /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
  262. CFI_OFFSET eip, PT_EIP-PT_OLDESP
  263. /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
  264. /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
  265. CFI_OFFSET eax, PT_EAX-PT_OLDESP
  266. CFI_OFFSET ebp, PT_EBP-PT_OLDESP
  267. CFI_OFFSET edi, PT_EDI-PT_OLDESP
  268. CFI_OFFSET esi, PT_ESI-PT_OLDESP
  269. CFI_OFFSET edx, PT_EDX-PT_OLDESP
  270. CFI_OFFSET ecx, PT_ECX-PT_OLDESP
  271. CFI_OFFSET ebx, PT_EBX-PT_OLDESP
  272. .endm
  273. ENTRY(ret_from_fork)
  274. CFI_STARTPROC
  275. pushl_cfi %eax
  276. call schedule_tail
  277. GET_THREAD_INFO(%ebp)
  278. popl_cfi %eax
  279. pushl_cfi $0x0202 # Reset kernel eflags
  280. popfl_cfi
  281. jmp syscall_exit
  282. CFI_ENDPROC
  283. END(ret_from_fork)
  284. /*
  285. * Interrupt exit functions should be protected against kprobes
  286. */
  287. .pushsection .kprobes.text, "ax"
  288. /*
  289. * Return to user mode is not as complex as all this looks,
  290. * but we want the default path for a system call return to
  291. * go as quickly as possible which is why some of this is
  292. * less clear than it otherwise should be.
  293. */
  294. # userspace resumption stub bypassing syscall exit tracing
  295. ALIGN
  296. RING0_PTREGS_FRAME
  297. ret_from_exception:
  298. preempt_stop(CLBR_ANY)
  299. ret_from_intr:
  300. GET_THREAD_INFO(%ebp)
  301. check_userspace:
  302. movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
  303. movb PT_CS(%esp), %al
  304. andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
  305. cmpl $USER_RPL, %eax
  306. jb resume_kernel # not returning to v8086 or userspace
  307. ENTRY(resume_userspace)
  308. LOCKDEP_SYS_EXIT
  309. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  310. # setting need_resched or sigpending
  311. # between sampling and the iret
  312. TRACE_IRQS_OFF
  313. movl TI_flags(%ebp), %ecx
  314. andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
  315. # int/exception return?
  316. jne work_pending
  317. jmp restore_all
  318. END(ret_from_exception)
  319. #ifdef CONFIG_PREEMPT
  320. ENTRY(resume_kernel)
  321. DISABLE_INTERRUPTS(CLBR_ANY)
  322. cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
  323. jnz restore_all
  324. need_resched:
  325. movl TI_flags(%ebp), %ecx # need_resched set ?
  326. testb $_TIF_NEED_RESCHED, %cl
  327. jz restore_all
  328. testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
  329. jz restore_all
  330. call preempt_schedule_irq
  331. jmp need_resched
  332. END(resume_kernel)
  333. #endif
  334. CFI_ENDPROC
  335. /*
  336. * End of kprobes section
  337. */
  338. .popsection
  339. /* SYSENTER_RETURN points to after the "sysenter" instruction in
  340. the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
  341. # sysenter call handler stub
  342. ENTRY(ia32_sysenter_target)
  343. CFI_STARTPROC simple
  344. CFI_SIGNAL_FRAME
  345. CFI_DEF_CFA esp, 0
  346. CFI_REGISTER esp, ebp
  347. movl TSS_sysenter_sp0(%esp),%esp
  348. sysenter_past_esp:
  349. /*
  350. * Interrupts are disabled here, but we can't trace it until
  351. * enough kernel state to call TRACE_IRQS_OFF can be called - but
  352. * we immediately enable interrupts at that point anyway.
  353. */
  354. pushl_cfi $__USER_DS
  355. /*CFI_REL_OFFSET ss, 0*/
  356. pushl_cfi %ebp
  357. CFI_REL_OFFSET esp, 0
  358. pushfl_cfi
  359. orl $X86_EFLAGS_IF, (%esp)
  360. pushl_cfi $__USER_CS
  361. /*CFI_REL_OFFSET cs, 0*/
  362. /*
  363. * Push current_thread_info()->sysenter_return to the stack.
  364. * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
  365. * pushed above; +8 corresponds to copy_thread's esp0 setting.
  366. */
  367. pushl_cfi ((TI_sysenter_return)-THREAD_SIZE_asm+8+4*4)(%esp)
  368. CFI_REL_OFFSET eip, 0
  369. pushl_cfi %eax
  370. SAVE_ALL
  371. ENABLE_INTERRUPTS(CLBR_NONE)
  372. /*
  373. * Load the potential sixth argument from user stack.
  374. * Careful about security.
  375. */
  376. cmpl $__PAGE_OFFSET-3,%ebp
  377. jae syscall_fault
  378. 1: movl (%ebp),%ebp
  379. movl %ebp,PT_EBP(%esp)
  380. .section __ex_table,"a"
  381. .align 4
  382. .long 1b,syscall_fault
  383. .previous
  384. GET_THREAD_INFO(%ebp)
  385. testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
  386. jnz sysenter_audit
  387. sysenter_do_call:
  388. cmpl $(nr_syscalls), %eax
  389. jae syscall_badsys
  390. call *sys_call_table(,%eax,4)
  391. movl %eax,PT_EAX(%esp)
  392. LOCKDEP_SYS_EXIT
  393. DISABLE_INTERRUPTS(CLBR_ANY)
  394. TRACE_IRQS_OFF
  395. movl TI_flags(%ebp), %ecx
  396. testl $_TIF_ALLWORK_MASK, %ecx
  397. jne sysexit_audit
  398. sysenter_exit:
  399. /* if something modifies registers it must also disable sysexit */
  400. movl PT_EIP(%esp), %edx
  401. movl PT_OLDESP(%esp), %ecx
  402. xorl %ebp,%ebp
  403. TRACE_IRQS_ON
  404. 1: mov PT_FS(%esp), %fs
  405. PTGS_TO_GS
  406. ENABLE_INTERRUPTS_SYSEXIT
  407. #ifdef CONFIG_AUDITSYSCALL
  408. sysenter_audit:
  409. testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  410. jnz syscall_trace_entry
  411. addl $4,%esp
  412. CFI_ADJUST_CFA_OFFSET -4
  413. /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
  414. /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
  415. /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
  416. movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
  417. movl %eax,%edx /* 2nd arg: syscall number */
  418. movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
  419. call audit_syscall_entry
  420. pushl_cfi %ebx
  421. movl PT_EAX(%esp),%eax /* reload syscall number */
  422. jmp sysenter_do_call
  423. sysexit_audit:
  424. testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
  425. jne syscall_exit_work
  426. TRACE_IRQS_ON
  427. ENABLE_INTERRUPTS(CLBR_ANY)
  428. movl %eax,%edx /* second arg, syscall return value */
  429. cmpl $0,%eax /* is it < 0? */
  430. setl %al /* 1 if so, 0 if not */
  431. movzbl %al,%eax /* zero-extend that */
  432. inc %eax /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
  433. call audit_syscall_exit
  434. DISABLE_INTERRUPTS(CLBR_ANY)
  435. TRACE_IRQS_OFF
  436. movl TI_flags(%ebp), %ecx
  437. testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
  438. jne syscall_exit_work
  439. movl PT_EAX(%esp),%eax /* reload syscall return value */
  440. jmp sysenter_exit
  441. #endif
  442. CFI_ENDPROC
  443. .pushsection .fixup,"ax"
  444. 2: movl $0,PT_FS(%esp)
  445. jmp 1b
  446. .section __ex_table,"a"
  447. .align 4
  448. .long 1b,2b
  449. .popsection
  450. PTGS_TO_GS_EX
  451. ENDPROC(ia32_sysenter_target)
  452. /*
  453. * syscall stub including irq exit should be protected against kprobes
  454. */
  455. .pushsection .kprobes.text, "ax"
  456. # system call handler stub
  457. ENTRY(system_call)
  458. RING0_INT_FRAME # can't unwind into user space anyway
  459. pushl_cfi %eax # save orig_eax
  460. SAVE_ALL
  461. GET_THREAD_INFO(%ebp)
  462. # system call tracing in operation / emulation
  463. testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
  464. jnz syscall_trace_entry
  465. cmpl $(nr_syscalls), %eax
  466. jae syscall_badsys
  467. syscall_call:
  468. call *sys_call_table(,%eax,4)
  469. movl %eax,PT_EAX(%esp) # store the return value
  470. syscall_exit:
  471. LOCKDEP_SYS_EXIT
  472. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  473. # setting need_resched or sigpending
  474. # between sampling and the iret
  475. TRACE_IRQS_OFF
  476. movl TI_flags(%ebp), %ecx
  477. testl $_TIF_ALLWORK_MASK, %ecx # current->work
  478. jne syscall_exit_work
  479. restore_all:
  480. TRACE_IRQS_IRET
  481. restore_all_notrace:
  482. movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
  483. # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
  484. # are returning to the kernel.
  485. # See comments in process.c:copy_thread() for details.
  486. movb PT_OLDSS(%esp), %ah
  487. movb PT_CS(%esp), %al
  488. andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
  489. cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
  490. CFI_REMEMBER_STATE
  491. je ldt_ss # returning to user-space with LDT SS
  492. restore_nocheck:
  493. RESTORE_REGS 4 # skip orig_eax/error_code
  494. irq_return:
  495. INTERRUPT_RETURN
  496. .section .fixup,"ax"
  497. ENTRY(iret_exc)
  498. pushl $0 # no error code
  499. pushl $do_iret_error
  500. jmp error_code
  501. .previous
  502. .section __ex_table,"a"
  503. .align 4
  504. .long irq_return,iret_exc
  505. .previous
  506. CFI_RESTORE_STATE
  507. ldt_ss:
  508. larl PT_OLDSS(%esp), %eax
  509. jnz restore_nocheck
  510. testl $0x00400000, %eax # returning to 32bit stack?
  511. jnz restore_nocheck # allright, normal return
  512. #ifdef CONFIG_PARAVIRT
  513. /*
  514. * The kernel can't run on a non-flat stack if paravirt mode
  515. * is active. Rather than try to fixup the high bits of
  516. * ESP, bypass this code entirely. This may break DOSemu
  517. * and/or Wine support in a paravirt VM, although the option
  518. * is still available to implement the setting of the high
  519. * 16-bits in the INTERRUPT_RETURN paravirt-op.
  520. */
  521. cmpl $0, pv_info+PARAVIRT_enabled
  522. jne restore_nocheck
  523. #endif
  524. /*
  525. * Setup and switch to ESPFIX stack
  526. *
  527. * We're returning to userspace with a 16 bit stack. The CPU will not
  528. * restore the high word of ESP for us on executing iret... This is an
  529. * "official" bug of all the x86-compatible CPUs, which we can work
  530. * around to make dosemu and wine happy. We do this by preloading the
  531. * high word of ESP with the high word of the userspace ESP while
  532. * compensating for the offset by changing to the ESPFIX segment with
  533. * a base address that matches for the difference.
  534. */
  535. #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
  536. mov %esp, %edx /* load kernel esp */
  537. mov PT_OLDESP(%esp), %eax /* load userspace esp */
  538. mov %dx, %ax /* eax: new kernel esp */
  539. sub %eax, %edx /* offset (low word is 0) */
  540. shr $16, %edx
  541. mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
  542. mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
  543. pushl_cfi $__ESPFIX_SS
  544. pushl_cfi %eax /* new kernel esp */
  545. /* Disable interrupts, but do not irqtrace this section: we
  546. * will soon execute iret and the tracer was already set to
  547. * the irqstate after the iret */
  548. DISABLE_INTERRUPTS(CLBR_EAX)
  549. lss (%esp), %esp /* switch to espfix segment */
  550. CFI_ADJUST_CFA_OFFSET -8
  551. jmp restore_nocheck
  552. CFI_ENDPROC
  553. ENDPROC(system_call)
  554. # perform work that needs to be done immediately before resumption
  555. ALIGN
  556. RING0_PTREGS_FRAME # can't unwind into user space anyway
  557. work_pending:
  558. testb $_TIF_NEED_RESCHED, %cl
  559. jz work_notifysig
  560. work_resched:
  561. call schedule
  562. LOCKDEP_SYS_EXIT
  563. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  564. # setting need_resched or sigpending
  565. # between sampling and the iret
  566. TRACE_IRQS_OFF
  567. movl TI_flags(%ebp), %ecx
  568. andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
  569. # than syscall tracing?
  570. jz restore_all
  571. testb $_TIF_NEED_RESCHED, %cl
  572. jnz work_resched
  573. work_notifysig: # deal with pending signals and
  574. # notify-resume requests
  575. #ifdef CONFIG_VM86
  576. testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
  577. movl %esp, %eax
  578. jne work_notifysig_v86 # returning to kernel-space or
  579. # vm86-space
  580. xorl %edx, %edx
  581. call do_notify_resume
  582. jmp resume_userspace_sig
  583. ALIGN
  584. work_notifysig_v86:
  585. pushl_cfi %ecx # save ti_flags for do_notify_resume
  586. call save_v86_state # %eax contains pt_regs pointer
  587. popl_cfi %ecx
  588. movl %eax, %esp
  589. #else
  590. movl %esp, %eax
  591. #endif
  592. xorl %edx, %edx
  593. call do_notify_resume
  594. jmp resume_userspace_sig
  595. END(work_pending)
  596. # perform syscall exit tracing
  597. ALIGN
  598. syscall_trace_entry:
  599. movl $-ENOSYS,PT_EAX(%esp)
  600. movl %esp, %eax
  601. call syscall_trace_enter
  602. /* What it returned is what we'll actually use. */
  603. cmpl $(nr_syscalls), %eax
  604. jnae syscall_call
  605. jmp syscall_exit
  606. END(syscall_trace_entry)
  607. # perform syscall exit tracing
  608. ALIGN
  609. syscall_exit_work:
  610. testl $_TIF_WORK_SYSCALL_EXIT, %ecx
  611. jz work_pending
  612. TRACE_IRQS_ON
  613. ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
  614. # schedule() instead
  615. movl %esp, %eax
  616. call syscall_trace_leave
  617. jmp resume_userspace
  618. END(syscall_exit_work)
  619. CFI_ENDPROC
  620. RING0_INT_FRAME # can't unwind into user space anyway
  621. syscall_fault:
  622. GET_THREAD_INFO(%ebp)
  623. movl $-EFAULT,PT_EAX(%esp)
  624. jmp resume_userspace
  625. END(syscall_fault)
  626. syscall_badsys:
  627. movl $-ENOSYS,PT_EAX(%esp)
  628. jmp resume_userspace
  629. END(syscall_badsys)
  630. CFI_ENDPROC
  631. /*
  632. * End of kprobes section
  633. */
  634. .popsection
  635. /*
  636. * System calls that need a pt_regs pointer.
  637. */
  638. #define PTREGSCALL0(name) \
  639. ALIGN; \
  640. ptregs_##name: \
  641. leal 4(%esp),%eax; \
  642. jmp sys_##name;
  643. #define PTREGSCALL1(name) \
  644. ALIGN; \
  645. ptregs_##name: \
  646. leal 4(%esp),%edx; \
  647. movl (PT_EBX+4)(%esp),%eax; \
  648. jmp sys_##name;
  649. #define PTREGSCALL2(name) \
  650. ALIGN; \
  651. ptregs_##name: \
  652. leal 4(%esp),%ecx; \
  653. movl (PT_ECX+4)(%esp),%edx; \
  654. movl (PT_EBX+4)(%esp),%eax; \
  655. jmp sys_##name;
  656. #define PTREGSCALL3(name) \
  657. ALIGN; \
  658. ptregs_##name: \
  659. CFI_STARTPROC; \
  660. leal 4(%esp),%eax; \
  661. pushl_cfi %eax; \
  662. movl PT_EDX(%eax),%ecx; \
  663. movl PT_ECX(%eax),%edx; \
  664. movl PT_EBX(%eax),%eax; \
  665. call sys_##name; \
  666. addl $4,%esp; \
  667. CFI_ADJUST_CFA_OFFSET -4; \
  668. ret; \
  669. CFI_ENDPROC; \
  670. ENDPROC(ptregs_##name)
  671. PTREGSCALL1(iopl)
  672. PTREGSCALL0(fork)
  673. PTREGSCALL0(vfork)
  674. PTREGSCALL3(execve)
  675. PTREGSCALL2(sigaltstack)
  676. PTREGSCALL0(sigreturn)
  677. PTREGSCALL0(rt_sigreturn)
  678. PTREGSCALL2(vm86)
  679. PTREGSCALL1(vm86old)
  680. /* Clone is an oddball. The 4th arg is in %edi */
  681. ALIGN;
  682. ptregs_clone:
  683. CFI_STARTPROC
  684. leal 4(%esp),%eax
  685. pushl_cfi %eax
  686. pushl_cfi PT_EDI(%eax)
  687. movl PT_EDX(%eax),%ecx
  688. movl PT_ECX(%eax),%edx
  689. movl PT_EBX(%eax),%eax
  690. call sys_clone
  691. addl $8,%esp
  692. CFI_ADJUST_CFA_OFFSET -8
  693. ret
  694. CFI_ENDPROC
  695. ENDPROC(ptregs_clone)
  696. .macro FIXUP_ESPFIX_STACK
  697. /*
  698. * Switch back for ESPFIX stack to the normal zerobased stack
  699. *
  700. * We can't call C functions using the ESPFIX stack. This code reads
  701. * the high word of the segment base from the GDT and swiches to the
  702. * normal stack and adjusts ESP with the matching offset.
  703. */
  704. /* fixup the stack */
  705. mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
  706. mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
  707. shl $16, %eax
  708. addl %esp, %eax /* the adjusted stack pointer */
  709. pushl_cfi $__KERNEL_DS
  710. pushl_cfi %eax
  711. lss (%esp), %esp /* switch to the normal stack segment */
  712. CFI_ADJUST_CFA_OFFSET -8
  713. .endm
  714. .macro UNWIND_ESPFIX_STACK
  715. movl %ss, %eax
  716. /* see if on espfix stack */
  717. cmpw $__ESPFIX_SS, %ax
  718. jne 27f
  719. movl $__KERNEL_DS, %eax
  720. movl %eax, %ds
  721. movl %eax, %es
  722. /* switch to normal stack */
  723. FIXUP_ESPFIX_STACK
  724. 27:
  725. .endm
  726. /*
  727. * Build the entry stubs and pointer table with some assembler magic.
  728. * We pack 7 stubs into a single 32-byte chunk, which will fit in a
  729. * single cache line on all modern x86 implementations.
  730. */
  731. .section .init.rodata,"a"
  732. ENTRY(interrupt)
  733. .text
  734. .p2align 5
  735. .p2align CONFIG_X86_L1_CACHE_SHIFT
  736. ENTRY(irq_entries_start)
  737. RING0_INT_FRAME
  738. vector=FIRST_EXTERNAL_VECTOR
  739. .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
  740. .balign 32
  741. .rept 7
  742. .if vector < NR_VECTORS
  743. .if vector <> FIRST_EXTERNAL_VECTOR
  744. CFI_ADJUST_CFA_OFFSET -4
  745. .endif
  746. 1: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
  747. .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
  748. jmp 2f
  749. .endif
  750. .previous
  751. .long 1b
  752. .text
  753. vector=vector+1
  754. .endif
  755. .endr
  756. 2: jmp common_interrupt
  757. .endr
  758. END(irq_entries_start)
  759. .previous
  760. END(interrupt)
  761. .previous
  762. /*
  763. * the CPU automatically disables interrupts when executing an IRQ vector,
  764. * so IRQ-flags tracing has to follow that:
  765. */
  766. .p2align CONFIG_X86_L1_CACHE_SHIFT
  767. common_interrupt:
  768. addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
  769. SAVE_ALL
  770. TRACE_IRQS_OFF
  771. movl %esp,%eax
  772. call do_IRQ
  773. jmp ret_from_intr
  774. ENDPROC(common_interrupt)
  775. CFI_ENDPROC
  776. /*
  777. * Irq entries should be protected against kprobes
  778. */
  779. .pushsection .kprobes.text, "ax"
  780. #define BUILD_INTERRUPT3(name, nr, fn) \
  781. ENTRY(name) \
  782. RING0_INT_FRAME; \
  783. pushl_cfi $~(nr); \
  784. SAVE_ALL; \
  785. TRACE_IRQS_OFF \
  786. movl %esp,%eax; \
  787. call fn; \
  788. jmp ret_from_intr; \
  789. CFI_ENDPROC; \
  790. ENDPROC(name)
  791. #define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
  792. /* The include is where all of the SMP etc. interrupts come from */
  793. #include <asm/entry_arch.h>
  794. ENTRY(coprocessor_error)
  795. RING0_INT_FRAME
  796. pushl_cfi $0
  797. pushl_cfi $do_coprocessor_error
  798. jmp error_code
  799. CFI_ENDPROC
  800. END(coprocessor_error)
  801. ENTRY(simd_coprocessor_error)
  802. RING0_INT_FRAME
  803. pushl_cfi $0
  804. #ifdef CONFIG_X86_INVD_BUG
  805. /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
  806. 661: pushl_cfi $do_general_protection
  807. 662:
  808. .section .altinstructions,"a"
  809. .balign 4
  810. .long 661b
  811. .long 663f
  812. .word X86_FEATURE_XMM
  813. .byte 662b-661b
  814. .byte 664f-663f
  815. .previous
  816. .section .altinstr_replacement,"ax"
  817. 663: pushl $do_simd_coprocessor_error
  818. 664:
  819. .previous
  820. #else
  821. pushl_cfi $do_simd_coprocessor_error
  822. #endif
  823. jmp error_code
  824. CFI_ENDPROC
  825. END(simd_coprocessor_error)
  826. ENTRY(device_not_available)
  827. RING0_INT_FRAME
  828. pushl_cfi $-1 # mark this as an int
  829. pushl_cfi $do_device_not_available
  830. jmp error_code
  831. CFI_ENDPROC
  832. END(device_not_available)
  833. #ifdef CONFIG_PARAVIRT
  834. ENTRY(native_iret)
  835. iret
  836. .section __ex_table,"a"
  837. .align 4
  838. .long native_iret, iret_exc
  839. .previous
  840. END(native_iret)
  841. ENTRY(native_irq_enable_sysexit)
  842. sti
  843. sysexit
  844. END(native_irq_enable_sysexit)
  845. #endif
  846. ENTRY(overflow)
  847. RING0_INT_FRAME
  848. pushl_cfi $0
  849. pushl_cfi $do_overflow
  850. jmp error_code
  851. CFI_ENDPROC
  852. END(overflow)
  853. ENTRY(bounds)
  854. RING0_INT_FRAME
  855. pushl_cfi $0
  856. pushl_cfi $do_bounds
  857. jmp error_code
  858. CFI_ENDPROC
  859. END(bounds)
  860. ENTRY(invalid_op)
  861. RING0_INT_FRAME
  862. pushl_cfi $0
  863. pushl_cfi $do_invalid_op
  864. jmp error_code
  865. CFI_ENDPROC
  866. END(invalid_op)
  867. ENTRY(coprocessor_segment_overrun)
  868. RING0_INT_FRAME
  869. pushl_cfi $0
  870. pushl_cfi $do_coprocessor_segment_overrun
  871. jmp error_code
  872. CFI_ENDPROC
  873. END(coprocessor_segment_overrun)
  874. ENTRY(invalid_TSS)
  875. RING0_EC_FRAME
  876. pushl_cfi $do_invalid_TSS
  877. jmp error_code
  878. CFI_ENDPROC
  879. END(invalid_TSS)
  880. ENTRY(segment_not_present)
  881. RING0_EC_FRAME
  882. pushl_cfi $do_segment_not_present
  883. jmp error_code
  884. CFI_ENDPROC
  885. END(segment_not_present)
  886. ENTRY(stack_segment)
  887. RING0_EC_FRAME
  888. pushl_cfi $do_stack_segment
  889. jmp error_code
  890. CFI_ENDPROC
  891. END(stack_segment)
  892. ENTRY(alignment_check)
  893. RING0_EC_FRAME
  894. pushl_cfi $do_alignment_check
  895. jmp error_code
  896. CFI_ENDPROC
  897. END(alignment_check)
  898. ENTRY(divide_error)
  899. RING0_INT_FRAME
  900. pushl_cfi $0 # no error code
  901. pushl_cfi $do_divide_error
  902. jmp error_code
  903. CFI_ENDPROC
  904. END(divide_error)
  905. #ifdef CONFIG_X86_MCE
  906. ENTRY(machine_check)
  907. RING0_INT_FRAME
  908. pushl_cfi $0
  909. pushl_cfi machine_check_vector
  910. jmp error_code
  911. CFI_ENDPROC
  912. END(machine_check)
  913. #endif
  914. ENTRY(spurious_interrupt_bug)
  915. RING0_INT_FRAME
  916. pushl_cfi $0
  917. pushl_cfi $do_spurious_interrupt_bug
  918. jmp error_code
  919. CFI_ENDPROC
  920. END(spurious_interrupt_bug)
  921. /*
  922. * End of kprobes section
  923. */
  924. .popsection
  925. ENTRY(kernel_thread_helper)
  926. pushl $0 # fake return address for unwinder
  927. CFI_STARTPROC
  928. movl %edi,%eax
  929. call *%esi
  930. call do_exit
  931. ud2 # padding for call trace
  932. CFI_ENDPROC
  933. ENDPROC(kernel_thread_helper)
  934. #ifdef CONFIG_XEN
  935. /* Xen doesn't set %esp to be precisely what the normal sysenter
  936. entrypoint expects, so fix it up before using the normal path. */
  937. ENTRY(xen_sysenter_target)
  938. RING0_INT_FRAME
  939. addl $5*4, %esp /* remove xen-provided frame */
  940. CFI_ADJUST_CFA_OFFSET -5*4
  941. jmp sysenter_past_esp
  942. CFI_ENDPROC
  943. ENTRY(xen_hypervisor_callback)
  944. CFI_STARTPROC
  945. pushl_cfi $0
  946. SAVE_ALL
  947. TRACE_IRQS_OFF
  948. /* Check to see if we got the event in the critical
  949. region in xen_iret_direct, after we've reenabled
  950. events and checked for pending events. This simulates
  951. iret instruction's behaviour where it delivers a
  952. pending interrupt when enabling interrupts. */
  953. movl PT_EIP(%esp),%eax
  954. cmpl $xen_iret_start_crit,%eax
  955. jb 1f
  956. cmpl $xen_iret_end_crit,%eax
  957. jae 1f
  958. jmp xen_iret_crit_fixup
  959. ENTRY(xen_do_upcall)
  960. 1: mov %esp, %eax
  961. call xen_evtchn_do_upcall
  962. jmp ret_from_intr
  963. CFI_ENDPROC
  964. ENDPROC(xen_hypervisor_callback)
  965. # Hypervisor uses this for application faults while it executes.
  966. # We get here for two reasons:
  967. # 1. Fault while reloading DS, ES, FS or GS
  968. # 2. Fault while executing IRET
  969. # Category 1 we fix up by reattempting the load, and zeroing the segment
  970. # register if the load fails.
  971. # Category 2 we fix up by jumping to do_iret_error. We cannot use the
  972. # normal Linux return path in this case because if we use the IRET hypercall
  973. # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
  974. # We distinguish between categories by maintaining a status value in EAX.
  975. ENTRY(xen_failsafe_callback)
  976. CFI_STARTPROC
  977. pushl_cfi %eax
  978. movl $1,%eax
  979. 1: mov 4(%esp),%ds
  980. 2: mov 8(%esp),%es
  981. 3: mov 12(%esp),%fs
  982. 4: mov 16(%esp),%gs
  983. testl %eax,%eax
  984. popl_cfi %eax
  985. lea 16(%esp),%esp
  986. CFI_ADJUST_CFA_OFFSET -16
  987. jz 5f
  988. addl $16,%esp
  989. jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
  990. 5: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
  991. SAVE_ALL
  992. jmp ret_from_exception
  993. CFI_ENDPROC
  994. .section .fixup,"ax"
  995. 6: xorl %eax,%eax
  996. movl %eax,4(%esp)
  997. jmp 1b
  998. 7: xorl %eax,%eax
  999. movl %eax,8(%esp)
  1000. jmp 2b
  1001. 8: xorl %eax,%eax
  1002. movl %eax,12(%esp)
  1003. jmp 3b
  1004. 9: xorl %eax,%eax
  1005. movl %eax,16(%esp)
  1006. jmp 4b
  1007. .previous
  1008. .section __ex_table,"a"
  1009. .align 4
  1010. .long 1b,6b
  1011. .long 2b,7b
  1012. .long 3b,8b
  1013. .long 4b,9b
  1014. .previous
  1015. ENDPROC(xen_failsafe_callback)
  1016. BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
  1017. xen_evtchn_do_upcall)
  1018. #endif /* CONFIG_XEN */
  1019. #ifdef CONFIG_FUNCTION_TRACER
  1020. #ifdef CONFIG_DYNAMIC_FTRACE
  1021. ENTRY(mcount)
  1022. ret
  1023. END(mcount)
  1024. ENTRY(ftrace_caller)
  1025. cmpl $0, function_trace_stop
  1026. jne ftrace_stub
  1027. pushl %eax
  1028. pushl %ecx
  1029. pushl %edx
  1030. movl 0xc(%esp), %eax
  1031. movl 0x4(%ebp), %edx
  1032. subl $MCOUNT_INSN_SIZE, %eax
  1033. .globl ftrace_call
  1034. ftrace_call:
  1035. call ftrace_stub
  1036. popl %edx
  1037. popl %ecx
  1038. popl %eax
  1039. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1040. .globl ftrace_graph_call
  1041. ftrace_graph_call:
  1042. jmp ftrace_stub
  1043. #endif
  1044. .globl ftrace_stub
  1045. ftrace_stub:
  1046. ret
  1047. END(ftrace_caller)
  1048. #else /* ! CONFIG_DYNAMIC_FTRACE */
  1049. ENTRY(mcount)
  1050. cmpl $0, function_trace_stop
  1051. jne ftrace_stub
  1052. cmpl $ftrace_stub, ftrace_trace_function
  1053. jnz trace
  1054. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1055. cmpl $ftrace_stub, ftrace_graph_return
  1056. jnz ftrace_graph_caller
  1057. cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
  1058. jnz ftrace_graph_caller
  1059. #endif
  1060. .globl ftrace_stub
  1061. ftrace_stub:
  1062. ret
  1063. /* taken from glibc */
  1064. trace:
  1065. pushl %eax
  1066. pushl %ecx
  1067. pushl %edx
  1068. movl 0xc(%esp), %eax
  1069. movl 0x4(%ebp), %edx
  1070. subl $MCOUNT_INSN_SIZE, %eax
  1071. call *ftrace_trace_function
  1072. popl %edx
  1073. popl %ecx
  1074. popl %eax
  1075. jmp ftrace_stub
  1076. END(mcount)
  1077. #endif /* CONFIG_DYNAMIC_FTRACE */
  1078. #endif /* CONFIG_FUNCTION_TRACER */
  1079. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1080. ENTRY(ftrace_graph_caller)
  1081. cmpl $0, function_trace_stop
  1082. jne ftrace_stub
  1083. pushl %eax
  1084. pushl %ecx
  1085. pushl %edx
  1086. movl 0xc(%esp), %edx
  1087. lea 0x4(%ebp), %eax
  1088. movl (%ebp), %ecx
  1089. subl $MCOUNT_INSN_SIZE, %edx
  1090. call prepare_ftrace_return
  1091. popl %edx
  1092. popl %ecx
  1093. popl %eax
  1094. ret
  1095. END(ftrace_graph_caller)
  1096. .globl return_to_handler
  1097. return_to_handler:
  1098. pushl %eax
  1099. pushl %edx
  1100. movl %ebp, %eax
  1101. call ftrace_return_to_handler
  1102. movl %eax, %ecx
  1103. popl %edx
  1104. popl %eax
  1105. jmp *%ecx
  1106. #endif
  1107. .section .rodata,"a"
  1108. #include "syscall_table_32.S"
  1109. syscall_table_size=(.-sys_call_table)
  1110. /*
  1111. * Some functions should be protected against kprobes
  1112. */
  1113. .pushsection .kprobes.text, "ax"
  1114. ENTRY(page_fault)
  1115. RING0_EC_FRAME
  1116. pushl_cfi $do_page_fault
  1117. ALIGN
  1118. error_code:
  1119. /* the function address is in %gs's slot on the stack */
  1120. pushl_cfi %fs
  1121. /*CFI_REL_OFFSET fs, 0*/
  1122. pushl_cfi %es
  1123. /*CFI_REL_OFFSET es, 0*/
  1124. pushl_cfi %ds
  1125. /*CFI_REL_OFFSET ds, 0*/
  1126. pushl_cfi %eax
  1127. CFI_REL_OFFSET eax, 0
  1128. pushl_cfi %ebp
  1129. CFI_REL_OFFSET ebp, 0
  1130. pushl_cfi %edi
  1131. CFI_REL_OFFSET edi, 0
  1132. pushl_cfi %esi
  1133. CFI_REL_OFFSET esi, 0
  1134. pushl_cfi %edx
  1135. CFI_REL_OFFSET edx, 0
  1136. pushl_cfi %ecx
  1137. CFI_REL_OFFSET ecx, 0
  1138. pushl_cfi %ebx
  1139. CFI_REL_OFFSET ebx, 0
  1140. cld
  1141. movl $(__KERNEL_PERCPU), %ecx
  1142. movl %ecx, %fs
  1143. UNWIND_ESPFIX_STACK
  1144. GS_TO_REG %ecx
  1145. movl PT_GS(%esp), %edi # get the function address
  1146. movl PT_ORIG_EAX(%esp), %edx # get the error code
  1147. movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
  1148. REG_TO_PTGS %ecx
  1149. SET_KERNEL_GS %ecx
  1150. movl $(__USER_DS), %ecx
  1151. movl %ecx, %ds
  1152. movl %ecx, %es
  1153. TRACE_IRQS_OFF
  1154. movl %esp,%eax # pt_regs pointer
  1155. call *%edi
  1156. jmp ret_from_exception
  1157. CFI_ENDPROC
  1158. END(page_fault)
  1159. /*
  1160. * Debug traps and NMI can happen at the one SYSENTER instruction
  1161. * that sets up the real kernel stack. Check here, since we can't
  1162. * allow the wrong stack to be used.
  1163. *
  1164. * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
  1165. * already pushed 3 words if it hits on the sysenter instruction:
  1166. * eflags, cs and eip.
  1167. *
  1168. * We just load the right stack, and push the three (known) values
  1169. * by hand onto the new stack - while updating the return eip past
  1170. * the instruction that would have done it for sysenter.
  1171. */
  1172. .macro FIX_STACK offset ok label
  1173. cmpw $__KERNEL_CS, 4(%esp)
  1174. jne \ok
  1175. \label:
  1176. movl TSS_sysenter_sp0 + \offset(%esp), %esp
  1177. CFI_DEF_CFA esp, 0
  1178. CFI_UNDEFINED eip
  1179. pushfl_cfi
  1180. pushl_cfi $__KERNEL_CS
  1181. pushl_cfi $sysenter_past_esp
  1182. CFI_REL_OFFSET eip, 0
  1183. .endm
  1184. ENTRY(debug)
  1185. RING0_INT_FRAME
  1186. cmpl $ia32_sysenter_target,(%esp)
  1187. jne debug_stack_correct
  1188. FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
  1189. debug_stack_correct:
  1190. pushl_cfi $-1 # mark this as an int
  1191. SAVE_ALL
  1192. TRACE_IRQS_OFF
  1193. xorl %edx,%edx # error code 0
  1194. movl %esp,%eax # pt_regs pointer
  1195. call do_debug
  1196. jmp ret_from_exception
  1197. CFI_ENDPROC
  1198. END(debug)
  1199. /*
  1200. * NMI is doubly nasty. It can happen _while_ we're handling
  1201. * a debug fault, and the debug fault hasn't yet been able to
  1202. * clear up the stack. So we first check whether we got an
  1203. * NMI on the sysenter entry path, but after that we need to
  1204. * check whether we got an NMI on the debug path where the debug
  1205. * fault happened on the sysenter path.
  1206. */
  1207. ENTRY(nmi)
  1208. RING0_INT_FRAME
  1209. pushl_cfi %eax
  1210. movl %ss, %eax
  1211. cmpw $__ESPFIX_SS, %ax
  1212. popl_cfi %eax
  1213. je nmi_espfix_stack
  1214. cmpl $ia32_sysenter_target,(%esp)
  1215. je nmi_stack_fixup
  1216. pushl_cfi %eax
  1217. movl %esp,%eax
  1218. /* Do not access memory above the end of our stack page,
  1219. * it might not exist.
  1220. */
  1221. andl $(THREAD_SIZE-1),%eax
  1222. cmpl $(THREAD_SIZE-20),%eax
  1223. popl_cfi %eax
  1224. jae nmi_stack_correct
  1225. cmpl $ia32_sysenter_target,12(%esp)
  1226. je nmi_debug_stack_check
  1227. nmi_stack_correct:
  1228. /* We have a RING0_INT_FRAME here */
  1229. pushl_cfi %eax
  1230. SAVE_ALL
  1231. xorl %edx,%edx # zero error code
  1232. movl %esp,%eax # pt_regs pointer
  1233. call do_nmi
  1234. jmp restore_all_notrace
  1235. CFI_ENDPROC
  1236. nmi_stack_fixup:
  1237. RING0_INT_FRAME
  1238. FIX_STACK 12, nmi_stack_correct, 1
  1239. jmp nmi_stack_correct
  1240. nmi_debug_stack_check:
  1241. /* We have a RING0_INT_FRAME here */
  1242. cmpw $__KERNEL_CS,16(%esp)
  1243. jne nmi_stack_correct
  1244. cmpl $debug,(%esp)
  1245. jb nmi_stack_correct
  1246. cmpl $debug_esp_fix_insn,(%esp)
  1247. ja nmi_stack_correct
  1248. FIX_STACK 24, nmi_stack_correct, 1
  1249. jmp nmi_stack_correct
  1250. nmi_espfix_stack:
  1251. /* We have a RING0_INT_FRAME here.
  1252. *
  1253. * create the pointer to lss back
  1254. */
  1255. pushl_cfi %ss
  1256. pushl_cfi %esp
  1257. addl $4, (%esp)
  1258. /* copy the iret frame of 12 bytes */
  1259. .rept 3
  1260. pushl_cfi 16(%esp)
  1261. .endr
  1262. pushl_cfi %eax
  1263. SAVE_ALL
  1264. FIXUP_ESPFIX_STACK # %eax == %esp
  1265. xorl %edx,%edx # zero error code
  1266. call do_nmi
  1267. RESTORE_REGS
  1268. lss 12+4(%esp), %esp # back to espfix stack
  1269. CFI_ADJUST_CFA_OFFSET -24
  1270. jmp irq_return
  1271. CFI_ENDPROC
  1272. END(nmi)
  1273. ENTRY(int3)
  1274. RING0_INT_FRAME
  1275. pushl_cfi $-1 # mark this as an int
  1276. SAVE_ALL
  1277. TRACE_IRQS_OFF
  1278. xorl %edx,%edx # zero error code
  1279. movl %esp,%eax # pt_regs pointer
  1280. call do_int3
  1281. jmp ret_from_exception
  1282. CFI_ENDPROC
  1283. END(int3)
  1284. ENTRY(general_protection)
  1285. RING0_EC_FRAME
  1286. pushl_cfi $do_general_protection
  1287. jmp error_code
  1288. CFI_ENDPROC
  1289. END(general_protection)
  1290. /*
  1291. * End of kprobes section
  1292. */
  1293. .popsection