head.S 22 KB

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