Link the rest of CARD

This commit is contained in:
Phillip Stephens 2022-10-20 23:32:50 -07:00
parent 4fa9495dd1
commit f7964a3908
5 changed files with 595 additions and 5 deletions

View File

@ -991,12 +991,12 @@ LIBS = [
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
["Dolphin/card/CARDBios", False], ["Dolphin/card/CARDBios", True],
["Dolphin/card/CARDUnlock", True], ["Dolphin/card/CARDUnlock", True],
["Dolphin/card/CARDRdwr", True], ["Dolphin/card/CARDRdwr", True],
["Dolphin/card/CARDBlock", True], ["Dolphin/card/CARDBlock", True],
["Dolphin/card/CARDDir", True], ["Dolphin/card/CARDDir", True],
["Dolphin/card/CARDCheck", False], ["Dolphin/card/CARDCheck", True],
["Dolphin/card/CARDMount", True], ["Dolphin/card/CARDMount", True],
["Dolphin/card/CARDFormat", True], ["Dolphin/card/CARDFormat", True],
["Dolphin/card/CARDOpen", True], ["Dolphin/card/CARDOpen", True],

View File

@ -822,12 +822,12 @@ DTK_FILES :=\
$(BUILD_DIR)/src/Dolphin/dtk.o $(BUILD_DIR)/src/Dolphin/dtk.o
CARD_FILES :=\ CARD_FILES :=\
$(BUILD_DIR)/asm/Dolphin/card/CARDBios.o\ $(BUILD_DIR)/src/Dolphin/card/CARDBios.ep.o\
$(BUILD_DIR)/src/Dolphin/card/CARDUnlock.ep.o\ $(BUILD_DIR)/src/Dolphin/card/CARDUnlock.ep.o\
$(BUILD_DIR)/src/Dolphin/card/CARDRdwr.ep.o\ $(BUILD_DIR)/src/Dolphin/card/CARDRdwr.ep.o\
$(BUILD_DIR)/src/Dolphin/card/CARDBlock.ep.o\ $(BUILD_DIR)/src/Dolphin/card/CARDBlock.ep.o\
$(BUILD_DIR)/src/Dolphin/card/CARDDir.ep.o\ $(BUILD_DIR)/src/Dolphin/card/CARDDir.ep.o\
$(BUILD_DIR)/asm/Dolphin/card/CARDCheck.o\ $(BUILD_DIR)/src/Dolphin/card/CARDCheck.ep.o\
$(BUILD_DIR)/src/Dolphin/card/CARDMount.ep.o\ $(BUILD_DIR)/src/Dolphin/card/CARDMount.ep.o\
$(BUILD_DIR)/src/Dolphin/card/CARDFormat.ep.o\ $(BUILD_DIR)/src/Dolphin/card/CARDFormat.ep.o\
$(BUILD_DIR)/src/Dolphin/card/CARDOpen.ep.o\ $(BUILD_DIR)/src/Dolphin/card/CARDOpen.ep.o\

View File

@ -59,6 +59,7 @@ s32 __GBASync(s32 chan) {
} }
#else #else
extern void OSSleepThread(); extern void OSSleepThread();
/* clang-format off */
#pragma push #pragma push
#pragma optimization_level 0 #pragma optimization_level 0
#pragma optimizewithasm off #pragma optimizewithasm off
@ -94,6 +95,7 @@ lbl_803CAD50:
mtlr r0 mtlr r0
blr blr
} }
/* clang-format on */
#pragma pop #pragma pop
#endif #endif

View File

@ -397,6 +397,7 @@ s32 __CARDWritePage(s32 chan, CARDCallback callback) {
return result; return result;
} }
#if NONMATCHING
/* TODO: Needs frank fix for disconnected stack epilogue */ /* TODO: Needs frank fix for disconnected stack epilogue */
s32 __CARDEraseSector(s32 chan, u32 addr, CARDCallback callback) { s32 __CARDEraseSector(s32 chan, u32 addr, CARDCallback callback) {
CARDControl* card; CARDControl* card;
@ -427,7 +428,77 @@ s32 __CARDEraseSector(s32 chan, u32 addr, CARDCallback callback) {
} }
return result; return result;
} }
#else
/* clang-format off */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 __CARDEraseSector(s32 chan, u32 addr, CARDCallback callback) {
nofralloc
mflr r0
stw r0, 4(r1)
stwu r1, -0x28(r1)
stw r31, 0x24(r1)
stw r30, 0x20(r1)
stw r29, 0x1c(r1)
addi r29, r3, 0
mulli r6, r29, 0x110
lis r3, __CARDBlock@ha
addi r0, r3, __CARDBlock@l
add r31, r0, r6
li r0, 0xf1
stb r0, 0x94(r31)
rlwinm r3, r4, 0xf, 0x19, 0x1f
rlwinm r0, r4, 0x17, 0x18, 0x1f
stb r3, 0x95(r31)
li r6, 3
addi r3, r29, 0
stb r0, 0x96(r31)
li r0, -1
li r4, 0
stw r6, 0xa0(r31)
stw r0, 0xa4(r31)
stw r6, 0xa8(r31)
bl __CARDStart
addi r30, r3, 0
cmpwi r30, -1
bne lbl_803B8C4C
li r30, 0
b lbl_803B8C94
lbl_803B8C4C:
cmpwi r30, 0
blt lbl_803B8C94
lwz r5, 0xa0(r31)
addi r3, r29, 0
addi r4, r31, 0x94
li r6, 1
bl EXIImmEx
cmpwi r3, 0
bne lbl_803B8C80
li r0, 0
stw r0, 0xcc(r31)
li r30, -3
b lbl_803B8C84
lbl_803B8C80:
li r30, 0
lbl_803B8C84:
mr r3, r29
bl EXIDeselect
mr r3, r29
bl EXIUnlock
lbl_803B8C94:
mr r3, r30
lwz r0, 0x2c(r1)
lwz r31, 0x24(r1)
lwz r30, 0x20(r1)
lwz r29, 0x1c(r1)
addi r1, r1, 0x28
mtlr r0
blr
}
/* clang-format on */
#pragma pop
#endif
void CARDInit(void) { void CARDInit(void) {
int chan; int chan;
@ -486,6 +557,7 @@ s32 __CARDGetControlBlock(s32 chan, CARDControl** pcard) {
return result; return result;
} }
#if NONMATCHING
/* TODO: Needs frank fix for disconnected stack epilogue */ /* TODO: Needs frank fix for disconnected stack epilogue */
s32 __CARDPutControlBlock(CARDControl* card, s32 result) { s32 __CARDPutControlBlock(CARDControl* card, s32 result) {
BOOL enabled; BOOL enabled;
@ -499,6 +571,44 @@ s32 __CARDPutControlBlock(CARDControl* card, s32 result) {
OSRestoreInterrupts(enabled); OSRestoreInterrupts(enabled);
return result; return result;
} }
#else
#pragma push
/* clang-format off */
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 __CARDPutControlBlock(CARDControl* card, s32 result) {
nofralloc
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
addi r31, r4, 0
stw r30, 0x10(r1)
addi r30, r3, 0
bl OSDisableInterrupts
lwz r0, 0(r30)
cmpwi r0, 0
beq lbl_803B8E8C
stw r31, 4(r30)
b lbl_803B8E9C
lbl_803B8E8C:
lwz r0, 4(r30)
cmpwi r0, -1
bne lbl_803B8E9C
stw r31, 4(r30)
lbl_803B8E9C:
bl OSRestoreInterrupts
mr r3, r31
lwz r0, 0x1c(r1)
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
mtlr r0
blr
}
/* clang-format on */
#pragma pop
#endif
s32 CARDGetResultCode(s32 chan) { s32 CARDGetResultCode(s32 chan) {
CARDControl* card; CARDControl* card;
@ -509,6 +619,7 @@ s32 CARDGetResultCode(s32 chan) {
return card->result; return card->result;
} }
#if NONMATCHING
s32 CARDFreeBlocks(s32 chan, s32* byteNotUsed, s32* filesNotUsed) { s32 CARDFreeBlocks(s32 chan, s32* byteNotUsed, s32* filesNotUsed) {
CARDControl* card; CARDControl* card;
s32 result; s32 result;
@ -544,6 +655,114 @@ s32 CARDFreeBlocks(s32 chan, s32* byteNotUsed, s32* filesNotUsed) {
return __CARDPutControlBlock(card, CARD_RESULT_READY); return __CARDPutControlBlock(card, CARD_RESULT_READY);
} }
#else
/* clang-format off */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 CARDFreeBlocks(s32 chan, s32* byteNotUsed, s32* filesNotUsed) {
nofralloc
mflr r0
stw r0, 4(r1)
stwu r1, -0x30(r1)
stw r31, 0x2c(r1)
addi r31, r5, 0
stw r30, 0x28(r1)
stw r29, 0x24(r1)
addi r29, r4, 0
addi r4, r1, 0x18
bl __CARDGetControlBlock
cmpwi r3, 0
bge lbl_803B8F20
b lbl_803B9020
lbl_803B8F20:
lwz r3, 0x18(r1)
bl __CARDGetFatBlock
mr r30, r3
lwz r3, 0x18(r1)
bl __CARDGetDirBlock
cmplwi r30, 0
beq lbl_803B8F44
cmplwi r3, 0
bne lbl_803B8F84
lbl_803B8F44:
lwz r30, 0x18(r1)
bl OSDisableInterrupts
lwz r0, 0(r30)
cmpwi r0, 0
beq lbl_803B8F64
li r0, -6
stw r0, 4(r30)
b lbl_803B8F78
lbl_803B8F64:
lwz r0, 4(r30)
cmpwi r0, -1
bne lbl_803B8F78
li r0, -6
stw r0, 4(r30)
lbl_803B8F78:
bl OSRestoreInterrupts
li r3, -6
b lbl_803B9020
lbl_803B8F84:
cmplwi r29, 0
beq lbl_803B8FA0
lwz r4, 0x18(r1)
lhz r0, 6(r30)
lwz r4, 0xc(r4)
mullw r0, r4, r0
stw r0, 0(r29)
lbl_803B8FA0:
cmplwi r31, 0
beq lbl_803B8FE4
li r0, 0
stw r0, 0(r31)
li r5, 0
b lbl_803B8FD8
lbl_803B8FB8:
lbz r0, 8(r3)
cmplwi r0, 0xff
bne lbl_803B8FD0
lwz r4, 0(r31)
addi r0, r4, 1
stw r0, 0(r31)
lbl_803B8FD0:
addi r3, r3, 0x40
addi r5, r5, 1
lbl_803B8FD8:
clrlwi r0, r5, 0x10
cmplwi r0, 0x7f
blt lbl_803B8FB8
lbl_803B8FE4:
lwz r30, 0x18(r1)
bl OSDisableInterrupts
lwz r0, 0(r30)
cmpwi r0, 0
beq lbl_803B9004
li r0, 0
stw r0, 4(r30)
b lbl_803B9018
lbl_803B9004:
lwz r0, 4(r30)
cmpwi r0, -1
bne lbl_803B9018
li r0, 0
stw r0, 4(r30)
lbl_803B9018:
bl OSRestoreInterrupts
li r3, 0
lbl_803B9020:
lwz r0, 0x34(r1)
lwz r31, 0x2c(r1)
lwz r30, 0x28(r1)
lwz r29, 0x24(r1)
addi r1, r1, 0x30
mtlr r0
blr
}
/* clang-format on */
#pragma pop
#endif
static BOOL OnReset(BOOL f) { static BOOL OnReset(BOOL f) {
if (!f) { if (!f) {

View File

@ -6,6 +6,8 @@
#include <dolphin/CARDPriv.h> #include <dolphin/CARDPriv.h>
#include <dolphin/OSRtcPriv.h> #include <dolphin/OSRtcPriv.h>
#include "string.h"
#define __CARDGetDirCheck(dir) ((CARDDirCheck*)&(dir)[CARD_MAX_FILE]) #define __CARDGetDirCheck(dir) ((CARDDirCheck*)&(dir)[CARD_MAX_FILE])
void __CARDCheckSum(void* ptr, int length, u16* checksum, u16* checksumInv) { void __CARDCheckSum(void* ptr, int length, u16* checksum, u16* checksumInv) {
@ -65,6 +67,7 @@ static s32 VerifyID(CARDControl* card) {
return CARD_RESULT_READY; return CARD_RESULT_READY;
} }
#if NONMATCHING
static s32 VerifyDir(CARDControl* card, int* outCurrent) { static s32 VerifyDir(CARDControl* card, int* outCurrent) {
CARDDir* dir[2]; CARDDir* dir[2];
CARDDirCheck* check[2]; CARDDirCheck* check[2];
@ -104,7 +107,179 @@ static s32 VerifyDir(CARDControl* card, int* outCurrent) {
} }
return errors; return errors;
} }
#else
/* clang-format off */
#pragma push
#pragma optimization_level
#pragma optimizewithasm off
static asm s32 VerifyDir(CARDControl* card, int* outCurrent) {
nofralloc
mflr r0
stw r0, 4(r1)
stwu r1, -0x38(r1)
stw r31, 0x34(r1)
addi r7, r1, 0x1c
addi r8, r1, 0x14
stw r30, 0x30(r1)
li r31, 0
li r30, 0
stw r29, 0x2c(r1)
addi r29, r4, 0
li r4, 0
lbl_803BB038:
addi r0, r4, 1
lwz r5, 0x80(r3)
slwi r0, r0, 0xd
add r0, r5, r0
stw r0, 0(r7)
li r6, 0x1ffc
srawi r6, r6, 1
lwz r5, 0(r7)
addze. r6, r6
li r11, 0
addi r0, r5, 0x1fc0
stw r0, 0(r8)
li r10, 0
lwz r5, 0(r7)
ble lbl_803BB12C
rlwinm. r0, r6, 0x1d, 3, 0x1f
mtctr r0
beq lbl_803BB110
lbl_803BB080:
lhz r9, 0(r5)
nor r0, r9, r9
add r10, r10, r9
lhz r9, 2(r5)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 4(r5)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 6(r5)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 8(r5)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 0xa(r5)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 0xc(r5)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 0xe(r5)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
add r11, r11, r0
addi r5, r5, 0x10
bdnz lbl_803BB080
andi. r6, r6, 7
beq lbl_803BB12C
lbl_803BB110:
mtctr r6
lbl_803BB114:
lhz r9, 0(r5)
addi r5, r5, 2
nor r0, r9, r9
add r10, r10, r9
add r11, r11, r0
bdnz lbl_803BB114
lbl_803BB12C:
clrlwi r0, r10, 0x10
cmplwi r0, 0xffff
bne lbl_803BB13C
li r10, 0
lbl_803BB13C:
clrlwi r0, r11, 0x10
cmplwi r0, 0xffff
bne lbl_803BB14C
li r11, 0
lbl_803BB14C:
lwz r6, 0(r8)
clrlwi r5, r10, 0x10
lhz r0, 0x3c(r6)
cmplw r5, r0
bne lbl_803BB170
lhz r0, 0x3e(r6)
clrlwi r5, r11, 0x10
cmplw r5, r0
beq lbl_803BB180
lbl_803BB170:
li r0, 0
stw r0, 0x84(r3)
addi r30, r4, 0
addi r31, r31, 1
lbl_803BB180:
addi r4, r4, 1
cmpwi r4, 2
addi r7, r7, 4
addi r8, r8, 4
blt lbl_803BB038
cmpwi r31, 0
bne lbl_803BB21C
lwz r4, 0x84(r3)
cmplwi r4, 0
bne lbl_803BB200
lwz r5, 0x18(r1)
lwz r4, 0x14(r1)
lha r5, 0x3a(r5)
lha r0, 0x3a(r4)
subf. r0, r5, r0
bge lbl_803BB1C8
li r30, 0
b lbl_803BB1CC
lbl_803BB1C8:
li r30, 1
lbl_803BB1CC:
slwi r0, r30, 2
addi r6, r1, 0x1c
add r6, r6, r0
lwz r4, 0(r6)
xori r0, r30, 1
slwi r0, r0, 2
stw r4, 0x84(r3)
addi r4, r1, 0x1c
li r5, 0x2000
lwz r3, 0(r6)
lwzx r4, r4, r0
bl memcpy
b lbl_803BB21C
lbl_803BB200:
lwz r0, 0x1c(r1)
cmplw r4, r0
bne lbl_803BB214
li r0, 0
b lbl_803BB218
lbl_803BB214:
li r0, 1
lbl_803BB218:
mr r30, r0
lbl_803BB21C:
cmplwi r29, 0
beq lbl_803BB228
stw r30, 0(r29)
lbl_803BB228:
mr r3, r31
lwz r0, 0x3c(r1)
lwz r31, 0x34(r1)
lwz r30, 0x30(r1)
lwz r29, 0x2c(r1)
addi r1, r1, 0x38
mtlr r0
blr
}
/* clang-format on */
#pragma pop
#endif
#if NONMATCHING
static s32 VerifyFAT(CARDControl* card, int* outCurrent) { static s32 VerifyFAT(CARDControl* card, int* outCurrent) {
u16* fat[2]; u16* fat[2];
u16* fatp; u16* fatp;
@ -161,6 +336,200 @@ static s32 VerifyFAT(CARDControl* card, int* outCurrent) {
} }
return errors; return errors;
} }
#else
/* clang-format off */
#pragma push
#pragma optimization_level
#pragma optimizewithasm off
static asm s32 VerifyFAT(CARDControl* card, int* outCurrent) {
nofralloc
mflr r0
li r5, 0
stw r0, 4(r1)
stwu r1, -0x28(r1)
stw r31, 0x24(r1)
li r31, 0
stw r30, 0x20(r1)
li r30, 0
stw r29, 0x1c(r1)
addi r29, r4, 0
addi r4, r1, 0x10
lbl_803BB274:
li r8, 0x1ffc
lwz r6, 0x80(r3)
addi r0, r5, 3
srawi r8, r8, 1
slwi r0, r0, 0xd
add r7, r6, r0
addze. r8, r8
stw r7, 0(r4)
addi r6, r7, 4
li r11, 0
li r10, 0
ble lbl_803BB35C
rlwinm. r0, r8, 0x1d, 3, 0x1f
mtctr r0
beq lbl_803BB340
lbl_803BB2B0:
lhz r9, 0(r6)
nor r0, r9, r9
add r10, r10, r9
lhz r9, 2(r6)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 4(r6)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 6(r6)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 8(r6)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 0xa(r6)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 0xc(r6)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
lhz r9, 0xe(r6)
add r11, r11, r0
nor r0, r9, r9
add r10, r10, r9
add r11, r11, r0
addi r6, r6, 0x10
bdnz lbl_803BB2B0
andi. r8, r8, 7
beq lbl_803BB35C
lbl_803BB340:
mtctr r8
lbl_803BB344:
lhz r9, 0(r6)
addi r6, r6, 2
nor r0, r9, r9
add r10, r10, r9
add r11, r11, r0
bdnz lbl_803BB344
lbl_803BB35C:
clrlwi r0, r10, 0x10
cmplwi r0, 0xffff
bne lbl_803BB36C
li r10, 0
lbl_803BB36C:
clrlwi r0, r11, 0x10
cmplwi r0, 0xffff
bne lbl_803BB37C
li r11, 0
lbl_803BB37C:
lhz r6, 0(r7)
clrlwi r0, r10, 0x10
cmplw r6, r0
bne lbl_803BB39C
lhz r6, 2(r7)
clrlwi r0, r11, 0x10
cmplw r6, r0
beq lbl_803BB3B0
lbl_803BB39C:
li r0, 0
stw r0, 0x88(r3)
addi r30, r5, 0
addi r31, r31, 1
b lbl_803BB408
lbl_803BB3B0:
lhz r8, 0x10(r3)
addi r6, r7, 0xa
li r10, 0
li r9, 5
b lbl_803BB3DC
lbl_803BB3C4:
lhz r0, 0(r6)
cmplwi r0, 0
bne lbl_803BB3D4
addi r10, r10, 1
lbl_803BB3D4:
addi r6, r6, 2
addi r9, r9, 1
lbl_803BB3DC:
clrlwi r0, r9, 0x10
cmplw r0, r8
blt lbl_803BB3C4
lhz r0, 6(r7)
clrlwi r6, r10, 0x10
cmplw r6, r0
beq lbl_803BB408
li r0, 0
stw r0, 0x88(r3)
addi r30, r5, 0
addi r31, r31, 1
lbl_803BB408:
addi r5, r5, 1
cmpwi r5, 2
addi r4, r4, 4
blt lbl_803BB274
cmpwi r31, 0
bne lbl_803BB4A0
lwz r4, 0x88(r3)
cmplwi r4, 0
bne lbl_803BB484
lwz r5, 0x14(r1)
lwz r4, 0x10(r1)
lha r5, 4(r5)
lha r0, 4(r4)
subf. r0, r5, r0
bge lbl_803BB44C
li r30, 0
b lbl_803BB450
lbl_803BB44C:
li r30, 1
lbl_803BB450:
slwi r0, r30, 2
addi r6, r1, 0x10
add r6, r6, r0
lwz r4, 0(r6)
xori r0, r30, 1
slwi r0, r0, 2
stw r4, 0x88(r3)
addi r4, r1, 0x10
li r5, 0x2000
lwz r3, 0(r6)
lwzx r4, r4, r0
bl memcpy
b lbl_803BB4A0
lbl_803BB484:
lwz r0, 0x10(r1)
cmplw r4, r0
bne lbl_803BB498
li r0, 0
b lbl_803BB49C
lbl_803BB498:
li r0, 1
lbl_803BB49C:
mr r30, r0
lbl_803BB4A0:
cmplwi r29, 0
beq lbl_803BB4AC
stw r30, 0(r29)
lbl_803BB4AC:
mr r3, r31
lwz r0, 0x2c(r1)
lwz r31, 0x24(r1)
lwz r30, 0x20(r1)
lwz r29, 0x1c(r1)
addi r1, r1, 0x28
mtlr r0
blr
}
/* clang-format on */
#pragma pop
#endif
s32 __CARDVerify(CARDControl* card) { s32 __CARDVerify(CARDControl* card) {
s32 result; s32 result;