Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build

on:
push:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
container: ghcr.io/grumpycoders/pcsx-redux-build:latest

steps:
- uses: actions/checkout@v4

- name: Nugget
# Checked out rather than vendored: nugget's psyqo-lua consumes psxlua,
# so a submodule here would close a dependency cycle.
uses: actions/checkout@v4
with:
repository: pcsx-redux/nugget
path: nugget

- name: Library
run: make -C src psx -j2

- name: Library without the parser
run: |
make -C src clean
make -C src psx-noparser -j2

- name: Compiler
run: |
make -C src clean
make -C src psx-luac NUGGET=$GITHUB_WORKSPACE/nugget -j2

- name: pcsx-redux
# --appimage-extract rather than mounting it: the runner has no FUSE.
run: |
curl -sL -o pcsx-redux.zip https://distrib.app/pub/org/pcsx-redux/project/dev-linux-x64/latest
unzip -q pcsx-redux.zip
./PCSX-Redux-*.AppImage --appimage-extract > /dev/null

- name: Compile a script on the console
# pcsx-redux brings SDL video up even under -testmode, which is why
# pcsx-redux's own CI runs its tests under xvfb-run.
run: xvfb-run tests/run-luac.sh "$GITHUB_WORKSPACE/squashfs-root/AppRun"

- uses: actions/upload-artifact@v4
with:
name: luac.ps-exe
path: src/luac.ps-exe
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.o
*.a
luac
lua
*.ps-exe
*.elf
*.map
*.dep
23 changes: 19 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,33 @@ further information about Lua, see doc/readme.html.

This version of Lua has been modified to work on the Sony PlayStation 1.

There are now only three platforms available for compilation:
There are now only four platforms available for compilation:
- `psx`: This platform is used to compile Lua for the Sony PlayStation 1. This
will only generate a library file named "liblua.a". The binary footprint of
this library will be roughly 110kB.
- `psx-noparser`: This platform is used to compile Lua for the Sony PlayStation
1 without the parser. Only precompiled bytecode can be loaded by this version.
This will only generate a library file named "liblua-noparser.a". The binary
footprint of this library will be roughly 85kB.
- `psx-luac`: This platform builds the Lua compiler itself as a ps-exe, named
"luac.ps-exe". Running the compiler on the target is what makes its bytecode
a sure thing: the number representation, the pointer size and the endianness
are the target's by construction rather than by a matching host build.
- `host32`: This platform is used to compile Lua for a 32-bit host system. This
will generate the Lua interpreter (lua) and the lua compiler (luac). The
compiler should be able to generate bytecode that can be run on the Sony
PlayStation 1.
will generate the Lua interpreter (lua). It no longer generates the compiler;
use `psx-luac` for that, since a 32-bit host build is not available in most
environments any more.

The `psx-luac` platform is the only part of this repository that needs nugget,
and it is not vendored: nugget's psyqo-lua consumes psxlua, so a submodule here
would close a dependency cycle. Point NUGGET at a checkout instead.

make -C src psx-luac NUGGET=/path/to/nugget

luac.ps-exe reads its arguments from unmapped memory at 0x40000000 and does its
file I/O over PCDRV, so it runs under an emulator that serves both. src/args.lua
is the pcsx-redux side: call createArgsBuffer() with the arguments you would
have passed on a command line, and load it alongside the executable.

The following key differences exist between the original Lua 5.2.4 and this
version of Lua:
Expand Down
13 changes: 7 additions & 6 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ MYOBJS=

# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======

PLATS= host32 psx psx-noparser
PLATS= host32 psx psx-noparser psx-luac

ifeq ($(NOPARSER),true)
LUA_A= liblua-noparser.a
Expand All @@ -78,8 +78,8 @@ LUA_O= lua.o
LUAC_T= luac
LUAC_O= luac.o

ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)
ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
ALL_O= $(BASE_O) $(LUA_O)
ALL_T= $(LUA_A) $(LUA_T)
ALL_A= $(LUA_A)

# Targets start here.
Expand All @@ -98,11 +98,9 @@ $(LUA_A): $(BASE_O)
$(LUA_T): $(LUA_O) $(LUA_A)
$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)

$(LUAC_T): $(LUAC_O) $(LUA_A)
$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)

clean:
$(RM) $(ALL_T) $(ALL_O) $(ALL_A) liblua-noparser.a lnoparser.o
$(RM) $(LUAC_T) $(LUAC_O) psx-heap.o psx-glue.o luac.elf luac.map luac.ps-exe *.dep

depend:
@$(CC) $(CFLAGS) -MM l*.c
Expand Down Expand Up @@ -132,6 +130,9 @@ psx:
psx-noparser:
$(MAKE) a TARGET=psx NOPARSER=true

psx-luac: psx
$(MAKE) -f luac-psx.mk

# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: all $(PLATS) default o a clean depend echo none

Expand Down
33 changes: 33 additions & 0 deletions src/args.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local ffi = require 'ffi'
local uint8_t = ffi.typeof 'uint8_t[?]'
local argsBuffer
local processName = 'luac.ps-exe'

function createArgsBuffer(...)
local args = { ... }
local spaceNeeded = #processName + 2
for i, v in ipairs(args) do
local a = tostring(v)
spaceNeeded = spaceNeeded + #a + 1
end
argsBuffer = ffi.new(uint8_t, spaceNeeded)
local ptr = ffi.cast('uint8_t *', argsBuffer)
ffi.copy(ptr, processName)
ptr = ptr + #processName + 1
for i, v in ipairs(args) do
local a = tostring(v)
ffi.copy(ptr, a)
ptr = ptr + #a + 1
end
ptr[0] = 0
end

function UnknownMemoryRead(address, size)
if size ~= 1 then return 0xffffffff end
local offset = address - 0x40000000
if offset < 0 then return 0xff end
if offset >= ffi.sizeof(argsBuffer) then return 0xff end
return argsBuffer[offset]
end

createArgsBuffer()
35 changes: 35 additions & 0 deletions src/luac-psx.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Builds luac as a ps-exe, so the compiler runs on the console (or in an
# emulator) instead of on the host. Input and output go through PCDRV, and
# argv is read from unmapped memory at 0x40000000 - see args.lua.
#
# psxlua does not depend on nugget: nugget's psyqo-lua consumes psxlua, so
# vendoring it here would close a cycle. Point NUGGET at a checkout instead.
#
# make psx-luac NUGGET=/path/to/nugget
#
# liblua.a must be built for the same target first; the psx-luac rule in
# Makefile does that for you.

ifeq ($(strip $(NUGGET)),)
$(error NUGGET is not set - point it at a nugget checkout, e.g. make psx-luac NUGGET=../../nugget)
endif

TARGET = luac
TYPE = ps-exe

SRCS = \
luac.c \
psx-heap.c \
psx-glue.s \
$(NUGGET)/common/syscalls/printf.s \
$(NUGGET)/common/crt0/memory-s.s \
$(NUGGET)/common/crt0/memory-c.c \

LIBRARIES = liblua.a

CPPFLAGS += -I. -DLUA_COMPAT_ALL

include $(NUGGET)/common.mk

liblua.a:
$(MAKE) -f Makefile a TARGET=psx
Loading
Loading