entry.S 21 KB

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