Skip to content

Commit a900e64

Browse files
committed
Some improvements
1 parent f2853dd commit a900e64

12 files changed

Lines changed: 96 additions & 75 deletions

File tree

compile.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ mipsel-none-elf-gcc \
7676
-Os \
7777
-Wl,-z,max-page-size=0x1 \
7878
-o build/code.elf \
79+
src/code/*.S \
7980
src/code/*.c
8081

8182
mipsel-none-elf-objcopy \
@@ -87,6 +88,8 @@ mipsel-none-elf-objcopy \
8788
build/code.elf \
8889
build/code.bin
8990

91+
echo "actual code.bin size: $(wc -c < build/code.bin)"
92+
9093
mipsel-none-elf-gcc \
9194
-DV$dvd_ver \
9295
-Wl,--defsym=V$dvd_ver=1 \
@@ -102,8 +105,8 @@ mipsel-none-elf-gcc \
102105
-Os \
103106
-Wl,-z,max-page-size=0x1 \
104107
-o build/jump.elf \
105-
src/jump/jump.c \
106-
src/jump/ps2syscalls.c
108+
src/jump/*.S \
109+
src/jump/*.c
107110

108111
mipsel-none-elf-objcopy \
109112
-O binary \
@@ -114,6 +117,8 @@ mipsel-none-elf-objcopy \
114117
build/jump.elf \
115118
build/jump.bin
116119

120+
echo "actual jump.bin size: $(wc -c < build/jump.bin)"
121+
117122
gcc -DV$dvd_ver src/injector/*.c -o build/injector.elf
118123

119124
cp --recursive fs build/

fs/BOOT.ELF

108 KB
Binary file not shown.

src/code/code.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,15 @@ void main() {
121121
unsigned char *elf_data = (unsigned char *)0x100000;
122122
Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elf_data;
123123

124+
setup_pointers();
125+
124126
sceSifInitRpc(0);
125127
readBufferInternal("", 0, elf_rsect, elf_data, BOOT_FILE_SC, 0);
126128
sceSifExitRpc();
127129

130+
while (!sceSifResetIop("", 0));
131+
while(!sceSifSyncIop());
132+
128133
// Validate ELF header
129134
if (ehdr->e_phnum > 256 || ehdr->e_phnum == 0) {
130135
Exit(0); // Invalid program header count
@@ -139,7 +144,7 @@ void main() {
139144
if (phdr->p_memsz > 0x2000000 || phdr->p_filesz > phdr->p_memsz) {
140145
continue; // Skip invalid segments
141146
}
142-
memcpy((unsigned char *)(unsigned long)phdr->p_vaddr, elf_data + phdr->p_offset, phdr->p_filesz);
147+
memmove((unsigned char *)(unsigned long)phdr->p_vaddr, elf_data + phdr->p_offset, phdr->p_filesz);
143148
if(phdr->p_memsz > phdr->p_filesz) {
144149
memset((unsigned char *)(unsigned long)phdr->p_vaddr + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
145150
}
@@ -149,14 +154,7 @@ void main() {
149154
FlushCache(0);
150155
FlushCache(2);
151156

152-
while (!sceSifResetIop("", 0));
153-
while(!sceSifSyncIop());
154-
155157
ExecPS2((void *)(unsigned long)ehdr->e_entry, 0, 0, NULL);
156-
}
157158

158-
__attribute__((section(".text.boot")))
159-
void _start(void) {
160-
setup_pointers();
161-
main();
159+
Exit(0); // This should never occur
162160
}

src/code/crt0.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.set noreorder
2+
.section .text.boot
3+
4+
.global _start
5+
_start:
6+
lui $sp, 0x7000
7+
j main
8+
ori $sp, $sp, 0x4000

src/code/ps2syscalls.S

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.set noreorder
2+
.section .text
3+
4+
.macro syscall_map name, idn
5+
.global \name
6+
.type \name, @function
7+
\name:
8+
li $v1, \idn
9+
syscall
10+
jr $ra
11+
nop
12+
.endm
13+
14+
syscall_map ExecPS2, 0x07
15+
syscall_map FlushCache, 0x64
16+
syscall_map DeleteThread, 0x21
17+
syscall_map TerminateThread, 0x25
18+
syscall_map ChangeThreadPriority, 0x29
19+
syscall_map GetThreadId, 0x2f
20+
syscall_map CancelWakeupThread, 0x35
21+
syscall_map Exit, 0x04
22+
syscall_map sceSifStopDma, 0x6b
23+
syscall_map sceSifGetReg, 0x7a
24+
syscall_map sceSifSetReg, 0x79
25+
syscall_map sceSifSetDma, 0x77

src/code/ps2syscalls.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/code/ps2syscalls.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ typedef struct {
88
unsigned int mode;
99
} sceSifDmaData;
1010

11-
void ExecPS2(void *entry, void *gp, int argc, char **argv);
12-
void FlushCache(int mode);
13-
void DeleteThread(int thread_id);
14-
void TerminateThread(int thread_id);
15-
void ChangeThreadPriority(int thread_id, int priority);
16-
int GetThreadId(void);
17-
int CancelWakeupThread(int thread_id);
18-
int Exit(int status);
19-
void sceSifStopDma(void);
20-
int sceSifGetReg(unsigned int register_num);
21-
int sceSifSetReg(unsigned int register_num, int register_value);
22-
unsigned int sceSifSetDma(sceSifDmaData *sdd, int len);
11+
extern void ExecPS2(void *entry, void *gp, int argc, char **argv);
12+
extern void FlushCache(int mode);
13+
extern void DeleteThread(int thread_id);
14+
extern void TerminateThread(int thread_id);
15+
extern void ChangeThreadPriority(int thread_id, int priority);
16+
extern int GetThreadId(void);
17+
extern int CancelWakeupThread(int thread_id);
18+
extern int Exit(int status);
19+
extern void sceSifStopDma(void);
20+
extern int sceSifGetReg(unsigned int register_num);
21+
extern int sceSifSetReg(unsigned int register_num, int register_value);
22+
extern unsigned int sceSifSetDma(sceSifDmaData *sdd, int len);
2323

2424
#endif

src/jump/crt0.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.set noreorder
2+
.section .text.boot
3+
4+
.global _start
5+
_start:
6+
lui $sp, 0x7000
7+
j main
8+
ori $sp, $sp, 0x4000

src/jump/jump.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,11 @@ static void killAllThreads(void) {
4848
}
4949
}
5050

51-
__attribute__((section(".text.boot")))
52-
void _start(void) {
53-
asm ("la $sp, 0x70004000");
51+
void main(void) {
5452
killAllThreads();
5553
readBufferInternal("", 0, 4, code, 2, 0);
5654
FlushCache(0);
5755
FlushCache(2);
5856
code();
59-
for (;;);
57+
Exit(0);
6058
}

src/jump/ps2syscalls.S

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.set noreorder
2+
.section .text
3+
4+
.macro syscall_map name, idn
5+
.global \name
6+
.type \name, @function
7+
\name:
8+
li $v1, \idn
9+
syscall
10+
jr $ra
11+
nop
12+
.endm
13+
14+
syscall_map FlushCache, 0x64
15+
syscall_map DeleteThread, 0x21
16+
syscall_map TerminateThread, 0x25
17+
syscall_map ChangeThreadPriority, 0x29
18+
syscall_map GetThreadId, 0x2f
19+
syscall_map CancelWakeupThread, 0x35
20+
syscall_map Exit, 0x04

0 commit comments

Comments
 (0)