arm1176_mmu.gcc.s 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. @*******************************************************************************
  2. @*******************************************************************************
  3. @**
  4. @** Filename...: src/arm1176_mmu.gcc.s
  5. @** Source.....: src/arm1176_mmu.s
  6. @** Generator..: asm2gas.pl
  7. @** Note.......: DO NOT MODIFY THIS FILE BY HAND!
  8. @**
  9. @*******************************************************************************
  10. @*******************************************************************************
  11. @*******************************************************************************
  12. @*******************************************************************************
  13. @**
  14. @** ARM1176 Startup, MMU initialization and data cache setup
  15. @**
  16. @** This module initialized the MMU in flat memory mode, all addresses are
  17. @** directly mapped, vitual addresses are equal to physical addresses. The
  18. @** MMU is required only to enable the cache mode of dedicated memory
  19. @** regions.
  20. @**
  21. @** Version: $Id: arm1176_mmu.gcc.s 9143 2012-04-25 09:33:55Z jrende $
  22. @**
  23. @** (C) Copyright 2012-2013 by Goke Microelectronics Shanghai Branch**
  24. @*******************************************************************************
  25. @*******************************************************************************
  26. .text
  27. .section ".ARM1176INIT"
  28. .align 8
  29. .extern _start
  30. .extern _end_readonly
  31. .extern |_start|
  32. .extern |ARM1176_MMU_ttb0|
  33. .extern |ARM1176_MMU_ttb1|
  34. .equ ARM1176_PHYSICAL_TTB0_BASE, arm1176_mmu_ttb0
  35. .equ ARM1176_PHYSICAL_TTB1_BASE, arm1176_mmu_ttb1
  36. .equ ARM1176_TTB_ENTRIES, 4096
  37. .if CPU_USE_GK710XS==1
  38. .equ ARM1176_PHYSICAL_PERI_BASE, 0x90000000
  39. .else
  40. .equ ARM1176_PHYSICAL_PERI_BASE, 0x60000000
  41. .endif
  42. .equ ARM1176_PHYSICAL_PERI_SIZE, 0x20000000
  43. .equ ARM1176_REMAPPED_PERI_BASE, ARM1176_PHYSICAL_PERI_BASE
  44. .equ ARM1176_PHYSICAL_PPM_BASE, DDR_MEMORY_PPM_BASE
  45. .equ ARM1176_PHYSICAL_PPM_SIZE, DDR_MEMORY_PPM_SIZE
  46. .equ ARM1176_REMAPPED_PPM_BASE, ARM1176_PHYSICAL_PPM_BASE
  47. .equ ARM1176_PHYSICAL_RTOS_BASE, DDR_MEMORY_OS_BASE
  48. .equ ARM1176_PHYSICAL_RTOS_SIZE, DDR_MEMORY_OS_SIZE
  49. .equ ARM1176_REMAPPED_RTOS_BASE, ARM1176_PHYSICAL_RTOS_BASE
  50. @ use mmu map bsb address from 0xCxxxxxxx(DDR_MEMORY_BSB_BASE) to 0xD0000000|DDR_MEMORY_BSB_BASE
  51. .equ ARM1176_PHYSICAL_BSB_REAMP_BASE, 0xD0000000
  52. .equ ARM1176_PHYSICAL_BSB_BASE, DDR_MEMORY_BSB_BASE
  53. .equ ARM1176_PHYSICAL_BSB_SIZE, DDR_MEMORY_BSB_SIZE
  54. .equ ARM1176_REMAPPED_BSB_BASE, ARM1176_PHYSICAL_BSB_BASE|ARM1176_PHYSICAL_BSB_REAMP_BASE
  55. @ use mmu remap bsb address 0xCxxxxxxx(DDR_MEMORY_BSB_BASE) to ARM1176_REMAPPED_BSB_BASE+DDR_MEMORY_BSB_SIZE, it resolve bsb data revert.
  56. .equ ARM1176_PHYSICAL_BSB_BASE, DDR_MEMORY_BSB_BASE
  57. .equ ARM1176_PHYSICAL_BSB_SIZE, DDR_MEMORY_BSB_SIZE
  58. .equ ARM1176_REMAPPED_BSB_BASE_EXT, ARM1176_REMAPPED_BSB_BASE+DDR_MEMORY_BSB_SIZE
  59. .equ ARM1176_PHYSICAL_DSP_BASE, DDR_MEMORY_DSP_BASE
  60. .equ ARM1176_PHYSICAL_DSP_SIZE, DDR_MEMORY_DSP_SIZE
  61. .equ ARM1176_REMAPPED_DSP_BASE, ARM1176_PHYSICAL_DSP_BASE
  62. .equ ARM1176_1MB_CACHE_NOBUFFER, 0x00000DEA @ cachable/non-bufferable
  63. .equ ARM1176_1MB_CACHE_BUFFER, 0x00000DEE @ cachable/bufferable
  64. .equ ARM1176_1MB_NOCACHE_NOBUFFER, 0x00000DE2 @ non-cachable/non-bufferable
  65. .equ ARM1176_1MB_NORMAL_NOCACHE, 0x00001DE2 @ Normal memory, non-cachable/non-bufferable
  66. .equ ARM1176_1MB_CACHE_BUFFER_RO, 0x000011EE @ cachable/bufferable read-only
  67. .equ ARM1176_1MB_NOCACHE_NOBUFFER_RO, 0x000011E2 @ non-cachable/non-bufferable read-only
  68. @*******************************************************************************
  69. @** Initialise the MMU
  70. @*******************************************************************************
  71. .global ARM1176_MmuInitialise
  72. ARM1176_MmuInitialise:
  73. @*******************************************************************************
  74. @** save link register on r11 as we are using bl commands internally
  75. @*******************************************************************************
  76. mov r11,lr
  77. @*******************************************************************************
  78. @** if MMU/MPU enabled - disable (useful for ARMulator tests)
  79. @*******************************************************************************
  80. mrc p15,0,r0,c1,c0,0 @ read CP15 register 1 into r0
  81. bic r0,r0,#0x1000 @ disable I-cache
  82. bic r0,r0,#0x0004 @ disable D-cache
  83. bic r0,r0,#0x0001 @ disable MMU
  84. mcr p15,0,r0,c1,c0,0 @ write value back
  85. @*******************************************************************************
  86. @** MMU Configuration
  87. @**
  88. @** Configure system to use extended v6 format pagetables
  89. @** Set translation table base
  90. @** Specify v6 format pagetables with no subpages
  91. @** set bit 23 [XP] in CP15 control register.
  92. @** ARM1176 supports two translation tables
  93. @** Configure translation table base (TTB) control register cp15,c2
  94. @** to a value of all zeros, indicates we are using TTB register 0.
  95. @*******************************************************************************
  96. mrc p15,0,r0,c1,c0,0 @ read CP15 register 1 into r0
  97. mov r1,#0x800000
  98. orr r0,r0,r1 @ disable Subpage AP bits
  99. mcr p15,0,r0,c1,c0,0 @ write value back
  100. mov r0,#0x0
  101. mcr p15,0,r0,c2,c0,2 @ Write Translation Table Base Control Register to 0, use Register 0
  102. ldr r0,ARM1176_PHYSICAL_TTB0_BASE
  103. mcr p15,0,r0,c2,c0,0 @ Write Translation Table Base Register 0 to ARM1176_PHYSICAL_TTB0_BASE
  104. @*******************************************************************************
  105. @** PAGE TABLE generation
  106. @**
  107. @** Generate the page tables
  108. @** Build a flat translation table for the whole address space.
  109. @** ie: Create 4096 1MB sections from 0x000xxxxx to 0xFFFxxxxx
  110. @**
  111. @** |31................20|19..18|17|16| 15|14..12|11.10|9|8....5| 4|3.2|1.0|
  112. @** |section base address| 0 0|nG| S|APX| TEX| AP |P|Domain|XN|C B|1 0|
  113. @**
  114. @** Bits[31:20] Top 12 bits of VA is pointer into table
  115. @** nG[17]=0. Non global, enables matching against ASID in the TLB when set.
  116. @** S[16]=0. Indicates normal memory is shared when set.
  117. @** Access Permissions - configure for full read/write access in all modes
  118. @** APX[15]=0 and AP[11:10]=11
  119. @**
  120. @** Set attributes to normal memory, non cacheable.
  121. @** TEX[14:12]=001 and CB[3:2]= 00
  122. @** P[9]=0. ECC enabled memory (not supported on ARM1136).
  123. @** Domain[5:8]=1111 = Set all pages to use domain 15
  124. @** XN[4]:=0 Execute never disabled.
  125. @** Bits[1:0] Indicate entry is a 1MB section.
  126. @**
  127. @** r0 contains the address of the translation table base
  128. @** r1 is loop counter
  129. @** r2 is level1 descriptor (bits 19:0)
  130. @**
  131. @** use loop counter to create 4096 individual table entries
  132. @** this writes from address 0x7FFC down to 0x4000 in word steps (4bytes).
  133. @**
  134. @** In this example we will set the cacheable attribute in the first descriptor
  135. @** only, so virtual memory from 0 to 1MB will be cacheable (write back mode).
  136. @** TEX[14:12]=000 and CB[3:2]=11
  137. @*******************************************************************************
  138. @*******************************************************************************
  139. @** create empty TTB entries to initialize entries 0..2047
  140. @** r0 = TTB base address
  141. @** r1 = unused
  142. @** r2 = unused
  143. @** r3 = virtual DDR address, upper 12 bits shifted 20 bits right (virt. index)
  144. @** r4 = remap size upper 12 bits shifted 20 bits right (table max. index)
  145. @** r5 = unused
  146. @*******************************************************************************
  147. ldr r0,ARM1176_PHYSICAL_TTB0_BASE @ set the MMU table base address
  148. ldr r1,=0x00000000 @ 0x00000000 == disable access
  149. ldr r2,=0x00000000 @ remap addresses from 0x00000000..
  150. ldr r3,=0x00000000 @ to 0x00000000..
  151. ldr r4,=0x80000000 @ fixed remap RAM size (2048MB)
  152. bl arm1176_update_mmu_table @ update mmu table entries
  153. @*******************************************************************************
  154. @** set the peri
  155. @*******************************************************************************
  156. ldr r0,ARM1176_PHYSICAL_TTB0_BASE
  157. ldr r1,=ARM1176_1MB_NOCACHE_NOBUFFER
  158. ldr r2,=ARM1176_PHYSICAL_PERI_BASE
  159. ldr r3,=ARM1176_REMAPPED_PERI_BASE
  160. ldr r4,=ARM1176_PHYSICAL_PERI_SIZE
  161. bl arm1176_update_mmu_table
  162. @*******************************************************************************
  163. @** set the ppm
  164. @*******************************************************************************
  165. ldr r0,ARM1176_PHYSICAL_TTB0_BASE
  166. ldr r1,=ARM1176_1MB_NOCACHE_NOBUFFER
  167. ldr r2,=ARM1176_PHYSICAL_PPM_BASE
  168. ldr r3,=ARM1176_REMAPPED_PPM_BASE
  169. ldr r4,=ARM1176_PHYSICAL_PPM_SIZE
  170. bl arm1176_update_mmu_table
  171. @*******************************************************************************
  172. @** set the rtos (nocache_section(1M)/code_heap(RTOSSIZE-1M))
  173. @*******************************************************************************
  174. ldr r0,ARM1176_PHYSICAL_TTB0_BASE
  175. ldr r1,=ARM1176_1MB_NOCACHE_NOBUFFER
  176. ldr r2,=ARM1176_PHYSICAL_RTOS_BASE
  177. ldr r3,=ARM1176_REMAPPED_RTOS_BASE
  178. ldr r4,=0x200000
  179. bl arm1176_update_mmu_table
  180. ldr r0,ARM1176_PHYSICAL_TTB0_BASE
  181. ldr r1,=ARM1176_1MB_CACHE_BUFFER
  182. ldr r2,=ARM1176_PHYSICAL_RTOS_BASE+0x100000
  183. ldr r3,=ARM1176_REMAPPED_RTOS_BASE+0x100000
  184. ldr r4,=ARM1176_PHYSICAL_RTOS_SIZE-0x100000
  185. bl arm1176_update_mmu_table
  186. @*******************************************************************************
  187. @** set the bsb
  188. @*******************************************************************************
  189. ldr r0,ARM1176_PHYSICAL_TTB0_BASE
  190. ldr r1,=ARM1176_1MB_CACHE_BUFFER
  191. ldr r2,=ARM1176_PHYSICAL_BSB_BASE
  192. ldr r3,=ARM1176_REMAPPED_BSB_BASE
  193. ldr r4,=ARM1176_PHYSICAL_BSB_SIZE
  194. bl arm1176_update_mmu_table
  195. @*******************************************************************************
  196. @** set the bsb again for continues address for frame address
  197. @*******************************************************************************
  198. ldr r0,ARM1176_PHYSICAL_TTB0_BASE
  199. ldr r1,=ARM1176_1MB_CACHE_BUFFER
  200. ldr r2,=ARM1176_PHYSICAL_BSB_BASE
  201. ldr r3,=ARM1176_REMAPPED_BSB_BASE_EXT
  202. ldr r4,=ARM1176_PHYSICAL_BSB_SIZE
  203. bl arm1176_update_mmu_table
  204. @*******************************************************************************
  205. @** set the dsp
  206. @*******************************************************************************
  207. ldr r0,ARM1176_PHYSICAL_TTB0_BASE
  208. ldr r1,=ARM1176_1MB_CACHE_BUFFER
  209. ldr r2,=ARM1176_PHYSICAL_DSP_BASE
  210. ldr r3,=ARM1176_REMAPPED_DSP_BASE
  211. ldr r4,=ARM1176_PHYSICAL_DSP_SIZE
  212. bl arm1176_update_mmu_table
  213. @*******************************************************************************
  214. @** copy TTB0 into TTB1
  215. @*******************************************************************************
  216. ldr r0,ARM1176_PHYSICAL_TTB0_BASE
  217. ldr r1,ARM1176_PHYSICAL_TTB1_BASE
  218. ldr r2,=ARM1176_TTB_ENTRIES
  219. bl arm1176_copy_mmu_table
  220. @*******************************************************************************
  221. @** Setup domain control register
  222. @** Enable all domains to client mode
  223. @*******************************************************************************
  224. mrc p15,0,r0,c3,c0,0 @ Read Domain Access Control Register
  225. ldr r0,=0x55555555 @ Initialise every domain entry to b01 (client)
  226. mcr p15,0,r0,c3,c0,0 @ Write Domain Access Control Register
  227. @*******************************************************************************
  228. @** Now the MMU is enabled, virtual to physical address translations will occur.
  229. @** This will affect the next instruction fetch.
  230. @**
  231. @** The two instructions currently in the ARM pipeline will have been fetched
  232. @** before the MMU was enabled. This property is useful because the next two
  233. @** instructions are safe even if new instruction fetches fail - If this
  234. @** routine was mapped out of the new virtual memory map, the branch to
  235. @** arm1176_BootLoaderMain would still succeed.
  236. @*******************************************************************************
  237. mov r0,#0 @ move 0 into r0
  238. mcr p15,0,r0,c7,c5,0 @ invalidate instruction cache
  239. mcr p15,0,r0,c7,c6,0 @ invalidate data cache
  240. mcr p15,0,r0,c7,c10,4 @ drain write barrier
  241. mcr p15,0,r0,c8,c5,0 @ reset intruction TLB entries
  242. mcr p15,0,r0,c8,c6,0 @ reset data TLB entries
  243. mcr p15,0,r0,c8,c7,0 @ reset unified TLB entries
  244. mrc p15,0,r0,c1,c0,0 @ read CP15 register c1 into r0
  245. orr r0,r0,#0x00001000 @ enable I-cache
  246. orr r0,r0,#0x00000004 @ enable D-cache
  247. orr r0,r0,#0x00000001 @ enable MMU
  248. orr r0,r0,#0x00400000 @ enable unaligned load/store
  249. orr r0,r0,#0x00000100 @ system bit enabled
  250. bic r0,r0,#0x00000200 @ rom bit disabled
  251. mcr p15,0,r0,c1,c0,0 @ write r0 back to CP15 register c1
  252. mov lr,r11 @ restore link register
  253. bx lr @ branch back to caller
  254. @*******************************************************************************
  255. @** create TTB entries to remap 1MB junks of memory
  256. @** register arguments:
  257. @** r0 = TTB base address
  258. @** r1 = access mask, lower 20 bits only
  259. @** r2 = physical address, upper 12 bits shifted 20 bits right (phys. index)
  260. @** r3 = virtual address, upper 12 bits shifted 20 bits right (virt. index)
  261. @** r4 = remap size upper 12 bits shifted 20 bits right (table max. index)
  262. @** internal used registers:
  263. @** r5 = temporary vector to be written into TTB entry
  264. @*******************************************************************************
  265. arm1176_update_mmu_table:
  266. lsr r2,r2,#20 @ 1M
  267. lsr r3,r3,#20 @ 1M
  268. lsr r4,r4,#20 @ 1M
  269. cmp r4,#0x0
  270. bxeq lr
  271. add r4,r4,r3
  272. arm1176_update_mmu_table_loop: @ update r4 times 1MB entries
  273. orr r5,r1,r2,LSL#20 @ r5 now contains full L1 descriptor to write
  274. str r5,[r0,r3,LSL#2] @ store table entry at TTB base + loopcount*4
  275. add r3,r3,#1 @ increment virtual address index
  276. add r2,r2,#1 @ increment physical address index
  277. cmp r3,r4 @ check for last entry
  278. bne arm1176_update_mmu_table_loop
  279. bx lr
  280. @*******************************************************************************
  281. @** copy one TTB into another
  282. @** register arguments:
  283. @** r0 = address of 1st TTB
  284. @** r1 = address of 2nd TTB
  285. @** r2 = table entry count
  286. @** internal used registers:
  287. @** r3 = temporary register holding read/wrrite values
  288. @*******************************************************************************
  289. arm1176_copy_mmu_table:
  290. cmp r2,#0x0
  291. bxeq lr
  292. arm1176_copy_mmu_table_loop: @ load entry from 1st table
  293. ldr r3,[r0] @ store entry into 2nd table
  294. str r3,[r1] @ store table entry at TTB base + loopcount*4
  295. add r0,r0,#4 @ increment 1st table address by 4 byte
  296. add r1,r1,#4 @ increment 2nd table address by 4 byte
  297. sub r2,r2,#1 @ decrement entry counter by 1
  298. cmp r2,#0x0
  299. bne arm1176_copy_mmu_table_loop
  300. bx lr
  301. @*******************************************************************************
  302. @** local variables containing far addresses
  303. @*******************************************************************************
  304. .ltorg
  305. arm1176_image_ro_base:
  306. .long _start
  307. arm1176_image_ro_limit:
  308. .long _end_readonly
  309. arm1176_image_start:
  310. .long _start
  311. arm1176_mmu_ttb0:
  312. .long ARM1176_MMU_ttb0
  313. arm1176_mmu_ttb1:
  314. .long ARM1176_MMU_ttb1
  315. arm1176_mmu_video_cached_ptr:
  316. .long arm1176_mmu_video_cached
  317. arm1176_mmu_video_cached:
  318. .long 0x0
  319. .global arm1176_mmu_video_cached
  320. .weak arm1176_mmu_video_cached
  321. @*******************************************************************************
  322. @** End of file
  323. @*******************************************************************************
  324. .end