diff --git a/app/include/module.h b/app/include/module.h index a892f21395..1af7015467 100644 --- a/app/include/module.h +++ b/app/include/module.h @@ -39,7 +39,19 @@ #define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y) #ifdef LUA_CROSS_COMPILER +#ifdef _MSC_VER +//on msvc it is necessary to go through more pre-processor hoops to get the +//section name built; string merging does not happen in the _declspecs. +//NOTE: linker magic is invoked via the magical '$' character. Caveat editor. +#define __TOKIFY(s) .rodata1$##s +#define __TOTOK(s) __TOKIFY(s) +#define __STRINGIFY(x) #x +#define __TOSTRING(x) __STRINGIFY(x) +#define __ROSECNAME(s) __TOSTRING(__TOTOK(s)) +#define LOCK_IN_SECTION(s) __declspec ( allocate( __ROSECNAME(s) ) ) +#else #define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".rodata1." #s))) +#endif #else #define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".lua_" #s))) #endif diff --git a/app/lua/lauxlib.c b/app/lua/lauxlib.c index eb1665ada1..f35dacd723 100644 --- a/app/lua/lauxlib.c +++ b/app/lua/lauxlib.c @@ -8,6 +8,9 @@ #include "lua.h" #include C_HEADER_CTYPE +#ifdef _MSC_VER //msvc #defines errno, which interferes with our #include macro +#undef errno +#endif #include C_HEADER_ERRNO #include C_HEADER_STDIO #include C_HEADER_STDLIB diff --git a/app/lua/linit.c b/app/lua/linit.c index b511d55383..ac95f46f0f 100644 --- a/app/lua/linit.c +++ b/app/lua/linit.c @@ -47,6 +47,21 @@ extern const luaR_entry lua_rotable_base[]; #define LUA_LIBS lua_libs_core #endif +#ifdef _MSC_VER +//MSVC requires us to declare these sections before we refer to them +#pragma section(__ROSECNAME(A), read) +#pragma section(__ROSECNAME(zzzzzzzz), read) +#pragma section(__ROSECNAME(libs), read) +#pragma section(__ROSECNAME(rotable), read) + +//These help us to find the beginning and ending of the RO data. NOTE: linker +//magic is used; the section names are lexically sorted, so 'a' and 'z' are +//important to keep the other sections lexically between these two dummy +//variables. Check your mapfile output if you need to fiddle with this stuff. +const LOCK_IN_SECTION(A) int _ro_start = 0; +const LOCK_IN_SECTION(zzzzzzzz) int _ro_end = 0; +#endif + static const LOCK_IN_SECTION(libs) luaL_reg LUA_LIBS[] = { {"", luaopen_base}, {LUA_LOADLIBNAME, luaopen_package}, diff --git a/app/lua/lrotable.c b/app/lua/lrotable.c index 99d3e6ef41..031c6217b5 100644 --- a/app/lua/lrotable.c +++ b/app/lua/lrotable.c @@ -9,7 +9,11 @@ #include "lobject.h" #include "lapi.h" +#ifdef _MSC_VER +#define ALIGNED_STRING (__declspec( align( 4 ) ) char*) +#else #define ALIGNED_STRING (__attribute__((aligned(4))) char *) +#endif #define LA_LINES 16 #define LA_SLOTS 4 //#define COLLECT_STATS diff --git a/app/lua/lrotable.h b/app/lua/lrotable.h index 055590ac86..ed010ae47d 100644 --- a/app/lua/lrotable.h +++ b/app/lua/lrotable.h @@ -72,6 +72,16 @@ int luaR_isrotable(void *p); extern const char _RODATA_END[]; #define IN_RODATA_AREA(p) (((const char *)(p)) < _RODATA_END) +#if defined(_MSC_VER) +//msvc build uses dummy vars to locate the beginning and ending addresses of the RO data +extern const int _ro_start; +extern const int _ro_end; +//and this is how we see if something is in the RO section +#undef IN_RODATA_AREA +#define IN_RODATA_AREA(p) (((const int*)(p)) >= &_ro_start && ((const int *)(p)) <= &_ro_end) +#endif + + #else /* xtensa tool chain for ESP target */ extern const char _irom0_text_start[]; diff --git a/app/lua/luac_cross/lflashimg.c b/app/lua/luac_cross/lflashimg.c index eaafa9d38f..092beaa297 100644 --- a/app/lua/luac_cross/lflashimg.c +++ b/app/lua/luac_cross/lflashimg.c @@ -112,7 +112,11 @@ static uint *flashAddrTag = flashImage + LUA_MAX_FLASH_SIZE; #define getFlashAddrTag(v) ((flashAddrTag[_TW(v)]&_TB(v)) != 0) #define fatal luac_fatal +#ifdef _MSC_VER +extern void __declspec( noreturn ) luac_fatal( const char* message ); +#else extern void __attribute__((noreturn)) luac_fatal(const char* message); +#endif #ifdef LOCAL_DEBUG #define DBG_PRINT(...) printf(__VA_ARGS__) diff --git a/app/lua/luac_cross/luac.c b/app/lua/luac_cross/luac.c index c369c4fb24..acaa62a36b 100644 --- a/app/lua/luac_cross/luac.c +++ b/app/lua/luac_cross/luac.c @@ -272,6 +272,9 @@ struct Smain { char** argv; }; +#ifdef _MSC_VER +typedef unsigned int uint; +#endif extern uint dumpToFlashImage (lua_State* L,const Proto *main, lua_Writer w, void* data, int strip, lu_int32 address, lu_int32 maxSize); diff --git a/app/lua/luaconf.h b/app/lua/luaconf.h index 2c81c2ef15..49eb843c05 100644 --- a/app/lua/luaconf.h +++ b/app/lua/luaconf.h @@ -40,8 +40,11 @@ #if defined(LUA_CROSS_COMPILER) +#ifdef _MSC_VER +#else #define LUA_USE_LINUX #endif +#endif #if defined(LUA_USE_LINUX) #define LUA_USE_POSIX @@ -264,7 +267,7 @@ #include #ifdef LUA_CROSS_COMPILER #include -else +#else #include "c_stdio.h" #endif @@ -631,7 +634,11 @@ extern int readline4lua(const char *prompt, char *buffer, int length); #define lua_str2number(s,p) c_strtoll((s), (p), 10) #endif // #if !defined LUA_INTEGRAL_LONGLONG #else +#ifdef _MSC_VER //what's wrong with stdlib strtod? +#define lua_str2number(s,p) strtod((s), (p)) +#else #define lua_str2number(s,p) c_strtod((s), (p)) +#endif #endif // #if defined LUA_NUMBER_INTEGRAL /* @@ -910,4 +917,4 @@ union luai_Cast { double l_d; long l_l; }; #error "Pipes not supported in aggresive optimization mode (LUA_OPTIMIZE_MEMORY=2)" #endif -#endif \ No newline at end of file +#endif diff --git a/app/uzlib/uzlib.h b/app/uzlib/uzlib.h index c89f5852cc..9aa86e48db 100644 --- a/app/uzlib/uzlib.h +++ b/app/uzlib/uzlib.h @@ -27,7 +27,11 @@ #include #include extern int dbg_break(void); +#ifdef _MSC_VER //msvc requires old name for longjmp +#define UZLIB_THROW(v) {dbg_break();longjmp(unwindAddr, (v));} +#else #define UZLIB_THROW(v) {dbg_break();_longjmp(unwindAddr, (v));} +#endif #define UZLIB_SETJMP _setjmp #define uz_malloc malloc #define uz_free free diff --git a/msvc/.gitignore b/msvc/.gitignore new file mode 100644 index 0000000000..855c76adfd --- /dev/null +++ b/msvc/.gitignore @@ -0,0 +1,8 @@ +.vs/ +*/Win32/ +*/x64/ + +*.vcxproj.user + +*.lua +*.img diff --git a/msvc/README.md b/msvc/README.md new file mode 100644 index 0000000000..fced341ae0 --- /dev/null +++ b/msvc/README.md @@ -0,0 +1,30 @@ +These are MSVC (Visual Studio 2017) project files for the host-side tools, +namely 'luac.cross' and 'spiffsimg'. Some may find these convenient if they +already have MSVC instead of, say, setting up a Cygwin or MingW build +system. + +To build 'luac.cross', you must first edit app/include/user_config.h to make +some choices about the kind of cross-compiler you are generating. + +In particular, the definition of + LUA_FLASH_STORE +should be enabled if you are creating a cross-compiler for generating images +for the Lua File Storage (LFS). The specific value of this define is not +critical for luac.cross, but it's existence is if you want to be able to +generate appropriate code for LFS. + +Be aware that the codebase, as checked in, has LUA_FLASH_STORE undefined. +Since it is expected that most folks wanting a host-side luac.cross is +for LFS use, you will want to first make sure that is changed to be +defined. + +Secondly, if you are wanting to generate code that is appropriate for an +integer-only build, you should ensure that + LUA_NUMBER_INTEGRAL +is defined. + +After altering those settings, you can build using the hosttools.sln file in +the Visual Studio UI, or directly on the command line. x86 and x64 targets +are provisioned, though there isn't anything to be gained with the 64-bit +build. + diff --git a/msvc/hosttools.sln b/msvc/hosttools.sln new file mode 100644 index 0000000000..30f55e26d4 --- /dev/null +++ b/msvc/hosttools.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.168 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "luac-cross", "luac-cross\luac-cross.vcxproj", "{78A3411A-A18F-41A4-B4A7-D76B273F0E44}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Debug|x64.ActiveCfg = Debug|x64 + {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Debug|x64.Build.0 = Debug|x64 + {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Debug|x86.ActiveCfg = Debug|Win32 + {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Debug|x86.Build.0 = Debug|Win32 + {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Release|x64.ActiveCfg = Release|x64 + {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Release|x64.Build.0 = Release|x64 + {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Release|x86.ActiveCfg = Release|Win32 + {78A3411A-A18F-41A4-B4A7-D76B273F0E44}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FC69D912-B682-4325-8FBC-1A887364B511} + EndGlobalSection +EndGlobal diff --git a/msvc/luac-cross/luac-cross.vcxproj b/msvc/luac-cross/luac-cross.vcxproj new file mode 100644 index 0000000000..7233372728 --- /dev/null +++ b/msvc/luac-cross/luac-cross.vcxproj @@ -0,0 +1,255 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {78A3411A-A18F-41A4-B4A7-D76B273F0E44} + Win32Proj + luaccross + 7.0 + + + + Application + true + v141_xp + MultiByte + + + Application + false + v141_xp + true + MultiByte + + + Application + true + v141_xp + MultiByte + + + Application + false + v141_xp + true + MultiByte + + + + + + + + + + + + + + + + + + + + + true + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + luac.cross + + + true + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + luac.cross + + + false + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + luac.cross + + + false + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + luac.cross + + + + NotUsing + Level3 + Disabled + true + LUA_CROSS_COMPILER;LUA_OPTIMIZE_MEMORY=2;_CRT_SECURE_NO_WARNINGS;_CONSOLE;LUA_DEBUG_BUILD;_DEBUG;WIN32;%(PreprocessorDefinitions) + true + pch.h + MultiThreadedDebug + $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib + + + Console + true + true + setargv.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + NotUsing + Level3 + Disabled + true + LUA_CROSS_COMPILER;LUA_OPTIMIZE_MEMORY=2;_CRT_SECURE_NO_WARNINGS;_CONSOLE;LUA_DEBUG_BUILD;_DEBUG;WIN32;%(PreprocessorDefinitions) + true + pch.h + MultiThreadedDebug + $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib + + + Console + true + true + setargv.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + LUA_CROSS_COMPILER;LUA_OPTIMIZE_MEMORY=2;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG;WIN32;%(PreprocessorDefinitions) + true + pch.h + MultiThreaded + $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib + + + Console + true + true + true + true + setargv.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + LUA_CROSS_COMPILER;LUA_OPTIMIZE_MEMORY=2;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG;WIN32;%(PreprocessorDefinitions) + true + pch.h + MultiThreaded + $(ProjectDir)\..\..\app\lua;$(ProjectDir)\..\..\app\libc;$(ProjectDir)\..\..\app\include;$(ProjectDir)\..\..\app\uzlib + + + Console + true + true + true + true + setargv.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/luac-cross/luac-cross.vcxproj.filters b/msvc/luac-cross/luac-cross.vcxproj.filters new file mode 100644 index 0000000000..20fb18c2e1 --- /dev/null +++ b/msvc/luac-cross/luac-cross.vcxproj.filters @@ -0,0 +1,237 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {4d57c826-be1b-40a4-afb4-e4bd4a62ef06} + + + {4a6a3fe9-6e73-4ac0-a7c8-eb7cff0094cf} + + + {df9c7976-ea6e-497b-aa10-c94220b331ac} + + + {016730a9-1aa4-4f7b-a5cf-3e566e37f2b6} + + + {439d70e8-0091-42d2-919f-7e710de3867c} + + + + + app\uzlib + + + app\uzlib + + + app\lua\luac_cross + + + app\lua\luac_cross + + + app\lua\luac_cross + + + app\lua\luac_cross + + + app\lua\luac_cross + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + + + app\uzlib + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\lua + + + app\include + + + app\include + + + app\include + + + \ No newline at end of file