From 34a62c7f738347e4981e7882bbf4f7a4f706dc5d Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sun, 17 Apr 2022 23:41:39 +0200 Subject: [PATCH] Add PS5 port. --- doc/install.html | 12 ++++- doc/luajit.html | 2 +- src/lib_io.c | 2 +- src/lib_os.c | 2 +- src/lj_alloc.c | 2 +- src/lj_arch.h | 11 ++++- src/lj_prng.c | 4 +- src/ps5build.bat | 123 +++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 src/ps5build.bat diff --git a/doc/install.html b/doc/install.html index 90f76bf8..a38bdb5f 100644 --- a/doc/install.html +++ b/doc/install.html @@ -118,7 +118,7 @@ operating systems, CPUs and compilers: x64 (64 bit) GCC 4.2+ -GCC 4.2+
ORBIS (PS4) +GCC 4.2+
ORBIS (PS4)
PROSPERO (PS5) XCode 5.0+
Clang MSVC
Durango (Xbox One) @@ -478,6 +478,16 @@ cd src ps4build

+To cross-compile for PS5 from a Windows host, +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: +

+
+cd src
+ps5build
+
+

To cross-compile for PS Vita from a Windows host, open a "Visual Studio .NET Command Prompt" (32 bit host compiler), cd to the directory where you've unpacked the sources and diff --git a/doc/luajit.html b/doc/luajit.html index 2aa143ae..06774ddf 100644 --- a/doc/luajit.html +++ b/doc/luajit.html @@ -162,7 +162,7 @@ LuaJIT is Copyright © 2005-2022 Mike Pall, released under the EmbeddedAndroidiOS - +
PS3PS4PS VitaXbox 360Xbox One
PS3PS4PS5PS VitaXbox 360Xbox One
diff --git a/src/lib_io.c b/src/lib_io.c index a3278ab2..7f218e49 100644 --- a/src/lib_io.c +++ b/src/lib_io.c @@ -439,7 +439,7 @@ LJLIB_CF(io_popen) LJLIB_CF(io_tmpfile) { IOFileUD *iof = io_file_new(L); -#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5 || LJ_TARGET_PSVITA iof->fp = NULL; errno = ENOSYS; #else iof->fp = tmpfile(); diff --git a/src/lib_os.c b/src/lib_os.c index a61ded40..eb8704cf 100644 --- a/src/lib_os.c +++ b/src/lib_os.c @@ -76,7 +76,7 @@ LJLIB_CF(os_rename) LJLIB_CF(os_tmpname) { -#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5 || LJ_TARGET_PSVITA lj_err_caller(L, LJ_ERR_OSUNIQF); return 0; #else diff --git a/src/lj_alloc.c b/src/lj_alloc.c index 165203fa..20e60493 100644 --- a/src/lj_alloc.c +++ b/src/lj_alloc.c @@ -330,7 +330,7 @@ static void *mmap_plain(size_t size) #define CALL_MMAP(prng, size) mmap_plain(size) #endif -#if LJ_64 && !LJ_GC64 && ((defined(__FreeBSD__) && __FreeBSD__ < 10) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4 +#if LJ_64 && !LJ_GC64 && ((defined(__FreeBSD__) && __FreeBSD__ < 10) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4 && !LJ_TARGET_PS5 #include diff --git a/src/lj_arch.h b/src/lj_arch.h index cc4eae72..1852c497 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -83,7 +83,7 @@ #define LUAJIT_OS LUAJIT_OS_OSX #elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ defined(__NetBSD__) || defined(__OpenBSD__) || \ - defined(__DragonFly__)) && !defined(__ORBIS__) + defined(__DragonFly__)) && !defined(__ORBIS__) && !defined(__PROSPERO__) #define LUAJIT_OS LUAJIT_OS_BSD #elif (defined(__sun__) && defined(__svr4__)) #define LJ_TARGET_SOLARIS 1 @@ -139,6 +139,13 @@ #define NULL ((void*)0) #endif +#ifdef __PROSPERO__ +#define LJ_TARGET_PS5 1 +#define LJ_TARGET_CONSOLE 1 +#undef NULL +#define NULL ((void*)0) +#endif + #ifdef __psp2__ #define LJ_TARGET_PSVITA 1 #define LJ_TARGET_CONSOLE 1 @@ -634,7 +641,7 @@ extern void *LJ_WIN_LOADLIBA(const char *path); #endif #endif -#if defined(LUAJIT_NO_UNWIND) || __GNU_COMPACT_EH__ || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4 +#if defined(LUAJIT_NO_UNWIND) || __GNU_COMPACT_EH__ || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5 #define LJ_NO_UNWIND 1 #endif diff --git a/src/lj_prng.c b/src/lj_prng.c index fff155a1..fd8219de 100644 --- a/src/lj_prng.c +++ b/src/lj_prng.c @@ -83,7 +83,7 @@ extern int XNetRandom(void *buf, unsigned int len); extern int sys_get_random_number(void *buf, uint64_t len); -#elif LJ_TARGET_PS4 || LJ_TARGET_PSVITA +#elif LJ_TARGET_PS4 || LJ_TARGET_PS5 || LJ_TARGET_PSVITA extern int sceRandomGetRandomNumber(void *buf, size_t len); @@ -171,7 +171,7 @@ int LJ_FASTCALL lj_prng_seed_secure(PRNGState *rs) if (sys_get_random_number(rs->u, sizeof(rs->u)) == 0) goto ok; -#elif LJ_TARGET_PS4 || LJ_TARGET_PSVITA +#elif LJ_TARGET_PS4 || LJ_TARGET_PS5 || LJ_TARGET_PSVITA if (sceRandomGetRandomNumber(rs->u, sizeof(rs->u)) == 0) goto ok; diff --git a/src/ps5build.bat b/src/ps5build.bat new file mode 100644 index 00000000..0b1ebd5b --- /dev/null +++ b/src/ps5build.bat @@ -0,0 +1,123 @@ +@rem Script to build LuaJIT with the PS5 SDK. +@rem Donated to the public domain. +@rem +@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler) +@rem or "VS20xx x64 Native Tools Command Prompt". +@rem +@rem Then cd to this directory and run this script. +@rem +@rem Recommended invocation: +@rem +@rem ps5build release build, amalgamated, 64-bit GC +@rem ps5build debug debug build, amalgamated, 64-bit GC +@rem +@rem Additional command-line options (not generally recommended): +@rem +@rem gc32 (before debug) 32-bit GC +@rem noamalg (after debug) non-amalgamated build + +@if not defined INCLUDE goto :FAIL +@if not defined SCE_PROSPERO_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 lib_buffer.c +@set GC64= +@set DASC=vm_x64.dasc + +@if "%1" neq "gc32" goto :NOGC32 +@shift +@set GC64=-DLUAJIT_DISABLE_GC64 +@set DASC=vm_x86.dasc +:NOGC32 + +%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 -D NO_UNWIND +minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC% +@if errorlevel 1 goto :BAD + +%LJCOMPILE% /I "." /I %DASMDIR% %GC64% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND 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_PROSPERO_SDK_DIR%\host_tools\bin\prospero-clang" -c -Wall -DLUAJIT_DISABLE_FFI %GC64% +@set LJLIB="%SCE_PROSPERO_SDK_DIR%\host_tools\bin\prospero-llvm-ar" rcus +@set INCLUDE="" + +%SCE_PROSPERO_SDK_DIR%\host_tools\bin\prospero-llvm-as -o lj_vm.o lj_vm.s + +@if "%1" neq "debug" goto :NODEBUG +@shift +@set LJCOMPILE=%LJCOMPILE% -g -O0 +@set TARGETLIB=libluajitD_ps5.a +goto :BUILD +:NODEBUG +@set LJCOMPILE=%LJCOMPILE% -O2 +@set TARGETLIB=libluajit_ps5.a +:BUILD +del %TARGETLIB% +@if "%1" neq "noamalg" 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 PS5 === + +@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 PS5 Prospero SDK must be installed, too. +:END
GCCClang
LLVM
MSVC