ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
loader.c File Reference
#include <kernel.h>
#include <loadfile.h>
#include <sifrpc.h>
#include <errno.h>
+ Include dependency graph for loader.c:

Go to the source code of this file.

Functions

static void wipeUserMem (void)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 40 of file loader.c.

41 {
42  static t_ExecData elfdata;
43  int ret;
44 
45  if (argc < 1) { // arg1=path to ELF
46  return -EINVAL;
47  }
48 
49  // Initialize
50  SifInitRpc(0);
51  wipeUserMem();
52 
53  //Writeback data cache before loading ELF.
54  FlushCache(0);
55  ret = SifLoadElf(argv[0], &elfdata);
56  if (ret == 0) {
57  SifExitRpc();
58  FlushCache(0);
59  FlushCache(2);
60 
61  // Following the standard the first parameter of a argv is the executable itself
62  return ExecPS2((void *)elfdata.epc, (void *)elfdata.gp, argc, argv);
63  } else {
64  SifExitRpc();
65  return -ENOENT;
66  }
67 }
#define ENOENT
Definition: errno.h:22
#define EINVAL
Definition: errno.h:62
int SifLoadElf(const char *path, t_ExecData *data)
void FlushCache(s32 operation)
s32 ExecPS2(void *entry, void *gp, int num_args, char *args[])
static void wipeUserMem(void)
Definition: loader.c:23
void SifInitRpc(int mode)
void SifExitRpc(void)
u32 epc
Definition: loadfile.h:51
u32 gp
Definition: loadfile.h:52

References EINVAL, ENOENT, t_ExecData::epc, ExecPS2(), FlushCache(), t_ExecData::gp, SifExitRpc(), SifInitRpc(), SifLoadElf(), and wipeUserMem().

◆ wipeUserMem()

static void wipeUserMem ( void  )
static

Definition at line 23 of file loader.c.

24 {
25  int i;
26  for (i = 0x100000; i < GetMemorySize(); i += 64) {
27  asm volatile(
28  "\tsq $0, 0(%0) \n"
29  "\tsq $0, 16(%0) \n"
30  "\tsq $0, 32(%0) \n"
31  "\tsq $0, 48(%0) \n" ::"r"(i));
32  }
33 }
s32 GetMemorySize(void)

References GetMemorySize().

Referenced by main().