Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for 64-bit MSVC minheadless build #313

Merged
merged 1 commit into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions platforms/Cross/plugins/IA32ABI/x64win64abicc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ extern
#endif
struct VirtualMachine* interpreterProxy;

#ifdef _MSC_VER
# define alloca _alloca
#endif
#if __GNUC__
# define setsp(sp) __asm__ volatile ("movq %0,%%rsp" : : "m"(sp))
# define getsp() ({ void *sp; __asm__ volatile ("movq %%rsp,%0" : "=r"(sp) : ); sp;})
Expand Down
32 changes: 25 additions & 7 deletions platforms/minheadless/windows/sqPlatformSpecific-Win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,27 @@

# define fopen_for_append(filename) fopen(filename,"a+t")

/* default fpu control word:
_RC_NEAR: round to nearest
_PC_53 : double precision arithmetic (instead of extended)
_EM_XXX: silent operations (no signals please)
/* default fpu control word and mask:
_MCW_RC: Rounding control
_RC_NEAR: round to nearest
_MCW_PC: Precision control
_PC_53: double precision arithmetic (instead of extended)
_MCW_EM: Interupt exception mask
_EM_XXX: silent operations (no signals please)
https://docs.microsoft.com/en-us/previous-versions/e9b52ceh%28v%3dvs.140%29
*/

#if !defined(_MCW_PC)
// x64 does not support _MCW_PC
// The x64 CPU hardware default is 64-bit precision mode (80-bit long double);
// Microsoft expects software to set 53-bit mode before any user mode x87 instructions
// are reached. Microsoft made a change in responsibility for initializing precision mode
// in the X64 OS. The X64 OS sets 53-bit mode prior to starting your .exe, where the 32-bit OS
// expected the program to make that initialization.
# define _MCW_PC 0
#endif

#define FPU_MASK (_MCW_EM | _MCW_RC | _MCW_PC)
#define FPU_DEFAULT (_RC_NEAR + _PC_53 + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL)

#define MAXFRAMES 64
Expand Down Expand Up @@ -116,7 +132,7 @@ void
ioInitPlatformSpecific(void)
{
/* Setup the FPU */
_controlfp(FPU_DEFAULT, _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC);
_controlfp(FPU_DEFAULT, FPU_MASK);

/* Create the wake up event. */
vmWakeUpEvent = CreateEvent(NULL, 1, 0, NULL);
Expand Down Expand Up @@ -363,8 +379,9 @@ static LONG CALLBACK squeakExceptionHandler(LPEXCEPTION_POINTERS exp)
DWORD code = exp->ExceptionRecord->ExceptionCode;
if((code >= EXCEPTION_FLT_DENORMAL_OPERAND) && (code <= EXCEPTION_FLT_UNDERFLOW))
{
/* turn on the default masking of exceptions in the FPU and proceed */
_controlfp(FPU_DEFAULT, _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC);
/* in case FFI callout to foreign code changed FP mode */
/* restore our default masking of exceptions in the FPU and proceed */
_controlfp(FPU_DEFAULT, FPU_MASK);
result = EXCEPTION_CONTINUE_EXECUTION;
}
}
Expand Down Expand Up @@ -799,3 +816,4 @@ void *os_exports[][3] =
{
{ 0, 0, 0 }
};

4 changes: 2 additions & 2 deletions platforms/minheadless/windows/sqPlatformSpecific-Win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ size_t sqImageFileWrite(const void *ptr, size_t sz, size_t count, sqImageFile h)
error "Not Win32!"
#endif /* WIN32 */

int ioSetCursorARGB(sqInt bitsIndex, sqInt w, sqInt h, sqInt x, sqInt y);
sqInt ioSetCursorARGB(sqInt bitsIndex, sqInt w, sqInt h, sqInt x, sqInt y);

/* poll and profile thread priorities. The stack vm uses a thread to cause the
* VM to poll for I/O, check for delay expiry et al at regular intervals. Both
Expand Down Expand Up @@ -185,4 +185,4 @@ extern const unsigned long tltiIndex;
#define TRY
#define EXCEPT(filter) if (0)
#define FINALLY
#endif
#endif