Merge branch 'sup39:main' into main

This commit is contained in:
Matteias Collet 2022-11-26 18:35:01 +01:00 committed by GitHub
commit 6c197981f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 115 additions and 5 deletions

80
ReadFile-C2.s Normal file
View file

@ -0,0 +1,80 @@
.file "ReadFile.c"
.machine ppc
.section ".text"
.globl onReadOptionBlock
.type onReadOptionBlock, @function
onReadOptionBlock:
.LFB0:
stwu 1,-32(1)
#mflr 0
stmw 27,12(1)
lis 29,0x817f
ori 29,29,0xe800
lis 28,0xabcd
lwz 9,0(29)
ori 28,28,0x1234
#stw 0,36(1)
mr 30,3
cmpw 0,9,28
mr 31,4
beq- 0,.L3
lis 9,mount_@ha
li 4,1
la 9,mount_@l(9)
mtctr 9
bctrl
cmpwi 0,3,0
bne- 0,.L3
lis 9,CARDOpen@ha
la 9,CARDOpen@l(9)
lwz 3,0(30)
mr 5,31
bl .LC0
.string "gct"
.section ".text"
.align 2
.LC0: mflr 4
mtctr 9
bctrl
cmpwi 0,3,0
bne- 0,.L3
lis 27,0x817f
lis 9,CARDRead@ha
la 9,CARDRead@l(9)
ori 27,27,0xa800
li 6,0
li 5,16384
mr 4,27
mr 3,31
mtctr 9
bctrl
cmpwi 0,3,0
bne- 0,.L5
lwz 9,0(27)
xoris 10,9,0xff2f
cmpwi 0,10,-16162
bne 0,.L5
lis 10,0x817f
ori 10,10,0xa804
lwz 10,0(10)
cmpw 0,10,9
bne+ 0,.L5
stw 28,0(29)
.L5:
lis 9,CARDClose@ha
mr 3,31
la 9,CARDClose@l(9)
mtctr 9
bctrl
.L3:
lis 9,open_@ha
mr 4,31
la 9,open_@l(9)
mr 3,30
mtctr 9
bctrl
lmw 27,12(1)
addi 1,1,32
.LFE0:
.size onReadOptionBlock, .-onReadOptionBlock
.ident "GCC: (devkitPPC release 41) 12.1.0"

View file

@ -1,3 +1,5 @@
#include <stdint.h>
typedef struct {
char pad[20];
} CARDFileInfo;
@ -24,10 +26,16 @@ int CARDRead(CARDFileInfo *fileInfo, void *buf, unsigned long size, unsigned lon
int CARDClose(CARDFileInfo *fileInfo);
#define fileName "gct"
#define dst ((void*)0x817F0000)
#define size 0xE000 // 7 blocks
#define dst ((void*)0x817FA800)
#define size 0x4000 // 2 blocks
#define magicAddr (dst+size)
#define magic 0xabcd1234
int onReadOptionBlock(TCardManager *this, CARDFileInfo *fileInfo) {
int rc;
// if magic is correct -> already loaded -> do not load again
if (*(unsigned int*)(magicAddr) == magic) goto orig;
// mount
if ((rc = mount_(this, 1))) goto orig;
@ -44,7 +52,11 @@ int onReadOptionBlock(TCardManager *this, CARDFileInfo *fileInfo) {
} else {
// everything is good => apply gecko code
// TODO entry
((void(*)())0x817f4000)();
// ((void(*)())0x817f4000)();
if (*(uint32_t*)(dst) == 0x00d0c0de && *(uint32_t*)(dst+4) == 0x00d0c0de) {
// is gct
*(uint32_t*)(magicAddr) = magic; // set magic to enable gecko code
}
}
// close file

View file

@ -1,4 +1,4 @@
$$ = 0x817eff00;
$$ = 0;
/* TCardManager::cmdLoop() */
$bl$onReadOptionBlock = 0x801069f4;
$C2$onReadOptionBlock = 0x801069f4;

10
gecko-gosub.s Normal file
View file

@ -0,0 +1,10 @@
.set dst, 0x817fa800
## backup r15 (pointer to current gecko instruction) at dst-4
add r0, r15, r4
lis r3, dst-4@ha
stwu r0, dst-4@l(r3)
## update r15 = dst + 8(header) - r4(this C0 code size)
addi r15, r3, 4+8
sub r15, r15, r4
blr

8
gecko-return.s Normal file
View file

@ -0,0 +1,8 @@
.set dst, 0x817fa800
## restore r15 (pointer to current gecko instruction) from dst-4
lis r3, dst-4@ha
lwz r15, dst-4@l(r3)
## update r15 = restored r15 - r4(this C0 code size)
sub r15, r15, r4
blr