Skip to content
Snippets Groups Projects
swtch.S 461 B
Newer Older
# Context switch
#
#   void swtch(struct context **old, struct context *new);
# 
rsc's avatar
rsc committed
# Save current register context in old
# and then load register context from new.

.globl swtch
swtch:
  movl 4(%esp), %eax
kolya's avatar
kolya committed
  movl 8(%esp), %edx
kolya's avatar
kolya committed
  # Save old callee-save registers
  pushl %ebp
  pushl %ebx
  pushl %esi
  pushl %edi
kolya's avatar
kolya committed
  # Switch stacks
  movl %esp, (%eax)
  movl %edx, %esp
kolya's avatar
kolya committed
  # Load new callee-save registers
  popl %edi
  popl %esi
  popl %ebx
  popl %ebp
rsc's avatar
rsc committed
  ret