head_64.S 9.7 KB

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