entry_32.S 32 KB

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