xref: /openbmc/linux/tools/testing/selftests/powerpc/nx-gzip/include/copy-paste.h (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1*f49b7572SRaphael Moreira Zinsly /* SPDX-License-Identifier: GPL-2.0-or-later */
2*f49b7572SRaphael Moreira Zinsly 
3*f49b7572SRaphael Moreira Zinsly /* From asm-compat.h */
4*f49b7572SRaphael Moreira Zinsly #define __stringify_in_c(...)	#__VA_ARGS__
5*f49b7572SRaphael Moreira Zinsly #define stringify_in_c(...)	__stringify_in_c(__VA_ARGS__) " "
6*f49b7572SRaphael Moreira Zinsly 
7*f49b7572SRaphael Moreira Zinsly /*
8*f49b7572SRaphael Moreira Zinsly  * Macros taken from arch/powerpc/include/asm/ppc-opcode.h and other
9*f49b7572SRaphael Moreira Zinsly  * header files.
10*f49b7572SRaphael Moreira Zinsly  */
11*f49b7572SRaphael Moreira Zinsly #define ___PPC_RA(a)    (((a) & 0x1f) << 16)
12*f49b7572SRaphael Moreira Zinsly #define ___PPC_RB(b)    (((b) & 0x1f) << 11)
13*f49b7572SRaphael Moreira Zinsly 
14*f49b7572SRaphael Moreira Zinsly #define PPC_INST_COPY                   0x7c20060c
15*f49b7572SRaphael Moreira Zinsly #define PPC_INST_PASTE                  0x7c20070d
16*f49b7572SRaphael Moreira Zinsly 
17*f49b7572SRaphael Moreira Zinsly #define PPC_COPY(a, b)          stringify_in_c(.long PPC_INST_COPY | \
18*f49b7572SRaphael Moreira Zinsly 						___PPC_RA(a) | ___PPC_RB(b))
19*f49b7572SRaphael Moreira Zinsly #define PPC_PASTE(a, b)         stringify_in_c(.long PPC_INST_PASTE | \
20*f49b7572SRaphael Moreira Zinsly 						___PPC_RA(a) | ___PPC_RB(b))
21*f49b7572SRaphael Moreira Zinsly #define CR0_SHIFT	28
22*f49b7572SRaphael Moreira Zinsly #define CR0_MASK	0xF
23*f49b7572SRaphael Moreira Zinsly /*
24*f49b7572SRaphael Moreira Zinsly  * Copy/paste instructions:
25*f49b7572SRaphael Moreira Zinsly  *
26*f49b7572SRaphael Moreira Zinsly  *	copy RA,RB
27*f49b7572SRaphael Moreira Zinsly  *		Copy contents of address (RA) + effective_address(RB)
28*f49b7572SRaphael Moreira Zinsly  *		to internal copy-buffer.
29*f49b7572SRaphael Moreira Zinsly  *
30*f49b7572SRaphael Moreira Zinsly  *	paste RA,RB
31*f49b7572SRaphael Moreira Zinsly  *		Paste contents of internal copy-buffer to the address
32*f49b7572SRaphael Moreira Zinsly  *		(RA) + effective_address(RB)
33*f49b7572SRaphael Moreira Zinsly  */
vas_copy(void * crb,int offset)34*f49b7572SRaphael Moreira Zinsly static inline int vas_copy(void *crb, int offset)
35*f49b7572SRaphael Moreira Zinsly {
36*f49b7572SRaphael Moreira Zinsly 	asm volatile(PPC_COPY(%0, %1)";"
37*f49b7572SRaphael Moreira Zinsly 		:
38*f49b7572SRaphael Moreira Zinsly 		: "b" (offset), "b" (crb)
39*f49b7572SRaphael Moreira Zinsly 		: "memory");
40*f49b7572SRaphael Moreira Zinsly 
41*f49b7572SRaphael Moreira Zinsly 	return 0;
42*f49b7572SRaphael Moreira Zinsly }
43*f49b7572SRaphael Moreira Zinsly 
vas_paste(void * paste_address,int offset)44*f49b7572SRaphael Moreira Zinsly static inline int vas_paste(void *paste_address, int offset)
45*f49b7572SRaphael Moreira Zinsly {
46*f49b7572SRaphael Moreira Zinsly 	__u32 cr;
47*f49b7572SRaphael Moreira Zinsly 
48*f49b7572SRaphael Moreira Zinsly 	cr = 0;
49*f49b7572SRaphael Moreira Zinsly 	asm volatile(PPC_PASTE(%1, %2)";"
50*f49b7572SRaphael Moreira Zinsly 		"mfocrf %0, 0x80;"
51*f49b7572SRaphael Moreira Zinsly 		: "=r" (cr)
52*f49b7572SRaphael Moreira Zinsly 		: "b" (offset), "b" (paste_address)
53*f49b7572SRaphael Moreira Zinsly 		: "memory", "cr0");
54*f49b7572SRaphael Moreira Zinsly 
55*f49b7572SRaphael Moreira Zinsly 	return (cr >> CR0_SHIFT) & CR0_MASK;
56*f49b7572SRaphael Moreira Zinsly }
57