entry_32.S 31 KB

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