entry.S 21 KB

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