entry_32.S 33 KB

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