head.S 9.8 KB

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