syscall_stub.S 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. .globl syscall_stub
  9. syscall_stub:
  10. /* Disable interrupts for the duration of the syscall: the trap gate keeps
  11. * IF=1, so otherwise the PIT could fire and the context switch would switch
  12. * the stack out from under us mid-syscall. Blocking syscalls (sleep/exit)
  13. * re-enable interrupts themselves. */
  14. cli
  15. /* Load the kernel data segment into DS/ES/FS/GS. int 0x80 only switches
  16. * CS and SS; IRET reset DS (etc.) to null when it returned to ring-3, so
  17. * DS is null here and the C dispatcher's data accesses would #GP. */
  18. pushl %eax
  19. movw $0x10, %ax
  20. movw %ax, %ds
  21. movw %ax, %es
  22. movw %ax, %fs
  23. movw %ax, %gs
  24. popl %eax
  25. pusha
  26. pushl %edx
  27. pushl %ecx
  28. pushl %ebx
  29. pushl %eax
  30. call syscall_dispatch
  31. addl $16, %esp
  32. movl %eax, 28(%esp) /* overwrite the saved eax with the return value */
  33. popa
  34. iret