From d61a6ea952e3709d9de2237e94a14c32457f3dfe Mon Sep 17 00:00:00 2001 From: sozud <122322823+sozud@users.noreply.github.com> Date: Sun, 9 Apr 2023 00:27:01 -0400 Subject: [PATCH] Initial Saturn support (#728) * Saturn support * linter issues * Fix black formatting issues * Try fixing ci * Try 3.10.0 * Try 3.9 * Update asm-differ hash --------- Co-authored-by: sozud --- .github/workflows/ci.yml | 8 +- backend/Dockerfile | 20 +++-- backend/compilers/download.py | 15 ++++ backend/coreapp/compilers.py | 30 ++++++++ backend/coreapp/flags.py | 5 ++ backend/coreapp/platforms.py | 29 ++++++++ backend/poetry.lock | 2 +- docker-compose.yaml | 1 + frontend/src/app/(navfooter)/credits/page.tsx | 1 + .../PlatformSelect/PlatformIcon.tsx | 2 + .../src/components/PlatformSelect/saturn.svg | 74 +++++++++++++++++++ .../src/lib/i18n/locales/en/compilers.json | 2 + 12 files changed, 177 insertions(+), 12 deletions(-) create mode 100644 frontend/src/components/PlatformSelect/saturn.svg diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fbdf073e..a2da307c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: jobs: full_test_and_build: name: full test and build - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 @@ -45,6 +45,7 @@ jobs: binutils-aarch64-linux-gnu \ binutils-mips-linux-gnu \ binutils-powerpc-linux-gnu \ + binutils-sh-elf \ dos2unix \ libprotobuf-dev \ libnl-route-3-dev \ @@ -54,7 +55,7 @@ jobs: - name: Install apt dependencies (cached) uses: awalsh128/cache-apt-pkgs-action@v1 with: - packages: docker-ce docker-ce-cli containerd.io docker-compose-plugin binutils-aarch64-linux-gnu binutils-mips-linux-gnu binutils-powerpc-linux-gnu dos2unix libprotobuf-dev libnl-route-3-dev libncurses5 protobuf-compiler wine software-properties-common + packages: docker-ce docker-ce-cli containerd.io docker-compose-plugin binutils-aarch64-linux-gnu binutils-mips-linux-gnu binutils-powerpc-linux-gnu binutils-sh-elf dos2unix libprotobuf-dev libnl-route-3-dev libncurses5 protobuf-compiler wine software-properties-common version: 1.0 - name: Install DOSEMU run: |- @@ -162,7 +163,8 @@ jobs: docker build backend \ -t decompme_backend \ --build-arg ENABLE_WII_GC_SUPPORT=YES \ - --build-arg ENABLE_PS1_SUPPORT=YES + --build-arg ENABLE_PS1_SUPPORT=YES \ + --build-arg ENABLE_SATURN_SUPPORT=YES - name: Run tests run: |- mkdir -p sandbox && chmod 777 sandbox diff --git a/backend/Dockerfile b/backend/Dockerfile index dcf12df1..be955cca 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 as base +FROM ubuntu:22.04 as base ENV DEBIAN_FRONTEND=noninteractive @@ -6,8 +6,8 @@ RUN apt-get update && apt-get install -y \ python3-pip \ python3 \ python-is-python3 \ - python3.9-venv \ - python3.9-dev + python3.10-venv \ + python3.10-dev FROM base AS nsjail @@ -37,6 +37,7 @@ RUN apt-get -y update && apt-get install -y \ binutils-mips-linux-gnu \ binutils-powerpc-linux-gnu \ binutils-aarch64-linux-gnu \ + binutils-sh-elf \ curl \ gcc-mips-linux-gnu \ git \ @@ -50,7 +51,7 @@ RUN apt-get -y update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | \ - POETRY_VERSION=1.3.1 POETRY_HOME=/etc/poetry python3.9 - + POETRY_VERSION=1.3.1 POETRY_HOME=/etc/poetry python3.10 - COPY --from=nsjail /nsjail/nsjail /bin/nsjail @@ -60,6 +61,7 @@ COPY --from=ghcr.io/decompals/wibo:0.2.4 /usr/local/sbin/wibo /usr/bin/ ARG ENABLE_NDS_SUPPORT ARG ENABLE_PS1_SUPPORT ARG ENABLE_WII_GC_SUPPORT +ARG ENABLE_SATURN_SUPPORT RUN if [ "${ENABLE_NDS_SUPPORT}" = "YES" ] || \ [ "${ENABLE_PS1_SUPPORT}" = "YES" ] || \ [ "${ENABLE_WII_GC_SUPPORT}" = "YES" ]; then \ @@ -68,8 +70,9 @@ RUN if [ "${ENABLE_NDS_SUPPORT}" = "YES" ] || \ wine; \ fi -# ps1 specifics -RUN if [ "${ENABLE_PS1_SUPPORT}" = "YES" ] ; then \ +# install dos2unix and dosemu2 for ps1 and saturn +RUN if [ "${ENABLE_PS1_SUPPORT}" = "YES" ] || \ + [ "${ENABLE_SATURN_SUPPORT}" = "YES" ]; then \ apt-get update && \ apt-get install -y -o APT::Immediate-Configure=false \ dos2unix software-properties-common && \ @@ -97,9 +100,10 @@ ENV ENABLE_N64_SUPPORT=${ENABLE_N64_SUPPORT} ENV ENABLE_NDS_SUPPORT=${ENABLE_NDS_SUPPORT} ENV ENABLE_PS1_SUPPORT=${ENABLE_PS1_SUPPORT} ENV ENABLE_SWITCH_SUPPORT=${ENABLE_SWITCH_SUPPORT} +ENV ENABLE_SATURN_SUPPORT=${ENABLE_SATURN_SUPPORT} -RUN python3.9 -m pip install requests tqdm \ - && python3.9 /compilers/download.py \ +RUN python3.10 -m pip install requests tqdm \ + && python3.10 /compilers/download.py \ && rm -rf /compilers/download_cache/ RUN mkdir -p /etc/fonts diff --git a/backend/compilers/download.py b/backend/compilers/download.py index 6b3963b9..0dde8d62 100755 --- a/backend/compilers/download.py +++ b/backend/compilers/download.py @@ -604,6 +604,19 @@ def download_ps1(): shutil.rmtree(compilers_path) +def download_saturn(): + if host_os != LINUX: + print("saturn compilers unsupported on " + host_os.name) + return + + download_zip( + url="https://github.com/sozud/saturn-compilers/archive/refs/heads/main.zip", + ) + + shutil.move(f"{COMPILERS_DIR}/saturn-compilers-main/cygnus-2.7-96Q3", COMPILERS_DIR) + shutil.rmtree(f"{COMPILERS_DIR}/saturn-compilers-main") + + def download_ps2(): if host_os != LINUX: print("ps2 compilers unsupported on " + host_os.name) @@ -817,6 +830,8 @@ def main(args): download_nds() if should_download("ps1"): download_ps1() + if should_download("saturn"): + download_saturn() if should_download("ps2"): download_ps2() if should_download("switch"): diff --git a/backend/coreapp/compilers.py b/backend/coreapp/compilers.py index acf0bc30..e227f2d0 100644 --- a/backend/coreapp/compilers.py +++ b/backend/coreapp/compilers.py @@ -16,6 +16,7 @@ from coreapp.flags import ( COMMON_GCC_PS1_FLAGS, COMMON_IDO_FLAGS, COMMON_MWCC_FLAGS, + COMMON_GCC_SATURN_FLAGS, Flags, ) @@ -32,6 +33,7 @@ from coreapp.platforms import ( PS1, PS2, SWITCH, + SATURN, ) import platform as platform_stdlib @@ -130,6 +132,11 @@ class GCCPS1Compiler(GCCCompiler): flags: ClassVar[Flags] = COMMON_GCC_PS1_FLAGS +@dataclass(frozen=True) +class GCCSaturnCompiler(GCCCompiler): + flags: ClassVar[Flags] = COMMON_GCC_SATURN_FLAGS + + @dataclass(frozen=True) class IDOCompiler(Compiler): is_ido: ClassVar[bool] = True @@ -334,6 +341,21 @@ PSYQ46 = GCCPS1Compiler( cc=PSYQ_CC, ) +# Saturn +SATURN_CC = ( + 'cat "$INPUT" | unix2dos > dos_src.c && cp -r ${COMPILER_DIR}/* . && ' + + '(HOME="." dosemu -quiet -dumb -f ${COMPILER_DIR}/dosemurc -K . -E "G:\RUN_CPP.BAT dos_src.c -o src_proc.c") && ' + + '(HOME="." dosemu -quiet -dumb -f ${COMPILER_DIR}/dosemurc -K . -E "G:\RUN_CC1.BAT -quiet ${COMPILER_FLAGS} src_proc.c -o cc1.o") && ' + + '(HOME="." dosemu -quiet -dumb -f ${COMPILER_DIR}/dosemurc -K . -E "G:\RUN_AS.BAT cc1.o -o as.o") && ' + + 'cp as.o "$OUTPUT"' +) + +CYGNUS_2_7_96Q3 = GCCSaturnCompiler( + id="cygnus-2.7-96Q3", + platform=SATURN, + cc=SATURN_CC, +) + # PS2 EE_GCC29_990721 = GCCCompiler( id="ee-gcc2.9-990721", @@ -889,6 +911,8 @@ _all_compilers: List[Compiler] = [ PSYQ43, PSYQ45, PSYQ46, + # Saturn + CYGNUS_2_7_96Q3, # PS2 EE_GCC29_990721, EE_GCC29_991111, @@ -1068,6 +1092,12 @@ _all_presets = [ PSYQ43, "-O2 -G8", ), + # Saturn + Preset( + "Castlevania: Symphony of the Night", + CYGNUS_2_7_96Q3, + "-O2 -m2 -fsigned-char", + ), # N64 Preset("AeroGauge", IDO53, "-O2 -mips2"), Preset("AeroGauge JP Kiosk Demo", IDO53, "-O2 -mips1"), diff --git a/backend/coreapp/flags.py b/backend/coreapp/flags.py index a582f5d5..70c465d6 100644 --- a/backend/coreapp/flags.py +++ b/backend/coreapp/flags.py @@ -159,3 +159,8 @@ COMMON_GCC_PS1_FLAGS: Flags = [ FlagSet(id="sdata_limit", flags=["-G0", "-G4", "-G8"]), FlagSet(id="endianness", flags=["-mel", "-meb"]), ] + +COMMON_GCC_SATURN_FLAGS: Flags = [ + FlagSet(id="gcc_opt_level", flags=["-O0", "-O1", "-O2", "-O3"]), + FlagSet(id="gcc_arch", flags=["-m2"]), +] diff --git a/backend/coreapp/platforms.py b/backend/coreapp/platforms.py index ebc3785b..5642d459 100644 --- a/backend/coreapp/platforms.py +++ b/backend/coreapp/platforms.py @@ -229,6 +229,34 @@ PS1 = Platform( .set noat .set noreorder +""", +) + +SATURN = Platform( + id="saturn", + name="Saturn", + description="SH2 (big-endian)", + arch="sh2", + assemble_cmd='sh-elf-as --isa=sh2 --big -o "$OUTPUT" "$INPUT"', + objdump_cmd="sh-elf-objdump", + nm_cmd="sh-elf-nm", + diff_flags=COMMON_DIFF_FLAGS, + asm_prelude=""" +.macro .late_rodata + .section .rodata +.endm + +.macro glabel label + .global \label + .type \label, @function + \label: +.endm + +.macro jlabel label + \label: +.endm + + """, ) @@ -687,6 +715,7 @@ _platforms: OrderedDict[str, Platform] = OrderedDict( "irix": IRIX, "n64": N64, "ps1": PS1, + "saturn": SATURN, "ps2": PS2, "gc_wii": GC_WII, "nds_arm9": NDS_ARM9, diff --git a/backend/poetry.lock b/backend/poetry.lock index 138a3a64..a518aa9a 100644 --- a/backend/poetry.lock +++ b/backend/poetry.lock @@ -51,7 +51,7 @@ watchdog = "^2.2.0" type = "git" url = "https://github.com/simonlindholm/asm-differ.git" reference = "HEAD" -resolved_reference = "857b39804a6f764634483cff7adc168a2f3e5c87" +resolved_reference = "f51abc54f7e2fc5c1eb1f4d148cea4f769a95b1d" [[package]] name = "attrs" diff --git a/docker-compose.yaml b/docker-compose.yaml index 8245adb5..13d7bdd2 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -21,6 +21,7 @@ services: ENABLE_WII_GC_SUPPORT: "NO" # dont install clang by default ENABLE_SWITCH_SUPPORT: "NO" + ENABLE_SATURN_SUPPORT: "NO" cap_drop: - all cap_add: diff --git a/frontend/src/app/(navfooter)/credits/page.tsx b/frontend/src/app/(navfooter)/credits/page.tsx index 5ad16769..a35cec9b 100644 --- a/frontend/src/app/(navfooter)/credits/page.tsx +++ b/frontend/src/app/(navfooter)/credits/page.tsx @@ -24,6 +24,7 @@ const ICON_SOURCES = { "GBA SVG by Andrew Vester from NounProject.com": "https://thenounproject.com/icon/gameboy-advanced-752507/", "Happy Mac by NiloGlock": "https://commons.wikimedia.org/wiki/File:Happy_Mac.svg", "Tiger-like-x by Althepal": "https://commons.wikimedia.org/wiki/File:Tiger-like-x.svg", + "Saturn by JustDanPatrick": "https://upload.wikimedia.org/wikipedia/commons/archive/7/78/20220518145749%21Sega_Saturn_Black_Logo.svg", } type Contributor = { diff --git a/frontend/src/components/PlatformSelect/PlatformIcon.tsx b/frontend/src/components/PlatformSelect/PlatformIcon.tsx index 08e9948c..c161f8d5 100644 --- a/frontend/src/components/PlatformSelect/PlatformIcon.tsx +++ b/frontend/src/components/PlatformSelect/PlatformIcon.tsx @@ -8,6 +8,7 @@ import LogoN64 from "./n64.svg" import LogoNDS from "./nds.svg" import LogoPS1 from "./ps1.svg" import LogoPS2 from "./ps2.svg" +import LogoSaturn from "./saturn.svg" import LogoSwitch from "./switch.svg" import UnknownIcon from "./unknown.svg" @@ -24,6 +25,7 @@ const ICONS = { "ps2": LogoPS2, "n3ds": LogoN3DS, "switch": LogoSwitch, + "saturn": LogoSaturn, } export const PLATFORMS = Object.keys(ICONS) diff --git a/frontend/src/components/PlatformSelect/saturn.svg b/frontend/src/components/PlatformSelect/saturn.svg new file mode 100644 index 00000000..915fcc69 --- /dev/null +++ b/frontend/src/components/PlatformSelect/saturn.svg @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/frontend/src/lib/i18n/locales/en/compilers.json b/frontend/src/lib/i18n/locales/en/compilers.json index 5bfb6ea3..11193744 100644 --- a/frontend/src/lib/i18n/locales/en/compilers.json +++ b/frontend/src/lib/i18n/locales/en/compilers.json @@ -106,6 +106,8 @@ "psyq4.5": "PSYQ4.5 (gcc 2.91.66)", "psyq4.6": "PSYQ4.6 (gcc 2.95.2)", + "cygnus-2.7-96Q3": "cygnus-2.7-96Q3 SOA-960904", + "armcc_opt_level": "Optimization level", "armcc_opt_level.-O0": "No optimization", "armcc_opt_level.-O1": "Some optimization",