user.S 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Return to Userspace (from thread creation) */
  2. .global return_to_userspace
  3. .type return_to_userspace, @function
  4. return_to_userspace:
  5. pop %gs
  6. pop %fs
  7. pop %es
  8. pop %ds
  9. popa
  10. add $8, %esp
  11. iret
  12. /* Enter userspace (ring3) */
  13. .global enter_userspace
  14. .type enter_userspace, @function
  15. .set MAGIC, 0xDECADE21
  16. enter_userspace:
  17. pushl %ebp
  18. mov %esp, %ebp
  19. mov 0xC(%ebp), %edx
  20. mov %edx, %esp
  21. pushl $MAGIC
  22. /* Segement selector */
  23. mov $0x23,%ax
  24. /* Save segement registers */
  25. mov %eax, %ds
  26. mov %eax, %es
  27. mov %eax, %fs
  28. mov %eax, %gs
  29. /* %ss is handled by iret */
  30. /* Store stack address in %eax */
  31. mov %esp, %eax
  32. /* Data segmenet with bottom 2 bits set for ring3 */
  33. pushl $0x23
  34. /* Push the stack address */
  35. pushl %eax
  36. /* Push flags and fix interrupt flag */
  37. pushf
  38. popl %eax
  39. /* Request ring3 */
  40. orl $0x200, %eax
  41. pushl %eax
  42. pushl $0x1B
  43. /* Push entry point */
  44. pushl 0x8(%ebp)
  45. iret
  46. popl %ebp
  47. ret