entry.S 20 KB

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