Home | History | Annotate | Download | only in ppc32
      1 
      2 #include <stdio.h>
      3 #include <config.h>
      4 
      5 static
      6 int try_mtocrf ( int x )
      7 {
      8   int base = 0x31415927;
      9   int res;
     10 #ifdef HAVE_AS_PPC_MFTOCRF
     11   /* pre-set CR */
     12   __asm__ __volatile__(
     13      "mtcr %0"
     14      : /*w*/ : /*r*/ "b"(base) : /*trash*/"cc" );
     15 
     16   /* do it */
     17   __asm__ __volatile__(
     18      "mtocrf 4, %0"
     19      : /*w*/ : /*r*/ "b"(x) : /*trash*/"cc" );
     20 
     21   /* get CR */
     22   __asm__ __volatile__(
     23      "mfcr %0"
     24      : /*w*/"=b"(res) : /*r*/ );
     25 #else
     26   res = 42;
     27 #endif
     28   return res;
     29 }
     30 
     31 static
     32 int try_mfocrf ( int x )
     33 {
     34    int res;
     35 #ifdef HAVE_AS_PPC_MFTOCRF
     36    /* CR = x */
     37    __asm__ __volatile__(
     38      "mtcr %0"
     39      : /*w*/ : /*r*/ "b"(x) : /*trash*/"cc" );
     40 
     41   /* do it */
     42   __asm__ __volatile__(
     43      "li %0,0\n\t"
     44      "mfocrf %0,64"
     45      : /*w*/"=b"(res) : /*r*/ );
     46 #else
     47   res = 42;
     48 #endif
     49   return res;
     50 }
     51 
     52 /* This is a bit of a kludge since mfocrf reads the spec'd CR field,
     53    but the remaining returned bits are undefined.  It seems like on
     54    MPC7447A (Apple Mac Mini) mfocrf just reads the entire CR, which is
     55    an acceptable implementation, but is not necessarily what other
     56    implementations are going to do. */
     57 
     58 int main ( void )
     59 {
     60   int i, j;
     61   for (i = 0; i < 32; i++) {
     62     printf("0x%08x\n", try_mtocrf( 1<<i ));
     63   }
     64   printf("\n");
     65   j = 1;
     66   for (i = 0; i < 32; i++) {
     67     printf("0x%08x\n", try_mfocrf( j ));
     68     j *= 3;
     69   }
     70 
     71   return 0;
     72 }
     73