nds_test2

annotate src/startup/mpu_setup.S @ 0:abcaf667f2bd

initial commit (3d + 2d)
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 28 Jan 2018 20:05:26 +0200
parents
children
rev   line source
nuclear@0 1 @ vi:set filetype=armasm:
nuclear@0 2 #define PAGE_4K (0b01011 << 1)
nuclear@0 3 #define PAGE_8K (0b01100 << 1)
nuclear@0 4 #define PAGE_16K (0b01101 << 1)
nuclear@0 5 #define PAGE_32K (0b01110 << 1)
nuclear@0 6 #define PAGE_64K (0b01111 << 1)
nuclear@0 7 #define PAGE_128K (0b10000 << 1)
nuclear@0 8 #define PAGE_256K (0b10001 << 1)
nuclear@0 9 #define PAGE_512K (0b10010 << 1)
nuclear@0 10 #define PAGE_1M (0b10011 << 1)
nuclear@0 11 #define PAGE_2M (0b10100 << 1)
nuclear@0 12 #define PAGE_4M (0b10101 << 1)
nuclear@0 13 #define PAGE_8M (0b10110 << 1)
nuclear@0 14 #define PAGE_16M (0b10111 << 1)
nuclear@0 15 #define PAGE_32M (0b11000 << 1)
nuclear@0 16 #define PAGE_64M (0b11001 << 1)
nuclear@0 17 #define PAGE_128M (0b11010 << 1)
nuclear@0 18 #define PAGE_256M (0b11011 << 1)
nuclear@0 19 #define PAGE_512M (0b11100 << 1)
nuclear@0 20 #define PAGE_1G (0b11101 << 1)
nuclear@0 21 #define PAGE_2G (0b11110 << 1)
nuclear@0 22 #define PAGE_4G (0b11111 << 1)
nuclear@0 23
nuclear@0 24 #define ITCM_LOAD (1<<19)
nuclear@0 25 #define ITCM_ENABLE (1<<18)
nuclear@0 26 #define DTCM_LOAD (1<<17)
nuclear@0 27 #define DTCM_ENABLE (1<<16)
nuclear@0 28 #define DISABLE_TBIT (1<<15)
nuclear@0 29 #define ROUND_ROBIN (1<<14)
nuclear@0 30 #define ALT_VECTORS (1<<13)
nuclear@0 31 #define ICACHE_ENABLE (1<<12)
nuclear@0 32 #define BIG_ENDIAN (1<<7)
nuclear@0 33 #define DCACHE_ENABLE (1<<2)
nuclear@0 34 #define PROTECT_ENABLE (1<<0)
nuclear@0 35
nuclear@0 36 .arch armv5te
nuclear@0 37 .cpu arm946e-s
nuclear@0 38
nuclear@0 39 .text
nuclear@0 40 .arm
nuclear@0 41
nuclear@0 42 .global mpu_setup
nuclear@0 43 .align 2
nuclear@0 44 mpu_setup:
nuclear@0 45 @ turn the power on for M3
nuclear@0 46 ldr r1, =0x8203
nuclear@0 47 mov r0, #0x04000000
nuclear@0 48 add r0, r0, #0x304
nuclear@0 49 strh r1, [r0]
nuclear@0 50
nuclear@0 51 ldr r1, =0x00002078 @ disable TCM and protection unit
nuclear@0 52 mcr p15, 0, r1, c1, c0
nuclear@0 53
nuclear@0 54 @ Protection Unit Setup added by Sasq
nuclear@0 55 @ Disable cache
nuclear@0 56 mov r0, #0
nuclear@0 57 mcr p15, 0, r0, c7, c5, 0 @ Instruction cache
nuclear@0 58 mcr p15, 0, r0, c7, c6, 0 @ Data cache
nuclear@0 59
nuclear@0 60 @ Wait for write buffer to empty
nuclear@0 61 mcr p15, 0, r0, c7, c10, 4
nuclear@0 62
nuclear@0 63 ldr r0, =__dtcm_start
nuclear@0 64 orr r0,r0,#0x0a
nuclear@0 65 mcr p15, 0, r0, c9, c1,0 @ DTCM base = __dtcm_start, size = 16 KB
nuclear@0 66
nuclear@0 67 mov r0,#0x20
nuclear@0 68 mcr p15, 0, r0, c9, c1,1 @ ITCM base = 0 , size = 32 MB
nuclear@0 69
nuclear@0 70 @ Setup memory regions similar to Release Version
nuclear@0 71 @ Region 0 - IO registers
nuclear@0 72 ldr r0,=( PAGE_64M | 0x04000000 | 1)
nuclear@0 73 mcr p15, 0, r0, c6, c0, 0
nuclear@0 74
nuclear@0 75 @ Region 1 - System ROM
nuclear@0 76 ldr r0,=( PAGE_64K | 0xFFFF0000 | 1)
nuclear@0 77 mcr p15, 0, r0, c6, c1, 0
nuclear@0 78
nuclear@0 79 @ Region 2 - alternate vector base
nuclear@0 80 ldr r0,=( PAGE_4K | 0x00000000 | 1)
nuclear@0 81 mcr p15, 0, r0, c6, c2, 0
nuclear@0 82
nuclear@0 83 @ Region 5 - DTCM
nuclear@0 84 ldr r0,=__dtcm_start
nuclear@0 85 orr r0,r0,#(PAGE_16K | 1)
nuclear@0 86 mcr p15, 0, r0, c6, c5, 0
nuclear@0 87
nuclear@0 88 @ Region 4 - ITCM
nuclear@0 89 ldr r0,=__itcm_start
nuclear@0 90
nuclear@0 91 @ align to 32k boundary
nuclear@0 92 mov r0,r0,lsr #15
nuclear@0 93 mov r0,r0,lsl #15
nuclear@0 94
nuclear@0 95 orr r0,r0,#(PAGE_32K | 1)
nuclear@0 96 mcr p15, 0, r0, c6, c4, 0
nuclear@0 97
nuclear@0 98 ldr r0,=0x4004008
nuclear@0 99 ldr r0,[r0]
nuclear@0 100 tst r0,#0x8000
nuclear@0 101 bne dsi_mode
nuclear@0 102
nuclear@0 103 swi 0xf0000
nuclear@0 104
nuclear@0 105 ldr r1,=( PAGE_128M | 0x08000000 | 1)
nuclear@0 106 cmp r0,#0
nuclear@0 107 bne debug_mode
nuclear@0 108
nuclear@0 109 ldr r3,=( PAGE_4M | 0x02000000 | 1)
nuclear@0 110 ldr r2,=( PAGE_16M | 0x02000000 | 1)
nuclear@0 111 mov r8,#0x02400000
nuclear@0 112
nuclear@0 113 ldr r9,=dsmasks
nuclear@0 114 b setregions
nuclear@0 115
nuclear@0 116 debug_mode:
nuclear@0 117 ldr r3,=( PAGE_8M | 0x02000000 | 1)
nuclear@0 118 ldr r2,=( PAGE_8M | 0x02800000 | 1)
nuclear@0 119 mov r8,#0x02800000
nuclear@0 120 ldr r9,=debugmasks
nuclear@0 121 b setregions
nuclear@0 122
nuclear@0 123 dsi_mode:
nuclear@0 124 tst r0,#0x4000
nuclear@0 125 ldr r1,=( PAGE_8M | 0x03000000 | 1)
nuclear@0 126 ldr r3,=( PAGE_16M | 0x02000000 | 1)
nuclear@0 127 ldreq r2,=( PAGE_16M | 0x0C000000 | 1)
nuclear@0 128 ldrne r2,=( PAGE_32M | 0x0C000000 | 1) @ DSi debugger extended iwram
nuclear@0 129 mov r8,#0x03000000
nuclear@0 130 ldr r9,=dsimasks
nuclear@0 131
nuclear@0 132 setregions:
nuclear@0 133 @ Region 3 - DS Accessory (GBA Cart) / DSi switchable iwram
nuclear@0 134 mcr p15, 0, r1, c6, c3, 0
nuclear@0 135
nuclear@0 136 @ Region 6 - non cacheable main ram
nuclear@0 137 mcr p15, 0, r2, c6, c6, 0
nuclear@0 138
nuclear@0 139 @ Region 7 - cacheable main ram
nuclear@0 140 mcr p15, 0, r3, c6, c7, 0
nuclear@0 141
nuclear@0 142
nuclear@0 143 @ Write buffer enable
nuclear@0 144 ldr r0,=0b10000000
nuclear@0 145 mcr p15, 0, r0, c3, c0, 0
nuclear@0 146
nuclear@0 147 @ DCache & ICache enable
nuclear@0 148 ldr r0,=0b10000010
nuclear@0 149 mcr p15, 0, r0, c2, c0, 0
nuclear@0 150 mcr p15, 0, r0, c2, c0, 1
nuclear@0 151
nuclear@0 152 @ IAccess
nuclear@0 153 ldr r0,=0x33333363
nuclear@0 154 mcr p15, 0, r0, c5, c0, 3
nuclear@0 155
nuclear@0 156 @ DAccess
nuclear@0 157 mcr p15, 0, r0, c5, c0, 2
nuclear@0 158
nuclear@0 159 @ Enable ICache, DCache, ITCM & DTCM
nuclear@0 160 mrc p15, 0, r0, c1, c0, 0
nuclear@0 161 ldr r1,= ITCM_ENABLE | DTCM_ENABLE | ICACHE_ENABLE | DCACHE_ENABLE | PROTECT_ENABLE
nuclear@0 162 orr r0,r0,r1
nuclear@0 163 mcr p15, 0, r0, c1, c0, 0
nuclear@0 164
nuclear@0 165 ldr r0,=masks
nuclear@0 166 str r9,[r0]
nuclear@0 167
nuclear@0 168 bx lr
nuclear@0 169
nuclear@0 170 .global memCached
nuclear@0 171 .align 2
nuclear@0 172 memCached:
nuclear@0 173 ldr r1,=masks
nuclear@0 174 ldr r1, [r1]
nuclear@0 175 ldr r2,[r1],#4
nuclear@0 176 and r0,r0,r2
nuclear@0 177 ldr r2,[r1]
nuclear@0 178 orr r0,r0,r2
nuclear@0 179 bx lr
nuclear@0 180
nuclear@0 181 .global memUncached
nuclear@0 182 .align 2
nuclear@0 183 memUncached:
nuclear@0 184 ldr r1,=masks
nuclear@0 185 ldr r1, [r1]
nuclear@0 186 ldr r2,[r1],#8
nuclear@0 187 and r0,r0,r2
nuclear@0 188 ldr r2,[r1]
nuclear@0 189 orr r0,r0,r2
nuclear@0 190 bx lr
nuclear@0 191
nuclear@0 192 .data
nuclear@0 193 .align 2
nuclear@0 194
nuclear@0 195 dsmasks:
nuclear@0 196 .word 0x003fffff, 0x02000000, 0x02c00000
nuclear@0 197 debugmasks:
nuclear@0 198 .word 0x007fffff, 0x02000000, 0x02800000
nuclear@0 199 dsimasks:
nuclear@0 200 .word 0x00ffffff, 0x02000000, 0x0c000000
nuclear@0 201
nuclear@0 202 masks: .word dsmasks
nuclear@0 203