diff --git a/elf-loader/Makefile b/elf-loader/Makefile index 08b4346..0a8b4f8 100644 --- a/elf-loader/Makefile +++ b/elf-loader/Makefile @@ -9,8 +9,8 @@ ### Adjust these three, for PS2Link compatibility tests ### Old LaunchELF used LA=0x90000, SA=0xB0000, SS=0x08000 LOADADDR = 0x90000 -STACKADDR = 0xA8000 #0xB0000 -STACKSIZE = 0x04000 #0x08000 +STACKADDR = 0xA8000 +STACKSIZE = 0x04000 ifeq ($(DEBUG),1) LOADADDR = 0x1700000 @@ -36,5 +36,6 @@ all: $(EE_BIN) clean: rm -f -r $(EE_OBJS) $(EE_BIN) -include $(PS2SDKSRC)/Defs.make -include Rules.make +# Include makefiles +include $(PS2SDK)/samples/Makefile.pref +include $(PS2SDK)/samples/Makefile.eeglobal diff --git a/elf-loader/Rules.make b/elf-loader/Rules.make deleted file mode 100644 index 48e1ffe..0000000 --- a/elf-loader/Rules.make +++ /dev/null @@ -1,66 +0,0 @@ -# _____ ___ ____ ___ ____ -# ____| | ____| | | |____| -# | ___| |____ ___| ____| | \ 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. - -EE_CC_VERSION := $(shell $(EE_CC) -dumpversion) - -EE_SRC_DIR ?= src/ -EE_INC_DIR ?= include/ - -# Include directories -EE_INCS := $(EE_INCS) -I$(EE_SRC_DIR) -I$(EE_SRC_DIR)include -I$(EE_INC_DIR) -I$(PS2SDKSRC)/ee/kernel/include -I$(PS2SDKSRC)/common/include -I$(PS2SDKSRC)/ee/libc/include -I$(PS2SDKSRC)/ee/erl/include - -# C compiler flags -EE_CFLAGS := -D_EE -O2 -G0 -Wall $(EE_CFLAGS) - -# C++ compiler flags -EE_CXXFLAGS := -D_EE -O2 -G0 -Wall $(EE_CXXFLAGS) - -# Linker flags -EE_LDFLAGS := -L$(PS2SDK)/ee/lib -L$(PS2DEV)/ee/ee/lib $(EE_LDFLAGS) -lc -lkernel - -# Assembler flags -EE_ASFLAGS := -G0 $(EE_ASFLAGS) - -# Externally defined variables: EE_BIN, EE_OBJS, EE_LIB - -# _____ ___ ____ ___ ____ -# ____| | ____| | | |____| -# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. -#----------------------------------------------------------------------- -# (c) 2020 Francisco Javier Trujillo Mata -# Licenced under Academic Free License version 2.0 -# Review ps2sdk README & LICENSE files for further details. - -# These macros can be used to simplify certain build rules. -EE_C_COMPILE = $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -EE_CXX_COMPILE = $(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS) - -%.o: %.c - $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ - -%.o: %.cc - $(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS) -c $< -o $@ - -%.o: %.cpp - $(EE_CXX) $(EE_CXXFLAGS) $(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) -o $(EE_BIN) $(EE_OBJS) $(EE_LDFLAGS) $(EE_LIBS) - -$(EE_ERL): $(EE_OBJS) - $(EE_CC) -o $(EE_ERL) $(EE_OBJS) $(EE_CFLAGS) $(EE_LDFLAGS) -Wl,-r -Wl,-d - $(EE_STRIP) --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment $(EE_ERL) - -$(EE_LIB): $(EE_OBJS) - $(EE_AR) cru $(EE_LIB) $(EE_OBJS) diff --git a/elf-loader/loader.c b/elf-loader/loader.c index 71e5f63..309dc41 100644 --- a/elf-loader/loader.c +++ b/elf-loader/loader.c @@ -32,15 +32,18 @@ #include #include + + void _ps2sdk_libc_init() {} + void _ps2sdk_libc_deinit() {} //Code for OSDSYS patching was taken from FMCB 1.8 sources -static u32 execps2_code[] = { + u32 execps2_code[] = { 0x24030007, // li v1, 7 0x0000000c, // syscall 0x03e00008, // jr ra 0x00000000 // nop }; -static u32 execps2_mask[] = { + u32 execps2_mask[] = { 0xffffffff, 0xffffffff, 0xffffffff, @@ -49,7 +52,7 @@ static u32 execps2_mask[] = { //========================================================================= // SkipHdd patch for v3, v4 (those not supporting "SkipHdd" arg) -static u32 pattern10[] = { + u32 pattern10[] = { // Code near MC Update & HDD load 0x0c000000, // jal CheckMcUpdate 0x0220282d, // daddu a1, s1, zero @@ -60,7 +63,7 @@ static u32 pattern10[] = { 0x0000302d, // daduu a2, zero, zero #arg2: 0 0x04400000 // bltz v0, Exit_HddLoad }; -static u32 pattern10_mask[] = { + u32 pattern10_mask[] = { 0xfc000000, 0xffffffff, 0xffffffff, @@ -71,7 +74,7 @@ static u32 pattern10_mask[] = { 0xffff0000}; //-------------------------------------------------------------- -static u8 *find_bytes_with_mask(u8 *buf, u32 bufsize, u8 *bytes, u8 *mask, u32 len) + u8 *find_bytes_with_mask(u8 *buf, u32 bufsize, u8 *bytes, u8 *mask, u32 len) { u32 i, j; @@ -88,7 +91,7 @@ static u8 *find_bytes_with_mask(u8 *buf, u32 bufsize, u8 *bytes, u8 *mask, u32 l return NULL; } //-------------------------------------------------------------- -static u8 *find_string(const u8 *string, u8 *buf, u32 bufsize) + u8 *find_string(const u8 *string, u8 *buf, u32 bufsize) { u32 i; const u8 *s, *p; @@ -103,8 +106,7 @@ static u8 *find_string(const u8 *string, u8 *buf, u32 bufsize) } return NULL; } - -static void patch_skip_hdd(u8 *osd) + void patch_skip_hdd(u8 *osd) { u8 *ptr; u32 addr; @@ -119,7 +121,7 @@ static void patch_skip_hdd(u8 *osd) _sw(0x10000000 + ((signed short)(_lw(addr + 28) & 0xffff) + 5), addr + 8); } -static void patch_and_execute_osdsys(void *epc, void *gp) + void patch_and_execute_osdsys(void *epc, void *gp) { int n = 0; @@ -154,7 +156,7 @@ static void patch_and_execute_osdsys(void *epc, void *gp) // PS2Link (C) 2003 Tord Lindstrom (pukko@home.se) // (C) 2003 adresd (adresd_ps2dev@yahoo.com) //-------------------------------------------------------------- -static void wipeUserMem(void) +void wipeUserMem(void) { int i; for (i = 0x100000; i < GetMemorySize(); i += 64) diff --git a/payload/Makefile b/payload/Makefile index dcca72f..7454c06 100755 --- a/payload/Makefile +++ b/payload/Makefile @@ -5,13 +5,13 @@ EE_BIN_RAW = $(EE_TARGET).bin EE_BIN_STRIPPED = $(EE_TARGET)-stripped.elf EE_BIN_RAW = $(EE_TARGET).bin -EE_OBJS = main.o pad.o timer.o elf_loader_elf.o $(EE_IOP_OBJS) +EE_OBJS = main.o pad.o elf_loader_elf.o $(EE_IOP_OBJS) EE_IOP_OBJS = IOMANX_irx.o FILEXIO_irx.o SIO2MAN_irx.o PADMAN_irx.o DEV9_irx.o ATAD_irx.o HDD_irx.o PFS_irx.o EE_LDFLAGS = -L $(PS2SDK)/ee/lib -Wl,--gc-sections -Wl,-Ttext -Wl,$(LOADADDR) -EE_LIBS = -lelf-loader -lkernel -lpatches -lfileXio -lpadx -EE_INCS= -I$(GSKIT)/include -I$(PS2SDK)/ports/include +EE_LIBS = -lpatches -lfileXio -lpadx +EE_INCS= -I$(GSKIT)/include -I$(PS2SDK)/ports/include EE_CFLAGS=-G0 -I $(PS2SDK)/ee/include -I $(PS2SDK)/common/include -D_EE -Os -Wall -ffunction-sections -fdata-sections -DNEWLIB_PORT_AWARE diff --git a/payload/main.c b/payload/main.c index 475f2d9..7504938 100755 --- a/payload/main.c +++ b/payload/main.c @@ -4,17 +4,9 @@ #include #include #include -#include #include -#include -#include -#include #include #include -#include -#include -#include -#include #include #include #include @@ -25,17 +17,15 @@ #include #include #include -#include #include #include -#include +#include +#include "pad.h" #define NTSC 2 #define PAL 3 -#define DELAY 100 - -#define SYSTEM_INIT_THREAD_STACK_SIZE 0x1000 +#define DELAY 100L // ELF-loading stuff #define ELF_MAGIC 0x464c457f @@ -103,8 +93,6 @@ typedef struct u32 align; } elf_pheader_t; - - u8 romver[16]; char romver_region_char[1]; char ROMVersionNumStr[5]; @@ -126,7 +114,7 @@ void ResetIOP() void InitPS2() { - int ret; + static const char PFS_args[] = "-n\0" "24\0" "-o\0" @@ -144,14 +132,13 @@ void InitPS2() SifExecModuleBuffer(FILEXIO_irx, size_FILEXIO_irx, 0, NULL, NULL); fileXioInit(); - //sceCdInit(SCECdINoD); - - ret = SifExecModuleBuffer(DEV9_irx, size_DEV9_irx, 0, NULL, &stat); + + SifExecModuleBuffer(DEV9_irx, size_DEV9_irx, 0, NULL, &stat); SifExecModuleBuffer(SIO2MAN_irx, size_SIO2MAN_irx, 0, NULL, NULL); - SifExecModuleBuffer(PADMAN_irx, size_PADMAN_irx, 0, NULL, NULL); PadInitPads(); + if (SifExecModuleBuffer(ATAD_irx, size_ATAD_irx, 0, NULL, NULL) >= 0) { @@ -161,7 +148,7 @@ void InitPS2() SifExitIopHeap(); SifLoadFileExit(); - + } void LoadElf(char *filename, char *party) @@ -245,11 +232,10 @@ int main(int argc, char *argv[]) int lastKey = 0; int keyStatus; int isEarlyJap = 0; - u64 tstart; + struct tms tstart,tstop; char *party = "hdd0:__sysconf"; - - char *args[1]; + InitPS2(); @@ -273,9 +259,7 @@ int main(int argc, char *argv[]) if (fileXioMount("pfs0:", party, FIO_MT_RDONLY) == 0) { - TimerInit(); - tstart = Timer(); - + times(&tstart); //Stores last key during DELAY msec do { @@ -283,9 +267,8 @@ int main(int argc, char *argv[]) keyStatus = ReadCombinedPadStatus(); if (keyStatus) lastKey = keyStatus; - - } while (Timer() <= (tstart + DELAY)); - TimerEnd(); + times(&tstop); + } while (tstop.tms_utime <= (tstart.tms_utime + DELAY)); //Deinits pad if (!isEarlyJap) @@ -299,46 +282,27 @@ int main(int argc, char *argv[]) { fileXioUmount("pfs0:"); - //LoadElf("rom0:OSDSYS", "hdd0:"); - args[0]="hdd0:"; - LoadELFFromFile("rom0:OSDSYS",1,args); + LoadElf("rom0:OSDSYS", "hdd0:"); } if (lastKey & PAD_CIRCLE) { - if (file_exists("pfs0:/softdev2/ULE.ELF")){ - //LoadElf("pfs0:/softdev2/ULE.ELF", party); - args[0]=party; - LoadELFFromFile("pfs0:/softdev2/ULE.ELF",1,args); - - } - - if (file_exists("pfs0:/softdev2/OPNPS2LD.ELF")){ - //LoadElf("pfs0:/softdev2/OPNPS2LD.ELF", party); - args[0]=party; - LoadELFFromFile("pfs0:/softdev2/OPNPS2LD.ELF",1,args); - - } + if (file_exists("pfs0:/softdev2/ULE.ELF")) + LoadElf("pfs0:/softdev2/ULE.ELF", party); + + if (file_exists("pfs0:/softdev2/OPNPS2LD.ELF")) + LoadElf("pfs0:/softdev2/OPNPS2LD.ELF", party); } - if (file_exists("pfs0:/softdev2/OPNPS2LD.ELF")){ - //LoadElf("pfs0:/softdev2/OPNPS2LD.ELF", party); - args[0]=party; - LoadELFFromFile("pfs0:/softdev2/OPNPS2LD.ELF",1,args); - } - - - if (file_exists("pfs0:/softdev2/ULE.ELF")){ - //LoadElf("pfs0:/softdev2/ULE.ELF", party); - args[0]=party; - LoadELFFromFile("pfs0:/softdev2/ULE.ELF",1,args); - } + if (file_exists("pfs0:/softdev2/OPNPS2LD.ELF")) + LoadElf("pfs0:/softdev2/OPNPS2LD.ELF", party); + + if (file_exists("pfs0:/softdev2/ULE.ELF")) + LoadElf("pfs0:/softdev2/ULE.ELF", party); } - //LoadElf("rom0:OSDSYS", "hdd0:"); - args[0]="hdd0:"; - LoadELFFromFile("rom0:OSDSYS",1,args); + LoadElf("rom0:OSDSYS", "hdd0:"); return 0; } diff --git a/payload/timer.c b/payload/timer.c deleted file mode 100755 index 3ae8a16..0000000 --- a/payload/timer.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - _____ ___ ____ - ____| | ____| PS2 Open Source Project - | ___| |____ - ---------------------------------------------------------------------------- - - Copyright (C) 2008 - Neme & jimmikaelkael (www.psx-scene.com) - - This program is free software; you can redistribute it and/or modify - it under the terms of the Free McBoot License. - - This program and any related documentation is provided "as is" - WITHOUT ANY WARRANTIES, either express or implied, including, but not - limited to, implied warranties of fitness for a particular purpose. The - entire risk arising out of use or performance of the software remains - with you. - In no event shall the author be liable for any damages whatsoever - (including, without limitation, damages to your hardware or equipment, - environmental damage, loss of health, or any kind of pecuniary loss) - arising out of the use of or inability to use this software or - documentation, even if the author has been advised of the possibility of - such damages. - - You should have received a copy of the Free McBoot License along with - this program; if not, please report at psx-scene : - http://psx-scene.com/forums/freevast/ - ---------------------------------------------------------------------------- - - The following Code is from uLaunchELF - ---------------------------------------------------------------------------- - -*/ - -#include -#include - -void TimerInit(void); -u64 Timer(void); -void TimerEnd(void); - -//________________ From uLaunchELF ______________________ -// Timer Define -#define T0_COUNT ((volatile unsigned long*)0x10000000) -#define T0_MODE ((volatile unsigned long*)0x10000010) - -static int TimerInterruptID = -1; -static u64 TimerInterruptCount = 0; - -//-------------------------------------------------------------- -// Timer Interrupt -int TimerInterrupt(int a) -{ - TimerInterruptCount++; - *T0_MODE |= (1 << 11); - return -1; -} -//-------------------------------------------------------------- -// Timer Init -void TimerInit(void) -{ - *T0_MODE = 0x0000; - TimerInterruptID = AddIntcHandler(9, TimerInterrupt, 0); - EnableIntc(9); - *T0_COUNT = 0; - *T0_MODE = ( 2 << 0 )+( 1 << 7 )+( 1 << 9 ); - TimerInterruptCount = 0; -} -//-------------------------------------------------------------- -// Timer Count -u64 Timer(void) -{ - u64 ticks = (*T0_COUNT + (TimerInterruptCount << 16)) * (1000.0F / ( 147456000.0F / 256.0F )); - return ticks; -} -//-------------------------------------------------------------- -// Timer End -void TimerEnd(void) -{ - *T0_MODE = 0x0000; - if (TimerInterruptID >= 0){ - DisableIntc(9); - RemoveIntcHandler(9, TimerInterruptID); - TimerInterruptID = -1; - } - TimerInterruptCount = 0; -} -//--------------------------------------------------------------