head.S 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. /* head.S: Initial boot code for the Sparc64 port of Linux.
  2. *
  3. * Copyright (C) 1996, 1997, 2007 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1996 David Sitsky (David.Sitsky@anu.edu.au)
  5. * Copyright (C) 1997, 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
  7. */
  8. #include <linux/version.h>
  9. #include <linux/errno.h>
  10. #include <linux/threads.h>
  11. #include <linux/init.h>
  12. #include <asm/thread_info.h>
  13. #include <asm/asi.h>
  14. #include <asm/pstate.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/spitfire.h>
  17. #include <asm/page.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/errno.h>
  20. #include <asm/signal.h>
  21. #include <asm/processor.h>
  22. #include <asm/lsu.h>
  23. #include <asm/dcr.h>
  24. #include <asm/dcu.h>
  25. #include <asm/head.h>
  26. #include <asm/ttable.h>
  27. #include <asm/mmu.h>
  28. #include <asm/cpudata.h>
  29. /* This section from from _start to sparc64_boot_end should fit into
  30. * 0x0000000000404000 to 0x0000000000408000.
  31. */
  32. .text
  33. .globl start, _start, stext, _stext
  34. _start:
  35. start:
  36. _stext:
  37. stext:
  38. ! 0x0000000000404000
  39. b sparc64_boot
  40. flushw /* Flush register file. */
  41. /* This stuff has to be in sync with SILO and other potential boot loaders
  42. * Fields should be kept upward compatible and whenever any change is made,
  43. * HdrS version should be incremented.
  44. */
  45. .global root_flags, ram_flags, root_dev
  46. .global sparc_ramdisk_image, sparc_ramdisk_size
  47. .global sparc_ramdisk_image64
  48. .ascii "HdrS"
  49. .word LINUX_VERSION_CODE
  50. /* History:
  51. *
  52. * 0x0300 : Supports being located at other than 0x4000
  53. * 0x0202 : Supports kernel params string
  54. * 0x0201 : Supports reboot_command
  55. */
  56. .half 0x0301 /* HdrS version */
  57. root_flags:
  58. .half 1
  59. root_dev:
  60. .half 0
  61. ram_flags:
  62. .half 0
  63. sparc_ramdisk_image:
  64. .word 0
  65. sparc_ramdisk_size:
  66. .word 0
  67. .xword reboot_command
  68. .xword bootstr_info
  69. sparc_ramdisk_image64:
  70. .xword 0
  71. .word _end
  72. /* PROM cif handler code address is in %o4. */
  73. sparc64_boot:
  74. mov %o4, %l7
  75. /* We need to remap the kernel. Use position independant
  76. * code to remap us to KERNBASE.
  77. *
  78. * SILO can invoke us with 32-bit address masking enabled,
  79. * so make sure that's clear.
  80. */
  81. rdpr %pstate, %g1
  82. andn %g1, PSTATE_AM, %g1
  83. wrpr %g1, 0x0, %pstate
  84. ba,a,pt %xcc, 1f
  85. .globl prom_finddev_name, prom_chosen_path, prom_root_node
  86. .globl prom_getprop_name, prom_mmu_name, prom_peer_name
  87. .globl prom_callmethod_name, prom_translate_name, prom_root_compatible
  88. .globl prom_map_name, prom_unmap_name, prom_mmu_ihandle_cache
  89. .globl prom_boot_mapped_pc, prom_boot_mapping_mode
  90. .globl prom_boot_mapping_phys_high, prom_boot_mapping_phys_low
  91. .globl prom_compatible_name, prom_cpu_path, prom_cpu_compatible
  92. .globl is_sun4v, sun4v_chip_type
  93. prom_peer_name:
  94. .asciz "peer"
  95. prom_compatible_name:
  96. .asciz "compatible"
  97. prom_finddev_name:
  98. .asciz "finddevice"
  99. prom_chosen_path:
  100. .asciz "/chosen"
  101. prom_cpu_path:
  102. .asciz "/cpu"
  103. prom_getprop_name:
  104. .asciz "getprop"
  105. prom_mmu_name:
  106. .asciz "mmu"
  107. prom_callmethod_name:
  108. .asciz "call-method"
  109. prom_translate_name:
  110. .asciz "translate"
  111. prom_map_name:
  112. .asciz "map"
  113. prom_unmap_name:
  114. .asciz "unmap"
  115. prom_sun4v_name:
  116. .asciz "sun4v"
  117. prom_niagara_prefix:
  118. .asciz "SUNW,UltraSPARC-T"
  119. .align 4
  120. prom_root_compatible:
  121. .skip 64
  122. prom_cpu_compatible:
  123. .skip 64
  124. prom_root_node:
  125. .word 0
  126. prom_mmu_ihandle_cache:
  127. .word 0
  128. prom_boot_mapped_pc:
  129. .word 0
  130. prom_boot_mapping_mode:
  131. .word 0
  132. .align 8
  133. prom_boot_mapping_phys_high:
  134. .xword 0
  135. prom_boot_mapping_phys_low:
  136. .xword 0
  137. is_sun4v:
  138. .word 0
  139. sun4v_chip_type:
  140. .word SUN4V_CHIP_INVALID
  141. 1:
  142. rd %pc, %l0
  143. mov (1b - prom_peer_name), %l1
  144. sub %l0, %l1, %l1
  145. mov 0, %l2
  146. /* prom_root_node = prom_peer(0) */
  147. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "peer"
  148. mov 1, %l3
  149. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 1
  150. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  151. stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1, 0
  152. stx %g0, [%sp + 2047 + 128 + 0x20] ! ret1
  153. call %l7
  154. add %sp, (2047 + 128), %o0 ! argument array
  155. ldx [%sp + 2047 + 128 + 0x20], %l4 ! prom root node
  156. mov (1b - prom_root_node), %l1
  157. sub %l0, %l1, %l1
  158. stw %l4, [%l1]
  159. mov (1b - prom_getprop_name), %l1
  160. mov (1b - prom_compatible_name), %l2
  161. mov (1b - prom_root_compatible), %l5
  162. sub %l0, %l1, %l1
  163. sub %l0, %l2, %l2
  164. sub %l0, %l5, %l5
  165. /* prom_getproperty(prom_root_node, "compatible",
  166. * &prom_root_compatible, 64)
  167. */
  168. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "getprop"
  169. mov 4, %l3
  170. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 4
  171. mov 1, %l3
  172. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  173. stx %l4, [%sp + 2047 + 128 + 0x18] ! arg1, prom_root_node
  174. stx %l2, [%sp + 2047 + 128 + 0x20] ! arg2, "compatible"
  175. stx %l5, [%sp + 2047 + 128 + 0x28] ! arg3, &prom_root_compatible
  176. mov 64, %l3
  177. stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4, size
  178. stx %g0, [%sp + 2047 + 128 + 0x38] ! ret1
  179. call %l7
  180. add %sp, (2047 + 128), %o0 ! argument array
  181. mov (1b - prom_finddev_name), %l1
  182. mov (1b - prom_chosen_path), %l2
  183. mov (1b - prom_boot_mapped_pc), %l3
  184. sub %l0, %l1, %l1
  185. sub %l0, %l2, %l2
  186. sub %l0, %l3, %l3
  187. stw %l0, [%l3]
  188. sub %sp, (192 + 128), %sp
  189. /* chosen_node = prom_finddevice("/chosen") */
  190. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "finddevice"
  191. mov 1, %l3
  192. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 1
  193. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  194. stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1, "/chosen"
  195. stx %g0, [%sp + 2047 + 128 + 0x20] ! ret1
  196. call %l7
  197. add %sp, (2047 + 128), %o0 ! argument array
  198. ldx [%sp + 2047 + 128 + 0x20], %l4 ! chosen device node
  199. mov (1b - prom_getprop_name), %l1
  200. mov (1b - prom_mmu_name), %l2
  201. mov (1b - prom_mmu_ihandle_cache), %l5
  202. sub %l0, %l1, %l1
  203. sub %l0, %l2, %l2
  204. sub %l0, %l5, %l5
  205. /* prom_mmu_ihandle_cache = prom_getint(chosen_node, "mmu") */
  206. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "getprop"
  207. mov 4, %l3
  208. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 4
  209. mov 1, %l3
  210. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  211. stx %l4, [%sp + 2047 + 128 + 0x18] ! arg1, chosen_node
  212. stx %l2, [%sp + 2047 + 128 + 0x20] ! arg2, "mmu"
  213. stx %l5, [%sp + 2047 + 128 + 0x28] ! arg3, &prom_mmu_ihandle_cache
  214. mov 4, %l3
  215. stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4, sizeof(arg3)
  216. stx %g0, [%sp + 2047 + 128 + 0x38] ! ret1
  217. call %l7
  218. add %sp, (2047 + 128), %o0 ! argument array
  219. mov (1b - prom_callmethod_name), %l1
  220. mov (1b - prom_translate_name), %l2
  221. sub %l0, %l1, %l1
  222. sub %l0, %l2, %l2
  223. lduw [%l5], %l5 ! prom_mmu_ihandle_cache
  224. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "call-method"
  225. mov 3, %l3
  226. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 3
  227. mov 5, %l3
  228. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 5
  229. stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1: "translate"
  230. stx %l5, [%sp + 2047 + 128 + 0x20] ! arg2: prom_mmu_ihandle_cache
  231. /* PAGE align */
  232. srlx %l0, 13, %l3
  233. sllx %l3, 13, %l3
  234. stx %l3, [%sp + 2047 + 128 + 0x28] ! arg3: vaddr, our PC
  235. stx %g0, [%sp + 2047 + 128 + 0x30] ! res1
  236. stx %g0, [%sp + 2047 + 128 + 0x38] ! res2
  237. stx %g0, [%sp + 2047 + 128 + 0x40] ! res3
  238. stx %g0, [%sp + 2047 + 128 + 0x48] ! res4
  239. stx %g0, [%sp + 2047 + 128 + 0x50] ! res5
  240. call %l7
  241. add %sp, (2047 + 128), %o0 ! argument array
  242. ldx [%sp + 2047 + 128 + 0x40], %l1 ! translation mode
  243. mov (1b - prom_boot_mapping_mode), %l4
  244. sub %l0, %l4, %l4
  245. stw %l1, [%l4]
  246. mov (1b - prom_boot_mapping_phys_high), %l4
  247. sub %l0, %l4, %l4
  248. ldx [%sp + 2047 + 128 + 0x48], %l2 ! physaddr high
  249. stx %l2, [%l4 + 0x0]
  250. ldx [%sp + 2047 + 128 + 0x50], %l3 ! physaddr low
  251. /* 4MB align */
  252. srlx %l3, 22, %l3
  253. sllx %l3, 22, %l3
  254. stx %l3, [%l4 + 0x8]
  255. /* Leave service as-is, "call-method" */
  256. mov 7, %l3
  257. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 7
  258. mov 1, %l3
  259. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  260. mov (1b - prom_map_name), %l3
  261. sub %l0, %l3, %l3
  262. stx %l3, [%sp + 2047 + 128 + 0x18] ! arg1: "map"
  263. /* Leave arg2 as-is, prom_mmu_ihandle_cache */
  264. mov -1, %l3
  265. stx %l3, [%sp + 2047 + 128 + 0x28] ! arg3: mode (-1 default)
  266. sethi %hi(8 * 1024 * 1024), %l3
  267. stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4: size (8MB)
  268. sethi %hi(KERNBASE), %l3
  269. stx %l3, [%sp + 2047 + 128 + 0x38] ! arg5: vaddr (KERNBASE)
  270. stx %g0, [%sp + 2047 + 128 + 0x40] ! arg6: empty
  271. mov (1b - prom_boot_mapping_phys_low), %l3
  272. sub %l0, %l3, %l3
  273. ldx [%l3], %l3
  274. stx %l3, [%sp + 2047 + 128 + 0x48] ! arg7: phys addr
  275. call %l7
  276. add %sp, (2047 + 128), %o0 ! argument array
  277. add %sp, (192 + 128), %sp
  278. sethi %hi(prom_root_compatible), %g1
  279. or %g1, %lo(prom_root_compatible), %g1
  280. sethi %hi(prom_sun4v_name), %g7
  281. or %g7, %lo(prom_sun4v_name), %g7
  282. mov 5, %g3
  283. 90: ldub [%g7], %g2
  284. ldub [%g1], %g4
  285. cmp %g2, %g4
  286. bne,pn %icc, 80f
  287. add %g7, 1, %g7
  288. subcc %g3, 1, %g3
  289. bne,pt %xcc, 90b
  290. add %g1, 1, %g1
  291. sethi %hi(is_sun4v), %g1
  292. or %g1, %lo(is_sun4v), %g1
  293. mov 1, %g7
  294. stw %g7, [%g1]
  295. /* cpu_node = prom_finddevice("/cpu") */
  296. mov (1b - prom_finddev_name), %l1
  297. mov (1b - prom_cpu_path), %l2
  298. sub %l0, %l1, %l1
  299. sub %l0, %l2, %l2
  300. sub %sp, (192 + 128), %sp
  301. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "finddevice"
  302. mov 1, %l3
  303. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 1
  304. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  305. stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1, "/cpu"
  306. stx %g0, [%sp + 2047 + 128 + 0x20] ! ret1
  307. call %l7
  308. add %sp, (2047 + 128), %o0 ! argument array
  309. ldx [%sp + 2047 + 128 + 0x20], %l4 ! cpu device node
  310. mov (1b - prom_getprop_name), %l1
  311. mov (1b - prom_compatible_name), %l2
  312. mov (1b - prom_cpu_compatible), %l5
  313. sub %l0, %l1, %l1
  314. sub %l0, %l2, %l2
  315. sub %l0, %l5, %l5
  316. /* prom_getproperty(cpu_node, "compatible",
  317. * &prom_cpu_compatible, 64)
  318. */
  319. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "getprop"
  320. mov 4, %l3
  321. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 4
  322. mov 1, %l3
  323. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  324. stx %l4, [%sp + 2047 + 128 + 0x18] ! arg1, cpu_node
  325. stx %l2, [%sp + 2047 + 128 + 0x20] ! arg2, "compatible"
  326. stx %l5, [%sp + 2047 + 128 + 0x28] ! arg3, &prom_cpu_compatible
  327. mov 64, %l3
  328. stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4, size
  329. stx %g0, [%sp + 2047 + 128 + 0x38] ! ret1
  330. call %l7
  331. add %sp, (2047 + 128), %o0 ! argument array
  332. add %sp, (192 + 128), %sp
  333. sethi %hi(prom_cpu_compatible), %g1
  334. or %g1, %lo(prom_cpu_compatible), %g1
  335. sethi %hi(prom_niagara_prefix), %g7
  336. or %g7, %lo(prom_niagara_prefix), %g7
  337. mov 17, %g3
  338. 90: ldub [%g7], %g2
  339. ldub [%g1], %g4
  340. cmp %g2, %g4
  341. bne,pn %icc, 4f
  342. add %g7, 1, %g7
  343. subcc %g3, 1, %g3
  344. bne,pt %xcc, 90b
  345. add %g1, 1, %g1
  346. sethi %hi(prom_cpu_compatible), %g1
  347. or %g1, %lo(prom_cpu_compatible), %g1
  348. ldub [%g1 + 17], %g2
  349. cmp %g2, '1'
  350. be,pt %xcc, 5f
  351. mov SUN4V_CHIP_NIAGARA1, %g4
  352. cmp %g2, '2'
  353. be,pt %xcc, 5f
  354. mov SUN4V_CHIP_NIAGARA2, %g4
  355. 4:
  356. mov SUN4V_CHIP_UNKNOWN, %g4
  357. 5: sethi %hi(sun4v_chip_type), %g2
  358. or %g2, %lo(sun4v_chip_type), %g2
  359. stw %g4, [%g2]
  360. 80:
  361. BRANCH_IF_SUN4V(g1, jump_to_sun4u_init)
  362. BRANCH_IF_CHEETAH_BASE(g1,g7,cheetah_boot)
  363. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g7,cheetah_plus_boot)
  364. ba,pt %xcc, spitfire_boot
  365. nop
  366. cheetah_plus_boot:
  367. /* Preserve OBP chosen DCU and DCR register settings. */
  368. ba,pt %xcc, cheetah_generic_boot
  369. nop
  370. cheetah_boot:
  371. mov DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
  372. wr %g1, %asr18
  373. sethi %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g7
  374. or %g7, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g7
  375. sllx %g7, 32, %g7
  376. or %g7, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g7
  377. stxa %g7, [%g0] ASI_DCU_CONTROL_REG
  378. membar #Sync
  379. cheetah_generic_boot:
  380. mov TSB_EXTENSION_P, %g3
  381. stxa %g0, [%g3] ASI_DMMU
  382. stxa %g0, [%g3] ASI_IMMU
  383. membar #Sync
  384. mov TSB_EXTENSION_S, %g3
  385. stxa %g0, [%g3] ASI_DMMU
  386. membar #Sync
  387. mov TSB_EXTENSION_N, %g3
  388. stxa %g0, [%g3] ASI_DMMU
  389. stxa %g0, [%g3] ASI_IMMU
  390. membar #Sync
  391. ba,a,pt %xcc, jump_to_sun4u_init
  392. spitfire_boot:
  393. /* Typically PROM has already enabled both MMU's and both on-chip
  394. * caches, but we do it here anyway just to be paranoid.
  395. */
  396. mov (LSU_CONTROL_IC|LSU_CONTROL_DC|LSU_CONTROL_IM|LSU_CONTROL_DM), %g1
  397. stxa %g1, [%g0] ASI_LSU_CONTROL
  398. membar #Sync
  399. jump_to_sun4u_init:
  400. /*
  401. * Make sure we are in privileged mode, have address masking,
  402. * using the ordinary globals and have enabled floating
  403. * point.
  404. *
  405. * Again, typically PROM has left %pil at 13 or similar, and
  406. * (PSTATE_PRIV | PSTATE_PEF | PSTATE_IE) in %pstate.
  407. */
  408. wrpr %g0, (PSTATE_PRIV|PSTATE_PEF|PSTATE_IE), %pstate
  409. wr %g0, 0, %fprs
  410. set sun4u_init, %g2
  411. jmpl %g2 + %g0, %g0
  412. nop
  413. .section .text.init.refok
  414. sun4u_init:
  415. BRANCH_IF_SUN4V(g1, sun4v_init)
  416. /* Set ctx 0 */
  417. mov PRIMARY_CONTEXT, %g7
  418. stxa %g0, [%g7] ASI_DMMU
  419. membar #Sync
  420. mov SECONDARY_CONTEXT, %g7
  421. stxa %g0, [%g7] ASI_DMMU
  422. membar #Sync
  423. ba,pt %xcc, sun4u_continue
  424. nop
  425. sun4v_init:
  426. /* Set ctx 0 */
  427. mov PRIMARY_CONTEXT, %g7
  428. stxa %g0, [%g7] ASI_MMU
  429. membar #Sync
  430. mov SECONDARY_CONTEXT, %g7
  431. stxa %g0, [%g7] ASI_MMU
  432. membar #Sync
  433. ba,pt %xcc, niagara_tlb_fixup
  434. nop
  435. sun4u_continue:
  436. BRANCH_IF_ANY_CHEETAH(g1, g7, cheetah_tlb_fixup)
  437. ba,pt %xcc, spitfire_tlb_fixup
  438. nop
  439. niagara_tlb_fixup:
  440. mov 3, %g2 /* Set TLB type to hypervisor. */
  441. sethi %hi(tlb_type), %g1
  442. stw %g2, [%g1 + %lo(tlb_type)]
  443. /* Patch copy/clear ops. */
  444. sethi %hi(sun4v_chip_type), %g1
  445. lduw [%g1 + %lo(sun4v_chip_type)], %g1
  446. cmp %g1, SUN4V_CHIP_NIAGARA1
  447. be,pt %xcc, niagara_patch
  448. cmp %g1, SUN4V_CHIP_NIAGARA2
  449. be,pt %xcc, niagara2_patch
  450. nop
  451. call generic_patch_copyops
  452. nop
  453. call generic_patch_bzero
  454. nop
  455. call generic_patch_pageops
  456. nop
  457. ba,a,pt %xcc, 80f
  458. niagara2_patch:
  459. call niagara2_patch_copyops
  460. nop
  461. call niagara_patch_bzero
  462. nop
  463. call niagara2_patch_pageops
  464. nop
  465. ba,a,pt %xcc, 80f
  466. niagara_patch:
  467. call niagara_patch_copyops
  468. nop
  469. call niagara_patch_bzero
  470. nop
  471. call niagara_patch_pageops
  472. nop
  473. 80:
  474. /* Patch TLB/cache ops. */
  475. call hypervisor_patch_cachetlbops
  476. nop
  477. ba,pt %xcc, tlb_fixup_done
  478. nop
  479. cheetah_tlb_fixup:
  480. mov 2, %g2 /* Set TLB type to cheetah+. */
  481. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g7,1f)
  482. mov 1, %g2 /* Set TLB type to cheetah. */
  483. 1: sethi %hi(tlb_type), %g1
  484. stw %g2, [%g1 + %lo(tlb_type)]
  485. /* Patch copy/page operations to cheetah optimized versions. */
  486. call cheetah_patch_copyops
  487. nop
  488. call cheetah_patch_copy_page
  489. nop
  490. call cheetah_patch_cachetlbops
  491. nop
  492. ba,pt %xcc, tlb_fixup_done
  493. nop
  494. spitfire_tlb_fixup:
  495. /* Set TLB type to spitfire. */
  496. mov 0, %g2
  497. sethi %hi(tlb_type), %g1
  498. stw %g2, [%g1 + %lo(tlb_type)]
  499. tlb_fixup_done:
  500. sethi %hi(init_thread_union), %g6
  501. or %g6, %lo(init_thread_union), %g6
  502. ldx [%g6 + TI_TASK], %g4
  503. mov %sp, %l6
  504. wr %g0, ASI_P, %asi
  505. mov 1, %g1
  506. sllx %g1, THREAD_SHIFT, %g1
  507. sub %g1, (STACKFRAME_SZ + STACK_BIAS), %g1
  508. add %g6, %g1, %sp
  509. mov 0, %fp
  510. /* Set per-cpu pointer initially to zero, this makes
  511. * the boot-cpu use the in-kernel-image per-cpu areas
  512. * before setup_per_cpu_area() is invoked.
  513. */
  514. clr %g5
  515. wrpr %g0, 0, %wstate
  516. wrpr %g0, 0x0, %tl
  517. /* Clear the bss */
  518. sethi %hi(__bss_start), %o0
  519. or %o0, %lo(__bss_start), %o0
  520. sethi %hi(_end), %o1
  521. or %o1, %lo(_end), %o1
  522. call __bzero
  523. sub %o1, %o0, %o1
  524. #ifdef CONFIG_LOCKDEP
  525. /* We have this call this super early, as even prom_init can grab
  526. * spinlocks and thus call into the lockdep code.
  527. */
  528. call lockdep_init
  529. nop
  530. #endif
  531. mov %l6, %o1 ! OpenPROM stack
  532. call prom_init
  533. mov %l7, %o0 ! OpenPROM cif handler
  534. /* Initialize current_thread_info()->cpu as early as possible.
  535. * In order to do that accurately we have to patch up the get_cpuid()
  536. * assembler sequences. And that, in turn, requires that we know
  537. * if we are on a Starfire box or not. While we're here, patch up
  538. * the sun4v sequences as well.
  539. */
  540. call check_if_starfire
  541. nop
  542. call per_cpu_patch
  543. nop
  544. call sun4v_patch
  545. nop
  546. #ifdef CONFIG_SMP
  547. call hard_smp_processor_id
  548. nop
  549. cmp %o0, NR_CPUS
  550. blu,pt %xcc, 1f
  551. nop
  552. call boot_cpu_id_too_large
  553. nop
  554. /* Not reached... */
  555. 1:
  556. #else
  557. mov 0, %o0
  558. #endif
  559. sth %o0, [%g6 + TI_CPU]
  560. /* Off we go.... */
  561. call start_kernel
  562. nop
  563. /* Not reached... */
  564. .previous
  565. /* This is meant to allow the sharing of this code between
  566. * boot processor invocation (via setup_tba() below) and
  567. * secondary processor startup (via trampoline.S). The
  568. * former does use this code, the latter does not yet due
  569. * to some complexities. That should be fixed up at some
  570. * point.
  571. *
  572. * There used to be enormous complexity wrt. transferring
  573. * over from the firwmare's trap table to the Linux kernel's.
  574. * For example, there was a chicken & egg problem wrt. building
  575. * the OBP page tables, yet needing to be on the Linux kernel
  576. * trap table (to translate PAGE_OFFSET addresses) in order to
  577. * do that.
  578. *
  579. * We now handle OBP tlb misses differently, via linear lookups
  580. * into the prom_trans[] array. So that specific problem no
  581. * longer exists. Yet, unfortunately there are still some issues
  582. * preventing trampoline.S from using this code... ho hum.
  583. */
  584. .globl setup_trap_table
  585. setup_trap_table:
  586. save %sp, -192, %sp
  587. /* Force interrupts to be disabled. */
  588. rdpr %pstate, %l0
  589. andn %l0, PSTATE_IE, %o1
  590. wrpr %o1, 0x0, %pstate
  591. rdpr %pil, %l1
  592. wrpr %g0, 15, %pil
  593. /* Make the firmware call to jump over to the Linux trap table. */
  594. sethi %hi(is_sun4v), %o0
  595. lduw [%o0 + %lo(is_sun4v)], %o0
  596. brz,pt %o0, 1f
  597. nop
  598. TRAP_LOAD_TRAP_BLOCK(%g2, %g3)
  599. add %g2, TRAP_PER_CPU_FAULT_INFO, %g2
  600. stxa %g2, [%g0] ASI_SCRATCHPAD
  601. /* Compute physical address:
  602. *
  603. * paddr = kern_base + (mmfsa_vaddr - KERNBASE)
  604. */
  605. sethi %hi(KERNBASE), %g3
  606. sub %g2, %g3, %g2
  607. sethi %hi(kern_base), %g3
  608. ldx [%g3 + %lo(kern_base)], %g3
  609. add %g2, %g3, %o1
  610. call prom_set_trap_table_sun4v
  611. sethi %hi(sparc64_ttable_tl0), %o0
  612. ba,pt %xcc, 2f
  613. nop
  614. 1: call prom_set_trap_table
  615. sethi %hi(sparc64_ttable_tl0), %o0
  616. /* Start using proper page size encodings in ctx register. */
  617. 2: sethi %hi(sparc64_kern_pri_context), %g3
  618. ldx [%g3 + %lo(sparc64_kern_pri_context)], %g2
  619. mov PRIMARY_CONTEXT, %g1
  620. 661: stxa %g2, [%g1] ASI_DMMU
  621. .section .sun4v_1insn_patch, "ax"
  622. .word 661b
  623. stxa %g2, [%g1] ASI_MMU
  624. .previous
  625. membar #Sync
  626. BRANCH_IF_SUN4V(o2, 1f)
  627. /* Kill PROM timer */
  628. sethi %hi(0x80000000), %o2
  629. sllx %o2, 32, %o2
  630. wr %o2, 0, %tick_cmpr
  631. BRANCH_IF_ANY_CHEETAH(o2, o3, 1f)
  632. ba,pt %xcc, 2f
  633. nop
  634. /* Disable STICK_INT interrupts. */
  635. 1:
  636. sethi %hi(0x80000000), %o2
  637. sllx %o2, 32, %o2
  638. wr %o2, %asr25
  639. 2:
  640. wrpr %g0, %g0, %wstate
  641. call init_irqwork_curcpu
  642. nop
  643. /* Now we can restore interrupt state. */
  644. wrpr %l0, 0, %pstate
  645. wrpr %l1, 0x0, %pil
  646. ret
  647. restore
  648. .globl setup_tba
  649. setup_tba:
  650. save %sp, -192, %sp
  651. /* The boot processor is the only cpu which invokes this
  652. * routine, the other cpus set things up via trampoline.S.
  653. * So save the OBP trap table address here.
  654. */
  655. rdpr %tba, %g7
  656. sethi %hi(prom_tba), %o1
  657. or %o1, %lo(prom_tba), %o1
  658. stx %g7, [%o1]
  659. call setup_trap_table
  660. nop
  661. ret
  662. restore
  663. sparc64_boot_end:
  664. #include "etrap.S"
  665. #include "rtrap.S"
  666. #include "winfixup.S"
  667. #include "entry.S"
  668. #include "sun4v_tlb_miss.S"
  669. #include "sun4v_ivec.S"
  670. #include "ktlb.S"
  671. #include "tsb.S"
  672. /*
  673. * The following skip makes sure the trap table in ttable.S is aligned
  674. * on a 32K boundary as required by the v9 specs for TBA register.
  675. *
  676. * We align to a 32K boundary, then we have the 32K kernel TSB,
  677. * the 64K kernel 4MB TSB, and then the 32K aligned trap table.
  678. */
  679. 1:
  680. .skip 0x4000 + _start - 1b
  681. ! 0x0000000000408000
  682. .globl swapper_tsb
  683. swapper_tsb:
  684. .skip (32 * 1024)
  685. .globl swapper_4m_tsb
  686. swapper_4m_tsb:
  687. .skip (64 * 1024)
  688. ! 0x0000000000420000
  689. /* Some care needs to be exercised if you try to move the
  690. * location of the trap table relative to other things. For
  691. * one thing there are br* instructions in some of the
  692. * trap table entires which branch back to code in ktlb.S
  693. * Those instructions can only handle a signed 16-bit
  694. * displacement.
  695. *
  696. * There is a binutils bug (bugzilla #4558) which causes
  697. * the relocation overflow checks for such instructions to
  698. * not be done correctly. So bintuils will not notice the
  699. * error and will instead write junk into the relocation and
  700. * you'll have an unbootable kernel.
  701. */
  702. #include "ttable.S"
  703. ! 0x0000000000428000
  704. #include "systbls.S"
  705. .data
  706. .align 8
  707. .globl prom_tba, tlb_type
  708. prom_tba: .xword 0
  709. tlb_type: .word 0 /* Must NOT end up in BSS */
  710. .section ".fixup",#alloc,#execinstr
  711. .globl __ret_efault, __retl_efault
  712. __ret_efault:
  713. ret
  714. restore %g0, -EFAULT, %o0
  715. __retl_efault:
  716. retl
  717. mov -EFAULT, %o0