@@ -315,13 +315,19 @@ codegen_backend_init(void)
315315# endif
316316 host_x86_CALL (block , (void * ) x86gpf );
317317 codegen_exit_rout = & codeblock [block_current ].data [block_pos ];
318+ #ifdef _WIN64
318319 host_x86_ADD64_REG_IMM (block , REG_RSP , 0x38 );
320+ #else
321+ host_x86_ADD64_REG_IMM (block , REG_RSP , 0x48 );
322+ #endif
319323 host_x86_POP (block , REG_R15 );
320324 host_x86_POP (block , REG_R14 );
321325 host_x86_POP (block , REG_R13 );
322326 host_x86_POP (block , REG_R12 );
327+ #ifdef _WIN64
323328 host_x86_POP (block , REG_RDI );
324329 host_x86_POP (block , REG_RSI );
330+ #endif
325331 host_x86_POP (block , REG_RBP );
326332 host_x86_POP (block , REG_RDX );
327333 host_x86_RET (block );
@@ -346,33 +352,45 @@ codegen_backend_prologue(codeblock_t *block)
346352 block_pos = BLOCK_START ; /*Entry code*/
347353 host_x86_PUSH (block , REG_RBX );
348354 host_x86_PUSH (block , REG_RBP );
355+ #ifdef _WIN64
349356 host_x86_PUSH (block , REG_RSI );
350357 host_x86_PUSH (block , REG_RDI );
358+ #endif
351359 host_x86_PUSH (block , REG_R12 );
352360 host_x86_PUSH (block , REG_R13 );
353361 host_x86_PUSH (block , REG_R14 );
354362 host_x86_PUSH (block , REG_R15 );
363+ #ifdef _WIN64
355364 host_x86_SUB64_REG_IMM (block , REG_RSP , 0x38 );
365+ #else
366+ host_x86_SUB64_REG_IMM (block , REG_RSP , 0x48 );
367+ #endif
356368 host_x86_MOV64_REG_IMM (block , REG_RBP , ((uintptr_t ) & cpu_state ) + 128 );
357369 if (block -> flags & CODEBLOCK_HAS_FPU ) {
358370 host_x86_MOV32_REG_ABS (block , REG_EAX , & cpu_state .TOP );
359371 host_x86_SUB32_REG_IMM (block , REG_EAX , block -> TOP );
360372 host_x86_MOV32_BASE_OFFSET_REG (block , REG_RSP , IREG_TOP_diff_stack_offset , REG_EAX );
361373 }
362374 if (block -> flags & CODEBLOCK_NO_IMMEDIATES )
363- host_x86_MOV64_REG_IMM (block , REG_R12 , (uintptr_t ) ram );
375+ host_x86_MOV64_REG_IMM (block , REG_R12 , (( uintptr_t ) ram ) + 2147483648ULL );
364376}
365377
366378void
367379codegen_backend_epilogue (codeblock_t * block )
368380{
381+ #ifdef _WIN64
369382 host_x86_ADD64_REG_IMM (block , REG_RSP , 0x38 );
383+ #else
384+ host_x86_ADD64_REG_IMM (block , REG_RSP , 0x48 );
385+ #endif
370386 host_x86_POP (block , REG_R15 );
371387 host_x86_POP (block , REG_R14 );
372388 host_x86_POP (block , REG_R13 );
373389 host_x86_POP (block , REG_R12 );
390+ #ifdef _WIN64
374391 host_x86_POP (block , REG_RDI );
375392 host_x86_POP (block , REG_RSI );
393+ #endif
376394 host_x86_POP (block , REG_RBP );
377395 host_x86_POP (block , REG_RDX );
378396 host_x86_RET (block );
0 commit comments