ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
loader.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # (c) 2020 Francisco Javier Trujillo Mata <fjtrujy@gmail.com>
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
11 #include <kernel.h>
12 #include <loadfile.h>
13 #include <sifrpc.h>
14 #include <errno.h>
15 
16 //--------------------------------------------------------------
17 //Start of function code:
18 //--------------------------------------------------------------
19 // Clear user memory
20 // PS2Link (C) 2003 Tord Lindstrom (pukko@home.se)
21 // (C) 2003 adresd (adresd_ps2dev@yahoo.com)
22 //--------------------------------------------------------------
23 static void wipeUserMem(void)
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 }
34 
35 //--------------------------------------------------------------
36 //End of func: void wipeUserMem(void)
37 //--------------------------------------------------------------
38 // *** MAIN ***
39 //--------------------------------------------------------------
40 int main(int argc, char *argv[])
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 }
68 
69 //--------------------------------------------------------------
70 //End of func: int main(int argc, char *argv[])
71 //--------------------------------------------------------------
72 //End of file: loader.c
73 //--------------------------------------------------------------
#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[])
s32 GetMemorySize(void)
int main(int argc, char *argv[])
Definition: loader.c:40
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