From 6e61acc747cc355259d56b9132fd9eaeac511bd2 Mon Sep 17 00:00:00 2001 From: CosmicScale Date: Thu, 18 Jul 2024 19:27:09 +0100 Subject: [PATCH 1/4] Fix error when compiling with latest PS2 SDK --- Makefile | 18 ++++-------- cnf_lite.c | 3 ++ linkfile | 85 +++++++++++++++++++----------------------------------- main.c | 19 ++++++++---- 4 files changed, 50 insertions(+), 75 deletions(-) diff --git a/Makefile b/Makefile index 7ca76aa..b06b74d 100644 --- a/Makefile +++ b/Makefile @@ -4,20 +4,11 @@ EE_OBJS = main.o cnf_lite.o EE_INCS := -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I. EE_GPVAL = -G0 EE_CFLAGS = -D_EE -Os -mno-gpopt $(EE_GPVAL) -Wall $(EE_INCS) -EE_LDFLAGS = -Tlinkfile -L$(PS2SDK)/ee/lib -s -EE_LIBS += -lcdvd -ldebug -lc -lkernel-nopatch +EE_LIBS += -ldebug +EE_NEWLIB_NANO ?= 1 +EE_COMPACT_EXECUTABLE ?= 1 -%.o : %.c - $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ - -%.o : %.S - $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ - -%.o : %.s - $(EE_AS) $(EE_ASFLAGS) $< -o $@ - -$(EE_BIN) : $(EE_OBJS) - $(EE_CC) $(EE_CFLAGS) $(EE_LDFLAGS) -o $(EE_BIN) $(EE_OBJS) $(EE_LIBS) +EE_LINKFILE ?= linkfile all: $(EE_BIN) @@ -25,3 +16,4 @@ clean: rm -f $(EE_OBJS) $(EE_BIN) include $(PS2SDK)/Defs.make +include $(PS2SDK)/samples/Makefile.eeglobal \ No newline at end of file diff --git a/cnf_lite.c b/cnf_lite.c index 6e75f3e..c2ec88b 100644 --- a/cnf_lite.c +++ b/cnf_lite.c @@ -2,6 +2,9 @@ #include #include +#define NEWLIB_PORT_AWARE +#include + #include "cnf_lite.h" // Function prototypes. diff --git a/linkfile b/linkfile index fc2a08c..5663d22 100644 --- a/linkfile +++ b/linkfile @@ -1,97 +1,70 @@ -ENTRY(_start); +ENTRY(__start); + +MEMORY { + bios : ORIGIN = 0x00000000, LENGTH = 528K /* 0x00000000 - 0x00084000: BIOS memory */ + bram : ORIGIN = 0x00084000, LENGTH = 496K /* 0x00084000 - 0x00100000: BIOS unused memory */ + gram : ORIGIN = 0x00100000, LENGTH = 31M /* 0x00100000 - 0x02000000: GAME memory */ +} + +REGION_ALIAS("MAIN_REGION", bram); + +PHDRS { + text PT_LOAD; +} SECTIONS { - .text 0x00084000: { - _ftext = . ; + .text : { *(.text) - *(.text.*) - *(.gnu.linkonce.t*) - KEEP(*(.init)) - KEEP(*(.fini)) - QUAD(0) - } - - PROVIDE(_etext = .); - PROVIDE(etext = .); + } >MAIN_REGION :text - .reginfo : { *(.reginfo) } + .reginfo : { *(.reginfo) } >MAIN_REGION - /* Global/static constructors and deconstructors. */ .ctors ALIGN(16): { KEEP(*crtbegin*.o(.ctors)) KEEP(*(EXCLUDE_FILE(*crtend*.o) .ctors)) KEEP(*(SORT(.ctors.*))) KEEP(*(.ctors)) - } + } >MAIN_REGION + .dtors ALIGN(16): { KEEP(*crtbegin*.o(.dtors)) KEEP(*(EXCLUDE_FILE(*crtend*.o) .dtors)) KEEP(*(SORT(.dtors.*))) KEEP(*(.dtors)) - } + } >MAIN_REGION - /* Static data. */ .rodata ALIGN(128): { *(.rodata) - *(.rodata.*) - *(.gnu.linkonce.r*) - } + } >MAIN_REGION .data ALIGN(128): { _fdata = . ; *(.data) - *(.data.*) - *(.gnu.linkonce.d*) SORT(CONSTRUCTORS) - } - - .rdata ALIGN(128): { *(.rdata) } - .gcc_except_table ALIGN(128): { *(.gcc_except_table) } + } >MAIN_REGION _gp = ALIGN(128) + 0x7ff0; - .lit4 ALIGN(128): { *(.lit4) } - .lit8 ALIGN(128): { *(.lit8) } + .lit4 ALIGN(128): { *(.lit4) } >MAIN_REGION + .lit8 ALIGN(128): { *(.lit8) } >MAIN_REGION .sdata ALIGN(128): { *(.sdata) - *(.sdata.*) - *(.gnu.linkonce.s*) - } - - _edata = .; - PROVIDE(edata = .); + } >MAIN_REGION - /* Uninitialized data. */ .sbss ALIGN(128) : { _fbss = . ; *(.sbss) - *(.sbss.*) - *(.gnu.linkonce.sb*) - *(.scommon) - } + } >MAIN_REGION .bss ALIGN(128) : { *(.bss) - *(.bss.*) - *(.gnu.linkonce.b*) - *(COMMON) - } - _end_bss = .; + } >MAIN_REGION /* Symbols needed by crt0.s. */ - PROVIDE(_heap_size = 0x2000); - PROVIDE(_stack_size = 0x2000); + PROVIDE(_end = .); + PROVIDE(_heap_size = -1); - _stack = ALIGN(128); PROVIDE(_stack = .); - . = _stack + _stack_size; - - _end = .; - PROVIDE(end = .); - - /* Unwanted stuff */ - /DISCARD/ : { - * ( .MIPS.abiflags ) - } + PROVIDE(_stack_size = ORIGIN(MAIN_REGION) + LENGTH(MAIN_REGION) - _stack); } diff --git a/main.c b/main.c index fe30f35..f662ae0 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,13 +9,19 @@ #include #include + +#define NEWLIB_PORT_AWARE #include + #include #include #include "cnf_lite.h" +// Disable all the patched functions +DISABLE_PATCHED_FUNCTIONS(); + /* Some macros used for patching. */ #define JAL(addr) (0x0c000000 | (0x3ffffff & ((addr) >> 2))) #define JMP(addr) (0x08000000 | (0x3ffffff & ((addr) >> 2))) @@ -78,18 +85,18 @@ static int InitVideoModeParams(void) temp = (temp & 0xFFFFFC00) | 3; temp = (temp & 0xFFF003FF) | 0x1800; temp = (temp & 0xC00FFFFF) | 0x01200000; - temp = (temp & 0xFFFFFC00FFFFFFFF) | (0xC000L << 19); - temp = (temp & 0xFFE003FFFFFFFFFF) | (0xF300L << 35); - temp = (temp & 0x801FFFFFFFFFFFFF) | (0xC000L << 40); + temp = (temp & 0xFFFFFC00FFFFFFFF) | (0xC000LL << 19); + temp = (temp & 0xFFE003FFFFFFFFFF) | (0xF300LL << 35); + temp = (temp & 0x801FFFFFFFFFFFFF) | (0xC000LL << 40); *emu_SYNCHV_I = temp; // Nearly a repeat of the block above. temp = (temp & 0xFFFFFC00) | 4; temp = (temp & 0xFFF003FF) | 0x1800; temp = (temp & 0xC00FFFFF) | 0x01200000; - temp = (temp & 0xFFFFFC00FFFFFFFF) | (0xC000L << 19); - temp = (temp & 0xFFE003FFFFFFFFFF) | (0xF300L << 35); - temp = (temp & 0x801FFFFFFFFFFFFF) | (0xC000L << 40); + temp = (temp & 0xFFFFFC00FFFFFFFF) | (0xC000LL << 19); + temp = (temp & 0xFFE003FFFFFFFFFF) | (0xF300LL << 35); + temp = (temp & 0x801FFFFFFFFFFFFF) | (0xC000LL << 40); *emu_SYNCHV_NI = temp; } From 5a46e07a23f612025ebcee51c4ecfa94a24a5514 Mon Sep 17 00:00:00 2001 From: AKuHAK <621640+AKuHAK@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:58:55 +0300 Subject: [PATCH 2/4] Update compilation.yml --- .github/workflows/compilation.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/compilation.yml b/.github/workflows/compilation.yml index 9029aba..d9236f2 100644 --- a/.github/workflows/compilation.yml +++ b/.github/workflows/compilation.yml @@ -7,14 +7,10 @@ on: jobs: build: runs-on: ubuntu-latest - container: ps2dev/ps2dev:v1.0 + container: ghcr.io/ps2homebrew/ps2homebrew:main # instead of "ps2dev/ps2dev:latest" you can use different tags, for example for old projects you can use "ps2dev/ps2dev:v1.0" steps: - - name: Install dependencies - run: | - apk add build-base git zip - - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Compile project run: | @@ -44,7 +40,7 @@ jobs: - name: Create release if: github.ref == 'refs/heads/main' - uses: marvinpinto/action-automatic-releases@latest + uses: mathieucarbou/marvinpinto-action-automatic-releases@latest with: repo_token: "${{ secrets.GITHUB_TOKEN }}" automatic_release_tag: "latest" From 604192bc2be6ba7f6f823979a0fac64c4f209950 Mon Sep 17 00:00:00 2001 From: CosmicScale Date: Fri, 19 Jul 2024 13:22:27 +0100 Subject: [PATCH 3/4] Replaced linkfile and updated Makefile to pack elf --- Makefile | 9 +++++-- linkfile | 77 ++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index b06b74d..451917b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ EE_BIN = PS1VModeNeg.elf +EE_BIN_PACKED = PS1VModeNegPacked.elf EE_OBJS = main.o cnf_lite.o EE_INCS := -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I. @@ -10,10 +11,14 @@ EE_COMPACT_EXECUTABLE ?= 1 EE_LINKFILE ?= linkfile -all: $(EE_BIN) +all: $(EE_BIN_PACKED) + +$(EE_BIN_PACKED): $(EE_BIN) + echo "Compressing..." + ps2-packer $< $@ clean: - rm -f $(EE_OBJS) $(EE_BIN) + rm -f $(EE_OBJS) $(EE_BIN) $(EE_BIN_PACKED) include $(PS2SDK)/Defs.make include $(PS2SDK)/samples/Makefile.eeglobal \ No newline at end of file diff --git a/linkfile b/linkfile index 5663d22..2d7fe5d 100644 --- a/linkfile +++ b/linkfile @@ -1,32 +1,54 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +# +# Linkfile script for ee-ld +*/ ENTRY(__start); MEMORY { - bios : ORIGIN = 0x00000000, LENGTH = 528K /* 0x00000000 - 0x00084000: BIOS memory */ - bram : ORIGIN = 0x00084000, LENGTH = 496K /* 0x00084000 - 0x00100000: BIOS unused memory */ + bios : ORIGIN = 0x00000000, LENGTH = 592K /* 0x00000000 - 0x00094000: BIOS memory & patched area */ + bram : ORIGIN = 0x00094000, LENGTH = 432K /* 0x00094000 - 0x00100000: BIOS unused memory */ gram : ORIGIN = 0x00100000, LENGTH = 31M /* 0x00100000 - 0x02000000: GAME memory */ + + high : ORIGIN = 0x01ee8000, LENGTH = 1120K /* 0x01ee8000 - 0x02000000: */ } REGION_ALIAS("MAIN_REGION", bram); +END_MAIN_REGION = ORIGIN(MAIN_REGION) + LENGTH(MAIN_REGION); + PHDRS { text PT_LOAD; } SECTIONS { .text : { + _ftext = . ; *(.text) + *(.text.*) + *(.gnu.linkonce.t*) + KEEP(*(.init)) + KEEP(*(.fini)) + QUAD(0) } >MAIN_REGION :text - .reginfo : { *(.reginfo) } >MAIN_REGION + PROVIDE(_etext = .); + PROVIDE(etext = .); + /* Global/static constructors and deconstructors. */ .ctors ALIGN(16): { KEEP(*crtbegin*.o(.ctors)) KEEP(*(EXCLUDE_FILE(*crtend*.o) .ctors)) KEEP(*(SORT(.ctors.*))) KEEP(*(.ctors)) } >MAIN_REGION - .dtors ALIGN(16): { KEEP(*crtbegin*.o(.dtors)) KEEP(*(EXCLUDE_FILE(*crtend*.o) .dtors)) @@ -34,37 +56,66 @@ SECTIONS { KEEP(*(.dtors)) } >MAIN_REGION - .rodata ALIGN(128): { - *(.rodata) - } >MAIN_REGION + .reginfo : { *(.reginfo) } >MAIN_REGION .data ALIGN(128): { _fdata = . ; *(.data) + *(.data.*) + *(.gnu.linkonce.d*) SORT(CONSTRUCTORS) } >MAIN_REGION + /* Static data. */ + .rodata ALIGN(128): { + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r*) + } >MAIN_REGION + + .rdata ALIGN(128): { *(.rdata) } >MAIN_REGION + .gcc_except_table ALIGN(128): { *(.gcc_except_table) } >MAIN_REGION + _gp = ALIGN(128) + 0x7ff0; .lit4 ALIGN(128): { *(.lit4) } >MAIN_REGION .lit8 ALIGN(128): { *(.lit8) } >MAIN_REGION .sdata ALIGN(128): { *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s*) } >MAIN_REGION + _edata = .; + PROVIDE(edata = .); + + /* Uninitialized data. */ .sbss ALIGN(128) : { _fbss = . ; *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb*) + *(.scommon) } >MAIN_REGION .bss ALIGN(128) : { *(.bss) + *(.bss.*) + *(.gnu.linkonce.b*) + *(COMMON) } >MAIN_REGION + _end_bss = .; - /* Symbols needed by crt0.s. */ - PROVIDE(_end = .); - PROVIDE(_heap_size = -1); + _end = . ; + PROVIDE(end = .); - PROVIDE(_stack = .); - PROVIDE(_stack_size = ORIGIN(MAIN_REGION) + LENGTH(MAIN_REGION) - _stack); -} + .spad 0x70000000: { + *(.spad) + } >MAIN_REGION + + /* Symbols needed by crt0.c. */ + /* We set a fixed stack size and the pointer for the stack, letting the remaining memory be the heap. */ + PROVIDE(_stack_size = 32 * 1024); + PROVIDE(_stack = END_MAIN_REGION - _stack_size); + PROVIDE(_heap_size = -1); +} \ No newline at end of file From 86553abd0dd5390a8cd935d58f238cb9ba9f82b6 Mon Sep 17 00:00:00 2001 From: CosmicScale Date: Mon, 22 Jul 2024 22:22:28 +0100 Subject: [PATCH 4/4] Delete raw elf after packing --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 451917b..c9ddeb8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -EE_BIN = PS1VModeNeg.elf -EE_BIN_PACKED = PS1VModeNegPacked.elf +EE_BIN = PS1VModeNegRaw.elf +EE_BIN_PACKED = PS1VModeNeg.elf EE_OBJS = main.o cnf_lite.o EE_INCS := -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I. @@ -16,9 +16,10 @@ all: $(EE_BIN_PACKED) $(EE_BIN_PACKED): $(EE_BIN) echo "Compressing..." ps2-packer $< $@ + rm -f $(EE_BIN) clean: - rm -f $(EE_OBJS) $(EE_BIN) $(EE_BIN_PACKED) + rm -f $(EE_OBJS) $(EE_BIN_PACKED) include $(PS2SDK)/Defs.make include $(PS2SDK)/samples/Makefile.eeglobal \ No newline at end of file