Skip to content

Commit

Permalink
Code refactoring for new SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
parrado committed Aug 10, 2021
1 parent aa14612 commit 89b0450
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 234 deletions.
9 changes: 5 additions & 4 deletions elf-loader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
66 changes: 0 additions & 66 deletions elf-loader/Rules.make

This file was deleted.

22 changes: 12 additions & 10 deletions elf-loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@
#include <string.h>
#include <iopcontrol.h>


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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -154,7 +156,7 @@ static void patch_and_execute_osdsys(void *epc, void *gp)
// PS2Link (C) 2003 Tord Lindstrom ([email protected])
// (C) 2003 adresd ([email protected])
//--------------------------------------------------------------
static void wipeUserMem(void)
void wipeUserMem(void)
{
int i;
for (i = 0x100000; i < GetMemorySize(); i += 64)
Expand Down
6 changes: 3 additions & 3 deletions payload/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
86 changes: 25 additions & 61 deletions payload/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@
#include <kernel.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <libcdvd.h>
#include <iopcontrol.h>
#include <iopheap.h>
#include <kernel.h>
#include <libcdvd.h>
#include <libmc.h>
#include <libpwroff.h>
#include <loadfile.h>
#include <libpad.h>
#include <sbv_patches.h>
Expand All @@ -25,17 +17,15 @@
#include <fileXio_rpc.h>
#include <fcntl.h>
#include <sbv_patches.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/times.h>
#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
Expand Down Expand Up @@ -103,8 +93,6 @@ typedef struct
u32 align;
} elf_pheader_t;



u8 romver[16];
char romver_region_char[1];
char ROMVersionNumStr[5];
Expand All @@ -126,7 +114,7 @@ void ResetIOP()

void InitPS2()
{
int ret;

static const char PFS_args[] = "-n\0"
"24\0"
"-o\0"
Expand All @@ -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)
{
Expand All @@ -161,7 +148,7 @@ void InitPS2()

SifExitIopHeap();
SifLoadFileExit();

}

void LoadElf(char *filename, char *party)
Expand Down Expand Up @@ -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();

Expand All @@ -273,19 +259,16 @@ 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
{

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)
Expand All @@ -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;
}
Loading

0 comments on commit 89b0450

Please sign in to comment.