@@ -85,18 +85,20 @@ ___firefly_swap_stack:
8585 .cfi_def_cfa rbp , 16
8686 .cfi_offset rbp , - 16
8787
88- # Now th at the frames are linked , we can call the entry point. For now , this
89- # is __firefly_trap_exceptions , which expects to receive two arguments: the function
90- # being wrapped by the exception handler , and the value of the closure environment ,
91- # _if_ it is a closure being called , otherwise the value of th at argument is Term::NONE
88+ # Now th at the frames are linked , we can call the entry point.
89+ # The only argument is the value of the closure environment ( or Term::NONE if not a closure)
9290 mov rdi , r12
93-
94- # We have already set up the stack precisely , so we don't use call here , instead
95- # we go ahead and jump straight to the beginning of the entry function.
96- # NOTE: This call never truly returns , as the exception handler calls __firefly_builtin_exit
97- # with the return value of the 'real' entry function , or with an exception if one
98- # is caught. However , swap_stack _does_ return for all other swaps , just not the first.
9991 call r14
92+
93+ # When we return to this point , the process has fully unwound and should exit , returning
94+ # back to the scheduler. We handle this by calling __firefly_builtin_exit , which sets up the
95+ # process status , and then yields to the scheduler. Control never returns here , so we hint
96+ # as such by which branch instruction we use
97+ #
98+ # NOTE: The ErlangResult struct will have been saved in rax / rdx , so we must move it to rdi / rsi
99+ # to reflect passing it by value as the sole argument to the __firefly_builtin_exit intrinsic
100+ mov rax , rdi
101+ mov rdx , rsi
100102 jmp ___firefly_builtin_exit
101103
102104L_resume:
0 commit comments