head_32.S 19 KB

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