entry.S 22 KB

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