head_64.S 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. #ifdef CONFIG_EARLY_PRINTK
  191. /*
  192. * Setup a DTLB translation for SCIF phys.
  193. */
  194. addi r21, MMUDR_STEP, r21
  195. movi 0x0a03, r22 /* SCIF phys */
  196. shori 0x0148, r22
  197. putcfg r21, 1, r22 /* PTEL first */
  198. movi 0xfa03, r22 /* 0xfa030000, fixed SCIF virt */
  199. shori 0x0003, r22
  200. putcfg r21, 0, r22 /* PTEH last */
  201. #endif
  202. /*
  203. * Set cache behaviours.
  204. */
  205. /* ICache */
  206. movi ICCR_BASE, r21
  207. movi ICCR0_INIT_VAL, r22
  208. movi ICCR1_INIT_VAL, r23
  209. putcfg r21, ICCR_REG0, r22
  210. putcfg r21, ICCR_REG1, r23
  211. /* OCache */
  212. movi OCCR_BASE, r21
  213. movi OCCR0_INIT_VAL, r22
  214. movi OCCR1_INIT_VAL, r23
  215. putcfg r21, OCCR_REG0, r22
  216. putcfg r21, OCCR_REG1, r23
  217. /*
  218. * Enable Caches and MMU. Do the first non-PIC jump.
  219. * Now head.S global variables, constants and externs
  220. * can be used.
  221. */
  222. getcon SR, r21
  223. movi SR_ENABLE_MMU, r22
  224. or r21, r22, r21
  225. putcon r21, SSR
  226. movi hyperspace, r22
  227. ori r22, 1, r22 /* Make it SHmedia, not required but..*/
  228. putcon r22, SPC
  229. synco
  230. rte /* And now go into the hyperspace ... */
  231. hyperspace: /* ... that's the next instruction ! */
  232. /*
  233. * Set CPU to a consistent state.
  234. * r31 = FPU support flag
  235. * tr0/tr7 in use. Others give a chance to loop somewhere safe
  236. */
  237. movi start_kernel, r32
  238. ori r32, 1, r32
  239. ptabs r32, tr0 /* r32 = _start_kernel address */
  240. pta/u hopeless, tr1
  241. pta/u hopeless, tr2
  242. pta/u hopeless, tr3
  243. pta/u hopeless, tr4
  244. pta/u hopeless, tr5
  245. pta/u hopeless, tr6
  246. pta/u hopeless, tr7
  247. gettr tr1, r28 /* r28 = hopeless address */
  248. /* Set initial stack pointer */
  249. movi init_thread_union, SP
  250. putcon SP, KCR0 /* Set current to init_task */
  251. movi THREAD_SIZE, r22 /* Point to the end */
  252. add SP, r22, SP
  253. /*
  254. * Initialize FPU.
  255. * Keep FPU flag in r31. After this block:
  256. * r31 = FPU flag
  257. */
  258. movi fpu_in_use, r31 /* Temporary */
  259. #ifdef CONFIG_SH_FPU
  260. getcon SR, r21
  261. movi SR_ENABLE_FPU, r22
  262. and r21, r22, r22
  263. putcon r22, SR /* Try to enable */
  264. getcon SR, r22
  265. xor r21, r22, r21
  266. shlri r21, 15, r21 /* Supposedly 0/1 */
  267. st.q r31, 0 , r21 /* Set fpu_in_use */
  268. #else
  269. movi 0, r21
  270. st.q r31, 0 , r21 /* Set fpu_in_use */
  271. #endif
  272. or r21, ZERO, r31 /* Set FPU flag at last */
  273. #ifndef CONFIG_SH_NO_BSS_INIT
  274. /* Don't clear BSS if running on slow platforms such as an RTL simulation,
  275. remote memory via SHdebug link, etc. For these the memory can be guaranteed
  276. to be all zero on boot anyway. */
  277. /*
  278. * Clear bss
  279. */
  280. pta clear_quad, tr1
  281. movi __bss_start, r22
  282. movi _end, r23
  283. clear_quad:
  284. st.q r22, 0, ZERO
  285. addi r22, 8, r22
  286. bne r22, r23, tr1 /* Both quad aligned, see vmlinux.lds.S */
  287. #endif
  288. pta/u hopeless, tr1
  289. /* Say bye to head.S but be prepared to wrongly get back ... */
  290. blink tr0, LINK
  291. /* If we ever get back here through LINK/tr1-tr7 */
  292. pta/u hopeless, tr7
  293. hopeless:
  294. /*
  295. * Something's badly wrong here. Loop endlessly,
  296. * there's nothing more we can do about it.
  297. *
  298. * Note on hopeless: it can be jumped into invariably
  299. * before or after jumping into hyperspace. The only
  300. * requirement is to be PIC called (PTA) before and
  301. * any way (PTA/PTABS) after. According to Virtual
  302. * to Physical mapping a simulator/emulator can easily
  303. * tell where we came here from just looking at hopeless
  304. * (PC) address.
  305. *
  306. * For debugging purposes:
  307. * (r28) hopeless/loop address
  308. * (r29) Original SR
  309. * (r30) CPU type/Platform endianness
  310. * (r31) FPU Support
  311. * (r32) _start_kernel address
  312. */
  313. blink tr7, ZERO