Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/modula3/cm3
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykrell committed Jan 6, 2016
2 parents 8545f86 + e0bfe8c commit d96413a
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 3 deletions.
15 changes: 15 additions & 0 deletions m3-libs/m3core/src/m3core.h
Expand Up @@ -249,7 +249,22 @@ M3EXTERNC_END

#include <sys/types.h>
#include <sys/stat.h>
/* Strongly consider requiring a different bootstrap procedure and remove this workaround. */
/* Newer Visual C++ has both _wassert and _assert. Older only have _assert.
Favor _assert so that we can bootstrap from newer to older. */
#if _MSC_VER
#undef assert
#ifdef __cplusplus
extern "C" {
#endif
void __cdecl _assert(void *, void *, unsigned);
#ifdef __cplusplus
} /* extern C */
#endif
#define assert(exp) ((void)((!!(exp)) || (_assert(#exp, __FILE__, __LINE__), 0)))
#else /* _MSC_VER */
#include <assert.h>
#endif
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
15 changes: 15 additions & 0 deletions m3-libs/m3core/src/thread/WIN32/ThreadWin32C.c
Expand Up @@ -31,7 +31,22 @@
#endif

#include <windows.h>
/* Strongly consider requiring a different bootstrap procedure and remove this workaround. */
/* Newer Visual C++ has both _wassert and _assert. Older only have _assert.
Favor _assert so that we can bootstrap from newer to older. */
#if _MSC_VER
#undef assert
#ifdef __cplusplus
extern "C" {
#endif
void __cdecl _assert(void *, void *, unsigned);
#ifdef __cplusplus
} /* extern C */
#endif
#define assert(exp) ((void)((!!(exp)) || (_assert(#exp, __FILE__, __LINE__), 0)))
#else /* _MSC_VER */
#include <assert.h>
#endif
#include <setjmp.h>
#include <stddef.h>
#include <string.h>
Expand Down
121 changes: 119 additions & 2 deletions m3-libs/sysutils/src/LibcCompatC.c
@@ -1,3 +1,5 @@
/* Strongly consider requiring a different bootstrap procedure and remove this file. */

#ifdef _MSC_VER

#if 0 /* This is a problem with certain old<=>new bootstrap steps,
Expand Down Expand Up @@ -48,14 +50,16 @@ extern int (__cdecl * const _imp__printf)(const char* , ...) = &printf;
As long as _adjust_fdiv is zero, the other functions will not be called.
*/
#ifdef _M_IX86 /* Microsoft x86 */
#if _MSC_VER < 1000 || _MSC_VER >= 1100 /* TODO test 4.1 and 4.2 */

#ifdef __cplusplus
extern "C"
{
#endif

#pragma warning(disable:4035) /* no return value */

#if _MSC_VER < 1000 || _MSC_VER >= 1100 /* TODO test 4.1 and 4.2 */

#pragma warning(disable:4725) /* instruction may be inaccurate on some Pentiums */

int _adjust_fdiv;
Expand All @@ -76,11 +80,124 @@ float __cdecl _adj_fdiv_m32(float b)
__asm { ret 4 }
}

#endif /* _MSC_VER < 1000 || _MSC_VER >= 1100 */ /* TODO test 4.1 and 4.2 */

#if _MSC_VER <= 1310

/* TODO find out when ftol2_sse introduced.
I only currently have 2.0, 4.0, 5.0 (1100), 7.1 (1310), 2015 (14/1900).
I lack 4.1, 4.2, 6, 7, 8, 9, 10, 11, 12.
Newer compilers output a call to _ftol2_sse when casting a float or double to an int.
Older runtimes have only _ftol or only _ftol and _ftol2.
_ftol2_sse jmps to _ftol2 when SSE is not available.
_ftol temporarily changes the rounding mode, _ftol2 does not (nor does _ftol2_sse).
Another workaround would be to forward to msvcrt.dll -- have mklib
always output such forwarders.
*/
int __cdecl _ftol(double b);
int __cdecl _ftol2(double b);

__declspec(naked)
int __cdecl _ftol2_sse(double b)
{
#if _MSC_VER <= 1100
__asm { jmp _ftol }
#else
__asm { jmp _ftol2 }
#endif
}

#endif /* _MSC_VER <= 1310 */ /* TODO test 6 (1200), 7 (1300), 8 (1400), 9 (1500), 10 (1600), 11 (1700), 12 (1800) */

#if _MSC_VER <= 1310 /* TODO find exact versions */

/*
Starting with 5.8.6 release and upgrading with Visual C++ 7.1.
m3core.lib.sa(ThreadWin32C.obj) : error LNK2019: unresolved external symbol __wassert referenced in function _ThreadWin32__ProcessStopped
*/

#include <wchar.h>

void
__cdecl
_wassert (
wchar_t const* w_Message,
wchar_t const* w_File,
unsigned Line
)
{
size_t len;
size_t i;
char* a_Message = "";
char* a_File = "";

if (w_Message && w_Message[0])
{
len = wcslen(w_Message) + 1;
a_Message = (char*)_alloca(len);
for (i = 0; i < len; ++i)
a_Message[i] = (char)w_Message[i];
}

if (w_File && w_File[0])
{
len = wcslen(w_File) + 1;
a_Message = (char*)_alloca(len);
for (i = 0; i < len; ++i)
a_File[i] = (char)w_File[i];
}

_assert(a_Message, a_File, Line);
}

#endif

/*
no workaround
Consider moving TimeWin32 back to Modula-3, and rewriting strtod in Modula-3 also.
Or improve and use the cross automation which avoids using the old libs.
The calling conventions of the new float to integer functions cannot be implemented with the older compiler.
/arch:IA32 would suppress their use.
m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __dtol3 referenced in function _TimeWin32__ToFileTime
m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __ltod3 referenced in function _TimeWin32__FromFileTime
m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __imp____fpe_flt_rounds referenced in function _m3_strtod
m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __dtoui3 referenced in function _m3_strtod
This is particularly odd, as the symbol has been around for a long time.
m3core.lib.sa(ThreadWin32C.obj) : error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function _ThreadWin32__ProcessLive
*/

#if _MSC_VER < 1900 /* TODO find exact versions */

/*
no workaround
Consider moving TimeWin32 back to Modula-3, and rewriting strtod in Modula-3 also.
Or improve and use the cross automation which avoids using the old libs.
The calling conventions of the new float to integer functions cannot be implemented with the older compiler.
/arch:IA32 would suppress their use.
m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __dtol3 referenced in function _TimeWin32__ToFileTime
m3core.lib.sa(TimeWin32.obj) : error LNK2019: unresolved external symbol __ltod3 referenced in function _TimeWin32__FromFileTime
m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __imp____fpe_flt_rounds referenced in function _m3_strtod
m3core.lib.sa(dtoa.obj) : error LNK2019: unresolved external symbol __dtoui3 referenced in function _m3_strtod
This is particularly odd, as the symbol has been around for a long time.
m3core.lib.sa(ThreadWin32C.obj) : error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function _ThreadWin32__ProcessLive
*/

#endif

#ifdef __cplusplus
}
#endif

#endif /* _MSC_VER < 1000 || _MSC_VER >= 1100 */ /* TODO test 4.1 and 4.2 */
#endif /* _M_IX86 */
#endif /* _MSC_VER */

Expand Down
2 changes: 1 addition & 1 deletion scripts/env/winddk/3790/wxp/x86.cmd
Expand Up @@ -4,7 +4,7 @@
@rem cderr.h is missing

@call :F1 c:\winddk\3790 wxp i386
rem @call :F3 c:\winddk\3790 wnet i386
@call :F3 c:\winddk\3790 wnet i386
@goto :eof

:F1
Expand Down
7 changes: 7 additions & 0 deletions scripts/python/test1.cmd
@@ -0,0 +1,7 @@
call ..\env\clean2.cmd
call ..\env\winddk\3790\wnet\x86.cmd

rd /q/s \cm3.2
xcopy /fivery \cm3-5.8.6-min \cm3.2
.\make-dist-cfg.py
.\upgrade-full.cmd

0 comments on commit d96413a

Please sign in to comment.