Home | History | Annotate | Download | only in powerpc
      1 #ifndef _SELFTESTS_POWERPC_INSTRUCTIONS_H
      2 #define _SELFTESTS_POWERPC_INSTRUCTIONS_H
      3 
      4 #include <stdio.h>
      5 #include <stdlib.h>
      6 
      7 /* This defines the "copy" instruction from Power ISA 3.0 Book II, section 4.4. */
      8 #define __COPY(RA, RB, L) \
      9 	(0x7c00060c | (RA) << (31-15) | (RB) << (31-20) | (L) << (31-10))
     10 #define COPY(RA, RB, L) \
     11 	.long __COPY((RA), (RB), (L))
     12 
     13 static inline void copy(void *i)
     14 {
     15 	asm volatile(str(COPY(0, %0, 0))";"
     16 			:
     17 			: "b" (i)
     18 			: "memory"
     19 		    );
     20 }
     21 
     22 static inline void copy_first(void *i)
     23 {
     24 	asm volatile(str(COPY(0, %0, 1))";"
     25 			:
     26 			: "b" (i)
     27 			: "memory"
     28 		    );
     29 }
     30 
     31 /* This defines the "paste" instruction from Power ISA 3.0 Book II, section 4.4. */
     32 #define __PASTE(RA, RB, L, RC) \
     33 	(0x7c00070c | (RA) << (31-15) | (RB) << (31-20) | (L) << (31-10) | (RC) << (31-31))
     34 #define PASTE(RA, RB, L, RC) \
     35 	.long __PASTE((RA), (RB), (L), (RC))
     36 
     37 static inline int paste(void *i)
     38 {
     39 	int cr;
     40 
     41 	asm volatile(str(PASTE(0, %1, 0, 0))";"
     42 			"mfcr %0;"
     43 			: "=r" (cr)
     44 			: "b" (i)
     45 			: "memory"
     46 		    );
     47 	return cr;
     48 }
     49 
     50 static inline int paste_last(void *i)
     51 {
     52 	int cr;
     53 
     54 	asm volatile(str(PASTE(0, %1, 1, 1))";"
     55 			"mfcr %0;"
     56 			: "=r" (cr)
     57 			: "b" (i)
     58 			: "memory"
     59 		    );
     60 	return cr;
     61 }
     62 
     63 #define PPC_INST_COPY                  __COPY(0, 0, 0)
     64 #define PPC_INST_COPY_FIRST            __COPY(0, 0, 1)
     65 #define PPC_INST_PASTE                 __PASTE(0, 0, 0, 0)
     66 #define PPC_INST_PASTE_LAST            __PASTE(0, 0, 1, 1)
     67 
     68 #endif /* _SELFTESTS_POWERPC_INSTRUCTIONS_H */
     69