Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _SELFTESTS_POWERPC_INSTRUCTIONS_H
0003 #define _SELFTESTS_POWERPC_INSTRUCTIONS_H
0004 
0005 #include <stdio.h>
0006 #include <stdlib.h>
0007 
0008 /* This defines the "copy" instruction from Power ISA 3.0 Book II, section 4.4. */
0009 #define __COPY(RA, RB, L) \
0010     (0x7c00060c | (RA) << (31-15) | (RB) << (31-20) | (L) << (31-10))
0011 #define COPY(RA, RB, L) \
0012     .long __COPY((RA), (RB), (L))
0013 
0014 static inline void copy(void *i)
0015 {
0016     asm volatile(str(COPY(0, %0, 0))";"
0017             :
0018             : "b" (i)
0019             : "memory"
0020             );
0021 }
0022 
0023 static inline void copy_first(void *i)
0024 {
0025     asm volatile(str(COPY(0, %0, 1))";"
0026             :
0027             : "b" (i)
0028             : "memory"
0029             );
0030 }
0031 
0032 /* This defines the "paste" instruction from Power ISA 3.0 Book II, section 4.4. */
0033 #define __PASTE(RA, RB, L, RC) \
0034     (0x7c00070c | (RA) << (31-15) | (RB) << (31-20) | (L) << (31-10) | (RC) << (31-31))
0035 #define PASTE(RA, RB, L, RC) \
0036     .long __PASTE((RA), (RB), (L), (RC))
0037 
0038 static inline int paste(void *i)
0039 {
0040     int cr;
0041 
0042     asm volatile(str(PASTE(0, %1, 0, 0))";"
0043             "mfcr %0;"
0044             : "=r" (cr)
0045             : "b" (i)
0046             : "memory"
0047             );
0048     return cr;
0049 }
0050 
0051 static inline int paste_last(void *i)
0052 {
0053     int cr;
0054 
0055     asm volatile(str(PASTE(0, %1, 1, 1))";"
0056             "mfcr %0;"
0057             : "=r" (cr)
0058             : "b" (i)
0059             : "memory"
0060             );
0061     return cr;
0062 }
0063 
0064 #define PPC_INST_COPY                  __COPY(0, 0, 0)
0065 #define PPC_INST_COPY_FIRST            __COPY(0, 0, 1)
0066 #define PPC_INST_PASTE                 __PASTE(0, 0, 0, 0)
0067 #define PPC_INST_PASTE_LAST            __PASTE(0, 0, 1, 1)
0068 
0069 /* This defines the prefixed load/store instructions */
0070 #ifdef __ASSEMBLY__
0071 #  define stringify_in_c(...)   __VA_ARGS__
0072 #else
0073 #  define __stringify_in_c(...) #__VA_ARGS__
0074 #  define stringify_in_c(...)   __stringify_in_c(__VA_ARGS__) " "
0075 #endif
0076 
0077 #define __PPC_RA(a) (((a) & 0x1f) << 16)
0078 #define __PPC_RS(s) (((s) & 0x1f) << 21)
0079 #define __PPC_RT(t) __PPC_RS(t)
0080 #define __PPC_PREFIX_R(r)   (((r) & 0x1) << 20)
0081 
0082 #define PPC_PREFIX_MLS          0x06000000
0083 #define PPC_PREFIX_8LS          0x04000000
0084 
0085 #define PPC_INST_LBZ            0x88000000
0086 #define PPC_INST_LHZ            0xa0000000
0087 #define PPC_INST_LHA            0xa8000000
0088 #define PPC_INST_LWZ            0x80000000
0089 #define PPC_INST_STB            0x98000000
0090 #define PPC_INST_STH            0xb0000000
0091 #define PPC_INST_STW            0x90000000
0092 #define PPC_INST_STD            0xf8000000
0093 #define PPC_INST_LFS            0xc0000000
0094 #define PPC_INST_LFD            0xc8000000
0095 #define PPC_INST_STFS           0xd0000000
0096 #define PPC_INST_STFD           0xd8000000
0097 
0098 #define PREFIX_MLS(instr, t, a, r, d)   stringify_in_c(.balign 64, , 4;)        \
0099                     stringify_in_c(.long PPC_PREFIX_MLS |       \
0100                                __PPC_PREFIX_R(r) |      \
0101                                (((d) >> 16) & 0x3ffff);)    \
0102                     stringify_in_c(.long (instr)  |         \
0103                                __PPC_RT(t) |            \
0104                                __PPC_RA(a) |            \
0105                                ((d) & 0xffff);\n)
0106 
0107 #define PREFIX_8LS(instr, t, a, r, d)   stringify_in_c(.balign 64, , 4;)        \
0108                     stringify_in_c(.long PPC_PREFIX_8LS |       \
0109                                __PPC_PREFIX_R(r) |      \
0110                                (((d) >> 16) & 0x3ffff);)    \
0111                     stringify_in_c(.long (instr)  |         \
0112                                __PPC_RT(t) |            \
0113                                __PPC_RA(a) |            \
0114                                ((d) & 0xffff);\n)
0115 
0116 /* Prefixed Integer Load/Store instructions */
0117 #define PLBZ(t, a, r, d)        PREFIX_MLS(PPC_INST_LBZ, t, a, r, d)
0118 #define PLHZ(t, a, r, d)        PREFIX_MLS(PPC_INST_LHZ, t, a, r, d)
0119 #define PLHA(t, a, r, d)        PREFIX_MLS(PPC_INST_LHA, t, a, r, d)
0120 #define PLWZ(t, a, r, d)        PREFIX_MLS(PPC_INST_LWZ, t, a, r, d)
0121 #define PLWA(t, a, r, d)        PREFIX_8LS(0xa4000000, t, a, r, d)
0122 #define PLD(t, a, r, d)         PREFIX_8LS(0xe4000000, t, a, r, d)
0123 #define PLQ(t, a, r, d)         PREFIX_8LS(0xe0000000, t, a, r, d)
0124 #define PSTB(s, a, r, d)        PREFIX_MLS(PPC_INST_STB, s, a, r, d)
0125 #define PSTH(s, a, r, d)        PREFIX_MLS(PPC_INST_STH, s, a, r, d)
0126 #define PSTW(s, a, r, d)        PREFIX_MLS(PPC_INST_STW, s, a, r, d)
0127 #define PSTD(s, a, r, d)        PREFIX_8LS(0xf4000000, s, a, r, d)
0128 #define PSTQ(s, a, r, d)        PREFIX_8LS(0xf0000000, s, a, r, d)
0129 
0130 /* Prefixed Floating-Point Load/Store Instructions */
0131 #define PLFS(frt, a, r, d)      PREFIX_MLS(PPC_INST_LFS, frt, a, r, d)
0132 #define PLFD(frt, a, r, d)      PREFIX_MLS(PPC_INST_LFD, frt, a, r, d)
0133 #define PSTFS(frs, a, r, d)     PREFIX_MLS(PPC_INST_STFS, frs, a, r, d)
0134 #define PSTFD(frs, a, r, d)     PREFIX_MLS(PPC_INST_STFD, frs, a, r, d)
0135 
0136 /* Prefixed VSX Load/Store Instructions */
0137 #define PLXSD(vrt, a, r, d)     PREFIX_8LS(0xa8000000, vrt, a, r, d)
0138 #define PLXSSP(vrt, a, r, d)        PREFIX_8LS(0xac000000, vrt, a, r, d)
0139 #define PLXV0(s, a, r, d)       PREFIX_8LS(0xc8000000, s, a, r, d)
0140 #define PLXV1(s, a, r, d)       PREFIX_8LS(0xcc000000, s, a, r, d)
0141 #define PSTXSD(vrs, a, r, d)        PREFIX_8LS(0xb8000000, vrs, a, r, d)
0142 #define PSTXSSP(vrs, a, r, d)       PREFIX_8LS(0xbc000000, vrs, a, r, d)
0143 #define PSTXV0(s, a, r, d)      PREFIX_8LS(0xd8000000, s, a, r, d)
0144 #define PSTXV1(s, a, r, d)      PREFIX_8LS(0xdc000000, s, a, r, d)
0145 
0146 #endif /* _SELFTESTS_POWERPC_INSTRUCTIONS_H */