xref: /linux/arch/parisc/kernel/real2.S (revision 4add395bc77f19e2e5cedbef4368ffdebc89b165)
11da177e4SLinus Torvalds/*
21da177e4SLinus Torvalds *
31da177e4SLinus Torvalds * This file is subject to the terms and conditions of the GNU General Public
41da177e4SLinus Torvalds * License.  See the file "COPYING" in the main directory of this archive
51da177e4SLinus Torvalds * for more details.
61da177e4SLinus Torvalds *
71da177e4SLinus Torvalds * Copyright (C) 2000 Hewlett Packard (Paul Bame bame@puffin.external.hp.com)
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds */
10413059f2SGrant Grundler
116c86cb82SKyle McMartin#include <asm/pdc.h>
121da177e4SLinus Torvalds#include <asm/psw.h>
13896a3756SGrant Grundler#include <asm/assembly.h>
146c86cb82SKyle McMartin#include <asm/asm-offsets.h>
151da177e4SLinus Torvalds
168e9e9844SHelge Deller#include <linux/linkage.h>
178e9e9844SHelge Deller
181da177e4SLinus Torvalds	.export real_stack
191da177e4SLinus Torvalds	.export real64_stack
20*4add395bSHelge Deller	__PAGE_ALIGNED_BSS
211da177e4SLinus Torvaldsreal_stack:
221da177e4SLinus Torvaldsreal64_stack:
231da177e4SLinus Torvalds	.block	8192
241da177e4SLinus Torvalds
251da177e4SLinus Torvalds#define N_SAVED_REGS 9
26*4add395bSHelge Deller	.section	.bss
271da177e4SLinus Torvaldssave_cr_space:
281da177e4SLinus Torvalds	.block	REG_SZ * N_SAVED_REGS
291da177e4SLinus Torvaldssave_cr_end:
301da177e4SLinus Torvalds
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds/************************ 32-bit real-mode calls ***********************/
331da177e4SLinus Torvalds/* This can be called in both narrow and wide kernels */
341da177e4SLinus Torvalds
35dfcf753bSKyle McMartin	.text
361da177e4SLinus Torvalds
371da177e4SLinus Torvalds	/* unsigned long real32_call_asm(unsigned int *sp,
381da177e4SLinus Torvalds	 *		unsigned int *arg0p,
391da177e4SLinus Torvalds	 *		unsigned int iodc_fn)
401da177e4SLinus Torvalds	 *	sp is value of stack pointer to adopt before calling PDC (virt)
411da177e4SLinus Torvalds	 *	arg0p points to where saved arg values may be found
421da177e4SLinus Torvalds	 *	iodc_fn is the IODC function to call
431da177e4SLinus Torvalds	 */
441da177e4SLinus Torvalds
45f39cce65SHelge DellerENTRY_CFI(real32_call_asm)
461da177e4SLinus Torvalds	STREG	%rp, -RP_OFFSET(%sp)	/* save RP */
47413059f2SGrant Grundler#ifdef CONFIG_64BIT
481da177e4SLinus Torvalds	callee_save
491da177e4SLinus Torvalds	ldo	2*REG_SZ(%sp), %sp	/* room for a couple more saves */
501da177e4SLinus Torvalds	STREG	%r27, -1*REG_SZ(%sp)
511da177e4SLinus Torvalds	STREG	%r29, -2*REG_SZ(%sp)
521da177e4SLinus Torvalds#endif
531da177e4SLinus Torvalds	STREG	%sp, -REG_SZ(%arg0)	/* save SP on real-mode stack */
541da177e4SLinus Torvalds	copy	%arg0, %sp		/* adopt the real-mode SP */
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds	/* save iodc_fn */
571da177e4SLinus Torvalds	copy	%arg2, %r31
581da177e4SLinus Torvalds
591da177e4SLinus Torvalds	/* load up the arg registers from the saved arg area */
601da177e4SLinus Torvalds	/* 32-bit calling convention passes first 4 args in registers */
611da177e4SLinus Torvalds	ldw	0(%arg1), %arg0		/* note overwriting arg0 */
621da177e4SLinus Torvalds	ldw	-8(%arg1), %arg2
631da177e4SLinus Torvalds	ldw	-12(%arg1), %arg3
641da177e4SLinus Torvalds	ldw	-4(%arg1), %arg1	/* obviously must do this one last! */
651da177e4SLinus Torvalds
661da177e4SLinus Torvalds	tophys_r1  %sp
671da177e4SLinus Torvalds
681da177e4SLinus Torvalds	b,l	rfi_virt2real,%r2
691da177e4SLinus Torvalds	nop
701da177e4SLinus Torvalds
711da177e4SLinus Torvalds	b,l	save_control_regs,%r2		/* modifies r1, r2, r28 */
721da177e4SLinus Torvalds	nop
731da177e4SLinus Torvalds
74413059f2SGrant Grundler#ifdef CONFIG_64BIT
751da177e4SLinus Torvalds	rsm	PSW_SM_W, %r0		/* go narrow */
761da177e4SLinus Torvalds#endif
771da177e4SLinus Torvalds
781da177e4SLinus Torvalds	load32	PA(ric_ret), %r2
791da177e4SLinus Torvalds	bv	0(%r31)
801da177e4SLinus Torvalds	nop
811da177e4SLinus Torvaldsric_ret:
82413059f2SGrant Grundler#ifdef CONFIG_64BIT
831da177e4SLinus Torvalds	ssm	PSW_SM_W, %r0		/* go wide */
841da177e4SLinus Torvalds#endif
851da177e4SLinus Torvalds	/* restore CRs before going virtual in case we page fault */
861da177e4SLinus Torvalds	b,l	restore_control_regs, %r2	/* modifies r1, r2, r26 */
871da177e4SLinus Torvalds	nop
881da177e4SLinus Torvalds
891da177e4SLinus Torvalds	b,l	rfi_real2virt,%r2
901da177e4SLinus Torvalds	nop
911da177e4SLinus Torvalds
921da177e4SLinus Torvalds	tovirt_r1 %sp
931da177e4SLinus Torvalds	LDREG	-REG_SZ(%sp), %sp	/* restore SP */
94413059f2SGrant Grundler#ifdef CONFIG_64BIT
951da177e4SLinus Torvalds	LDREG	-1*REG_SZ(%sp), %r27
961da177e4SLinus Torvalds	LDREG	-2*REG_SZ(%sp), %r29
971da177e4SLinus Torvalds	ldo	-2*REG_SZ(%sp), %sp
981da177e4SLinus Torvalds	callee_rest
991da177e4SLinus Torvalds#endif
1001da177e4SLinus Torvalds	LDREG	-RP_OFFSET(%sp), %rp	/* restore RP */
1011da177e4SLinus Torvalds	bv	0(%rp)
1021da177e4SLinus Torvalds	nop
103f39cce65SHelge DellerENDPROC_CFI(real32_call_asm)
1041da177e4SLinus Torvalds
1051da177e4SLinus Torvalds
1061da177e4SLinus Torvalds#  define PUSH_CR(r, where) mfctl r, %r1 ! STREG,ma %r1, REG_SZ(where)
1071da177e4SLinus Torvalds#  define POP_CR(r, where) LDREG,mb -REG_SZ(where), %r1 ! mtctl %r1, r
1081da177e4SLinus Torvalds
109dfcf753bSKyle McMartin	.text
110f39cce65SHelge DellerENTRY_CFI(save_control_regs)
1111da177e4SLinus Torvalds	load32	PA(save_cr_space), %r28
1121da177e4SLinus Torvalds	PUSH_CR(%cr24, %r28)
1131da177e4SLinus Torvalds	PUSH_CR(%cr25, %r28)
1141da177e4SLinus Torvalds	PUSH_CR(%cr26, %r28)
1151da177e4SLinus Torvalds	PUSH_CR(%cr27, %r28)
1161da177e4SLinus Torvalds	PUSH_CR(%cr28, %r28)
1171da177e4SLinus Torvalds	PUSH_CR(%cr29, %r28)
1181da177e4SLinus Torvalds	PUSH_CR(%cr30, %r28)
1191da177e4SLinus Torvalds	PUSH_CR(%cr31, %r28)
1201da177e4SLinus Torvalds	PUSH_CR(%cr15, %r28)
1211da177e4SLinus Torvalds	bv 0(%r2)
1221da177e4SLinus Torvalds	nop
123f39cce65SHelge DellerENDPROC_CFI(save_control_regs)
1241da177e4SLinus Torvalds
125f39cce65SHelge DellerENTRY_CFI(restore_control_regs)
1261da177e4SLinus Torvalds	load32	PA(save_cr_end), %r26
1271da177e4SLinus Torvalds	POP_CR(%cr15, %r26)
1281da177e4SLinus Torvalds	POP_CR(%cr31, %r26)
1291da177e4SLinus Torvalds	POP_CR(%cr30, %r26)
1301da177e4SLinus Torvalds	POP_CR(%cr29, %r26)
1311da177e4SLinus Torvalds	POP_CR(%cr28, %r26)
1321da177e4SLinus Torvalds	POP_CR(%cr27, %r26)
1331da177e4SLinus Torvalds	POP_CR(%cr26, %r26)
1341da177e4SLinus Torvalds	POP_CR(%cr25, %r26)
1351da177e4SLinus Torvalds	POP_CR(%cr24, %r26)
1361da177e4SLinus Torvalds	bv 0(%r2)
1371da177e4SLinus Torvalds	nop
138f39cce65SHelge DellerENDPROC_CFI(restore_control_regs)
1391da177e4SLinus Torvalds
1401da177e4SLinus Torvalds/* rfi_virt2real() and rfi_real2virt() could perhaps be adapted for
1411da177e4SLinus Torvalds * more general-purpose use by the several places which need RFIs
1421da177e4SLinus Torvalds */
143dfcf753bSKyle McMartin	.text
144e55fb3e7SGrant Grundler	.align 128
145f39cce65SHelge DellerENTRY_CFI(rfi_virt2real)
146f5213b2cSHelge Deller#if !defined(BOOTLOADER)
1471da177e4SLinus Torvalds	/* switch to real mode... */
148896a3756SGrant Grundler	rsm		PSW_SM_I,%r0
149896a3756SGrant Grundler	load32		PA(rfi_v2r_1), %r1
1501da177e4SLinus Torvalds	nop
1511da177e4SLinus Torvalds	nop
1521da177e4SLinus Torvalds	nop
1531da177e4SLinus Torvalds	nop
1541da177e4SLinus Torvalds	nop
1551da177e4SLinus Torvalds
156896a3756SGrant Grundler	rsm             PSW_SM_Q,%r0  /* disable Q & I bits to load iia queue */
1571da177e4SLinus Torvalds	mtctl		%r0, %cr17	/* Clear IIASQ tail */
1581da177e4SLinus Torvalds	mtctl		%r0, %cr17	/* Clear IIASQ head */
1591da177e4SLinus Torvalds	mtctl		%r1, %cr18	/* IIAOQ head */
1601da177e4SLinus Torvalds	ldo		4(%r1), %r1
1611da177e4SLinus Torvalds	mtctl		%r1, %cr18	/* IIAOQ tail */
1621da177e4SLinus Torvalds	load32          REAL_MODE_PSW, %r1
1631da177e4SLinus Torvalds	mtctl		%r1, %cr22
1641da177e4SLinus Torvalds	rfi
1651da177e4SLinus Torvalds
1661da177e4SLinus Torvalds	nop
1671da177e4SLinus Torvalds	nop
1681da177e4SLinus Torvalds	nop
1691da177e4SLinus Torvalds	nop
1701da177e4SLinus Torvalds	nop
1711da177e4SLinus Torvalds	nop
1721da177e4SLinus Torvalds	nop
1731da177e4SLinus Torvalds	nop
1741da177e4SLinus Torvaldsrfi_v2r_1:
1751da177e4SLinus Torvalds	tophys_r1 %r2
176f5213b2cSHelge Deller#endif /* defined(BOOTLOADER) */
1771da177e4SLinus Torvalds	bv	0(%r2)
1781da177e4SLinus Torvalds	nop
179f39cce65SHelge DellerENDPROC_CFI(rfi_virt2real)
1801da177e4SLinus Torvalds
181dfcf753bSKyle McMartin	.text
1821da177e4SLinus Torvalds	.align 128
183f39cce65SHelge DellerENTRY_CFI(rfi_real2virt)
184f5213b2cSHelge Deller#if !defined(BOOTLOADER)
185896a3756SGrant Grundler	rsm		PSW_SM_I,%r0
186896a3756SGrant Grundler	load32		(rfi_r2v_1), %r1
1871da177e4SLinus Torvalds	nop
1881da177e4SLinus Torvalds	nop
1891da177e4SLinus Torvalds	nop
1901da177e4SLinus Torvalds	nop
1911da177e4SLinus Torvalds	nop
1921da177e4SLinus Torvalds
1931da177e4SLinus Torvalds	rsm             PSW_SM_Q,%r0    /* disable Q bit to load iia queue */
1941da177e4SLinus Torvalds	mtctl		%r0, %cr17	/* Clear IIASQ tail */
1951da177e4SLinus Torvalds	mtctl		%r0, %cr17	/* Clear IIASQ head */
1961da177e4SLinus Torvalds	mtctl		%r1, %cr18	/* IIAOQ head */
1971da177e4SLinus Torvalds	ldo		4(%r1), %r1
1981da177e4SLinus Torvalds	mtctl		%r1, %cr18	/* IIAOQ tail */
1991da177e4SLinus Torvalds	load32		KERNEL_PSW, %r1
2001da177e4SLinus Torvalds	mtctl		%r1, %cr22
2011da177e4SLinus Torvalds	rfi
2021da177e4SLinus Torvalds
2031da177e4SLinus Torvalds	nop
2041da177e4SLinus Torvalds	nop
2051da177e4SLinus Torvalds	nop
2061da177e4SLinus Torvalds	nop
2071da177e4SLinus Torvalds	nop
2081da177e4SLinus Torvalds	nop
2091da177e4SLinus Torvalds	nop
2101da177e4SLinus Torvalds	nop
2111da177e4SLinus Torvaldsrfi_r2v_1:
2121da177e4SLinus Torvalds	tovirt_r1 %r2
213f5213b2cSHelge Deller#endif /* defined(BOOTLOADER) */
2141da177e4SLinus Torvalds	bv	0(%r2)
2151da177e4SLinus Torvalds	nop
216f39cce65SHelge DellerENDPROC_CFI(rfi_real2virt)
2171da177e4SLinus Torvalds
218413059f2SGrant Grundler#ifdef CONFIG_64BIT
2191da177e4SLinus Torvalds
2201da177e4SLinus Torvalds/************************ 64-bit real-mode calls ***********************/
2211da177e4SLinus Torvalds/* This is only usable in wide kernels right now and will probably stay so */
222dfcf753bSKyle McMartin	.text
2231da177e4SLinus Torvalds	/* unsigned long real64_call_asm(unsigned long *sp,
2241da177e4SLinus Torvalds	 *		unsigned long *arg0p,
2251da177e4SLinus Torvalds	 *		unsigned long fn)
2261da177e4SLinus Torvalds	 *	sp is value of stack pointer to adopt before calling PDC (virt)
2271da177e4SLinus Torvalds	 *	arg0p points to where saved arg values may be found
2281da177e4SLinus Torvalds	 *	iodc_fn is the IODC function to call
2291da177e4SLinus Torvalds	 */
230f39cce65SHelge DellerENTRY_CFI(real64_call_asm)
2311da177e4SLinus Torvalds	std	%rp, -0x10(%sp)		/* save RP */
2321da177e4SLinus Torvalds	std	%sp, -8(%arg0)		/* save SP on real-mode stack */
2331da177e4SLinus Torvalds	copy	%arg0, %sp		/* adopt the real-mode SP */
2341da177e4SLinus Torvalds
2351da177e4SLinus Torvalds	/* save fn */
2361da177e4SLinus Torvalds	copy	%arg2, %r31
2371da177e4SLinus Torvalds
2381da177e4SLinus Torvalds	/* set up the new ap */
2391da177e4SLinus Torvalds	ldo	64(%arg1), %r29
2401da177e4SLinus Torvalds
2411da177e4SLinus Torvalds	/* load up the arg registers from the saved arg area */
2421da177e4SLinus Torvalds	/* 32-bit calling convention passes first 4 args in registers */
2431da177e4SLinus Torvalds	ldd	0*REG_SZ(%arg1), %arg0		/* note overwriting arg0 */
2441da177e4SLinus Torvalds	ldd	2*REG_SZ(%arg1), %arg2
2451da177e4SLinus Torvalds	ldd	3*REG_SZ(%arg1), %arg3
2461da177e4SLinus Torvalds	ldd	4*REG_SZ(%arg1), %r22
2471da177e4SLinus Torvalds	ldd	5*REG_SZ(%arg1), %r21
2481da177e4SLinus Torvalds	ldd	6*REG_SZ(%arg1), %r20
2491da177e4SLinus Torvalds	ldd	7*REG_SZ(%arg1), %r19
2501da177e4SLinus Torvalds	ldd	1*REG_SZ(%arg1), %arg1		/* do this one last! */
2511da177e4SLinus Torvalds
2521da177e4SLinus Torvalds	tophys_r1 %sp
2531da177e4SLinus Torvalds
2541da177e4SLinus Torvalds	b,l	rfi_virt2real,%r2
2551da177e4SLinus Torvalds	nop
2561da177e4SLinus Torvalds
2571da177e4SLinus Torvalds	b,l	save_control_regs,%r2		/* modifies r1, r2, r28 */
2581da177e4SLinus Torvalds	nop
2591da177e4SLinus Torvalds
2601da177e4SLinus Torvalds	load32	PA(r64_ret), %r2
2611da177e4SLinus Torvalds	bv	0(%r31)
2621da177e4SLinus Torvalds	nop
2631da177e4SLinus Torvaldsr64_ret:
2641da177e4SLinus Torvalds	/* restore CRs before going virtual in case we page fault */
2651da177e4SLinus Torvalds	b,l	restore_control_regs, %r2	/* modifies r1, r2, r26 */
2661da177e4SLinus Torvalds	nop
2671da177e4SLinus Torvalds
2681da177e4SLinus Torvalds	b,l	rfi_real2virt,%r2
2691da177e4SLinus Torvalds	nop
2701da177e4SLinus Torvalds
2711da177e4SLinus Torvalds	tovirt_r1 %sp
2721da177e4SLinus Torvalds	ldd	-8(%sp), %sp		/* restore SP */
2731da177e4SLinus Torvalds	ldd	-0x10(%sp), %rp		/* restore RP */
2741da177e4SLinus Torvalds	bv	0(%rp)
2751da177e4SLinus Torvalds	nop
276f39cce65SHelge DellerENDPROC_CFI(real64_call_asm)
2771da177e4SLinus Torvalds
2781da177e4SLinus Torvalds#endif
2791da177e4SLinus Torvalds
280dfcf753bSKyle McMartin	.text
2811da177e4SLinus Torvalds	/* http://lists.parisc-linux.org/hypermail/parisc-linux/10916.html
2821da177e4SLinus Torvalds	**	GCC 3.3 and later has a new function in libgcc.a for
2831da177e4SLinus Torvalds	**	comparing function pointers.
2841da177e4SLinus Torvalds	*/
285f39cce65SHelge DellerENTRY_CFI(__canonicalize_funcptr_for_compare)
286413059f2SGrant Grundler#ifdef CONFIG_64BIT
2871da177e4SLinus Torvalds	bve (%r2)
2881da177e4SLinus Torvalds#else
2891da177e4SLinus Torvalds	bv %r0(%r2)
2901da177e4SLinus Torvalds#endif
2911da177e4SLinus Torvalds	copy %r26,%r28
292f39cce65SHelge DellerENDPROC_CFI(__canonicalize_funcptr_for_compare)
2938e9e9844SHelge Deller
294