head_64.S 9.2 KB

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