head.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /* $Id: head.S,v 1.87 2002/02/09 19:49:31 davem Exp $
  2. * head.S: Initial boot code for the Sparc64 port of Linux.
  3. *
  4. * Copyright (C) 1996,1997 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1996 David Sitsky (David.Sitsky@anu.edu.au)
  6. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  7. * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
  8. */
  9. #include <linux/config.h>
  10. #include <linux/version.h>
  11. #include <linux/errno.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. /* This section from from _start to sparc64_boot_end should fit into
  29. * 0x0000.0000.0040.4000 to 0x0000.0000.0040.8000 and will be sharing space
  30. * with bootup_user_stack, which is from 0x0000.0000.0040.4000 to
  31. * 0x0000.0000.0040.6000 and empty_bad_page, which is from
  32. * 0x0000.0000.0040.6000 to 0x0000.0000.0040.8000.
  33. */
  34. .text
  35. .globl start, _start, stext, _stext
  36. _start:
  37. start:
  38. _stext:
  39. stext:
  40. bootup_user_stack:
  41. ! 0x0000000000404000
  42. b sparc64_boot
  43. flushw /* Flush register file. */
  44. /* This stuff has to be in sync with SILO and other potential boot loaders
  45. * Fields should be kept upward compatible and whenever any change is made,
  46. * HdrS version should be incremented.
  47. */
  48. .global root_flags, ram_flags, root_dev
  49. .global sparc_ramdisk_image, sparc_ramdisk_size
  50. .global sparc_ramdisk_image64
  51. .ascii "HdrS"
  52. .word LINUX_VERSION_CODE
  53. /* History:
  54. *
  55. * 0x0300 : Supports being located at other than 0x4000
  56. * 0x0202 : Supports kernel params string
  57. * 0x0201 : Supports reboot_command
  58. */
  59. .half 0x0301 /* HdrS version */
  60. root_flags:
  61. .half 1
  62. root_dev:
  63. .half 0
  64. ram_flags:
  65. .half 0
  66. sparc_ramdisk_image:
  67. .word 0
  68. sparc_ramdisk_size:
  69. .word 0
  70. .xword reboot_command
  71. .xword bootstr_info
  72. sparc_ramdisk_image64:
  73. .xword 0
  74. .word _end
  75. /* We must be careful, 32-bit OpenBOOT will get confused if it
  76. * tries to save away a register window to a 64-bit kernel
  77. * stack address. Flush all windows, disable interrupts,
  78. * remap if necessary, jump onto kernel trap table, then kernel
  79. * stack, or else we die.
  80. *
  81. * PROM entry point is on %o4
  82. */
  83. sparc64_boot:
  84. BRANCH_IF_CHEETAH_BASE(g1,g7,cheetah_boot)
  85. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g7,cheetah_plus_boot)
  86. ba,pt %xcc, spitfire_boot
  87. nop
  88. cheetah_plus_boot:
  89. /* Preserve OBP chosen DCU and DCR register settings. */
  90. ba,pt %xcc, cheetah_generic_boot
  91. nop
  92. cheetah_boot:
  93. mov DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
  94. wr %g1, %asr18
  95. sethi %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g7
  96. or %g7, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g7
  97. sllx %g7, 32, %g7
  98. or %g7, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g7
  99. stxa %g7, [%g0] ASI_DCU_CONTROL_REG
  100. membar #Sync
  101. cheetah_generic_boot:
  102. mov TSB_EXTENSION_P, %g3
  103. stxa %g0, [%g3] ASI_DMMU
  104. stxa %g0, [%g3] ASI_IMMU
  105. membar #Sync
  106. mov TSB_EXTENSION_S, %g3
  107. stxa %g0, [%g3] ASI_DMMU
  108. membar #Sync
  109. mov TSB_EXTENSION_N, %g3
  110. stxa %g0, [%g3] ASI_DMMU
  111. stxa %g0, [%g3] ASI_IMMU
  112. membar #Sync
  113. wrpr %g0, (PSTATE_PRIV|PSTATE_PEF|PSTATE_IE), %pstate
  114. wr %g0, 0, %fprs
  115. /* Just like for Spitfire, we probe itlb-2 for a mapping which
  116. * matches our current %pc. We take the physical address in
  117. * that mapping and use it to make our own.
  118. */
  119. /* %g5 holds the tlb data */
  120. sethi %uhi(_PAGE_VALID | _PAGE_SZ4MB), %g5
  121. sllx %g5, 32, %g5
  122. or %g5, (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_L | _PAGE_W | _PAGE_G), %g5
  123. /* Put PADDR tlb data mask into %g3. */
  124. sethi %uhi(_PAGE_PADDR), %g3
  125. or %g3, %ulo(_PAGE_PADDR), %g3
  126. sllx %g3, 32, %g3
  127. sethi %hi(_PAGE_PADDR), %g7
  128. or %g7, %lo(_PAGE_PADDR), %g7
  129. or %g3, %g7, %g3
  130. set 2 << 16, %l0 /* TLB entry walker. */
  131. set 0x1fff, %l2 /* Page mask. */
  132. rd %pc, %l3
  133. andn %l3, %l2, %g2 /* vaddr comparator */
  134. 1: ldxa [%l0] ASI_ITLB_TAG_READ, %g1
  135. membar #Sync
  136. andn %g1, %l2, %g1
  137. cmp %g1, %g2
  138. be,pn %xcc, cheetah_got_tlbentry
  139. nop
  140. and %l0, (127 << 3), %g1
  141. cmp %g1, (127 << 3)
  142. blu,pt %xcc, 1b
  143. add %l0, (1 << 3), %l0
  144. /* Search the small TLB. OBP never maps us like that but
  145. * newer SILO can.
  146. */
  147. clr %l0
  148. 1: ldxa [%l0] ASI_ITLB_TAG_READ, %g1
  149. membar #Sync
  150. andn %g1, %l2, %g1
  151. cmp %g1, %g2
  152. be,pn %xcc, cheetah_got_tlbentry
  153. nop
  154. cmp %l0, (15 << 3)
  155. blu,pt %xcc, 1b
  156. add %l0, (1 << 3), %l0
  157. /* BUG() if we get here... */
  158. ta 0x5
  159. cheetah_got_tlbentry:
  160. ldxa [%l0] ASI_ITLB_DATA_ACCESS, %g0
  161. ldxa [%l0] ASI_ITLB_DATA_ACCESS, %g1
  162. membar #Sync
  163. and %g1, %g3, %g1
  164. set 0x5fff, %l0
  165. andn %g1, %l0, %g1
  166. or %g5, %g1, %g5
  167. /* Clear out any KERNBASE area entries. */
  168. set 2 << 16, %l0
  169. sethi %hi(KERNBASE), %g3
  170. sethi %hi(KERNBASE<<1), %g7
  171. mov TLB_TAG_ACCESS, %l7
  172. /* First, check ITLB */
  173. 1: ldxa [%l0] ASI_ITLB_TAG_READ, %g1
  174. membar #Sync
  175. andn %g1, %l2, %g1
  176. cmp %g1, %g3
  177. blu,pn %xcc, 2f
  178. cmp %g1, %g7
  179. bgeu,pn %xcc, 2f
  180. nop
  181. stxa %g0, [%l7] ASI_IMMU
  182. membar #Sync
  183. stxa %g0, [%l0] ASI_ITLB_DATA_ACCESS
  184. membar #Sync
  185. 2: and %l0, (127 << 3), %g1
  186. cmp %g1, (127 << 3)
  187. blu,pt %xcc, 1b
  188. add %l0, (1 << 3), %l0
  189. /* Next, check DTLB */
  190. set 2 << 16, %l0
  191. 1: ldxa [%l0] ASI_DTLB_TAG_READ, %g1
  192. membar #Sync
  193. andn %g1, %l2, %g1
  194. cmp %g1, %g3
  195. blu,pn %xcc, 2f
  196. cmp %g1, %g7
  197. bgeu,pn %xcc, 2f
  198. nop
  199. stxa %g0, [%l7] ASI_DMMU
  200. membar #Sync
  201. stxa %g0, [%l0] ASI_DTLB_DATA_ACCESS
  202. membar #Sync
  203. 2: and %l0, (511 << 3), %g1
  204. cmp %g1, (511 << 3)
  205. blu,pt %xcc, 1b
  206. add %l0, (1 << 3), %l0
  207. /* On Cheetah+, have to check second DTLB. */
  208. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,l0,2f)
  209. ba,pt %xcc, 9f
  210. nop
  211. 2: set 3 << 16, %l0
  212. 1: ldxa [%l0] ASI_DTLB_TAG_READ, %g1
  213. membar #Sync
  214. andn %g1, %l2, %g1
  215. cmp %g1, %g3
  216. blu,pn %xcc, 2f
  217. cmp %g1, %g7
  218. bgeu,pn %xcc, 2f
  219. nop
  220. stxa %g0, [%l7] ASI_DMMU
  221. membar #Sync
  222. stxa %g0, [%l0] ASI_DTLB_DATA_ACCESS
  223. membar #Sync
  224. 2: and %l0, (511 << 3), %g1
  225. cmp %g1, (511 << 3)
  226. blu,pt %xcc, 1b
  227. add %l0, (1 << 3), %l0
  228. 9:
  229. /* Now lock the TTE we created into ITLB-0 and DTLB-0,
  230. * entry 15 (and maybe 14 too).
  231. */
  232. sethi %hi(KERNBASE), %g3
  233. set (0 << 16) | (15 << 3), %g7
  234. stxa %g3, [%l7] ASI_DMMU
  235. membar #Sync
  236. stxa %g5, [%g7] ASI_DTLB_DATA_ACCESS
  237. membar #Sync
  238. stxa %g3, [%l7] ASI_IMMU
  239. membar #Sync
  240. stxa %g5, [%g7] ASI_ITLB_DATA_ACCESS
  241. membar #Sync
  242. flush %g3
  243. membar #Sync
  244. sethi %hi(_end), %g3 /* Check for bigkernel case */
  245. or %g3, %lo(_end), %g3
  246. srl %g3, 23, %g3 /* Check if _end > 8M */
  247. brz,pt %g3, 1f
  248. sethi %hi(KERNBASE), %g3 /* Restore for fixup code below */
  249. sethi %hi(0x400000), %g3
  250. or %g3, %lo(0x400000), %g3
  251. add %g5, %g3, %g5 /* New tte data */
  252. andn %g5, (_PAGE_G), %g5
  253. sethi %hi(KERNBASE+0x400000), %g3
  254. or %g3, %lo(KERNBASE+0x400000), %g3
  255. set (0 << 16) | (14 << 3), %g7
  256. stxa %g3, [%l7] ASI_DMMU
  257. membar #Sync
  258. stxa %g5, [%g7] ASI_DTLB_DATA_ACCESS
  259. membar #Sync
  260. stxa %g3, [%l7] ASI_IMMU
  261. membar #Sync
  262. stxa %g5, [%g7] ASI_ITLB_DATA_ACCESS
  263. membar #Sync
  264. flush %g3
  265. membar #Sync
  266. sethi %hi(KERNBASE), %g3 /* Restore for fixup code below */
  267. ba,pt %xcc, 1f
  268. nop
  269. 1: set sun4u_init, %g2
  270. jmpl %g2 + %g0, %g0
  271. nop
  272. spitfire_boot:
  273. /* Typically PROM has already enabled both MMU's and both on-chip
  274. * caches, but we do it here anyway just to be paranoid.
  275. */
  276. mov (LSU_CONTROL_IC|LSU_CONTROL_DC|LSU_CONTROL_IM|LSU_CONTROL_DM), %g1
  277. stxa %g1, [%g0] ASI_LSU_CONTROL
  278. membar #Sync
  279. /*
  280. * Make sure we are in privileged mode, have address masking,
  281. * using the ordinary globals and have enabled floating
  282. * point.
  283. *
  284. * Again, typically PROM has left %pil at 13 or similar, and
  285. * (PSTATE_PRIV | PSTATE_PEF | PSTATE_IE) in %pstate.
  286. */
  287. wrpr %g0, (PSTATE_PRIV|PSTATE_PEF|PSTATE_IE), %pstate
  288. wr %g0, 0, %fprs
  289. spitfire_create_mappings:
  290. /* %g5 holds the tlb data */
  291. sethi %uhi(_PAGE_VALID | _PAGE_SZ4MB), %g5
  292. sllx %g5, 32, %g5
  293. or %g5, (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_L | _PAGE_W | _PAGE_G), %g5
  294. /* Base of physical memory cannot reliably be assumed to be
  295. * at 0x0! Figure out where it happens to be. -DaveM
  296. */
  297. /* Put PADDR tlb data mask into %g3. */
  298. sethi %uhi(_PAGE_PADDR_SF), %g3
  299. or %g3, %ulo(_PAGE_PADDR_SF), %g3
  300. sllx %g3, 32, %g3
  301. sethi %hi(_PAGE_PADDR_SF), %g7
  302. or %g7, %lo(_PAGE_PADDR_SF), %g7
  303. or %g3, %g7, %g3
  304. /* Walk through entire ITLB, looking for entry which maps
  305. * our %pc currently, stick PADDR from there into %g5 tlb data.
  306. */
  307. clr %l0 /* TLB entry walker. */
  308. set 0x1fff, %l2 /* Page mask. */
  309. rd %pc, %l3
  310. andn %l3, %l2, %g2 /* vaddr comparator */
  311. 1:
  312. /* Yes, the nops seem to be necessary for now, don't ask me why. -DaveM */
  313. ldxa [%l0] ASI_ITLB_TAG_READ, %g1
  314. nop
  315. nop
  316. nop
  317. andn %g1, %l2, %g1 /* Get vaddr */
  318. cmp %g1, %g2
  319. be,a,pn %xcc, spitfire_got_tlbentry
  320. ldxa [%l0] ASI_ITLB_DATA_ACCESS, %g1
  321. cmp %l0, (63 << 3)
  322. blu,pt %xcc, 1b
  323. add %l0, (1 << 3), %l0
  324. /* BUG() if we get here... */
  325. ta 0x5
  326. spitfire_got_tlbentry:
  327. /* Nops here again, perhaps Cheetah/Blackbird are better behaved... */
  328. nop
  329. nop
  330. nop
  331. and %g1, %g3, %g1 /* Mask to just get paddr bits. */
  332. set 0x5fff, %l3 /* Mask offset to get phys base. */
  333. andn %g1, %l3, %g1
  334. /* NOTE: We hold on to %g1 paddr base as we need it below to lock
  335. * NOTE: the PROM cif code into the TLB.
  336. */
  337. or %g5, %g1, %g5 /* Or it into TAG being built. */
  338. clr %l0 /* TLB entry walker. */
  339. sethi %hi(KERNBASE), %g3 /* 4M lower limit */
  340. sethi %hi(KERNBASE<<1), %g7 /* 8M upper limit */
  341. mov TLB_TAG_ACCESS, %l7
  342. 1:
  343. /* Yes, the nops seem to be necessary for now, don't ask me why. -DaveM */
  344. ldxa [%l0] ASI_ITLB_TAG_READ, %g1
  345. nop
  346. nop
  347. nop
  348. andn %g1, %l2, %g1 /* Get vaddr */
  349. cmp %g1, %g3
  350. blu,pn %xcc, 2f
  351. cmp %g1, %g7
  352. bgeu,pn %xcc, 2f
  353. nop
  354. stxa %g0, [%l7] ASI_IMMU
  355. stxa %g0, [%l0] ASI_ITLB_DATA_ACCESS
  356. membar #Sync
  357. 2:
  358. cmp %l0, (63 << 3)
  359. blu,pt %xcc, 1b
  360. add %l0, (1 << 3), %l0
  361. nop; nop; nop
  362. clr %l0 /* TLB entry walker. */
  363. 1:
  364. /* Yes, the nops seem to be necessary for now, don't ask me why. -DaveM */
  365. ldxa [%l0] ASI_DTLB_TAG_READ, %g1
  366. nop
  367. nop
  368. nop
  369. andn %g1, %l2, %g1 /* Get vaddr */
  370. cmp %g1, %g3
  371. blu,pn %xcc, 2f
  372. cmp %g1, %g7
  373. bgeu,pn %xcc, 2f
  374. nop
  375. stxa %g0, [%l7] ASI_DMMU
  376. stxa %g0, [%l0] ASI_DTLB_DATA_ACCESS
  377. membar #Sync
  378. 2:
  379. cmp %l0, (63 << 3)
  380. blu,pt %xcc, 1b
  381. add %l0, (1 << 3), %l0
  382. nop; nop; nop
  383. /* PROM never puts any TLB entries into the MMU with the lock bit
  384. * set. So we gladly use tlb entry 63 for KERNBASE. And maybe 62 too.
  385. */
  386. sethi %hi(KERNBASE), %g3
  387. mov (63 << 3), %g7
  388. stxa %g3, [%l7] ASI_DMMU /* KERNBASE into TLB TAG */
  389. stxa %g5, [%g7] ASI_DTLB_DATA_ACCESS /* TTE into TLB DATA */
  390. membar #Sync
  391. stxa %g3, [%l7] ASI_IMMU /* KERNBASE into TLB TAG */
  392. stxa %g5, [%g7] ASI_ITLB_DATA_ACCESS /* TTE into TLB DATA */
  393. membar #Sync
  394. flush %g3
  395. membar #Sync
  396. sethi %hi(_end), %g3 /* Check for bigkernel case */
  397. or %g3, %lo(_end), %g3
  398. srl %g3, 23, %g3 /* Check if _end > 8M */
  399. brz,pt %g3, 2f
  400. sethi %hi(KERNBASE), %g3 /* Restore for fixup code below */
  401. sethi %hi(0x400000), %g3
  402. or %g3, %lo(0x400000), %g3
  403. add %g5, %g3, %g5 /* New tte data */
  404. andn %g5, (_PAGE_G), %g5
  405. sethi %hi(KERNBASE+0x400000), %g3
  406. or %g3, %lo(KERNBASE+0x400000), %g3
  407. mov (62 << 3), %g7
  408. stxa %g3, [%l7] ASI_DMMU
  409. stxa %g5, [%g7] ASI_DTLB_DATA_ACCESS
  410. membar #Sync
  411. stxa %g3, [%l7] ASI_IMMU
  412. stxa %g5, [%g7] ASI_ITLB_DATA_ACCESS
  413. membar #Sync
  414. flush %g3
  415. membar #Sync
  416. sethi %hi(KERNBASE), %g3 /* Restore for fixup code below */
  417. 2: ba,pt %xcc, 1f
  418. nop
  419. 1:
  420. set sun4u_init, %g2
  421. jmpl %g2 + %g0, %g0
  422. nop
  423. sun4u_init:
  424. /* Set ctx 0 */
  425. mov PRIMARY_CONTEXT, %g7
  426. stxa %g0, [%g7] ASI_DMMU
  427. membar #Sync
  428. mov SECONDARY_CONTEXT, %g7
  429. stxa %g0, [%g7] ASI_DMMU
  430. membar #Sync
  431. /* We are now safely (we hope) in Nucleus context (0), rewrite
  432. * the KERNBASE TTE's so they no longer have the global bit set.
  433. * Don't forget to setup TAG_ACCESS first 8-)
  434. */
  435. mov TLB_TAG_ACCESS, %g2
  436. stxa %g3, [%g2] ASI_IMMU
  437. stxa %g3, [%g2] ASI_DMMU
  438. membar #Sync
  439. BRANCH_IF_ANY_CHEETAH(g1,g7,cheetah_tlb_fixup)
  440. ba,pt %xcc, spitfire_tlb_fixup
  441. nop
  442. cheetah_tlb_fixup:
  443. set (0 << 16) | (15 << 3), %g7
  444. ldxa [%g7] ASI_ITLB_DATA_ACCESS, %g0
  445. ldxa [%g7] ASI_ITLB_DATA_ACCESS, %g1
  446. andn %g1, (_PAGE_G), %g1
  447. stxa %g1, [%g7] ASI_ITLB_DATA_ACCESS
  448. membar #Sync
  449. ldxa [%g7] ASI_DTLB_DATA_ACCESS, %g0
  450. ldxa [%g7] ASI_DTLB_DATA_ACCESS, %g1
  451. andn %g1, (_PAGE_G), %g1
  452. stxa %g1, [%g7] ASI_DTLB_DATA_ACCESS
  453. membar #Sync
  454. /* Kill instruction prefetch queues. */
  455. flush %g3
  456. membar #Sync
  457. mov 2, %g2 /* Set TLB type to cheetah+. */
  458. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g7,1f)
  459. mov 1, %g2 /* Set TLB type to cheetah. */
  460. 1: sethi %hi(tlb_type), %g1
  461. stw %g2, [%g1 + %lo(tlb_type)]
  462. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g7,1f)
  463. ba,pt %xcc, 2f
  464. nop
  465. 1: /* Patch context register writes to support nucleus page
  466. * size correctly.
  467. */
  468. call cheetah_plus_patch_etrap
  469. nop
  470. call cheetah_plus_patch_rtrap
  471. nop
  472. call cheetah_plus_patch_fpdis
  473. nop
  474. call cheetah_plus_patch_winfixup
  475. nop
  476. 2: /* Patch copy/page operations to cheetah optimized versions. */
  477. call cheetah_patch_copyops
  478. nop
  479. call cheetah_patch_copy_page
  480. nop
  481. call cheetah_patch_cachetlbops
  482. nop
  483. ba,pt %xcc, tlb_fixup_done
  484. nop
  485. spitfire_tlb_fixup:
  486. mov (63 << 3), %g7
  487. ldxa [%g7] ASI_ITLB_DATA_ACCESS, %g1
  488. andn %g1, (_PAGE_G), %g1
  489. stxa %g1, [%g7] ASI_ITLB_DATA_ACCESS
  490. membar #Sync
  491. ldxa [%g7] ASI_DTLB_DATA_ACCESS, %g1
  492. andn %g1, (_PAGE_G), %g1
  493. stxa %g1, [%g7] ASI_DTLB_DATA_ACCESS
  494. membar #Sync
  495. /* Kill instruction prefetch queues. */
  496. flush %g3
  497. membar #Sync
  498. /* Set TLB type to spitfire. */
  499. mov 0, %g2
  500. sethi %hi(tlb_type), %g1
  501. stw %g2, [%g1 + %lo(tlb_type)]
  502. tlb_fixup_done:
  503. sethi %hi(init_thread_union), %g6
  504. or %g6, %lo(init_thread_union), %g6
  505. ldx [%g6 + TI_TASK], %g4
  506. mov %sp, %l6
  507. mov %o4, %l7
  508. #if 0 /* We don't do it like this anymore, but for historical hack value
  509. * I leave this snippet here to show how crazy we can be sometimes. 8-)
  510. */
  511. /* Setup "Linux Current Register", thanks Sun 8-) */
  512. wr %g0, 0x1, %pcr
  513. /* Blackbird errata workaround. See commentary in
  514. * smp.c:smp_percpu_timer_interrupt() for more
  515. * information.
  516. */
  517. ba,pt %xcc, 99f
  518. nop
  519. .align 64
  520. 99: wr %g6, %g0, %pic
  521. rd %pic, %g0
  522. #endif
  523. wr %g0, ASI_P, %asi
  524. mov 1, %g1
  525. sllx %g1, THREAD_SHIFT, %g1
  526. sub %g1, (STACKFRAME_SZ + STACK_BIAS), %g1
  527. add %g6, %g1, %sp
  528. mov 0, %fp
  529. /* Set per-cpu pointer initially to zero, this makes
  530. * the boot-cpu use the in-kernel-image per-cpu areas
  531. * before setup_per_cpu_area() is invoked.
  532. */
  533. clr %g5
  534. wrpr %g0, 0, %wstate
  535. wrpr %g0, 0x0, %tl
  536. /* Clear the bss */
  537. sethi %hi(__bss_start), %o0
  538. or %o0, %lo(__bss_start), %o0
  539. sethi %hi(_end), %o1
  540. or %o1, %lo(_end), %o1
  541. call __bzero
  542. sub %o1, %o0, %o1
  543. mov %l6, %o1 ! OpenPROM stack
  544. call prom_init
  545. mov %l7, %o0 ! OpenPROM cif handler
  546. /* Off we go.... */
  547. call start_kernel
  548. nop
  549. /* Not reached... */
  550. /* IMPORTANT NOTE: Whenever making changes here, check
  551. * trampoline.S as well. -jj */
  552. .globl setup_tba
  553. setup_tba: /* i0 = is_starfire */
  554. save %sp, -160, %sp
  555. rdpr %tba, %g7
  556. sethi %hi(prom_tba), %o1
  557. or %o1, %lo(prom_tba), %o1
  558. stx %g7, [%o1]
  559. /* Setup "Linux" globals 8-) */
  560. rdpr %pstate, %o1
  561. mov %g6, %o2
  562. wrpr %o1, (PSTATE_AG|PSTATE_IE), %pstate
  563. sethi %hi(sparc64_ttable_tl0), %g1
  564. wrpr %g1, %tba
  565. mov %o2, %g6
  566. /* Set up MMU globals */
  567. wrpr %o1, (PSTATE_MG|PSTATE_IE), %pstate
  568. /* Set fixed globals used by dTLB miss handler. */
  569. #define KERN_HIGHBITS ((_PAGE_VALID|_PAGE_SZ4MB)^0xfffff80000000000)
  570. #define KERN_LOWBITS (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W)
  571. mov TSB_REG, %g1
  572. stxa %g0, [%g1] ASI_DMMU
  573. membar #Sync
  574. stxa %g0, [%g1] ASI_IMMU
  575. membar #Sync
  576. mov TLB_SFSR, %g1
  577. sethi %uhi(KERN_HIGHBITS), %g2
  578. or %g2, %ulo(KERN_HIGHBITS), %g2
  579. sllx %g2, 32, %g2
  580. or %g2, KERN_LOWBITS, %g2
  581. BRANCH_IF_ANY_CHEETAH(g3,g7,cheetah_vpte_base)
  582. ba,pt %xcc, spitfire_vpte_base
  583. nop
  584. cheetah_vpte_base:
  585. sethi %uhi(VPTE_BASE_CHEETAH), %g3
  586. or %g3, %ulo(VPTE_BASE_CHEETAH), %g3
  587. ba,pt %xcc, 2f
  588. sllx %g3, 32, %g3
  589. spitfire_vpte_base:
  590. sethi %uhi(VPTE_BASE_SPITFIRE), %g3
  591. or %g3, %ulo(VPTE_BASE_SPITFIRE), %g3
  592. sllx %g3, 32, %g3
  593. 2:
  594. clr %g7
  595. #undef KERN_HIGHBITS
  596. #undef KERN_LOWBITS
  597. /* Kill PROM timer */
  598. sethi %hi(0x80000000), %o2
  599. sllx %o2, 32, %o2
  600. wr %o2, 0, %tick_cmpr
  601. BRANCH_IF_ANY_CHEETAH(o2,o3,1f)
  602. ba,pt %xcc, 2f
  603. nop
  604. /* Disable STICK_INT interrupts. */
  605. 1:
  606. sethi %hi(0x80000000), %o2
  607. sllx %o2, 32, %o2
  608. wr %o2, %asr25
  609. /* Ok, we're done setting up all the state our trap mechanims needs,
  610. * now get back into normal globals and let the PROM know what is up.
  611. */
  612. 2:
  613. wrpr %g0, %g0, %wstate
  614. wrpr %o1, PSTATE_IE, %pstate
  615. call init_irqwork_curcpu
  616. nop
  617. call prom_set_trap_table
  618. sethi %hi(sparc64_ttable_tl0), %o0
  619. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g2,g3,1f)
  620. ba,pt %xcc, 2f
  621. nop
  622. 1: /* Start using proper page size encodings in ctx register. */
  623. sethi %uhi(CTX_CHEETAH_PLUS_NUC), %g3
  624. mov PRIMARY_CONTEXT, %g1
  625. sllx %g3, 32, %g3
  626. sethi %hi(CTX_CHEETAH_PLUS_CTX0), %g2
  627. or %g3, %g2, %g3
  628. stxa %g3, [%g1] ASI_DMMU
  629. membar #Sync
  630. 2:
  631. rdpr %pstate, %o1
  632. or %o1, PSTATE_IE, %o1
  633. wrpr %o1, 0, %pstate
  634. ret
  635. restore
  636. /*
  637. * The following skips make sure the trap table in ttable.S is aligned
  638. * on a 32K boundary as required by the v9 specs for TBA register.
  639. */
  640. sparc64_boot_end:
  641. .skip 0x2000 + _start - sparc64_boot_end
  642. bootup_user_stack_end:
  643. .skip 0x2000
  644. #ifdef CONFIG_SBUS
  645. /* This is just a hack to fool make depend config.h discovering
  646. strategy: As the .S files below need config.h, but
  647. make depend does not find it for them, we include config.h
  648. in head.S */
  649. #endif
  650. ! 0x0000000000408000
  651. #include "ttable.S"
  652. #include "systbls.S"
  653. .align 1024
  654. .globl swapper_pg_dir
  655. swapper_pg_dir:
  656. .word 0
  657. #include "etrap.S"
  658. #include "rtrap.S"
  659. #include "winfixup.S"
  660. #include "entry.S"
  661. /* This is just anal retentiveness on my part... */
  662. .align 16384
  663. .data
  664. .align 8
  665. .globl prom_tba, tlb_type
  666. prom_tba: .xword 0
  667. tlb_type: .word 0 /* Must NOT end up in BSS */
  668. .section ".fixup",#alloc,#execinstr
  669. .globl __ret_efault
  670. __ret_efault:
  671. ret
  672. restore %g0, -EFAULT, %o0