Skip to content

Commit

Permalink
now uses wLE loader, wLE settings can be saved
Browse files Browse the repository at this point in the history
  • Loading branch information
parrado committed Apr 15, 2021
1 parent 5ef37da commit b860b23
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 701 deletions.
87 changes: 65 additions & 22 deletions loader-old/loader.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# (c) 2020 Francisco Javier Trujillo Mata <[email protected]>
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
*/

//--------------------------------------------------------------
//File name: loader.c
//--------------------------------------------------------------
//dlanor: This subprogram has been modified to minimize the code
//dlanor: size of the resident loader portion. Some of the parts
//dlanor: that were moved into the main program include loading
//dlanor: of all IRXs and mounting pfs0: for ELFs on hdd.
//dlanor: Another change was to skip threading in favor of ExecPS2
/*==================================================================
== ==
== Copyright(c)2004 Adam Metcalf([email protected]) ==
== Copyright(c)2004 Thomas Hawcroft([email protected]) ==
== This file is subject to terms and conditions shown in the ==
== file LICENSE which should be kept in the top folder of ==
== this distribution. ==
== ==
== Portions of this code taken from PS2Link: ==
== pkoLoadElf ==
== wipeUserMemory ==
== (C) 2003 Tord Lindstrom ([email protected]) ==
== (C) 2003 adresd ([email protected]) ==
== Portions of this code taken from Independence MC exploit ==
== tLoadElf ==
== LoadAndRunHDDElf ==
== (C) 2003 Marcus Brown <[email protected]> ==
== ==
==================================================================*/
#include <kernel.h>
#include <loadfile.h>
#include <sifrpc.h>
#include <errno.h>
#include <string.h>
#include <iopcontrol.h>
//--------------------------------------------------------------

//--------------------------------------------------------------
//End of data declarations
//--------------------------------------------------------------
//Start of function code:
//--------------------------------------------------------------
Expand All @@ -25,10 +47,10 @@ static void wipeUserMem(void)
int i;
for (i = 0x100000; i < GetMemorySize(); i += 64) {
asm volatile(
"\tsq $0, 0(%0) \n"
"\tsq $0, 16(%0) \n"
"\tsq $0, 32(%0) \n"
"\tsq $0, 48(%0) \n" ::"r"(i));
"\tsq $0, 0(%0) \n"
"\tsq $0, 16(%0) \n"
"\tsq $0, 32(%0) \n"
"\tsq $0, 48(%0) \n" ::"r"(i));
}
}

Expand All @@ -40,32 +62,53 @@ static void wipeUserMem(void)
int main(int argc, char *argv[])
{
static t_ExecData elfdata;
char *target, *path;
char *args[1];
int ret;

if (argc < 1) { // arg1=path to ELF
return -EINVAL;
}

// Initialize
SifInitRpc(0);
wipeUserMem();

if (argc != 2) { // arg1=path to ELF, arg2=partition to mount
SifExitRpc();
return -EINVAL;
}

target = argv[0];
path = argv[1];

//Writeback data cache before loading ELF.
FlushCache(0);
ret = SifLoadElf(argv[0], &elfdata);
ret = SifLoadElf(target, &elfdata);
if (ret == 0) {
args[0] = path;

if (strncmp(path, "hdd", 3) == 0 && (path[3] >= '0' && path[3] <= ':')) { /* Final IOP reset, to fill the IOP with the default modules.
It appears that it was once a thing for the booting software to leave the IOP with the required IOP modules.
This can be seen in OSDSYS v1.0x (no IOP reboot) and the mechanism to boot DVD player updates (OSDSYS will get LoadExecPS2 to load SIO2 modules).
However, it changed with the introduction of the HDD unit, as the software booted may be built with a different SDK revision.
Reboot the IOP, to leave it in a clean & consistent state.
But do not do that for boot targets on other devices, for backward-compatibility with older (homebrew) software. */
while (!SifIopReset("", 0)) {
};
while (!SifIopSync()) {
};
}

SifExitRpc();

FlushCache(0);
FlushCache(2);

// Following the standard the first parameter of a argv is the executable itself
return ExecPS2((void *)elfdata.epc, (void *)elfdata.gp, argc, argv);
ExecPS2((void *)elfdata.epc, (void *)elfdata.gp, 1, args);
return 0;
} else {
SifExitRpc();
return -ENOENT;
}
}

//--------------------------------------------------------------
//End of func: int main(int argc, char *argv[])
//--------------------------------------------------------------
Expand Down
Binary file removed loader-old/loader.elf
Binary file not shown.
Binary file removed loader-old/loader.o
Binary file not shown.
1 change: 1 addition & 0 deletions payload/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ all:


clean:
$(MAKE) -C ../loader-old/ clean
rm -f *.elf *.ELF *.irx *.o *.s *.bin

DEV9_irx.c: $(PS2SDK)/iop/irx/ps2dev9.irx
Expand Down
Loading

0 comments on commit b860b23

Please sign in to comment.