head_64.S 22 KB

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