From 9245b8538d13e7ade43cf04b0338f25fbcfc94fa Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 21 Aug 2022 20:36:34 +0200 Subject: [PATCH] Fix pscdgen and psexe build --- lib/Makefile | 8 +- lib/pcsx-redux/default.ld | 1 + lib/pcsx-redux/ps-exe.ld | 198 ++++++++++++++++++ src/Library/src/start.c | 3 + src/Library/src/test.cpp | 3 - src/Tools/psxcdgen/src/xml_reader/mkpsxiso.rs | 4 +- 6 files changed, 211 insertions(+), 6 deletions(-) create mode 100644 lib/pcsx-redux/default.ld create mode 100644 lib/pcsx-redux/ps-exe.ld create mode 100644 src/Library/src/start.c delete mode 100644 src/Library/src/test.cpp diff --git a/lib/Makefile b/lib/Makefile index 88675838..6b2de056 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -19,6 +19,13 @@ PREFIX ?= mipsel-none-elf FORMAT ?= elf32-littlemips endif +LDSCRIPT ?= $(PSCX_REDUX_DIR)/ps-exe.ld +ifneq ($(strip $(OVERLAYSCRIPT)),) +LDSCRIPT := $(addprefix $(OVERLAYSCRIPT) , -T$(LDSCRIPT)) +else +LDSCRIPT := $(addprefix $(PSCX_REDUX_DIR)/default.ld , -T$(LDSCRIPT)) +endif + CC = $(PREFIX)-gcc-10 CXX = $(PREFIX)-g++-10 LD = $(CXX) @@ -77,7 +84,6 @@ $(TARGET).a: $(OBJS) @mkdir -p $(dir $@) $(AR) rcs $(TARGET).a $(OBJS) - $(TARGET).elf: $(OBJS) $(LD) -o $(TARGET).elf $(LDFLAGS_all) $(LDFLAGS) $(OBJS) $(LIBS_all) $(LIBS) diff --git a/lib/pcsx-redux/default.ld b/lib/pcsx-redux/default.ld new file mode 100644 index 00000000..031fbe69 --- /dev/null +++ b/lib/pcsx-redux/default.ld @@ -0,0 +1 @@ +__heap_base = __bss_end; \ No newline at end of file diff --git a/lib/pcsx-redux/ps-exe.ld b/lib/pcsx-redux/ps-exe.ld new file mode 100644 index 00000000..db24b82a --- /dev/null +++ b/lib/pcsx-redux/ps-exe.ld @@ -0,0 +1,198 @@ +/* + +MIT License + +Copyright (c) 2019 PCSX-Redux authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +OUTPUT_FORMAT("binary") + +EXTERN(_start) +ENTRY(_start) + +TLOAD_ADDR = DEFINED(TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000; + +MEMORY { + loader : ORIGIN = (TLOAD_ADDR - 0x800), LENGTH = 2048 + ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 + dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 +} + +__ram_top = ORIGIN(ram) + LENGTH(ram); +__sp = __ram_top - 0x100; + +__dcache = ORIGIN(dcache); +__dcache_top = ORIGIN(dcache) + LENGTH(dcache); + +__bss_len = (__bss_end - __bss_start); +__ftext_len = (__ftext_end - __ftext_start); +__fdata_len = (__fdata_end - __fdata_start); + +__stack_start = ORIGIN(ram) + LENGTH(ram); + +SECTIONS { + .PSX_EXE_Header : { + /* + 0x0000 - 0x0007 : "PS-X EXE" + */ + BYTE(80); BYTE(83); BYTE(45); BYTE(88); BYTE(32); BYTE(69); BYTE(88); BYTE(69); + + /* 0x0008 - 0x000F : skip text_off and data_off since they're not supported by the PS1 BIOS */ + LONG(0); LONG(0); + + /* 0x0010 - 0x0013 : entry point */ + LONG(ABSOLUTE(_start)); + + /* 0x0014 - 0x0017 : initial value of $gp */ + LONG(0); + + /* 0x0018 - 0x001B : Memory address to load "text" section to. */ + /* + NOTE: The "text" section is actually all of the "load" + sections of the file including .text, .rodata, .data. + etc. + */ + LONG(TLOAD_ADDR); + + /* 0x001C - 0x001F : size, in bytes, of the "text" section. */ + LONG(__ftext_len + __fdata_len); + + /* 0x0020 - 0x002F : + Skip "data_addr", "data_size", "bss_addr" and "bss_size". + None of these are supported by retail PS1 BIOS. + */ + LONG(0); LONG(0); + LONG(0); LONG(0); + + /* 0x0030 - 0x0033 : Initial stack address. */ + LONG(DEFINED(_sp) ? ABSOLUTE(_sp) : 0x801FFF00); + + /* 0x0034 - 0x0037 : Initial stack size, set it to 0. */ + LONG(0); + + /* Skip the remaining fields as they're not supported by the BIOS */ + /* e.g. 2048 header bytes minus whatever we've actually used */ + . = . + 1992; + } > loader + + __ftext_start = ABSOLUTE(.); + .text TLOAD_ADDR : { + *(.start) + *(.init) + KEEP (*(SORT_NONE(.fini))) + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + *(.text.exit .text.exit.*) + *(.text.startup .text.startup.*) + *(.text.hot .text.hot.*) + *(.text .stub .text.* .gnu.linkonce.t.*) + + . = ALIGN(16); + KEEP(*(.init)) + . = ALIGN(16); + KEEP(*(.fini)) + } > ram + + . = ALIGN(16); + __text_end = .; + __ftext_end = ABSOLUTE(.); + + __fdata_start = ABSOLUTE(.); + + .rodata : { + *(.rodata .rodata.* .rdata .rdata.* .gnu.linkonce.r.*) + . = ALIGN(16); + __preinit_array_start = .; + KEEP (*(.preinit_array)) + __preinit_array_end = .; + + . = ALIGN(16); + __init_array_start = .; + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + + . = ALIGN(16); + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*crtend.o(.ctors)) + __init_array_end = .; + + . = ALIGN(16); + __fini_array_start = .; + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*crtend.o(.dtors)) + __fini_array_end = .; + __build_id = .; + *(.note.gnu.build-id) + __build_id_end = .; + } > ram + + .rodata1 : { + *(.rodata1) + } > ram + + __data_start = .; + .data : { + *(.a0table) + *(.data .data.* .gnu.linkonce.d.*) + *(.data1) + *(.sdata .sdata.* .gnu.linkonce.s.*) + *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) + *(.got.plt) + *(.got) + /* pad file to be a multiple of 2048 bytes. Needed for loading from CD-ROM. */ + . = ALIGN(2048); + } > ram + + __data_end = .; + __fdata_end = .; + __bss_start = .; + .sbss (NOLOAD) : { + *(.dynsbss) + *(.sbss .sbss.* .gnu.linkonce.sb.*) + *(.scommon) + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + } > ram + + . = ALIGN(4); + __bss_end = .; + + __heap_start = __heap_base; + + . = ADDR(.text) - 0x800; + __end = .; + + /DISCARD/ : { *(.MIPS.abiflags) } + + /* Everything is statically linked, so discard PLTs. */ + /DISCARD/ : { *(.rel.iplt) *(.rela.iplt) *(.rel.plt) *(.rela.plt) *(.plt) *(.iplt) } + + /* Discard things that the standard link script drops, too. */ + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } +} diff --git a/src/Library/src/start.c b/src/Library/src/start.c new file mode 100644 index 00000000..e439c866 --- /dev/null +++ b/src/Library/src/start.c @@ -0,0 +1,3 @@ +void _start() { + //call main here +} \ No newline at end of file diff --git a/src/Library/src/test.cpp b/src/Library/src/test.cpp deleted file mode 100644 index 52125bc2..00000000 --- a/src/Library/src/test.cpp +++ /dev/null @@ -1,3 +0,0 @@ -int wuff() { - return 0; -} \ No newline at end of file diff --git a/src/Tools/psxcdgen/src/xml_reader/mkpsxiso.rs b/src/Tools/psxcdgen/src/xml_reader/mkpsxiso.rs index 35683d55..a19e2c27 100644 --- a/src/Tools/psxcdgen/src/xml_reader/mkpsxiso.rs +++ b/src/Tools/psxcdgen/src/xml_reader/mkpsxiso.rs @@ -260,7 +260,7 @@ fn handle_directory(dir: &mut DirectoryDataType, parser: &mut XMLReader) -> Resu if file.name == "SCES_003.90" { file.set_lba_padding(0); - file.is_hidden = true; + file.is_hidden = false; } dir.add_file(file); }, @@ -274,7 +274,7 @@ fn handle_directory(dir: &mut DirectoryDataType, parser: &mut XMLReader) -> Resu let mut new_dir = DirectoryDataType::new(XMLReader::get_attribute_value_str(&dir_name)?); if new_dir.name == "XB" { - new_dir.is_hidden = true; + new_dir.is_hidden = false; } handle_directory(&mut new_dir, parser)?; dir.add_dir(new_dir);