head_64.S 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. * arch/sh/kernel/head_64.S
  3. *
  4. * Copyright (C) 2000, 2001 Paolo Alberelli
  5. * Copyright (C) 2003, 2004 Paul Mundt
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <asm/page.h>
  12. #include <asm/cache.h>
  13. #include <asm/tlb.h>
  14. #include <cpu/registers.h>
  15. #include <cpu/mmu_context.h>
  16. #include <asm/thread_info.h>
  17. /*
  18. * MMU defines: TLB boundaries.
  19. */
  20. #define MMUIR_FIRST ITLB_FIXED
  21. #define MMUIR_END ITLB_LAST_VAR_UNRESTRICTED+TLB_STEP
  22. #define MMUIR_STEP TLB_STEP
  23. #define MMUDR_FIRST DTLB_FIXED
  24. #define MMUDR_END DTLB_LAST_VAR_UNRESTRICTED+TLB_STEP
  25. #define MMUDR_STEP TLB_STEP
  26. /* Safety check : CONFIG_PAGE_OFFSET has to be a multiple of 512Mb */
  27. #if (CONFIG_PAGE_OFFSET & ((1UL<<29)-1))
  28. #error "CONFIG_PAGE_OFFSET must be a multiple of 512Mb"
  29. #endif
  30. /*
  31. * MMU defines: Fixed TLBs.
  32. */
  33. /* Deal safely with the case where the base of RAM is not 512Mb aligned */
  34. #define ALIGN_512M_MASK (0xffffffffe0000000)
  35. #define ALIGNED_EFFECTIVE ((CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START) & ALIGN_512M_MASK)
  36. #define ALIGNED_PHYSICAL (CONFIG_MEMORY_START & ALIGN_512M_MASK)
  37. #define MMUIR_TEXT_H (0x0000000000000003 | ALIGNED_EFFECTIVE)
  38. /* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
  39. #define MMUIR_TEXT_L (0x000000000000009a | ALIGNED_PHYSICAL)
  40. /* 512 Mb, Cacheable, Write-back, execute, Not User, Ph. Add. */
  41. #define MMUDR_CACHED_H 0x0000000000000003 | ALIGNED_EFFECTIVE
  42. /* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
  43. #define MMUDR_CACHED_L 0x000000000000015a | ALIGNED_PHYSICAL
  44. /* 512 Mb, Cacheable, Write-back, read/write, Not User, Ph. Add. */
  45. #ifdef CONFIG_CACHE_OFF
  46. #define ICCR0_INIT_VAL ICCR0_OFF /* ICACHE off */
  47. #else
  48. #define ICCR0_INIT_VAL ICCR0_ON | ICCR0_ICI /* ICE + ICI */
  49. #endif
  50. #define ICCR1_INIT_VAL ICCR1_NOLOCK /* No locking */
  51. #if defined (CONFIG_CACHE_OFF)
  52. #define OCCR0_INIT_VAL OCCR0_OFF /* D-cache: off */
  53. #elif defined (CONFIG_CACHE_WRITETHROUGH)
  54. #define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WT /* D-cache: on, */
  55. /* WT, invalidate */
  56. #elif defined (CONFIG_CACHE_WRITEBACK)
  57. #define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WB /* D-cache: on, */
  58. /* WB, invalidate */
  59. #else
  60. #error preprocessor flag CONFIG_CACHE_... not recognized!
  61. #endif
  62. #define OCCR1_INIT_VAL OCCR1_NOLOCK /* No locking */
  63. .section .empty_zero_page, "aw"
  64. .global empty_zero_page
  65. empty_zero_page:
  66. .long 1 /* MOUNT_ROOT_RDONLY */
  67. .long 0 /* RAMDISK_FLAGS */
  68. .long 0x0200 /* ORIG_ROOT_DEV */
  69. .long 1 /* LOADER_TYPE */
  70. .long 0x00800000 /* INITRD_START */
  71. .long 0x00800000 /* INITRD_SIZE */
  72. .long 0
  73. .text
  74. .balign 4096,0,4096
  75. .section .data, "aw"
  76. .balign PAGE_SIZE
  77. .section .data, "aw"
  78. .balign PAGE_SIZE
  79. .global mmu_pdtp_cache
  80. mmu_pdtp_cache:
  81. .space PAGE_SIZE, 0
  82. .global empty_bad_page
  83. empty_bad_page:
  84. .space PAGE_SIZE, 0
  85. .global empty_bad_pte_table
  86. empty_bad_pte_table:
  87. .space PAGE_SIZE, 0
  88. .global fpu_in_use
  89. fpu_in_use: .quad 0
  90. .section .text.head, "ax"
  91. .balign L1_CACHE_BYTES
  92. /*
  93. * Condition at the entry of __stext:
  94. * . Reset state:
  95. * . SR.FD = 1 (FPU disabled)
  96. * . SR.BL = 1 (Exceptions disabled)
  97. * . SR.MD = 1 (Privileged Mode)
  98. * . SR.MMU = 0 (MMU Disabled)
  99. * . SR.CD = 0 (CTC User Visible)
  100. * . SR.IMASK = Undefined (Interrupt Mask)
  101. *
  102. * Operations supposed to be performed by __stext:
  103. * . prevent speculative fetch onto device memory while MMU is off
  104. * . reflect as much as possible SH5 ABI (r15, r26, r27, r18)
  105. * . first, save CPU state and set it to something harmless
  106. * . any CPU detection and/or endianness settings (?)
  107. * . initialize EMI/LMI (but not TMU/RTC/INTC/SCIF): TBD
  108. * . set initial TLB entries for cached and uncached regions
  109. * (no fine granularity paging)
  110. * . set initial cache state
  111. * . enable MMU and caches
  112. * . set CPU to a consistent state
  113. * . registers (including stack pointer and current/KCR0)
  114. * . NOT expecting to set Exception handling nor VBR/RESVEC/DCR
  115. * at this stage. This is all to later Linux initialization steps.
  116. * . initialize FPU
  117. * . clear BSS
  118. * . jump into start_kernel()
  119. * . be prepared to hopeless start_kernel() returns.
  120. *
  121. */
  122. .global _stext
  123. _stext:
  124. /*
  125. * Prevent speculative fetch on device memory due to
  126. * uninitialized target registers.
  127. */
  128. ptabs/u ZERO, tr0
  129. ptabs/u ZERO, tr1
  130. ptabs/u ZERO, tr2
  131. ptabs/u ZERO, tr3
  132. ptabs/u ZERO, tr4
  133. ptabs/u ZERO, tr5
  134. ptabs/u ZERO, tr6
  135. ptabs/u ZERO, tr7
  136. synci
  137. /*
  138. * Read/Set CPU state. After this block:
  139. * r29 = Initial SR
  140. */
  141. getcon SR, r29
  142. movi SR_HARMLESS, r20
  143. putcon r20, SR
  144. /*
  145. * Initialize EMI/LMI. To Be Done.
  146. */
  147. /*
  148. * CPU detection and/or endianness settings (?). To Be Done.
  149. * Pure PIC code here, please ! Just save state into r30.
  150. * After this block:
  151. * r30 = CPU type/Platform Endianness
  152. */
  153. /*
  154. * Set initial TLB entries for cached and uncached regions.
  155. * Note: PTA/BLINK is PIC code, PTABS/BLINK isn't !
  156. */
  157. /* Clear ITLBs */
  158. pta clear_ITLB, tr1
  159. movi MMUIR_FIRST, r21
  160. movi MMUIR_END, r22
  161. clear_ITLB:
  162. putcfg r21, 0, ZERO /* Clear MMUIR[n].PTEH.V */
  163. addi r21, MMUIR_STEP, r21
  164. bne r21, r22, tr1
  165. /* Clear DTLBs */
  166. pta clear_DTLB, tr1
  167. movi MMUDR_FIRST, r21
  168. movi MMUDR_END, r22
  169. clear_DTLB:
  170. putcfg r21, 0, ZERO /* Clear MMUDR[n].PTEH.V */
  171. addi r21, MMUDR_STEP, r21
  172. bne r21, r22, tr1
  173. /* Map one big (512Mb) page for ITLB */
  174. movi MMUIR_FIRST, r21
  175. movi MMUIR_TEXT_L, r22 /* PTEL first */
  176. add.l r22, r63, r22 /* Sign extend */
  177. putcfg r21, 1, r22 /* Set MMUIR[0].PTEL */
  178. movi MMUIR_TEXT_H, r22 /* PTEH last */
  179. add.l r22, r63, r22 /* Sign extend */
  180. putcfg r21, 0, r22 /* Set MMUIR[0].PTEH */
  181. /* Map one big CACHED (512Mb) page for DTLB */
  182. movi MMUDR_FIRST, r21
  183. movi MMUDR_CACHED_L, r22 /* PTEL first */
  184. add.l r22, r63, r22 /* Sign extend */
  185. putcfg r21, 1, r22 /* Set MMUDR[0].PTEL */
  186. movi MMUDR_CACHED_H, r22 /* PTEH last */
  187. add.l r22, r63, r22 /* Sign extend */
  188. putcfg r21, 0, r22 /* Set MMUDR[0].PTEH */
  189. #ifdef CONFIG_EARLY_PRINTK
  190. /*
  191. * Setup a DTLB translation for SCIF phys.
  192. */
  193. addi r21, MMUDR_STEP, r21
  194. movi 0x0a03, r22 /* SCIF phys */
  195. shori 0x0148, r22
  196. putcfg r21, 1, r22 /* PTEL first */
  197. movi 0xfa03, r22 /* 0xfa030000, fixed SCIF virt */
  198. shori 0x0003, r22
  199. putcfg r21, 0, r22 /* PTEH last */
  200. #endif
  201. /*
  202. * Set cache behaviours.
  203. */
  204. /* ICache */
  205. movi ICCR_BASE, r21
  206. movi ICCR0_INIT_VAL, r22
  207. movi ICCR1_INIT_VAL, r23
  208. putcfg r21, ICCR_REG0, r22
  209. putcfg r21, ICCR_REG1, r23
  210. /* OCache */
  211. movi OCCR_BASE, r21
  212. movi OCCR0_INIT_VAL, r22
  213. movi OCCR1_INIT_VAL, r23
  214. putcfg r21, OCCR_REG0, r22
  215. putcfg r21, OCCR_REG1, r23
  216. /*
  217. * Enable Caches and MMU. Do the first non-PIC jump.
  218. * Now head.S global variables, constants and externs
  219. * can be used.
  220. */
  221. getcon SR, r21
  222. movi SR_ENABLE_MMU, r22
  223. or r21, r22, r21
  224. putcon r21, SSR
  225. movi hyperspace, r22
  226. ori r22, 1, r22 /* Make it SHmedia, not required but..*/
  227. putcon r22, SPC
  228. synco
  229. rte /* And now go into the hyperspace ... */
  230. hyperspace: /* ... that's the next instruction ! */
  231. /*
  232. * Set CPU to a consistent state.
  233. * r31 = FPU support flag
  234. * tr0/tr7 in use. Others give a chance to loop somewhere safe
  235. */
  236. movi start_kernel, r32
  237. ori r32, 1, r32
  238. ptabs r32, tr0 /* r32 = _start_kernel address */
  239. pta/u hopeless, tr1
  240. pta/u hopeless, tr2
  241. pta/u hopeless, tr3
  242. pta/u hopeless, tr4
  243. pta/u hopeless, tr5
  244. pta/u hopeless, tr6
  245. pta/u hopeless, tr7
  246. gettr tr1, r28 /* r28 = hopeless address */
  247. /* Set initial stack pointer */
  248. movi init_thread_union, SP
  249. putcon SP, KCR0 /* Set current to init_task */
  250. movi THREAD_SIZE, r22 /* Point to the end */
  251. add SP, r22, SP
  252. /*
  253. * Initialize FPU.
  254. * Keep FPU flag in r31. After this block:
  255. * r31 = FPU flag
  256. */
  257. movi fpu_in_use, r31 /* Temporary */
  258. #ifdef CONFIG_SH_FPU
  259. getcon SR, r21
  260. movi SR_ENABLE_FPU, r22
  261. and r21, r22, r22
  262. putcon r22, SR /* Try to enable */
  263. getcon SR, r22
  264. xor r21, r22, r21
  265. shlri r21, 15, r21 /* Supposedly 0/1 */
  266. st.q r31, 0 , r21 /* Set fpu_in_use */
  267. #else
  268. movi 0, r21
  269. st.q r31, 0 , r21 /* Set fpu_in_use */
  270. #endif
  271. or r21, ZERO, r31 /* Set FPU flag at last */
  272. #ifndef CONFIG_SH_NO_BSS_INIT
  273. /* Don't clear BSS if running on slow platforms such as an RTL simulation,
  274. remote memory via SHdebug link, etc. For these the memory can be guaranteed
  275. to be all zero on boot anyway. */
  276. /*
  277. * Clear bss
  278. */
  279. pta clear_quad, tr1
  280. movi __bss_start, r22
  281. movi _end, r23
  282. clear_quad:
  283. st.q r22, 0, ZERO
  284. addi r22, 8, r22
  285. bne r22, r23, tr1 /* Both quad aligned, see vmlinux.lds.S */
  286. #endif
  287. pta/u hopeless, tr1
  288. /* Say bye to head.S but be prepared to wrongly get back ... */
  289. blink tr0, LINK
  290. /* If we ever get back here through LINK/tr1-tr7 */
  291. pta/u hopeless, tr7
  292. hopeless:
  293. /*
  294. * Something's badly wrong here. Loop endlessly,
  295. * there's nothing more we can do about it.
  296. *
  297. * Note on hopeless: it can be jumped into invariably
  298. * before or after jumping into hyperspace. The only
  299. * requirement is to be PIC called (PTA) before and
  300. * any way (PTA/PTABS) after. According to Virtual
  301. * to Physical mapping a simulator/emulator can easily
  302. * tell where we came here from just looking at hopeless
  303. * (PC) address.
  304. *
  305. * For debugging purposes:
  306. * (r28) hopeless/loop address
  307. * (r29) Original SR
  308. * (r30) CPU type/Platform endianness
  309. * (r31) FPU Support
  310. * (r32) _start_kernel address
  311. */
  312. blink tr7, ZERO