|
| 1 | +/* |
| 2 | + Copyright 2006 - 2015 Dave Murphy (WinterMute) |
| 3 | + |
| 4 | + This program is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU General Public License as published by |
| 6 | + the Free Software Foundation, either version 2 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | + |
| 9 | + This program is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU General Public License for more details. |
| 13 | + |
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +*/ |
| 18 | + |
| 19 | +#include <nds/arm9/cache_asm.h> |
| 20 | + |
| 21 | + .text |
| 22 | + .align 4 |
| 23 | + |
| 24 | + .arm |
| 25 | + |
| 26 | + .arch armv5te |
| 27 | + .cpu arm946e-s |
| 28 | + |
| 29 | +@--------------------------------------------------------------------------------- |
| 30 | + .global _start |
| 31 | + .type _start STT_FUNC |
| 32 | +@--------------------------------------------------------------------------------- |
| 33 | +_start: |
| 34 | +@--------------------------------------------------------------------------------- |
| 35 | + @ Switch off MPU |
| 36 | + mrc p15, 0, r0, c1, c0, 0 |
| 37 | + bic r0, r0, #PROTECT_ENABLE |
| 38 | + mcr p15, 0, r0, c1, c0, 0 |
| 39 | + |
| 40 | + |
| 41 | + adr r12, mpu_initial_data |
| 42 | + ldmia r12, {r0-r10} |
| 43 | + |
| 44 | + mcr p15, 0, r0, c2, c0, 0 |
| 45 | + mcr p15, 0, r0, c2, c0, 1 |
| 46 | + mcr p15, 0, r1, c3, c0, 0 |
| 47 | + mcr p15, 0, r2, c5, c0, 2 |
| 48 | + mcr p15, 0, r3, c5, c0, 3 |
| 49 | + mcr p15, 0, r4, c6, c0, 0 |
| 50 | + mcr p15, 0, r5, c6, c1, 0 |
| 51 | + mcr p15, 0, r6, c6, c3, 0 |
| 52 | + mcr p15, 0, r7, c6, c4, 0 |
| 53 | + mcr p15, 0, r8, c6, c6, 0 |
| 54 | + mcr p15, 0, r9, c6, c7, 0 |
| 55 | + mcr p15, 0, r10, c9, c1, 0 |
| 56 | + |
| 57 | + mov r0, #0 |
| 58 | + mcr p15, 0, r0, c6, c2, 0 @ PU Protection Unit Data/Unified Region 2 |
| 59 | + mcr p15, 0, r0, c6, c5, 0 @ PU Protection Unit Data/Unified Region 5 |
| 60 | + |
| 61 | + mrc p15, 0, r0, c9, c1, 0 @ DTCM |
| 62 | + mov r0, r0, lsr #12 @ base |
| 63 | + mov r0, r0, lsl #12 @ size |
| 64 | + add r0, r0, #0x4000 @ dtcm top |
| 65 | + |
| 66 | + sub r0, r0, #4 @ irq vector |
| 67 | + mov r1, #0 |
| 68 | + str r1, [r0] |
| 69 | + sub r0, r0, #4 @ IRQ1 Check Bits |
| 70 | + str r1, [r0] |
| 71 | + |
| 72 | + sub r0, r0, #128 |
| 73 | + bic r0, r0, #7 |
| 74 | + |
| 75 | + msr cpsr_c, #0xd3 @ svc mode |
| 76 | + mov sp, r0 |
| 77 | + sub r0, r0, #128 |
| 78 | + msr cpsr_c, #0xd2 @ irq mode |
| 79 | + mov sp, r0 |
| 80 | + sub r0, r0, #128 |
| 81 | + msr cpsr_c, #0xdf @ system mode |
| 82 | + mov sp, r0 |
| 83 | + |
| 84 | + @ enable cache & tcm |
| 85 | + mrc p15, 0, r0, c1, c0, 0 |
| 86 | + ldr r1,= ITCM_ENABLE | DTCM_ENABLE | ICACHE_ENABLE | DCACHE_ENABLE |
| 87 | + orr r0,r0,r1 |
| 88 | + mcr p15, 0, r0, c1, c0, 0 |
| 89 | + |
| 90 | + ldr r10, =0x2FFFE04 |
| 91 | + ldr r0, =0xE59FF018 |
| 92 | + str r0, [r10] |
| 93 | + add r1, r10, #0x20 |
| 94 | + str r10, [r1] |
| 95 | + bx r10 |
| 96 | + |
| 97 | + .pool |
| 98 | + |
| 99 | +mpu_initial_data: |
| 100 | + .word 0x00000042 @ p15,0,c2,c0,0..1,r0 ;PU Cachability Bits for Data/Unified+Instruction Protection Region |
| 101 | + .word 0x00000002 @ p15,0,c3,c0,0,r1 ;PU Write-Bufferability Bits for Data Protection Regions |
| 102 | + .word 0x15111011 @ p15,0,c5,c0,2,r2 ;PU Extended Access Permission Data/Unified Protection Region |
| 103 | + .word 0x05100011 @ p15,0,c5,c0,3,r3 ;PU Extended Access Permission Instruction Protection Region |
| 104 | + .word 0x04000033 @ p15,0,c6,c0,0,r4 ;PU Protection Unit Data/Unified Region 0 |
| 105 | + .word 0x0200002b @ p15,0,c6,c1,0,r5 ;PU Protection Unit Data/Unified Region 1 4MB |
| 106 | + .word 0x08000035 @ p15,0,c6,c3,0,r6 ;PU Protection Unit Data/Unified Region 3 |
| 107 | + .word 0x0300001b @ p15,0,c6,c4,0,r7 ;PU Protection Unit Data/Unified Region 4 |
| 108 | + .word 0xffff001d @ p15,0,c6,c6,0,r8 ;PU Protection Unit Data/Unified Region 6 |
| 109 | + .word 0x02fff017 @ p15,0,c6,c7,0,r9 ;PU Protection Unit Data/Unified Region 7 4KB |
| 110 | + .word 0x0300000a @ p15,0,c9,c1,0,r10 ;TCM Data TCM Base and Virtual Size |
0 commit comments