entry_32.S 33 KB

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