]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Add PS Vita port.
authorMike Pall <mike>
Sat, 26 Apr 2014 22:09:45 +0000 (00:09 +0200)
committerMike Pall <mike>
Sat, 26 Apr 2014 22:09:45 +0000 (00:09 +0200)
Thanks to Anton Stenmark.

doc/install.html
doc/luajit.html
src/host/buildvm_asm.c
src/lib_io.c
src/lib_os.c
src/lj_arch.h
src/lj_def.h
src/psvitabuild.bat [new file with mode: 0644]

index 2388ff338e5b7c31201627782462dc70acbea568..f81631535bc089e0952b1f7c3d7080605366ad9b 100644 (file)
@@ -127,7 +127,7 @@ operating systems, CPUs and compilers:
 <tr class="odd">
 <td class="compatcpu"><a href="#cross2">ARMv5+<br>ARM9E+</a></td>
 <td class="compatos">GCC 4.2+</td>
-<td class="compatos">GCC 4.2+</td>
+<td class="compatos">GCC 4.2+<br>PSP2 (<a href="#psvita">PS VITA</a>)</td>
 <td class="compatos">GCC 4.2+</td>
 <td class="compatos compatno">&nbsp;</td>
 </tr>
@@ -458,41 +458,56 @@ ISDKF="-arch armv7 -isysroot $ISDK/SDKs/$ISDKVER"
 make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" \
      TARGET_SYS=iOS
 </pre>
+
+<h3 id="consoles">Cross-compiling for consoles</h3>
 <p>
-You can cross-compile for <b id="ps3">PS3</b> using the PS3&nbsp;SDK from
-a Linux host or a Windows host (requires 32&nbsp;bit MinGW (GCC) on the host,
-too). Due to restrictions on consoles, the JIT compiler is disabled and
-only the fast interpreter is built:
+Building LuaJIT for consoles requires both a supported host compiler
+(x86 or x64) and a cross-compiler (to PPC or ARM) from the official
+console SDK.
 </p>
-<pre class="code">
-make HOST_CC="gcc -m32" CROSS=ppu-lv2-
-</pre>
 <p>
-You can cross-compile for <b id="ps4">PS4</b> from a Windows host using
-the PS4&nbsp;SDK (ORBIS) plus 64&nbsp;bit MSVC. Due to restrictions on
-consoles, the JIT compiler is disabled and only the fast interpreter
-is built.
+Due to restrictions on consoles, the JIT compiler is disabled and only
+the fast interpreter is built. This is still faster than plain Lua,
+but much slower than the JIT compiler. The FFI is disabled, too, since
+it's not very useful in such an environment.
 </p>
 <p>
-Open a "Visual Studio .NET Command Prompt" (64&nbsp;bit host compiler),
-<tt>cd</tt> to the directory where you've unpacked the sources and run
-the following commands. This builds a static library <tt>libluajit.a</tt>,
+The following commands build a static library <tt>libluajit.a</tt>,
 which can be linked against your game, just like the Lua library.
 </p>
+<p>
+To cross-compile for <b id="ps3">PS3</b> from a Linux host (requires
+32&nbsp;bit GCC, i.e. multilib Linux/x64) or a Windows host (requires
+32&nbsp;bit MinGW), run this command:
+</p>
+<pre class="code">
+make HOST_CC="gcc -m32" CROSS=ppu-lv2-
+</pre>
+<p>
+To cross-compile for <b id="ps4">PS4</b> from a Windows host,
+open a "Visual Studio .NET Command Prompt" (64&nbsp;bit host compiler),
+<tt>cd</tt> to the directory where you've unpacked the sources and
+run the following commands:
+</p>
 <pre class="code">
 cd src
 ps4build
 </pre>
 <p>
-You can cross-compile for <b id="xbox360">Xbox 360</b> using the
-Xbox&nbsp;360 SDK (MSVC + XEDK). Due to restrictions on consoles, the
-JIT compiler is disabled and only the fast interpreter is built.
+To cross-compile for <b id="psvita">PS Vita</b> from a Windows host,
+open a "Visual Studio .NET Command Prompt" (32&nbsp;bit host compiler),
+<tt>cd</tt> to the directory where you've unpacked the sources and
+run the following commands:
 </p>
+<pre class="code">
+cd src
+psvitabuild
+</pre>
 <p>
-Open a "Visual Studio .NET Command Prompt" (32&nbsp;bit host compiler),
+To cross-compile for <b id="xbox360">Xbox 360</b> from a Windows host,
+open a "Visual Studio .NET Command Prompt" (32&nbsp;bit host compiler),
 <tt>cd</tt> to the directory where you've unpacked the sources and run
-the following commands. This builds a static library <tt>luajit20.lib</tt>,
-which can be linked against your game, just like the Lua library.
+the following commands:
 </p>
 <pre class="code">
 cd src
index 43af69c920247ca3d1de70edba373a661090f7ce..ddbc0164b898c99218396a3b7d78586e39868124 100644 (file)
@@ -38,6 +38,9 @@ table.os1 td {
 table.os2 td {
   color: #ffa040;
 }
+table.os3 td {
+  color: #40ffff;
+}
 table.compiler td {
   color: #2080ff;
   background: #62bf41;
@@ -158,7 +161,10 @@ LuaJIT is Copyright &copy; 2005-2014 Mike Pall, released under the
 <tr><td>Windows</td><td>Linux</td><td>BSD</td><td>OSX</td><td>POSIX</td></tr>
 </table>
 <table class="feature os os2">
-<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td><td>PS3</td><td>PS4</td><td>Xbox 360</td></tr>
+<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr>
+</table>
+<table class="feature os os3">
+<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td></tr>
 </table>
 <table class="feature compiler">
 <tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr>
index 9b28b3b38468f97be1b0caf4b1e62af1027401c0..079e9a809743bad6ea8a302ce7f5dd18f2514a1d 100644 (file)
@@ -286,7 +286,7 @@ void emit_asm(BuildCtx *ctx)
   fprintf(ctx->fp, "\n");
   switch (ctx->mode) {
   case BUILD_elfasm:
-#if !LJ_TARGET_PS3
+#if !(LJ_TARGET_PS3 || LJ_TARGET_PSVITA)
     fprintf(ctx->fp, "\t.section .note.GNU-stack,\"\"," ELFASM_PX "progbits\n");
 #endif
 #if LJ_TARGET_PPCSPE
index 04f0f7390f361979d93e2bd1abb837b0e39763b8..90f310bb7d9dcd1d0bf11b88d277b5519094e7dc 100644 (file)
@@ -426,7 +426,7 @@ LJLIB_CF(io_popen)
 LJLIB_CF(io_tmpfile)
 {
   IOFileUD *iof = io_file_new(L);
-#if LJ_TARGET_PS3 || LJ_TARGET_PS4
+#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA
   iof->fp = NULL; errno = ENOSYS;
 #else
   iof->fp = tmpfile();
index f62e8c8bb2ea2cead8f9e44903f04c4958087878..713ec93547f76b5d8f66a70aad49d2b353c5ca2e 100644 (file)
@@ -7,7 +7,6 @@
 */
 
 #include <errno.h>
-#include <locale.h>
 #include <time.h>
 
 #define lib_os_c
 #include <stdio.h>
 #endif
 
+#if !LJ_TARGET_PSVITA
+#include <locale.h>
+#endif
+
 /* ------------------------------------------------------------------------ */
 
 #define LJLIB_MODULE_os
@@ -70,7 +73,7 @@ LJLIB_CF(os_rename)
 
 LJLIB_CF(os_tmpname)
 {
-#if LJ_TARGET_PS3 || LJ_TARGET_PS4
+#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA
   lj_err_caller(L, LJ_ERR_OSUNIQF);
   return 0;
 #else
@@ -254,6 +257,9 @@ LJLIB_CF(os_difftime)
 
 LJLIB_CF(os_setlocale)
 {
+#if LJ_TARGET_PSVITA
+  lua_pushliteral(L, "C");
+#else
   GCstr *s = lj_lib_optstr(L, 1);
   const char *str = s ? strdata(s) : NULL;
   int opt = lj_lib_checkopt(L, 2, 6,
@@ -265,6 +271,7 @@ LJLIB_CF(os_setlocale)
   else if (opt == 4) opt = LC_MONETARY;
   else if (opt == 6) opt = LC_ALL;
   lua_pushstring(L, setlocale(opt, str));
+#endif
   return 1;
 }
 
index 0196eedc0caa7108fec7d55daa76a47d45596191..f04da3bf9180ba7c6fbf5c43aaf0b3fd01522338 100644 (file)
 #define NULL ((void*)0)
 #endif
 
+#ifdef __psp2__
+#define LJ_TARGET_PSVITA       1
+#define LJ_TARGET_CONSOLE      1
+#endif
+
 #if _XBOX_VER >= 200
 #define LJ_TARGET_XBOX360      1
 #define LJ_TARGET_CONSOLE      1
index 3c43be7887632cd3725ce286a222f65f372e2c7f..8624aed26bf50818dd40c43ff60e2bcdd1c2969a 100644 (file)
@@ -111,7 +111,7 @@ typedef uintptr_t BloomFilter;
 #define bloomset(b, x) ((b) |= bloombit((x)))
 #define bloomtest(b, x)        ((b) & bloombit((x)))
 
-#if defined(__GNUC__)
+#if defined(__GNUC__) || defined(__psp2__)
 
 #define LJ_NORET       __attribute__((noreturn))
 #define LJ_ALIGN(n)    __attribute__((aligned(n)))
@@ -119,7 +119,7 @@ typedef uintptr_t BloomFilter;
 #define LJ_AINLINE     inline __attribute__((always_inline))
 #define LJ_NOINLINE    __attribute__((noinline))
 
-#if defined(__ELF__) || defined(__MACH__)
+#if defined(__ELF__) || defined(__MACH__) || defined(__psp2__)
 #if !((defined(__sun__) && defined(__svr4__)) || defined(__CELLOS_LV2__))
 #define LJ_NOAPI       extern __attribute__((visibility("hidden")))
 #endif
@@ -150,6 +150,9 @@ static LJ_AINLINE uint32_t lj_fls(uint32_t x)
 #if defined(__arm__)
 static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
 {
+#if defined(__psp2__)
+  return __builtin_rev(x);
+#else
   uint32_t r;
 #if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\
     __ARM_ARCH_6ZK__ || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__
@@ -163,6 +166,7 @@ static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
 #endif
   return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8);
 #endif
+#endif
 }
 
 static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
diff --git a/src/psvitabuild.bat b/src/psvitabuild.bat
new file mode 100644 (file)
index 0000000..3991dc6
--- /dev/null
@@ -0,0 +1,93 @@
+@rem Script to build LuaJIT with the PS Vita SDK.\r
+@rem Donated to the public domain.\r
+@rem\r
+@rem Open a "Visual Studio .NET Command Prompt" (32 bit host compiler)\r
+@rem Then cd to this directory and run this script.\r
+\r
+@if not defined INCLUDE goto :FAIL\r
+@if not defined SCE_PSP2_SDK_DIR goto :FAIL\r
+\r
+@setlocal\r
+@rem ---- Host compiler ----\r
+@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\r
+@set LJLINK=link /nologo\r
+@set LJMT=mt /nologo\r
+@set DASMDIR=..\dynasm\r
+@set DASM=%DASMDIR%\dynasm.lua\r
+@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\r
+\r
+%LJCOMPILE% host\minilua.c\r
+@if errorlevel 1 goto :BAD\r
+%LJLINK% /out:minilua.exe minilua.obj\r
+@if errorlevel 1 goto :BAD\r
+if exist minilua.exe.manifest^\r
+  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\r
+\r
+@rem Check for 32 bit host compiler.\r
+@minilua\r
+@if errorlevel 8 goto :FAIL\r
+\r
+@set DASMFLAGS=-D FPU -D HFABI\r
+minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_arm.dasc\r
+@if errorlevel 1 goto :BAD\r
+\r
+%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_ARM -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLJ_TARGET_PSVITA=1 host\buildvm*.c\r
+@if errorlevel 1 goto :BAD\r
+%LJLINK% /out:buildvm.exe buildvm*.obj\r
+@if errorlevel 1 goto :BAD\r
+if exist buildvm.exe.manifest^\r
+  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\r
+\r
+buildvm -m elfasm -o lj_vm.s\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m libdef -o lj_libdef.h %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m recdef -o lj_recdef.h %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m folddef -o lj_folddef.h lj_opt_fold.c\r
+@if errorlevel 1 goto :BAD\r
+\r
+@rem ---- Cross compiler ----\r
+@set LJCOMPILE="%SCE_PSP2_SDK_DIR%\host_tools\build\bin\psp2snc" -c -w -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC\r
+@set LJLIB="%SCE_PSP2_SDK_DIR%\host_tools\build\bin\psp2ld32" -r --output=\r
+@set INCLUDE=""\r
+\r
+"%SCE_PSP2_SDK_DIR%\host_tools\build\bin\psp2as" -o lj_vm.o lj_vm.s\r
+\r
+@if "%1" neq "debug" goto :NODEBUG\r
+@shift\r
+@set LJCOMPILE=%LJCOMPILE% -g -O0\r
+@set TARGETLIB=libluajitD.a\r
+goto :BUILD\r
+:NODEBUG\r
+@set LJCOMPILE=%LJCOMPILE% -O2\r
+@set TARGETLIB=libluajit.a\r
+:BUILD\r
+del %TARGETLIB%\r
+\r
+%LJCOMPILE% ljamalg.c\r
+@if errorlevel 1 goto :BAD\r
+%LJLIB%%TARGETLIB% ljamalg.o lj_vm.o\r
+@if errorlevel 1 goto :BAD\r
+\r
+@del *.o *.obj *.manifest minilua.exe buildvm.exe\r
+@echo.\r
+@echo === Successfully built LuaJIT for PS Vita ===\r
+\r
+@goto :END\r
+:BAD\r
+@echo.\r
+@echo *******************************************************\r
+@echo *** Build FAILED -- Please check the error messages ***\r
+@echo *******************************************************\a\r
+@goto :END\r
+:FAIL\r
+@echo To run this script you must open a "Visual Studio .NET Command Prompt"\r
+@echo (32 bit host compiler). The PS Vita SDK must be installed, too.\r
+:END\r