summaryrefslogtreecommitdiff
path: root/swtch.S
diff options
context:
space:
mode:
Diffstat (limited to 'swtch.S')
-rw-r--r--swtch.S59
1 files changed, 33 insertions, 26 deletions
diff --git a/swtch.S b/swtch.S
index aa527d8..17a8663 100644
--- a/swtch.S
+++ b/swtch.S
@@ -1,35 +1,42 @@
# Context switch
#
-# void swtch(struct context **old, struct context *new);
+# void swtch(struct context *old, struct context *new);
#
-# Save the current registers on the stack, creating
-# a struct context, and save its address in *old.
-# Switch stacks to new and pop previously-saved registers.
+# Save current registers in old. Load from new.
+
.globl swtch
swtch:
- # Save old callee-saved registers
- push %rbp
- push %rbx
- push %r11
- push %r12
- push %r13
- push %r14
- push %r15
-
- # Switch stacks
- mov %rsp, (%rdi) # first arg of swtch is in rdi
- mov %rsi, %rsp # second arg of swtch is in rsi
-
- # Load new callee-saved registers
- pop %r15
- pop %r14
- pop %r13
- pop %r12
- pop %r11
- pop %rbx
- pop %rbp
+ sd ra, 0(a0)
+ sd sp, 8(a0)
+ sd s0, 16(a0)
+ sd s1, 24(a0)
+ sd s2, 32(a0)
+ sd s3, 40(a0)
+ sd s4, 48(a0)
+ sd s5, 56(a0)
+ sd s6, 64(a0)
+ sd s7, 72(a0)
+ sd s8, 80(a0)
+ sd s9, 88(a0)
+ sd s10, 96(a0)
+ sd s11, 104(a0)
- ret
+ ld ra, 0(a1)
+ ld sp, 8(a1)
+ ld s0, 16(a1)
+ ld s1, 24(a1)
+ ld s2, 32(a1)
+ ld s3, 40(a1)
+ ld s4, 48(a1)
+ ld s5, 56(a1)
+ ld s6, 64(a1)
+ ld s7, 72(a1)
+ ld s8, 80(a1)
+ ld s9, 88(a1)
+ ld s10, 96(a1)
+ ld s11, 104(a1)
+
+ ret