entry_32.S 33 KB

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