《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
756 B

  1. .text
  2. .globl switch_to
  3. switch_to: # switch_to(from, to)
  4. # save from's registers
  5. movl 4(%esp), %eax # eax points to from
  6. popl 0(%eax) # save eip !popl
  7. movl %esp, 4(%eax)
  8. movl %ebx, 8(%eax)
  9. movl %ecx, 12(%eax)
  10. movl %edx, 16(%eax)
  11. movl %esi, 20(%eax)
  12. movl %edi, 24(%eax)
  13. movl %ebp, 28(%eax)
  14. # restore to's registers
  15. movl 4(%esp), %eax # not 8(%esp): popped return address already
  16. # eax now points to to
  17. movl 28(%eax), %ebp
  18. movl 24(%eax), %edi
  19. movl 20(%eax), %esi
  20. movl 16(%eax), %edx
  21. movl 12(%eax), %ecx
  22. movl 8(%eax), %ebx
  23. movl 4(%eax), %esp
  24. pushl 0(%eax) # push eip
  25. ret