head_64.S 23 KB

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