Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 
0003 /* From asm-compat.h */
0004 #define __stringify_in_c(...)   #__VA_ARGS__
0005 #define stringify_in_c(...) __stringify_in_c(__VA_ARGS__) " "
0006 
0007 /*
0008  * Macros taken from arch/powerpc/include/asm/ppc-opcode.h and other
0009  * header files.
0010  */
0011 #define ___PPC_RA(a)    (((a) & 0x1f) << 16)
0012 #define ___PPC_RB(b)    (((b) & 0x1f) << 11)
0013 
0014 #define PPC_INST_COPY                   0x7c20060c
0015 #define PPC_INST_PASTE                  0x7c20070d
0016 
0017 #define PPC_COPY(a, b)          stringify_in_c(.long PPC_INST_COPY | \
0018                         ___PPC_RA(a) | ___PPC_RB(b))
0019 #define PPC_PASTE(a, b)         stringify_in_c(.long PPC_INST_PASTE | \
0020                         ___PPC_RA(a) | ___PPC_RB(b))
0021 #define CR0_SHIFT   28
0022 #define CR0_MASK    0xF
0023 /*
0024  * Copy/paste instructions:
0025  *
0026  *  copy RA,RB
0027  *      Copy contents of address (RA) + effective_address(RB)
0028  *      to internal copy-buffer.
0029  *
0030  *  paste RA,RB
0031  *      Paste contents of internal copy-buffer to the address
0032  *      (RA) + effective_address(RB)
0033  */
0034 static inline int vas_copy(void *crb, int offset)
0035 {
0036     asm volatile(PPC_COPY(%0, %1)";"
0037         :
0038         : "b" (offset), "b" (crb)
0039         : "memory");
0040 
0041     return 0;
0042 }
0043 
0044 static inline int vas_paste(void *paste_address, int offset)
0045 {
0046     __u32 cr;
0047 
0048     cr = 0;
0049     asm volatile(PPC_PASTE(%1, %2)";"
0050         "mfocrf %0, 0x80;"
0051         : "=r" (cr)
0052         : "b" (offset), "b" (paste_address)
0053         : "memory", "cr0");
0054 
0055     return (cr >> CR0_SHIFT) & CR0_MASK;
0056 }