entry_32.S 31 KB

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