This source file includes following definitions.
- get_user_byte
- get_user_word
- get_user_long
- get_user_dlong
- put_user_byte
- put_user_word
- put_user_long
- put_user_dlong
- __generic_memcpy_tofs
- __constant_memcpy_tofs
- __generic_memcpy_fromfs
- __constant_memcpy_fromfs
- get_fs
- get_ds
- set_fs
1
2
3
4
5
6
7
8
9
10
11
12 #ifndef _ASM_MIPS_SEGMENT_H_
13 #define _ASM_MIPS_SEGMENT_H_
14
15 static inline unsigned char get_user_byte(const char * addr)
16 {
17 register unsigned char _v;
18
19 __asm__ ("lbu\t%0,%1":"=r" (_v):"r" (*addr));
20
21 return _v;
22 }
23
24 #define get_fs_byte(addr) get_user_byte((char *)(addr))
25
26 static inline unsigned short get_user_word(const short *addr)
27 {
28 unsigned short _v;
29
30 __asm__ ("lhu\t%0,%1":"=r" (_v):"r" (*addr));
31
32 return _v;
33 }
34
35 #define get_fs_word(addr) get_user_word((short *)(addr))
36
37 static inline unsigned long get_user_long(const int *addr)
38 {
39 unsigned long _v;
40
41 __asm__ ("lwu\t%0,%1":"=r" (_v):"r" (*addr)); \
42 return _v;
43 }
44
45 #define get_fs_long(addr) get_user_long((int *)(addr))
46
47 static inline unsigned long get_user_dlong(const int *addr)
48 {
49 unsigned long _v;
50
51 __asm__ ("ld\t%0,%1":"=r" (_v):"r" (*addr)); \
52 return _v;
53 }
54
55 #define get_fs_dlong(addr) get_user_dlong((int *)(addr))
56
57 static inline void put_user_byte(char val,char *addr)
58 {
59 __asm__ ("sb\t%0,%1": :"r" (val),"r" (*addr));
60 }
61
62 #define put_fs_byte(x,addr) put_user_byte((x),(char *)(addr))
63
64 static inline void put_user_word(short val,short * addr)
65 {
66 __asm__ ("sh\t%0,%1": :"r" (val),"r" (*addr));
67 }
68
69 #define put_fs_word(x,addr) put_user_word((x),(short *)(addr))
70
71 static inline void put_user_long(unsigned long val,int * addr)
72 {
73 __asm__ ("sw\t%0,%1": :"r" (val),"r" (*addr));
74 }
75
76 #define put_fs_long(x,addr) put_user_long((x),(int *)(addr))
77
78 static inline void put_user_dlong(unsigned long val,int * addr)
79 {
80 __asm__ ("sd\t%0,%1": :"r" (val),"r" (*addr));
81 }
82
83 #define put_fs_dlong(x,addr) put_user_dlong((x),(int *)(addr))
84
85
86
87
88 extern unsigned long segment_fs;
89
90 static inline void __generic_memcpy_tofs(void * to, const void * from, unsigned long n)
91 {
92 __asm__(
93 ".set\tnoreorder\n\t"
94 ".set\tnoat\n"
95 "1:\tlbu\t$1,(%2)\n\t"
96 "addiu\t%2,%2,1\n\t"
97 "sb\t$1,(%1)\n\t"
98 "addiu\t%0,%0,-1\n\t"
99 "bne\t$0,%0,1b\n\t"
100 "addiu\t%1,%1,1\n\t"
101 ".set\tat\n\t"
102 ".set\treorder"
103 :
104 :"d" (n),"d" (((long) to)| segment_fs),"d" ((long) from)
105 :"$1");
106 }
107
108 static inline void __constant_memcpy_tofs(void * to, const void * from, unsigned long n)
109 {
110
111
112
113 switch (n) {
114 case 0:
115 return;
116 case 1:
117 put_user_byte(*(const char *) from, (char *) to);
118 return;
119 case 2:
120 put_user_byte(*(const char *) from, (char *) to);
121 put_user_byte(*(1+(const char *) from), 1+(char *) to);
122 return;
123 case 3:
124 put_user_byte(*((const char *) from), (char *) to);
125 put_user_byte(*(1+(const char *) from), 1+(char *) to);
126 put_user_byte(*(2+(const char *) from), 2+(char *) to);
127 return;
128 case 4:
129 put_user_byte(*((const char *) from), (char *) to);
130 put_user_byte(*(1+(const char *) from), 1+(char *) to);
131 put_user_byte(*(2+(const char *) from), 2+(char *) to);
132 put_user_byte(*(3+(const char *) from), 3+(char *) to);
133 return;
134 }
135
136 __generic_memcpy_tofs(to, from, n);
137
138 return;
139 }
140
141 static inline void __generic_memcpy_fromfs(void * to, const void * from, unsigned long n)
142 {
143 __asm__(
144 ".set\tnoreorder\n\t"
145 ".set\tnoat\n"
146 "1:\tlbu\t$1,(%2)\n\t"
147 "addiu\t%2,%2,1\n\t"
148 "sb\t$1,(%1)\n\t"
149 "addiu\t%0,%0,-1\n\t"
150 "bne\t$0,%0,1b\n\t"
151 "addiu\t%1,%1,1\n\t"
152 ".set\tat\n\t"
153 ".set\treorder"
154 :
155 :"d" (n),"d" ((long) to),"d" (((long) from | segment_fs))
156 :"$1","memory");
157 }
158
159 static inline void __constant_memcpy_fromfs(void * to, const void * from, unsigned long n)
160 {
161
162
163
164 switch (n) {
165 case 0:
166 return;
167 case 1:
168 *(char *)to = get_user_byte((const char *) from);
169 return;
170 case 2:
171 *(char *) to = get_user_byte((const char *) from);
172 *(char *) to = get_user_byte(1+(const char *) from);
173 return;
174 case 3:
175 *(char *) to = get_user_byte((const char *) from);
176 *(char *) to = get_user_byte(1+(const char *) from);
177 *(char *) to = get_user_byte(2+(const char *) from);
178 return;
179 case 4:
180 *(char *) to = get_user_byte((const char *) from);
181 *(char *) to = get_user_byte(1+(const char *) from);
182 *(char *) to = get_user_byte(2+(const char *) from);
183 *(char *) to = get_user_byte(3+(const char *) from);
184 return;
185 }
186
187
188 __generic_memcpy_fromfs(to, from, n);
189 return;
190 }
191
192 #define memcpy_fromfs(to, from, n) \
193 (__builtin_constant_p(n) ? \
194 __constant_memcpy_fromfs((to),(from),(n)) : \
195 __generic_memcpy_fromfs((to),(from),(n)))
196
197 #define memcpy_tofs(to, from, n) \
198 (__builtin_constant_p(n) ? \
199 __constant_memcpy_tofs((to),(from),(n)) : \
200 __generic_memcpy_tofs((to),(from),(n)))
201
202 static inline unsigned long get_fs(void)
203 {
204 return segment_fs;
205 }
206
207 static inline unsigned long get_ds(void)
208 {
209 return KERNEL_DS;
210 }
211
212 static inline void set_fs(unsigned long val)
213 {
214 segment_fs = val;
215 }
216
217 #endif