head_32.S 19 KB

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