StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ppcIOLib.h
1 /*
2  these routines _MUST_ be declared as they are because we want to
3  inline them.
4 
5 */
6 
7 #ifndef _PPC_IO_LIB_H
8 #define _PPC_IO_LIB_H
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 
15 /*
16  eieio ensures that all the instructions preceeding it will finish
17  before new ones are started.
18  It effectively flushes the PPC's pipeline
19 */
20 extern __inline void eieio(void)
21 {
22  __asm__ volatile ("eieio ") ;
23 
24  return ;
25 }
26 
27 
28 /*
29  w32 writes a 32bit quantity "data" to the address in
30  "addr" followed by the sync primitive (eieio) thus
31  ensuring that the write finishes before any other operation
32  after it
33 */
34 extern __inline void w32(volatile unsigned int *addr, unsigned int data)
35 {
36  *addr = data ;
37  eieio() ;
38  return ;
39 }
40 
41 /*
42  see above
43 */
44 extern __inline void w16(volatile unsigned short *addr, unsigned short data)
45 {
46  *addr = data ;
47  eieio() ;
48  return ;
49 }
50 
51 /*
52  see above
53 */
54 extern __inline void w8(volatile unsigned char *addr, unsigned char data)
55 {
56  *addr = data ;
57  eieio() ;
58  return ;
59 }
60 
61 
62 /*
63  routines returns the byte-swapped 32bit integer at address "addr".
64  Used for endian conversion
65 */
66 extern __inline unsigned int rs32(volatile unsigned int *addr)
67 {
68  unsigned int tmp ;
69 
70  __asm__ volatile ("lwbrx %0,0,%1 " : "=rI" (tmp) : "rI" (addr)) ;
71 
72 
73  return tmp ;
74 }
75 
76 /*
77  see above except for 16bit datum
78 */
79 extern __inline unsigned short rs16(volatile unsigned short *addr)
80 {
81  unsigned int tmp ;
82 
83  __asm__ volatile ("lhbrx %0,0,%1 " : "=rI" (tmp) : "rI" (addr)) ;
84 
85 
86  return (unsigned short)tmp ;
87 }
88 
89 
90 /*
91  writes the data byte-spawed to address addr followed by the
92  syncing primitive (eieio)
93  Used for endian conversion
94 */
95 extern __inline void ws32(volatile unsigned int *addr, unsigned int data)
96 {
97  __asm__ volatile ("stwbrx %0,0,%1; eieio " : : "r" (data) , "rI" (addr)) ;
98 
99  return ;
100 }
101 
102 /*
103  writes the data byte-spawed to address addr WIHTOUT eieio
104  Used for endian conversion
105 */
106 extern __inline void ws32_no_eieio(volatile unsigned int *addr, unsigned int data)
107 {
108  __asm__ volatile ("stwbrx %0,0,%1 " : : "r" (data) , "rI" (addr)) ;
109 
110  return ;
111 }
112 
113 /*
114  see above except for 16bit data
115 */
116 extern __inline void ws16(volatile unsigned short *addr, unsigned short data)
117 {
118  __asm__ volatile ("sthbrx %0,0,%1 \n eieio " : : "r" (data) , "rI" (addr)) ;
119 
120  return ;
121 }
122 
123 
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif