head_64.S 23 KB

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