entry_32.S 33 KB

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