entry.S 22 KB

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