entry.S 23 KB

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