This commit is contained in:
Aurora
2016-07-01 20:27:28 +02:00
parent 61684ecb68
commit 136e0d8974
14 changed files with 151 additions and 156 deletions

5
loader/source/cache.h Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
#include "types.h"
void flushCaches(void);

39
loader/source/cache.s Normal file
View File

@@ -0,0 +1,39 @@
@
@ cache.s
@ by TuxSH
@
@ This is part of Luma3DS, see LICENSE.txt for details
@
.arm
.global flushCaches
.type flushCaches STT_FUNC
flushCaches:
@ Clean and flush data cache
@ Adpated from http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0155a/ch03s03s05.html ,
@ and https://github.com/gemarcano/libctr9_io/blob/master/src/ctr_system_ARM.c#L39 as well
@ Note: ARM's example is actually for a 8KB DCache (which is what the 3DS has)
@ Implemented in bootROM at address 0xffff0830
mov r1, #0 @ segment counter
outer_loop:
mov r0, #0 @ line counter
inner_loop:
orr r2, r1, r0 @ generate segment and line address
mcr p15, 0, r2, c7, c14, 2 @ clean and flush the line
add r0, #0x20 @ increment to next line
cmp r0, #0x400
bne inner_loop
add r1, #0x40000000
cmp r1, #0
bne outer_loop
mcr p15, 0, r1, c7, c10, 4 @ drain write buffer
@ Flush instruction cache
mcr p15, 0, r1, c7, c5, 0
bx lr

View File

@@ -1,4 +1,5 @@
#include "memory.h"
#include "cache.h"
void main(void)
{
@@ -6,8 +7,7 @@ void main(void)
memcpy(payloadAddress, (void*)0x24F00000, *(u32 *)0x24FFFF04);
((void (*)(void))0xFFFF0830)(); //Clean and flush the entire DCache, then drain the write buffer
((void (*)(void))0xFFFF0AB4)(); //Flush the entire ICache
flushCaches();
((void (*)())payloadAddress)();
}

View File

@@ -2,15 +2,6 @@
.align 4
.global _start
_start:
b start
b main
.word 0
start:
@ Flush caches
mov r0, #0
mcr p15, 0, r0, c7, c5, 0 @ flush I-cache
mcr p15, 0, r0, c7, c6, 0 @ flush D-cache
mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
b main