mirror of
https://github.com/LNH-team/pico-loader.git
synced 2026-06-02 09:16:49 +02:00
Added check to CardiTaskThreadPatch that the required slot is actually mapped to arm7. Fixes #60
This commit is contained in:
@@ -8,6 +8,7 @@ extern "C" void __patch_carditaskthread_entry_sdk4();
|
|||||||
|
|
||||||
extern u16 __patch_carditaskthread_mov_cardicommon_to_r4;
|
extern u16 __patch_carditaskthread_mov_cardicommon_to_r4;
|
||||||
extern u16 __patch_carditaskthread_mov_command_to_r0;
|
extern u16 __patch_carditaskthread_mov_command_to_r0;
|
||||||
|
extern u16 __patch_carditaskthread_lsls_exmemstat_bit_to_r1;
|
||||||
|
|
||||||
extern u32 __patch_carditaskthread_failoffset;
|
extern u32 __patch_carditaskthread_failoffset;
|
||||||
extern u32 __patch_carditaskthread_successoffset;
|
extern u32 __patch_carditaskthread_successoffset;
|
||||||
|
|||||||
@@ -21,18 +21,22 @@ __patch_carditaskthread_mov_cardicommon_to_r4:
|
|||||||
__patch_carditaskthread_mov_command_to_r0:
|
__patch_carditaskthread_mov_command_to_r0:
|
||||||
ldr r0, [r4, #4] // r0 = command
|
ldr r0, [r4, #4] // r0 = command
|
||||||
|
|
||||||
cmp r0, #2
|
ldr r1,= 0x04000204
|
||||||
beq identify_backup
|
ldrh r1, [r1]
|
||||||
|
.global __patch_carditaskthread_lsls_exmemstat_bit_to_r1
|
||||||
|
__patch_carditaskthread_lsls_exmemstat_bit_to_r1:
|
||||||
|
lsls r1, r1, #20
|
||||||
|
mvns r1, r1
|
||||||
|
lsrs r1, r1, #31 // r1 = 0 when slot mapped to arm7, 1 when slot not mapped to arm7
|
||||||
|
|
||||||
|
cmp r0, #2
|
||||||
|
beq end_success // identify
|
||||||
cmp r0, #6
|
cmp r0, #6
|
||||||
beq read_backup
|
beq read_backup
|
||||||
|
|
||||||
cmp r0, #7
|
cmp r0, #7
|
||||||
beq write_backup
|
beq write_backup
|
||||||
|
|
||||||
cmp r0, #8
|
cmp r0, #8
|
||||||
beq write_backup
|
beq write_backup
|
||||||
|
|
||||||
cmp r0, #9
|
cmp r0, #9
|
||||||
beq verify_backup
|
beq verify_backup
|
||||||
|
|
||||||
@@ -58,18 +62,8 @@ end:
|
|||||||
adds r3, r0
|
adds r3, r0
|
||||||
bx r3
|
bx r3
|
||||||
|
|
||||||
identify_backup:
|
|
||||||
b end_success
|
|
||||||
|
|
||||||
read_backup:
|
read_backup:
|
||||||
ldr r0, [r4]
|
bl read_write_verify_backup_common
|
||||||
movs r1, #0
|
|
||||||
str r1, [r0] // result
|
|
||||||
ldr r1, [r0, #0xC] // src
|
|
||||||
ldr r2, [r0, #0x10] // dst
|
|
||||||
ldr r3, [r0, #0x14] // len
|
|
||||||
cmp r3, #0
|
|
||||||
beq end_success
|
|
||||||
|
|
||||||
ldr r0, __patch_carditaskthread_readsave_asm_address
|
ldr r0, __patch_carditaskthread_readsave_asm_address
|
||||||
bl blx_r0
|
bl blx_r0
|
||||||
@@ -77,14 +71,7 @@ read_backup:
|
|||||||
b end_success
|
b end_success
|
||||||
|
|
||||||
write_backup:
|
write_backup:
|
||||||
ldr r0, [r4]
|
bl read_write_verify_backup_common
|
||||||
movs r1, #0
|
|
||||||
str r1, [r0] // result
|
|
||||||
ldr r1, [r0, #0xC] // src
|
|
||||||
ldr r2, [r0, #0x10] // dst
|
|
||||||
ldr r3, [r0, #0x14] // len
|
|
||||||
cmp r3, #0
|
|
||||||
beq end_success
|
|
||||||
|
|
||||||
ldr r0, __patch_carditaskthread_writesave_asm_address
|
ldr r0, __patch_carditaskthread_writesave_asm_address
|
||||||
bl blx_r0
|
bl blx_r0
|
||||||
@@ -92,12 +79,7 @@ write_backup:
|
|||||||
b end_success
|
b end_success
|
||||||
|
|
||||||
verify_backup:
|
verify_backup:
|
||||||
ldr r0, [r4]
|
bl read_write_verify_backup_common
|
||||||
ldr r2, [r0, #0xC] // src
|
|
||||||
ldr r1, [r0, #0x10] // dst
|
|
||||||
ldr r3, [r0, #0x14] // len
|
|
||||||
cmp r3, #0
|
|
||||||
beq end_success
|
|
||||||
|
|
||||||
push {r0}
|
push {r0}
|
||||||
ldr r0, __patch_carditaskthread_verifysave_asm_address
|
ldr r0, __patch_carditaskthread_verifysave_asm_address
|
||||||
@@ -106,6 +88,18 @@ verify_backup:
|
|||||||
str r0, [r1] // result
|
str r0, [r1] // result
|
||||||
b end_success
|
b end_success
|
||||||
|
|
||||||
|
read_write_verify_backup_common:
|
||||||
|
ldr r0, [r4]
|
||||||
|
str r1, [r0] // result
|
||||||
|
cmp r1, #0
|
||||||
|
bne end_success
|
||||||
|
ldr r1, [r0, #0xC] // src
|
||||||
|
ldr r2, [r0, #0x10] // dst
|
||||||
|
ldr r3, [r0, #0x14] // len
|
||||||
|
cmp r3, #0
|
||||||
|
beq end_success
|
||||||
|
bx lr
|
||||||
|
|
||||||
blx_r0:
|
blx_r0:
|
||||||
bx r0
|
bx r0
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
.syntax unified
|
.syntax unified
|
||||||
.thumb
|
.thumb
|
||||||
|
|
||||||
// r1 = save src
|
// r1 = memory src
|
||||||
// r2 = memory src
|
// r2 = save src
|
||||||
// r3 = byte length
|
// r3 = byte length
|
||||||
.global verifysave_asm
|
.global verifysave_asm
|
||||||
.type verifysave_asm, %function
|
.type verifysave_asm, %function
|
||||||
verifysave_asm:
|
verifysave_asm:
|
||||||
push {r4,r5,r6,r7,lr}
|
push {r4,r5,r6,r7,lr}
|
||||||
movs r4, r3 // remaining bytes
|
movs r4, r3 // remaining bytes
|
||||||
movs r5, r1
|
movs r5, r2
|
||||||
movs r6, r2
|
movs r6, r1
|
||||||
1:
|
1:
|
||||||
movs r0, r5 // will be rounded down by function
|
movs r0, r5 // will be rounded down by function
|
||||||
ldr r3, verifysave_save_offset_to_sd_sector_asm_address
|
ldr r3, verifysave_save_offset_to_sd_sector_asm_address
|
||||||
|
|||||||
@@ -133,6 +133,16 @@ void CardiTaskThreadPatch::ApplyPatch(PatchContext& patchContext)
|
|||||||
__patch_carditaskthread_readsave_asm_address = (u32)readSavePatchCode->GetReadSaveFunction();
|
__patch_carditaskthread_readsave_asm_address = (u32)readSavePatchCode->GetReadSaveFunction();
|
||||||
__patch_carditaskthread_writesave_asm_address = (u32)writeSavePatchCode->GetWriteSaveFunction();
|
__patch_carditaskthread_writesave_asm_address = (u32)writeSavePatchCode->GetWriteSaveFunction();
|
||||||
__patch_carditaskthread_verifysave_asm_address = (u32)verifySavePatchCode->GetVerifySaveFunction();
|
__patch_carditaskthread_verifysave_asm_address = (u32)verifySavePatchCode->GetVerifySaveFunction();
|
||||||
|
if (loaderPlatform->GetPlatformType() == LoaderPlatformType::Slot1)
|
||||||
|
{
|
||||||
|
// Test REG_EXMEMSTAT bit 11
|
||||||
|
__patch_carditaskthread_lsls_exmemstat_bit_to_r1 = THUMB_LSLS_IMM(THUMB_R1, THUMB_R1, 31 - 11);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Test REG_EXMEMSTAT bit 7
|
||||||
|
__patch_carditaskthread_lsls_exmemstat_bit_to_r1 = THUMB_LSLS_IMM(THUMB_R1, THUMB_R1, 31 - 7);
|
||||||
|
}
|
||||||
|
|
||||||
if (_patchVariant >= PatchVariant::ThumbA)
|
if (_patchVariant >= PatchVariant::ThumbA)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -93,6 +93,16 @@ void CardiDoTaskFromArm9Patch::ApplyPatch(PatchContext& patchContext)
|
|||||||
__patch_carditaskthread_readsave_asm_address = (u32)readSavePatchCode->GetReadSaveFunction();
|
__patch_carditaskthread_readsave_asm_address = (u32)readSavePatchCode->GetReadSaveFunction();
|
||||||
__patch_carditaskthread_writesave_asm_address = (u32)writeSavePatchCode->GetWriteSaveFunction();
|
__patch_carditaskthread_writesave_asm_address = (u32)writeSavePatchCode->GetWriteSaveFunction();
|
||||||
__patch_carditaskthread_verifysave_asm_address = (u32)verifySavePatchCode->GetVerifySaveFunction();
|
__patch_carditaskthread_verifysave_asm_address = (u32)verifySavePatchCode->GetVerifySaveFunction();
|
||||||
|
if (loaderPlatform->GetPlatformType() == LoaderPlatformType::Slot1)
|
||||||
|
{
|
||||||
|
// Test REG_EXMEMSTAT bit 11
|
||||||
|
__patch_carditaskthread_lsls_exmemstat_bit_to_r1 = THUMB_LSLS_IMM(THUMB_R1, THUMB_R1, 31 - 11);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Test REG_EXMEMSTAT bit 7
|
||||||
|
__patch_carditaskthread_lsls_exmemstat_bit_to_r1 = THUMB_LSLS_IMM(THUMB_R1, THUMB_R1, 31 - 7);
|
||||||
|
}
|
||||||
|
|
||||||
u32 patchOffset;
|
u32 patchOffset;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "SdWritePatchCode.h"
|
#include "SdWritePatchCode.h"
|
||||||
#include "../PatchHeap.h"
|
#include "../PatchHeap.h"
|
||||||
#include "../PatchCodeCollection.h"
|
#include "../PatchCodeCollection.h"
|
||||||
|
#include "LoaderPlatformType.h"
|
||||||
|
|
||||||
/// @brief Abstract class for platform (flashcard or other sd access method) specific parts of the loader.
|
/// @brief Abstract class for platform (flashcard or other sd access method) specific parts of the loader.
|
||||||
class LoaderPlatform
|
class LoaderPlatform
|
||||||
@@ -38,6 +39,10 @@ public:
|
|||||||
virtual const SdReadPatchCode* CreateRomReadPatchCode(
|
virtual const SdReadPatchCode* CreateRomReadPatchCode(
|
||||||
PatchCodeCollection& patchCodeCollection, PatchHeap& patchHeap) const { return nullptr; }
|
PatchCodeCollection& patchCodeCollection, PatchHeap& patchHeap) const { return nullptr; }
|
||||||
|
|
||||||
|
/// @brief Returns the type of this loader platform.
|
||||||
|
/// @return The type of this loader platform.
|
||||||
|
virtual LoaderPlatformType GetPlatformType() const = 0;
|
||||||
|
|
||||||
/// @brief Checks if the platform supports rom reads directly.
|
/// @brief Checks if the platform supports rom reads directly.
|
||||||
/// @return True if the platform supports rom reads, or false otherwise.
|
/// @return True if the platform supports rom reads, or false otherwise.
|
||||||
virtual bool HasRomReads() const { return false; }
|
virtual bool HasRomReads() const { return false; }
|
||||||
|
|||||||
11
arm9/source/patches/platform/LoaderPlatformType.h
Normal file
11
arm9/source/patches/platform/LoaderPlatformType.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/// @brief Enum representing the type of loader platform.
|
||||||
|
enum class LoaderPlatformType
|
||||||
|
{
|
||||||
|
/// @brief Slot 1 (DS) cartridge.
|
||||||
|
Slot1,
|
||||||
|
|
||||||
|
/// @brief Slot 2 (GBA) cartridge.
|
||||||
|
Slot2
|
||||||
|
};
|
||||||
@@ -34,5 +34,7 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot1; }
|
||||||
|
|
||||||
bool HasDmaSdReads() const override { return true; }
|
bool HasDmaSdReads() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ public:
|
|||||||
explicit IoRPGLoaderPlatform(u8 ioRpgCmdSdioByte)
|
explicit IoRPGLoaderPlatform(u8 ioRpgCmdSdioByte)
|
||||||
: _ioRpgCmdSdioByte(ioRpgCmdSdioByte) { }
|
: _ioRpgCmdSdioByte(ioRpgCmdSdioByte) { }
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot1; }
|
||||||
|
|
||||||
bool InitializeSdCard() override;
|
bool InitializeSdCard() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -43,5 +43,7 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot1; }
|
||||||
|
|
||||||
bool HasDmaSdReads() const override { return true; }
|
bool HasDmaSdReads() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,5 +34,7 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot1; }
|
||||||
|
|
||||||
bool InitializeSdCard() override;
|
bool InitializeSdCard() override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,4 +30,6 @@ public:
|
|||||||
return new EZPWriteSectorsPatchCode(patchHeap);
|
return new EZPWriteSectorsPatchCode(patchHeap);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot1; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,5 +34,7 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot1; }
|
||||||
|
|
||||||
bool HasDmaSdReads() const override { return true; }
|
bool HasDmaSdReads() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot2; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u32 GetAgbRamPtr() const
|
u32 GetAgbRamPtr() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,4 +33,6 @@ public:
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot1; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,4 +25,6 @@ public:
|
|||||||
return new MelonDSWriteSdPatchCode(patchHeap);
|
return new MelonDSWriteSdPatchCode(patchHeap);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot1; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot1; }
|
||||||
|
|
||||||
bool HasRomReads() const override { return true; }
|
bool HasRomReads() const override { return true; }
|
||||||
|
|
||||||
void PrepareRomBoot(u32 romDirSector, u32 romDirSectorOffset) const override;
|
void PrepareRomBoot(u32 romDirSector, u32 romDirSectorOffset) const override;
|
||||||
|
|||||||
@@ -99,6 +99,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoaderPlatformType GetPlatformType() const override { return LoaderPlatformType::Slot2; }
|
||||||
|
|
||||||
bool InitializeSdCard() override;
|
bool InitializeSdCard() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user