diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor index e438bd1c0f..59012f9a9a 100644 --- a/basis/cpu/x86/32/bootstrap.factor +++ b/basis/cpu/x86/32/bootstrap.factor @@ -335,7 +335,18 @@ IN: bootstrap.x86 jit-set-context ] \ (set-context-and-delete) define-sub-primitive +: jit-start-context-and-delete ( -- ) + jit-load-vm + jit-load-context + ESP [] vm-reg MOV + ESP 4 [+] ctx-reg MOV + "reset_context" jit-call + + jit-pop-quot-and-param + ctx-reg jit-switch-context + jit-push-param + jit-jump-quot ; + [ - jit-delete-current-context - jit-start-context + jit-start-context-and-delete ] \ (start-context-and-delete) define-sub-primitive diff --git a/basis/cpu/x86/64/bootstrap.factor b/basis/cpu/x86/64/bootstrap.factor index e8c8d99643..d4913545e1 100644 --- a/basis/cpu/x86/64/bootstrap.factor +++ b/basis/cpu/x86/64/bootstrap.factor @@ -230,9 +230,6 @@ IN: bootstrap.x86 : jit-switch-context ( reg -- ) -8 jit-scrub-return - ! Save ds, rs registers - jit-save-context - ! Make the new context the current one ctx-reg swap MOV vm-reg vm-context-offset [+] ctx-reg MOV @@ -257,6 +254,7 @@ IN: bootstrap.x86 : jit-set-context ( -- ) jit-pop-context-and-param + jit-save-context arg1 jit-switch-context RSP 8 ADD jit-push-param ; @@ -269,17 +267,17 @@ IN: bootstrap.x86 ds-reg 16 SUB ; : jit-start-context ( -- ) - ! Create the new context in return-reg + ! Create the new context in return-reg. Have to save context + ! twice, first before calling new_context() which may GC, + ! and again after popping the two parameters from the stack. jit-save-context arg1 vm-reg MOV "new_context" jit-call jit-pop-quot-and-param - + jit-save-context return-reg jit-switch-context - jit-push-param - jit-jump-quot ; [ jit-start-context ] \ (start-context) define-sub-primitive @@ -295,7 +293,17 @@ IN: bootstrap.x86 jit-set-context ] \ (set-context-and-delete) define-sub-primitive +: jit-start-context-and-delete ( -- ) + jit-load-context + arg1 vm-reg MOV + arg2 ctx-reg MOV + "reset_context" jit-call + + jit-pop-quot-and-param + ctx-reg jit-switch-context + jit-push-param + jit-jump-quot ; + [ - jit-delete-current-context - jit-start-context + jit-start-context-and-delete ] \ (start-context-and-delete) define-sub-primitive diff --git a/vm/contexts.cpp b/vm/contexts.cpp index 8359e09307..0ddd51e1be 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -166,6 +166,12 @@ VM_C_API void delete_context(factor_vm *parent, context *old_context) parent->delete_context(old_context); } +VM_C_API void reset_context(factor_vm *parent, context *ctx) +{ + ctx->reset(); + parent->init_context(ctx); +} + cell factor_vm::begin_callback(cell quot_) { data_root quot(quot_,this); diff --git a/vm/contexts.hpp b/vm/contexts.hpp index 4aa7d7c221..1098bb892f 100644 --- a/vm/contexts.hpp +++ b/vm/contexts.hpp @@ -73,6 +73,7 @@ struct context { VM_C_API context *new_context(factor_vm *parent); VM_C_API void delete_context(factor_vm *parent, context *old_context); +VM_C_API void reset_context(factor_vm *parent, context *ctx); VM_C_API cell begin_callback(factor_vm *parent, cell quot); VM_C_API void end_callback(factor_vm *parent);