entry_32.S 32 KB

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