Skip to content

Commit

Permalink
Merge pull request #22 from ahezard/card
Browse files Browse the repository at this point in the history
Merge stable card build
  • Loading branch information
ahezard authored Dec 27, 2016
2 parents d46850c + 4b08002 commit 604d6c3
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 73 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ addons:

after_success:
- >
if [ "$TRAVIS_BRANCH" == "master" ]; then
if [ "$TRAVIS_BRANCH" == "master" ] || [ "$TRAVIS_BRANCH" == "card" ]; then
GITDATE="`git show -s --date=short --format='%ad' | sed 's/-//g'`"
GITREV="`git show -s --format='%h'`"
REV_NAME="bootstrap-dldi-${GITDATE}-${GITREV}.nds"
REV_NAME="bootstrap-${TRAVIS_BRANCH}-${GITDATE}-${GITREV}.nds"
cp bootstrap-dldi.nds $REV_NAME
lftp -c "open -u nds-bootstrap,$BUILD_PASSWORD sftp://joshuadoes.com; put -O ' /home/nds-bootstrap' '${REV_NAME}'"
lftp ftp://nds-bootstrap:[email protected] -e "set net:timeout 5; set net:max-retries 2; cd files; put ${REV_NAME}; bye"
lftp sftp://twlbuild:[email protected] -e "set net:timeout 5; set net:max-retries 2; cd files; put ${REV_NAME}; bye"
fi
52 changes: 36 additions & 16 deletions bootloader/source/card_patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ u32 cardPullOutSignature1[4] = {0xE92D4000,0xE24DD004,0xE201003F,0xE3500011};
u32 cardPullOutSignature4[4] = {0xE92D4008,0xE201003F,0xE3500011,0x1A00000D};
u32 a9cardSendSignature[7] = {0xE92D40F0,0xE24DD004,0xE1A07000,0xE1A06001,0xE1A01007,0xE3A0000E,0xE3A02000};
u32 cardCheckPullOutSignature[4] = {0xE92D4018,0xE24DD004,0xE59F204C,0xE1D210B0};
u32 cardReadCachedSignature[4] = {0xE92D4030,0xE24DD004,0xE59F5090,0xE3A01C02};
u32 cardReadCachedStartSignature1[2] = {0xE92D4030,0xE24DD004};
u32 cardReadCachedEndSignature1[4] = {0xE5950020,0xE3500000,0x13A00001,0x03A00000};

u32 cardReadCachedEndSignature3[4] = {0xE5950024,0xE3500000,0x13A00001,0x03A00000};

u32 cardReadCachedStartSignature4[2] = {0xE92D4038,0xE59F407C};
u32 cardReadCachedEndSignature4[4] = {0xE5940024,0xE3500000,0x13A00001,0x03A00000};

// irqEnable
u32 irqEnableStartSignature[4] = {0xE59FC02C,0xE1DC30B0,0xE3A01000,0xE1CC10B0};

Expand Down Expand Up @@ -153,10 +159,16 @@ u32 patchCardNds (const tNDSHeader* ndsHeader, u32* cardEngineLocation, module_p
u32* a9cardReadSignature = a9cardReadSignature1;
u32* cardReadStartSignature = cardReadStartSignature1;
u32* cardPullOutSignature = cardPullOutSignature1;
if(moduleParams->sdk_version > 0x4000000) {
u32* cardReadCachedStartSignature = cardReadCachedStartSignature1;
u32* cardReadCachedEndSignature = cardReadCachedEndSignature1;
if(moduleParams->sdk_version > 0x3000000 && moduleParams->sdk_version < 0x4000000) {
cardReadCachedEndSignature = cardReadCachedEndSignature3;
} else if(moduleParams->sdk_version > 0x4000000) {
a9cardReadSignature = a9cardReadSignature4;
cardReadStartSignature = cardReadStartSignature4;
cardPullOutSignature = cardPullOutSignature4;
cardReadCachedStartSignature = cardReadCachedStartSignature4;
cardReadCachedEndSignature = cardReadCachedEndSignature4;
}

// Find the card read
Expand Down Expand Up @@ -189,17 +201,6 @@ u32 patchCardNds (const tNDSHeader* ndsHeader, u32* cardEngineLocation, module_p
nocashMessage("Card check pull out found\n");
}

u32 cardReadCachedOffset =
getOffsetA9((u32*)ndsHeader->arm9destination, 0x00400000,//, ndsHeader->arm9binarySize,
(u32*)cardReadCachedSignature, 4, 1);
if (!cardReadCachedOffset) {
nocashMessage("Card read cached not found\n");
return 0;
} else {
debug[0] = cardReadCachedOffset;
nocashMessage("Card read cached found\n");
}

u32 cardIrqEnableOffset =
getOffsetA9((u32*)ndsHeader->arm7destination, 0x00400000,//, ndsHeader->arm9binarySize,
(u32*)irqEnableStartSignature, 4, 1);
Expand Down Expand Up @@ -230,6 +231,25 @@ u32 patchCardNds (const tNDSHeader* ndsHeader, u32* cardEngineLocation, module_p
debug[0] = cardPullOutOffset;
nocashMessage("Card pull out handler found\n");


u32 cardReadCachedEndOffset =
getOffsetA9((u32*)ndsHeader->arm9destination, 0x00300000,//ndsHeader->arm9binarySize,
(u32*)cardReadCachedEndSignature, 4, 1);
if (!cardReadCachedEndOffset) {
nocashMessage("Card read cached end not found\n");
return 0;
}
debug[1] = cardReadCachedEndOffset;
u32 cardReadCachedOffset =
getOffsetA9((u32*)cardReadCachedEndOffset, -0xFF,
(u32*)cardReadCachedStartSignature, 2, -1);
if (!cardReadStartOffset) {
nocashMessage("Card read cached start not found\n");
return 0;
}
debug[0] = cardReadCachedOffset;
nocashMessage("Card read cached found\n");

/*
// Find the card id
u32 cardIdEndOffset =
Expand All @@ -250,7 +270,7 @@ u32 patchCardNds (const tNDSHeader* ndsHeader, u32* cardEngineLocation, module_p
debug[0] = cardIdStartOffset;
nocashMessage("Card id found\n"); */

u32 arenaLoOffset =
/*u32 arenaLoOffset =
getOffsetA9((u32*)ndsHeader->arm9destination, 0x00300000,//, ndsHeader->arm9binarySize,
(u32*)arenaLowSignature, 4, 1);
if (!arenaLoOffset) {
Expand All @@ -276,7 +296,7 @@ u32 patchCardNds (const tNDSHeader* ndsHeader, u32* cardEngineLocation, module_p
//*((u32*)arenaLo2Offset) = *((u32*)arenaLo2Offset) + 0x800; // shrink heap by 8 kb
debug[13] = arenaLo2Offset;
}
}*/

debug[2] = cardEngineLocation;

Expand Down Expand Up @@ -337,7 +357,7 @@ u32 patchCardNds (const tNDSHeader* ndsHeader, u32* cardEngineLocation, module_p
if(cardCheckPullOutOffset>0)
copyLoop ((u32*)cardCheckPullOutOffset, cardCheckPullOutPatch, 0x4);

copyLoop ((u32*)cardPullOutOffset, cardPullOutPatch, 0x6C);
copyLoop ((u32*)cardPullOutOffset, cardPullOutPatch, 0x5C);

copyLoop ((u32*)cardIrqEnableOffset, cardIrqEnablePatch, 0x30);

Expand Down
116 changes: 62 additions & 54 deletions cardengine/source/card_engine_header.s
Original file line number Diff line number Diff line change
Expand Up @@ -102,81 +102,87 @@ patches:
card_read_arm9:
@---------------------------------------------------------------------------------
stmfd sp!, {r0-r11,lr}

@ registers used r0,r1,r2,r3,r5,r6,r7,r8
str r0, cacheRef

begin:
@ registers used r0,r1,r2,r3,r5,r8,r11
ldr r3,=0x4000100 @IPC_SYNC & command value
ldr r8,=0x027FFB08 @shared area command
ldr r4, cardStructArm9
ldr r8,=0x027FFB08 @shared area command
ldr r4, cardStructArm9
ldr r5, [R4] @SRC
ldr r1, [R4,#0x8] @LEN
ldr r0, [R4,#0x4] @DST
ldr r1, [R4,#0x8] @LEN
mov r2, #0x2400
mov r2, #0x2400

@page computation
mov r9, #0x200
rsb r10, r9, #0
and r11, r5, r10

@ check for cmd2
cmp r11, r5
bne cmd1
cmp r1, #1024
blt cmd1
sub r7, r8, #(0x027FFB08 - 0x026FFB08) @below dtcm
cmp r0, r7
bgt cmd1
sub r7, r8, #(0x027FFB08 - 0x019FFB08) @above itcm
cmp r0, r7
blt cmd1
ands r10, r0, #3
bne cmd1

@sub r7, r8, #(0x027FFB08 - 0x026FFB08) @below dtcm
@cmp r0, r7
@bgt check_partial
b check_partial @deactivate cmd2 optimization
cmd2:
sub r7, r8, #(0x027FFB08 - 0x025FFB08) @cmd2 marker
@r0 dst, r1 len
ldr r9, cacheFlushRef
blx r9 @ cache flush code
b partial_cmd2

check_partial:
cmp r1, #512
blt partial

chunck_loop:
mov r4, #512
sub r7, r8, #(0x027FFB08 - 0x027ff800) @shared area data
@dst, len, src, marker
stmia r8, {r0,r4,r5,r7}

@sendIPCSync
strh r2, [r3,#0x80]

chunck_loop_wait:
ldr r9, [r8,#12]
cmp r9,#0
bne chunck_loop_wait
chunck_loop_copy:
ldrb r9, [r7], #1
strb r9, [r0], #1
subs r4, #1
bgt chunck_loop_copy
b send_cmd

chunk_end_copy:
add r5, #512
subs r1, #512
beq exitfunc
b check_partial
cmd1:
mov R1, #0x200
mov r5, r11 @ current page
sub r7, r8, #(0x027FFB08 - 0x027ff800) @cmd1 marker

partial:
sub r7, r8, #(0x027FFB08 - 0x027ff800) @shared area data
partial_cmd2:
send_cmd:
@dst, len, src, marker
stmia r8, {r0,r1,r5,r7}

@sendIPCSync
strh r2, [r3,#0x80]

partial_loop_wait:
loop_wait:
ldr r9, [r8,#12]
cmp r9,#0
bne partial_loop_wait
bne loop_wait

@ check for cmd2
cmp r1, #0x200
bne exitfunc

sub r8, r8, #(0x027FFB08 - 0x027ff800) @shared area data
cmp r7, r8
bne exitfunc
ldr r9, cacheRef
add r9,r9,#0x20 @ cache buffer
mov r10,r7

partial_loop_copy:
ldrb r9, [r7], #1
strb r9, [r0], #1
subs r1, #1
bgt partial_loop_copy
@ copy 512 bytes
mov r8, #512
loop_copy:
ldmia r10!, {r0-r7}
stmia r9!, {r0-r7}
subs r8, r8, #32 @ 4*8 bytes
bgt loop_copy

exitfunc:
ldr r0, cacheRef
str r11, [r0, #8] @ cache page

ldr r9, readCachedRef
blx r9

cmp r0,#0
bne begin

exitfunc:
ldmfd sp!, {r0-r11,lr}
bx lr

Expand All @@ -186,6 +192,8 @@ cacheFlushRef:
.word 0x00000000
readCachedRef:
.word 0x00000000
cacheRef:
.word 0x00000000
.pool
@---------------------------------------------------------------------------------

Expand Down Expand Up @@ -259,4 +267,4 @@ DC_WaitWriteBufferEmpty:

ldmfd sp!, {r0-r11,lr}
bx lr
.pool
.pool

0 comments on commit 604d6c3

Please sign in to comment.