entry.S 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. /*
  2. * linux/arch/i386/entry.S
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /*
  7. * entry.S contains the system-call and fault low-level handling routines.
  8. * This also contains the timer-interrupt handler, as well as all interrupts
  9. * and faults that can result in a task-switch.
  10. *
  11. * NOTE: This code handles signal-recognition, which happens every time
  12. * after a timer-interrupt and after each system call.
  13. *
  14. * I changed all the .align's to 4 (16 byte alignment), as that's faster
  15. * on a 486.
  16. *
  17. * Stack layout in 'ret_from_system_call':
  18. * ptrace needs to have all regs on the stack.
  19. * if the order here is changed, it needs to be
  20. * updated in fork.c:copy_process, signal.c:do_signal,
  21. * ptrace.c and ptrace.h
  22. *
  23. * 0(%esp) - %ebx
  24. * 4(%esp) - %ecx
  25. * 8(%esp) - %edx
  26. * C(%esp) - %esi
  27. * 10(%esp) - %edi
  28. * 14(%esp) - %ebp
  29. * 18(%esp) - %eax
  30. * 1C(%esp) - %ds
  31. * 20(%esp) - %es
  32. * 24(%esp) - %gs
  33. * 28(%esp) - orig_eax
  34. * 2C(%esp) - %eip
  35. * 30(%esp) - %cs
  36. * 34(%esp) - %eflags
  37. * 38(%esp) - %oldesp
  38. * 3C(%esp) - %oldss
  39. *
  40. * "current" is in register %ebx during any slow entries.
  41. */
  42. #include <linux/linkage.h>
  43. #include <asm/thread_info.h>
  44. #include <asm/irqflags.h>
  45. #include <asm/errno.h>
  46. #include <asm/segment.h>
  47. #include <asm/smp.h>
  48. #include <asm/page.h>
  49. #include <asm/desc.h>
  50. #include <asm/percpu.h>
  51. #include <asm/dwarf2.h>
  52. #include "irq_vectors.h"
  53. #define nr_syscalls ((syscall_table_size)/4)
  54. CF_MASK = 0x00000001
  55. TF_MASK = 0x00000100
  56. IF_MASK = 0x00000200
  57. DF_MASK = 0x00000400
  58. NT_MASK = 0x00004000
  59. VM_MASK = 0x00020000
  60. #ifdef CONFIG_PREEMPT
  61. #define preempt_stop DISABLE_INTERRUPTS; TRACE_IRQS_OFF
  62. #else
  63. #define preempt_stop
  64. #define resume_kernel restore_nocheck
  65. #endif
  66. .macro TRACE_IRQS_IRET
  67. #ifdef CONFIG_TRACE_IRQFLAGS
  68. testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off?
  69. jz 1f
  70. TRACE_IRQS_ON
  71. 1:
  72. #endif
  73. .endm
  74. #ifdef CONFIG_VM86
  75. #define resume_userspace_sig check_userspace
  76. #else
  77. #define resume_userspace_sig resume_userspace
  78. #endif
  79. #define SAVE_ALL \
  80. cld; \
  81. pushl %gs; \
  82. CFI_ADJUST_CFA_OFFSET 4;\
  83. /*CFI_REL_OFFSET gs, 0;*/\
  84. pushl %es; \
  85. CFI_ADJUST_CFA_OFFSET 4;\
  86. /*CFI_REL_OFFSET es, 0;*/\
  87. pushl %ds; \
  88. CFI_ADJUST_CFA_OFFSET 4;\
  89. /*CFI_REL_OFFSET ds, 0;*/\
  90. pushl %eax; \
  91. CFI_ADJUST_CFA_OFFSET 4;\
  92. CFI_REL_OFFSET eax, 0;\
  93. pushl %ebp; \
  94. CFI_ADJUST_CFA_OFFSET 4;\
  95. CFI_REL_OFFSET ebp, 0;\
  96. pushl %edi; \
  97. CFI_ADJUST_CFA_OFFSET 4;\
  98. CFI_REL_OFFSET edi, 0;\
  99. pushl %esi; \
  100. CFI_ADJUST_CFA_OFFSET 4;\
  101. CFI_REL_OFFSET esi, 0;\
  102. pushl %edx; \
  103. CFI_ADJUST_CFA_OFFSET 4;\
  104. CFI_REL_OFFSET edx, 0;\
  105. pushl %ecx; \
  106. CFI_ADJUST_CFA_OFFSET 4;\
  107. CFI_REL_OFFSET ecx, 0;\
  108. pushl %ebx; \
  109. CFI_ADJUST_CFA_OFFSET 4;\
  110. CFI_REL_OFFSET ebx, 0;\
  111. movl $(__USER_DS), %edx; \
  112. movl %edx, %ds; \
  113. movl %edx, %es; \
  114. movl $(__KERNEL_PDA), %edx; \
  115. movl %edx, %gs
  116. #define RESTORE_INT_REGS \
  117. popl %ebx; \
  118. CFI_ADJUST_CFA_OFFSET -4;\
  119. CFI_RESTORE ebx;\
  120. popl %ecx; \
  121. CFI_ADJUST_CFA_OFFSET -4;\
  122. CFI_RESTORE ecx;\
  123. popl %edx; \
  124. CFI_ADJUST_CFA_OFFSET -4;\
  125. CFI_RESTORE edx;\
  126. popl %esi; \
  127. CFI_ADJUST_CFA_OFFSET -4;\
  128. CFI_RESTORE esi;\
  129. popl %edi; \
  130. CFI_ADJUST_CFA_OFFSET -4;\
  131. CFI_RESTORE edi;\
  132. popl %ebp; \
  133. CFI_ADJUST_CFA_OFFSET -4;\
  134. CFI_RESTORE ebp;\
  135. popl %eax; \
  136. CFI_ADJUST_CFA_OFFSET -4;\
  137. CFI_RESTORE eax
  138. #define RESTORE_REGS \
  139. RESTORE_INT_REGS; \
  140. 1: popl %ds; \
  141. CFI_ADJUST_CFA_OFFSET -4;\
  142. /*CFI_RESTORE ds;*/\
  143. 2: popl %es; \
  144. CFI_ADJUST_CFA_OFFSET -4;\
  145. /*CFI_RESTORE es;*/\
  146. 3: popl %gs; \
  147. CFI_ADJUST_CFA_OFFSET -4;\
  148. /*CFI_RESTORE gs;*/\
  149. .pushsection .fixup,"ax"; \
  150. 4: movl $0,(%esp); \
  151. jmp 1b; \
  152. 5: movl $0,(%esp); \
  153. jmp 2b; \
  154. 6: movl $0,(%esp); \
  155. jmp 3b; \
  156. .section __ex_table,"a";\
  157. .align 4; \
  158. .long 1b,4b; \
  159. .long 2b,5b; \
  160. .long 3b,6b; \
  161. .popsection
  162. #define RING0_INT_FRAME \
  163. CFI_STARTPROC simple;\
  164. CFI_SIGNAL_FRAME;\
  165. CFI_DEF_CFA esp, 3*4;\
  166. /*CFI_OFFSET cs, -2*4;*/\
  167. CFI_OFFSET eip, -3*4
  168. #define RING0_EC_FRAME \
  169. CFI_STARTPROC simple;\
  170. CFI_SIGNAL_FRAME;\
  171. CFI_DEF_CFA esp, 4*4;\
  172. /*CFI_OFFSET cs, -2*4;*/\
  173. CFI_OFFSET eip, -3*4
  174. #define RING0_PTREGS_FRAME \
  175. CFI_STARTPROC simple;\
  176. CFI_SIGNAL_FRAME;\
  177. CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
  178. /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
  179. CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
  180. /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
  181. /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
  182. CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
  183. CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
  184. CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
  185. CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
  186. CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
  187. CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
  188. CFI_OFFSET ebx, PT_EBX-PT_OLDESP
  189. ENTRY(ret_from_fork)
  190. CFI_STARTPROC
  191. pushl %eax
  192. CFI_ADJUST_CFA_OFFSET 4
  193. call schedule_tail
  194. GET_THREAD_INFO(%ebp)
  195. popl %eax
  196. CFI_ADJUST_CFA_OFFSET -4
  197. pushl $0x0202 # Reset kernel eflags
  198. CFI_ADJUST_CFA_OFFSET 4
  199. popfl
  200. CFI_ADJUST_CFA_OFFSET -4
  201. jmp syscall_exit
  202. CFI_ENDPROC
  203. /*
  204. * Return to user mode is not as complex as all this looks,
  205. * but we want the default path for a system call return to
  206. * go as quickly as possible which is why some of this is
  207. * less clear than it otherwise should be.
  208. */
  209. # userspace resumption stub bypassing syscall exit tracing
  210. ALIGN
  211. RING0_PTREGS_FRAME
  212. ret_from_exception:
  213. preempt_stop
  214. ret_from_intr:
  215. GET_THREAD_INFO(%ebp)
  216. check_userspace:
  217. movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
  218. movb PT_CS(%esp), %al
  219. andl $(VM_MASK | SEGMENT_RPL_MASK), %eax
  220. cmpl $USER_RPL, %eax
  221. jb resume_kernel # not returning to v8086 or userspace
  222. ENTRY(resume_userspace)
  223. DISABLE_INTERRUPTS # make sure we don't miss an interrupt
  224. # setting need_resched or sigpending
  225. # between sampling and the iret
  226. movl TI_flags(%ebp), %ecx
  227. andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
  228. # int/exception return?
  229. jne work_pending
  230. jmp restore_all
  231. #ifdef CONFIG_PREEMPT
  232. ENTRY(resume_kernel)
  233. DISABLE_INTERRUPTS
  234. cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
  235. jnz restore_nocheck
  236. need_resched:
  237. movl TI_flags(%ebp), %ecx # need_resched set ?
  238. testb $_TIF_NEED_RESCHED, %cl
  239. jz restore_all
  240. testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off (exception path) ?
  241. jz restore_all
  242. call preempt_schedule_irq
  243. jmp need_resched
  244. #endif
  245. CFI_ENDPROC
  246. /* SYSENTER_RETURN points to after the "sysenter" instruction in
  247. the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
  248. # sysenter call handler stub
  249. ENTRY(sysenter_entry)
  250. CFI_STARTPROC simple
  251. CFI_SIGNAL_FRAME
  252. CFI_DEF_CFA esp, 0
  253. CFI_REGISTER esp, ebp
  254. movl TSS_sysenter_esp0(%esp),%esp
  255. sysenter_past_esp:
  256. /*
  257. * No need to follow this irqs on/off section: the syscall
  258. * disabled irqs and here we enable it straight after entry:
  259. */
  260. ENABLE_INTERRUPTS
  261. pushl $(__USER_DS)
  262. CFI_ADJUST_CFA_OFFSET 4
  263. /*CFI_REL_OFFSET ss, 0*/
  264. pushl %ebp
  265. CFI_ADJUST_CFA_OFFSET 4
  266. CFI_REL_OFFSET esp, 0
  267. pushfl
  268. CFI_ADJUST_CFA_OFFSET 4
  269. pushl $(__USER_CS)
  270. CFI_ADJUST_CFA_OFFSET 4
  271. /*CFI_REL_OFFSET cs, 0*/
  272. /*
  273. * Push current_thread_info()->sysenter_return to the stack.
  274. * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
  275. * pushed above; +8 corresponds to copy_thread's esp0 setting.
  276. */
  277. pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
  278. CFI_ADJUST_CFA_OFFSET 4
  279. CFI_REL_OFFSET eip, 0
  280. /*
  281. * Load the potential sixth argument from user stack.
  282. * Careful about security.
  283. */
  284. cmpl $__PAGE_OFFSET-3,%ebp
  285. jae syscall_fault
  286. 1: movl (%ebp),%ebp
  287. .section __ex_table,"a"
  288. .align 4
  289. .long 1b,syscall_fault
  290. .previous
  291. pushl %eax
  292. CFI_ADJUST_CFA_OFFSET 4
  293. SAVE_ALL
  294. GET_THREAD_INFO(%ebp)
  295. /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
  296. testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  297. jnz syscall_trace_entry
  298. cmpl $(nr_syscalls), %eax
  299. jae syscall_badsys
  300. call *sys_call_table(,%eax,4)
  301. movl %eax,PT_EAX(%esp)
  302. DISABLE_INTERRUPTS
  303. TRACE_IRQS_OFF
  304. movl TI_flags(%ebp), %ecx
  305. testw $_TIF_ALLWORK_MASK, %cx
  306. jne syscall_exit_work
  307. /* if something modifies registers it must also disable sysexit */
  308. movl PT_EIP(%esp), %edx
  309. movl PT_OLDESP(%esp), %ecx
  310. xorl %ebp,%ebp
  311. TRACE_IRQS_ON
  312. 1: mov PT_GS(%esp), %gs
  313. ENABLE_INTERRUPTS_SYSEXIT
  314. CFI_ENDPROC
  315. .pushsection .fixup,"ax"
  316. 2: movl $0,PT_GS(%esp)
  317. jmp 1b
  318. .section __ex_table,"a"
  319. .align 4
  320. .long 1b,2b
  321. .popsection
  322. # system call handler stub
  323. ENTRY(system_call)
  324. RING0_INT_FRAME # can't unwind into user space anyway
  325. pushl %eax # save orig_eax
  326. CFI_ADJUST_CFA_OFFSET 4
  327. SAVE_ALL
  328. GET_THREAD_INFO(%ebp)
  329. testl $TF_MASK,PT_EFLAGS(%esp)
  330. jz no_singlestep
  331. orl $_TIF_SINGLESTEP,TI_flags(%ebp)
  332. no_singlestep:
  333. # system call tracing in operation / emulation
  334. /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
  335. testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  336. jnz syscall_trace_entry
  337. cmpl $(nr_syscalls), %eax
  338. jae syscall_badsys
  339. syscall_call:
  340. call *sys_call_table(,%eax,4)
  341. movl %eax,PT_EAX(%esp) # store the return value
  342. syscall_exit:
  343. DISABLE_INTERRUPTS # make sure we don't miss an interrupt
  344. # setting need_resched or sigpending
  345. # between sampling and the iret
  346. TRACE_IRQS_OFF
  347. movl TI_flags(%ebp), %ecx
  348. testw $_TIF_ALLWORK_MASK, %cx # current->work
  349. jne syscall_exit_work
  350. restore_all:
  351. movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
  352. # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
  353. # are returning to the kernel.
  354. # See comments in process.c:copy_thread() for details.
  355. movb PT_OLDSS(%esp), %ah
  356. movb PT_CS(%esp), %al
  357. andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
  358. cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
  359. CFI_REMEMBER_STATE
  360. je ldt_ss # returning to user-space with LDT SS
  361. restore_nocheck:
  362. TRACE_IRQS_IRET
  363. restore_nocheck_notrace:
  364. RESTORE_REGS
  365. addl $4, %esp # skip orig_eax/error_code
  366. CFI_ADJUST_CFA_OFFSET -4
  367. 1: INTERRUPT_RETURN
  368. .section .fixup,"ax"
  369. iret_exc:
  370. TRACE_IRQS_ON
  371. ENABLE_INTERRUPTS
  372. pushl $0 # no error code
  373. pushl $do_iret_error
  374. jmp error_code
  375. .previous
  376. .section __ex_table,"a"
  377. .align 4
  378. .long 1b,iret_exc
  379. .previous
  380. CFI_RESTORE_STATE
  381. ldt_ss:
  382. larl PT_OLDSS(%esp), %eax
  383. jnz restore_nocheck
  384. testl $0x00400000, %eax # returning to 32bit stack?
  385. jnz restore_nocheck # allright, normal return
  386. #ifdef CONFIG_PARAVIRT
  387. /*
  388. * The kernel can't run on a non-flat stack if paravirt mode
  389. * is active. Rather than try to fixup the high bits of
  390. * ESP, bypass this code entirely. This may break DOSemu
  391. * and/or Wine support in a paravirt VM, although the option
  392. * is still available to implement the setting of the high
  393. * 16-bits in the INTERRUPT_RETURN paravirt-op.
  394. */
  395. cmpl $0, paravirt_ops+PARAVIRT_enabled
  396. jne restore_nocheck
  397. #endif
  398. /* If returning to userspace with 16bit stack,
  399. * try to fix the higher word of ESP, as the CPU
  400. * won't restore it.
  401. * This is an "official" bug of all the x86-compatible
  402. * CPUs, which we can try to work around to make
  403. * dosemu and wine happy. */
  404. movl PT_OLDESP(%esp), %eax
  405. movl %esp, %edx
  406. call patch_espfix_desc
  407. pushl $__ESPFIX_SS
  408. CFI_ADJUST_CFA_OFFSET 4
  409. pushl %eax
  410. CFI_ADJUST_CFA_OFFSET 4
  411. DISABLE_INTERRUPTS
  412. TRACE_IRQS_OFF
  413. lss (%esp), %esp
  414. CFI_ADJUST_CFA_OFFSET -8
  415. jmp restore_nocheck
  416. CFI_ENDPROC
  417. # perform work that needs to be done immediately before resumption
  418. ALIGN
  419. RING0_PTREGS_FRAME # can't unwind into user space anyway
  420. work_pending:
  421. testb $_TIF_NEED_RESCHED, %cl
  422. jz work_notifysig
  423. work_resched:
  424. call schedule
  425. DISABLE_INTERRUPTS # make sure we don't miss an interrupt
  426. # setting need_resched or sigpending
  427. # between sampling and the iret
  428. TRACE_IRQS_OFF
  429. movl TI_flags(%ebp), %ecx
  430. andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
  431. # than syscall tracing?
  432. jz restore_all
  433. testb $_TIF_NEED_RESCHED, %cl
  434. jnz work_resched
  435. work_notifysig: # deal with pending signals and
  436. # notify-resume requests
  437. #ifdef CONFIG_VM86
  438. testl $VM_MASK, PT_EFLAGS(%esp)
  439. movl %esp, %eax
  440. jne work_notifysig_v86 # returning to kernel-space or
  441. # vm86-space
  442. xorl %edx, %edx
  443. call do_notify_resume
  444. jmp resume_userspace_sig
  445. ALIGN
  446. work_notifysig_v86:
  447. pushl %ecx # save ti_flags for do_notify_resume
  448. CFI_ADJUST_CFA_OFFSET 4
  449. call save_v86_state # %eax contains pt_regs pointer
  450. popl %ecx
  451. CFI_ADJUST_CFA_OFFSET -4
  452. movl %eax, %esp
  453. #else
  454. movl %esp, %eax
  455. #endif
  456. xorl %edx, %edx
  457. call do_notify_resume
  458. jmp resume_userspace_sig
  459. # perform syscall exit tracing
  460. ALIGN
  461. syscall_trace_entry:
  462. movl $-ENOSYS,PT_EAX(%esp)
  463. movl %esp, %eax
  464. xorl %edx,%edx
  465. call do_syscall_trace
  466. cmpl $0, %eax
  467. jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
  468. # so must skip actual syscall
  469. movl PT_ORIG_EAX(%esp), %eax
  470. cmpl $(nr_syscalls), %eax
  471. jnae syscall_call
  472. jmp syscall_exit
  473. # perform syscall exit tracing
  474. ALIGN
  475. syscall_exit_work:
  476. testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
  477. jz work_pending
  478. TRACE_IRQS_ON
  479. ENABLE_INTERRUPTS # could let do_syscall_trace() call
  480. # schedule() instead
  481. movl %esp, %eax
  482. movl $1, %edx
  483. call do_syscall_trace
  484. jmp resume_userspace
  485. CFI_ENDPROC
  486. RING0_INT_FRAME # can't unwind into user space anyway
  487. syscall_fault:
  488. pushl %eax # save orig_eax
  489. CFI_ADJUST_CFA_OFFSET 4
  490. SAVE_ALL
  491. GET_THREAD_INFO(%ebp)
  492. movl $-EFAULT,PT_EAX(%esp)
  493. jmp resume_userspace
  494. syscall_badsys:
  495. movl $-ENOSYS,PT_EAX(%esp)
  496. jmp resume_userspace
  497. CFI_ENDPROC
  498. #define FIXUP_ESPFIX_STACK \
  499. /* since we are on a wrong stack, we cant make it a C code :( */ \
  500. movl %gs:PDA_cpu, %ebx; \
  501. PER_CPU(cpu_gdt_descr, %ebx); \
  502. movl GDS_address(%ebx), %ebx; \
  503. GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
  504. addl %esp, %eax; \
  505. pushl $__KERNEL_DS; \
  506. CFI_ADJUST_CFA_OFFSET 4; \
  507. pushl %eax; \
  508. CFI_ADJUST_CFA_OFFSET 4; \
  509. lss (%esp), %esp; \
  510. CFI_ADJUST_CFA_OFFSET -8;
  511. #define UNWIND_ESPFIX_STACK \
  512. movl %ss, %eax; \
  513. /* see if on espfix stack */ \
  514. cmpw $__ESPFIX_SS, %ax; \
  515. jne 27f; \
  516. movl $__KERNEL_DS, %eax; \
  517. movl %eax, %ds; \
  518. movl %eax, %es; \
  519. /* switch to normal stack */ \
  520. FIXUP_ESPFIX_STACK; \
  521. 27:;
  522. /*
  523. * Build the entry stubs and pointer table with
  524. * some assembler magic.
  525. */
  526. .data
  527. ENTRY(interrupt)
  528. .text
  529. vector=0
  530. ENTRY(irq_entries_start)
  531. RING0_INT_FRAME
  532. .rept NR_IRQS
  533. ALIGN
  534. .if vector
  535. CFI_ADJUST_CFA_OFFSET -4
  536. .endif
  537. 1: pushl $~(vector)
  538. CFI_ADJUST_CFA_OFFSET 4
  539. jmp common_interrupt
  540. .data
  541. .long 1b
  542. .text
  543. vector=vector+1
  544. .endr
  545. /*
  546. * the CPU automatically disables interrupts when executing an IRQ vector,
  547. * so IRQ-flags tracing has to follow that:
  548. */
  549. ALIGN
  550. common_interrupt:
  551. SAVE_ALL
  552. TRACE_IRQS_OFF
  553. movl %esp,%eax
  554. call do_IRQ
  555. jmp ret_from_intr
  556. CFI_ENDPROC
  557. #define BUILD_INTERRUPT(name, nr) \
  558. ENTRY(name) \
  559. RING0_INT_FRAME; \
  560. pushl $~(nr); \
  561. CFI_ADJUST_CFA_OFFSET 4; \
  562. SAVE_ALL; \
  563. TRACE_IRQS_OFF \
  564. movl %esp,%eax; \
  565. call smp_/**/name; \
  566. jmp ret_from_intr; \
  567. CFI_ENDPROC
  568. /* The include is where all of the SMP etc. interrupts come from */
  569. #include "entry_arch.h"
  570. KPROBE_ENTRY(page_fault)
  571. RING0_EC_FRAME
  572. pushl $do_page_fault
  573. CFI_ADJUST_CFA_OFFSET 4
  574. ALIGN
  575. error_code:
  576. /* the function address is in %gs's slot on the stack */
  577. pushl %es
  578. CFI_ADJUST_CFA_OFFSET 4
  579. /*CFI_REL_OFFSET es, 0*/
  580. pushl %ds
  581. CFI_ADJUST_CFA_OFFSET 4
  582. /*CFI_REL_OFFSET ds, 0*/
  583. pushl %eax
  584. CFI_ADJUST_CFA_OFFSET 4
  585. CFI_REL_OFFSET eax, 0
  586. pushl %ebp
  587. CFI_ADJUST_CFA_OFFSET 4
  588. CFI_REL_OFFSET ebp, 0
  589. pushl %edi
  590. CFI_ADJUST_CFA_OFFSET 4
  591. CFI_REL_OFFSET edi, 0
  592. pushl %esi
  593. CFI_ADJUST_CFA_OFFSET 4
  594. CFI_REL_OFFSET esi, 0
  595. pushl %edx
  596. CFI_ADJUST_CFA_OFFSET 4
  597. CFI_REL_OFFSET edx, 0
  598. pushl %ecx
  599. CFI_ADJUST_CFA_OFFSET 4
  600. CFI_REL_OFFSET ecx, 0
  601. pushl %ebx
  602. CFI_ADJUST_CFA_OFFSET 4
  603. CFI_REL_OFFSET ebx, 0
  604. cld
  605. pushl %gs
  606. CFI_ADJUST_CFA_OFFSET 4
  607. /*CFI_REL_OFFSET gs, 0*/
  608. movl $(__KERNEL_PDA), %ecx
  609. movl %ecx, %gs
  610. UNWIND_ESPFIX_STACK
  611. popl %ecx
  612. CFI_ADJUST_CFA_OFFSET -4
  613. /*CFI_REGISTER es, ecx*/
  614. movl PT_GS(%esp), %edi # get the function address
  615. movl PT_ORIG_EAX(%esp), %edx # get the error code
  616. movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
  617. mov %ecx, PT_GS(%esp)
  618. /*CFI_REL_OFFSET gs, ES*/
  619. movl $(__USER_DS), %ecx
  620. movl %ecx, %ds
  621. movl %ecx, %es
  622. movl %esp,%eax # pt_regs pointer
  623. call *%edi
  624. jmp ret_from_exception
  625. CFI_ENDPROC
  626. KPROBE_END(page_fault)
  627. ENTRY(coprocessor_error)
  628. RING0_INT_FRAME
  629. pushl $0
  630. CFI_ADJUST_CFA_OFFSET 4
  631. pushl $do_coprocessor_error
  632. CFI_ADJUST_CFA_OFFSET 4
  633. jmp error_code
  634. CFI_ENDPROC
  635. ENTRY(simd_coprocessor_error)
  636. RING0_INT_FRAME
  637. pushl $0
  638. CFI_ADJUST_CFA_OFFSET 4
  639. pushl $do_simd_coprocessor_error
  640. CFI_ADJUST_CFA_OFFSET 4
  641. jmp error_code
  642. CFI_ENDPROC
  643. ENTRY(device_not_available)
  644. RING0_INT_FRAME
  645. pushl $-1 # mark this as an int
  646. CFI_ADJUST_CFA_OFFSET 4
  647. SAVE_ALL
  648. GET_CR0_INTO_EAX
  649. testl $0x4, %eax # EM (math emulation bit)
  650. jne device_not_available_emulate
  651. preempt_stop
  652. call math_state_restore
  653. jmp ret_from_exception
  654. device_not_available_emulate:
  655. pushl $0 # temporary storage for ORIG_EIP
  656. CFI_ADJUST_CFA_OFFSET 4
  657. call math_emulate
  658. addl $4, %esp
  659. CFI_ADJUST_CFA_OFFSET -4
  660. jmp ret_from_exception
  661. CFI_ENDPROC
  662. /*
  663. * Debug traps and NMI can happen at the one SYSENTER instruction
  664. * that sets up the real kernel stack. Check here, since we can't
  665. * allow the wrong stack to be used.
  666. *
  667. * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
  668. * already pushed 3 words if it hits on the sysenter instruction:
  669. * eflags, cs and eip.
  670. *
  671. * We just load the right stack, and push the three (known) values
  672. * by hand onto the new stack - while updating the return eip past
  673. * the instruction that would have done it for sysenter.
  674. */
  675. #define FIX_STACK(offset, ok, label) \
  676. cmpw $__KERNEL_CS,4(%esp); \
  677. jne ok; \
  678. label: \
  679. movl TSS_sysenter_esp0+offset(%esp),%esp; \
  680. CFI_DEF_CFA esp, 0; \
  681. CFI_UNDEFINED eip; \
  682. pushfl; \
  683. CFI_ADJUST_CFA_OFFSET 4; \
  684. pushl $__KERNEL_CS; \
  685. CFI_ADJUST_CFA_OFFSET 4; \
  686. pushl $sysenter_past_esp; \
  687. CFI_ADJUST_CFA_OFFSET 4; \
  688. CFI_REL_OFFSET eip, 0
  689. KPROBE_ENTRY(debug)
  690. RING0_INT_FRAME
  691. cmpl $sysenter_entry,(%esp)
  692. jne debug_stack_correct
  693. FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
  694. debug_stack_correct:
  695. pushl $-1 # mark this as an int
  696. CFI_ADJUST_CFA_OFFSET 4
  697. SAVE_ALL
  698. xorl %edx,%edx # error code 0
  699. movl %esp,%eax # pt_regs pointer
  700. call do_debug
  701. jmp ret_from_exception
  702. CFI_ENDPROC
  703. KPROBE_END(debug)
  704. /*
  705. * NMI is doubly nasty. It can happen _while_ we're handling
  706. * a debug fault, and the debug fault hasn't yet been able to
  707. * clear up the stack. So we first check whether we got an
  708. * NMI on the sysenter entry path, but after that we need to
  709. * check whether we got an NMI on the debug path where the debug
  710. * fault happened on the sysenter path.
  711. */
  712. KPROBE_ENTRY(nmi)
  713. RING0_INT_FRAME
  714. pushl %eax
  715. CFI_ADJUST_CFA_OFFSET 4
  716. movl %ss, %eax
  717. cmpw $__ESPFIX_SS, %ax
  718. popl %eax
  719. CFI_ADJUST_CFA_OFFSET -4
  720. je nmi_espfix_stack
  721. cmpl $sysenter_entry,(%esp)
  722. je nmi_stack_fixup
  723. pushl %eax
  724. CFI_ADJUST_CFA_OFFSET 4
  725. movl %esp,%eax
  726. /* Do not access memory above the end of our stack page,
  727. * it might not exist.
  728. */
  729. andl $(THREAD_SIZE-1),%eax
  730. cmpl $(THREAD_SIZE-20),%eax
  731. popl %eax
  732. CFI_ADJUST_CFA_OFFSET -4
  733. jae nmi_stack_correct
  734. cmpl $sysenter_entry,12(%esp)
  735. je nmi_debug_stack_check
  736. nmi_stack_correct:
  737. /* We have a RING0_INT_FRAME here */
  738. pushl %eax
  739. CFI_ADJUST_CFA_OFFSET 4
  740. SAVE_ALL
  741. xorl %edx,%edx # zero error code
  742. movl %esp,%eax # pt_regs pointer
  743. call do_nmi
  744. jmp restore_nocheck_notrace
  745. CFI_ENDPROC
  746. nmi_stack_fixup:
  747. RING0_INT_FRAME
  748. FIX_STACK(12,nmi_stack_correct, 1)
  749. jmp nmi_stack_correct
  750. nmi_debug_stack_check:
  751. /* We have a RING0_INT_FRAME here */
  752. cmpw $__KERNEL_CS,16(%esp)
  753. jne nmi_stack_correct
  754. cmpl $debug,(%esp)
  755. jb nmi_stack_correct
  756. cmpl $debug_esp_fix_insn,(%esp)
  757. ja nmi_stack_correct
  758. FIX_STACK(24,nmi_stack_correct, 1)
  759. jmp nmi_stack_correct
  760. nmi_espfix_stack:
  761. /* We have a RING0_INT_FRAME here.
  762. *
  763. * create the pointer to lss back
  764. */
  765. pushl %ss
  766. CFI_ADJUST_CFA_OFFSET 4
  767. pushl %esp
  768. CFI_ADJUST_CFA_OFFSET 4
  769. addw $4, (%esp)
  770. /* copy the iret frame of 12 bytes */
  771. .rept 3
  772. pushl 16(%esp)
  773. CFI_ADJUST_CFA_OFFSET 4
  774. .endr
  775. pushl %eax
  776. CFI_ADJUST_CFA_OFFSET 4
  777. SAVE_ALL
  778. FIXUP_ESPFIX_STACK # %eax == %esp
  779. xorl %edx,%edx # zero error code
  780. call do_nmi
  781. RESTORE_REGS
  782. lss 12+4(%esp), %esp # back to espfix stack
  783. CFI_ADJUST_CFA_OFFSET -24
  784. 1: INTERRUPT_RETURN
  785. CFI_ENDPROC
  786. .section __ex_table,"a"
  787. .align 4
  788. .long 1b,iret_exc
  789. .previous
  790. KPROBE_END(nmi)
  791. #ifdef CONFIG_PARAVIRT
  792. ENTRY(native_iret)
  793. 1: iret
  794. .section __ex_table,"a"
  795. .align 4
  796. .long 1b,iret_exc
  797. .previous
  798. ENTRY(native_irq_enable_sysexit)
  799. sti
  800. sysexit
  801. #endif
  802. KPROBE_ENTRY(int3)
  803. RING0_INT_FRAME
  804. pushl $-1 # mark this as an int
  805. CFI_ADJUST_CFA_OFFSET 4
  806. SAVE_ALL
  807. xorl %edx,%edx # zero error code
  808. movl %esp,%eax # pt_regs pointer
  809. call do_int3
  810. jmp ret_from_exception
  811. CFI_ENDPROC
  812. KPROBE_END(int3)
  813. ENTRY(overflow)
  814. RING0_INT_FRAME
  815. pushl $0
  816. CFI_ADJUST_CFA_OFFSET 4
  817. pushl $do_overflow
  818. CFI_ADJUST_CFA_OFFSET 4
  819. jmp error_code
  820. CFI_ENDPROC
  821. ENTRY(bounds)
  822. RING0_INT_FRAME
  823. pushl $0
  824. CFI_ADJUST_CFA_OFFSET 4
  825. pushl $do_bounds
  826. CFI_ADJUST_CFA_OFFSET 4
  827. jmp error_code
  828. CFI_ENDPROC
  829. ENTRY(invalid_op)
  830. RING0_INT_FRAME
  831. pushl $0
  832. CFI_ADJUST_CFA_OFFSET 4
  833. pushl $do_invalid_op
  834. CFI_ADJUST_CFA_OFFSET 4
  835. jmp error_code
  836. CFI_ENDPROC
  837. ENTRY(coprocessor_segment_overrun)
  838. RING0_INT_FRAME
  839. pushl $0
  840. CFI_ADJUST_CFA_OFFSET 4
  841. pushl $do_coprocessor_segment_overrun
  842. CFI_ADJUST_CFA_OFFSET 4
  843. jmp error_code
  844. CFI_ENDPROC
  845. ENTRY(invalid_TSS)
  846. RING0_EC_FRAME
  847. pushl $do_invalid_TSS
  848. CFI_ADJUST_CFA_OFFSET 4
  849. jmp error_code
  850. CFI_ENDPROC
  851. ENTRY(segment_not_present)
  852. RING0_EC_FRAME
  853. pushl $do_segment_not_present
  854. CFI_ADJUST_CFA_OFFSET 4
  855. jmp error_code
  856. CFI_ENDPROC
  857. ENTRY(stack_segment)
  858. RING0_EC_FRAME
  859. pushl $do_stack_segment
  860. CFI_ADJUST_CFA_OFFSET 4
  861. jmp error_code
  862. CFI_ENDPROC
  863. KPROBE_ENTRY(general_protection)
  864. RING0_EC_FRAME
  865. pushl $do_general_protection
  866. CFI_ADJUST_CFA_OFFSET 4
  867. jmp error_code
  868. CFI_ENDPROC
  869. KPROBE_END(general_protection)
  870. ENTRY(alignment_check)
  871. RING0_EC_FRAME
  872. pushl $do_alignment_check
  873. CFI_ADJUST_CFA_OFFSET 4
  874. jmp error_code
  875. CFI_ENDPROC
  876. ENTRY(divide_error)
  877. RING0_INT_FRAME
  878. pushl $0 # no error code
  879. CFI_ADJUST_CFA_OFFSET 4
  880. pushl $do_divide_error
  881. CFI_ADJUST_CFA_OFFSET 4
  882. jmp error_code
  883. CFI_ENDPROC
  884. #ifdef CONFIG_X86_MCE
  885. ENTRY(machine_check)
  886. RING0_INT_FRAME
  887. pushl $0
  888. CFI_ADJUST_CFA_OFFSET 4
  889. pushl machine_check_vector
  890. CFI_ADJUST_CFA_OFFSET 4
  891. jmp error_code
  892. CFI_ENDPROC
  893. #endif
  894. ENTRY(spurious_interrupt_bug)
  895. RING0_INT_FRAME
  896. pushl $0
  897. CFI_ADJUST_CFA_OFFSET 4
  898. pushl $do_spurious_interrupt_bug
  899. CFI_ADJUST_CFA_OFFSET 4
  900. jmp error_code
  901. CFI_ENDPROC
  902. #ifdef CONFIG_STACK_UNWIND
  903. ENTRY(arch_unwind_init_running)
  904. CFI_STARTPROC
  905. movl 4(%esp), %edx
  906. movl (%esp), %ecx
  907. leal 4(%esp), %eax
  908. movl %ebx, PT_EBX(%edx)
  909. xorl %ebx, %ebx
  910. movl %ebx, PT_ECX(%edx)
  911. movl %ebx, PT_EDX(%edx)
  912. movl %esi, PT_ESI(%edx)
  913. movl %edi, PT_EDI(%edx)
  914. movl %ebp, PT_EBP(%edx)
  915. movl %ebx, PT_EAX(%edx)
  916. movl $__USER_DS, PT_DS(%edx)
  917. movl $__USER_DS, PT_ES(%edx)
  918. movl $0, PT_GS(%edx)
  919. movl %ebx, PT_ORIG_EAX(%edx)
  920. movl %ecx, PT_EIP(%edx)
  921. movl 12(%esp), %ecx
  922. movl $__KERNEL_CS, PT_CS(%edx)
  923. movl %ebx, PT_EFLAGS(%edx)
  924. movl %eax, PT_OLDESP(%edx)
  925. movl 8(%esp), %eax
  926. movl %ecx, 8(%esp)
  927. movl PT_EBX(%edx), %ebx
  928. movl $__KERNEL_DS, PT_OLDSS(%edx)
  929. jmpl *%eax
  930. CFI_ENDPROC
  931. ENDPROC(arch_unwind_init_running)
  932. #endif
  933. ENTRY(kernel_thread_helper)
  934. pushl $0 # fake return address for unwinder
  935. CFI_STARTPROC
  936. movl %edx,%eax
  937. push %edx
  938. CFI_ADJUST_CFA_OFFSET 4
  939. call *%ebx
  940. push %eax
  941. CFI_ADJUST_CFA_OFFSET 4
  942. call do_exit
  943. CFI_ENDPROC
  944. ENDPROC(kernel_thread_helper)
  945. .section .rodata,"a"
  946. #include "syscall_table.S"
  947. syscall_table_size=(.-sys_call_table)