syscall_stub.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* int 0x80 syscall stub (ring-3 -> ring-0).
  2. *
  3. * On entry the CPU has pushed SS, ESP, EFLAGS, CS, EIP (from ring-3).
  4. * Registers: eax = syscall number, ebx/ecx/edx = args 1..3.
  5. * The dispatcher's return value is placed in eax before returning to user. */
  6. .code32
  7. .text
  8. .include "irqret.inc"
  9. .globl syscall_stub
  10. syscall_stub:
  11. /* Disable interrupts for the duration of the syscall: the trap gate keeps
  12. * IF=1, so otherwise the PIT could fire and the context switch would switch
  13. * the stack out from under us mid-syscall. Blocking syscalls (sleep/exit)
  14. * re-enable interrupts themselves. */
  15. cli
  16. /* Load the kernel data segment into DS/ES/FS/GS. int 0x80 only switches
  17. * CS and SS; IRET reset DS (etc.) to null when it returned to ring-3, so
  18. * DS is null here and the C dispatcher's data accesses would #GP. */
  19. pushl %eax
  20. movw $0x10, %ax
  21. movw %ax, %ds
  22. movw %ax, %es
  23. movw %ax, %fs
  24. movw %ax, %gs
  25. popl %eax
  26. pusha
  27. pushl %edx
  28. pushl %ecx
  29. pushl %ebx
  30. pushl %eax
  31. call syscall_dispatch
  32. addl $16, %esp
  33. movl %eax, 28(%esp) /* overwrite the saved eax with the return value */
  34. /* Returning to the ring-3 caller: leave it a usable data selector (the
  35. * IRET would null 0x10, and user code #GPs on its first data access).
  36. * See irqret.inc for the why; this gate is ring-3-only. */
  37. IRQ_RETURN_DS 36
  38. popa
  39. iret