From 6a47e123a4339e33a7942525a19348cd2068b057 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 26 Feb 2014 15:56:07 +0100 Subject: [PATCH] Add PS4 port. Thanks to Eddie Edwards. --- doc/install.html | 20 ++++++++- doc/luajit.html | 2 +- src/lib_io.c | 2 +- src/lib_os.c | 2 +- src/lj_alloc.c | 8 ++-- src/lj_arch.h | 11 ++++- src/ps4build.bat | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 138 insertions(+), 10 deletions(-) create mode 100644 src/ps4build.bat diff --git a/doc/install.html b/doc/install.html index 15193b81..baf14690 100644 --- a/doc/install.html +++ b/doc/install.html @@ -120,7 +120,7 @@ operating systems, CPUs and compilers: x64 (64 bit) GCC 4.x -  +ORBIS (PS4) GCC 4.x MSVC + SDK v7.0
WinSDK v7.0 @@ -460,7 +460,7 @@ make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" \

You can cross-compile for PS3 using the PS3 SDK from -a Linux host or a Windows host (requires 32 bit MinGW (GCC) on the host, +a Linux host or a Windows host (requires 32 bit MinGW (GCC) on the host, too). Due to restrictions on consoles, the JIT compiler is disabled and only the fast interpreter is built:

@@ -468,6 +468,22 @@ only the fast interpreter is built: make HOST_CC="gcc -m32" CROSS=ppu-lv2-

+You can cross-compile for PS4 from a Windows host using +the PS4 SDK (ORBIS) plus 64 bit MSVC. Due to restrictions on +consoles, the JIT compiler is disabled and only the fast interpreter +is built. +

+

+Open a "Visual Studio .NET Command Prompt" (64 bit host compiler), +cd to the directory where you've unpacked the sources and run +the following commands. This builds a static library libluajit.a, +which can be linked against your game, just like the Lua library. +

+
+cd src
+ps4build
+
+

You can cross-compile for Xbox 360 using the Xbox 360 SDK (MSVC + XEDK). Due to restrictions on consoles, the JIT compiler is disabled and only the fast interpreter is built. diff --git a/doc/luajit.html b/doc/luajit.html index 07ef9b97..43af69c9 100644 --- a/doc/luajit.html +++ b/doc/luajit.html @@ -158,7 +158,7 @@ LuaJIT is Copyright © 2005-2014 Mike Pall, released under the WindowsLinuxBSDOSXPOSIX - +
EmbeddedAndroidiOSPS3Xbox 360
EmbeddedAndroidiOSPS3PS4Xbox 360
diff --git a/src/lib_io.c b/src/lib_io.c index 51cad52f..04f0f739 100644 --- a/src/lib_io.c +++ b/src/lib_io.c @@ -426,7 +426,7 @@ LJLIB_CF(io_popen) LJLIB_CF(io_tmpfile) { IOFileUD *iof = io_file_new(L); -#if LJ_TARGET_PS3 +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 iof->fp = NULL; errno = ENOSYS; #else iof->fp = tmpfile(); diff --git a/src/lib_os.c b/src/lib_os.c index 70d9c55a..f62e8c8b 100644 --- a/src/lib_os.c +++ b/src/lib_os.c @@ -70,7 +70,7 @@ LJLIB_CF(os_rename) LJLIB_CF(os_tmpname) { -#if LJ_TARGET_PS3 +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 lj_err_caller(L, LJ_ERR_OSUNIQF); return 0; #else diff --git a/src/lj_alloc.c b/src/lj_alloc.c index b381bba1..f856a7a0 100644 --- a/src/lj_alloc.c +++ b/src/lj_alloc.c @@ -188,7 +188,7 @@ static LJ_AINLINE void *CALL_MMAP(size_t size) return ptr; } -#elif LJ_TARGET_OSX || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun__) +#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun__) /* OSX and FreeBSD mmap() use a naive first-fit linear search. ** That's perfect for us. Except that -pagezero_size must be set for OSX, @@ -197,12 +197,14 @@ static LJ_AINLINE void *CALL_MMAP(size_t size) */ #if LJ_TARGET_OSX #define MMAP_REGION_START ((uintptr_t)0x10000) +#elif LJ_TARGET_PS4 +#define MMAP_REGION_START ((uintptr_t)0x4000) #else #define MMAP_REGION_START ((uintptr_t)0x10000000) #endif #define MMAP_REGION_END ((uintptr_t)0x80000000) -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4 #include #endif @@ -212,7 +214,7 @@ static LJ_AINLINE void *CALL_MMAP(size_t size) /* Hint for next allocation. Doesn't need to be thread-safe. */ static uintptr_t alloc_hint = MMAP_REGION_START; int retry = 0; -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4 static int rlimit_modified = 0; if (LJ_UNLIKELY(rlimit_modified == 0)) { struct rlimit rlim; diff --git a/src/lj_arch.h b/src/lj_arch.h index 8b276e8f..0196eedc 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -66,8 +66,8 @@ #define LUAJIT_OS LUAJIT_OS_LINUX #elif defined(__MACH__) && defined(__APPLE__) #define LUAJIT_OS LUAJIT_OS_OSX -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ - defined(__NetBSD__) || defined(__OpenBSD__) +#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__NetBSD__) || defined(__OpenBSD__)) && !defined(__ORBIS__) #define LUAJIT_OS LUAJIT_OS_BSD #elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__) #define LUAJIT_OS LUAJIT_OS_POSIX @@ -104,6 +104,13 @@ #define LJ_TARGET_CONSOLE 1 #endif +#ifdef __ORBIS__ +#define LJ_TARGET_PS4 1 +#define LJ_TARGET_CONSOLE 1 +#undef NULL +#define NULL ((void*)0) +#endif + #if _XBOX_VER >= 200 #define LJ_TARGET_XBOX360 1 #define LJ_TARGET_CONSOLE 1 diff --git a/src/ps4build.bat b/src/ps4build.bat new file mode 100644 index 00000000..42fc9a64 --- /dev/null +++ b/src/ps4build.bat @@ -0,0 +1,103 @@ +@rem Script to build LuaJIT with the PS4 SDK. +@rem Donated to the public domain. +@rem +@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler) +@rem Then cd to this directory and run this script. + +@if not defined INCLUDE goto :FAIL +@if not defined SCE_ORBIS_SDK_DIR goto :FAIL + +@setlocal +@rem ---- Host compiler ---- +@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE +@set LJLINK=link /nologo +@set LJMT=mt /nologo +@set DASMDIR=..\dynasm +@set DASM=%DASMDIR%\dynasm.lua +@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 + +%LJCOMPILE% host\minilua.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:minilua.exe minilua.obj +@if errorlevel 1 goto :BAD +if exist minilua.exe.manifest^ + %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe + +@rem Check for 64 bit host compiler. +@minilua +@if not errorlevel 8 goto :FAIL + +@set DASMFLAGS=-D P64 +minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc +@if errorlevel 1 goto :BAD + +%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI host\buildvm*.c +@if errorlevel 1 goto :BAD +%LJLINK% /out:buildvm.exe buildvm*.obj +@if errorlevel 1 goto :BAD +if exist buildvm.exe.manifest^ + %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe + +buildvm -m elfasm -o lj_vm.s +@if errorlevel 1 goto :BAD +buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m libdef -o lj_libdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m recdef -o lj_recdef.h %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% +@if errorlevel 1 goto :BAD +buildvm -m folddef -o lj_folddef.h lj_opt_fold.c +@if errorlevel 1 goto :BAD + +@rem ---- Cross compiler ---- +@set LJCOMPILE="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-clang" -c -Wall -DLUAJIT_DISABLE_FFI +@set LJLIB="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-ar" rcus +@set INCLUDE="" + +orbis-as -o lj_vm.o lj_vm.s + +@if "%1" neq "debug" goto :NODEBUG +@shift +@set LJCOMPILE=%LJCOMPILE% -g -O0 +@set TARGETLIB=libluajitD.a +goto :BUILD +:NODEBUG +@set LJCOMPILE=%LJCOMPILE% -O2 +@set TARGETLIB=libluajit.a +:BUILD +del %TARGETLIB% +@if "%1"=="amalg" goto :AMALG +for %%f in (lj_*.c lib_*.c) do ( + %LJCOMPILE% %%f + @if errorlevel 1 goto :BAD +) + +%LJLIB% %TARGETLIB% lj_*.o lib_*.o +@if errorlevel 1 goto :BAD +@goto :NOAMALG +:AMALG +%LJCOMPILE% ljamalg.c +@if errorlevel 1 goto :BAD +%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o +@if errorlevel 1 goto :BAD +:NOAMALG + +@del *.o *.obj *.manifest minilua.exe buildvm.exe +@echo. +@echo === Successfully built LuaJIT for PS4 === + +@goto :END +:BAD +@echo. +@echo ******************************************************* +@echo *** Build FAILED -- Please check the error messages *** +@echo ******************************************************* +@goto :END +:FAIL +@echo To run this script you must open a "Visual Studio .NET Command Prompt" +@echo (64 bit host compiler). The PS4 Orbis SDK must be installed, too. +:END
GCCCLANG
LLVM
MSVC