From 60a20004193f000a6bcc35d1237dabbcc4229143 Mon Sep 17 00:00:00 2001 From: Ch40zz Date: Wed, 19 May 2021 18:55:58 +0200 Subject: [PATCH] Fixes a crash when compiling the project on windows in 64 bit mode. Not all non-volatile registers were actually saved and restored, leading to a few registers being trashed after calling the vm instructions. All non-volatile registers have been added. --- code/asm/vm_x86_64.asm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/code/asm/vm_x86_64.asm b/code/asm/vm_x86_64.asm index 87e04f4d..f39289ec 100644 --- a/code/asm/vm_x86_64.asm +++ b/code/asm/vm_x86_64.asm @@ -30,9 +30,15 @@ ; uint8_t qvmcall64(int *programStack, int *opStack, intptr_t *instructionPointers, byte *dataBase); qvmcall64 PROC - push rsi ; push non-volatile registers to stack + push r12 ; push all non-volatile registers to stack + push r13 + push r14 + push r15 push rdi + push rsi push rbx + push rbp + ; need to save pointer in rcx so we can write back the programData value to caller push rcx @@ -48,9 +54,14 @@ qvmcall64 PROC mov dword ptr [rcx], esi ; write back the programStack value mov al, bl ; return opStack offset + pop rbp ; restore all non-volatile registers after the call pop rbx - pop rdi pop rsi + pop rdi + pop r15 + pop r14 + pop r13 + pop r12 ret qvmcall64 ENDP