Skip to content

Commit

Permalink
Win64 port.
Browse files Browse the repository at this point in the history
  • Loading branch information
gildor2 committed Nov 25, 2014
1 parent bd9d8e8 commit aac5551
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 31 deletions.
13 changes: 10 additions & 3 deletions Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ template<> struct CompileTimeError<true> {};
# if _MSC_VER >= 1400
# define IS_POD(T) __is_pod(T)
# endif
# pragma warning(disable : 4291) // no matched operator delete found
//# pragma warning(disable : 4291) // no matched operator delete found
// this functions are smaller, when in intrinsic form (and, of course, faster):
# pragma intrinsic(memcpy, memset, memcmp, abs, fabs, _rotl8, _rotl, _rotr8, _rotr)
// allow nested inline expansions
Expand Down Expand Up @@ -218,15 +218,16 @@ typedef size_t address_t;
#define S_WHITE "^7"


// Using size_t typecasts - that's platform integer type
template<class T> inline T OffsetPointer(const T ptr, int offset)
{
return (T) ((unsigned)ptr + offset);
return (T) ((size_t)ptr + offset);
}

// Align integer or pointer of any type
template<class T> inline T Align(const T ptr, int alignment)
{
return (T) (((unsigned)ptr + alignment - 1) & ~(alignment - 1));
return (T) (((size_t)ptr + alignment - 1) & ~(alignment - 1));
}

template<class T> inline void Exchange(T& A, T& B)
Expand Down Expand Up @@ -395,6 +396,12 @@ void appDumpMemoryAllocations();
unsigned win32ExceptFilter2();
#define EXCEPT_FILTER win32ExceptFilter2() // may use 1==EXCEPTION_EXECUTE_HANDLER or win32ExceptFilter2()

#if _WIN64
//!! todo
#undef EXCEPT_FILTER
#define EXCEPT_FILTER 1 // EXCEPTION_EXECUTE_HANDLER
#endif

#define guard(func) \
{ \
static const char __FUNC__[] = #func; \
Expand Down
15 changes: 14 additions & 1 deletion Core/CoreWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

#endif // VSTUDIO_INTEGRATION

#ifdef _WIN64
#undef UNWIND_EBP_FRAMES //!! should review the code and perhaps adopt to Win64
#endif

#if USE_DBGHELP
#include <dbghelp.h>
Expand Down Expand Up @@ -165,7 +168,7 @@ const char *appSymbolName(address_t addr)
// *s = 0;
if (s = strrchr(moduleName, '\\'))
strcpy(moduleName, s+1); // remove "path\" part
appSprintf(ARRAY_ARG(buf), "%s+0x%X", moduleName, addr - (int)hModule);
appSprintf(ARRAY_ARG(buf), "%s+0x%X", moduleName, (int)(addr - (size_t)hModule));
return buf;
#endif // GET_EXTENDED_INFO

Expand Down Expand Up @@ -288,6 +291,7 @@ static void DumpSEH()

static void DropSEHFrames()
{
#ifndef _WIN64
__asm
{
push edx
Expand All @@ -306,6 +310,7 @@ static void DropSEHFrames()
pop ebx
pop edx
}
#endif // _WIN64
}


Expand Down Expand Up @@ -432,9 +437,15 @@ long WINAPI win32ExceptFilter(struct _EXCEPTION_POINTERS *info)

// log error
CONTEXT* ctx = info->ContextRecord;
#ifndef _WIN64
appSprintf(ARRAY_ARG(GErrorHistory), "%s (%08X) at %s\n",
excName, info->ExceptionRecord->ExceptionCode, appSymbolName(ctx->Eip)
);
#else
appSprintf(ARRAY_ARG(GErrorHistory), "%s (%08X) at %s\n",
excName, info->ExceptionRecord->ExceptionCode, appSymbolName(ctx->Rip)
);
#endif // _WIN64
#if UNWIND_EBP_FRAMES
UnwindEbpFrame((address_t*) ctx->Ebp);
#endif // UNWIND_EBP_FRAMES
Expand All @@ -445,6 +456,7 @@ long WINAPI win32ExceptFilter(struct _EXCEPTION_POINTERS *info)
return EXCEPTION_EXECUTE_HANDLER;
}

#ifndef _WIN64
__declspec(naked) unsigned win32ExceptFilter2()
{
__asm {
Expand All @@ -453,6 +465,7 @@ __declspec(naked) unsigned win32ExceptFilter2()
retn // return value from win32ExceptFilter()
}
}
#endif // _WIN64

#endif // WIN32_USE_SEH

Expand Down
23 changes: 13 additions & 10 deletions Core/Win32Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@
# endif
# ifndef WINGDIAPI
# define WINGDIAPI
# ifdef _WIN64
# error Review these types!
# endif
typedef void* HANDLE;
#ifndef _WIN64
typedef int INT_PTR;
typedef long LONG_PTR;
#else
typedef __int64 INT_PTR;
typedef __int64 LONG_PTR;
#endif
typedef unsigned HDC;
typedef unsigned HGLRC;
typedef HANDLE HGLRC;
typedef const char * LPCSTR;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef unsigned int UINT;
typedef void* HANDLE;
typedef void* HWND;
typedef void* HMENU;
typedef size_t WPARAM;
typedef long LPARAM;
typedef int INT_PTR;
typedef HANDLE HWND;
typedef HANDLE HMENU;
typedef INT_PTR WPARAM;
typedef LONG_PTR LPARAM;
typedef int (APIENTRY *PROC)();
typedef void PIXELFORMATDESCRIPTOR; // structure
typedef PIXELFORMATDESCRIPTOR * LPPIXELFORMATDESCRIPTOR;
Expand Down
2 changes: 1 addition & 1 deletion Exporters/Exporters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct ExportedObjectEntry

int GetHash() const
{
return ( ((int)Package >> 3) ^ ExportIndex ^ (ExportIndex << 4) ) & (EXPORTED_LIST_HASH_SIZE - 1);
return ( ((size_t)Package >> 3) ^ ExportIndex ^ (ExportIndex << 4) ) & (EXPORTED_LIST_HASH_SIZE - 1);
}
};

Expand Down
20 changes: 15 additions & 5 deletions Tools/genmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ defined(var) will be replaced with 0 or 1
3. System variables:
platform specification:
PLATFORM = win32 | cygwin | unix
PLATFORM = win32 | win64 | cygwin | unix
COMPILER = VisualC | GnuC
TARGET = vc-win32 | mingw32 | cygwin | linux
TARGET = vc-win32 | vc-win64 | mingw32 | cygwin | linux
Should specify either "TARGET" or "PLATFORM"+"COMPILER"
global:
Expand Down Expand Up @@ -451,6 +451,9 @@ sub InitCompiler {
if ($TARGET eq "vc-win32") {
$COMPILER = "VisualC";
$PLATFORM = "win32";
} elsif ($TARGET eq "vc-win64") {
$COMPILER = "VisualC";
$PLATFORM = "win64";
} elsif ($TARGET eq "mingw32") {
$COMPILER = "GnuC";
$PLATFORM = "win32";
Expand Down Expand Up @@ -478,7 +481,7 @@ sub InitCompiler {
}
} elsif (defined($PLATFORM)) {
# defaults for PLATFORM
if ($PLATFORM eq "win32") {
if ($PLATFORM eq "win32" || $PLATFORM eq "win64") {
$COMPILER = "VisualC";
} elsif ($PLATFORM eq "cygwin") {
$COMPILER = "GnuC";
Expand Down Expand Up @@ -507,7 +510,7 @@ sub InitCompiler {
if ($PLATFORM eq "unix") {
$ExeFileExt = "";
$DllFileExt = ".so";
} elsif ($PLATFORM eq "win32" || $PLATFORM eq "cygwin") {
} elsif ($PLATFORM eq "win32" || $PLATFORM eq "win64" || $PLATFORM eq "cygwin") {
$ExeFileExt = ".exe";
$DllFileExt = ".dll";
}
Expand All @@ -518,7 +521,9 @@ sub EmitCompilerDefs {
Splitter ("Compiler definitions");
if ($COMPILER eq "VisualC") {
print "CPP = cl.exe -nologo -c -D WIN32 -D _WINDOWS\n";
print "LINK = link.exe -nologo -filealign:512 -incremental:no\n";
my $machine = "X86";
$machine = "X64" if $PLATFORM eq "win64";
print "LINK = link.exe -nologo -filealign:512 -incremental:no -machine:$machine\n";
print "AR = link.exe -lib -nologo\n"; # cannot use "LIB" name
} elsif ($COMPILER eq "GnuC") {
my $platf = "gcc";
Expand Down Expand Up @@ -1027,6 +1032,11 @@ sub FlushObjectFile {
my $defs = "";
$inc = " ".GenerateOptions ($includes, "-I ") if $includes ne "";
$defs = " ".GenerateOptions ($defines, "-D ") if $defines ne "";
if ($PLATFORM eq "win32") {
$defs .= " -D _WIN32 -D WIN32";
} else {
$defs .= " -D _WIN64 -D WIN64";
}
$line = "rc.exe -l 0x409 -i ${srcDir}${inc}${defs} -fo\"$objFile\" -dNDEBUG";
} else {
# C/C++ file
Expand Down
4 changes: 2 additions & 2 deletions UI/BaseDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ HWND UIElement::Window(const char* className, const char* text, DWORD style, DWO

if (Visible) style |= WS_VISIBLE;
HWND wnd = CreateWindowEx(exstyle, className, text, style | WS_CHILDWINDOW, x, y, w, h,
dialogWnd, (HMENU)id, hInstance, NULL);
dialogWnd, (HMENU)(size_t)id, hInstance, NULL); // convert int -> size_t -> HANDLE to avoid warnings on 64-bit platform
#if DEBUG_WINDOWS_ERRORS
if (!wnd) appNotify("CreateWindow failed, GetLastError returned %d\n", GetLastError());
#endif
Expand All @@ -229,7 +229,7 @@ HWND UIElement::Window(const wchar_t* className, const wchar_t* text, DWORD styl

if (Visible) style |= WS_VISIBLE;
HWND wnd = CreateWindowExW(exstyle, className, text, style | WS_CHILDWINDOW, x, y, w, h,
dialogWnd, (HMENU)id, hInstance, NULL);
dialogWnd, (HMENU)(size_t)id, hInstance, NULL);
#if DEBUG_WINDOWS_ERRORS
if (!wnd) appNotify("CreateWindow failed, GetLastError returned %d\n", GetLastError());
#endif
Expand Down
2 changes: 1 addition & 1 deletion UmodelTool/res/umodel.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<assemblyIdentity
version="0.0.1.0"
processorArchitecture="x86"
name="Controls"
name="Umodel"
type="win32"
/>
<description>wxWindows application</description>
Expand Down
5 changes: 5 additions & 0 deletions UmodelTool/res/umodel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@

// Enable themes for GUI elements
// http://www.angelfire.com/hi5/delphizeus/theme_xp.html
#ifndef _WIN64
1 RT_MANIFEST "umodel.manifest"
#else
1 RT_MANIFEST "umodel64.manifest"
#endif

IDC_MAIN_ICON ICON "umodel.ico"
22 changes: 22 additions & 0 deletions UmodelTool/res/umodel64.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="0.0.1.0"
processorArchitecture="amd64"
name="Umodel"
type="win32"
/>
<description>wxWindows application</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="amd64"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
2 changes: 1 addition & 1 deletion UmodelTool/umodel.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sources(MAIN) = {
Core/*.cpp
UI/*.cpp
$UMODEL/*.cpp
!if "$PLATFORM" eq "win32"
!if "$PLATFORM" eq "win32" || "$PLATFORM" eq "win64"
$UMODEL/res/umodel.rc
!endif
}
Expand Down
2 changes: 1 addition & 1 deletion Unreal/UnCoreCompression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int appDecompress(byte *CompressedBuffer, int CompressedSize, byte *Uncompressed
int r;
r = lzo_init();
if (r != LZO_E_OK) appError("lzo_init() returned %d", r);
unsigned long newLen = UncompressedSize;
lzo_uint newLen = UncompressedSize;
r = lzo1x_decompress_safe(CompressedBuffer, CompressedSize, UncompressedBuffer, &newLen, NULL);
if (r != LZO_E_OK) appError("lzo_decompress(%d,%d) returned %d", CompressedSize, UncompressedSize, r);
if (newLen != UncompressedSize) appError("len mismatch: %d != %d", newLen, UncompressedSize);
Expand Down
6 changes: 5 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ last_revision=${last_revision##* } # cut "#define ..."
#-------------------------------------------------------------

PLATFORM="vc-win32"
#PLATFORM="mingw32"
#PLATFORM="vc-win64"
#PLATFORM="mingw32" - not implemented yet

# force PLATFORM=linux under Linux OS
#?? check this, when cross-compile under wine
Expand Down Expand Up @@ -65,6 +66,9 @@ case "$PLATFORM" in
"vc-win32")
vc32tools --make $makefile || exit 1
;;
"vc-win64")
vc32tools --64 --make $makefile || exit 1
;;
"mingw32"|"cygwin")
PATH=/bin:/usr/bin:$PATH # configure paths for Cygwin
gccfilt make -f $makefile || exit 1
Expand Down
12 changes: 10 additions & 2 deletions common.project
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OLDCRT = 1
# Compiler-specific options
#------------------------------------------------

!if "$PLATFORM" ne "win32"
!if ("$PLATFORM" ne "win32") && ("$PLATFORM" ne "win64")
# linux/cygwin + GCC
STDLIBS = stdc++ m GL # libm for math.h functions
!if "$PLATFORM" ne "cygwin"
Expand All @@ -24,6 +24,11 @@ OLDCRT = 1
!if "$COMPILER" eq "VisualC"
CPP_EXCEPT = 0 # used with WIN32_USE_SEH in Core.h
OPTIONS = -GS- -GR- #?? VC8+
# -Wp64 enables 64-bit portability warnings. Note: this option is deprecated, it will display a command line warning.
# More information here:
# https://connect.microsoft.com/VisualStudio/feedback/details/806763/warnings-c4311-and-c4312-require-wp64-which-is-documented-as-deprecated
# http://blogs.msdn.com/b/vcblog/archive/2014/06/13/compiler-switch-deprecation-removal-changes-in-visual-studio-14.aspx
# OPTIONS += -Wp64 # 64-bit portability warnings; note: deprecated option, will display a command line warning
# OPTIONS += -FS # VS2013+, required for parallel build to work (jom.exe)
DEFINES += _USING_V110_SDK71_ # avoid some warnings, perhaps affects something else
# see http://tedwvc.wordpress.com/2014/01/01/how-to-target-xp-with-vc2012-or-vc2013-and-continue-to-use-the-windows-8-x-sdk/
Expand Down Expand Up @@ -108,10 +113,13 @@ sources(IOS_LIBS) = {
#------------------------------------------------

OBJDIR = $R/obj/$PRJ-$PLATFORM
LIBRARIES = $R/libs
STDLIBS += SDL2 SDL2main
INCLUDES += . $R/Core $R/Unreal $R/libs/include $R/libs/nvtt $R/libs/PowerVR

!if "$PLATFORM" eq "win32"
INCLUDES += $R/libs/includewin32
LIBRARIES = $R/libs/SDL2/x86
!elif "$PLATFORM" eq "win64"
INCLUDES += $R/libs/includewin32
LIBRARIES = $R/libs/SDL2/x64
!endif
Binary file added libs/SDL2/x64/SDL2.lib
Binary file not shown.
Binary file added libs/SDL2/x64/SDL2main.lib
Binary file not shown.
Binary file added libs/SDL2/x86/SDL2.lib
Binary file not shown.
Binary file added libs/SDL2/x86/SDL2main.lib
Binary file not shown.
6 changes: 3 additions & 3 deletions makefile-vc-win32
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#------------------------------------------------------------------------------

CPP = cl.exe -nologo -c -D WIN32 -D _WINDOWS
LINK = link.exe -nologo -filealign:512 -incremental:no
LINK = link.exe -nologo -filealign:512 -incremental:no -machine:X86
AR = link.exe -lib -nologo

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -113,7 +113,7 @@ IOS_LIBS_FILES = \

umodel.exe : $(OUT) $(OUT_1) $(MAIN_FILES) $(NV_LIBS_FILES) $(UE3_LIBS_FILES) $(IOS_LIBS_FILES)
echo Creating executable "umodel.exe" ...
$(LINK) -out:"umodel.exe" -libpath:./libs SDL2.lib SDL2main.lib -debug -pdb:"umodel.pdb" -opt:ref -opt:icf $(MAIN_FILES) $(NV_LIBS_FILES) $(UE3_LIBS_FILES) $(IOS_LIBS_FILES) -nodefaultlib:libcmt.lib -nodefaultlib:msvcprt.lib -manifest:no ./../Libs/msvcrt/startup/crtexe2.obj ./../Libs/msvcrt/lib/Win32/msvcrt.lib ./../Libs/msvcrt/lib/Win32/wdk_msvcrt_win2000.obj -subsystem:console
$(LINK) -out:"umodel.exe" -libpath:./libs/SDL2/x86 SDL2.lib SDL2main.lib -debug -pdb:"umodel.pdb" -opt:ref -opt:icf $(MAIN_FILES) $(NV_LIBS_FILES) $(UE3_LIBS_FILES) $(IOS_LIBS_FILES) -nodefaultlib:libcmt.lib -nodefaultlib:msvcprt.lib -manifest:no ./../Libs/msvcrt/startup/crtexe2.obj ./../Libs/msvcrt/lib/Win32/msvcrt.lib ./../Libs/msvcrt/lib/Win32/wdk_msvcrt_win2000.obj -subsystem:console

#------------------------------------------------------------------------------
# compiling source files
Expand Down Expand Up @@ -1191,7 +1191,7 @@ DEPENDS = \
UmodelTool/res/resource.h

$(OUT_1)/umodel.res : UmodelTool/res/umodel.rc $(DEPENDS)
rc.exe -l 0x409 -i UmodelTool/res/ -I . -I ./Core -I ./Unreal -I ./libs/include -I ./libs/nvtt -I ./libs/PowerVR -I ./libs/includewin32 -I UmodelTool -I UI -D _USING_V110_SDK71_ -D OLDCRT -fo"$(OUT_1)/umodel.res" -dNDEBUG UmodelTool/res/umodel.rc
rc.exe -l 0x409 -i UmodelTool/res/ -I . -I ./Core -I ./Unreal -I ./libs/include -I ./libs/nvtt -I ./libs/PowerVR -I ./libs/includewin32 -I UmodelTool -I UI -D _USING_V110_SDK71_ -D OLDCRT -D _WIN32 -D WIN32 -fo"$(OUT_1)/umodel.res" -dNDEBUG UmodelTool/res/umodel.rc

OPT_IOS_LIBS = -GS- -GR- -O1 -EHs- -Zi -Fd"$(OUT)/" -D _USING_V110_SDK71_ -D OLDCRT

Expand Down

0 comments on commit aac5551

Please sign in to comment.