xref: /linux/arch/parisc/kernel/real2.S (revision 6c86cb8237bf08443806089130dc108051569a93)
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
11*6c86cb82SKyle McMartin#include <asm/pdc.h>
121da177e4SLinus Torvalds#include <asm/psw.h>
13896a3756SGrant Grundler#include <asm/assembly.h>
14*6c86cb82SKyle McMartin#include <asm/asm-offsets.h>
151da177e4SLinus Torvalds
168e9e9844SHelge Deller#include <linux/linkage.h>
178e9e9844SHelge Deller
18*6c86cb82SKyle McMartin
191da177e4SLinus Torvalds	.section	.bss
20*6c86cb82SKyle McMartin
21*6c86cb82SKyle McMartin	.export pdc_result
22*6c86cb82SKyle McMartin	.export pdc_result2
23*6c86cb82SKyle McMartin	.align 8
24*6c86cb82SKyle McMartinpdc_result:
25*6c86cb82SKyle McMartin	.block	ASM_PDC_RESULT_SIZE
26*6c86cb82SKyle McMartinpdc_result2:
27*6c86cb82SKyle McMartin	.block	ASM_PDC_RESULT_SIZE
28*6c86cb82SKyle McMartin
291da177e4SLinus Torvalds	.export real_stack
301da177e4SLinus Torvalds	.export real32_stack
311da177e4SLinus Torvalds	.export real64_stack
321da177e4SLinus Torvalds	.align	64
331da177e4SLinus Torvaldsreal_stack:
341da177e4SLinus Torvaldsreal32_stack:
351da177e4SLinus Torvaldsreal64_stack:
361da177e4SLinus Torvalds	.block	8192
371da177e4SLinus Torvalds
38413059f2SGrant Grundler#ifdef CONFIG_64BIT
391da177e4SLinus Torvalds#  define REG_SZ 8
401da177e4SLinus Torvalds#else
411da177e4SLinus Torvalds#  define REG_SZ 4
421da177e4SLinus Torvalds#endif
431da177e4SLinus Torvalds
441da177e4SLinus Torvalds#define N_SAVED_REGS 9
451da177e4SLinus Torvalds
461da177e4SLinus Torvaldssave_cr_space:
471da177e4SLinus Torvalds	.block	REG_SZ * N_SAVED_REGS
481da177e4SLinus Torvaldssave_cr_end:
491da177e4SLinus Torvalds
501da177e4SLinus Torvalds
511da177e4SLinus Torvalds/************************ 32-bit real-mode calls ***********************/
521da177e4SLinus Torvalds/* This can be called in both narrow and wide kernels */
531da177e4SLinus Torvalds
54dfcf753bSKyle McMartin	.text
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds	/* unsigned long real32_call_asm(unsigned int *sp,
571da177e4SLinus Torvalds	 *		unsigned int *arg0p,
581da177e4SLinus Torvalds	 *		unsigned int iodc_fn)
591da177e4SLinus Torvalds	 *	sp is value of stack pointer to adopt before calling PDC (virt)
601da177e4SLinus Torvalds	 *	arg0p points to where saved arg values may be found
611da177e4SLinus Torvalds	 *	iodc_fn is the IODC function to call
621da177e4SLinus Torvalds	 */
631da177e4SLinus Torvalds
648e9e9844SHelge DellerENTRY(real32_call_asm)
651da177e4SLinus Torvalds	STREG	%rp, -RP_OFFSET(%sp)	/* save RP */
66413059f2SGrant Grundler#ifdef CONFIG_64BIT
671da177e4SLinus Torvalds	callee_save
681da177e4SLinus Torvalds	ldo	2*REG_SZ(%sp), %sp	/* room for a couple more saves */
691da177e4SLinus Torvalds	STREG	%r27, -1*REG_SZ(%sp)
701da177e4SLinus Torvalds	STREG	%r29, -2*REG_SZ(%sp)
711da177e4SLinus Torvalds#endif
721da177e4SLinus Torvalds	STREG	%sp, -REG_SZ(%arg0)	/* save SP on real-mode stack */
731da177e4SLinus Torvalds	copy	%arg0, %sp		/* adopt the real-mode SP */
741da177e4SLinus Torvalds
751da177e4SLinus Torvalds	/* save iodc_fn */
761da177e4SLinus Torvalds	copy	%arg2, %r31
771da177e4SLinus Torvalds
781da177e4SLinus Torvalds	/* load up the arg registers from the saved arg area */
791da177e4SLinus Torvalds	/* 32-bit calling convention passes first 4 args in registers */
801da177e4SLinus Torvalds	ldw	0(%arg1), %arg0		/* note overwriting arg0 */
811da177e4SLinus Torvalds	ldw	-8(%arg1), %arg2
821da177e4SLinus Torvalds	ldw	-12(%arg1), %arg3
831da177e4SLinus Torvalds	ldw	-4(%arg1), %arg1	/* obviously must do this one last! */
841da177e4SLinus Torvalds
851da177e4SLinus Torvalds	tophys_r1  %sp
861da177e4SLinus Torvalds
871da177e4SLinus Torvalds	b,l	rfi_virt2real,%r2
881da177e4SLinus Torvalds	nop
891da177e4SLinus Torvalds
901da177e4SLinus Torvalds	b,l	save_control_regs,%r2		/* modifies r1, r2, r28 */
911da177e4SLinus Torvalds	nop
921da177e4SLinus Torvalds
93413059f2SGrant Grundler#ifdef CONFIG_64BIT
941da177e4SLinus Torvalds	rsm	PSW_SM_W, %r0		/* go narrow */
951da177e4SLinus Torvalds#endif
961da177e4SLinus Torvalds
971da177e4SLinus Torvalds	load32	PA(ric_ret), %r2
981da177e4SLinus Torvalds	bv	0(%r31)
991da177e4SLinus Torvalds	nop
1001da177e4SLinus Torvaldsric_ret:
101413059f2SGrant Grundler#ifdef CONFIG_64BIT
1021da177e4SLinus Torvalds	ssm	PSW_SM_W, %r0		/* go wide */
1031da177e4SLinus Torvalds#endif
1041da177e4SLinus Torvalds	/* restore CRs before going virtual in case we page fault */
1051da177e4SLinus Torvalds	b,l	restore_control_regs, %r2	/* modifies r1, r2, r26 */
1061da177e4SLinus Torvalds	nop
1071da177e4SLinus Torvalds
1081da177e4SLinus Torvalds	b,l	rfi_real2virt,%r2
1091da177e4SLinus Torvalds	nop
1101da177e4SLinus Torvalds
1111da177e4SLinus Torvalds	tovirt_r1 %sp
1121da177e4SLinus Torvalds	LDREG	-REG_SZ(%sp), %sp	/* restore SP */
113413059f2SGrant Grundler#ifdef CONFIG_64BIT
1141da177e4SLinus Torvalds	LDREG	-1*REG_SZ(%sp), %r27
1151da177e4SLinus Torvalds	LDREG	-2*REG_SZ(%sp), %r29
1161da177e4SLinus Torvalds	ldo	-2*REG_SZ(%sp), %sp
1171da177e4SLinus Torvalds	callee_rest
1181da177e4SLinus Torvalds#endif
1191da177e4SLinus Torvalds	LDREG	-RP_OFFSET(%sp), %rp	/* restore RP */
1201da177e4SLinus Torvalds	bv	0(%rp)
1211da177e4SLinus Torvalds	nop
1228e9e9844SHelge DellerENDPROC(real32_call_asm)
1231da177e4SLinus Torvalds
1241da177e4SLinus Torvalds
1251da177e4SLinus Torvalds#  define PUSH_CR(r, where) mfctl r, %r1 ! STREG,ma %r1, REG_SZ(where)
1261da177e4SLinus Torvalds#  define POP_CR(r, where) LDREG,mb -REG_SZ(where), %r1 ! mtctl %r1, r
1271da177e4SLinus Torvalds
128dfcf753bSKyle McMartin	.text
1291da177e4SLinus Torvaldssave_control_regs:
1301da177e4SLinus Torvalds	load32	PA(save_cr_space), %r28
1311da177e4SLinus Torvalds	PUSH_CR(%cr24, %r28)
1321da177e4SLinus Torvalds	PUSH_CR(%cr25, %r28)
1331da177e4SLinus Torvalds	PUSH_CR(%cr26, %r28)
1341da177e4SLinus Torvalds	PUSH_CR(%cr27, %r28)
1351da177e4SLinus Torvalds	PUSH_CR(%cr28, %r28)
1361da177e4SLinus Torvalds	PUSH_CR(%cr29, %r28)
1371da177e4SLinus Torvalds	PUSH_CR(%cr30, %r28)
1381da177e4SLinus Torvalds	PUSH_CR(%cr31, %r28)
1391da177e4SLinus Torvalds	PUSH_CR(%cr15, %r28)
1401da177e4SLinus Torvalds	bv 0(%r2)
1411da177e4SLinus Torvalds	nop
1421da177e4SLinus Torvalds
1431da177e4SLinus Torvaldsrestore_control_regs:
1441da177e4SLinus Torvalds	load32	PA(save_cr_end), %r26
1451da177e4SLinus Torvalds	POP_CR(%cr15, %r26)
1461da177e4SLinus Torvalds	POP_CR(%cr31, %r26)
1471da177e4SLinus Torvalds	POP_CR(%cr30, %r26)
1481da177e4SLinus Torvalds	POP_CR(%cr29, %r26)
1491da177e4SLinus Torvalds	POP_CR(%cr28, %r26)
1501da177e4SLinus Torvalds	POP_CR(%cr27, %r26)
1511da177e4SLinus Torvalds	POP_CR(%cr26, %r26)
1521da177e4SLinus Torvalds	POP_CR(%cr25, %r26)
1531da177e4SLinus Torvalds	POP_CR(%cr24, %r26)
1541da177e4SLinus Torvalds	bv 0(%r2)
1551da177e4SLinus Torvalds	nop
1561da177e4SLinus Torvalds
1571da177e4SLinus Torvalds/* rfi_virt2real() and rfi_real2virt() could perhaps be adapted for
1581da177e4SLinus Torvalds * more general-purpose use by the several places which need RFIs
1591da177e4SLinus Torvalds */
160dfcf753bSKyle McMartin	.text
161e55fb3e7SGrant Grundler	.align 128
1621da177e4SLinus Torvaldsrfi_virt2real:
1631da177e4SLinus Torvalds	/* switch to real mode... */
164896a3756SGrant Grundler	rsm		PSW_SM_I,%r0
165896a3756SGrant Grundler	load32		PA(rfi_v2r_1), %r1
1661da177e4SLinus Torvalds	nop
1671da177e4SLinus Torvalds	nop
1681da177e4SLinus Torvalds	nop
1691da177e4SLinus Torvalds	nop
1701da177e4SLinus Torvalds	nop
1711da177e4SLinus Torvalds
172896a3756SGrant Grundler	rsm             PSW_SM_Q,%r0  /* disable Q & I bits to load iia queue */
1731da177e4SLinus Torvalds	mtctl		%r0, %cr17	/* Clear IIASQ tail */
1741da177e4SLinus Torvalds	mtctl		%r0, %cr17	/* Clear IIASQ head */
1751da177e4SLinus Torvalds	mtctl		%r1, %cr18	/* IIAOQ head */
1761da177e4SLinus Torvalds	ldo		4(%r1), %r1
1771da177e4SLinus Torvalds	mtctl		%r1, %cr18	/* IIAOQ tail */
1781da177e4SLinus Torvalds	load32          REAL_MODE_PSW, %r1
1791da177e4SLinus Torvalds	mtctl		%r1, %cr22
1801da177e4SLinus Torvalds	rfi
1811da177e4SLinus Torvalds
1821da177e4SLinus Torvalds	nop
1831da177e4SLinus Torvalds	nop
1841da177e4SLinus Torvalds	nop
1851da177e4SLinus Torvalds	nop
1861da177e4SLinus Torvalds	nop
1871da177e4SLinus Torvalds	nop
1881da177e4SLinus Torvalds	nop
1891da177e4SLinus Torvalds	nop
1901da177e4SLinus Torvaldsrfi_v2r_1:
1911da177e4SLinus Torvalds	tophys_r1 %r2
1921da177e4SLinus Torvalds	bv	0(%r2)
1931da177e4SLinus Torvalds	nop
1941da177e4SLinus Torvalds
195dfcf753bSKyle McMartin	.text
1961da177e4SLinus Torvalds	.align 128
1971da177e4SLinus Torvaldsrfi_real2virt:
198896a3756SGrant Grundler	rsm		PSW_SM_I,%r0
199896a3756SGrant Grundler	load32		(rfi_r2v_1), %r1
2001da177e4SLinus Torvalds	nop
2011da177e4SLinus Torvalds	nop
2021da177e4SLinus Torvalds	nop
2031da177e4SLinus Torvalds	nop
2041da177e4SLinus Torvalds	nop
2051da177e4SLinus Torvalds
2061da177e4SLinus Torvalds	rsm             PSW_SM_Q,%r0    /* disable Q bit to load iia queue */
2071da177e4SLinus Torvalds	mtctl		%r0, %cr17	/* Clear IIASQ tail */
2081da177e4SLinus Torvalds	mtctl		%r0, %cr17	/* Clear IIASQ head */
2091da177e4SLinus Torvalds	mtctl		%r1, %cr18	/* IIAOQ head */
2101da177e4SLinus Torvalds	ldo		4(%r1), %r1
2111da177e4SLinus Torvalds	mtctl		%r1, %cr18	/* IIAOQ tail */
2121da177e4SLinus Torvalds	load32		KERNEL_PSW, %r1
2131da177e4SLinus Torvalds	mtctl		%r1, %cr22
2141da177e4SLinus Torvalds	rfi
2151da177e4SLinus Torvalds
2161da177e4SLinus Torvalds	nop
2171da177e4SLinus Torvalds	nop
2181da177e4SLinus Torvalds	nop
2191da177e4SLinus Torvalds	nop
2201da177e4SLinus Torvalds	nop
2211da177e4SLinus Torvalds	nop
2221da177e4SLinus Torvalds	nop
2231da177e4SLinus Torvalds	nop
2241da177e4SLinus Torvaldsrfi_r2v_1:
2251da177e4SLinus Torvalds	tovirt_r1 %r2
2261da177e4SLinus Torvalds	bv	0(%r2)
2271da177e4SLinus Torvalds	nop
2281da177e4SLinus Torvalds
229413059f2SGrant Grundler#ifdef CONFIG_64BIT
2301da177e4SLinus Torvalds
2311da177e4SLinus Torvalds/************************ 64-bit real-mode calls ***********************/
2321da177e4SLinus Torvalds/* This is only usable in wide kernels right now and will probably stay so */
233dfcf753bSKyle McMartin	.text
2341da177e4SLinus Torvalds	/* unsigned long real64_call_asm(unsigned long *sp,
2351da177e4SLinus Torvalds	 *		unsigned long *arg0p,
2361da177e4SLinus Torvalds	 *		unsigned long fn)
2371da177e4SLinus Torvalds	 *	sp is value of stack pointer to adopt before calling PDC (virt)
2381da177e4SLinus Torvalds	 *	arg0p points to where saved arg values may be found
2391da177e4SLinus Torvalds	 *	iodc_fn is the IODC function to call
2401da177e4SLinus Torvalds	 */
2418e9e9844SHelge DellerENTRY(real64_call_asm)
2421da177e4SLinus Torvalds	std	%rp, -0x10(%sp)		/* save RP */
2431da177e4SLinus Torvalds	std	%sp, -8(%arg0)		/* save SP on real-mode stack */
2441da177e4SLinus Torvalds	copy	%arg0, %sp		/* adopt the real-mode SP */
2451da177e4SLinus Torvalds
2461da177e4SLinus Torvalds	/* save fn */
2471da177e4SLinus Torvalds	copy	%arg2, %r31
2481da177e4SLinus Torvalds
2491da177e4SLinus Torvalds	/* set up the new ap */
2501da177e4SLinus Torvalds	ldo	64(%arg1), %r29
2511da177e4SLinus Torvalds
2521da177e4SLinus Torvalds	/* load up the arg registers from the saved arg area */
2531da177e4SLinus Torvalds	/* 32-bit calling convention passes first 4 args in registers */
2541da177e4SLinus Torvalds	ldd	0*REG_SZ(%arg1), %arg0		/* note overwriting arg0 */
2551da177e4SLinus Torvalds	ldd	2*REG_SZ(%arg1), %arg2
2561da177e4SLinus Torvalds	ldd	3*REG_SZ(%arg1), %arg3
2571da177e4SLinus Torvalds	ldd	4*REG_SZ(%arg1), %r22
2581da177e4SLinus Torvalds	ldd	5*REG_SZ(%arg1), %r21
2591da177e4SLinus Torvalds	ldd	6*REG_SZ(%arg1), %r20
2601da177e4SLinus Torvalds	ldd	7*REG_SZ(%arg1), %r19
2611da177e4SLinus Torvalds	ldd	1*REG_SZ(%arg1), %arg1		/* do this one last! */
2621da177e4SLinus Torvalds
2631da177e4SLinus Torvalds	tophys_r1 %sp
2641da177e4SLinus Torvalds
2651da177e4SLinus Torvalds	b,l	rfi_virt2real,%r2
2661da177e4SLinus Torvalds	nop
2671da177e4SLinus Torvalds
2681da177e4SLinus Torvalds	b,l	save_control_regs,%r2		/* modifies r1, r2, r28 */
2691da177e4SLinus Torvalds	nop
2701da177e4SLinus Torvalds
2711da177e4SLinus Torvalds	load32	PA(r64_ret), %r2
2721da177e4SLinus Torvalds	bv	0(%r31)
2731da177e4SLinus Torvalds	nop
2741da177e4SLinus Torvaldsr64_ret:
2751da177e4SLinus Torvalds	/* restore CRs before going virtual in case we page fault */
2761da177e4SLinus Torvalds	b,l	restore_control_regs, %r2	/* modifies r1, r2, r26 */
2771da177e4SLinus Torvalds	nop
2781da177e4SLinus Torvalds
2791da177e4SLinus Torvalds	b,l	rfi_real2virt,%r2
2801da177e4SLinus Torvalds	nop
2811da177e4SLinus Torvalds
2821da177e4SLinus Torvalds	tovirt_r1 %sp
2831da177e4SLinus Torvalds	ldd	-8(%sp), %sp		/* restore SP */
2841da177e4SLinus Torvalds	ldd	-0x10(%sp), %rp		/* restore RP */
2851da177e4SLinus Torvalds	bv	0(%rp)
2861da177e4SLinus Torvalds	nop
2878e9e9844SHelge DellerENDPROC(real64_call_asm)
2881da177e4SLinus Torvalds
2891da177e4SLinus Torvalds#endif
2901da177e4SLinus Torvalds
291dfcf753bSKyle McMartin	.text
2921da177e4SLinus Torvalds	/* http://lists.parisc-linux.org/hypermail/parisc-linux/10916.html
2931da177e4SLinus Torvalds	**	GCC 3.3 and later has a new function in libgcc.a for
2941da177e4SLinus Torvalds	**	comparing function pointers.
2951da177e4SLinus Torvalds	*/
2968e9e9844SHelge DellerENTRY(__canonicalize_funcptr_for_compare)
297413059f2SGrant Grundler#ifdef CONFIG_64BIT
2981da177e4SLinus Torvalds	bve (%r2)
2991da177e4SLinus Torvalds#else
3001da177e4SLinus Torvalds	bv %r0(%r2)
3011da177e4SLinus Torvalds#endif
3021da177e4SLinus Torvalds	copy %r26,%r28
3038e9e9844SHelge DellerENDPROC(__canonicalize_funcptr_for_compare)
3048e9e9844SHelge Deller
305