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