changeset 1828:37afb9cf58be

Get 64-bit builds working for Windows target
author Michael Pavone <pavone@retrodev.com>
date Sun, 07 Apr 2019 00:06:29 -0700
parents c945a25aa75c
children a79e92929044
files Makefile gen_x86.c gen_x86.h m68k_core_x86.c z80_to_x86.c
diffstat 5 files changed, 32 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sat Apr 06 21:38:11 2019 -0700
+++ b/Makefile	Sun Apr 07 00:06:29 2019 -0700
@@ -10,16 +10,8 @@
 	zlib/gzwrite.o zlib/infback.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/trees.o zlib/uncompr.o zlib/zutil.o
 
 ifeq ($(OS),Windows)
-ifndef SDL2_PREFIX
-SDL2_PREFIX:="sdl/i686-w64-mingw32"
-endif
-ifndef GLEW_PREFIX
+
 GLEW_PREFIX:=glew
-endif
-ifndef GLEW32S_LIB
-GLEW32S_LIB:=$(GLEW_PREFIX)/lib/Release/Win32/glew32s.lib
-endif
-
 MEM:=mem_win.o
 TERMINAL:=terminal_win.o
 FONT:=nuklear_ui/font_win.o
@@ -29,9 +21,16 @@
 CPU:=i686
 ifeq ($(CPU),i686)
 CC:=i686-w64-mingw32-gcc-win32
+WINDRES:=i686-w64-mingw32-windres
+GLUDIR:=Win32
+SDL2_PREFIX:="sdl/i686-w64-mingw32"
 else
 CC:=x86_64-w64-mingw32-gcc-win32
+WINDRES:=x86_64-w64-mingw32-windres
+SDL2_PREFIX:="sdl/x86_64-w64-mingw32"
+GLUDIR:=x64
 endif
+GLEW32S_LIB:=$(GLEW_PREFIX)/lib/Release/$(GLUDIR)/glew32s.lib
 CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration
 LDFLAGS:=-lm -lmingw32 -lws2_32 -mwindows
 ifneq ($(MAKECMDGOALS),libblastem.dll)
@@ -365,7 +364,7 @@
 %.bin : %.sz8
 	vasmz80_mot -Fbin -spaces -o $@ $<
 res.o : blastem.rc
-	i686-w64-mingw32-windres blastem.rc res.o
+	$(WINDRES) blastem.rc res.o
 
 arrow.tiles : arrow.png
 cursor.tiles : cursor.png
--- a/gen_x86.c	Sat Apr 06 21:38:11 2019 -0700
+++ b/gen_x86.c	Sun Apr 07 00:06:29 2019 -0700
@@ -2111,7 +2111,12 @@
 	}
 #ifdef X86_64
 	uint32_t stack_args = 0;
+#ifdef _WIN32
+	//Microsoft is too good for the ABI that everyone else uses on x86-64 apparently
+	uint8_t abi_regs[] = {RCX, RDX, R8, R9};
+#else
 	uint8_t abi_regs[] = {RDI, RSI, RDX, RCX, R8, R9};
+#endif
 	int8_t reg_swap[R15+1];
 	uint32_t usage = 0;
 	memset(reg_swap, -1, sizeof(reg_swap));
@@ -2153,6 +2158,11 @@
 		push_r(code, arg_arr[i]);
 	}
 	free(arg_arr);
+#if defined(X86_64) && defined(_WIN32)
+	sub_ir(code, 32, RSP, SZ_PTR);
+	code->stack_off += 32;
+	adjust += 32;
+#endif
 	
 	return stack_args * sizeof(void *) + adjust;
 }
--- a/gen_x86.h	Sat Apr 06 21:38:11 2019 -0700
+++ b/gen_x86.h	Sun Apr 07 00:06:29 2019 -0700
@@ -63,6 +63,13 @@
 #ifdef X86_64
 #define SZ_PTR SZ_Q
 #define MAX_INST_LEN 14
+#ifdef _WIN32
+#define FIRST_ARG_REG RCX
+#define SECOND_ARG_REG RDX
+#else
+#define FIRST_ARG_REG RDI
+#define SECOND_ARG_REG RSI
+#endif
 #else
 #define SZ_PTR SZ_D
 #define MAX_INST_LEN 11
--- a/m68k_core_x86.c	Sat Apr 06 21:38:11 2019 -0700
+++ b/m68k_core_x86.c	Sun Apr 07 00:06:29 2019 -0700
@@ -2658,8 +2658,11 @@
 	opts->start_context = (start_fun)code->cur;
 	save_callee_save_regs(code);
 #ifdef X86_64
-	if (opts->gen.scratch2 != RDI) {
-		mov_rr(code, RDI, opts->gen.scratch2, SZ_PTR);
+	if (opts->gen.scratch2 != FIRST_ARG_REG) {
+		mov_rr(code, FIRST_ARG_REG, opts->gen.scratch2, SZ_PTR);
+	}
+	if (opts->gen.context_reg != SECOND_ARG_REG) {
+		mov_rr(code, SECOND_ARG_REG, opts->gen.context_reg, SZ_PTR);
 	}
 #else
 	mov_rdispr(code, RSP, 20, opts->gen.scratch2, SZ_D);
--- a/z80_to_x86.c	Sat Apr 06 21:38:11 2019 -0700
+++ b/z80_to_x86.c	Sun Apr 07 00:06:29 2019 -0700
@@ -3601,7 +3601,7 @@
 	tmp_stack_off = code->stack_off;
 	save_callee_save_regs(code);
 #ifdef X86_64
-	mov_rr(code, RDI, options->gen.context_reg, SZ_PTR);
+	mov_rr(code, FIRST_ARG_REG, options->gen.context_reg, SZ_PTR);
 #else
 	mov_rdispr(code, RSP, 5 * sizeof(int32_t), options->gen.context_reg, SZ_PTR);
 #endif