2 Copyright 2009-2010, jimmikaelkael <jimmikaelkael@wanadoo.fr>
3 Copyright 2009-2010, misfire <misfire@xploderfreax.de>
5 Licenced under Academic Free License version 3.0
6 Review OpenUsbLd README & LICENSE files for further details.
12 #include <iopcontrol.h>
18 #define GS_BGCOLOUR *((volatile unsigned long int*)0x120000E0)
20 #define ELF_MAGIC 0x464c457f
53 static char *g_argv
[MAX_G_ARGS
];
54 static char g_argbuf
[1024];
56 static void t_loadElf(void)
59 elf_header_t elf_header
;
60 elf_pheader_t elf_pheader
;
63 GS_BGCOLOUR
= 0x800080; // mid purple
69 for (i
= 0x00100000; i
< 0x02000000; i
+= 64) {
79 // clear scratchpad memory
80 memset((void*)0x70000000, 0, 16 * 1024);
83 GS_BGCOLOUR
= 0x008000; // mid green
88 fd
= open(g_argv
[0], O_RDONLY
);
90 goto error
; // can't open file, exiting...
94 if (read(fd
, &elf_header
, sizeof(elf_header
)) != sizeof(elf_header
)) {
96 goto error
; // can't read header, exiting...
100 if ((*(u32
*)elf_header
.ident
) != ELF_MAGIC
) {
102 goto error
; // not an ELF file, exiting...
105 // copy loadable program segments to RAM
106 for (i
= 0; i
< elf_header
.phnum
; i
++) {
107 lseek(fd
, elf_header
.phoff
+(i
*sizeof(elf_pheader
)), SEEK_SET
);
108 read(fd
, &elf_pheader
, sizeof(elf_pheader
));
110 if (elf_pheader
.type
!= ELF_PT_LOAD
)
113 lseek(fd
, elf_pheader
.offset
, SEEK_SET
);
114 read(fd
, elf_pheader
.vaddr
, elf_pheader
.filesz
);
116 if (elf_pheader
.memsz
> elf_pheader
.filesz
)
117 memset(elf_pheader
.vaddr
+ elf_pheader
.filesz
, 0,
118 elf_pheader
.memsz
- elf_pheader
.filesz
);
134 SifLoadModule("rom0:SIO2MAN", 0, NULL
);
135 SifLoadModule("rom0:MCMAN", 0, NULL
);
136 SifLoadModule("rom0:MCSERV", 0, NULL
);
149 GS_BGCOLOUR
= 0x000000; // black
152 // finally, run ELF...
153 ExecPS2((void*)elf_header
.entry
, NULL
, g_argc
, g_argv
);
155 GS_BGCOLOUR
= 0x808080; // gray screen: error
159 int main(int argc
, char **argv
)
165 GS_BGCOLOUR
= 0x000080; // mid blue
172 g_argc
= argc
> MAX_G_ARGS
? MAX_G_ARGS
: argc
;
174 memset(g_argbuf
, 0, sizeof(g_argbuf
));
178 for (i
= 0; i
< g_argc
; i
++) {
179 arglen
= strlen(argv
[i
]) + 1;
180 memcpy(p
, argv
[i
], arglen
);
188 ExecPS2(t_loadElf
, NULL
, 0, NULL
);
190 GS_BGCOLOUR
= 0xffffff; // white screen: error