head_64.S 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 empty_bad_page
  84. empty_bad_page:
  85. .space PAGE_SIZE, 0
  86. .global empty_bad_pte_table
  87. empty_bad_pte_table:
  88. .space PAGE_SIZE, 0
  89. .global fpu_in_use
  90. fpu_in_use: .quad 0
  91. __HEAD
  92. .balign L1_CACHE_BYTES
  93. /*
  94. * Condition at the entry of __stext:
  95. * . Reset state:
  96. * . SR.FD = 1 (FPU disabled)
  97. * . SR.BL = 1 (Exceptions disabled)
  98. * . SR.MD = 1 (Privileged Mode)
  99. * . SR.MMU = 0 (MMU Disabled)
  100. * . SR.CD = 0 (CTC User Visible)
  101. * . SR.IMASK = Undefined (Interrupt Mask)
  102. *
  103. * Operations supposed to be performed by __stext:
  104. * . prevent speculative fetch onto device memory while MMU is off
  105. * . reflect as much as possible SH5 ABI (r15, r26, r27, r18)
  106. * . first, save CPU state and set it to something harmless
  107. * . any CPU detection and/or endianness settings (?)
  108. * . initialize EMI/LMI (but not TMU/RTC/INTC/SCIF): TBD
  109. * . set initial TLB entries for cached and uncached regions
  110. * (no fine granularity paging)
  111. * . set initial cache state
  112. * . enable MMU and caches
  113. * . set CPU to a consistent state
  114. * . registers (including stack pointer and current/KCR0)
  115. * . NOT expecting to set Exception handling nor VBR/RESVEC/DCR
  116. * at this stage. This is all to later Linux initialization steps.
  117. * . initialize FPU
  118. * . clear BSS
  119. * . jump into start_kernel()
  120. * . be prepared to hopeless start_kernel() returns.
  121. *
  122. */
  123. .global _stext
  124. _stext:
  125. /*
  126. * Prevent speculative fetch on device memory due to
  127. * uninitialized target registers.
  128. */
  129. ptabs/u ZERO, tr0
  130. ptabs/u ZERO, tr1
  131. ptabs/u ZERO, tr2
  132. ptabs/u ZERO, tr3
  133. ptabs/u ZERO, tr4
  134. ptabs/u ZERO, tr5
  135. ptabs/u ZERO, tr6
  136. ptabs/u ZERO, tr7
  137. synci
  138. /*
  139. * Read/Set CPU state. After this block:
  140. * r29 = Initial SR
  141. */
  142. getcon SR, r29
  143. movi SR_HARMLESS, r20
  144. putcon r20, SR
  145. /*
  146. * Initialize EMI/LMI. To Be Done.
  147. */
  148. /*
  149. * CPU detection and/or endianness settings (?). To Be Done.
  150. * Pure PIC code here, please ! Just save state into r30.
  151. * After this block:
  152. * r30 = CPU type/Platform Endianness
  153. */
  154. /*
  155. * Set initial TLB entries for cached and uncached regions.
  156. * Note: PTA/BLINK is PIC code, PTABS/BLINK isn't !
  157. */
  158. /* Clear ITLBs */
  159. pta clear_ITLB, tr1
  160. movi MMUIR_FIRST, r21
  161. movi MMUIR_END, r22
  162. clear_ITLB:
  163. putcfg r21, 0, ZERO /* Clear MMUIR[n].PTEH.V */
  164. addi r21, MMUIR_STEP, r21
  165. bne r21, r22, tr1
  166. /* Clear DTLBs */
  167. pta clear_DTLB, tr1
  168. movi MMUDR_FIRST, r21
  169. movi MMUDR_END, r22
  170. clear_DTLB:
  171. putcfg r21, 0, ZERO /* Clear MMUDR[n].PTEH.V */
  172. addi r21, MMUDR_STEP, r21
  173. bne r21, r22, tr1
  174. /* Map one big (512Mb) page for ITLB */
  175. movi MMUIR_FIRST, r21
  176. movi MMUIR_TEXT_L, r22 /* PTEL first */
  177. add.l r22, r63, r22 /* Sign extend */
  178. putcfg r21, 1, r22 /* Set MMUIR[0].PTEL */
  179. movi MMUIR_TEXT_H, r22 /* PTEH last */
  180. add.l r22, r63, r22 /* Sign extend */
  181. putcfg r21, 0, r22 /* Set MMUIR[0].PTEH */
  182. /* Map one big CACHED (512Mb) page for DTLB */
  183. movi MMUDR_FIRST, r21
  184. movi MMUDR_CACHED_L, r22 /* PTEL first */
  185. add.l r22, r63, r22 /* Sign extend */
  186. putcfg r21, 1, r22 /* Set MMUDR[0].PTEL */
  187. movi MMUDR_CACHED_H, r22 /* PTEH last */
  188. add.l r22, r63, r22 /* Sign extend */
  189. putcfg r21, 0, r22 /* Set MMUDR[0].PTEH */
  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. /*
  201. * Set cache behaviours.
  202. */
  203. /* ICache */
  204. movi ICCR_BASE, r21
  205. movi ICCR0_INIT_VAL, r22
  206. movi ICCR1_INIT_VAL, r23
  207. putcfg r21, ICCR_REG0, r22
  208. putcfg r21, ICCR_REG1, r23
  209. /* OCache */
  210. movi OCCR_BASE, r21
  211. movi OCCR0_INIT_VAL, r22
  212. movi OCCR1_INIT_VAL, r23
  213. putcfg r21, OCCR_REG0, r22
  214. putcfg r21, OCCR_REG1, r23
  215. /*
  216. * Enable Caches and MMU. Do the first non-PIC jump.
  217. * Now head.S global variables, constants and externs
  218. * can be used.
  219. */
  220. getcon SR, r21
  221. movi SR_ENABLE_MMU, r22
  222. or r21, r22, r21
  223. putcon r21, SSR
  224. movi hyperspace, r22
  225. ori r22, 1, r22 /* Make it SHmedia, not required but..*/
  226. putcon r22, SPC
  227. synco
  228. rte /* And now go into the hyperspace ... */
  229. hyperspace: /* ... that's the next instruction ! */
  230. /*
  231. * Set CPU to a consistent state.
  232. * r31 = FPU support flag
  233. * tr0/tr7 in use. Others give a chance to loop somewhere safe
  234. */
  235. movi start_kernel, r32
  236. ori r32, 1, r32
  237. ptabs r32, tr0 /* r32 = _start_kernel address */
  238. pta/u hopeless, tr1
  239. pta/u hopeless, tr2
  240. pta/u hopeless, tr3
  241. pta/u hopeless, tr4
  242. pta/u hopeless, tr5
  243. pta/u hopeless, tr6
  244. pta/u hopeless, tr7
  245. gettr tr1, r28 /* r28 = hopeless address */
  246. /* Set initial stack pointer */
  247. movi init_thread_union, SP
  248. putcon SP, KCR0 /* Set current to init_task */
  249. movi THREAD_SIZE, r22 /* Point to the end */
  250. add SP, r22, SP
  251. /*
  252. * Initialize FPU.
  253. * Keep FPU flag in r31. After this block:
  254. * r31 = FPU flag
  255. */
  256. movi fpu_in_use, r31 /* Temporary */
  257. #ifdef CONFIG_SH_FPU
  258. getcon SR, r21
  259. movi SR_ENABLE_FPU, r22
  260. and r21, r22, r22
  261. putcon r22, SR /* Try to enable */
  262. getcon SR, r22
  263. xor r21, r22, r21
  264. shlri r21, 15, r21 /* Supposedly 0/1 */
  265. st.q r31, 0 , r21 /* Set fpu_in_use */
  266. #else
  267. movi 0, r21
  268. st.q r31, 0 , r21 /* Set fpu_in_use */
  269. #endif
  270. or r21, ZERO, r31 /* Set FPU flag at last */
  271. #ifndef CONFIG_SH_NO_BSS_INIT
  272. /* Don't clear BSS if running on slow platforms such as an RTL simulation,
  273. remote memory via SHdebug link, etc. For these the memory can be guaranteed
  274. to be all zero on boot anyway. */
  275. /*
  276. * Clear bss
  277. */
  278. pta clear_quad, tr1
  279. movi __bss_start, r22
  280. movi _end, r23
  281. clear_quad:
  282. st.q r22, 0, ZERO
  283. addi r22, 8, r22
  284. bne r22, r23, tr1 /* Both quad aligned, see vmlinux.lds.S */
  285. #endif
  286. pta/u hopeless, tr1
  287. /* Say bye to head.S but be prepared to wrongly get back ... */
  288. blink tr0, LINK
  289. /* If we ever get back here through LINK/tr1-tr7 */
  290. pta/u hopeless, tr7
  291. hopeless:
  292. /*
  293. * Something's badly wrong here. Loop endlessly,
  294. * there's nothing more we can do about it.
  295. *
  296. * Note on hopeless: it can be jumped into invariably
  297. * before or after jumping into hyperspace. The only
  298. * requirement is to be PIC called (PTA) before and
  299. * any way (PTA/PTABS) after. According to Virtual
  300. * to Physical mapping a simulator/emulator can easily
  301. * tell where we came here from just looking at hopeless
  302. * (PC) address.
  303. *
  304. * For debugging purposes:
  305. * (r28) hopeless/loop address
  306. * (r29) Original SR
  307. * (r30) CPU type/Platform endianness
  308. * (r31) FPU Support
  309. * (r32) _start_kernel address
  310. */
  311. blink tr7, ZERO