head_32.S 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /* $Id: head.S,v 1.7 2003/09/01 17:58:19 lethal Exp $
  2. *
  3. * arch/sh/kernel/head.S
  4. *
  5. * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
  6. * Copyright (C) 2010 Matt Fleming
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. *
  12. * Head.S contains the SH exception handlers and startup code.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/linkage.h>
  16. #include <asm/thread_info.h>
  17. #include <asm/mmu.h>
  18. #include <cpu/mmu_context.h>
  19. #ifdef CONFIG_CPU_SH4A
  20. #define SYNCO() synco
  21. #define PREFI(label, reg) \
  22. mov.l label, reg; \
  23. prefi @reg
  24. #else
  25. #define SYNCO()
  26. #define PREFI(label, reg)
  27. #endif
  28. .section .empty_zero_page, "aw"
  29. ENTRY(empty_zero_page)
  30. .long 1 /* MOUNT_ROOT_RDONLY */
  31. .long 0 /* RAMDISK_FLAGS */
  32. .long 0x0200 /* ORIG_ROOT_DEV */
  33. .long 1 /* LOADER_TYPE */
  34. .long 0x00000000 /* INITRD_START */
  35. .long 0x00000000 /* INITRD_SIZE */
  36. #ifdef CONFIG_32BIT
  37. .long 0x53453f00 + 32 /* "SE?" = 32 bit */
  38. #else
  39. .long 0x53453f00 + 29 /* "SE?" = 29 bit */
  40. #endif
  41. 1:
  42. .skip PAGE_SIZE - empty_zero_page - 1b
  43. __HEAD
  44. /*
  45. * Condition at the entry of _stext:
  46. *
  47. * BSC has already been initialized.
  48. * INTC may or may not be initialized.
  49. * VBR may or may not be initialized.
  50. * MMU may or may not be initialized.
  51. * Cache may or may not be initialized.
  52. * Hardware (including on-chip modules) may or may not be initialized.
  53. *
  54. */
  55. ENTRY(_stext)
  56. ! Initialize Status Register
  57. mov.l 1f, r0 ! MD=1, RB=0, BL=0, IMASK=0xF
  58. ldc r0, sr
  59. ! Initialize global interrupt mask
  60. #ifdef CONFIG_CPU_HAS_SR_RB
  61. mov #0, r0
  62. ldc r0, r6_bank
  63. #endif
  64. #ifdef CONFIG_OF_FLATTREE
  65. mov r4, r12 ! Store device tree blob pointer in r12
  66. #endif
  67. /*
  68. * Prefetch if possible to reduce cache miss penalty.
  69. *
  70. * We do this early on for SH-4A as a micro-optimization,
  71. * as later on we will have speculative execution enabled
  72. * and this will become less of an issue.
  73. */
  74. PREFI(5f, r0)
  75. PREFI(6f, r0)
  76. !
  77. mov.l 2f, r0
  78. mov r0, r15 ! Set initial r15 (stack pointer)
  79. #ifdef CONFIG_CPU_HAS_SR_RB
  80. mov.l 7f, r0
  81. ldc r0, r7_bank ! ... and initial thread_info
  82. #endif
  83. #ifdef CONFIG_PMB
  84. /*
  85. * Reconfigure the initial PMB mappings setup by the hardware.
  86. *
  87. * When we boot in 32-bit MMU mode there are 2 PMB entries already
  88. * setup for us.
  89. *
  90. * Entry VPN PPN V SZ C UB WT
  91. * ---------------------------------------------------------------
  92. * 0 0x80000000 0x00000000 1 512MB 1 0 1
  93. * 1 0xA0000000 0x00000000 1 512MB 0 0 0
  94. *
  95. * But we reprogram them here because we want complete control over
  96. * our address space and the initial mappings may not map PAGE_OFFSET
  97. * to __MEMORY_START (or even map all of our RAM).
  98. *
  99. * Once we've setup cached and uncached mappings we clear the rest of the
  100. * PMB entries. This clearing also deals with the fact that PMB entries
  101. * can persist across reboots. The PMB could have been left in any state
  102. * when the reboot occurred, so to be safe we clear all entries and start
  103. * with with a clean slate.
  104. *
  105. * The uncached mapping is constructed using the smallest possible
  106. * mapping with a single unbufferable page. Only the kernel text needs to
  107. * be covered via the uncached mapping so that certain functions can be
  108. * run uncached.
  109. *
  110. * Drivers and the like that have previously abused the 1:1 identity
  111. * mapping are unsupported in 32-bit mode and must specify their caching
  112. * preference when page tables are constructed.
  113. *
  114. * This frees up the P2 space for more nefarious purposes.
  115. *
  116. * Register utilization is as follows:
  117. *
  118. * r0 = PMB_DATA data field
  119. * r1 = PMB_DATA address field
  120. * r2 = PMB_ADDR data field
  121. * r3 = PMB_ADDR address field
  122. * r4 = PMB_E_SHIFT
  123. * r5 = remaining amount of RAM to map
  124. * r6 = PMB mapping size we're trying to use
  125. * r7 = cached_to_uncached
  126. * r8 = scratch register
  127. * r9 = scratch register
  128. * r10 = number of PMB entries we've setup
  129. * r11 = scratch register
  130. */
  131. mov.l .LMMUCR, r1 /* Flush the TLB */
  132. mov.l @r1, r0
  133. or #MMUCR_TI, r0
  134. mov.l r0, @r1
  135. mov.l .LMEMORY_SIZE, r5
  136. mov #PMB_E_SHIFT, r0
  137. mov #0x1, r4
  138. shld r0, r4
  139. mov.l .LFIRST_DATA_ENTRY, r0
  140. mov.l .LPMB_DATA, r1
  141. mov.l .LFIRST_ADDR_ENTRY, r2
  142. mov.l .LPMB_ADDR, r3
  143. /*
  144. * First we need to walk the PMB and figure out if there are any
  145. * existing mappings that match the initial mappings VPN/PPN.
  146. * If these have already been established by the bootloader, we
  147. * don't bother setting up new entries here, and let the late PMB
  148. * initialization take care of things instead.
  149. *
  150. * Note that we may need to coalesce and merge entries in order
  151. * to reclaim more available PMB slots, which is much more than
  152. * we want to do at this early stage.
  153. */
  154. mov #0, r10
  155. mov #NR_PMB_ENTRIES, r9
  156. mov r1, r7 /* temporary PMB_DATA iter */
  157. .Lvalidate_existing_mappings:
  158. mov.l .LPMB_DATA_MASK, r11
  159. mov.l @r7, r8
  160. and r11, r8
  161. cmp/eq r0, r8 /* Check for valid __MEMORY_START mappings */
  162. bt .Lpmb_done
  163. add #1, r10 /* Increment the loop counter */
  164. cmp/eq r9, r10
  165. bf/s .Lvalidate_existing_mappings
  166. add r4, r7 /* Increment to the next PMB_DATA entry */
  167. /*
  168. * If we've fallen through, continue with setting up the initial
  169. * mappings.
  170. */
  171. mov r5, r7 /* cached_to_uncached */
  172. mov #0, r10
  173. #ifdef CONFIG_UNCACHED_MAPPING
  174. /*
  175. * Uncached mapping
  176. */
  177. mov #(PMB_SZ_16M >> 2), r9
  178. shll2 r9
  179. mov #(PMB_UB >> 8), r8
  180. shll8 r8
  181. or r0, r8
  182. or r9, r8
  183. mov.l r8, @r1
  184. mov r2, r8
  185. add r7, r8
  186. mov.l r8, @r3
  187. add r4, r1
  188. add r4, r3
  189. add #1, r10
  190. #endif
  191. /*
  192. * Iterate over all of the available sizes from largest to
  193. * smallest for constructing the cached mapping.
  194. */
  195. #define __PMB_ITER_BY_SIZE(size) \
  196. .L##size: \
  197. mov #(size >> 4), r6; \
  198. shll16 r6; \
  199. shll8 r6; \
  200. \
  201. cmp/hi r5, r6; \
  202. bt 9999f; \
  203. \
  204. mov #(PMB_SZ_##size##M >> 2), r9; \
  205. shll2 r9; \
  206. \
  207. /* \
  208. * Cached mapping \
  209. */ \
  210. mov #PMB_C, r8; \
  211. or r0, r8; \
  212. or r9, r8; \
  213. mov.l r8, @r1; \
  214. mov.l r2, @r3; \
  215. \
  216. /* Increment to the next PMB_DATA entry */ \
  217. add r4, r1; \
  218. /* Increment to the next PMB_ADDR entry */ \
  219. add r4, r3; \
  220. /* Increment number of PMB entries */ \
  221. add #1, r10; \
  222. \
  223. sub r6, r5; \
  224. add r6, r0; \
  225. add r6, r2; \
  226. \
  227. bra .L##size; \
  228. 9999:
  229. __PMB_ITER_BY_SIZE(512)
  230. __PMB_ITER_BY_SIZE(128)
  231. __PMB_ITER_BY_SIZE(64)
  232. __PMB_ITER_BY_SIZE(16)
  233. #ifdef CONFIG_UNCACHED_MAPPING
  234. /*
  235. * Now that we can access it, update cached_to_uncached and
  236. * uncached_size.
  237. */
  238. mov.l .Lcached_to_uncached, r0
  239. mov.l r7, @r0
  240. mov.l .Luncached_size, r0
  241. mov #1, r7
  242. shll16 r7
  243. shll8 r7
  244. mov.l r7, @r0
  245. #endif
  246. /*
  247. * Clear the remaining PMB entries.
  248. *
  249. * r3 = entry to begin clearing from
  250. * r10 = number of entries we've setup so far
  251. */
  252. mov #0, r1
  253. mov #NR_PMB_ENTRIES, r0
  254. .Lagain:
  255. mov.l r1, @r3 /* Clear PMB_ADDR entry */
  256. add #1, r10 /* Increment the loop counter */
  257. cmp/eq r0, r10
  258. bf/s .Lagain
  259. add r4, r3 /* Increment to the next PMB_ADDR entry */
  260. mov.l 6f, r0
  261. icbi @r0
  262. .Lpmb_done:
  263. #endif /* CONFIG_PMB */
  264. #ifndef CONFIG_SH_NO_BSS_INIT
  265. /*
  266. * Don't clear BSS if running on slow platforms such as an RTL simulation,
  267. * remote memory via SHdebug link, etc. For these the memory can be guaranteed
  268. * to be all zero on boot anyway.
  269. */
  270. ! Clear BSS area
  271. #ifdef CONFIG_SMP
  272. mov.l 3f, r0
  273. cmp/eq #0, r0 ! skip clear if set to zero
  274. bt 10f
  275. #endif
  276. mov.l 3f, r1
  277. add #4, r1
  278. mov.l 4f, r2
  279. mov #0, r0
  280. 9: cmp/hs r2, r1
  281. bf/s 9b ! while (r1 < r2)
  282. mov.l r0,@-r2
  283. 10:
  284. #endif
  285. #ifdef CONFIG_OF_FLATTREE
  286. mov.l 8f, r0 ! Make flat device tree available early.
  287. jsr @r0
  288. mov r12, r4
  289. #endif
  290. ! Additional CPU initialization
  291. mov.l 6f, r0
  292. jsr @r0
  293. nop
  294. SYNCO() ! Wait for pending instructions..
  295. ! Start kernel
  296. mov.l 5f, r0
  297. jmp @r0
  298. nop
  299. .balign 4
  300. #if defined(CONFIG_CPU_SH2)
  301. 1: .long 0x000000F0 ! IMASK=0xF
  302. #else
  303. 1: .long 0x500080F0 ! MD=1, RB=0, BL=1, FD=1, IMASK=0xF
  304. #endif
  305. ENTRY(stack_start)
  306. 2: .long init_thread_union+THREAD_SIZE
  307. 3: .long __bss_start
  308. 4: .long _end
  309. 5: .long start_kernel
  310. 6: .long cpu_init
  311. 7: .long init_thread_union
  312. #if defined(CONFIG_OF_FLATTREE)
  313. 8: .long sh_fdt_init
  314. #endif
  315. #ifdef CONFIG_PMB
  316. .LPMB_ADDR: .long PMB_ADDR
  317. .LPMB_DATA: .long PMB_DATA
  318. .LPMB_DATA_MASK: .long PMB_PFN_MASK | PMB_V
  319. .LFIRST_ADDR_ENTRY: .long PAGE_OFFSET | PMB_V
  320. .LFIRST_DATA_ENTRY: .long __MEMORY_START | PMB_V
  321. .LMMUCR: .long MMUCR
  322. .LMEMORY_SIZE: .long __MEMORY_SIZE
  323. #ifdef CONFIG_UNCACHED_MAPPING
  324. .Lcached_to_uncached: .long cached_to_uncached
  325. .Luncached_size: .long uncached_size
  326. #endif
  327. #endif