entry_32.S 28 KB

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