head.S 9.8 KB

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