aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2015-06-12 22:28:38 +0200
committerMike Pall <mike>2015-06-12 22:28:38 +0200
commit26b95a90f5f76f8a726ad0954f29781bec8ccc05 (patch)
tree87012c4e14c843891cd007a2a95bfaa95634e178
parent458a40b7242aefe2f0893019f0451fb2f2deccd9 (diff)
downloadluajit-26b95a90f5f76f8a726ad0954f29781bec8ccc05.tar.gz
luajit-26b95a90f5f76f8a726ad0954f29781bec8ccc05.tar.bz2
luajit-26b95a90f5f76f8a726ad0954f29781bec8ccc05.zip
Add Xbox One port.
-rw-r--r--doc/install.html12
-rw-r--r--doc/luajit.html2
-rw-r--r--src/lib_io.c4
-rw-r--r--src/lib_package.c8
-rw-r--r--src/lj_arch.h7
-rw-r--r--src/lj_clib.c8
-rw-r--r--src/xb1build.bat101
7 files changed, 138 insertions, 4 deletions
diff --git a/doc/install.html b/doc/install.html
index 008721f0..b5df697b 100644
--- a/doc/install.html
+++ b/doc/install.html
@@ -124,7 +124,7 @@ operating systems, CPUs and compilers:
124<td class="compatos">GCC 4.x</td> 124<td class="compatos">GCC 4.x</td>
125<td class="compatos">ORBIS (<a href="#ps4">PS4</a>)</td> 125<td class="compatos">ORBIS (<a href="#ps4">PS4</a>)</td>
126<td class="compatos">GCC 4.x</td> 126<td class="compatos">GCC 4.x</td>
127<td class="compatos">MSVC + SDK v7.0<br>WinSDK v7.0</td> 127<td class="compatos">MSVC + SDK v7.0<br>WinSDK v7.0<br>Durango (<a href="#xboxone">Xbox One</a>)</td>
128</tr> 128</tr>
129<tr class="odd"> 129<tr class="odd">
130<td class="compatcpu"><a href="#cross2">ARMv5+<br>ARM9E+</a></td> 130<td class="compatcpu"><a href="#cross2">ARMv5+<br>ARM9E+</a></td>
@@ -516,6 +516,16 @@ the following commands:
516cd src 516cd src
517xedkbuild 517xedkbuild
518</pre> 518</pre>
519<p>
520To cross-compile for <b id="xboxone">Xbox One</b> from a Windows host,
521open a "Visual Studio .NET Command Prompt" (64&nbsp;bit host compiler),
522<tt>cd</tt> to the directory where you've unpacked the sources and run
523the following commands:
524</p>
525<pre class="code">
526cd src
527xb1build
528</pre>
519 529
520<h2 id="embed">Embedding LuaJIT</h2> 530<h2 id="embed">Embedding LuaJIT</h2>
521<p> 531<p>
diff --git a/doc/luajit.html b/doc/luajit.html
index 721f636b..8a653e2d 100644
--- a/doc/luajit.html
+++ b/doc/luajit.html
@@ -166,7 +166,7 @@ LuaJIT is Copyright &copy; 2005-2015 Mike Pall, released under the
166<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr> 166<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr>
167</table> 167</table>
168<table class="feature os os3"> 168<table class="feature os os3">
169<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td></tr> 169<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td><td>Xbox One</td></tr>
170</table> 170</table>
171<table class="feature compiler"> 171<table class="feature compiler">
172<tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr> 172<tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr>
diff --git a/src/lib_io.c b/src/lib_io.c
index 468d3275..8836d052 100644
--- a/src/lib_io.c
+++ b/src/lib_io.c
@@ -99,7 +99,7 @@ static int io_file_close(lua_State *L, IOFileUD *iof)
99 int stat = -1; 99 int stat = -1;
100#if LJ_TARGET_POSIX 100#if LJ_TARGET_POSIX
101 stat = pclose(iof->fp); 101 stat = pclose(iof->fp);
102#elif LJ_TARGET_WINDOWS 102#elif LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE
103 stat = _pclose(iof->fp); 103 stat = _pclose(iof->fp);
104#else 104#else
105 lua_assert(0); 105 lua_assert(0);
@@ -400,7 +400,7 @@ LJLIB_CF(io_open)
400 400
401LJLIB_CF(io_popen) 401LJLIB_CF(io_popen)
402{ 402{
403#if LJ_TARGET_POSIX || LJ_TARGET_WINDOWS 403#if LJ_TARGET_POSIX || (LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE)
404 const char *fname = strdata(lj_lib_checkstr(L, 1)); 404 const char *fname = strdata(lj_lib_checkstr(L, 1));
405 GCstr *s = lj_lib_optstr(L, 2); 405 GCstr *s = lj_lib_optstr(L, 2);
406 const char *mode = s ? strdata(s) : "r"; 406 const char *mode = s ? strdata(s) : "r";
diff --git a/src/lib_package.c b/src/lib_package.c
index 6b6eb8f6..014cfd9e 100644
--- a/src/lib_package.c
+++ b/src/lib_package.c
@@ -96,9 +96,17 @@ static void setprogdir(lua_State *L)
96static void pusherror(lua_State *L) 96static void pusherror(lua_State *L)
97{ 97{
98 DWORD error = GetLastError(); 98 DWORD error = GetLastError();
99#if LJ_TARGET_XBOXONE
100 wchar_t wbuffer[128];
101 char buffer[128*2];
102 if (FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
103 NULL, error, 0, buffer, sizeof(wbuffer)/sizeof(wchar_t), NULL) &&
104 WideCharToMultiByte(CP_ACP, 0, wbuffer, 128, buffer, 128*2, NULL, NULL))
105#else
99 char buffer[128]; 106 char buffer[128];
100 if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, 107 if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
101 NULL, error, 0, buffer, sizeof(buffer), NULL)) 108 NULL, error, 0, buffer, sizeof(buffer), NULL))
109#endif
102 lua_pushstring(L, buffer); 110 lua_pushstring(L, buffer);
103 else 111 else
104 lua_pushfstring(L, "system error %d\n", error); 112 lua_pushfstring(L, "system error %d\n", error);
diff --git a/src/lj_arch.h b/src/lj_arch.h
index 96e9a99e..e705a3b2 100644
--- a/src/lj_arch.h
+++ b/src/lj_arch.h
@@ -120,6 +120,13 @@
120#define LJ_TARGET_CONSOLE 1 120#define LJ_TARGET_CONSOLE 1
121#endif 121#endif
122 122
123#ifdef _DURANGO
124#define LJ_TARGET_XBOXONE 1
125#define LJ_TARGET_CONSOLE 1
126#define LJ_TARGET_GC64 1
127#define LoadLibraryA(name) LoadLibraryExA((name), NULL, 0)
128#endif
129
123#define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */ 130#define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */
124#define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */ 131#define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */
125#define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */ 132#define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */
diff --git a/src/lj_clib.c b/src/lj_clib.c
index 6bdad67f..74b4b001 100644
--- a/src/lj_clib.c
+++ b/src/lj_clib.c
@@ -172,9 +172,17 @@ LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt,
172 const char *name) 172 const char *name)
173{ 173{
174 DWORD err = GetLastError(); 174 DWORD err = GetLastError();
175#if LJ_TARGET_XBOXONE
176 wchar_t wbuf[128];
177 char buf[128*2];
178 if (!FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,
179 NULL, err, 0, buf, sizeof(wbuf)/sizeof(wchar_t), NULL) ||
180 !WideCharToMultiByte(CP_ACP, 0, wbuf, 128, buf, 128*2, NULL, NULL))
181#else
175 char buf[128]; 182 char buf[128];
176 if (!FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM, 183 if (!FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,
177 NULL, err, 0, buf, sizeof(buf), NULL)) 184 NULL, err, 0, buf, sizeof(buf), NULL))
185#endif
178 buf[0] = '\0'; 186 buf[0] = '\0';
179 lj_err_callermsg(L, lj_strfmt_pushf(L, fmt, name, buf)); 187 lj_err_callermsg(L, lj_strfmt_pushf(L, fmt, name, buf));
180} 188}
diff --git a/src/xb1build.bat b/src/xb1build.bat
new file mode 100644
index 00000000..847e84a5
--- /dev/null
+++ b/src/xb1build.bat
@@ -0,0 +1,101 @@
1@rem Script to build LuaJIT with the Xbox One SDK.
2@rem Donated to the public domain.
3@rem
4@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler)
5@rem Then cd to this directory and run this script.
6
7@if not defined INCLUDE goto :FAIL
8@if not defined DurangoXDK goto :FAIL
9
10@setlocal
11@echo ---- Host compiler ----
12@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /DLUAJIT_ENABLE_GC64
13@set LJLINK=link /nologo
14@set LJMT=mt /nologo
15@set DASMDIR=..\dynasm
16@set DASM=%DASMDIR%\dynasm.lua
17@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c
18
19%LJCOMPILE% host\minilua.c
20@if errorlevel 1 goto :BAD
21%LJLINK% /out:minilua.exe minilua.obj
22@if errorlevel 1 goto :BAD
23if exist minilua.exe.manifest^
24 %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
25
26@rem Error out for 64 bit host compiler
27@minilua
28@if not errorlevel 8 goto :FAIL
29
30@set DASMFLAGS=-D WIN -D FFI -D P64
31minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x64.dasc
32@if errorlevel 1 goto :BAD
33
34%LJCOMPILE% /I "." /I %DASMDIR% /D_DURANGO host\buildvm*.c
35@if errorlevel 1 goto :BAD
36%LJLINK% /out:buildvm.exe buildvm*.obj
37@if errorlevel 1 goto :BAD
38if exist buildvm.exe.manifest^
39 %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
40
41buildvm -m peobj -o lj_vm.obj
42@if errorlevel 1 goto :BAD
43buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
44@if errorlevel 1 goto :BAD
45buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
46@if errorlevel 1 goto :BAD
47buildvm -m libdef -o lj_libdef.h %ALL_LIB%
48@if errorlevel 1 goto :BAD
49buildvm -m recdef -o lj_recdef.h %ALL_LIB%
50@if errorlevel 1 goto :BAD
51buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
52@if errorlevel 1 goto :BAD
53buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
54@if errorlevel 1 goto :BAD
55
56@echo ---- Cross compiler ----
57
58@set CWD=%cd%
59@call "%DurangoXDK%\xdk\DurangoVars.cmd" XDK
60@cd /D "%CWD%"
61@shift
62
63@set LJCOMPILE="cl" /nologo /c /W3 /GF /Gm- /GR- /GS- /Gy /openmp- /D_CRT_SECURE_NO_DEPRECATE /D_LIB /D_UNICODE /D_DURANGO
64@set LJLIB="lib" /nologo
65
66@if "%1"=="debug" (
67 @shift
68 @set LJCOMPILE=%LJCOMPILE% /Zi /MDd /Od
69 @set LJLINK=%LJLINK% /debug
70) else (
71 @set LJCOMPILE=%LJCOMPILE% /MD /O2 /DNDEBUG
72)
73
74@if "%1"=="amalg" goto :AMALG
75%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c
76@if errorlevel 1 goto :BAD
77%LJLIB% /OUT:luajit.lib lj_*.obj lib_*.obj
78@if errorlevel 1 goto :BAD
79@goto :NOAMALG
80:AMALG
81%LJCOMPILE% /DLUA_BUILD_AS_DLL ljamalg.c
82@if errorlevel 1 goto :BAD
83%LJLIB% /OUT:luajit.lib ljamalg.obj lj_vm.obj
84@if errorlevel 1 goto :BAD
85:NOAMALG
86
87@del *.obj *.manifest minilua.exe buildvm.exe
88@echo.
89@echo === Successfully built LuaJIT for Xbox One ===
90
91@goto :END
92:BAD
93@echo.
94@echo *******************************************************
95@echo *** Build FAILED -- Please check the error messages ***
96@echo *******************************************************
97@goto :END
98:FAIL
99@echo To run this script you must open a "Visual Studio .NET Command Prompt"
100@echo (64 bit host compiler). The Xbox One SDK must be installed, too.
101:END