18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * head.S: The initial boot code for the Sparc port of Linux.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
68c2ecf20Sopenharmony_ci * Copyright (C) 1995,1999 Pete Zaitcev   (zaitcev@yahoo.com)
78c2ecf20Sopenharmony_ci * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
88c2ecf20Sopenharmony_ci * Copyright (C) 1997 Jakub Jelinek   (jj@sunsite.mff.cuni.cz)
98c2ecf20Sopenharmony_ci * Copyright (C) 1997 Michael A. Griffith (grif@acm.org)
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * CompactPCI platform by Eric Brower, 1999.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/version.h>
158c2ecf20Sopenharmony_ci#include <linux/init.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <asm/head.h>
188c2ecf20Sopenharmony_ci#include <asm/asi.h>
198c2ecf20Sopenharmony_ci#include <asm/contregs.h>
208c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
218c2ecf20Sopenharmony_ci#include <asm/psr.h>
228c2ecf20Sopenharmony_ci#include <asm/page.h>
238c2ecf20Sopenharmony_ci#include <asm/kdebug.h>
248c2ecf20Sopenharmony_ci#include <asm/winmacro.h>
258c2ecf20Sopenharmony_ci#include <asm/thread_info.h>	/* TI_UWINMASK */
268c2ecf20Sopenharmony_ci#include <asm/errno.h>
278c2ecf20Sopenharmony_ci#include <asm/pgtable.h>	/* PGDIR_SHIFT */
288c2ecf20Sopenharmony_ci#include <asm/export.h>
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	.data
318c2ecf20Sopenharmony_ci/* The following are used with the prom_vector node-ops to figure out
328c2ecf20Sopenharmony_ci * the cpu-type
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci	.align 4
358c2ecf20Sopenharmony_ci	.globl cputypval
368c2ecf20Sopenharmony_cicputypval:
378c2ecf20Sopenharmony_ci	.asciz "sun4m"
388c2ecf20Sopenharmony_ci	.ascii "     "
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* Tested on SS-5, SS-10 */
418c2ecf20Sopenharmony_ci	.align 4
428c2ecf20Sopenharmony_cicputypvar:
438c2ecf20Sopenharmony_ci	.asciz "compatible"
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	.align 4
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cinotsup:
488c2ecf20Sopenharmony_ci	.asciz	"Sparc-Linux sun4/sun4c or MMU-less not supported\n\n"
498c2ecf20Sopenharmony_ci	.align 4
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cisun4e_notsup:
528c2ecf20Sopenharmony_ci        .asciz  "Sparc-Linux sun4e support does not exist\n\n"
538c2ecf20Sopenharmony_ci	.align 4
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* The trap-table - located in the __HEAD section */
568c2ecf20Sopenharmony_ci#include "ttable_32.S"
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	.align PAGE_SIZE
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* This was the only reasonable way I could think of to properly align
618c2ecf20Sopenharmony_ci * these page-table data structures.
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_ci	.globl empty_zero_page
648c2ecf20Sopenharmony_ciempty_zero_page:	.skip PAGE_SIZE
658c2ecf20Sopenharmony_ciEXPORT_SYMBOL(empty_zero_page)
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	.global root_flags
688c2ecf20Sopenharmony_ci	.global ram_flags
698c2ecf20Sopenharmony_ci	.global root_dev
708c2ecf20Sopenharmony_ci	.global sparc_ramdisk_image
718c2ecf20Sopenharmony_ci	.global sparc_ramdisk_size
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* This stuff has to be in sync with SILO and other potential boot loaders
748c2ecf20Sopenharmony_ci * Fields should be kept upward compatible and whenever any change is made,
758c2ecf20Sopenharmony_ci * HdrS version should be incremented.
768c2ecf20Sopenharmony_ci */
778c2ecf20Sopenharmony_ci	.ascii	"HdrS"
788c2ecf20Sopenharmony_ci	.word	LINUX_VERSION_CODE
798c2ecf20Sopenharmony_ci	.half	0x0203		/* HdrS version */
808c2ecf20Sopenharmony_ciroot_flags:
818c2ecf20Sopenharmony_ci	.half	1
828c2ecf20Sopenharmony_ciroot_dev:
838c2ecf20Sopenharmony_ci	.half	0
848c2ecf20Sopenharmony_ciram_flags:
858c2ecf20Sopenharmony_ci	.half	0
868c2ecf20Sopenharmony_cisparc_ramdisk_image:
878c2ecf20Sopenharmony_ci	.word	0
888c2ecf20Sopenharmony_cisparc_ramdisk_size:
898c2ecf20Sopenharmony_ci	.word	0
908c2ecf20Sopenharmony_ci	.word	reboot_command
918c2ecf20Sopenharmony_ci	.word	0, 0, 0
928c2ecf20Sopenharmony_ci	.word	_end
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* Cool, here we go. Pick up the romvec pointer in %o0 and stash it in
958c2ecf20Sopenharmony_ci * %g7 and at prom_vector_p. And also quickly check whether we are on
968c2ecf20Sopenharmony_ci * a v0, v2, or v3 prom.
978c2ecf20Sopenharmony_ci */
988c2ecf20Sopenharmony_cigokernel:
998c2ecf20Sopenharmony_ci		/* Ok, it's nice to know, as early as possible, if we
1008c2ecf20Sopenharmony_ci		 * are already mapped where we expect to be in virtual
1018c2ecf20Sopenharmony_ci		 * memory.  The Solaris /boot elf format bootloader
1028c2ecf20Sopenharmony_ci		 * will peek into our elf header and load us where
1038c2ecf20Sopenharmony_ci		 * we want to be, otherwise we have to re-map.
1048c2ecf20Sopenharmony_ci		 *
1058c2ecf20Sopenharmony_ci		 * Some boot loaders don't place the jmp'rs address
1068c2ecf20Sopenharmony_ci		 * in %o7, so we do a pc-relative call to a local
1078c2ecf20Sopenharmony_ci		 * label, then see what %o7 has.
1088c2ecf20Sopenharmony_ci		 */
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci		mov	%o7, %g4		! Save %o7
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci		/* Jump to it, and pray... */
1138c2ecf20Sopenharmony_cicurrent_pc:
1148c2ecf20Sopenharmony_ci		call	1f
1158c2ecf20Sopenharmony_ci		 nop
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci1:
1188c2ecf20Sopenharmony_ci		mov	%o7, %g3
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci		tst	%o0
1218c2ecf20Sopenharmony_ci		be	no_sun4u_here
1228c2ecf20Sopenharmony_ci		 mov	%g4, %o7		/* Previous %o7. */
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci		mov	%o0, %l0		! stash away romvec
1258c2ecf20Sopenharmony_ci		mov	%o0, %g7		! put it here too
1268c2ecf20Sopenharmony_ci		mov	%o1, %l1		! stash away debug_vec too
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci		/* Ok, let's check out our run time program counter. */
1298c2ecf20Sopenharmony_ci		set	current_pc, %g5
1308c2ecf20Sopenharmony_ci		cmp	%g3, %g5
1318c2ecf20Sopenharmony_ci		be	already_mapped
1328c2ecf20Sopenharmony_ci		 nop
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci		/* %l6 will hold the offset we have to subtract
1358c2ecf20Sopenharmony_ci		 * from absolute symbols in order to access areas
1368c2ecf20Sopenharmony_ci		 * in our own image.  If already mapped this is
1378c2ecf20Sopenharmony_ci		 * just plain zero, else it is KERNBASE.
1388c2ecf20Sopenharmony_ci		 */
1398c2ecf20Sopenharmony_ci		set	KERNBASE, %l6
1408c2ecf20Sopenharmony_ci		b	copy_prom_lvl14
1418c2ecf20Sopenharmony_ci		 nop
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_cialready_mapped:
1448c2ecf20Sopenharmony_ci		mov	0, %l6
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci		/* Copy over the Prom's level 14 clock handler. */
1478c2ecf20Sopenharmony_cicopy_prom_lvl14:
1488c2ecf20Sopenharmony_ci#if 1
1498c2ecf20Sopenharmony_ci		/* DJHR
1508c2ecf20Sopenharmony_ci		 * preserve our linked/calculated instructions
1518c2ecf20Sopenharmony_ci		 */
1528c2ecf20Sopenharmony_ci		set	lvl14_save, %g1
1538c2ecf20Sopenharmony_ci		set	t_irq14, %g3
1548c2ecf20Sopenharmony_ci		sub	%g1, %l6, %g1		! translate to physical
1558c2ecf20Sopenharmony_ci		sub	%g3, %l6, %g3		! translate to physical
1568c2ecf20Sopenharmony_ci		ldd	[%g3], %g4
1578c2ecf20Sopenharmony_ci		std	%g4, [%g1]
1588c2ecf20Sopenharmony_ci		ldd	[%g3+8], %g4
1598c2ecf20Sopenharmony_ci		std	%g4, [%g1+8]
1608c2ecf20Sopenharmony_ci#endif
1618c2ecf20Sopenharmony_ci		rd	%tbr, %g1
1628c2ecf20Sopenharmony_ci		andn	%g1, 0xfff, %g1		! proms trap table base
1638c2ecf20Sopenharmony_ci		or	%g0, (0x1e<<4), %g2	! offset to lvl14 intr
1648c2ecf20Sopenharmony_ci		or	%g1, %g2, %g2
1658c2ecf20Sopenharmony_ci		set	t_irq14, %g3
1668c2ecf20Sopenharmony_ci		sub	%g3, %l6, %g3
1678c2ecf20Sopenharmony_ci		ldd	[%g2], %g4
1688c2ecf20Sopenharmony_ci		std	%g4, [%g3]
1698c2ecf20Sopenharmony_ci		ldd	[%g2 + 0x8], %g4
1708c2ecf20Sopenharmony_ci		std	%g4, [%g3 + 0x8]	! Copy proms handler
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/* DON'T TOUCH %l0 thru %l5 in these remapping routines,
1738c2ecf20Sopenharmony_ci * we need their values afterwards!
1748c2ecf20Sopenharmony_ci */
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci		/* Now check whether we are already mapped, if we
1778c2ecf20Sopenharmony_ci		 * are we can skip all this garbage coming up.
1788c2ecf20Sopenharmony_ci		 */
1798c2ecf20Sopenharmony_cicopy_prom_done:
1808c2ecf20Sopenharmony_ci		cmp	%l6, 0
1818c2ecf20Sopenharmony_ci		be	go_to_highmem		! this will be a nop then
1828c2ecf20Sopenharmony_ci		 nop
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci		/* Validate that we are in fact running on an
1858c2ecf20Sopenharmony_ci		 * SRMMU based cpu.
1868c2ecf20Sopenharmony_ci		 */
1878c2ecf20Sopenharmony_ci		set	0x4000, %g6
1888c2ecf20Sopenharmony_ci		cmp	%g7, %g6
1898c2ecf20Sopenharmony_ci		bne	not_a_sun4
1908c2ecf20Sopenharmony_ci		 nop
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cihalt_notsup:
1938c2ecf20Sopenharmony_ci		ld	[%g7 + 0x68], %o1
1948c2ecf20Sopenharmony_ci		set	notsup, %o0
1958c2ecf20Sopenharmony_ci		sub	%o0, %l6, %o0
1968c2ecf20Sopenharmony_ci		call	%o1
1978c2ecf20Sopenharmony_ci		 nop
1988c2ecf20Sopenharmony_ci		ba	halt_me
1998c2ecf20Sopenharmony_ci		 nop
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cinot_a_sun4:
2028c2ecf20Sopenharmony_ci		/* It looks like this is a machine we support.
2038c2ecf20Sopenharmony_ci		 * Now find out what MMU we are dealing with
2048c2ecf20Sopenharmony_ci		 * LEON - identified by the psr.impl field
2058c2ecf20Sopenharmony_ci		 * Viking - identified by the psr.impl field
2068c2ecf20Sopenharmony_ci		 * In all other cases a sun4m srmmu.
2078c2ecf20Sopenharmony_ci		 * We check that the MMU is enabled in all cases.
2088c2ecf20Sopenharmony_ci		 */
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci		/* Check if this is a LEON CPU */
2118c2ecf20Sopenharmony_ci		rd	%psr, %g3
2128c2ecf20Sopenharmony_ci		srl	%g3, PSR_IMPL_SHIFT, %g3
2138c2ecf20Sopenharmony_ci		and	%g3, PSR_IMPL_SHIFTED_MASK, %g3
2148c2ecf20Sopenharmony_ci		cmp	%g3, PSR_IMPL_LEON
2158c2ecf20Sopenharmony_ci		be	leon_remap		/* It is a LEON - jump */
2168c2ecf20Sopenharmony_ci		 nop
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci		/* Sanity-check, is MMU enabled */
2198c2ecf20Sopenharmony_ci		lda	[%g0] ASI_M_MMUREGS, %g1
2208c2ecf20Sopenharmony_ci		andcc	%g1, 1, %g0
2218c2ecf20Sopenharmony_ci		be	halt_notsup
2228c2ecf20Sopenharmony_ci		 nop
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci		/* Check for a viking (TI) module. */
2258c2ecf20Sopenharmony_ci		cmp	%g3, PSR_IMPL_TI
2268c2ecf20Sopenharmony_ci		bne	srmmu_not_viking
2278c2ecf20Sopenharmony_ci		 nop
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci		/* Figure out what kind of viking we are on.
2308c2ecf20Sopenharmony_ci		 * We need to know if we have to play with the
2318c2ecf20Sopenharmony_ci		 * AC bit and disable traps or not.
2328c2ecf20Sopenharmony_ci		 */
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci		/* I've only seen MicroSparc's on SparcClassics with this
2358c2ecf20Sopenharmony_ci		 * bit set.
2368c2ecf20Sopenharmony_ci		 */
2378c2ecf20Sopenharmony_ci		set	0x800, %g2
2388c2ecf20Sopenharmony_ci		lda	[%g0] ASI_M_MMUREGS, %g3	! peek in the control reg
2398c2ecf20Sopenharmony_ci		and	%g2, %g3, %g3
2408c2ecf20Sopenharmony_ci		subcc	%g3, 0x0, %g0
2418c2ecf20Sopenharmony_ci		bnz	srmmu_not_viking			! is in mbus mode
2428c2ecf20Sopenharmony_ci		 nop
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci		rd	%psr, %g3			! DO NOT TOUCH %g3
2458c2ecf20Sopenharmony_ci		andn	%g3, PSR_ET, %g2
2468c2ecf20Sopenharmony_ci		wr	%g2, 0x0, %psr
2478c2ecf20Sopenharmony_ci		WRITE_PAUSE
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci		/* Get context table pointer, then convert to
2508c2ecf20Sopenharmony_ci		 * a physical address, which is 36 bits.
2518c2ecf20Sopenharmony_ci		 */
2528c2ecf20Sopenharmony_ci		set	AC_M_CTPR, %g4
2538c2ecf20Sopenharmony_ci		lda	[%g4] ASI_M_MMUREGS, %g4
2548c2ecf20Sopenharmony_ci		sll	%g4, 0x4, %g4			! We use this below
2558c2ecf20Sopenharmony_ci							! DO NOT TOUCH %g4
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci		/* Set the AC bit in the Viking's MMU control reg. */
2588c2ecf20Sopenharmony_ci		lda	[%g0] ASI_M_MMUREGS, %g5	! DO NOT TOUCH %g5
2598c2ecf20Sopenharmony_ci		set	0x8000, %g6			! AC bit mask
2608c2ecf20Sopenharmony_ci		or	%g5, %g6, %g6			! Or it in...
2618c2ecf20Sopenharmony_ci		sta	%g6, [%g0] ASI_M_MMUREGS	! Close your eyes...
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci		/* Grrr, why does it seem like every other load/store
2648c2ecf20Sopenharmony_ci		 * on the sun4m is in some ASI space...
2658c2ecf20Sopenharmony_ci		 * Fine with me, let's get the pointer to the level 1
2668c2ecf20Sopenharmony_ci		 * page table directory and fetch its entry.
2678c2ecf20Sopenharmony_ci		 */
2688c2ecf20Sopenharmony_ci		lda	[%g4] ASI_M_BYPASS, %o1		! This is a level 1 ptr
2698c2ecf20Sopenharmony_ci		srl	%o1, 0x4, %o1			! Clear low 4 bits
2708c2ecf20Sopenharmony_ci		sll	%o1, 0x8, %o1			! Make physical
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci		/* Ok, pull in the PTD. */
2738c2ecf20Sopenharmony_ci		lda	[%o1] ASI_M_BYPASS, %o2		! This is the 0x0 16MB pgd
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci		/* Calculate to KERNBASE entry. */
2768c2ecf20Sopenharmony_ci		add	%o1, KERNBASE >> (PGDIR_SHIFT - 2), %o3
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci		/* Poke the entry into the calculated address. */
2798c2ecf20Sopenharmony_ci		sta	%o2, [%o3] ASI_M_BYPASS
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci		/* I don't get it Sun, if you engineered all these
2828c2ecf20Sopenharmony_ci		 * boot loaders and the PROM (thank you for the debugging
2838c2ecf20Sopenharmony_ci		 * features btw) why did you not have them load kernel
2848c2ecf20Sopenharmony_ci		 * images up in high address space, since this is necessary
2858c2ecf20Sopenharmony_ci		 * for ABI compliance anyways?  Does this low-mapping provide
2868c2ecf20Sopenharmony_ci		 * enhanced interoperability?
2878c2ecf20Sopenharmony_ci		 *
2888c2ecf20Sopenharmony_ci		 * "The PROM is the computer."
2898c2ecf20Sopenharmony_ci		 */
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci		/* Ok, restore the MMU control register we saved in %g5 */
2928c2ecf20Sopenharmony_ci		sta	%g5, [%g0] ASI_M_MMUREGS	! POW... ouch
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci		/* Turn traps back on.  We saved it in %g3 earlier. */
2958c2ecf20Sopenharmony_ci		wr	%g3, 0x0, %psr			! tick tock, tick tock
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci		/* Now we burn precious CPU cycles due to bad engineering. */
2988c2ecf20Sopenharmony_ci		WRITE_PAUSE
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci		/* Wow, all that just to move a 32-bit value from one
3018c2ecf20Sopenharmony_ci		 * place to another...  Jump to high memory.
3028c2ecf20Sopenharmony_ci		 */
3038c2ecf20Sopenharmony_ci		b	go_to_highmem
3048c2ecf20Sopenharmony_ci		 nop
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_cisrmmu_not_viking:
3078c2ecf20Sopenharmony_ci		/* This works on viking's in Mbus mode and all
3088c2ecf20Sopenharmony_ci		 * other MBUS modules.  It is virtually the same as
3098c2ecf20Sopenharmony_ci		 * the above madness sans turning traps off and flipping
3108c2ecf20Sopenharmony_ci		 * the AC bit.
3118c2ecf20Sopenharmony_ci		 */
3128c2ecf20Sopenharmony_ci		set	AC_M_CTPR, %g1
3138c2ecf20Sopenharmony_ci		lda	[%g1] ASI_M_MMUREGS, %g1	! get ctx table ptr
3148c2ecf20Sopenharmony_ci		sll	%g1, 0x4, %g1			! make physical addr
3158c2ecf20Sopenharmony_ci		lda	[%g1] ASI_M_BYPASS, %g1		! ptr to level 1 pg_table
3168c2ecf20Sopenharmony_ci		srl	%g1, 0x4, %g1
3178c2ecf20Sopenharmony_ci		sll	%g1, 0x8, %g1			! make phys addr for l1 tbl
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci		lda	[%g1] ASI_M_BYPASS, %g2		! get level1 entry for 0x0
3208c2ecf20Sopenharmony_ci		add	%g1, KERNBASE >> (PGDIR_SHIFT - 2), %g3
3218c2ecf20Sopenharmony_ci		sta	%g2, [%g3] ASI_M_BYPASS		! place at KERNBASE entry
3228c2ecf20Sopenharmony_ci		b	go_to_highmem
3238c2ecf20Sopenharmony_ci		 nop					! wheee....
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_cileon_remap:
3278c2ecf20Sopenharmony_ci		/* Sanity-check, is MMU enabled */
3288c2ecf20Sopenharmony_ci		lda	[%g0] ASI_LEON_MMUREGS, %g1
3298c2ecf20Sopenharmony_ci		andcc	%g1, 1, %g0
3308c2ecf20Sopenharmony_ci		be	halt_notsup
3318c2ecf20Sopenharmony_ci		 nop
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci		/* Same code as in the srmmu_not_viking case,
3348c2ecf20Sopenharmony_ci		 * with the LEON ASI for mmuregs
3358c2ecf20Sopenharmony_ci		 */
3368c2ecf20Sopenharmony_ci		set	AC_M_CTPR, %g1
3378c2ecf20Sopenharmony_ci		lda	[%g1] ASI_LEON_MMUREGS, %g1	! get ctx table ptr
3388c2ecf20Sopenharmony_ci		sll	%g1, 0x4, %g1			! make physical addr
3398c2ecf20Sopenharmony_ci		lda	[%g1] ASI_M_BYPASS, %g1		! ptr to level 1 pg_table
3408c2ecf20Sopenharmony_ci		srl	%g1, 0x4, %g1
3418c2ecf20Sopenharmony_ci		sll	%g1, 0x8, %g1			! make phys addr for l1 tbl
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci		lda	[%g1] ASI_M_BYPASS, %g2		! get level1 entry for 0x0
3448c2ecf20Sopenharmony_ci		add	%g1, KERNBASE >> (PGDIR_SHIFT - 2), %g3
3458c2ecf20Sopenharmony_ci		sta	%g2, [%g3] ASI_M_BYPASS		! place at KERNBASE entry
3468c2ecf20Sopenharmony_ci		b	go_to_highmem
3478c2ecf20Sopenharmony_ci		 nop					! wheee....
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci/* Now do a non-relative jump so that PC is in high-memory */
3508c2ecf20Sopenharmony_cigo_to_highmem:
3518c2ecf20Sopenharmony_ci		set	execute_in_high_mem, %g1
3528c2ecf20Sopenharmony_ci		jmpl	%g1, %g0
3538c2ecf20Sopenharmony_ci		 nop
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci/* The code above should be at beginning and we have to take care about
3568c2ecf20Sopenharmony_ci * short jumps, as branching to .init.text section from .text is usually
3578c2ecf20Sopenharmony_ci * impossible */
3588c2ecf20Sopenharmony_ci		__INIT
3598c2ecf20Sopenharmony_ci/* Acquire boot time privileged register values, this will help debugging.
3608c2ecf20Sopenharmony_ci * I figure out and store nwindows and nwindowsm1 later on.
3618c2ecf20Sopenharmony_ci */
3628c2ecf20Sopenharmony_ciexecute_in_high_mem:
3638c2ecf20Sopenharmony_ci		mov	%l0, %o0		! put back romvec
3648c2ecf20Sopenharmony_ci		mov	%l1, %o1		! and debug_vec
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci		sethi	%hi(prom_vector_p), %g1
3678c2ecf20Sopenharmony_ci		st	%o0, [%g1 + %lo(prom_vector_p)]
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci		sethi	%hi(linux_dbvec), %g1
3708c2ecf20Sopenharmony_ci		st	%o1, [%g1 + %lo(linux_dbvec)]
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci		/* Get the machine type via the romvec
3738c2ecf20Sopenharmony_ci		 * getprops node operation
3748c2ecf20Sopenharmony_ci		 */
3758c2ecf20Sopenharmony_ci		add	%g7, 0x1c, %l1
3768c2ecf20Sopenharmony_ci		ld	[%l1], %l0
3778c2ecf20Sopenharmony_ci		ld	[%l0], %l0
3788c2ecf20Sopenharmony_ci		call	%l0
3798c2ecf20Sopenharmony_ci		 or	%g0, %g0, %o0		! next_node(0) = first_node
3808c2ecf20Sopenharmony_ci		or	%o0, %g0, %g6
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci		sethi	%hi(cputypvar), %o1	! First node has cpu-arch
3838c2ecf20Sopenharmony_ci		or	%o1, %lo(cputypvar), %o1
3848c2ecf20Sopenharmony_ci		sethi	%hi(cputypval), %o2	! information, the string
3858c2ecf20Sopenharmony_ci		or	%o2, %lo(cputypval), %o2
3868c2ecf20Sopenharmony_ci		ld	[%l1], %l0		! 'compatible' tells
3878c2ecf20Sopenharmony_ci		ld	[%l0 + 0xc], %l0	! that we want 'sun4x' where
3888c2ecf20Sopenharmony_ci		call	%l0			! x is one of 'm', 'd' or 'e'.
3898c2ecf20Sopenharmony_ci		 nop				! %o2 holds pointer
3908c2ecf20Sopenharmony_ci						! to a buf where above string
3918c2ecf20Sopenharmony_ci						! will get stored by the prom.
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci		/* Check value of "compatible" property.
3958c2ecf20Sopenharmony_ci		 * "value" => "model"
3968c2ecf20Sopenharmony_ci		 * leon => sparc_leon
3978c2ecf20Sopenharmony_ci		 * sun4m => sun4m
3988c2ecf20Sopenharmony_ci		 * sun4s => sun4m
3998c2ecf20Sopenharmony_ci		 * sun4d => sun4d
4008c2ecf20Sopenharmony_ci		 * sun4e => "no_sun4e_here"
4018c2ecf20Sopenharmony_ci		 * '*'   => "no_sun4u_here"
4028c2ecf20Sopenharmony_ci		 * Check single letters only
4038c2ecf20Sopenharmony_ci		 */
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci		set	cputypval, %o2
4068c2ecf20Sopenharmony_ci		/* If cputypval[0] == 'l' (lower case letter L) this is leon */
4078c2ecf20Sopenharmony_ci		ldub	[%o2], %l1
4088c2ecf20Sopenharmony_ci		cmp	%l1, 'l'
4098c2ecf20Sopenharmony_ci		be	leon_init
4108c2ecf20Sopenharmony_ci		 nop
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci		/* Check cputypval[4] to find the sun model */
4138c2ecf20Sopenharmony_ci		ldub	[%o2 + 0x4], %l1
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci		cmp	%l1, 'm'
4168c2ecf20Sopenharmony_ci		be	sun4m_init
4178c2ecf20Sopenharmony_ci		 cmp	%l1, 's'
4188c2ecf20Sopenharmony_ci		be	sun4m_init
4198c2ecf20Sopenharmony_ci		 cmp	%l1, 'd'
4208c2ecf20Sopenharmony_ci		be	sun4d_init
4218c2ecf20Sopenharmony_ci		 cmp	%l1, 'e'
4228c2ecf20Sopenharmony_ci		be	no_sun4e_here		! Could be a sun4e.
4238c2ecf20Sopenharmony_ci		 nop
4248c2ecf20Sopenharmony_ci		b	no_sun4u_here		! AIEEE, a V9 sun4u... Get our BIG BROTHER kernel :))
4258c2ecf20Sopenharmony_ci		 nop
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_cileon_init:
4288c2ecf20Sopenharmony_ci		/* LEON CPU - set boot_cpu_id */
4298c2ecf20Sopenharmony_ci		sethi	%hi(boot_cpu_id), %g2	! boot-cpu index
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
4328c2ecf20Sopenharmony_ci		ldub	[%g2 + %lo(boot_cpu_id)], %g1
4338c2ecf20Sopenharmony_ci		cmp	%g1, 0xff		! unset means first CPU
4348c2ecf20Sopenharmony_ci		bne	leon_smp_cpu_startup	! continue only with master
4358c2ecf20Sopenharmony_ci		 nop
4368c2ecf20Sopenharmony_ci#endif
4378c2ecf20Sopenharmony_ci		/* Get CPU-ID from most significant 4-bit of ASR17 */
4388c2ecf20Sopenharmony_ci		rd     %asr17, %g1
4398c2ecf20Sopenharmony_ci		srl    %g1, 28, %g1
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci		/* Update boot_cpu_id only on boot cpu */
4428c2ecf20Sopenharmony_ci		stub	%g1, [%g2 + %lo(boot_cpu_id)]
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci		ba continue_boot
4458c2ecf20Sopenharmony_ci		 nop
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci/* CPUID in bootbus can be found at PA 0xff0140000 */
4488c2ecf20Sopenharmony_ci#define SUN4D_BOOTBUS_CPUID     0xf0140000
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_cisun4d_init:
4518c2ecf20Sopenharmony_ci	/* Need to patch call to handler_irq */
4528c2ecf20Sopenharmony_ci	set	patch_handler_irq, %g4
4538c2ecf20Sopenharmony_ci	set	sun4d_handler_irq, %g5
4548c2ecf20Sopenharmony_ci	sethi	%hi(0x40000000), %g3		! call
4558c2ecf20Sopenharmony_ci	sub	%g5, %g4, %g5
4568c2ecf20Sopenharmony_ci	srl	%g5, 2, %g5
4578c2ecf20Sopenharmony_ci	or	%g5, %g3, %g5
4588c2ecf20Sopenharmony_ci	st	%g5, [%g4]
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
4618c2ecf20Sopenharmony_ci	/* Get our CPU id out of bootbus */
4628c2ecf20Sopenharmony_ci	set     SUN4D_BOOTBUS_CPUID, %g3
4638c2ecf20Sopenharmony_ci	lduba   [%g3] ASI_M_CTL, %g3
4648c2ecf20Sopenharmony_ci	and     %g3, 0xf8, %g3
4658c2ecf20Sopenharmony_ci	srl     %g3, 3, %g4
4668c2ecf20Sopenharmony_ci	sta     %g4, [%g0] ASI_M_VIKING_TMP1
4678c2ecf20Sopenharmony_ci	sethi	%hi(boot_cpu_id), %g5
4688c2ecf20Sopenharmony_ci	stb	%g4, [%g5 + %lo(boot_cpu_id)]
4698c2ecf20Sopenharmony_ci#endif
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	/* Fall through to sun4m_init */
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_cisun4m_init:
4748c2ecf20Sopenharmony_ci/* Ok, the PROM could have done funny things and apple cider could still
4758c2ecf20Sopenharmony_ci * be sitting in the fault status/address registers.  Read them all to
4768c2ecf20Sopenharmony_ci * clear them so we don't get magic faults later on.
4778c2ecf20Sopenharmony_ci */
4788c2ecf20Sopenharmony_ci/* This sucks, apparently this makes Vikings call prom panic, will fix later */
4798c2ecf20Sopenharmony_ci2:
4808c2ecf20Sopenharmony_ci		rd	%psr, %o1
4818c2ecf20Sopenharmony_ci		srl	%o1, PSR_IMPL_SHIFT, %o1	! Get a type of the CPU
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci		subcc	%o1, PSR_IMPL_TI, %g0		! TI: Viking or MicroSPARC
4848c2ecf20Sopenharmony_ci		be	continue_boot
4858c2ecf20Sopenharmony_ci		 nop
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci		set	AC_M_SFSR, %o0
4888c2ecf20Sopenharmony_ci		lda	[%o0] ASI_M_MMUREGS, %g0
4898c2ecf20Sopenharmony_ci		set	AC_M_SFAR, %o0
4908c2ecf20Sopenharmony_ci		lda	[%o0] ASI_M_MMUREGS, %g0
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci		/* Fujitsu MicroSPARC-II has no asynchronous flavors of FARs */
4938c2ecf20Sopenharmony_ci		subcc	%o1, 0, %g0
4948c2ecf20Sopenharmony_ci		be	continue_boot
4958c2ecf20Sopenharmony_ci		 nop
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci		set	AC_M_AFSR, %o0
4988c2ecf20Sopenharmony_ci		lda	[%o0] ASI_M_MMUREGS, %g0
4998c2ecf20Sopenharmony_ci		set	AC_M_AFAR, %o0
5008c2ecf20Sopenharmony_ci		lda	[%o0] ASI_M_MMUREGS, %g0
5018c2ecf20Sopenharmony_ci		 nop
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_cicontinue_boot:
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci/* Aieee, now set PC and nPC, enable traps, give ourselves a stack and it's
5078c2ecf20Sopenharmony_ci * show-time!
5088c2ecf20Sopenharmony_ci */
5098c2ecf20Sopenharmony_ci		/* Turn on Supervisor, EnableFloating, and all the PIL bits.
5108c2ecf20Sopenharmony_ci		 * Also puts us in register window zero with traps off.
5118c2ecf20Sopenharmony_ci		 */
5128c2ecf20Sopenharmony_ci		set	(PSR_PS | PSR_S | PSR_PIL | PSR_EF), %g2
5138c2ecf20Sopenharmony_ci		wr	%g2, 0x0, %psr
5148c2ecf20Sopenharmony_ci		WRITE_PAUSE
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci		/* I want a kernel stack NOW! */
5178c2ecf20Sopenharmony_ci		set	init_thread_union, %g1
5188c2ecf20Sopenharmony_ci		set	(THREAD_SIZE - STACKFRAME_SZ), %g2
5198c2ecf20Sopenharmony_ci		add	%g1, %g2, %sp
5208c2ecf20Sopenharmony_ci		mov	0, %fp			/* And for good luck */
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci		/* Zero out our BSS section. */
5238c2ecf20Sopenharmony_ci		set	__bss_start , %o0	! First address of BSS
5248c2ecf20Sopenharmony_ci		set	_end , %o1		! Last address of BSS
5258c2ecf20Sopenharmony_ci		add	%o0, 0x1, %o0
5268c2ecf20Sopenharmony_ci1:
5278c2ecf20Sopenharmony_ci		stb	%g0, [%o0]
5288c2ecf20Sopenharmony_ci		subcc	%o0, %o1, %g0
5298c2ecf20Sopenharmony_ci		bl	1b
5308c2ecf20Sopenharmony_ci		 add	%o0, 0x1, %o0
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci		/* If boot_cpu_id has not been setup by machine specific
5338c2ecf20Sopenharmony_ci		 * init-code above we default it to zero.
5348c2ecf20Sopenharmony_ci		 */
5358c2ecf20Sopenharmony_ci		sethi	%hi(boot_cpu_id), %g2
5368c2ecf20Sopenharmony_ci		ldub	[%g2 + %lo(boot_cpu_id)], %g3
5378c2ecf20Sopenharmony_ci		cmp	%g3, 0xff
5388c2ecf20Sopenharmony_ci		bne	1f
5398c2ecf20Sopenharmony_ci		 nop
5408c2ecf20Sopenharmony_ci		mov	%g0, %g3
5418c2ecf20Sopenharmony_ci		stub	%g3, [%g2 + %lo(boot_cpu_id)]
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci1:		sll	%g3, 2, %g3
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_ci		/* Initialize the uwinmask value for init task just in case.
5468c2ecf20Sopenharmony_ci		 * But first make current_set[boot_cpu_id] point to something useful.
5478c2ecf20Sopenharmony_ci		 */
5488c2ecf20Sopenharmony_ci		set	init_thread_union, %g6
5498c2ecf20Sopenharmony_ci		set	current_set, %g2
5508c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
5518c2ecf20Sopenharmony_ci		st	%g6, [%g2]
5528c2ecf20Sopenharmony_ci		add	%g2, %g3, %g2
5538c2ecf20Sopenharmony_ci#endif
5548c2ecf20Sopenharmony_ci		st	%g6, [%g2]
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci		st	%g0, [%g6 + TI_UWINMASK]
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci/* Compute NWINDOWS and stash it away. Now uses %wim trick explained
5598c2ecf20Sopenharmony_ci * in the V8 manual. Ok, this method seems to work, Sparc is cool...
5608c2ecf20Sopenharmony_ci * No, it doesn't work, have to play the save/readCWP/restore trick.
5618c2ecf20Sopenharmony_ci */
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci		wr	%g0, 0x0, %wim			! so we do not get a trap
5648c2ecf20Sopenharmony_ci		WRITE_PAUSE
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci		save
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci		rd	%psr, %g3
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci		restore
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci		and	%g3, 0x1f, %g3
5738c2ecf20Sopenharmony_ci		add	%g3, 0x1, %g3
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci		mov	2, %g1
5768c2ecf20Sopenharmony_ci		wr	%g1, 0x0, %wim			! make window 1 invalid
5778c2ecf20Sopenharmony_ci		WRITE_PAUSE
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci		cmp	%g3, 0x7
5808c2ecf20Sopenharmony_ci		bne	2f
5818c2ecf20Sopenharmony_ci		 nop
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci		/* Adjust our window handling routines to
5848c2ecf20Sopenharmony_ci		 * do things correctly on 7 window Sparcs.
5858c2ecf20Sopenharmony_ci		 */
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci#define		PATCH_INSN(src, dest) \
5888c2ecf20Sopenharmony_ci		set	src, %g5; \
5898c2ecf20Sopenharmony_ci		set	dest, %g2; \
5908c2ecf20Sopenharmony_ci		ld	[%g5], %g4; \
5918c2ecf20Sopenharmony_ci		st	%g4, [%g2];
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci		/* Patch for window spills... */
5948c2ecf20Sopenharmony_ci		PATCH_INSN(spnwin_patch1_7win, spnwin_patch1)
5958c2ecf20Sopenharmony_ci		PATCH_INSN(spnwin_patch2_7win, spnwin_patch2)
5968c2ecf20Sopenharmony_ci		PATCH_INSN(spnwin_patch3_7win, spnwin_patch3)
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci		/* Patch for window fills... */
5998c2ecf20Sopenharmony_ci		PATCH_INSN(fnwin_patch1_7win, fnwin_patch1)
6008c2ecf20Sopenharmony_ci		PATCH_INSN(fnwin_patch2_7win, fnwin_patch2)
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci		/* Patch for trap entry setup... */
6038c2ecf20Sopenharmony_ci		PATCH_INSN(tsetup_7win_patch1, tsetup_patch1)
6048c2ecf20Sopenharmony_ci		PATCH_INSN(tsetup_7win_patch2, tsetup_patch2)
6058c2ecf20Sopenharmony_ci		PATCH_INSN(tsetup_7win_patch3, tsetup_patch3)
6068c2ecf20Sopenharmony_ci		PATCH_INSN(tsetup_7win_patch4, tsetup_patch4)
6078c2ecf20Sopenharmony_ci		PATCH_INSN(tsetup_7win_patch5, tsetup_patch5)
6088c2ecf20Sopenharmony_ci		PATCH_INSN(tsetup_7win_patch6, tsetup_patch6)
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci		/* Patch for returning from traps... */
6118c2ecf20Sopenharmony_ci		PATCH_INSN(rtrap_7win_patch1, rtrap_patch1)
6128c2ecf20Sopenharmony_ci		PATCH_INSN(rtrap_7win_patch2, rtrap_patch2)
6138c2ecf20Sopenharmony_ci		PATCH_INSN(rtrap_7win_patch3, rtrap_patch3)
6148c2ecf20Sopenharmony_ci		PATCH_INSN(rtrap_7win_patch4, rtrap_patch4)
6158c2ecf20Sopenharmony_ci		PATCH_INSN(rtrap_7win_patch5, rtrap_patch5)
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci		/* Patch for killing user windows from the register file. */
6188c2ecf20Sopenharmony_ci		PATCH_INSN(kuw_patch1_7win, kuw_patch1)
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci		/* Now patch the kernel window flush sequences.
6218c2ecf20Sopenharmony_ci		 * This saves 2 traps on every switch and fork.
6228c2ecf20Sopenharmony_ci		 */
6238c2ecf20Sopenharmony_ci		set	0x01000000, %g4
6248c2ecf20Sopenharmony_ci		set	flush_patch_one, %g5
6258c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x18]
6268c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x1c]
6278c2ecf20Sopenharmony_ci		set	flush_patch_two, %g5
6288c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x18]
6298c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x1c]
6308c2ecf20Sopenharmony_ci		set	flush_patch_three, %g5
6318c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x18]
6328c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x1c]
6338c2ecf20Sopenharmony_ci		set	flush_patch_four, %g5
6348c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x18]
6358c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x1c]
6368c2ecf20Sopenharmony_ci		set	flush_patch_exception, %g5
6378c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x18]
6388c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x1c]
6398c2ecf20Sopenharmony_ci		set	flush_patch_switch, %g5
6408c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x18]
6418c2ecf20Sopenharmony_ci		st	%g4, [%g5 + 0x1c]
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci2:
6448c2ecf20Sopenharmony_ci		sethi	%hi(nwindows), %g4
6458c2ecf20Sopenharmony_ci		st	%g3, [%g4 + %lo(nwindows)]	! store final value
6468c2ecf20Sopenharmony_ci		sub	%g3, 0x1, %g3
6478c2ecf20Sopenharmony_ci		sethi	%hi(nwindowsm1), %g4
6488c2ecf20Sopenharmony_ci		st	%g3, [%g4 + %lo(nwindowsm1)]
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci		/* Here we go, start using Linux's trap table... */
6518c2ecf20Sopenharmony_ci		set	trapbase, %g3
6528c2ecf20Sopenharmony_ci		wr	%g3, 0x0, %tbr
6538c2ecf20Sopenharmony_ci		WRITE_PAUSE
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci		/* Finally, turn on traps so that we can call c-code. */
6568c2ecf20Sopenharmony_ci		rd	%psr, %g3
6578c2ecf20Sopenharmony_ci		wr	%g3, 0x0, %psr
6588c2ecf20Sopenharmony_ci		WRITE_PAUSE
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci		wr	%g3, PSR_ET, %psr
6618c2ecf20Sopenharmony_ci		WRITE_PAUSE
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci		/* Call sparc32_start_kernel(struct linux_romvec *rp) */
6648c2ecf20Sopenharmony_ci		sethi	%hi(prom_vector_p), %g5
6658c2ecf20Sopenharmony_ci		ld	[%g5 + %lo(prom_vector_p)], %o0
6668c2ecf20Sopenharmony_ci		call	sparc32_start_kernel
6678c2ecf20Sopenharmony_ci		 nop
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci		/* We should not get here. */
6708c2ecf20Sopenharmony_ci		call	halt_me
6718c2ecf20Sopenharmony_ci		 nop
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_cino_sun4e_here:
6748c2ecf20Sopenharmony_ci		ld	[%g7 + 0x68], %o1
6758c2ecf20Sopenharmony_ci		set	sun4e_notsup, %o0
6768c2ecf20Sopenharmony_ci		call	%o1
6778c2ecf20Sopenharmony_ci		 nop
6788c2ecf20Sopenharmony_ci		b	halt_me
6798c2ecf20Sopenharmony_ci		 nop
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci		__INITDATA
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_cisun4u_1:
6848c2ecf20Sopenharmony_ci		.asciz "finddevice"
6858c2ecf20Sopenharmony_ci		.align	4
6868c2ecf20Sopenharmony_cisun4u_2:
6878c2ecf20Sopenharmony_ci		.asciz "/chosen"
6888c2ecf20Sopenharmony_ci		.align	4
6898c2ecf20Sopenharmony_cisun4u_3:
6908c2ecf20Sopenharmony_ci		.asciz "getprop"
6918c2ecf20Sopenharmony_ci		.align	4
6928c2ecf20Sopenharmony_cisun4u_4:
6938c2ecf20Sopenharmony_ci		.asciz "stdout"
6948c2ecf20Sopenharmony_ci		.align	4
6958c2ecf20Sopenharmony_cisun4u_5:
6968c2ecf20Sopenharmony_ci		.asciz "write"
6978c2ecf20Sopenharmony_ci		.align	4
6988c2ecf20Sopenharmony_cisun4u_6:
6998c2ecf20Sopenharmony_ci		.asciz  "\n\rOn sun4u you have to use sparc64 kernel\n\rand not a sparc32 version\n\r\n\r"
7008c2ecf20Sopenharmony_cisun4u_6e:
7018c2ecf20Sopenharmony_ci		.align	4
7028c2ecf20Sopenharmony_cisun4u_7:
7038c2ecf20Sopenharmony_ci		.asciz "exit"
7048c2ecf20Sopenharmony_ci		.align	8
7058c2ecf20Sopenharmony_cisun4u_a1:
7068c2ecf20Sopenharmony_ci		.word	0, sun4u_1, 0, 1, 0, 1, 0, sun4u_2, 0
7078c2ecf20Sopenharmony_cisun4u_r1:
7088c2ecf20Sopenharmony_ci		.word	0
7098c2ecf20Sopenharmony_cisun4u_a2:
7108c2ecf20Sopenharmony_ci		.word	0, sun4u_3, 0, 4, 0, 1, 0
7118c2ecf20Sopenharmony_cisun4u_i2:
7128c2ecf20Sopenharmony_ci		.word	0, 0, sun4u_4, 0, sun4u_1, 0, 8, 0
7138c2ecf20Sopenharmony_cisun4u_r2:
7148c2ecf20Sopenharmony_ci		.word	0
7158c2ecf20Sopenharmony_cisun4u_a3:
7168c2ecf20Sopenharmony_ci		.word	0, sun4u_5, 0, 3, 0, 1, 0
7178c2ecf20Sopenharmony_cisun4u_i3:
7188c2ecf20Sopenharmony_ci		.word	0, 0, sun4u_6, 0, sun4u_6e - sun4u_6 - 1, 0
7198c2ecf20Sopenharmony_cisun4u_r3:
7208c2ecf20Sopenharmony_ci		.word	0
7218c2ecf20Sopenharmony_cisun4u_a4:
7228c2ecf20Sopenharmony_ci		.word	0, sun4u_7, 0, 0, 0, 0
7238c2ecf20Sopenharmony_cisun4u_r4:
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci		__INIT
7268c2ecf20Sopenharmony_cino_sun4u_here:
7278c2ecf20Sopenharmony_ci		set	sun4u_a1, %o0
7288c2ecf20Sopenharmony_ci		set	current_pc, %l2
7298c2ecf20Sopenharmony_ci		cmp	%l2, %g3
7308c2ecf20Sopenharmony_ci		be	1f
7318c2ecf20Sopenharmony_ci		 mov	%o4, %l0
7328c2ecf20Sopenharmony_ci		sub	%g3, %l2, %l6
7338c2ecf20Sopenharmony_ci		add	%o0, %l6, %o0
7348c2ecf20Sopenharmony_ci		mov	%o0, %l4
7358c2ecf20Sopenharmony_ci		mov	sun4u_r4 - sun4u_a1, %l3
7368c2ecf20Sopenharmony_ci		ld	[%l4], %l5
7378c2ecf20Sopenharmony_ci2:
7388c2ecf20Sopenharmony_ci		add	%l4, 4, %l4
7398c2ecf20Sopenharmony_ci		cmp	%l5, %l2
7408c2ecf20Sopenharmony_ci		add	%l5, %l6, %l5
7418c2ecf20Sopenharmony_ci		bgeu,a	3f
7428c2ecf20Sopenharmony_ci		 st	%l5, [%l4 - 4]
7438c2ecf20Sopenharmony_ci3:
7448c2ecf20Sopenharmony_ci		subcc	%l3, 4, %l3
7458c2ecf20Sopenharmony_ci		bne	2b
7468c2ecf20Sopenharmony_ci		 ld	[%l4], %l5
7478c2ecf20Sopenharmony_ci1:
7488c2ecf20Sopenharmony_ci		call	%l0
7498c2ecf20Sopenharmony_ci		 mov	%o0, %l1
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_ci		ld	[%l1 + (sun4u_r1 - sun4u_a1)], %o1
7528c2ecf20Sopenharmony_ci		add	%l1, (sun4u_a2 - sun4u_a1), %o0
7538c2ecf20Sopenharmony_ci		call	%l0
7548c2ecf20Sopenharmony_ci		 st	%o1, [%o0 + (sun4u_i2 - sun4u_a2)]
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_ci		ld	[%l1 + (sun4u_1 - sun4u_a1)], %o1
7578c2ecf20Sopenharmony_ci		add	%l1, (sun4u_a3 - sun4u_a1), %o0
7588c2ecf20Sopenharmony_ci		call	%l0
7598c2ecf20Sopenharmony_ci		st	%o1, [%o0 + (sun4u_i3 - sun4u_a3)]
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_ci		call	%l0
7628c2ecf20Sopenharmony_ci		 add	%l1, (sun4u_a4 - sun4u_a1), %o0
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_ci		/* Not reached */
7658c2ecf20Sopenharmony_cihalt_me:
7668c2ecf20Sopenharmony_ci		ld	[%g7 + 0x74], %o0
7678c2ecf20Sopenharmony_ci		call	%o0			! Get us out of here...
7688c2ecf20Sopenharmony_ci		 nop				! Apparently Solaris is better.
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci/* Ok, now we continue in the .data/.text sections */
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ci	.data
7738c2ecf20Sopenharmony_ci	.align 4
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_ci/*
7768c2ecf20Sopenharmony_ci * Fill up the prom vector, note in particular the kind first element,
7778c2ecf20Sopenharmony_ci * no joke. I don't need all of them in here as the entire prom vector
7788c2ecf20Sopenharmony_ci * gets initialized in c-code so all routines can use it.
7798c2ecf20Sopenharmony_ci */
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ciprom_vector_p:
7828c2ecf20Sopenharmony_ci		.word 0
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci/* We calculate the following at boot time, window fills/spills and trap entry
7858c2ecf20Sopenharmony_ci * code uses these to keep track of the register windows.
7868c2ecf20Sopenharmony_ci */
7878c2ecf20Sopenharmony_ci
7888c2ecf20Sopenharmony_ci	.align 4
7898c2ecf20Sopenharmony_ci	.globl	nwindows
7908c2ecf20Sopenharmony_ci	.globl	nwindowsm1
7918c2ecf20Sopenharmony_cinwindows:
7928c2ecf20Sopenharmony_ci	.word	8
7938c2ecf20Sopenharmony_cinwindowsm1:
7948c2ecf20Sopenharmony_ci	.word	7
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ci/* Boot time debugger vector value.  We need this later on. */
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci	.align 4
7998c2ecf20Sopenharmony_ci	.globl	linux_dbvec
8008c2ecf20Sopenharmony_cilinux_dbvec:
8018c2ecf20Sopenharmony_ci	.word	0
8028c2ecf20Sopenharmony_ci	.word	0
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci	.align 8
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci	.globl	lvl14_save
8078c2ecf20Sopenharmony_cilvl14_save:
8088c2ecf20Sopenharmony_ci	.word	0
8098c2ecf20Sopenharmony_ci	.word	0
8108c2ecf20Sopenharmony_ci	.word	0
8118c2ecf20Sopenharmony_ci	.word	0
8128c2ecf20Sopenharmony_ci	.word	t_irq14
813