summaryrefslogtreecommitdiff
path: root/swtch.S
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-28 12:48:33 +0000
committerrsc <rsc>2007-08-28 12:48:33 +0000
commit818fc0125e7d73fdf4f1a94f178254e5d05c9831 (patch)
tree2aefee5aad4478bc570d772a73ee1999d6066b54 /swtch.S
parentb52dea08bc1252bd842bf86f34d912c9ab7a02df (diff)
downloadxv6-labs-818fc0125e7d73fdf4f1a94f178254e5d05c9831.tar.gz
xv6-labs-818fc0125e7d73fdf4f1a94f178254e5d05c9831.tar.bz2
xv6-labs-818fc0125e7d73fdf4f1a94f178254e5d05c9831.zip
replace setjmp/longjmp with swtch
Diffstat (limited to 'swtch.S')
-rw-r--r--swtch.S32
1 files changed, 32 insertions, 0 deletions
diff --git a/swtch.S b/swtch.S
new file mode 100644
index 0000000..786e9ac
--- /dev/null
+++ b/swtch.S
@@ -0,0 +1,32 @@
+# void swtch(struct context *old, struct context *new);
+#
+# Save current register context in old
+# and then load register context from new.
+
+.globl swtch
+swtch:
+ # Save old registers
+ movl 4(%esp), %eax
+
+ popl 0(%eax) # %eip
+ movl %esp, 4(%eax)
+ movl %ebx, 8(%eax)
+ movl %ecx, 12(%eax)
+ movl %edx, 16(%eax)
+ movl %esi, 20(%eax)
+ movl %edi, 24(%eax)
+ movl %ebp, 28(%eax)
+
+ # Load new registers
+ movl 4(%esp), %eax # not 8(%esp) - popped return address above
+
+ movl 28(%eax), %ebp
+ movl 24(%eax), %edi
+ movl 20(%eax), %esi
+ movl 16(%eax), %edx
+ movl 12(%eax), %ecx
+ movl 8(%eax), %ebx
+ movl 4(%eax), %esp
+ pushl 0(%eax) # %eip
+
+ ret