entry.S 20 KB

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