aboutsummaryrefslogtreecommitdiff
path: root/src/coro_unix_x64.s
diff options
context:
space:
mode:
Diffstat (limited to 'src/coro_unix_x64.s')
-rw-r--r--src/coro_unix_x64.s39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/coro_unix_x64.s b/src/coro_unix_x64.s
index 98710c2..d7de2a2 100644
--- a/src/coro_unix_x64.s
+++ b/src/coro_unix_x64.s
@@ -36,9 +36,9 @@ rerun:
; func(R7, R6, R2, R1, R8, R9, Z0-7): R0
;
; # Stack layout of an in-flight coro
-; ^coro
-; ^func
-; ^bp (base pointer of stack)
+; *coro
+; *func
+; *bp (base pointer of stack)
; ....... STACK .........
; Saved Clobbers
;
@@ -57,31 +57,33 @@ rerun:
; R14 [1]
; R15 [0]
-%define WORDS 8
-%define SAVES 9
+%define WORDSZ 8
+%define NSAVES 9
-; func sys.newCoro(co ^coro, fn func, bp ^stack)
+; coro *coro·new(co *coro, fn func, bp *stack)
_newcoro:
- lea R0, [coroinit]
- lea R1, [R2 - SAVES*WORDS]
+ lea R0, [coroinit] ; Store address of init function
+ lea R1, [R2 - NSAVES*WORDSZ] ; Store offset address of stack
- mov [R1 + 8*WORDS], R7
- mov [R1 + 7*WORDS], R6
- mov [R1 + 6*WORDS], R0
- mov [R1 + 5*WORDS], R2
+ mov [R1 + 8*WORDSZ], R7 ; Store context pointer
+ mov [R1 + 7*WORDSZ], R6 ; Store function pointer
+ mov [R1 + 6*WORDSZ], R0 ; Store initializer pointer
+ mov [R1 + 5*WORDSZ], R2 ; Store stack base pointer
xor R0, R0
+ ; Start of mutable stack
; Blank out the clobbers
- mov [R1 + 4*WORDS], R0 ; R3
- mov [R1 + 3*WORDS], R0 ; R12
- mov [R1 + 2*WORDS], R0 ; R13
- mov [R1 + 1*WORDS], R0 ; R14
- mov [R1 + 0*WORDS], R0 ; R15
+ mov [R1 + 4*WORDSZ], R0 ; R3
+ mov [R1 + 3*WORDSZ], R0 ; R12
+ mov [R1 + 2*WORDSZ], R0 ; R13
+ mov [R1 + 1*WORDSZ], R0 ; R14
+ mov [R1 + 0*WORDSZ], R0 ; R15
mov [R7], R1
ret
+; Saves register state
%macro pushclobs 0
push RBP
push R3
@@ -91,6 +93,7 @@ _newcoro:
push R15
%endmacro
+; Restores register state
%macro popclobs 0
pop R15
pop R14
@@ -100,7 +103,7 @@ _newcoro:
pop RBP
%endmacro
-; func coro.yield(co ^coro, ret uintptr)
+; uintptr coro.yield(co *coro, data uintptr)
_coroyield:
pushclobs
mov R0, R6 ; Move return value into return register.