head_32.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * head.S: The initial boot code for the Sparc port of Linux.
  4. *
  5. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  6. * Copyright (C) 1995,1999 Pete Zaitcev (zaitcev@yahoo.com)
  7. * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  8. * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  9. * Copyright (C) 1997 Michael A. Griffith (grif@acm.org)
  10. *
  11. * CompactPCI platform by Eric Brower, 1999.
  12. */
  13. #include <linux/export.h>
  14. #include <linux/version.h>
  15. #include <linux/init.h>
  16. #include <asm/head.h>
  17. #include <asm/asi.h>
  18. #include <asm/contregs.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/psr.h>
  21. #include <asm/page.h>
  22. #include <asm/kdebug.h>
  23. #include <asm/winmacro.h>
  24. #include <asm/thread_info.h> /* TI_UWINMASK */
  25. #include <asm/errno.h>
  26. #include <asm/pgtable.h> /* PGDIR_SHIFT */
  27. .data
  28. /* The following are used with the prom_vector node-ops to figure out
  29. * the cpu-type
  30. */
  31. .align 4
  32. .globl cputypval
  33. cputypval:
  34. .asciz "sun4m"
  35. .ascii " "
  36. /* Tested on SS-5, SS-10 */
  37. .align 4
  38. cputypvar:
  39. .asciz "compatible"
  40. .align 4
  41. notsup:
  42. .asciz "Sparc-Linux sun4/sun4c or MMU-less not supported\n\n"
  43. .align 4
  44. sun4e_notsup:
  45. .asciz "Sparc-Linux sun4e support does not exist\n\n"
  46. .align 4
  47. /* The trap-table - located in the __HEAD section */
  48. #include "ttable_32.S"
  49. .align PAGE_SIZE
  50. /* This was the only reasonable way I could think of to properly align
  51. * these page-table data structures.
  52. */
  53. .globl empty_zero_page
  54. empty_zero_page: .skip PAGE_SIZE
  55. EXPORT_SYMBOL(empty_zero_page)
  56. .global root_flags
  57. .global ram_flags
  58. .global root_dev
  59. .global sparc_ramdisk_image
  60. .global sparc_ramdisk_size
  61. /* This stuff has to be in sync with SILO and other potential boot loaders
  62. * Fields should be kept upward compatible and whenever any change is made,
  63. * HdrS version should be incremented.
  64. */
  65. .ascii "HdrS"
  66. .word LINUX_VERSION_CODE
  67. .half 0x0203 /* HdrS version */
  68. root_flags:
  69. .half 1
  70. root_dev:
  71. .half 0
  72. ram_flags:
  73. .half 0
  74. sparc_ramdisk_image:
  75. .word 0
  76. sparc_ramdisk_size:
  77. .word 0
  78. .word reboot_command
  79. .word 0, 0, 0
  80. .word _end
  81. /* Cool, here we go. Pick up the romvec pointer in %o0 and stash it in
  82. * %g7 and at prom_vector_p. And also quickly check whether we are on
  83. * a v0, v2, or v3 prom.
  84. */
  85. gokernel:
  86. /* Ok, it's nice to know, as early as possible, if we
  87. * are already mapped where we expect to be in virtual
  88. * memory. The Solaris /boot elf format bootloader
  89. * will peek into our elf header and load us where
  90. * we want to be, otherwise we have to re-map.
  91. *
  92. * Some boot loaders don't place the jmp'rs address
  93. * in %o7, so we do a pc-relative call to a local
  94. * label, then see what %o7 has.
  95. */
  96. mov %o7, %g4 ! Save %o7
  97. /* Jump to it, and pray... */
  98. current_pc:
  99. call 1f
  100. nop
  101. 1:
  102. mov %o7, %g3
  103. tst %o0
  104. bne 2f
  105. mov %g4, %o7 /* Previous %o7. */
  106. sethi %hi(no_sun4u_here), %l1
  107. jmpl %l1 + %lo(no_sun4u_here), %g0
  108. nop
  109. 2:
  110. mov %o0, %l0 ! stash away romvec
  111. mov %o0, %g7 ! put it here too
  112. mov %o1, %l1 ! stash away debug_vec too
  113. /* Ok, let's check out our run time program counter. */
  114. set current_pc, %g5
  115. cmp %g3, %g5
  116. be already_mapped
  117. nop
  118. /* %l6 will hold the offset we have to subtract
  119. * from absolute symbols in order to access areas
  120. * in our own image. If already mapped this is
  121. * just plain zero, else it is KERNBASE.
  122. */
  123. set KERNBASE, %l6
  124. b copy_prom_lvl14
  125. nop
  126. already_mapped:
  127. mov 0, %l6
  128. /* Copy over the Prom's level 14 clock handler. */
  129. copy_prom_lvl14:
  130. #if 1
  131. /* DJHR
  132. * preserve our linked/calculated instructions
  133. */
  134. set lvl14_save, %g1
  135. set t_irq14, %g3
  136. sub %g1, %l6, %g1 ! translate to physical
  137. sub %g3, %l6, %g3 ! translate to physical
  138. ldd [%g3], %g4
  139. std %g4, [%g1]
  140. ldd [%g3+8], %g4
  141. std %g4, [%g1+8]
  142. #endif
  143. rd %tbr, %g1
  144. andn %g1, 0xfff, %g1 ! proms trap table base
  145. or %g0, (0x1e<<4), %g2 ! offset to lvl14 intr
  146. or %g1, %g2, %g2
  147. set t_irq14, %g3
  148. sub %g3, %l6, %g3
  149. ldd [%g2], %g4
  150. std %g4, [%g3]
  151. ldd [%g2 + 0x8], %g4
  152. std %g4, [%g3 + 0x8] ! Copy proms handler
  153. /* DON'T TOUCH %l0 thru %l5 in these remapping routines,
  154. * we need their values afterwards!
  155. */
  156. /* Now check whether we are already mapped, if we
  157. * are we can skip all this garbage coming up.
  158. */
  159. copy_prom_done:
  160. cmp %l6, 0
  161. be go_to_highmem ! this will be a nop then
  162. nop
  163. /* Validate that we are in fact running on an
  164. * SRMMU based cpu.
  165. */
  166. set 0x4000, %g6
  167. cmp %g7, %g6
  168. bne not_a_sun4
  169. nop
  170. halt_notsup:
  171. ld [%g7 + 0x68], %o1
  172. set notsup, %o0
  173. sub %o0, %l6, %o0
  174. call %o1
  175. nop
  176. sethi %hi(halt_me), %o0
  177. jmpl %o0 + %lo(halt_me), %g0
  178. nop
  179. not_a_sun4:
  180. /* It looks like this is a machine we support.
  181. * Now find out what MMU we are dealing with
  182. * LEON - identified by the psr.impl field
  183. * Viking - identified by the psr.impl field
  184. * In all other cases a sun4m srmmu.
  185. * We check that the MMU is enabled in all cases.
  186. */
  187. /* Check if this is a LEON CPU */
  188. rd %psr, %g3
  189. srl %g3, PSR_IMPL_SHIFT, %g3
  190. and %g3, PSR_IMPL_SHIFTED_MASK, %g3
  191. cmp %g3, PSR_IMPL_LEON
  192. be leon_remap /* It is a LEON - jump */
  193. nop
  194. /* Sanity-check, is MMU enabled */
  195. lda [%g0] ASI_M_MMUREGS, %g1
  196. andcc %g1, 1, %g0
  197. be halt_notsup
  198. nop
  199. /* Check for a viking (TI) module. */
  200. cmp %g3, PSR_IMPL_TI
  201. bne srmmu_not_viking
  202. nop
  203. /* Figure out what kind of viking we are on.
  204. * We need to know if we have to play with the
  205. * AC bit and disable traps or not.
  206. */
  207. /* I've only seen MicroSparc's on SparcClassics with this
  208. * bit set.
  209. */
  210. set 0x800, %g2
  211. lda [%g0] ASI_M_MMUREGS, %g3 ! peek in the control reg
  212. and %g2, %g3, %g3
  213. subcc %g3, 0x0, %g0
  214. bnz srmmu_not_viking ! is in mbus mode
  215. nop
  216. rd %psr, %g3 ! DO NOT TOUCH %g3
  217. andn %g3, PSR_ET, %g2
  218. wr %g2, 0x0, %psr
  219. WRITE_PAUSE
  220. /* Get context table pointer, then convert to
  221. * a physical address, which is 36 bits.
  222. */
  223. set AC_M_CTPR, %g4
  224. lda [%g4] ASI_M_MMUREGS, %g4
  225. sll %g4, 0x4, %g4 ! We use this below
  226. ! DO NOT TOUCH %g4
  227. /* Set the AC bit in the Viking's MMU control reg. */
  228. lda [%g0] ASI_M_MMUREGS, %g5 ! DO NOT TOUCH %g5
  229. set 0x8000, %g6 ! AC bit mask
  230. or %g5, %g6, %g6 ! Or it in...
  231. sta %g6, [%g0] ASI_M_MMUREGS ! Close your eyes...
  232. /* Grrr, why does it seem like every other load/store
  233. * on the sun4m is in some ASI space...
  234. * Fine with me, let's get the pointer to the level 1
  235. * page table directory and fetch its entry.
  236. */
  237. lda [%g4] ASI_M_BYPASS, %o1 ! This is a level 1 ptr
  238. srl %o1, 0x4, %o1 ! Clear low 4 bits
  239. sll %o1, 0x8, %o1 ! Make physical
  240. /* Ok, pull in the PTD. */
  241. lda [%o1] ASI_M_BYPASS, %o2 ! This is the 0x0 16MB pgd
  242. /* Calculate to KERNBASE entry. */
  243. add %o1, KERNBASE >> (PGDIR_SHIFT - 2), %o3
  244. /* Poke the entry into the calculated address. */
  245. sta %o2, [%o3] ASI_M_BYPASS
  246. /* I don't get it Sun, if you engineered all these
  247. * boot loaders and the PROM (thank you for the debugging
  248. * features btw) why did you not have them load kernel
  249. * images up in high address space, since this is necessary
  250. * for ABI compliance anyways? Does this low-mapping provide
  251. * enhanced interoperability?
  252. *
  253. * "The PROM is the computer."
  254. */
  255. /* Ok, restore the MMU control register we saved in %g5 */
  256. sta %g5, [%g0] ASI_M_MMUREGS ! POW... ouch
  257. /* Turn traps back on. We saved it in %g3 earlier. */
  258. wr %g3, 0x0, %psr ! tick tock, tick tock
  259. /* Now we burn precious CPU cycles due to bad engineering. */
  260. WRITE_PAUSE
  261. /* Wow, all that just to move a 32-bit value from one
  262. * place to another... Jump to high memory.
  263. */
  264. b go_to_highmem
  265. nop
  266. srmmu_not_viking:
  267. /* This works on viking's in Mbus mode and all
  268. * other MBUS modules. It is virtually the same as
  269. * the above madness sans turning traps off and flipping
  270. * the AC bit.
  271. */
  272. set AC_M_CTPR, %g1
  273. lda [%g1] ASI_M_MMUREGS, %g1 ! get ctx table ptr
  274. sll %g1, 0x4, %g1 ! make physical addr
  275. lda [%g1] ASI_M_BYPASS, %g1 ! ptr to level 1 pg_table
  276. srl %g1, 0x4, %g1
  277. sll %g1, 0x8, %g1 ! make phys addr for l1 tbl
  278. lda [%g1] ASI_M_BYPASS, %g2 ! get level1 entry for 0x0
  279. add %g1, KERNBASE >> (PGDIR_SHIFT - 2), %g3
  280. sta %g2, [%g3] ASI_M_BYPASS ! place at KERNBASE entry
  281. b go_to_highmem
  282. nop ! wheee....
  283. leon_remap:
  284. /* Sanity-check, is MMU enabled */
  285. lda [%g0] ASI_LEON_MMUREGS, %g1
  286. andcc %g1, 1, %g0
  287. be halt_notsup
  288. nop
  289. /* Same code as in the srmmu_not_viking case,
  290. * with the LEON ASI for mmuregs
  291. */
  292. set AC_M_CTPR, %g1
  293. lda [%g1] ASI_LEON_MMUREGS, %g1 ! get ctx table ptr
  294. sll %g1, 0x4, %g1 ! make physical addr
  295. lda [%g1] ASI_M_BYPASS, %g1 ! ptr to level 1 pg_table
  296. srl %g1, 0x4, %g1
  297. sll %g1, 0x8, %g1 ! make phys addr for l1 tbl
  298. lda [%g1] ASI_M_BYPASS, %g2 ! get level1 entry for 0x0
  299. add %g1, KERNBASE >> (PGDIR_SHIFT - 2), %g3
  300. sta %g2, [%g3] ASI_M_BYPASS ! place at KERNBASE entry
  301. b go_to_highmem
  302. nop ! wheee....
  303. /* Now do a non-relative jump so that PC is in high-memory */
  304. go_to_highmem:
  305. set execute_in_high_mem, %g1
  306. jmpl %g1, %g0
  307. nop
  308. /* The code above should be at beginning and we have to take care about
  309. * short jumps, as branching to .init.text section from .text is usually
  310. * impossible */
  311. __INIT
  312. /* Acquire boot time privileged register values, this will help debugging.
  313. * I figure out and store nwindows and nwindowsm1 later on.
  314. */
  315. execute_in_high_mem:
  316. mov %l0, %o0 ! put back romvec
  317. mov %l1, %o1 ! and debug_vec
  318. sethi %hi(prom_vector_p), %g1
  319. st %o0, [%g1 + %lo(prom_vector_p)]
  320. sethi %hi(linux_dbvec), %g1
  321. st %o1, [%g1 + %lo(linux_dbvec)]
  322. /* Get the machine type via the romvec
  323. * getprops node operation
  324. */
  325. add %g7, 0x1c, %l1
  326. ld [%l1], %l0
  327. ld [%l0], %l0
  328. call %l0
  329. or %g0, %g0, %o0 ! next_node(0) = first_node
  330. or %o0, %g0, %g6
  331. sethi %hi(cputypvar), %o1 ! First node has cpu-arch
  332. or %o1, %lo(cputypvar), %o1
  333. sethi %hi(cputypval), %o2 ! information, the string
  334. or %o2, %lo(cputypval), %o2
  335. ld [%l1], %l0 ! 'compatible' tells
  336. ld [%l0 + 0xc], %l0 ! that we want 'sun4x' where
  337. call %l0 ! x is one of 'm', 'd' or 'e'.
  338. nop ! %o2 holds pointer
  339. ! to a buf where above string
  340. ! will get stored by the prom.
  341. /* Check value of "compatible" property.
  342. * "value" => "model"
  343. * leon => sparc_leon
  344. * sun4m => sun4m
  345. * sun4s => sun4m
  346. * sun4d => sun4d
  347. * sun4e => "no_sun4e_here"
  348. * '*' => "no_sun4u_here"
  349. * Check single letters only
  350. */
  351. set cputypval, %o2
  352. /* If cputypval[0] == 'l' (lower case letter L) this is leon */
  353. ldub [%o2], %l1
  354. cmp %l1, 'l'
  355. be leon_init
  356. nop
  357. /* Check cputypval[4] to find the sun model */
  358. ldub [%o2 + 0x4], %l1
  359. cmp %l1, 'm'
  360. be sun4m_init
  361. cmp %l1, 's'
  362. be sun4m_init
  363. cmp %l1, 'd'
  364. be sun4d_init
  365. cmp %l1, 'e'
  366. be no_sun4e_here ! Could be a sun4e.
  367. nop
  368. b no_sun4u_here ! AIEEE, a V9 sun4u... Get our BIG BROTHER kernel :))
  369. nop
  370. leon_init:
  371. /* LEON CPU - set boot_cpu_id */
  372. sethi %hi(boot_cpu_id), %g2 ! boot-cpu index
  373. #ifdef CONFIG_SMP
  374. ldub [%g2 + %lo(boot_cpu_id)], %g1
  375. cmp %g1, 0xff ! unset means first CPU
  376. be 1f
  377. sethi %hi(leon_smp_cpu_startup), %g1
  378. jmpl %g1 + %lo(leon_smp_cpu_startup), %g0
  379. nop
  380. 1:
  381. #endif
  382. /* Get CPU-ID from most significant 4-bit of ASR17 */
  383. rd %asr17, %g1
  384. srl %g1, 28, %g1
  385. /* Update boot_cpu_id only on boot cpu */
  386. stub %g1, [%g2 + %lo(boot_cpu_id)]
  387. ba continue_boot
  388. nop
  389. /* CPUID in bootbus can be found at PA 0xff0140000 */
  390. #define SUN4D_BOOTBUS_CPUID 0xf0140000
  391. sun4d_init:
  392. /* Need to patch call to handler_irq */
  393. set patch_handler_irq, %g4
  394. set sun4d_handler_irq, %g5
  395. sethi %hi(0x40000000), %g3 ! call
  396. sub %g5, %g4, %g5
  397. srl %g5, 2, %g5
  398. or %g5, %g3, %g5
  399. st %g5, [%g4]
  400. #ifdef CONFIG_SMP
  401. /* Get our CPU id out of bootbus */
  402. set SUN4D_BOOTBUS_CPUID, %g3
  403. lduba [%g3] ASI_M_CTL, %g3
  404. and %g3, 0xf8, %g3
  405. srl %g3, 3, %g4
  406. sta %g4, [%g0] ASI_M_VIKING_TMP1
  407. sethi %hi(boot_cpu_id), %g5
  408. stb %g4, [%g5 + %lo(boot_cpu_id)]
  409. #endif
  410. /* Fall through to sun4m_init */
  411. sun4m_init:
  412. /* Ok, the PROM could have done funny things and apple cider could still
  413. * be sitting in the fault status/address registers. Read them all to
  414. * clear them so we don't get magic faults later on.
  415. */
  416. /* This sucks, apparently this makes Vikings call prom panic, will fix later */
  417. 2:
  418. rd %psr, %o1
  419. srl %o1, PSR_IMPL_SHIFT, %o1 ! Get a type of the CPU
  420. subcc %o1, PSR_IMPL_TI, %g0 ! TI: Viking or MicroSPARC
  421. be continue_boot
  422. nop
  423. set AC_M_SFSR, %o0
  424. lda [%o0] ASI_M_MMUREGS, %g0
  425. set AC_M_SFAR, %o0
  426. lda [%o0] ASI_M_MMUREGS, %g0
  427. /* Fujitsu MicroSPARC-II has no asynchronous flavors of FARs */
  428. subcc %o1, 0, %g0
  429. be continue_boot
  430. nop
  431. set AC_M_AFSR, %o0
  432. lda [%o0] ASI_M_MMUREGS, %g0
  433. set AC_M_AFAR, %o0
  434. lda [%o0] ASI_M_MMUREGS, %g0
  435. nop
  436. continue_boot:
  437. /* Aieee, now set PC and nPC, enable traps, give ourselves a stack and it's
  438. * show-time!
  439. */
  440. /* Turn on Supervisor, EnableFloating, and all the PIL bits.
  441. * Also puts us in register window zero with traps off.
  442. */
  443. set (PSR_PS | PSR_S | PSR_PIL | PSR_EF), %g2
  444. wr %g2, 0x0, %psr
  445. WRITE_PAUSE
  446. /* I want a kernel stack NOW! */
  447. set init_thread_union, %g1
  448. set (THREAD_SIZE - STACKFRAME_SZ - TRACEREG_SZ), %g2
  449. add %g1, %g2, %sp
  450. mov 0, %fp /* And for good luck */
  451. /* Zero out our BSS section. */
  452. set __bss_start , %o0 ! First address of BSS
  453. set _end , %o1 ! Last address of BSS
  454. add %o0, 0x1, %o0
  455. 1:
  456. stb %g0, [%o0]
  457. subcc %o0, %o1, %g0
  458. bl 1b
  459. add %o0, 0x1, %o0
  460. /* If boot_cpu_id has not been setup by machine specific
  461. * init-code above we default it to zero.
  462. */
  463. sethi %hi(boot_cpu_id), %g2
  464. ldub [%g2 + %lo(boot_cpu_id)], %g3
  465. cmp %g3, 0xff
  466. bne 1f
  467. nop
  468. mov %g0, %g3
  469. stub %g3, [%g2 + %lo(boot_cpu_id)]
  470. 1: sll %g3, 2, %g3
  471. /* Initialize the uwinmask value for init task just in case.
  472. * But first make current_set[boot_cpu_id] point to something useful.
  473. */
  474. set init_thread_union, %g6
  475. set current_set, %g2
  476. #ifdef CONFIG_SMP
  477. st %g6, [%g2]
  478. add %g2, %g3, %g2
  479. #endif
  480. st %g6, [%g2]
  481. st %g0, [%g6 + TI_UWINMASK]
  482. /* Compute NWINDOWS and stash it away. Now uses %wim trick explained
  483. * in the V8 manual. Ok, this method seems to work, Sparc is cool...
  484. * No, it doesn't work, have to play the save/readCWP/restore trick.
  485. */
  486. wr %g0, 0x0, %wim ! so we do not get a trap
  487. WRITE_PAUSE
  488. save
  489. rd %psr, %g3
  490. restore
  491. and %g3, 0x1f, %g3
  492. add %g3, 0x1, %g3
  493. mov 2, %g1
  494. wr %g1, 0x0, %wim ! make window 1 invalid
  495. WRITE_PAUSE
  496. cmp %g3, 0x7
  497. bne 2f
  498. nop
  499. /* Adjust our window handling routines to
  500. * do things correctly on 7 window Sparcs.
  501. */
  502. #define PATCH_INSN(src, dest) \
  503. set src, %g5; \
  504. set dest, %g2; \
  505. ld [%g5], %g4; \
  506. st %g4, [%g2];
  507. /* Patch for window spills... */
  508. PATCH_INSN(spnwin_patch1_7win, spnwin_patch1)
  509. PATCH_INSN(spnwin_patch2_7win, spnwin_patch2)
  510. PATCH_INSN(spnwin_patch3_7win, spnwin_patch3)
  511. /* Patch for window fills... */
  512. PATCH_INSN(fnwin_patch1_7win, fnwin_patch1)
  513. PATCH_INSN(fnwin_patch2_7win, fnwin_patch2)
  514. /* Patch for trap entry setup... */
  515. PATCH_INSN(tsetup_7win_patch1, tsetup_patch1)
  516. PATCH_INSN(tsetup_7win_patch2, tsetup_patch2)
  517. PATCH_INSN(tsetup_7win_patch3, tsetup_patch3)
  518. PATCH_INSN(tsetup_7win_patch4, tsetup_patch4)
  519. PATCH_INSN(tsetup_7win_patch5, tsetup_patch5)
  520. PATCH_INSN(tsetup_7win_patch6, tsetup_patch6)
  521. /* Patch for returning from traps... */
  522. PATCH_INSN(rtrap_7win_patch1, rtrap_patch1)
  523. PATCH_INSN(rtrap_7win_patch2, rtrap_patch2)
  524. PATCH_INSN(rtrap_7win_patch3, rtrap_patch3)
  525. PATCH_INSN(rtrap_7win_patch4, rtrap_patch4)
  526. PATCH_INSN(rtrap_7win_patch5, rtrap_patch5)
  527. /* Patch for killing user windows from the register file. */
  528. PATCH_INSN(kuw_patch1_7win, kuw_patch1)
  529. /* Now patch the kernel window flush sequences.
  530. * This saves 2 traps on every switch and fork.
  531. */
  532. set 0x01000000, %g4
  533. set flush_patch_one, %g5
  534. st %g4, [%g5 + 0x18]
  535. st %g4, [%g5 + 0x1c]
  536. set flush_patch_two, %g5
  537. st %g4, [%g5 + 0x18]
  538. st %g4, [%g5 + 0x1c]
  539. set flush_patch_three, %g5
  540. st %g4, [%g5 + 0x18]
  541. st %g4, [%g5 + 0x1c]
  542. set flush_patch_four, %g5
  543. st %g4, [%g5 + 0x18]
  544. st %g4, [%g5 + 0x1c]
  545. set flush_patch_exception, %g5
  546. st %g4, [%g5 + 0x18]
  547. st %g4, [%g5 + 0x1c]
  548. set flush_patch_switch, %g5
  549. st %g4, [%g5 + 0x18]
  550. st %g4, [%g5 + 0x1c]
  551. 2:
  552. sethi %hi(nwindows), %g4
  553. st %g3, [%g4 + %lo(nwindows)] ! store final value
  554. sub %g3, 0x1, %g3
  555. sethi %hi(nwindowsm1), %g4
  556. st %g3, [%g4 + %lo(nwindowsm1)]
  557. /* Here we go, start using Linux's trap table... */
  558. set trapbase, %g3
  559. wr %g3, 0x0, %tbr
  560. WRITE_PAUSE
  561. /* Finally, turn on traps so that we can call c-code. */
  562. rd %psr, %g3
  563. wr %g3, 0x0, %psr
  564. WRITE_PAUSE
  565. wr %g3, PSR_ET, %psr
  566. WRITE_PAUSE
  567. /* Call sparc32_start_kernel(struct linux_romvec *rp) */
  568. sethi %hi(prom_vector_p), %g5
  569. ld [%g5 + %lo(prom_vector_p)], %o0
  570. call sparc32_start_kernel
  571. nop
  572. /* We should not get here. */
  573. call halt_me
  574. nop
  575. no_sun4e_here:
  576. ld [%g7 + 0x68], %o1
  577. set sun4e_notsup, %o0
  578. call %o1
  579. nop
  580. b halt_me
  581. nop
  582. __INITDATA
  583. sun4u_1:
  584. .asciz "finddevice"
  585. .align 4
  586. sun4u_2:
  587. .asciz "/chosen"
  588. .align 4
  589. sun4u_3:
  590. .asciz "getprop"
  591. .align 4
  592. sun4u_4:
  593. .asciz "stdout"
  594. .align 4
  595. sun4u_5:
  596. .asciz "write"
  597. .align 4
  598. sun4u_6:
  599. .asciz "\n\rOn sun4u you have to use sparc64 kernel\n\rand not a sparc32 version\n\r\n\r"
  600. sun4u_6e:
  601. .align 4
  602. sun4u_7:
  603. .asciz "exit"
  604. .align 8
  605. sun4u_a1:
  606. .word 0, sun4u_1, 0, 1, 0, 1, 0, sun4u_2, 0
  607. sun4u_r1:
  608. .word 0
  609. sun4u_a2:
  610. .word 0, sun4u_3, 0, 4, 0, 1, 0
  611. sun4u_i2:
  612. .word 0, 0, sun4u_4, 0, sun4u_1, 0, 8, 0
  613. sun4u_r2:
  614. .word 0
  615. sun4u_a3:
  616. .word 0, sun4u_5, 0, 3, 0, 1, 0
  617. sun4u_i3:
  618. .word 0, 0, sun4u_6, 0, sun4u_6e - sun4u_6 - 1, 0
  619. sun4u_r3:
  620. .word 0
  621. sun4u_a4:
  622. .word 0, sun4u_7, 0, 0, 0, 0
  623. sun4u_r4:
  624. __INIT
  625. no_sun4u_here:
  626. set sun4u_a1, %o0
  627. set current_pc, %l2
  628. cmp %l2, %g3
  629. be 1f
  630. mov %o4, %l0
  631. sub %g3, %l2, %l6
  632. add %o0, %l6, %o0
  633. mov %o0, %l4
  634. mov sun4u_r4 - sun4u_a1, %l3
  635. ld [%l4], %l5
  636. 2:
  637. add %l4, 4, %l4
  638. cmp %l5, %l2
  639. add %l5, %l6, %l5
  640. bgeu,a 3f
  641. st %l5, [%l4 - 4]
  642. 3:
  643. subcc %l3, 4, %l3
  644. bne 2b
  645. ld [%l4], %l5
  646. 1:
  647. call %l0
  648. mov %o0, %l1
  649. ld [%l1 + (sun4u_r1 - sun4u_a1)], %o1
  650. add %l1, (sun4u_a2 - sun4u_a1), %o0
  651. call %l0
  652. st %o1, [%o0 + (sun4u_i2 - sun4u_a2)]
  653. ld [%l1 + (sun4u_1 - sun4u_a1)], %o1
  654. add %l1, (sun4u_a3 - sun4u_a1), %o0
  655. call %l0
  656. st %o1, [%o0 + (sun4u_i3 - sun4u_a3)]
  657. call %l0
  658. add %l1, (sun4u_a4 - sun4u_a1), %o0
  659. /* Not reached */
  660. halt_me:
  661. ld [%g7 + 0x74], %o0
  662. call %o0 ! Get us out of here...
  663. nop ! Apparently Solaris is better.
  664. /* Ok, now we continue in the .data/.text sections */
  665. .data
  666. .align 4
  667. /*
  668. * Fill up the prom vector, note in particular the kind first element,
  669. * no joke. I don't need all of them in here as the entire prom vector
  670. * gets initialized in c-code so all routines can use it.
  671. */
  672. prom_vector_p:
  673. .word 0
  674. /* We calculate the following at boot time, window fills/spills and trap entry
  675. * code uses these to keep track of the register windows.
  676. */
  677. .align 4
  678. .globl nwindows
  679. .globl nwindowsm1
  680. nwindows:
  681. .word 8
  682. nwindowsm1:
  683. .word 7
  684. /* Boot time debugger vector value. We need this later on. */
  685. .align 4
  686. .globl linux_dbvec
  687. linux_dbvec:
  688. .word 0
  689. .word 0
  690. .align 8
  691. .globl lvl14_save
  692. lvl14_save:
  693. .word 0
  694. .word 0
  695. .word 0
  696. .word 0
  697. .word t_irq14