head.S 22 KB

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